From 5ba92396c2ec9046e72af5867d9714634fe537bc Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 12 Jul 2014 19:25:25 +0300 Subject: [PATCH] After changing active pattern piece calculate pattern piece's bounding rect and use them for best fit zooming. --HG-- branch : develop --- src/app/mainwindow.cpp | 7 +- src/app/tools/drawTools/vtoolbisector.h | 1 + src/app/tools/drawTools/vtoolpointofcontact.h | 1 + src/app/tools/drawTools/vtoolshoulderpoint.h | 1 + src/app/widgets/vmaingraphicsview.cpp | 2 +- src/app/xml/vpattern.cpp | 114 ++++++++++++++++++ src/app/xml/vpattern.h | 3 + 7 files changed, 122 insertions(+), 7 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index c2bd32cd2..bd2ced0db 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1112,12 +1112,7 @@ void MainWindow::currentDrawChanged( int index ) if (drawMode) { ArrowTool(); - quint32 id = doc->SPointActiveDraw(); - if (id != 0) - { - const VPointF *p = pattern->GeometricObject(id); - view->centerOn(p->toQPointF()); - } + view->fitInView(doc->ActiveDrawBoundingRect(), Qt::KeepAspectRatio); } } } diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index 4660ce323..58a1a7951 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -36,6 +36,7 @@ */ class VToolBisector : public VToolLinePoint { + Q_OBJECT public: VToolBisector(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 941644a0c..942378c17 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -36,6 +36,7 @@ */ class VToolPointOfContact : public VToolPoint { + Q_OBJECT public: VToolPointOfContact(VPattern *doc, VContainer *data, const quint32 &id, const QString &arcRadius, const quint32 ¢er, const quint32 &firstPointId, const quint32 &secondPointId, diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index 2609504dd..c6acd946e 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -37,6 +37,7 @@ */ class VToolShoulderPoint : public VToolLinePoint { + Q_OBJECT public: VToolShoulderPoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, const quint32 &p1Line, const quint32 &p2Line, const quint32 &pShoulder, diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index 1e597d23c..af96f549b 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.cpp @@ -179,7 +179,7 @@ void VMainGraphicsView::ZoomFitBest() return; } - this->fitInView(rect,Qt::KeepAspectRatio); + this->fitInView(rect, Qt::KeepAspectRatio); VAbstractTool::NewSceneRect(this->scene(), this); QTransform trans = this->transform(); emit NewFactor(trans.m11()); diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 8317806ff..f1075c670 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1909,3 +1909,117 @@ int VPattern::CountPP() const return rootElement.elementsByTagName( TagDraw ).count(); } + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VPattern::ActiveDrawBoundingRect() const +{ + QRectF rec; + + for (qint32 i = 0; i< history.size(); ++i) + { + const VToolRecord tool = history.at(i); + if (tool.getNameDraw() == nameActivDraw) + { + switch ( tool.getTypeTool() ) + { + case Tool::ArrowTool: + Q_UNREACHABLE(); + break; + case Tool::SinglePointTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::EndLineTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::LineTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::AlongLineTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::ShoulderPointTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::NormalTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::BisectorTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::LineIntersectTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::SplineTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::ArcTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::SplinePathTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::PointOfContact: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::Height: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::Triangle: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::PointOfIntersection: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::CutArcTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::CutSplineTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + case Tool::CutSplinePathTool: + rec = ToolBoundingRect(rec, tool.getId()); + break; + //Because "history" not only show history of pattern, but help restore current data for each pattern's + //piece, we need add record about details and nodes, but don't show them. + case Tool::DetailTool: + break; + case Tool::UnionDetails: + break; + case Tool::NodeArc: + break; + case Tool::NodePoint: + break; + case Tool::NodeSpline: + break; + case Tool::NodeSplinePath: + break; + default: + qDebug()<<"Got wrong tool type. Ignore."; + break; + } + } + } + return rec; +} + +template +QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const +{ + QRectF recTool = recTool.united(rec); + if (tools.contains(id)) + { + T *vTool = qobject_cast(tools.value(id)); + SCASSERT(vTool != nullptr); + + QRectF childrenRect = vTool->childrenBoundingRect(); + //map to scene coordinate. + childrenRect.translate(vTool->scenePos()); + + recTool = recTool | vTool->boundingRect() | childrenRect; + } + else + { + qDebug()<<"Can't find tool with id="< + QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; }; //---------------------------------------------------------------------------------------------------------------------