After changing active pattern piece calculate pattern piece's bounding rect and

use them for best fit zooming.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-12 19:25:25 +03:00
parent c7c7f88977
commit 5ba92396c2
7 changed files with 122 additions and 7 deletions

View File

@ -1112,12 +1112,7 @@ void MainWindow::currentDrawChanged( int index )
if (drawMode)
{
ArrowTool();
quint32 id = doc->SPointActiveDraw();
if (id != 0)
{
const VPointF *p = pattern->GeometricObject<const VPointF *>(id);
view->centerOn(p->toQPointF());
}
view->fitInView(doc->ActiveDrawBoundingRect(), Qt::KeepAspectRatio);
}
}
}

View File

@ -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,

View File

@ -36,6 +36,7 @@
*/
class VToolPointOfContact : public VToolPoint
{
Q_OBJECT
public:
VToolPointOfContact(VPattern *doc, VContainer *data, const quint32 &id, const QString &arcRadius,
const quint32 &center, const quint32 &firstPointId, const quint32 &secondPointId,

View File

@ -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,

View File

@ -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());

View File

@ -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<VToolSinglePoint>(rec, tool.getId());
break;
case Tool::EndLineTool:
rec = ToolBoundingRect<VToolEndLine>(rec, tool.getId());
break;
case Tool::LineTool:
rec = ToolBoundingRect<VToolLine>(rec, tool.getId());
break;
case Tool::AlongLineTool:
rec = ToolBoundingRect<VToolAlongLine>(rec, tool.getId());
break;
case Tool::ShoulderPointTool:
rec = ToolBoundingRect<VToolShoulderPoint>(rec, tool.getId());
break;
case Tool::NormalTool:
rec = ToolBoundingRect<VToolNormal>(rec, tool.getId());
break;
case Tool::BisectorTool:
rec = ToolBoundingRect<VToolBisector>(rec, tool.getId());
break;
case Tool::LineIntersectTool:
rec = ToolBoundingRect<VToolLineIntersect>(rec, tool.getId());
break;
case Tool::SplineTool:
rec = ToolBoundingRect<VToolSpline>(rec, tool.getId());
break;
case Tool::ArcTool:
rec = ToolBoundingRect<VToolArc>(rec, tool.getId());
break;
case Tool::SplinePathTool:
rec = ToolBoundingRect<VToolSplinePath>(rec, tool.getId());
break;
case Tool::PointOfContact:
rec = ToolBoundingRect<VToolPointOfContact>(rec, tool.getId());
break;
case Tool::Height:
rec = ToolBoundingRect<VToolHeight>(rec, tool.getId());
break;
case Tool::Triangle:
rec = ToolBoundingRect<VToolTriangle>(rec, tool.getId());
break;
case Tool::PointOfIntersection:
rec = ToolBoundingRect<VToolPointOfIntersection>(rec, tool.getId());
break;
case Tool::CutArcTool:
rec = ToolBoundingRect<VToolCutArc>(rec, tool.getId());
break;
case Tool::CutSplineTool:
rec = ToolBoundingRect<VToolCutSpline>(rec, tool.getId());
break;
case Tool::CutSplinePathTool:
rec = ToolBoundingRect<VToolCutSplinePath>(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 <typename T>
QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const
{
QRectF recTool = recTool.united(rec);
if (tools.contains(id))
{
T *vTool = qobject_cast<T *>(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="<<id;
}
return recTool;
}

View File

@ -111,6 +111,7 @@ public:
QDomElement GetPPElement(const QString &name);
bool CheckNamePP(const QString& name) const;
int CountPP() const;
QRectF ActiveDrawBoundingRect() const;
signals:
/**
* @brief ChangedActivDraw change active pattern peace.
@ -210,6 +211,8 @@ private:
void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my);
void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject,
quint32 &idTool);
template <typename T>
QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const;
};
//---------------------------------------------------------------------------------------------------------------------