From 8a2639b7aa447fce705964a5e4dc16a8b5031c4d Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 12 Jan 2014 21:23:44 +0200 Subject: [PATCH] Bug in uniontool with splinepath. --HG-- branch : feature --- src/container/vcontainer.cpp | 32 ++++++++++++------------ src/mainwindow.cpp | 40 +++++++++++++++++++++++------- src/mainwindow.h | 1 + src/tools/vtooldetail.cpp | 23 +++++++++++++++++ src/tools/vtooluniondetails.cpp | 25 ++++++++++--------- src/widgets/vmaingraphicsscene.cpp | 8 ++++-- 6 files changed, 90 insertions(+), 39 deletions(-) diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 9cc2f9419..db16f5e60 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -241,22 +241,22 @@ QVector VContainer::CorrectEquidistantPoints(const QVector &po correctPoints.append(points.at(i)); } } - if(correctPoints.size()<3) - { - return correctPoints; - } - //Remove point on line - QPointF point; - for(qint32 i = 1; i ()), dialogCutSplinePath (QSharedPointer()), dialogUnionDetails(QSharedPointer()), dialogCutArc(QSharedPointer()), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), - mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0) + mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true) { ui->setupUi(this); static const char * GENERIC_ICON_TO_CHECK = "document-open"; @@ -709,11 +709,14 @@ void MainWindow::currentDrawChanged( int index ) { doc->setCurrentData(); doc->ChangeActivDraw(comboBoxDraws->itemText(index)); - qint64 id = doc->SPointActiveDraw(); - if (id != 0) + if(drawMode) { - const VPointF *p = pattern->GeometricObject(id); - view->centerOn(p->toQPointF()); + qint64 id = doc->SPointActiveDraw(); + if (id != 0) + { + const VPointF *p = pattern->GeometricObject(id); + view->centerOn(p->toQPointF()); + } } } } @@ -920,6 +923,7 @@ void MainWindow::ActionDraw(bool checked) mode = Draw::Calculation; comboBoxDraws->setEnabled(true); comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace + drawMode = true; SetEnableTool(true); doc->setCurrentData(); @@ -942,10 +946,12 @@ void MainWindow::ActionDetails(bool checked) view->setScene(sceneDetails); RestoreCurrentScene(); + drawMode = false; currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1); comboBoxDraws->setEnabled(false); + mode = Draw::Modeling; SetEnableTool(true); currentToolBoxIndex = ui->toolBox->currentIndex(); @@ -1014,10 +1020,26 @@ void MainWindow::ActionOpen() if (fileName.isEmpty() && changeInFile == false) { OpenPattern(fName); - sceneDraw->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), - view->contentsRect().height()-view->contentsRect().y())); - sceneDetails->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), - view->contentsRect().height()-view->contentsRect().y())); + + QRectF rect = sceneDraw->itemsBoundingRect(); + //Correct BoundingRect + rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); + + QRect rec = view->contentsRect(); + //Correct contentsRect + rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y()); + + if(rec.contains(rect.toRect())) + { + sceneDraw->setSceneRect(rec); + sceneDetails->setSceneRect(rec); + } + else + { + rect = rect.united(rec); + sceneDraw->setSceneRect(rect); + sceneDetails->setSceneRect(rect); + } } else { diff --git a/src/mainwindow.h b/src/mainwindow.h index 04f775398..72122d673 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -511,6 +511,7 @@ private: Draw::Draws mode; qint32 currentDrawIndex; qint32 currentToolBoxIndex; + bool drawMode; /** * @brief ToolBarOption */ diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 72d6b4de4..740512790 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -247,6 +247,29 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const { domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x()))); domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y()))); + + QGraphicsScene *sc = this->scene(); + QRectF rect = sc->itemsBoundingRect(); + //Correct BoundingRect + rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); + qDebug()<<"rect"< list = sc->views(); + QRect rec = list[0]->contentsRect(); + qDebug()<<"rec"<setSceneRect(rec); + } + else + { + rect = rect.united(rec); + sc->setSceneRect(rect); + } + doc->haveLiteChange(); } } diff --git a/src/tools/vtooluniondetails.cpp b/src/tools/vtooluniondetails.cpp index c81edeb96..685571f19 100644 --- a/src/tools/vtooluniondetails.cpp +++ b/src/tools/vtooluniondetails.cpp @@ -139,10 +139,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai BiasRotatePoint(p1, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); qint64 idP1 = data->AddGObject(p1); - VPointF p2 = VPointF(spline->GetP2().x(), spline->GetP2().y(), "A", 0, 0); + VPointF p2 = VPointF(spline->GetP2()); BiasRotatePoint(&p2, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); - VPointF p3 = VPointF(spline->GetP3().x(), spline->GetP3().y(), "A", 0, 0); + VPointF p3 = VPointF(spline->GetP3()); BiasRotatePoint(&p3, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); VPointF *p4 = new VPointF(spline->GetP4()); @@ -150,9 +150,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); qint64 idP4 = data->AddGObject(p4); - VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); + VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0, + Draw::Modeling); Q_ASSERT(spl != 0); - spl->setMode(Draw::Modeling); idObject = data->AddGObject(spl); VSpline *spl1 = new VSpline(*spl); @@ -208,10 +208,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai if (i==1) { path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), - splinePath->at(i-1).KAsm1())); + splinePath->at(i-1).KAsm2())); } - path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), - splinePath->at(i).KAsm1())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, + splinePath->at(i).KAsm2())); } while(k>=0) { @@ -310,9 +310,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c ++idCount; data->UpdateGObject(idDetail+idCount, p4); - VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); + VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0, + Draw::Modeling); + Q_ASSERT(spl != 0); - spl->setMode(Draw::Modeling); ++idCount; data->UpdateGObject(idDetail+idCount, spl); @@ -364,10 +365,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c if (i==1) { path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), - splinePath->at(i-1).KAsm1())); + splinePath->at(i-1).KAsm2())); } - path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), - splinePath->at(i).KAsm1())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, + splinePath->at(i).KAsm2())); } while(k>=0) diff --git a/src/widgets/vmaingraphicsscene.cpp b/src/widgets/vmaingraphicsscene.cpp index 9bb9d9abd..e2bd07775 100644 --- a/src/widgets/vmaingraphicsscene.cpp +++ b/src/widgets/vmaingraphicsscene.cpp @@ -31,10 +31,14 @@ #include VMainGraphicsScene::VMainGraphicsScene() - :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} + :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()) +{ +} VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent) - :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} + :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()) +{ +} void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {