diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 2fb5c2587..808de858b 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -73,16 +73,7 @@ void VToolAlongLine::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolAlongLine * visual = qobject_cast(vis); - visual->setPoint1Id(basePointId); - visual->setPoint2Id(secondPointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -163,6 +154,21 @@ void VToolAlongLine::ReadToolAttributes(const QDomElement &domElement) secondPointId = doc->GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::SetVisualization() +{ + if (vis != nullptr) + { + VisToolAlongLine *visual = qobject_cast(vis); + SCASSERT(visual != nullptr) + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolAlongLine::GetSecondPointId() const { @@ -188,23 +194,12 @@ void VToolAlongLine::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolAlongLine *visual = new VisToolAlongLine(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(basePointId); - visual->setPoint2Id(secondPointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolAlongLine * visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolAlongLine * visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index af32bf23d..be72a818f 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -65,6 +65,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief secondPointId id second point of line. */ quint32 secondPointId; diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 57ab391d3..9946bcf0a 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -292,25 +292,12 @@ void VToolArc::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolArc * visual = new VisToolArc(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); - - visual->setPoint1Id(arc->GetCenter().id()); - visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius())); - visual->setF1(qApp->FormulaToUser(arc->GetFormulaF1())); - visual->setF2(qApp->FormulaToUser(arc->GetFormulaF2())); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolArc *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolArc *visual = qobject_cast(vis)) { visual->show(); } @@ -375,18 +362,13 @@ void VToolArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshGeometry refresh item on scene. - */ -void VToolArc::RefreshGeometry() +void VToolArc::SetVisualization() { - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); - this->setPath(ToolPath()); - if (vis != nullptr) { const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); VisToolArc *visual = qobject_cast(vis); + SCASSERT(visual != nullptr) visual->setPoint1Id(arc->GetCenter().id()); visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius())); @@ -395,3 +377,15 @@ void VToolArc::RefreshGeometry() visual->RefreshGeometry(); } } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief RefreshGeometry refresh item on scene. + */ +void VToolArc::RefreshGeometry() +{ + this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPath(ToolPath()); + + SetVisualization(); +} diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 21df02572..e67072579 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -71,6 +71,7 @@ protected: virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); + virtual void SetVisualization(); private: void RefreshGeometry(); }; diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 4361b76a7..bde8cbcc7 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -321,6 +321,23 @@ void VToolBisector::ReadToolAttributes(const QDomElement &domElement) thirdPointId = doc->GetParametrUInt(domElement, AttrThirdPoint, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::SetVisualization() +{ + if (vis != nullptr) + { + VisToolBisector *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(basePointId); + visual->setPoint3Id(thirdPointId); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolBisector::GetThirdPointId() const { @@ -346,24 +363,12 @@ void VToolBisector::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolBisector * visual = new VisToolBisector(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(firstPointId); - visual->setPoint2Id(basePointId); - visual->setPoint3Id(thirdPointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolBisector *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolBisector *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index 38056063b..0ac0281b1 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -72,6 +72,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief firstPointId id first point of angle. */ quint32 firstPointId; diff --git a/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp b/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp index 7bcd8ea8d..1e4cdb7ae 100644 --- a/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp +++ b/src/app/tools/drawTools/vtoolcurveintersectaxis.cpp @@ -226,23 +226,12 @@ void VToolCurveIntersectAxis::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolCurveIntersectAxis * visual = new VisToolCurveIntersectAxis(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(curveId); - visual->setAxisPointId(basePointId); - visual->SetAngle(qApp->FormulaToUser(formulaAngle)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolCurveIntersectAxis *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolCurveIntersectAxis *visual = qobject_cast(vis)) { visual->show(); } @@ -320,3 +309,19 @@ void VToolCurveIntersectAxis::ReadToolAttributes(const QDomElement &domElement) curveId = doc->GetParametrUInt(domElement, AttrCurve, NULL_ID_STR); formulaAngle = doc->GetParametrString(domElement, AttrAngle, ""); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCurveIntersectAxis::SetVisualization() +{ + if (vis != nullptr) + { + VisToolCurveIntersectAxis *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(curveId); + visual->setAxisPointId(basePointId); + visual->SetAngle(qApp->FormulaToUser(formulaAngle)); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} diff --git a/src/app/tools/drawTools/vtoolcurveintersectaxis.h b/src/app/tools/drawTools/vtoolcurveintersectaxis.h index d70080cb1..271e69954 100644 --- a/src/app/tools/drawTools/vtoolcurveintersectaxis.h +++ b/src/app/tools/drawTools/vtoolcurveintersectaxis.h @@ -69,6 +69,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolCurveIntersectAxis) QString formulaAngle; diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index 6f2876c63..2864d14a5 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -191,21 +191,12 @@ void VToolCutArc::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolCutArc * visual = new VisToolCutArc(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(curveCutId); - visual->setLength(qApp->FormulaToUser(formula)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolCutArc *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolCutArc *visual = qobject_cast(vis)) { visual->show(); } @@ -226,14 +217,7 @@ void VToolCutArc::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolCutArc *visual = qobject_cast(vis); - visual->setPoint1Id(curveCutId); - visual->setLength(qApp->FormulaToUser(formula)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -320,3 +304,17 @@ void VToolCutArc::ReadToolAttributes(const QDomElement &domElement) curveCutId = doc->GetParametrUInt(domElement, AttrArc, NULL_ID_STR); lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutArc::SetVisualization() +{ + if (vis != nullptr) + { + VisToolCutArc *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(curveCutId); + visual->setLength(qApp->FormulaToUser(formula)); + visual->RefreshGeometry(); + } +} diff --git a/src/app/tools/drawTools/vtoolcutarc.h b/src/app/tools/drawTools/vtoolcutarc.h index 9af2b4a16..335e978fe 100644 --- a/src/app/tools/drawTools/vtoolcutarc.h +++ b/src/app/tools/drawTools/vtoolcutarc.h @@ -61,6 +61,7 @@ protected: PathDirection direction = PathDirection::Hide); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolCutArc) }; diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index e4f2690c5..36f3d8f17 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -201,21 +201,12 @@ void VToolCutSpline::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolCutSpline * visual = new VisToolCutSpline(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(curveCutId); - visual->setLength(qApp->FormulaToUser(formula)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolCutSpline * visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolCutSpline * visual = qobject_cast(vis)) { visual->show(); } @@ -247,14 +238,7 @@ void VToolCutSpline::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolCutSpline *visual = qobject_cast(vis); - visual->setPoint1Id(curveCutId); - visual->setLength(qApp->FormulaToUser(formula)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -341,3 +325,17 @@ void VToolCutSpline::ReadToolAttributes(const QDomElement &domElement) curveCutId = doc->GetParametrUInt(domElement, AttrSpline, NULL_ID_STR); lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSpline::SetVisualization() +{ + if (vis != nullptr) + { + VisToolCutSpline *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(curveCutId); + visual->setLength(qApp->FormulaToUser(formula)); + visual->RefreshGeometry(); + } +} diff --git a/src/app/tools/drawTools/vtoolcutspline.h b/src/app/tools/drawTools/vtoolcutspline.h index 9445ed33a..44c649618 100644 --- a/src/app/tools/drawTools/vtoolcutspline.h +++ b/src/app/tools/drawTools/vtoolcutspline.h @@ -63,6 +63,7 @@ protected: PathDirection direction = PathDirection::Hide); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolCutSpline) }; diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 211022387..a81f9c3eb 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -245,21 +245,12 @@ void VToolCutSplinePath::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(curveCutId); - visual->setLength(qApp->FormulaToUser(formula)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolCutSplinePath *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolCutSplinePath *visual = qobject_cast(vis)) { visual->show(); } @@ -291,14 +282,7 @@ void VToolCutSplinePath::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolCutSplinePath *visual = qobject_cast(vis); - visual->setPoint1Id(curveCutId); - visual->setLength(qApp->FormulaToUser(formula)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -387,3 +371,17 @@ void VToolCutSplinePath::ReadToolAttributes(const QDomElement &domElement) curveCutId = doc->GetParametrUInt(domElement, AttrSplinePath, NULL_ID_STR); lineColor = doc->GetParametrString(domElement, AttrColor, ColorBlack); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSplinePath::SetVisualization() +{ + if (vis != nullptr) + { + VisToolCutSplinePath *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(curveCutId); + visual->setLength(qApp->FormulaToUser(formula)); + visual->RefreshGeometry(); + } +} diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.h b/src/app/tools/drawTools/vtoolcutsplinepath.h index 859a81a29..e4cfa8a0a 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.h +++ b/src/app/tools/drawTools/vtoolcutsplinepath.h @@ -64,6 +64,7 @@ protected: PathDirection direction = PathDirection::Hide); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolCutSplinePath) }; diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index d69a26404..b5b9d11ae 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -189,16 +189,7 @@ void VToolEndLine::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolEndLine *visual = qobject_cast(vis); - visual->setPoint1Id(basePointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->SetAngle(qApp->FormulaToUser(formulaAngle)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -257,6 +248,22 @@ void VToolEndLine::ReadToolAttributes(const QDomElement &domElement) formulaAngle = doc->GetParametrString(domElement, AttrAngle, ""); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::SetVisualization() +{ + if (vis != nullptr) + { + VisToolEndLine *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(basePointId); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->SetAngle(qApp->FormulaToUser(formulaAngle)); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- VFormula VToolEndLine::GetFormulaAngle() const { @@ -286,23 +293,12 @@ void VToolEndLine::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolEndLine * visual = new VisToolEndLine(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(basePointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->SetAngle(qApp->FormulaToUser(formulaAngle)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolEndLine *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolEndLine *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index ec816f386..f778af214 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -64,6 +64,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: QString formulaAngle; }; diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index 84acc0609..12467fc75 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -197,16 +197,7 @@ void VToolHeight::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolHeight *visual = qobject_cast(vis); - visual->setPoint1Id(basePointId); - visual->setLineP1Id(p1LineId); - visual->setLineP2Id(p2LineId); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -265,6 +256,22 @@ void VToolHeight::ReadToolAttributes(const QDomElement &domElement) p2LineId = doc->GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::SetVisualization() +{ + if (vis != nullptr) + { + VisToolHeight *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(basePointId); + visual->setLineP1Id(p1LineId); + visual->setLineP2Id(p2LineId); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolHeight::GetP2LineId() const { @@ -290,23 +297,12 @@ void VToolHeight::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolHeight * visual = new VisToolHeight(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(basePointId); - visual->setLineP1Id(p1LineId); - visual->setLineP2Id(p2LineId); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolHeight *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolHeight *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolheight.h b/src/app/tools/drawTools/vtoolheight.h index 9a9f7d27d..f9ce54d5a 100644 --- a/src/app/tools/drawTools/vtoolheight.h +++ b/src/app/tools/drawTools/vtoolheight.h @@ -67,6 +67,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief p1LineId id first point of line. */ quint32 p1LineId; diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index 20fa07a60..55395dc54 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -195,15 +195,7 @@ void VToolLine::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolLine *visual = qobject_cast(vis); - visual->setPoint1Id(firstPoint); - visual->setPoint2Id(secondPoint); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -402,6 +394,21 @@ void VToolLine::ReadToolAttributes(const QDomElement &domElement) lineColor = doc->GetParametrString(domElement, AttrLineColor, ColorBlack); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::SetVisualization() +{ + if (vis != nullptr) + { + VisToolLine *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(firstPoint); + visual->setPoint2Id(secondPoint); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLine::GetSecondPoint() const { @@ -427,22 +434,12 @@ void VToolLine::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolLine * visual = new VisToolLine(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(firstPoint); - visual->setPoint2Id(secondPoint); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolLine *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolLine *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 8326d95cc..1c08b591e 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -80,6 +80,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief firstPoint id first line point. */ quint32 firstPoint; diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 10ce3e675..b3b2bc39b 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -195,16 +195,7 @@ void VToolLineIntersect::FullUpdateFromFile() { ReadAttributes(); RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); - - if (vis != nullptr) - { - VisToolLineIntersect *visual = qobject_cast(vis); - visual->setPoint1Id(p1Line1); - visual->setLine1P2Id(p2Line1); - visual->setLine2P1Id(p1Line2); - visual->setLine2P2Id(p2Line2); - vis->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -283,6 +274,22 @@ void VToolLineIntersect::ReadToolAttributes(const QDomElement &domElement) p2Line2 = doc->GetParametrUInt(domElement, AttrP2Line2, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::SetVisualization() +{ + if (vis != nullptr) + { + VisToolLineIntersect *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(p1Line1); + visual->setLine1P2Id(p2Line1); + visual->setLine2P1Id(p1Line2); + visual->setLine2P2Id(p2Line2); + vis->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLineIntersect::GetP2Line2() const { @@ -308,23 +315,12 @@ void VToolLineIntersect::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolLineIntersect * visual = new VisToolLineIntersect(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(p1Line1); - visual->setLine1P2Id(p2Line1); - visual->setLine2P1Id(p1Line2); - visual->setLine2P2Id(p2Line2); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolLineIntersect *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolLineIntersect *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoollineintersect.h b/src/app/tools/drawTools/vtoollineintersect.h index 62273cfbb..cb4e7fab2 100644 --- a/src/app/tools/drawTools/vtoollineintersect.h +++ b/src/app/tools/drawTools/vtoollineintersect.h @@ -73,6 +73,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief p1Line1 id first point first line. */ quint32 p1Line1; diff --git a/src/app/tools/drawTools/vtoollineintersectaxis.cpp b/src/app/tools/drawTools/vtoollineintersectaxis.cpp index a6ead89bc..4c333577e 100644 --- a/src/app/tools/drawTools/vtoollineintersectaxis.cpp +++ b/src/app/tools/drawTools/vtoollineintersectaxis.cpp @@ -238,24 +238,12 @@ void VToolLineIntersectAxis::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolLineIntersectAxis * visual = new VisToolLineIntersectAxis(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(firstPointId); - visual->setPoint2Id(secondPointId); - visual->setAxisPointId(basePointId); - visual->SetAngle(qApp->FormulaToUser(formulaAngle)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolLineIntersectAxis *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolLineIntersectAxis *visual = qobject_cast(vis)) { visual->show(); } @@ -273,17 +261,7 @@ void VToolLineIntersectAxis::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolLineIntersectAxis *visual = qobject_cast(vis); - visual->setPoint1Id(firstPointId); - visual->setPoint2Id(secondPointId); - visual->setAxisPointId(basePointId); - visual->SetAngle(qApp->FormulaToUser(formulaAngle)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -337,3 +315,20 @@ void VToolLineIntersectAxis::ReadToolAttributes(const QDomElement &domElement) secondPointId = doc->GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); formulaAngle = doc->GetParametrString(domElement, AttrAngle, ""); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersectAxis::SetVisualization() +{ + if (vis != nullptr) + { + VisToolLineIntersectAxis *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->setAxisPointId(basePointId); + visual->SetAngle(qApp->FormulaToUser(formulaAngle)); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} diff --git a/src/app/tools/drawTools/vtoollineintersectaxis.h b/src/app/tools/drawTools/vtoollineintersectaxis.h index 34f4e7a94..2b38959b0 100644 --- a/src/app/tools/drawTools/vtoollineintersectaxis.h +++ b/src/app/tools/drawTools/vtoollineintersectaxis.h @@ -73,6 +73,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolLineIntersectAxis) QString formulaAngle; diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 9b6f4e4e8..68d30e1e2 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -205,17 +205,7 @@ void VToolNormal::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolNormal *visual = qobject_cast(vis); - visual->setPoint1Id(basePointId); - visual->setPoint2Id(secondPointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->SetAngle(angle); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -298,6 +288,23 @@ void VToolNormal::ReadToolAttributes(const QDomElement &domElement) angle = doc->GetParametrDouble(domElement, AttrAngle, "0"); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::SetVisualization() +{ + if (vis != nullptr) + { + VisToolNormal *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->SetAngle(angle); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolNormal::GetSecondPointId() const { @@ -323,24 +330,12 @@ void VToolNormal::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolNormal * visual = new VisToolNormal(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(basePointId); - visual->setPoint2Id(secondPointId); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->SetAngle(angle); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolNormal *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolNormal *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index 815d65017..0ce27fddb 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -67,6 +67,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief secondPointId id second line point. */ quint32 secondPointId; diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 14bf954fc..4c6e6a1c5 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -248,16 +248,7 @@ void VToolPointOfContact::FullUpdateFromFile() { ReadAttributes(); RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); - - if (vis != nullptr) - { - VisToolPointOfContact *visual = qobject_cast(vis); - visual->setPoint1Id(firstPointId); - visual->setLineP2Id(secondPointId); - visual->setRadiusId(center); - visual->setRadius(qApp->FormulaToUser(arcRadius)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -335,6 +326,22 @@ void VToolPointOfContact::ReadToolAttributes(const QDomElement &domElement) secondPointId = doc->GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::SetVisualization() +{ + if (vis != nullptr) + { + VisToolPointOfContact *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(firstPointId); + visual->setLineP2Id(secondPointId); + visual->setRadiusId(center); + visual->setRadius(qApp->FormulaToUser(arcRadius)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolPointOfContact::GetSecondPointId() const { @@ -354,23 +361,12 @@ void VToolPointOfContact::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolPointOfContact * visual = new VisToolPointOfContact(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(firstPointId); - visual->setLineP2Id(secondPointId); - visual->setRadiusId(center); - visual->setRadius(qApp->FormulaToUser(arcRadius)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolPointOfContact *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolPointOfContact *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 0be23dadc..a0f423a72 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -78,6 +78,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief radius string with formula radius arc. */ QString arcRadius; diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 7ea98a311..1cfb3506e 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -167,14 +167,7 @@ void VToolPointOfIntersection::FullUpdateFromFile() { ReadAttributes(); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); - - if (vis != nullptr) - { - VisToolPointOfIntersection *visual = qobject_cast(vis); - visual->setPoint1Id(firstPointId); - visual->setPoint2Id(secondPointId); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -234,6 +227,20 @@ void VToolPointOfIntersection::ReadToolAttributes(const QDomElement &domElement) secondPointId = doc->GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::SetVisualization() +{ + if (vis != nullptr) + { + VisToolPointOfIntersection *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolPointOfIntersection::GetSecondPointId() const { @@ -259,21 +266,12 @@ void VToolPointOfIntersection::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolPointOfIntersection * visual = new VisToolPointOfIntersection(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(firstPointId); - visual->setPoint2Id(secondPointId); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolPointOfIntersection *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolPointOfIntersection *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index 9697550af..8dda21709 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -67,6 +67,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolPointOfIntersection) /** @brief firstPointId id first line point. */ diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 4537df002..e37d560f0 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -231,17 +231,7 @@ void VToolShoulderPoint::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); - - if (vis != nullptr) - { - VisToolShoulderPoint *visual = qobject_cast(vis); - visual->setPoint1Id(pShoulder); - visual->setLineP1Id(basePointId); - visual->setLineP2Id(p2Line); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -325,6 +315,23 @@ void VToolShoulderPoint::ReadToolAttributes(const QDomElement &domElement) pShoulder = doc->GetParametrUInt(domElement, AttrPShoulder, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::SetVisualization() +{ + if (vis != nullptr) + { + VisToolShoulderPoint *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(pShoulder); + visual->setLineP1Id(basePointId); + visual->setLineP2Id(p2Line); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction quint32 VToolShoulderPoint::getPShoulder() const @@ -352,24 +359,12 @@ void VToolShoulderPoint::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolShoulderPoint * visual = new VisToolShoulderPoint(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(pShoulder); - visual->setLineP1Id(basePointId); - visual->setLineP2Id(p2Line); - visual->setLength(qApp->FormulaToUser(formulaLength)); - visual->setLineStyle(VAbstractTool::LineStyleToPenStyle(typeLine)); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolShoulderPoint *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolShoulderPoint *visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index 2d24b9b32..bad156b66 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -71,6 +71,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: /** @brief p2Line id second line point. */ quint32 p2Line; diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index ffc611a00..76d189182 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -69,6 +69,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization() {} private: QString namePP; QString mPath; diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index cd04d94e5..d36e8e828 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -236,26 +236,12 @@ void VToolSpline::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolSpline *visual = new VisToolSpline(getData(), this); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - visual->setPoint1Id(spl->GetP1().id()); - visual->setPoint4Id(spl->GetP4().id()); - visual->SetAngle1(spl->GetAngle1()); - visual->SetAngle2(spl->GetAngle2()); - visual->SetKAsm1(spl->GetKasm1()); - visual->SetKAsm2(spl->GetKasm2()); - visual->SetKCurve(spl->GetKcurve()); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolSpline *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolSpline *visual = qobject_cast(vis)) { visual->show(); } @@ -490,6 +476,26 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) VAbstractSpline::hoverLeaveEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::SetVisualization() +{ + if (vis != nullptr) + { + VisToolSpline *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); + visual->setPoint1Id(spl->GetP1().id()); + visual->setPoint4Id(spl->GetP4().id()); + visual->SetAngle1(spl->GetAngle1()); + visual->SetAngle2(spl->GetAngle2()); + visual->SetKAsm1(spl->GetKasm1()); + visual->SetKAsm2(spl->GetKasm2()); + visual->SetKCurve(spl->GetKcurve()); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. @@ -523,16 +529,5 @@ void VToolSpline::RefreshGeometry() controlPoints[0]->blockSignals(false); controlPoints[1]->blockSignals(false); - if (vis != nullptr) - { - VisToolSpline *visual = qobject_cast(vis); - visual->setPoint1Id(spl->GetP1().id()); - visual->setPoint4Id(spl->GetP4().id()); - visual->SetAngle1(spl->GetAngle1()); - visual->SetAngle2(spl->GetAngle2()); - visual->SetKAsm1(spl->GetKasm1()); - visual->SetKAsm2(spl->GetKasm2()); - visual->SetKCurve(spl->GetKcurve()); - visual->RefreshGeometry(); - } + SetVisualization(); } diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index 39d2e67ab..e6684b8cb 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -69,6 +69,7 @@ protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolSpline) void RefreshGeometry (); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 9fd9947dd..b45a2a8d9 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -317,21 +317,12 @@ void VToolSplinePath::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolSplinePath *visual = new VisToolSplinePath(getData(), this); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - - QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); - visual->setPath(*splPath.data()); - visual->setMode(Mode::Show); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolSplinePath *visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolSplinePath *visual = qobject_cast(vis)) { visual->show(); } @@ -563,6 +554,21 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) VAbstractSpline::hoverLeaveEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::SetVisualization() +{ + if (vis != nullptr) + { + VisToolSplinePath *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + visual->setPath(*splPath.data()); + visual->setMode(Mode::Show); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. @@ -601,12 +607,5 @@ void VToolSplinePath::RefreshGeometry() controlPoints[j-1]->blockSignals(false); } - if (vis != nullptr) - { - VisToolSplinePath *visual = qobject_cast(vis); - QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); - visual->setPath(*splPath.data()); - visual->setMode(Mode::Show); - visual->RefreshGeometry(); - } + SetVisualization(); } diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index 268803eb8..0cddec8f3 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -86,6 +86,7 @@ protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void SetVisualization(); private: QPointF oldPosition; diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index 965d629c7..7b7579e7b 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -222,16 +222,7 @@ void VToolTriangle::FullUpdateFromFile() { ReadAttributes(); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); - - if (vis != nullptr) - { - VisToolTriangle * visual = qobject_cast(vis); - visual->setPoint1Id(axisP1Id); - visual->setPoint2Id(axisP2Id); - visual->setHypotenuseP1Id(firstPointId); - visual->setHypotenuseP2Id(secondPointId); - visual->RefreshGeometry(); - } + SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- @@ -299,6 +290,22 @@ void VToolTriangle::ReadToolAttributes(const QDomElement &domElement) secondPointId = doc->GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::SetVisualization() +{ + if (vis != nullptr) + { + VisToolTriangle * visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->setPoint1Id(axisP1Id); + visual->setPoint2Id(axisP2Id); + visual->setHypotenuseP1Id(firstPointId); + visual->setHypotenuseP2Id(secondPointId); + visual->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolTriangle::GetSecondPointId() const { @@ -324,23 +331,12 @@ void VToolTriangle::ShowVisualization(bool show) { if (vis == nullptr) { - VisToolTriangle * visual = new VisToolTriangle(getData()); - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); - scene->addItem(visual); - - visual->setPoint1Id(axisP1Id); - visual->setPoint2Id(axisP2Id); - visual->setHypotenuseP1Id(firstPointId); - visual->setHypotenuseP2Id(secondPointId); - visual->RefreshGeometry(); - vis = visual; + AddVisualization(); + SetVisualization(); } else { - VisToolTriangle * visual = qobject_cast(vis); - if (visual != nullptr) + if (VisToolTriangle * visual = qobject_cast(vis)) { visual->show(); } diff --git a/src/app/tools/drawTools/vtooltriangle.h b/src/app/tools/drawTools/vtooltriangle.h index 1f0779272..2524e3c37 100644 --- a/src/app/tools/drawTools/vtooltriangle.h +++ b/src/app/tools/drawTools/vtooltriangle.h @@ -75,6 +75,7 @@ protected: virtual void SaveDialog(QDomElement &domElement); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual void ReadToolAttributes(const QDomElement &domElement); + virtual void SetVisualization(); private: Q_DISABLE_COPY(VToolTriangle) /** @brief axisP1Id id first axis point. */ diff --git a/src/app/tools/nodeDetails/vabstractnode.h b/src/app/tools/nodeDetails/vabstractnode.h index 7c3ca0926..5cecb1233 100644 --- a/src/app/tools/nodeDetails/vabstractnode.h +++ b/src/app/tools/nodeDetails/vabstractnode.h @@ -63,6 +63,7 @@ protected: virtual void RemoveReferens(); virtual void RestoreReferens(); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); + virtual void SetVisualization() {} }; #endif // VABSTRACTNODE_H diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 962d87239..6ee96ee69 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -31,6 +31,9 @@ #include "vdatatool.h" #include "../xml/vpattern.h" +#include "../core/vapplication.h" +#include "../widgets/vmaingraphicsscene.h" +#include "../visualization/visualization.h" class QDomElement; class QLineF; @@ -166,6 +169,20 @@ protected: static int ConfirmDeletion(); void SaveOption(QSharedPointer &obj); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj)=0; + + template + void AddVisualization() + { + T *visual = new T(getData()); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr) + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + vis = visual; + } + + virtual void SetVisualization()=0; private: Q_DISABLE_COPY(VAbstractTool) }; diff --git a/src/app/tools/vtooldetail.h b/src/app/tools/vtooldetail.h index 62e4a1c38..db001138b 100644 --- a/src/app/tools/vtooldetail.h +++ b/src/app/tools/vtooldetail.h @@ -99,6 +99,7 @@ protected: virtual void RemoveReferens(); virtual void keyReleaseEvent(QKeyEvent * event); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); + virtual void SetVisualization() {} private: Q_DISABLE_COPY(VToolDetail) /** @brief dialog dialog options. */ diff --git a/src/app/tools/vtooluniondetails.h b/src/app/tools/vtooluniondetails.h index 3e40c7868..900eba391 100644 --- a/src/app/tools/vtooluniondetails.h +++ b/src/app/tools/vtooluniondetails.h @@ -87,6 +87,7 @@ protected: virtual void AddToFile(); virtual void RefreshDataInFile(); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); + virtual void SetVisualization() {} private: Q_DISABLE_COPY(VToolUnionDetails) /** @brief d1 first detail. */