From e7db934fb56e7687070434bd95df3395ca3f09d4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 18 Sep 2017 11:37:23 +0300 Subject: [PATCH] Refactor tool clases to pass data in structure. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 16 +- src/app/valentina/xml/vpattern.cpp | 1279 +++++++++-------- src/app/valentina/xml/vpattern.h | 8 +- .../operation/flipping/vabstractflipping.cpp | 77 +- .../operation/flipping/vabstractflipping.h | 5 +- .../flipping/vtoolflippingbyaxis.cpp | 67 +- .../operation/flipping/vtoolflippingbyaxis.h | 23 +- .../flipping/vtoolflippingbyline.cpp | 70 +- .../operation/flipping/vtoolflippingbyline.h | 24 +- .../operation/vabstractoperation.cpp | 11 +- .../drawTools/operation/vabstractoperation.h | 17 +- .../tools/drawTools/operation/vtoolmove.cpp | 139 +- .../tools/drawTools/operation/vtoolmove.h | 22 +- .../drawTools/operation/vtoolrotation.cpp | 136 +- .../tools/drawTools/operation/vtoolrotation.h | 22 +- .../drawTools/toolcurve/vabstractspline.h | 12 + .../tools/drawTools/toolcurve/vtoolarc.cpp | 95 +- .../tools/drawTools/toolcurve/vtoolarc.h | 23 +- .../toolcurve/vtoolarcwithlength.cpp | 79 +- .../drawTools/toolcurve/vtoolarcwithlength.h | 24 +- .../drawTools/toolcurve/vtoolcubicbezier.cpp | 60 +- .../drawTools/toolcurve/vtoolcubicbezier.h | 17 +- .../toolcurve/vtoolcubicbezierpath.cpp | 60 +- .../toolcurve/vtoolcubicbezierpath.h | 17 +- .../toolcurve/vtoolellipticalarc.cpp | 108 +- .../drawTools/toolcurve/vtoolellipticalarc.h | 29 +- .../tools/drawTools/toolcurve/vtoolspline.cpp | 96 +- .../tools/drawTools/toolcurve/vtoolspline.h | 34 +- .../drawTools/toolcurve/vtoolsplinepath.cpp | 96 +- .../drawTools/toolcurve/vtoolsplinepath.h | 33 +- .../tooldoublepoint/vtooltruedarts.cpp | 120 +- .../tooldoublepoint/vtooltruedarts.h | 59 +- .../toolsinglepoint/toolcut/vtoolcutarc.cpp | 92 +- .../toolsinglepoint/toolcut/vtoolcutarc.h | 20 +- .../toolcut/vtoolcutspline.cpp | 90 +- .../toolsinglepoint/toolcut/vtoolcutspline.h | 21 +- .../toolcut/vtoolcutsplinepath.cpp | 94 +- .../toolcut/vtoolcutsplinepath.h | 20 +- .../toollinepoint/vtoolalongline.cpp | 110 +- .../toollinepoint/vtoolalongline.h | 26 +- .../toollinepoint/vtoolbisector.cpp | 117 +- .../toollinepoint/vtoolbisector.h | 27 +- .../toollinepoint/vtoolcurveintersectaxis.cpp | 90 +- .../toollinepoint/vtoolcurveintersectaxis.h | 24 +- .../toollinepoint/vtoolendline.cpp | 105 +- .../toollinepoint/vtoolendline.h | 26 +- .../toollinepoint/vtoolheight.cpp | 116 +- .../toollinepoint/vtoolheight.h | 25 +- .../toollinepoint/vtoollineintersectaxis.cpp | 103 +- .../toollinepoint/vtoollineintersectaxis.h | 28 +- .../toollinepoint/vtoollinepoint.h | 12 + .../toollinepoint/vtoolnormal.cpp | 113 +- .../toollinepoint/vtoolnormal.h | 27 +- .../toollinepoint/vtoolshoulderpoint.cpp | 122 +- .../toollinepoint/vtoolshoulderpoint.h | 27 +- .../toolsinglepoint/vtoolbasepoint.cpp | 42 +- .../toolsinglepoint/vtoolbasepoint.h | 21 +- .../toolsinglepoint/vtoollineintersect.cpp | 127 +- .../toolsinglepoint/vtoollineintersect.h | 26 +- .../vtoolpointfromarcandtangent.cpp | 76 +- .../vtoolpointfromarcandtangent.h | 24 +- .../vtoolpointfromcircleandtangent.cpp | 89 +- .../vtoolpointfromcircleandtangent.h | 27 +- .../toolsinglepoint/vtoolpointofcontact.cpp | 118 +- .../toolsinglepoint/vtoolpointofcontact.h | 27 +- .../vtoolpointofintersection.cpp | 89 +- .../vtoolpointofintersection.h | 21 +- .../vtoolpointofintersectionarcs.cpp | 75 +- .../vtoolpointofintersectionarcs.h | 23 +- .../vtoolpointofintersectioncircles.cpp | 106 +- .../vtoolpointofintersectioncircles.h | 31 +- .../vtoolpointofintersectioncurves.cpp | 86 +- .../vtoolpointofintersectioncurves.h | 29 +- .../toolsinglepoint/vtoolsinglepoint.h | 16 + .../toolsinglepoint/vtooltriangle.cpp | 106 +- .../toolpoint/toolsinglepoint/vtooltriangle.h | 26 +- src/libs/vtools/tools/drawTools/vtoolline.cpp | 92 +- src/libs/vtools/tools/drawTools/vtoolline.h | 25 +- .../vtools/tools/nodeDetails/vabstractnode.h | 14 + .../vtools/tools/nodeDetails/vnodearc.cpp | 42 +- src/libs/vtools/tools/nodeDetails/vnodearc.h | 6 +- .../tools/nodeDetails/vnodeellipticalarc.cpp | 29 +- .../tools/nodeDetails/vnodeellipticalarc.h | 7 +- .../vtools/tools/nodeDetails/vnodepoint.cpp | 56 +- .../vtools/tools/nodeDetails/vnodepoint.h | 8 +- .../vtools/tools/nodeDetails/vnodespline.cpp | 43 +- .../vtools/tools/nodeDetails/vnodespline.h | 8 +- .../tools/nodeDetails/vnodesplinepath.cpp | 44 +- .../tools/nodeDetails/vnodesplinepath.h | 7 +- .../tools/nodeDetails/vtoolpiecepath.cpp | 66 +- .../vtools/tools/nodeDetails/vtoolpiecepath.h | 20 +- .../vtools/tools/nodeDetails/vtoolpin.cpp | 55 +- src/libs/vtools/tools/nodeDetails/vtoolpin.h | 18 +- src/libs/vtools/tools/vabstracttool.cpp | 30 +- src/libs/vtools/tools/vabstracttool.h | 20 + src/libs/vtools/tools/vtoolseamallowance.cpp | 88 +- src/libs/vtools/tools/vtoolseamallowance.h | 21 +- src/libs/vtools/tools/vtooluniondetails.cpp | 280 ++-- src/libs/vtools/tools/vtooluniondetails.h | 19 +- 99 files changed, 3365 insertions(+), 3131 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d1576778f..95c44e8f3 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -263,9 +263,19 @@ void MainWindow::AddPP(const QString &PPName) ui->view->itemClicked(nullptr);//hide options previous tool const QString label = doc->GenerateLabel(LabelType::NewPatternPiece); const QPointF startPosition = StartPositionNewPP(); - VPointF *point = new VPointF(startPosition.x(), startPosition.y(), label, 5, 10); - auto spoint = VToolBasePoint::Create(0, PPName, point, sceneDraw, doc, pattern, Document::FullParse, - Source::FromGui); + + VToolBasePointInitData initData; + initData.scene = sceneDraw; + initData.doc = doc; + initData.data = pattern; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + initData.x = startPosition.x(); + initData.y = startPosition.y(); + initData.name = label; + initData.nameActivPP = PPName; + + auto spoint = VToolBasePoint::Create(initData); ui->view->itemClicked(spoint); SetEnableTool(true); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 0d779a307..de6777e33 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -798,23 +798,24 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); try { - VPiece detail; - const quint32 id = GetParametrId(domElement); - detail.SetName(GetParametrString(domElement, AttrName, tr("Detail"))); - detail.SetMx(qApp->toPixel(GetParametrDouble(domElement, AttrMx, "0.0"))); - detail.SetMy(qApp->toPixel(GetParametrDouble(domElement, AttrMy, "0.0"))); - detail.SetSeamAllowance(GetParametrBool(domElement, VToolSeamAllowance::AttrSeamAllowance, falseStr)); - detail.SetHideMainPath(GetParametrBool(domElement, VToolSeamAllowance::AttrHideMainPath, + VToolSeamAllowanceInitData initData; + initData.id = GetParametrId(domElement); + initData.detail.SetName(GetParametrString(domElement, AttrName, tr("Detail"))); + initData.detail.SetMx(qApp->toPixel(GetParametrDouble(domElement, AttrMx, "0.0"))); + initData.detail.SetMy(qApp->toPixel(GetParametrDouble(domElement, AttrMy, "0.0"))); + initData.detail.SetSeamAllowance(GetParametrBool(domElement, VToolSeamAllowance::AttrSeamAllowance, falseStr)); + initData.detail.SetHideMainPath(GetParametrBool(domElement, VToolSeamAllowance::AttrHideMainPath, QString().setNum(qApp->ValentinaSettings()->IsHideMainPath()))); - detail.SetSeamAllowanceBuiltIn(GetParametrBool(domElement, VToolSeamAllowance::AttrSeamAllowanceBuiltIn, - falseStr)); - detail.SetForbidFlipping(GetParametrBool(domElement, VToolSeamAllowance::AttrForbidFlipping, + initData.detail.SetSeamAllowanceBuiltIn(GetParametrBool(domElement, + VToolSeamAllowance::AttrSeamAllowanceBuiltIn, + falseStr)); + initData.detail.SetForbidFlipping(GetParametrBool(domElement, VToolSeamAllowance::AttrForbidFlipping, QString().setNum(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping()))); - detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr)); - detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr)); + initData.detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr)); + initData.detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr)); - const QString width = GetParametrString(domElement, AttrWidth, "0.0"); - QString w = width;//need for saving fixed formula; + initData.width = GetParametrString(domElement, AttrWidth, "0.0"); + const QString w = initData.width;//need for saving fixed formula; const uint version = GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1"); const QStringList tags = QStringList() << TagNodes @@ -841,41 +842,48 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse "Time to refactor the code."); const bool closed = GetParametrUInt(domElement, AttrClosed, "1"); const qreal width = GetParametrDouble(domElement, AttrWidth, "0.0"); - ParseDetailNodes(element, detail, width, closed); + ParseDetailNodes(element, initData.detail, width, closed); } else { - detail.SetPath(ParsePieceNodes(element)); + initData.detail.SetPath(ParsePieceNodes(element)); } break; case 1:// TagData - ParsePieceDataTag(element, detail); + ParsePieceDataTag(element, initData.detail); break; case 2:// TagPatternInfo - ParsePiecePatternInfo(element, detail); + ParsePiecePatternInfo(element, initData.detail); break; case 3:// TagGrainline - ParsePieceGrainline(element, detail); + ParsePieceGrainline(element, initData.detail); break; case 4:// VToolSeamAllowance::TagCSA - detail.SetCustomSARecords(ParsePieceCSARecords(element)); + initData.detail.SetCustomSARecords(ParsePieceCSARecords(element)); break; case 5:// VToolSeamAllowance::TagIPaths - detail.SetInternalPaths(ParsePieceInternalPaths(element)); + initData.detail.SetInternalPaths(ParsePieceInternalPaths(element)); break; case 6:// VToolSeamAllowance::TagPins - detail.SetPins(ParsePiecePins(element)); + initData.detail.SetPins(ParsePiecePins(element)); break; default: break; } } } - VToolSeamAllowance::Create(id, detail, w, sceneDetail, this, data, parse, Source::FromFile); + + initData.scene = sceneDetail; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; + + VToolSeamAllowance::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (w != width) + if (w != initData.width) { - SetAttribute(domElement, AttrWidth, w); + SetAttribute(domElement, AttrWidth, initData.width); modified = true; haveLiteChange(); } @@ -987,21 +995,19 @@ void VPattern::ParseDetails(const QDomElement &domElement, const Document &parse } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx, qreal &my, - bool &labelVisible, QString &typeLine, QString &lineColor) +void VPattern::PointsWithLineCommonAttributes(const QDomElement &domElement, VToolLinePointInitData &initData) { - PointsCommonAttributes(domElement, id, name, mx, my, labelVisible); - typeLine = GetParametrString(domElement, AttrTypeLine, TypeLineLine); - lineColor = GetParametrString(domElement, AttrLineColor, ColorBlack); + PointsCommonAttributes(domElement, initData); + initData.typeLine = GetParametrString(domElement, AttrTypeLine, TypeLineLine); + initData.lineColor = GetParametrString(domElement, AttrLineColor, ColorBlack); } //--------------------------------------------------------------------------------------------------------------------- -void VPattern::PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx, qreal &my, - bool &labelVisible) +void VPattern::PointsCommonAttributes(const QDomElement &domElement, VToolSinglePointInitData &initData) { - PointsCommonAttributes(domElement, id, mx, my); - name = GetParametrString(domElement, AttrName, "A"); - labelVisible = GetParametrBool(domElement, AttrShowLabel, trueStr); + PointsCommonAttributes(domElement, initData.id, initData.mx, initData.my); + initData.name = GetParametrString(domElement, AttrName, "A"); + initData.showLabel = GetParametrBool(domElement, AttrShowLabel, trueStr); } //--------------------------------------------------------------------------------------------------------------------- @@ -1145,16 +1151,19 @@ void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &do Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); try { - quint32 id = 0; - ToolsCommonAttributes(domElement, id); - const quint32 firstPoint = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPoint = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - const QString typeLine = GetParametrString(domElement, AttrTypeLine, - TypeLineLine); - const QString lineColor = GetParametrString(domElement, AttrLineColor, - ColorBlack); + VToolLineInitData initData; + ToolsCommonAttributes(domElement, initData.id); + initData.firstPoint = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPoint = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + initData.typeLine = GetParametrString(domElement, AttrTypeLine, TypeLineLine); + initData.lineColor = GetParametrString(domElement, AttrLineColor, ColorBlack); + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - VToolLine::Create(id, firstPoint, secondPoint, typeLine, lineColor, scene, this, data, parse, Source::FromFile); + VToolLine::Create(initData); } catch (const VExceptionBadId &e) { @@ -1257,19 +1266,18 @@ void VPattern::ParseToolBasePoint(VMainGraphicsScene *scene, const QDomElement & VToolBasePoint *spoint = nullptr; try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolBasePointInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const qreal x = qApp->toPixel(GetParametrDouble(domElement, AttrX, "10.0")); - const qreal y = qApp->toPixel(GetParametrDouble(domElement, AttrY, "10.0")); + PointsCommonAttributes(domElement, initData); + initData.x = qApp->toPixel(GetParametrDouble(domElement, AttrX, "10.0")); + initData.y = qApp->toPixel(GetParametrDouble(domElement, AttrY, "10.0")); - VPointF *point = new VPointF(x, y, name, mx, my); - point->SetShowLabel(showLabel); - spoint = VToolBasePoint::Create(id, nameActivPP, point, scene, this, data, parse, Source::FromFile); + spoint = VToolBasePoint::Create(initData); } catch (const VExceptionBadId &e) { @@ -1289,31 +1297,29 @@ void VPattern::ParseToolEndLine(VMainGraphicsScene *scene, QDomElement &domEleme try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolEndLineInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); + PointsWithLineCommonAttributes(domElement, initData); - const QString formula = GetParametrString(domElement, AttrLength, "100.0"); - QString f = formula;//need for saving fixed formula; + initData.formulaLength = GetParametrString(domElement, AttrLength, "100.0"); + const QString f = initData.formulaLength;//need for saving fixed formula; - const quint32 basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); + initData.basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); - const QString angle = GetParametrString(domElement, AttrAngle, "0.0"); - QString angleFix = angle; + initData.formulaAngle = GetParametrString(domElement, AttrAngle, "0.0"); + const QString angleFix = initData.formulaAngle; - VToolEndLine::Create(id, name, typeLine, lineColor, f, angleFix, basePointId, mx, my, showLabel, scene, this, - data, parse, Source::FromFile); + VToolEndLine::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula || angleFix != angle) + if (f != initData.formulaLength || angleFix != initData.formulaAngle) { - SetAttribute(domElement, AttrLength, f); - SetAttribute(domElement, AttrAngle, angleFix); + SetAttribute(domElement, AttrLength, initData.formulaLength); + SetAttribute(domElement, AttrAngle, initData.formulaAngle); modified = true; haveLiteChange(); } @@ -1340,26 +1346,24 @@ void VPattern::ParseToolAlongLine(VMainGraphicsScene *scene, QDomElement &domEle try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolAlongLineInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); - const QString formula = GetParametrString(domElement, AttrLength, "100.0"); - QString f = formula;//need for saving fixed formula; - const quint32 firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + PointsWithLineCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "100.0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - VToolAlongLine::Create(id, name, typeLine, lineColor, f, firstPointId, secondPointId, mx, my, showLabel, scene, - this, data, parse, Source::FromFile); + VToolAlongLine::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1386,27 +1390,25 @@ void VPattern::ParseToolShoulderPoint(VMainGraphicsScene *scene, QDomElement &do try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolShoulderPointInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); - const QString formula = GetParametrString(domElement, AttrLength, "100.0"); - QString f = formula;//need for saving fixed formula; - const quint32 p1Line = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); - const quint32 p2Line = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); - const quint32 pShoulder = GetParametrUInt(domElement, AttrPShoulder, NULL_ID_STR); + PointsWithLineCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "100.0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.p1Line = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + initData.p2Line = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + initData.pShoulder = GetParametrUInt(domElement, AttrPShoulder, NULL_ID_STR); - VToolShoulderPoint::Create(id, f, p1Line, p2Line, pShoulder, typeLine, lineColor, name, mx, my, showLabel, - scene, this, data, parse, Source::FromFile); + VToolShoulderPoint::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1433,27 +1435,25 @@ void VPattern::ParseToolNormal(VMainGraphicsScene *scene, QDomElement &domElemen try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolNormalInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); - const QString formula = GetParametrString(domElement, AttrLength, "100.0"); - QString f = formula;//need for saving fixed formula; - const quint32 firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - const qreal angle = GetParametrDouble(domElement, AttrAngle, "0.0"); + PointsWithLineCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "100.0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + initData.angle = GetParametrDouble(domElement, AttrAngle, "0.0"); - VToolNormal::Create(id, f, firstPointId, secondPointId, typeLine, lineColor, name, angle, mx, my, showLabel, - scene, this, data, parse, Source::FromFile); + VToolNormal::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1480,27 +1480,25 @@ void VPattern::ParseToolBisector(VMainGraphicsScene *scene, QDomElement &domElem try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolBisectorInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); - const QString formula = GetParametrString(domElement, AttrLength, "100.0"); - QString f = formula;//need for saving fixed formula; - const quint32 firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - const quint32 thirdPointId = GetParametrUInt(domElement, AttrThirdPoint, NULL_ID_STR); + PointsWithLineCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "100.0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + initData.thirdPointId = GetParametrUInt(domElement, AttrThirdPoint, NULL_ID_STR); - VToolBisector::Create(id, f, firstPointId, secondPointId, thirdPointId, - typeLine, lineColor, name, mx, my, showLabel, scene, this, data, parse, Source::FromFile); + VToolBisector::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1527,20 +1525,20 @@ void VPattern::ParseToolLineIntersect(VMainGraphicsScene *scene, const QDomEleme try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolLineIntersectInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 p1Line1Id = GetParametrUInt(domElement, AttrP1Line1, NULL_ID_STR); - const quint32 p2Line1Id = GetParametrUInt(domElement, AttrP2Line1, NULL_ID_STR); - const quint32 p1Line2Id = GetParametrUInt(domElement, AttrP1Line2, NULL_ID_STR); - const quint32 p2Line2Id = GetParametrUInt(domElement, AttrP2Line2, NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.p1Line1Id = GetParametrUInt(domElement, AttrP1Line1, NULL_ID_STR); + initData.p2Line1Id = GetParametrUInt(domElement, AttrP2Line1, NULL_ID_STR); + initData.p1Line2Id = GetParametrUInt(domElement, AttrP1Line2, NULL_ID_STR); + initData.p2Line2Id = GetParametrUInt(domElement, AttrP2Line2, NULL_ID_STR); - VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, - mx, my, showLabel, scene, this, data, parse, Source::FromFile); + VToolLineIntersect::Create(initData); } catch (const VExceptionBadId &e) { @@ -1558,25 +1556,25 @@ void VPattern::ParseToolPointOfContact(VMainGraphicsScene *scene, QDomElement &d try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointOfContactInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const QString radius = GetParametrString(domElement, AttrRadius, "0"); - QString f = radius;//need for saving fixed formula; - const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - const quint32 firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.radius = GetParametrString(domElement, AttrRadius, "0"); + const QString f = initData.radius;//need for saving fixed formula; + initData.center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + initData.firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - VToolPointOfContact::Create(id, f, center, firstPointId, secondPointId, name, mx, my, showLabel, scene, this, - data, parse, Source::FromFile); + VToolPointOfContact::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != radius) + if (f != initData.radius) { - SetAttribute(domElement, AttrRadius, f); + SetAttribute(domElement, AttrRadius, initData.radius); modified = true; haveLiteChange(); } @@ -1602,26 +1600,33 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par try { - quint32 id = 0; + VAbstractNodeInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; + initData.scene = sceneDetail; + qreal mx = 0; qreal my = 0; - PointsCommonAttributes(domElement, id, mx, my); - const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); - const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + PointsCommonAttributes(domElement, initData.id, mx, my); + initData.idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); QSharedPointer point; try { - point = data->GeometricObject(idObject); + point = initData.data->GeometricObject(initData.idObject); } catch (const VExceptionBadId &e) { // Possible case. Parent was deleted, but the node object is still here. Q_UNUSED(e) return;// Just ignore } - data->UpdateGObject(id, new VPointF(static_cast(*point), point->name(), mx, my, idObject, - Draw::Modeling)); - VNodePoint::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, "", idTool); + initData.data->UpdateGObject(initData.id, + new VPointF(static_cast(*point), point->name(), mx, my, initData.idObject, + Draw::Modeling)); + VNodePoint::Create(initData); } catch (const VExceptionBadId &e) { @@ -1638,12 +1643,16 @@ void VPattern::ParsePinPoint(const QDomElement &domElement, const Document &pars try { - quint32 id = 0; + VToolPinInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); - const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); - VToolPin::Create(id, idObject, NULL_ID, this, data, parse, Source::FromFile, "", idTool); + ToolsCommonAttributes(domElement, initData.id); + initData.pointId = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + VToolPin::Create(initData); } catch (const VExceptionBadId &e) { @@ -1661,21 +1670,19 @@ void VPattern::ParseToolHeight(VMainGraphicsScene *scene, const QDomElement &dom try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolHeightInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); - const quint32 basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); - const quint32 p1LineId = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); - const quint32 p2LineId = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + PointsWithLineCommonAttributes(domElement, initData); + initData.basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); + initData.p1LineId = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + initData.p2LineId = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); - VToolHeight::Create(id, name, typeLine, lineColor, basePointId, p1LineId, p2LineId, - mx, my, showLabel, scene, this, data, parse, Source::FromFile); + VToolHeight::Create(initData); } catch (const VExceptionBadId &e) { @@ -1693,20 +1700,20 @@ void VPattern::ParseToolTriangle(VMainGraphicsScene *scene, const QDomElement &d try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolTriangleInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 axisP1Id = GetParametrUInt(domElement, AttrAxisP1, NULL_ID_STR); - const quint32 axisP2Id = GetParametrUInt(domElement, AttrAxisP2, NULL_ID_STR); - const quint32 firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.axisP1Id = GetParametrUInt(domElement, AttrAxisP1, NULL_ID_STR); + initData.axisP2Id = GetParametrUInt(domElement, AttrAxisP2, NULL_ID_STR); + initData.firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, showLabel, scene, this, - data, parse, Source::FromFile); + VToolTriangle::Create(initData); } catch (const VExceptionBadId &e) { @@ -1725,18 +1732,18 @@ void VPattern::ParseToolPointOfIntersection(VMainGraphicsScene *scene, const QDo try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointOfIntersectionInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.firstPointId = GetParametrUInt(domElement, AttrFirstPoint, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrSecondPoint, NULL_ID_STR); - VToolPointOfIntersection::Create(id, name, firstPointId, secondPointId, mx, my, showLabel, scene, this, data, - parse, Source::FromFile); + VToolPointOfIntersection::Create(initData); } catch (const VExceptionBadId &e) { @@ -1754,22 +1761,23 @@ void VPattern::ParseToolCutSpline(VMainGraphicsScene *scene, QDomElement &domEle try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolCutSplineInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const QString formula = GetParametrString(domElement, AttrLength, "0"); - QString f = formula;//need for saving fixed formula; - const quint32 splineId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.splineId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, NULL_ID_STR); - VToolCutSpline::Create(id, name, f, splineId, mx, my, showLabel, scene, this, data, parse, Source::FromFile); + VToolCutSpline::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1796,24 +1804,23 @@ void VPattern::ParseToolCutSplinePath(VMainGraphicsScene *scene, QDomElement &do try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolCutSplinePathInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const QString formula = GetParametrString(domElement, AttrLength, "0"); - QString f = formula;//need for saving fixed formula; - const quint32 splinePathId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, - NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.splinePathId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, NULL_ID_STR); - VToolCutSplinePath::Create(id, name, f, splinePathId, mx, my, showLabel, scene, this, data, parse, - Source::FromFile); + VToolCutSplinePath::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1840,22 +1847,23 @@ void VPattern::ParseToolCutArc(VMainGraphicsScene *scene, QDomElement &domElemen try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolCutArcInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const QString formula = GetParametrString(domElement, AttrLength, "0"); - QString f = formula;//need for saving fixed formula; - const quint32 arcId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); + PointsCommonAttributes(domElement, initData); + initData.formula = GetParametrString(domElement, AttrLength, "0"); + const QString f = initData.formula;//need for saving fixed formula; + initData.arcId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); - VToolCutArc::Create(id, name, f, arcId, mx, my, showLabel, scene, this, data, parse, Source::FromFile); + VToolCutArc::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != initData.formula) { - SetAttribute(domElement, AttrLength, f); + SetAttribute(domElement, AttrLength, initData.formula); modified = true; haveLiteChange(); } @@ -1883,29 +1891,27 @@ void VPattern::ParseToolLineIntersectAxis(VMainGraphicsScene *scene, QDomElement try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolLineIntersectAxisInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); + PointsWithLineCommonAttributes(domElement, initData); - const quint32 basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); - const quint32 firstPointId = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); - const quint32 secondPointId = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + initData.basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); + initData.firstPointId = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + initData.secondPointId = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); - const QString angle = GetParametrString(domElement, AttrAngle, "0.0"); - QString angleFix = angle; + initData.formulaAngle = GetParametrString(domElement, AttrAngle, "0.0"); + const QString angleFix = initData.formulaAngle; - VToolLineIntersectAxis::Create(id, name, typeLine, lineColor, angleFix, basePointId, firstPointId, - secondPointId, mx, my, showLabel, scene, this, data, parse, Source::FromFile); + VToolLineIntersectAxis::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (angleFix != angle) + if (angleFix != initData.formulaAngle) { - SetAttribute(domElement, AttrAngle, angleFix); + SetAttribute(domElement, AttrAngle, initData.formulaAngle); modified = true; haveLiteChange(); } @@ -1935,27 +1941,25 @@ void VPattern::ParseToolCurveIntersectAxis(VMainGraphicsScene *scene, QDomElemen try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - QString typeLine; - QString lineColor; - bool showLabel = true; + VToolCurveIntersectAxisInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel, typeLine, lineColor); + PointsWithLineCommonAttributes(domElement, initData); - const quint32 basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); - const quint32 curveId = GetParametrUInt(domElement, AttrCurve, NULL_ID_STR); - const QString angle = GetParametrString(domElement, AttrAngle, "0.0"); - QString angleFix = angle; + initData.basePointId = GetParametrUInt(domElement, AttrBasePoint, NULL_ID_STR); + initData.curveId = GetParametrUInt(domElement, AttrCurve, NULL_ID_STR); + initData.formulaAngle = GetParametrString(domElement, AttrAngle, "0.0"); + const QString angleFix = initData.formulaAngle; - VToolCurveIntersectAxis::Create(id, name, typeLine, lineColor, angleFix, basePointId, curveId, mx, my, - showLabel, scene, this, data, parse, Source::FromFile); + VToolCurveIntersectAxis::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (angleFix != angle) + if (angleFix != initData.formulaAngle) { - SetAttribute(domElement, AttrAngle, angleFix); + SetAttribute(domElement, AttrAngle, initData.formulaAngle); modified = true; haveLiteChange(); } @@ -1985,21 +1989,19 @@ void VPattern::ParseToolPointOfIntersectionArcs(VMainGraphicsScene *scene, const try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointOfIntersectionArcsInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 firstArcId = GetParametrUInt(domElement, AttrFirstArc, NULL_ID_STR); - const quint32 secondArcId = GetParametrUInt(domElement, AttrSecondArc, NULL_ID_STR); - const CrossCirclesPoint crossPoint = static_cast(GetParametrUInt(domElement, - AttrCrossPoint, - "1")); + PointsCommonAttributes(domElement, initData); + initData.firstArcId = GetParametrUInt(domElement, AttrFirstArc, NULL_ID_STR); + initData.secondArcId = GetParametrUInt(domElement, AttrSecondArc, NULL_ID_STR); + initData.pType = static_cast(GetParametrUInt(domElement, AttrCrossPoint, "1")); - VToolPointOfIntersectionArcs::Create(id, name, firstArcId, secondArcId, crossPoint, mx, my, showLabel, scene, - this, data, parse, Source::FromFile); + VToolPointOfIntersectionArcs::Create(initData); } catch (const VExceptionBadId &e) { @@ -2018,29 +2020,28 @@ void VPattern::ParseToolPointOfIntersectionCircles(VMainGraphicsScene *scene, QD try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointOfIntersectionCirclesInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 c1CenterId = GetParametrUInt(domElement, AttrC1Center, NULL_ID_STR); - const quint32 c2CenterId = GetParametrUInt(domElement, AttrC2Center, NULL_ID_STR); - const QString c1Radius = GetParametrString(domElement, AttrC1Radius); - QString c1R = c1Radius; - const QString c2Radius = GetParametrString(domElement, AttrC2Radius); - QString c2R = c2Radius; - const CrossCirclesPoint crossPoint = static_cast(GetParametrUInt(domElement, - AttrCrossPoint, "1")); + PointsCommonAttributes(domElement, initData); + initData.firstCircleCenterId = GetParametrUInt(domElement, AttrC1Center, NULL_ID_STR); + initData.secondCircleCenterId = GetParametrUInt(domElement, AttrC2Center, NULL_ID_STR); + initData.firstCircleRadius = GetParametrString(domElement, AttrC1Radius); + const QString c1R = initData.firstCircleRadius; + initData.secondCircleRadius = GetParametrString(domElement, AttrC2Radius); + const QString c2R = initData.secondCircleRadius; + initData.crossPoint = static_cast(GetParametrUInt(domElement, AttrCrossPoint, "1")); - VToolPointOfIntersectionCircles::Create(id, name, c1CenterId, c2CenterId, c1R, c2R, crossPoint, mx, my, - showLabel, scene, this, data, parse, Source::FromFile); + VToolPointOfIntersectionCircles::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (c1R != c1Radius || c2R != c2Radius) + if (c1R != initData.firstCircleRadius || c2R != initData.secondCircleRadius) { - SetAttribute(domElement, AttrC1Center, c1R); - SetAttribute(domElement, AttrC2Center, c2R); + SetAttribute(domElement, AttrC1Center, initData.firstCircleRadius); + SetAttribute(domElement, AttrC2Center, initData.secondCircleRadius); modified = true; haveLiteChange(); } @@ -2062,20 +2063,20 @@ void VPattern::ParseToolPointOfIntersectionCurves(VMainGraphicsScene *scene, QDo try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointOfIntersectionCurvesInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const auto curve1Id = GetParametrUInt(domElement, AttrCurve1, NULL_ID_STR); - const auto curve2Id = GetParametrUInt(domElement, AttrCurve2, NULL_ID_STR); - const auto vCrossPoint = static_cast(GetParametrUInt(domElement, AttrVCrossPoint, "1")); - const auto hCrossPoint = static_cast(GetParametrUInt(domElement, AttrHCrossPoint, "1")); + PointsCommonAttributes(domElement, initData); + initData.firstCurveId = GetParametrUInt(domElement, AttrCurve1, NULL_ID_STR); + initData.secondCurveId = GetParametrUInt(domElement, AttrCurve2, NULL_ID_STR); + initData.vCrossPoint = static_cast(GetParametrUInt(domElement, AttrVCrossPoint, "1")); + initData.hCrossPoint = static_cast(GetParametrUInt(domElement, AttrHCrossPoint, "1")); - VToolPointOfIntersectionCurves::Create(id, name, curve1Id, curve2Id, vCrossPoint, hCrossPoint, mx, my, - showLabel, scene, this, data, parse, Source::FromFile); + VToolPointOfIntersectionCurves::Create(initData); } catch (const VExceptionBadId &e) { @@ -2094,27 +2095,25 @@ void VPattern::ParseToolPointFromCircleAndTangent(VMainGraphicsScene *scene, QDo try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointFromCircleAndTangentInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 cCenterId = GetParametrUInt(domElement, AttrCCenter, NULL_ID_STR); - const quint32 tangentId = GetParametrUInt(domElement, AttrTangent, NULL_ID_STR); - const QString cRadius = GetParametrString(domElement, AttrCRadius); - QString cR = cRadius; - const CrossCirclesPoint crossPoint = static_cast(GetParametrUInt(domElement, - AttrCrossPoint, - "1")); + PointsCommonAttributes(domElement, initData); + initData.circleCenterId = GetParametrUInt(domElement, AttrCCenter, NULL_ID_STR); + initData.tangentPointId = GetParametrUInt(domElement, AttrTangent, NULL_ID_STR); + initData.circleRadius = GetParametrString(domElement, AttrCRadius); + const QString cR = initData.circleRadius; + initData.crossPoint = static_cast(GetParametrUInt(domElement, AttrCrossPoint, "1")); - VToolPointFromCircleAndTangent::Create(id, name, cCenterId, cR, tangentId, crossPoint, mx, my, showLabel, - scene, this, data, parse, Source::FromFile); + VToolPointFromCircleAndTangent::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (cR != cRadius) + if (cR != initData.circleRadius) { - SetAttribute(domElement, AttrCCenter, cR); + SetAttribute(domElement, AttrCCenter, initData.circleRadius); modified = true; haveLiteChange(); } @@ -2136,21 +2135,19 @@ void VPattern::ParseToolPointFromArcAndTangent(VMainGraphicsScene *scene, const try { - quint32 id = 0; - QString name; - qreal mx = 0; - qreal my = 0; - bool showLabel = true; + VToolPointFromArcAndTangentInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - PointsCommonAttributes(domElement, id, name, mx, my, showLabel); - const quint32 arcId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); - const quint32 tangentId = GetParametrUInt(domElement, AttrTangent, NULL_ID_STR); - const CrossCirclesPoint crossPoint = static_cast(GetParametrUInt(domElement, - AttrCrossPoint, - "1")); + PointsCommonAttributes(domElement, initData); + initData.arcId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); + initData.tangentPointId = GetParametrUInt(domElement, AttrTangent, NULL_ID_STR); + initData.crossPoint = static_cast(GetParametrUInt(domElement, AttrCrossPoint, "1")); - VToolPointFromArcAndTangent::Create(id, name, arcId, tangentId, crossPoint, mx, my, showLabel, - scene, this, data, parse, Source::FromFile); + VToolPointFromArcAndTangent::Create(initData); } catch (const VExceptionBadId &e) { @@ -2168,31 +2165,33 @@ void VPattern::ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement & try { - quint32 id = 0; + VToolTrueDartsInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); + ToolsCommonAttributes(domElement, initData.id); - const quint32 p1Id = GetParametrUInt(domElement, AttrPoint1, NULL_ID_STR); - const quint32 p2Id = GetParametrUInt(domElement, AttrPoint2, NULL_ID_STR); + initData.p1id = GetParametrUInt(domElement, AttrPoint1, NULL_ID_STR); + initData.p2id = GetParametrUInt(domElement, AttrPoint2, NULL_ID_STR); - const quint32 baseLineP1Id = GetParametrUInt(domElement, AttrBaseLineP1, NULL_ID_STR); - const quint32 baseLineP2Id = GetParametrUInt(domElement, AttrBaseLineP2, NULL_ID_STR); - const quint32 dartP1Id = GetParametrUInt(domElement, AttrDartP1, NULL_ID_STR); - const quint32 dartP2Id = GetParametrUInt(domElement, AttrDartP2, NULL_ID_STR); - const quint32 dartP3Id = GetParametrUInt(domElement, AttrDartP3, NULL_ID_STR); + initData.baseLineP1Id = GetParametrUInt(domElement, AttrBaseLineP1, NULL_ID_STR); + initData.baseLineP2Id = GetParametrUInt(domElement, AttrBaseLineP2, NULL_ID_STR); + initData.dartP1Id = GetParametrUInt(domElement, AttrDartP1, NULL_ID_STR); + initData.dartP2Id = GetParametrUInt(domElement, AttrDartP2, NULL_ID_STR); + initData.dartP3Id = GetParametrUInt(domElement, AttrDartP3, NULL_ID_STR); - const QString name1 = GetParametrString(domElement, AttrName1, "A"); - const qreal mx1 = qApp->toPixel(GetParametrDouble(domElement, AttrMx1, "10.0")); - const qreal my1 = qApp->toPixel(GetParametrDouble(domElement, AttrMy1, "15.0")); + initData.name1 = GetParametrString(domElement, AttrName1, "A"); + initData.mx1 = qApp->toPixel(GetParametrDouble(domElement, AttrMx1, "10.0")); + initData.my1 = qApp->toPixel(GetParametrDouble(domElement, AttrMy1, "15.0")); - const QString name2 = GetParametrString(domElement, AttrName2, "A"); - const qreal mx2 = qApp->toPixel(GetParametrDouble(domElement, AttrMx2, "10.0")); - const qreal my2 = qApp->toPixel(GetParametrDouble(domElement, AttrMy2, "15.0")); + initData.name2 = GetParametrString(domElement, AttrName2, "A"); + initData.mx2 = qApp->toPixel(GetParametrDouble(domElement, AttrMx2, "10.0")); + initData.my2 = qApp->toPixel(GetParametrDouble(domElement, AttrMy2, "15.0")); - VToolTrueDarts::Create(id, p1Id, p2Id, - baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id, - name1, mx1, my1, name2, mx2, my2, - scene, this, data, parse, Source::FromFile); + VToolTrueDarts::Create(initData); } catch (const VExceptionBadId &e) { @@ -2211,9 +2210,14 @@ void VPattern::ParseOldToolSpline(VMainGraphicsScene *scene, const QDomElement & try { - quint32 id = 0; + VToolSplineInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); + ToolsCommonAttributes(domElement, initData.id); const quint32 point1 = GetParametrUInt(domElement, AttrPoint1, NULL_ID_STR); const quint32 point4 = GetParametrUInt(domElement, AttrPoint4, NULL_ID_STR); const qreal angle1 = GetParametrDouble(domElement, AttrAngle1, "270.0"); @@ -2234,7 +2238,7 @@ void VPattern::ParseOldToolSpline(VMainGraphicsScene *scene, const QDomElement & } spline->SetColor(color); - VToolSpline::Create(id, spline, scene, this, data, parse, Source::FromFile); + VToolSpline::Create(initData, spline); } catch (const VExceptionBadId &e) { @@ -2252,30 +2256,34 @@ void VPattern::ParseToolSpline(VMainGraphicsScene *scene, QDomElement &domElemen try { - quint32 id = 0; + VToolSplineInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 point1 = GetParametrUInt(domElement, AttrPoint1, NULL_ID_STR); - const quint32 point4 = GetParametrUInt(domElement, AttrPoint4, NULL_ID_STR); + ToolsCommonAttributes(domElement, initData.id); + initData.point1 = GetParametrUInt(domElement, AttrPoint1, NULL_ID_STR); + initData.point4 = GetParametrUInt(domElement, AttrPoint4, NULL_ID_STR); - const QString angle1 = GetParametrString(domElement, AttrAngle1, "0"); - QString a1 = angle1;//need for saving fixed formula; + initData.a1 = GetParametrString(domElement, AttrAngle1, "0"); + const QString angle1 = initData.a1;//need for saving fixed formula; - const QString angle2 = GetParametrString(domElement, AttrAngle2, "0"); - QString a2 = angle2;//need for saving fixed formula; + initData.a2 = GetParametrString(domElement, AttrAngle2, "0"); + const QString angle2 = initData.a2;//need for saving fixed formula; - const QString length1 = GetParametrString(domElement, AttrLength1, "0"); - QString l1 = length1;//need for saving fixed formula; + initData.l1 = GetParametrString(domElement, AttrLength1, "0"); + const QString length1 = initData.l1;//need for saving fixed formula; - const QString length2 = GetParametrString(domElement, AttrLength2, "0"); - QString l2 = length2;//need for saving fixed formula; + initData.l2 = GetParametrString(domElement, AttrLength2, "0"); + const QString length2 = initData.l2;//need for saving fixed formula; - const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); - const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); + initData.color = GetParametrString(domElement, AttrColor, ColorBlack); + initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); + initData.duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); - VToolSpline *spl = VToolSpline::Create(id, point1, point4, a1, a2, l1, l2, duplicate, color, penStyle, scene, - this, data, parse, Source::FromFile); + VToolSpline *spl = VToolSpline::Create(initData); if (spl != nullptr) { @@ -2285,12 +2293,12 @@ void VPattern::ParseToolSpline(VMainGraphicsScene *scene, QDomElement &domElemen } //Rewrite attribute formula. Need for situation when we have wrong formula. - if (a1 != angle1 || a2 != angle2 || l1 != length1 || l2 != length2) + if (angle1 != initData.a1 || angle2 != initData.a2 || length1 != initData.l1 || length2 != initData.l2) { - SetAttribute(domElement, AttrAngle1, a1); - SetAttribute(domElement, AttrAngle2, a2); - SetAttribute(domElement, AttrLength1, l1); - SetAttribute(domElement, AttrLength2, l2); + SetAttribute(domElement, AttrAngle1, initData.a1); + SetAttribute(domElement, AttrAngle2, initData.a2); + SetAttribute(domElement, AttrLength1, initData.l1); + SetAttribute(domElement, AttrLength2, initData.l2); modified = true; haveLiteChange(); } @@ -2317,9 +2325,15 @@ void VPattern::ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement try { - quint32 id = 0; + VToolCubicBezierInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; + + ToolsCommonAttributes(domElement, initData.id); - ToolsCommonAttributes(domElement, id); const quint32 point1 = GetParametrUInt(domElement, AttrPoint1, NULL_ID_STR); const quint32 point2 = GetParametrUInt(domElement, AttrPoint2, NULL_ID_STR); const quint32 point3 = GetParametrUInt(domElement, AttrPoint3, NULL_ID_STR); @@ -2334,15 +2348,15 @@ void VPattern::ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement auto p3 = data->GeometricObject(point3); auto p4 = data->GeometricObject(point4); - VCubicBezier *spline = new VCubicBezier(*p1, *p2, *p3, *p4); + initData.spline = new VCubicBezier(*p1, *p2, *p3, *p4); if (duplicate > 0) { - spline->SetDuplicate(duplicate); + initData.spline->SetDuplicate(duplicate); } - spline->SetColor(color); - spline->SetPenStyle(penStyle); + initData.spline->SetColor(color); + initData.spline->SetPenStyle(penStyle); - VToolCubicBezier::Create(id, spline, scene, this, data, parse, Source::FromFile); + VToolCubicBezier::Create(initData); } catch (const VExceptionBadId &e) { @@ -2360,9 +2374,14 @@ void VPattern::ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomEleme try { - quint32 id = 0; + VToolSplinePathInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); + ToolsCommonAttributes(domElement, initData.id); const qreal kCurve = GetParametrDouble(domElement, AttrKCurve, "1.0"); const QString color = GetParametrString(domElement, AttrColor, ColorBlack); const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); @@ -2404,7 +2423,7 @@ void VPattern::ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomEleme } path->SetColor(color); - VToolSplinePath::Create(id, path, scene, this, data, parse, Source::FromFile); + VToolSplinePath::Create(initData, path); } catch (const VExceptionBadId &e) { @@ -2422,18 +2441,17 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement try { - quint32 id = 0; + VToolSplinePathInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); - const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); - - QVector points; - QVector angle1, a1; - QVector angle2, a2; - QVector length1, l1; - QVector length2, l2; + ToolsCommonAttributes(domElement, initData.id); + initData.color = GetParametrString(domElement, AttrColor, ColorBlack); + initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); + initData.duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); const QDomNodeList nodeList = domElement.childNodes(); const qint32 num = nodeList.size(); @@ -2442,12 +2460,12 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement const QDomElement element = nodeList.at(i).toElement(); if (not element.isNull() && element.tagName() == AttrPathPoint) { - angle1.append(GetParametrString(element, AttrAngle1, "0")); - angle2.append(GetParametrString(element, AttrAngle2, "0")); - length1.append(GetParametrString(element, AttrLength1, "0")); - length2.append(GetParametrString(element, AttrLength2, "0")); + initData.a1.append(GetParametrString(element, AttrAngle1, "0")); + initData.a2.append(GetParametrString(element, AttrAngle2, "0")); + initData.l1.append(GetParametrString(element, AttrLength1, "0")); + initData.l2.append(GetParametrString(element, AttrLength2, "0")); const quint32 pSpline = GetParametrUInt(element, AttrPSpline, NULL_ID_STR); - points.append(pSpline); + initData.points.append(pSpline); if (parse == Document::FullParse) { @@ -2457,13 +2475,12 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement } //need for saving fixed formula; - a1 = angle1; - a2 = angle2; - l1 = length1; - l2 = length2; + const QVector angle1 = initData.a1; + const QVector angle2 = initData.a2; + const QVector length1 = initData.l1; + const QVector length2 = initData.l2; - VToolSplinePath *spl = VToolSplinePath::Create(id, points, a1, a2, l1, l2, color, penStyle, duplicate, scene, - this, data, parse, Source::FromFile); + VToolSplinePath *spl = VToolSplinePath::Create(initData); if (spl != nullptr) { @@ -2479,13 +2496,13 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement QDomElement element = nodeList.at(i).toElement(); if (not element.isNull() && element.tagName() == AttrPathPoint) { - if (a1.at(count) != angle1.at(count) || a2.at(count) != angle2.at(count) || - l1.at(count) != length1.at(count) || l2.at(count) != length2.at(count)) + if (angle1.at(count) != initData.a1.at(count) || angle2.at(count) != initData.a2.at(count) || + length1.at(count) != initData.l1.at(count) || length2.at(count) != initData.l2.at(count)) { - SetAttribute(element, AttrAngle1, a1.at(count)); - SetAttribute(element, AttrAngle2, a2.at(count)); - SetAttribute(element, AttrLength1, l1.at(count)); - SetAttribute(element, AttrLength2, l2.at(count)); + SetAttribute(element, AttrAngle1, initData.a1.at(count)); + SetAttribute(element, AttrAngle2, initData.a2.at(count)); + SetAttribute(element, AttrLength1, initData.l1.at(count)); + SetAttribute(element, AttrLength2, initData.l2.at(count)); modified = true; haveLiteChange(); } @@ -2515,9 +2532,14 @@ void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomEle try { - quint32 id = 0; + VToolCubicBezierPathInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); + ToolsCommonAttributes(domElement, initData.id); const QString color = GetParametrString(domElement, AttrColor, ColorBlack); const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, "0"); @@ -2544,15 +2566,15 @@ void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomEle } } - auto path = new VCubicBezierPath(points); + initData.path = new VCubicBezierPath(points); if (duplicate > 0) { - path->SetDuplicate(duplicate); + initData.path->SetDuplicate(duplicate); } - path->SetColor(color); - path->SetPenStyle(penStyle); + initData.path->SetColor(color); + initData.path->SetPenStyle(penStyle); - VToolCubicBezierPath::Create(id, path, scene, this, data, parse, Source::FromFile); + VToolCubicBezierPath::Create(initData); } catch (const VExceptionBadId &e) { @@ -2569,27 +2591,29 @@ void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &pa try { - quint32 id = 0; - quint32 idObject = 0; - quint32 idTool = 0; + VAbstractNodeInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - SplinesCommonAttributes(domElement, id, idObject, idTool); + SplinesCommonAttributes(domElement, initData.id, initData.idObject, initData.idTool); try { - const auto obj = data->GetGObject(idObject); + const auto obj = initData.data->GetGObject(initData.idObject); if (obj->getType() == GOType::Spline) { - VSpline *spl = new VSpline(*data->GeometricObject(idObject)); - spl->setIdObject(idObject); + VSpline *spl = new VSpline(*data->GeometricObject(initData.idObject)); + spl->setIdObject(initData.idObject); spl->setMode(Draw::Modeling); - data->UpdateGObject(id, spl); + initData.data->UpdateGObject(initData.id, spl); } else { - VCubicBezier *spl = new VCubicBezier(*data->GeometricObject(idObject)); - spl->setIdObject(idObject); + VCubicBezier *spl = new VCubicBezier(*initData.data->GeometricObject(initData.idObject)); + spl->setIdObject(initData.idObject); spl->setMode(Draw::Modeling); - data->UpdateGObject(id, spl); + initData.data->UpdateGObject(initData.id, spl); } } catch (const VExceptionBadId &e) @@ -2598,7 +2622,7 @@ void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &pa return;// Just ignore } - VNodeSpline::Create(this, data, id, idObject, parse, Source::FromFile, "", idTool); + VNodeSpline::Create(initData); } catch (const VExceptionBadId &e) { @@ -2615,27 +2639,30 @@ void VPattern::ParseNodeSplinePath(const QDomElement &domElement, const Document try { - quint32 id = 0; - quint32 idObject = 0; - quint32 idTool = 0; + VAbstractNodeInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - SplinesCommonAttributes(domElement, id, idObject, idTool); + SplinesCommonAttributes(domElement, initData.id, initData.idObject, initData.idTool); try { - const auto obj = data->GetGObject(idObject); + const auto obj = initData.data->GetGObject(initData.idObject); if (obj->getType() == GOType::SplinePath) { - VSplinePath *path = new VSplinePath(*data->GeometricObject(idObject)); - path->setIdObject(idObject); + VSplinePath *path = new VSplinePath(*initData.data->GeometricObject(initData.idObject)); + path->setIdObject(initData.idObject); path->setMode(Draw::Modeling); - data->UpdateGObject(id, path); + initData.data->UpdateGObject(initData.id, path); } else { - VCubicBezierPath *spl = new VCubicBezierPath(*data->GeometricObject(idObject)); - spl->setIdObject(idObject); + VCubicBezierPath *spl = + new VCubicBezierPath(*initData.data->GeometricObject(initData.idObject)); + spl->setIdObject(initData.idObject); spl->setMode(Draw::Modeling); - data->UpdateGObject(id, spl); + initData.data->UpdateGObject(initData.id, spl); } } catch (const VExceptionBadId &e) @@ -2643,7 +2670,7 @@ void VPattern::ParseNodeSplinePath(const QDomElement &domElement, const Document Q_UNUSED(e) return;// Just ignore } - VNodeSplinePath::Create(this, data, id, idObject, parse, Source::FromFile, "", idTool); + VNodeSplinePath::Create(initData); } catch (const VExceptionBadId &e) { @@ -2661,26 +2688,31 @@ void VPattern::ParseToolArc(VMainGraphicsScene *scene, QDomElement &domElement, try { - quint32 id = 0; + VToolArcInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - const QString radius = GetParametrString(domElement, AttrRadius, "10"); - QString r = radius;//need for saving fixed formula; - const QString f1 = GetParametrString(domElement, AttrAngle1, "180"); - QString f1Fix = f1;//need for saving fixed formula; - const QString f2 = GetParametrString(domElement, AttrAngle2, "270"); - QString f2Fix = f2;//need for saving fixed formula; - const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); + ToolsCommonAttributes(domElement, initData.id); + initData.center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + initData.radius = GetParametrString(domElement, AttrRadius, "10"); + const QString r = initData.radius;//need for saving fixed formula; + initData.f1 = GetParametrString(domElement, AttrAngle1, "180"); + const QString f1Fix = initData.f1;//need for saving fixed formula; + initData.f2 = GetParametrString(domElement, AttrAngle2, "270"); + const QString f2Fix = initData.f2;//need for saving fixed formula; + initData.color = GetParametrString(domElement, AttrColor, ColorBlack); + initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); - VToolArc::Create(id, center, r, f1Fix, f2Fix, color, penStyle, scene, this, data, parse, Source::FromFile); + VToolArc::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (r != radius || f1Fix != f1 || f2Fix != f2) + if (r != initData.radius || f1Fix != initData.f1 || f2Fix != initData.f2) { - SetAttribute(domElement, AttrRadius, r); - SetAttribute(domElement, AttrAngle1, f1Fix); - SetAttribute(domElement, AttrAngle2, f2Fix); + SetAttribute(domElement, AttrRadius, initData.radius); + SetAttribute(domElement, AttrAngle1, initData.f1); + SetAttribute(domElement, AttrAngle2, initData.f2); modified = true; haveLiteChange(); } @@ -2707,33 +2739,38 @@ void VPattern::ParseToolEllipticalArc(VMainGraphicsScene *scene, QDomElement &do try { - quint32 id = 0; + VToolEllipticalArcInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - const QString radius1 = GetParametrString(domElement, AttrRadius1, "10"); - const QString radius2 = GetParametrString(domElement, AttrRadius2, "10"); - QString r1 = radius1;//need for saving fixed formula; - QString r2 = radius2;//need for saving fixed formula; - const QString f1 = GetParametrString(domElement, AttrAngle1, "180"); - QString f1Fix = f1;//need for saving fixed formula; - const QString f2 = GetParametrString(domElement, AttrAngle2, "270"); - QString f2Fix = f2;//need for saving fixed formula; - const QString frotation = GetParametrString(domElement, AttrRotationAngle, "0"); - QString frotationFix = frotation;//need for saving fixed formula; - const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); + ToolsCommonAttributes(domElement, initData.id); + initData.center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + initData.radius1 = GetParametrString(domElement, AttrRadius1, "10"); + initData.radius2 = GetParametrString(domElement, AttrRadius2, "10"); + const QString r1 = initData.radius1;//need for saving fixed formula; + const QString r2 = initData.radius2;//need for saving fixed formula; + initData.f1 = GetParametrString(domElement, AttrAngle1, "180"); + const QString f1Fix = initData.f1;//need for saving fixed formula; + initData.f2 = GetParametrString(domElement, AttrAngle2, "270"); + const QString f2Fix = initData.f2;//need for saving fixed formula; + initData.rotationAngle = GetParametrString(domElement, AttrRotationAngle, "0"); + const QString frotationFix = initData.rotationAngle;//need for saving fixed formula; + initData.color = GetParametrString(domElement, AttrColor, ColorBlack); + initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); - VToolEllipticalArc::Create(id, center, r1, r2, f1Fix, f2Fix, frotationFix, color, penStyle, scene, this, data, - parse, Source::FromFile); + VToolEllipticalArc::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (r1 != radius1 || r2 != radius2 || f1Fix != f1 || f2Fix != f2 || frotationFix != frotation) + if (r1 != initData.radius1 || r2 != initData.radius2 || f1Fix != initData.f1 || f2Fix != initData.f2 + || frotationFix != initData.rotationAngle) { - SetAttribute(domElement, AttrRadius1, r1); - SetAttribute(domElement, AttrRadius2, r2); - SetAttribute(domElement, AttrAngle1, f1Fix); - SetAttribute(domElement, AttrAngle2, f2Fix); - SetAttribute(domElement, AttrRotationAngle, frotationFix); + SetAttribute(domElement, AttrRadius1, initData.radius1); + SetAttribute(domElement, AttrRadius2, initData.radius2); + SetAttribute(domElement, AttrAngle1, initData.f1); + SetAttribute(domElement, AttrAngle2, initData.f2); + SetAttribute(domElement, AttrRotationAngle, initData.rotationAngle); modified = true; haveLiteChange(); } @@ -2759,25 +2796,29 @@ void VPattern::ParseNodeEllipticalArc(const QDomElement &domElement, const Docum try { - quint32 id = 0; + VAbstractNodeInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); - const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + ToolsCommonAttributes(domElement, initData.id); + initData.idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); VEllipticalArc *arc = nullptr; try { - arc = new VEllipticalArc(*data->GeometricObject(idObject)); + arc = new VEllipticalArc(*initData.data->GeometricObject(initData.idObject)); } catch (const VExceptionBadId &e) { // Possible case. Parent was deleted, but the node object is still here. Q_UNUSED(e) return;// Just ignore } - arc->setIdObject(idObject); + arc->setIdObject(initData.idObject); arc->setMode(Draw::Modeling); - data->UpdateGObject(id, arc); - VNodeEllipticalArc::Create(this, data, id, idObject, parse, Source::FromFile, "", idTool); + initData.data->UpdateGObject(initData.id, arc); + VNodeEllipticalArc::Create(initData); } catch (const VExceptionBadId &e) { @@ -2794,25 +2835,29 @@ void VPattern::ParseNodeArc(const QDomElement &domElement, const Document &parse try { - quint32 id = 0; + VAbstractNodeInitData initData; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); - const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + ToolsCommonAttributes(domElement, initData.id); + initData.idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); VArc *arc = nullptr; try { - arc = new VArc(*data->GeometricObject(idObject)); + arc = new VArc(*data->GeometricObject(initData.idObject)); } catch (const VExceptionBadId &e) { // Possible case. Parent was deleted, but the node object is still here. Q_UNUSED(e) return;// Just ignore } - arc->setIdObject(idObject); + arc->setIdObject(initData.idObject); arc->setMode(Draw::Modeling); - data->UpdateGObject(id, arc); - VNodeArc::Create(this, data, id, idObject, parse, Source::FromFile, "", idTool); + initData.data->UpdateGObject(initData.id, arc); + VNodeArc::Create(initData); } catch (const VExceptionBadId &e) { @@ -2830,27 +2875,31 @@ void VPattern::ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &do try { - quint32 id = 0; + VToolArcWithLengthInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - const QString radius = GetParametrString(domElement, AttrRadius, "10"); - QString r = radius;//need for saving fixed formula; - const QString f1 = GetParametrString(domElement, AttrAngle1, "180"); - QString f1Fix = f1;//need for saving fixed formula; - const QString length = GetParametrString(domElement, AttrLength, "10"); - QString lengthFix = length;//need for saving fixed length; - const QString color = GetParametrString(domElement, AttrColor, ColorBlack); - const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); + ToolsCommonAttributes(domElement, initData.id); + initData.center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + initData.radius = GetParametrString(domElement, AttrRadius, "10"); + const QString r = initData.radius;//need for saving fixed formula; + initData.f1 = GetParametrString(domElement, AttrAngle1, "180"); + const QString f1Fix = initData.f1;//need for saving fixed formula; + initData.length = GetParametrString(domElement, AttrLength, "10"); + const QString lengthFix = initData.length;//need for saving fixed length; + initData.color = GetParametrString(domElement, AttrColor, ColorBlack); + initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); - VToolArcWithLength::Create(id, center, r, f1Fix, lengthFix, color, penStyle, scene, this, data, parse, - Source::FromFile); + VToolArcWithLength::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (r != radius || f1Fix != f1 || lengthFix != length) + if (r != initData.radius || f1Fix != initData.f1 || lengthFix != initData.length) { - SetAttribute(domElement, AttrRadius, r); - SetAttribute(domElement, AttrAngle1, f1Fix); - SetAttribute(domElement, AttrLength, lengthFix); + SetAttribute(domElement, AttrRadius, initData.radius); + SetAttribute(domElement, AttrAngle1, initData.f1); + SetAttribute(domElement, AttrLength, initData.length); modified = true; haveLiteChange(); } @@ -2877,23 +2926,26 @@ void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElem try { - quint32 id = NULL_ID; + VToolRotationInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - const QString angle = GetParametrString(domElement, AttrAngle, "10"); - QString a = angle;//need for saving fixed formula; - const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + ToolsCommonAttributes(domElement, initData.id); + initData.origin = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + initData.angle = GetParametrString(domElement, AttrAngle, "10"); + const QString a = initData.angle;//need for saving fixed formula; + initData.suffix = GetParametrString(domElement, AttrSuffix, ""); - QVector source; - QVector destination; - VAbstractOperation::ExtractData(domElement, source, destination); + VAbstractOperation::ExtractData(domElement, initData); - VToolRotation::Create(id, center, a, suffix, source, destination, scene, this, data, parse, Source::FromFile); + VToolRotation::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (a != angle) + if (a != initData.angle) { - SetAttribute(domElement, AttrAngle, a); + SetAttribute(domElement, AttrAngle, initData.angle); modified = true; haveLiteChange(); } @@ -2920,19 +2972,21 @@ void VPattern::ParseToolFlippingByLine(VMainGraphicsScene *scene, QDomElement &d try { - quint32 id = NULL_ID; + VToolFlippingByLineInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 p1 = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); - const quint32 p2 = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); - const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + ToolsCommonAttributes(domElement, initData.id); + initData.firstLinePointId = GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); + initData.secondLinePointId = GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); + initData.suffix = GetParametrString(domElement, AttrSuffix, ""); - QVector source; - QVector destination; - VAbstractOperation::ExtractData(domElement, source, destination); + VAbstractOperation::ExtractData(domElement, initData); - VToolFlippingByLine::Create(id, p1, p2, suffix, source, destination, scene, this, data, parse, - Source::FromFile); + VToolFlippingByLine::Create(initData); } catch (const VExceptionBadId &e) { @@ -2950,19 +3004,21 @@ void VPattern::ParseToolFlippingByAxis(VMainGraphicsScene *scene, QDomElement &d try { - quint32 id = NULL_ID; + VToolFlippingByAxisInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const quint32 origin = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); - const auto axisType = static_cast(GetParametrUInt(domElement, AttrAxisType, "1")); - const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + ToolsCommonAttributes(domElement, initData.id); + initData.originPointId = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + initData.axisType = static_cast(GetParametrUInt(domElement, AttrAxisType, "1")); + initData.suffix = GetParametrString(domElement, AttrSuffix, ""); - QVector source; - QVector destination; - VAbstractOperation::ExtractData(domElement, source, destination); + VAbstractOperation::ExtractData(domElement, initData); - VToolFlippingByAxis::Create(id, origin, axisType, suffix, source, destination, scene, this, data, parse, - Source::FromFile); + VToolFlippingByAxis::Create(initData); } catch (const VExceptionBadId &e) { @@ -2980,25 +3036,28 @@ void VPattern::ParseToolMove(VMainGraphicsScene *scene, QDomElement &domElement, try { - quint32 id = NULL_ID; + VToolMoveInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; - ToolsCommonAttributes(domElement, id); - const QString angle = GetParametrString(domElement, AttrAngle, "0"); - QString a = angle;//need for saving fixed formula; - const QString length = GetParametrString(domElement, AttrLength, "0"); - QString len = length;//need for saving fixed formula; - const QString suffix = GetParametrString(domElement, AttrSuffix, ""); + ToolsCommonAttributes(domElement, initData.id); + initData.formulaAngle = GetParametrString(domElement, AttrAngle, "0"); + const QString a = initData.formulaAngle;//need for saving fixed formula; + initData.formulaLength = GetParametrString(domElement, AttrLength, "0"); + const QString len = initData.formulaLength;//need for saving fixed formula; + initData.suffix = GetParametrString(domElement, AttrSuffix, ""); - QVector source; - QVector destination; - VAbstractOperation::ExtractData(domElement, source, destination); + VAbstractOperation::ExtractData(domElement, initData); - VToolMove::Create(id, a, len, suffix, source, destination, scene, this, data, parse, Source::FromFile); + VToolMove::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (a != angle || len != length) + if (a != initData.formulaAngle || len != initData.formulaLength) { - SetAttribute(domElement, AttrAngle, a); - SetAttribute(domElement, AttrLength, len); + SetAttribute(domElement, AttrAngle, initData.formulaAngle); + SetAttribute(domElement, AttrLength, initData.formulaLength); modified = true; haveLiteChange(); } @@ -3348,9 +3407,6 @@ void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &d case 0: //VToolUnionDetails::ToolType try { - quint32 id = 0; - ToolsCommonAttributes(domElement, id); - VToolUnionDetailsInitData initData; initData.indexD1 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD1, "-1"); initData.indexD2 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD2, "-1"); @@ -3360,7 +3416,9 @@ void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &d initData.parse = parse; initData.typeCreation = Source::FromFile; - VToolUnionDetails::Create(id, initData); + ToolsCommonAttributes(domElement, initData.id); + + VToolUnionDetails::Create(initData); } catch (const VExceptionBadId &e) { @@ -3415,28 +3473,29 @@ void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domEleme Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); try { - quint32 id = 0; - ToolsCommonAttributes(domElement, id); - const QString name = GetParametrString(domElement, AttrName, tr("Unnamed path")); - const QString defType = QString().setNum(static_cast(PiecePathType::CustomSeamAllowance)); - const PiecePathType type = static_cast(GetParametrUInt(domElement, AttrType, defType)); - const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); - const QString penType = GetParametrString(domElement, AttrTypeLine, TypeLineLine); - const bool cut = GetParametrBool(domElement, AttrCut, falseStr); + VToolPiecePathInitData initData; + initData.scene = scene; + initData.doc = this; + initData.data = data; + initData.parse = parse; + initData.typeCreation = Source::FromFile; + + ToolsCommonAttributes(domElement, initData.id); + initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); - VPiecePath path; const QDomElement element = domElement.firstChildElement(VAbstractPattern::TagNodes); if (not element.isNull()) { - path = ParsePathNodes(element); + initData.path = ParsePathNodes(element); } - path.SetType(type); - path.SetName(name); - path.SetPenType(LineStyleToPenStyle(penType)); - path.SetCutPath(cut); + const QString defType = QString().setNum(static_cast(PiecePathType::CustomSeamAllowance)); + initData.path.SetType(static_cast(GetParametrUInt(domElement, AttrType, defType))); + initData.path.SetName(GetParametrString(domElement, AttrName, tr("Unnamed path"))); + initData.path.SetPenType(LineStyleToPenStyle(GetParametrString(domElement, AttrTypeLine, TypeLineLine))); + initData.path.SetCutPath(GetParametrBool(domElement, AttrCut, falseStr)); - VToolPiecePath::Create(id, path, 0, scene, this, data, parse, Source::FromFile, "", idTool); + VToolPiecePath::Create(initData); } catch (const VExceptionBadId &e) { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index dd2023ba7..15b1069e4 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -36,6 +36,8 @@ class VMainGraphicsScene; class VNodeDetail; +class VToolSinglePointInitData; +class VToolLinePointInitData; /** * @brief The VPattern class working with pattern file. @@ -155,10 +157,8 @@ private: void ParseIncrementsElement(const QDomNode& node); void PrepareForParse(const Document &parse); void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id); - void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx, - qreal &my, bool &labelVisible, QString &typeLine, QString &lineColor); - void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, QString &name, qreal &mx, - qreal &my, bool &labelVisible); + void PointsWithLineCommonAttributes(const QDomElement &domElement, VToolLinePointInitData &initData); + void PointsCommonAttributes(const QDomElement &domElement, VToolSinglePointInitData &initData); void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my); void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool); diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp index f37fc9c1c..1e1f37e2a 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -46,21 +46,19 @@ VAbstractFlipping::VAbstractFlipping(VAbstractPattern *doc, VContainer *data, qu } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractFlipping::CreateDestination(Source typeCreation, quint32 &id, QVector &dest, - const QVector &source, const QPointF &fPoint, const QPointF &sPoint, - const QString &suffix, VAbstractPattern *doc, VContainer *data, - const Document &parse) +void VAbstractFlipping::CreateDestination(VAbstractOperationInitData &initData, const QPointF &fPoint, + const QPointF &sPoint) { - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - dest.clear();// Try to avoid mistake, value must be empty + initData.destination.clear();// Try to avoid mistake, value must be empty - id = VContainer::getNextId();//Just reserve id for tool + initData.id = VContainer::getNextId();//Just reserve id for tool - for (int i = 0; i < source.size(); ++i) + for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); + const quint32 idObject = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); @@ -70,25 +68,34 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - dest.append(CreatePoint(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, + initData.data)); break; case GOType::Arc: - dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreateArc(initData.id, idObject, fPoint, sPoint, initData.suffix, + initData.data)); break; case GOType::EllipticalArc: - dest.append(CreateArc(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreateArc(initData.id, idObject, fPoint, sPoint, + initData.suffix, initData.data)); break; case GOType::Spline: - dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreateCurve(initData.id, idObject, fPoint, sPoint, + initData.suffix, initData.data)); break; case GOType::SplinePath: - dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreateCurveWithSegments(initData.id, idObject, fPoint, + sPoint, initData.suffix, + initData.data)); break; case GOType::CubicBezier: - dest.append(CreateCurve(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreateCurve(initData.id, idObject, fPoint, sPoint, + initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - dest.append(CreateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data)); + initData.destination.append(CreateCurveWithSegments(initData.id, idObject, fPoint, + sPoint, initData.suffix, + initData.data)); break; case GOType::Unknown: break; @@ -98,10 +105,10 @@ QT_WARNING_POP } else { - for (int i = 0; i < source.size(); ++i) + for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); + const quint32 idObject = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); @@ -111,36 +118,44 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - UpdatePoint(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id, dest.at(i).mx, - dest.at(i).my); + { + const DestinationItem &item = initData.destination.at(i); + UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item.id, item.mx, + item.my); break; + } case GOType::Arc: - UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + UpdateArc(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::EllipticalArc: - UpdateArc(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + UpdateArc(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + UpdateCurve(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + UpdateCurveWithSegments(initData.id, idObject, fPoint, sPoint, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::CubicBezier: - UpdateCurve(id, idObject, fPoint, sPoint, suffix, data, dest.at(i).id); + UpdateCurve(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::CubicBezierPath: - UpdateCurveWithSegments(id, idObject, fPoint, sPoint, suffix, data, - dest.at(i).id); + UpdateCurveWithSegments(initData.id, idObject, fPoint, sPoint, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::Unknown: break; } QT_WARNING_POP } - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } } diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h index f9f3558b2..f678ba646 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h @@ -43,10 +43,7 @@ protected: const QVector &source, const QVector &destination, QGraphicsItem *parent = nullptr); - static void CreateDestination(Source typeCreation, quint32 &id, QVector &dest, - const QVector &source, const QPointF &fPoint, const QPointF &sPoint, - const QString &suffix, VAbstractPattern *doc, VContainer *data, - const Document &parse); + static void CreateDestination(VAbstractOperationInitData &initData, const QPointF &fPoint, const QPointF &sPoint); static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data); diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp index 810e59917..d35cb8fcf 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp @@ -84,12 +84,19 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(QSharedPointer dial SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 originPointId = dialogTool->GetOriginPointId(); - const AxisType axisType = dialogTool->GetAxisType(); - const QString suffix = dialogTool->GetSuffix(); - const QVector source = dialogTool->GetObjects(); - VToolFlippingByAxis* operation = Create(0, originPointId, axisType, suffix, source, QVector(), - scene, doc, data, Document::FullParse, Source::FromGui); + + VToolFlippingByAxisInitData initData; + initData.originPointId = dialogTool->GetOriginPointId(); + initData.axisType = dialogTool->GetAxisType(); + initData.suffix = dialogTool->GetSuffix(); + initData.source = dialogTool->GetObjects(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolFlippingByAxis* operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialogTool; @@ -98,17 +105,13 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(QSharedPointer dial } //--------------------------------------------------------------------------------------------------------------------- -VToolFlippingByAxis *VToolFlippingByAxis::Create(const quint32 _id, quint32 originPointId, AxisType axisType, - const QString &suffix, const QVector &source, - const QVector &destination, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolFlippingByAxis *VToolFlippingByAxis::Create(VToolFlippingByAxisInitData initData) { - const auto originPoint = *data->GeometricObject(originPointId); + const auto originPoint = *initData.data->GeometricObject(initData.originPointId); const QPointF fPoint = static_cast(originPoint); QPointF sPoint; - if (axisType == AxisType::VerticalAxis) + if (initData.axisType == AxisType::VerticalAxis) { sPoint = QPointF(fPoint.x(), fPoint.y() + 100); } @@ -117,23 +120,19 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(const quint32 _id, quint32 orig sPoint = QPointF(fPoint.x() + 100, fPoint.y()); } - QVector dest = destination; + CreateDestination(initData, fPoint, sPoint); - quint32 id = _id; - CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse); - - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::FlippingByAxis, doc); - VToolFlippingByAxis *tool = new VToolFlippingByAxis(doc, data, id, originPointId, axisType, suffix, source, - dest, typeCreation); - scene->addItem(tool); - InitOperationToolConnections(scene, tool); - VAbstractPattern::AddTool(id, tool); - doc->IncrementReferens(originPoint.getIdTool()); - for (int i = 0; i < source.size(); ++i) + VAbstractTool::AddRecord(initData.id, Tool::FlippingByAxis, initData.doc); + VToolFlippingByAxis *tool = new VToolFlippingByAxis(initData); + initData.scene->addItem(tool); + InitOperationToolConnections(initData.scene, tool); + VAbstractPattern::AddTool(initData.id, tool); + initData.doc->IncrementReferens(originPoint.getIdTool()); + for (int i = 0; i < initData.source.size(); ++i) { - doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool()); } return tool; } @@ -239,15 +238,13 @@ QString VToolFlippingByAxis::MakeToolTip() const } //--------------------------------------------------------------------------------------------------------------------- -VToolFlippingByAxis::VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId, - AxisType axisType, const QString &suffix, - const QVector &source, const QVector &destination, - const Source &typeCreation, QGraphicsItem *parent) - : VAbstractFlipping(doc, data, id, suffix, source, destination, parent), - m_originPointId(originPointId), - m_axisType(axisType) +VToolFlippingByAxis::VToolFlippingByAxis(const VToolFlippingByAxisInitData &initData, QGraphicsItem *parent) + : VAbstractFlipping(initData.doc, initData.data, initData.id, initData.suffix, initData.source, + initData.destination, parent), + m_originPointId(initData.originPointId), + m_axisType(initData.axisType) { InitOperatedObjects(); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h index 7ef398d5e..6b30e6590 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.h @@ -33,6 +33,18 @@ #include "vabstractflipping.h" +struct VToolFlippingByAxisInitData : public VAbstractOperationInitData +{ + VToolFlippingByAxisInitData() + : VAbstractOperationInitData(), + originPointId(NULL_ID), + axisType(AxisType::VerticalAxis) + {} + + quint32 originPointId; + AxisType axisType; +}; + class VToolFlippingByAxis : public VAbstractFlipping { Q_OBJECT @@ -41,11 +53,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolFlippingByAxis* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolFlippingByAxis* Create(const quint32 _id, quint32 originPointId, AxisType axisType, - const QString &suffix, const QVector &source, - const QVector &destination, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolFlippingByAxis* Create(VToolFlippingByAxisInitData initData); static const QString ToolType; @@ -72,10 +80,7 @@ private: quint32 m_originPointId; AxisType m_axisType; - VToolFlippingByAxis(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 originPointId, - AxisType axisType, const QString &suffix, const QVector &source, - const QVector &destination, const Source &typeCreation, - QGraphicsItem *parent = nullptr); + VToolFlippingByAxis(const VToolFlippingByAxisInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp index 5fc6a5986..0c2214da5 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -84,13 +84,19 @@ VToolFlippingByLine *VToolFlippingByLine::Create(QSharedPointer dial SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 firstLinePointId = dialogTool->GetFirstLinePointId(); - const quint32 secondLinePointId = dialogTool->GetSecondLinePointId(); - const QString suffix = dialogTool->GetSuffix(); - const QVector source = dialogTool->GetObjects(); - VToolFlippingByLine* operation = Create(0, firstLinePointId, secondLinePointId, suffix, source, - QVector(), scene, doc, data, Document::FullParse, - Source::FromGui); + + VToolFlippingByLineInitData initData; + initData.firstLinePointId = dialogTool->GetFirstLinePointId(); + initData.secondLinePointId = dialogTool->GetSecondLinePointId(); + initData.suffix = dialogTool->GetSuffix(); + initData.source = dialogTool->GetObjects(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolFlippingByLine* operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialogTool; @@ -99,36 +105,28 @@ VToolFlippingByLine *VToolFlippingByLine::Create(QSharedPointer dial } //--------------------------------------------------------------------------------------------------------------------- -VToolFlippingByLine *VToolFlippingByLine::Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, - const QString &suffix, const QVector &source, - const QVector &destination, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolFlippingByLine *VToolFlippingByLine::Create(VToolFlippingByLineInitData initData) { - const auto firstPoint = *data->GeometricObject(firstLinePointId); + const auto firstPoint = *initData.data->GeometricObject(initData.firstLinePointId); const QPointF fPoint = static_cast(firstPoint); - const auto secondPoint = *data->GeometricObject(secondLinePointId); + const auto secondPoint = *initData.data->GeometricObject(initData.secondLinePointId); const QPointF sPoint = static_cast(secondPoint); - QVector dest = destination; + CreateDestination(initData, fPoint, sPoint); - quint32 id = _id; - CreateDestination(typeCreation, id, dest, source, fPoint, sPoint, suffix, doc, data, parse); - - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::FlippingByLine, doc); - VToolFlippingByLine *tool = new VToolFlippingByLine(doc, data, id, firstLinePointId, secondLinePointId, suffix, - source, dest, typeCreation); - scene->addItem(tool); - InitOperationToolConnections(scene, tool); - VAbstractPattern::AddTool(id, tool); - doc->IncrementReferens(firstPoint.getIdTool()); - doc->IncrementReferens(secondPoint.getIdTool()); - for (int i = 0; i < source.size(); ++i) + VAbstractTool::AddRecord(initData.id, Tool::FlippingByLine, initData.doc); + VToolFlippingByLine *tool = new VToolFlippingByLine(initData); + initData.scene->addItem(tool); + InitOperationToolConnections(initData.scene, tool); + VAbstractPattern::AddTool(initData.id, tool); + initData.doc->IncrementReferens(firstPoint.getIdTool()); + initData.doc->IncrementReferens(secondPoint.getIdTool()); + for (int i = 0; i < initData.source.size(); ++i) { - doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool()); } return tool; } @@ -228,14 +226,12 @@ QString VToolFlippingByLine::MakeToolTip() const } //--------------------------------------------------------------------------------------------------------------------- -VToolFlippingByLine::VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, - quint32 secondLinePointId, const QString &suffix, - const QVector &source, const QVector &destination, - const Source &typeCreation, QGraphicsItem *parent) - : VAbstractFlipping(doc, data, id, suffix, source, destination, parent), - m_firstLinePointId(firstLinePointId), - m_secondLinePointId(secondLinePointId) +VToolFlippingByLine::VToolFlippingByLine(const VToolFlippingByLineInitData &initData, QGraphicsItem *parent) + : VAbstractFlipping(initData.doc, initData.data, initData.id, initData.suffix, initData.source, + initData.destination, parent), + m_firstLinePointId(initData.firstLinePointId), + m_secondLinePointId(initData.secondLinePointId) { InitOperatedObjects(); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h index 249395dfd..397dc47f3 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.h @@ -33,6 +33,19 @@ #include "vabstractflipping.h" +struct VToolFlippingByLineInitData : public VAbstractOperationInitData +{ + VToolFlippingByLineInitData() + : VAbstractOperationInitData(), + firstLinePointId(NULL_ID), + secondLinePointId(NULL_ID) + {} + + quint32 firstLinePointId; + quint32 secondLinePointId; +}; + + class VToolFlippingByLine : public VAbstractFlipping { Q_OBJECT @@ -41,11 +54,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolFlippingByLine* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolFlippingByLine* Create(const quint32 _id, quint32 firstLinePointId, quint32 secondLinePointId, - const QString &suffix, const QVector &source, - const QVector &destination, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolFlippingByLine* Create(VToolFlippingByLineInitData initData); static const QString ToolType; @@ -70,10 +79,7 @@ private: quint32 m_firstLinePointId; quint32 m_secondLinePointId; - VToolFlippingByLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstLinePointId, - quint32 secondLinePointId, const QString &suffix, const QVector &source, - const QVector &destination, const Source &typeCreation, - QGraphicsItem *parent = nullptr); + VToolFlippingByLine(const VToolFlippingByLineInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index e0021f661..52b2fa0d3 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -85,8 +85,7 @@ void VAbstractOperation::paint(QPainter *painter, const QStyleOptionGraphicsItem } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::ExtractData(const QDomElement &domElement, QVector &source, - QVector &destination) +void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData) { const QDomNodeList nodeList = domElement.childNodes(); for (qint32 i = 0; i < nodeList.size(); ++i) @@ -94,21 +93,21 @@ void VAbstractOperation::ExtractData(const QDomElement &domElement, QVectortoPixel(VDomDocument::GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); - destination.append(d); + initData.destination.append(d); } } } diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index bc70bf867..195c6819b 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -49,6 +49,20 @@ struct DestinationItem qreal my; }; +struct VAbstractOperationInitData : public VAbstractToolInitData +{ + VAbstractOperationInitData() + : VAbstractToolInitData(), + suffix(), + source(), + destination() + {} + + QString suffix; + QVector source; + QVector destination; +}; + // FIXME. I don't know how to use QGraphicsItem properly, so just took first available finished class. // QGraphicsItem itself produce case where clicking on empty space produce call to QGraphicsItem. // And i don't know how to fix it. @@ -73,8 +87,7 @@ public: virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; - static void ExtractData(const QDomElement &domElement, QVector &source, - QVector &destination); + static void ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData); public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 27127f122..6b9bad08c 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -92,12 +92,19 @@ VToolMove *VToolMove::Create(QSharedPointer dialog, VMainGraphicsSce SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - QString angle = dialogTool->GetAngle(); - QString length = dialogTool->GetLength(); - const QString suffix = dialogTool->GetSuffix(); - const QVector source = dialogTool->GetObjects(); - VToolMove* operation = Create(0, angle, length, suffix, source, QVector(), scene, doc, data, - Document::FullParse, Source::FromGui); + + VToolMoveInitData initData; + initData.formulaAngle = dialogTool->GetAngle(); + initData.formulaLength = dialogTool->GetLength(); + initData.suffix = dialogTool->GetSuffix(); + initData.source = dialogTool->GetObjects(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolMove* operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialogTool; @@ -106,31 +113,24 @@ VToolMove *VToolMove::Create(QSharedPointer dialog, VMainGraphicsSce } //--------------------------------------------------------------------------------------------------------------------- -VToolMove *VToolMove::Create(quint32 _id, QString &formulaAngle, QString &formulaLength, - const QString &suffix, const QVector &source, - const QVector &destination, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolMove *VToolMove::Create(VToolMoveInitData &initData) { qreal calcAngle = 0; qreal calcLength = 0; - calcAngle = CheckFormula(_id, formulaAngle, data); - calcLength = qApp->toPixel(CheckFormula(_id, formulaLength, data)); + calcAngle = CheckFormula(initData.id, initData.formulaAngle, initData.data); + calcLength = qApp->toPixel(CheckFormula(initData.id, initData.formulaLength, initData.data)); - QVector dest = destination; - - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - dest.clear();// Try to avoid mistake, value must be empty + initData.destination.clear();// Try to avoid mistake, value must be empty - id = VContainer::getNextId();//Just reserve id for tool + initData.id = VContainer::getNextId();//Just reserve id for tool - for (int i = 0; i < source.size(); ++i) + for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); + const quint32 idObject = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); @@ -140,27 +140,35 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - dest.append(CreatePoint(id, idObject, calcAngle, calcLength, suffix, data)); + initData.destination.append(CreatePoint(initData.id, idObject, calcAngle, calcLength, + initData.suffix, initData.data)); break; case GOType::Arc: - dest.append(CreateArc(id, idObject, calcAngle, calcLength, suffix, data)); + initData.destination.append(CreateArc(initData.id, idObject, calcAngle, calcLength, + initData.suffix, initData.data)); break; case GOType::EllipticalArc: - dest.append(CreateArc(id, idObject, calcAngle, calcLength, suffix, data)); + initData.destination.append(CreateArc(initData.id, idObject, calcAngle, calcLength, + initData.suffix, initData.data)); break; case GOType::Spline: - dest.append(CreateCurve(id, idObject, calcAngle, calcLength, suffix, data)); + initData.destination.append(CreateCurve(initData.id, idObject, calcAngle, calcLength, + initData.suffix, initData.data)); break; case GOType::SplinePath: - dest.append(CreateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, - data)); + initData.destination.append(CreateCurveWithSegments(initData.id, idObject, calcAngle, + calcLength, initData.suffix, + initData.data)); break; case GOType::CubicBezier: - dest.append(CreateCurve(id, idObject, calcAngle, calcLength, suffix, data)); + initData.destination.append(CreateCurve(initData.id, idObject, calcAngle, calcLength, + initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - dest.append(CreateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, - data)); + initData.destination.append(CreateCurveWithSegments(initData.id, idObject, + calcAngle, calcLength, + initData.suffix, + initData.data)); break; case GOType::Unknown: break; @@ -170,10 +178,10 @@ QT_WARNING_POP } else { - for (int i = 0; i < source.size(); ++i) + for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); + const quint32 idObject = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); @@ -183,51 +191,58 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - UpdatePoint(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id, dest.at(i).mx, - dest.at(i).my); + { + const DestinationItem &item = initData.destination.at(i); + UpdatePoint(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, item.id, + item.mx, item.my); break; + } case GOType::Arc: - UpdateArc(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + UpdateArc(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::EllipticalArc: - UpdateArc(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + UpdateArc(initData.id, idObject, calcAngle, calcLength, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + UpdateCurve(initData.id, idObject, calcAngle, calcLength, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, data, - dest.at(i).id); + UpdateCurveWithSegments(initData.id, idObject, calcAngle, calcLength, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::CubicBezier: - UpdateCurve(id, idObject, calcAngle, calcLength, suffix, data, dest.at(i).id); + UpdateCurve(initData.id, idObject, calcAngle, calcLength, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::CubicBezierPath: - UpdateCurveWithSegments(id, idObject, calcAngle, calcLength, suffix, data, - dest.at(i).id); + UpdateCurveWithSegments(initData.id, idObject, calcAngle, calcLength, + initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::Unknown: break; } QT_WARNING_POP } - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Move, doc); - VToolMove *tool = new VToolMove(doc, data, id, formulaAngle, formulaLength, suffix, source, dest, - typeCreation); - scene->addItem(tool); - InitOperationToolConnections(scene, tool); - VAbstractPattern::AddTool(id, tool); - for (int i = 0; i < source.size(); ++i) + VAbstractTool::AddRecord(initData.id, Tool::Move, initData.doc); + VToolMove *tool = new VToolMove(initData); + initData.scene->addItem(tool); + InitOperationToolConnections(initData.scene, tool); + VAbstractPattern::AddTool(initData.id, tool); + for (int i = 0; i < initData.source.size(); ++i) { - doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool()); } return tool; } @@ -361,16 +376,14 @@ QString VToolMove::MakeToolTip() const } //--------------------------------------------------------------------------------------------------------------------- -VToolMove::VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id, - const QString &formulaAngle, const QString &formulaLength, const QString &suffix, - const QVector &source, const QVector &destination, - const Source &typeCreation, QGraphicsItem *parent) - : VAbstractOperation(doc, data, id, suffix, source, destination, parent), - formulaAngle(formulaAngle), - formulaLength(formulaLength) +VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent) + : VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source, + initData.destination, parent), + formulaAngle(initData.formulaAngle), + formulaLength(initData.formulaLength) { InitOperatedObjects(); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h index 6c30bbff9..b054f54e9 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h @@ -45,6 +45,18 @@ template class QSharedPointer; class VFormula; +struct VToolMoveInitData : public VAbstractOperationInitData +{ + VToolMoveInitData() + : VAbstractOperationInitData(), + formulaAngle(), + formulaLength() + {} + + QString formulaAngle; + QString formulaLength; +}; + class VToolMove : public VAbstractOperation { Q_OBJECT @@ -53,10 +65,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolMove* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolMove* Create(quint32 _id, QString &formulaAngle, QString &formulaLength, const QString &suffix, - const QVector &source, const QVector &destination, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolMove* Create(VToolMoveInitData &initData); static const QString ToolType; @@ -83,10 +92,7 @@ private: QString formulaAngle; QString formulaLength; - VToolMove(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formulaAngle, - const QString &formulaLength, const QString &suffix, const QVector &source, - const QVector &destination, const Source &typeCreation, - QGraphicsItem *parent = nullptr); + VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent = nullptr); static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, const QString &suffix, VContainer *data); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 1342f4f40..ae8779bfd 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -80,16 +80,14 @@ template class QSharedPointer; const QString VToolRotation::ToolType = QStringLiteral("rotation"); //--------------------------------------------------------------------------------------------------------------------- -VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, - const QString &angle, const QString &suffix, const QVector &source, - const QVector &destination, const Source &typeCreation, - QGraphicsItem *parent) - : VAbstractOperation(doc, data, id, suffix, source, destination, parent), - origPointId(origPointId), - formulaAngle(angle) +VToolRotation::VToolRotation(const VToolRotationInitData &initData, QGraphicsItem *parent) + : VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source, + initData.destination, parent), + origPointId(initData.origin), + formulaAngle(initData.angle) { InitOperatedObjects(); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -110,12 +108,19 @@ VToolRotation *VToolRotation::Create(QSharedPointer dialog, VMainGra SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 originPointId = dialogTool->GetOrigPointId(); - QString angle = dialogTool->GetAngle(); - const QString suffix = dialogTool->GetSuffix(); - const QVector source = dialogTool->GetObjects(); - VToolRotation* operation = Create(0, originPointId, angle, suffix, source, QVector(), - scene, doc, data, Document::FullParse, Source::FromGui); + + VToolRotationInitData initData; + initData.origin = dialogTool->GetOrigPointId(); + initData.angle = dialogTool->GetAngle(); + initData.suffix = dialogTool->GetSuffix(); + initData.source = dialogTool->GetObjects(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolRotation* operation = Create(initData); if (operation != nullptr) { operation->m_dialog = dialogTool; @@ -124,32 +129,25 @@ VToolRotation *VToolRotation::Create(QSharedPointer dialog, VMainGra } //--------------------------------------------------------------------------------------------------------------------- -VToolRotation *VToolRotation::Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix, - const QVector &source, - const QVector &destination, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolRotation *VToolRotation::Create(VToolRotationInitData &initData) { qreal calcAngle = 0; - calcAngle = CheckFormula(_id, angle, data); + calcAngle = CheckFormula(initData.id, initData.angle, initData.data); - const auto originPoint = *data->GeometricObject(origin); + const auto originPoint = *initData.data->GeometricObject(initData.origin); const QPointF oPoint = static_cast(originPoint); - QVector dest = destination; - - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - dest.clear();// Try to avoid mistake, value must be empty + initData.destination.clear();// Try to avoid mistake, value must be empty - id = VContainer::getNextId();//Just reserve id for tool + initData.id = VContainer::getNextId();//Just reserve id for tool - for (int i = 0; i < source.size(); ++i) + for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); + const quint32 idObject = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); @@ -159,26 +157,34 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - dest.append(CreatePoint(id, idObject, oPoint, calcAngle, suffix, data)); + initData.destination.append(CreatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, + initData.data)); break; case GOType::Arc: - dest.append(CreateArc(id, idObject, oPoint, calcAngle, suffix, data)); + initData.destination.append(CreateArc(initData.id, idObject, oPoint, calcAngle, + initData.suffix, initData.data)); break; case GOType::EllipticalArc: - dest.append(CreateArc(id, idObject, oPoint, calcAngle, suffix, data)); + initData.destination.append(CreateArc(initData.id, idObject, oPoint, calcAngle, + initData.suffix, initData.data)); break; case GOType::Spline: - dest.append(CreateCurve(id, idObject, oPoint, calcAngle, suffix, data)); + initData.destination.append(CreateCurve(initData.id, idObject, oPoint, calcAngle, + initData.suffix, initData.data)); break; case GOType::SplinePath: - dest.append(CreateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data)); + initData.destination.append(CreateCurveWithSegments(initData.id, idObject, oPoint, + calcAngle, initData.suffix, + initData.data)); break; case GOType::CubicBezier: - dest.append(CreateCurve(id, idObject, oPoint, calcAngle, suffix, data)); + initData.destination.append(CreateCurve(initData.id, idObject, oPoint, calcAngle, + initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - dest.append(CreateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, - data)); + initData.destination.append(CreateCurveWithSegments(initData.id, idObject, oPoint, + calcAngle, initData.suffix, + initData.data)); break; case GOType::Unknown: break; @@ -188,10 +194,10 @@ QT_WARNING_POP } else { - for (int i = 0; i < source.size(); ++i) + for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = source.at(i); - const QSharedPointer obj = data->GetGObject(idObject); + const quint32 idObject = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(idObject); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); @@ -201,50 +207,58 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - UpdatePoint(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id, dest.at(i).mx, - dest.at(i).my); + { + const DestinationItem &item = initData.destination.at(i); + UpdatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + item.id, item.mx, item.my); break; + } case GOType::Arc: - UpdateArc(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + UpdateArc(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::EllipticalArc: - UpdateArc(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + UpdateArc(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + UpdateCurve(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + UpdateCurveWithSegments(initData.id, idObject, oPoint, calcAngle, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::CubicBezier: - UpdateCurve(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + UpdateCurve(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + initData.destination.at(i).id); break; case GOType::CubicBezierPath: - UpdateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data, - dest.at(i).id); + UpdateCurveWithSegments(initData.id, idObject, oPoint, calcAngle, initData.suffix, + initData.data, initData.destination.at(i).id); break; case GOType::Unknown: break; } QT_WARNING_POP } - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Rotation, doc); - VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation); - scene->addItem(tool); - InitOperationToolConnections(scene, tool); - VAbstractPattern::AddTool(id, tool); - doc->IncrementReferens(originPoint.getIdTool()); - for (int i = 0; i < source.size(); ++i) + VAbstractTool::AddRecord(initData.id, Tool::Rotation, initData.doc); + VToolRotation *tool = new VToolRotation(initData); + initData.scene->addItem(tool); + InitOperationToolConnections(initData.scene, tool); + VAbstractPattern::AddTool(initData.id, tool); + initData.doc->IncrementReferens(originPoint.getIdTool()); + for (int i = 0; i < initData.source.size(); ++i) { - doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(initData.source.at(i))->getIdTool()); } return tool; } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index bbdc81adb..a660aae95 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -45,6 +45,18 @@ template class QSharedPointer; class VFormula; +struct VToolRotationInitData : public VAbstractOperationInitData +{ + VToolRotationInitData() + : VAbstractOperationInitData(), + origin(NULL_ID), + angle() + {} + + quint32 origin; + QString angle; +}; + class VToolRotation : public VAbstractOperation { Q_OBJECT @@ -53,10 +65,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolRotation* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix, - const QVector &source, const QVector &destination, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolRotation* Create(VToolRotationInitData &initData); static const QString ToolType; @@ -83,10 +92,7 @@ private: quint32 origPointId; QString formulaAngle; - VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, - const QString &angle, const QString &suffix, const QVector &source, - const QVector &destination, const Source &typeCreation, - QGraphicsItem *parent = nullptr); + VToolRotation(const VToolRotationInitData &initData, QGraphicsItem *parent = nullptr); static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 0782bdbf2..569bedb0f 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -54,6 +54,18 @@ class VControlPointSpline; template class QSharedPointer; +struct VAbstractSplineInitData : public VAbstractToolInitData +{ + VAbstractSplineInitData() + : VAbstractToolInitData(), + color(ColorBlack), + penStyle(TypeLineLine) + {} + + QString color; + QString penStyle; +}; + class VAbstractSpline:public VDrawTool, public QGraphicsPathItem { Q_OBJECT diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index f04aaf1ab..190a40d3c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -61,21 +61,16 @@ const QString VToolArc::ToolType = QStringLiteral("simple"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolArc constuctor. - * @param doc dom document container - * @param data container with variables - * @param id object id in container - * @param typeCreation way we create this tool. - * @param parent parent object + * @param initData init data */ -VToolArc::VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem *parent) - : VAbstractSpline(doc, data, id, parent) +VToolArc::VToolArc(const VToolArcInitData &initData, QGraphicsItem *parent) + : VAbstractSpline(initData.doc, initData.data, initData.id, parent) { sceneType = SceneObject::Arc; this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -110,14 +105,21 @@ VToolArc* VToolArc::Create(QSharedPointer dialog, VMainGraphicsScene SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 center = dialogTool->GetCenter(); - QString radius = dialogTool->GetRadius(); - QString f1 = dialogTool->GetF1(); - QString f2 = dialogTool->GetF2(); - const QString color = dialogTool->GetColor(); - const QString penStyle = dialogTool->GetPenStyle(); - VToolArc* point = Create(0, center, radius, f1, f2, color, penStyle, scene, doc, data, Document::FullParse, - Source::FromGui); + + VToolArcInitData initData; + initData.center = dialogTool->GetCenter(); + initData.radius = dialogTool->GetRadius(); + initData.f1 = dialogTool->GetF1(); + initData.f2 = dialogTool->GetF2(); + initData.color = dialogTool->GetColor(); + initData.penStyle = dialogTool->GetPenStyle(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolArc* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -128,56 +130,45 @@ VToolArc* VToolArc::Create(QSharedPointer dialog, VMainGraphicsScene //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool form GUI. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param center id arc center point. - * @param radius arc radius. - * @param f1 start angle of arc. - * @param f2 end angle of arc. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, - const QString &color, const QString &penStyle, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) +VToolArc* VToolArc::Create(VToolArcInitData &initData) { qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; - calcRadius = qApp->toPixel(CheckFormula(_id, radius, data)); + calcRadius = qApp->toPixel(CheckFormula(initData.id, initData.radius, initData.data)); - calcF1 = CheckFormula(_id, f1, data); - calcF2 = CheckFormula(_id, f2, data); + calcF1 = CheckFormula(initData.id, initData.f1, initData.data); + calcF2 = CheckFormula(initData.id, initData.f2, initData.data); - const VPointF c = *data->GeometricObject(center); - VArc *arc = new VArc(c, calcRadius, radius, calcF1, f1, calcF2, f2 ); - arc->SetColor(color); - arc->SetPenStyle(penStyle); - quint32 id = _id; - if (typeCreation == Source::FromGui) + const VPointF c = *initData.data->GeometricObject(initData.center); + VArc *arc = new VArc(c, calcRadius, initData.radius, calcF1, initData.f1, calcF2, initData.f2 ); + arc->SetColor(initData.color); + arc->SetPenStyle(initData.penStyle); + + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(arc); - data->AddArc(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(arc); + initData.data->AddArc(initData.data->GeometricObject(initData.id), initData.id); } else { - data->UpdateGObject(id, arc); - data->AddArc(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, arc); + initData.data->AddArc(initData.data->GeometricObject(initData.id), initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Arc, doc); - VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); - scene->addItem(toolArc); - InitArcToolConnections(scene, toolArc); - VAbstractPattern::AddTool(id, toolArc); - doc->IncrementReferens(c.getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::Arc, initData.doc); + VToolArc *toolArc = new VToolArc(initData); + initData.scene->addItem(toolArc); + InitArcToolConnections(initData.scene, toolArc); + VAbstractPattern::AddTool(initData.id, toolArc); + initData.doc->IncrementReferens(c.getIdTool()); return toolArc; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h index 2e0ae4c04..031fac3b9 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.h @@ -43,6 +43,22 @@ class VFormula; template class QSharedPointer; +struct VToolArcInitData : public VAbstractSplineInitData +{ + VToolArcInitData() + : VAbstractSplineInitData(), + center(NULL_ID), + radius("0"), + f1("0"), + f2("0") + {} + + quint32 center; + QString radius; + QString f1; + QString f2; +}; + /** * @brief The VToolArc class tool for creation arc. */ @@ -53,9 +69,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolArc* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolArc* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, QString &f2, - const QString &color, const QString &penStyle, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); + static VToolArc* Create(VToolArcInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -88,8 +102,7 @@ protected: private: Q_DISABLE_COPY(VToolArc) - VToolArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolArc(const VToolArcInitData &initData, QGraphicsItem * parent = nullptr); }; #endif // VTOOLARC_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index d8493b20e..fd513ae21 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -59,15 +59,14 @@ const QString VToolArcWithLength::ToolType = QStringLiteral("arcWithLength"); //--------------------------------------------------------------------------------------------------------------------- -VToolArcWithLength::VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem *parent) - :VAbstractSpline(doc, data, id, parent) +VToolArcWithLength::VToolArcWithLength(const VToolArcWithLengthInitData &initData, QGraphicsItem *parent) + :VAbstractSpline(initData.doc, initData.data, initData.id, parent) { sceneType = SceneObject::Arc; this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -92,14 +91,21 @@ VToolArcWithLength *VToolArcWithLength::Create(QSharedPointer dialog SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 center = dialogTool->GetCenter(); - QString radius = dialogTool->GetRadius(); - QString f1 = dialogTool->GetF1(); - QString length = dialogTool->GetLength(); - const QString color = dialogTool->GetColor(); - const QString penStyle = dialogTool->GetPenStyle(); - VToolArcWithLength* point = Create(0, center, radius, f1, length, color, penStyle, scene, doc, data, - Document::FullParse, Source::FromGui); + + VToolArcWithLengthInitData initData; + initData.center = dialogTool->GetCenter(); + initData.radius = dialogTool->GetRadius(); + initData.f1 = dialogTool->GetF1(); + initData.length = dialogTool->GetLength(); + initData.color = dialogTool->GetColor(); + initData.penStyle = dialogTool->GetPenStyle(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolArcWithLength* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -108,45 +114,42 @@ VToolArcWithLength *VToolArcWithLength::Create(QSharedPointer dialog } //--------------------------------------------------------------------------------------------------------------------- -VToolArcWithLength *VToolArcWithLength::Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, - QString &length, const QString &color, const QString &penStyle, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolArcWithLength *VToolArcWithLength::Create(VToolArcWithLengthInitData &initData) { qreal calcRadius = 0, calcF1 = 0, calcLength = 0; - calcRadius = qApp->toPixel(CheckFormula(_id, radius, data)); - calcLength = qApp->toPixel(CheckFormula(_id, length, data)); - calcF1 = CheckFormula(_id, f1, data); + calcRadius = qApp->toPixel(CheckFormula(initData.id, initData.radius, initData.data)); + calcLength = qApp->toPixel(CheckFormula(initData.id, initData.length, initData.data)); + calcF1 = CheckFormula(initData.id, initData.f1, initData.data); - const VPointF c = *data->GeometricObject(center); - VArc *arc = new VArc(calcLength, length, c, calcRadius, radius, calcF1, f1); - arc->SetColor(color); - arc->SetPenStyle(penStyle); - quint32 id = _id; - if (typeCreation == Source::FromGui) + const VPointF c = *initData.data->GeometricObject(initData.center); + VArc *arc = new VArc(calcLength, initData.length, c, calcRadius, initData.radius, calcF1, initData.f1); + arc->SetColor(initData.color); + arc->SetPenStyle(initData.penStyle); + + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(arc); - data->AddArc(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(arc); + initData.data->AddArc(initData.data->GeometricObject(initData.id), initData.id); } else { - data->UpdateGObject(id, arc); - data->AddArc(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, arc); + initData.data->AddArc(initData.data->GeometricObject(initData.id), initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::ArcWithLength, doc); - VToolArcWithLength *toolArc = new VToolArcWithLength(doc, data, id, typeCreation); - scene->addItem(toolArc); - InitArcToolConnections(scene, toolArc); - VAbstractPattern::AddTool(id, toolArc); - doc->IncrementReferens(c.getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::ArcWithLength, initData.doc); + VToolArcWithLength *toolArc = new VToolArcWithLength(initData); + initData.scene->addItem(toolArc); + InitArcToolConnections(initData.scene, toolArc); + VAbstractPattern::AddTool(initData.id, toolArc); + initData.doc->IncrementReferens(c.getIdTool()); return toolArc; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h index fe1f70857..b2accec77 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.h @@ -43,6 +43,22 @@ class VFormula; template class QSharedPointer; +struct VToolArcWithLengthInitData : public VAbstractSplineInitData +{ + VToolArcWithLengthInitData() + : VAbstractSplineInitData(), + center(NULL_ID), + radius("0"), + f1("0"), + length("0") + {} + + quint32 center; + QString radius; + QString f1; + QString length; +}; + class VToolArcWithLength : public VAbstractSpline { Q_OBJECT @@ -50,10 +66,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolArcWithLength* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolArcWithLength* Create(const quint32 _id, const quint32 ¢er, QString &radius, QString &f1, - QString &length, const QString &color, const QString &penStyle, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolArcWithLength* Create(VToolArcWithLengthInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -86,8 +99,7 @@ protected: private: Q_DISABLE_COPY(VToolArcWithLength) - VToolArcWithLength(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolArcWithLength(const VToolArcWithLengthInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLARCWITHLENGTH_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp index 690653db1..71cd2547c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp @@ -57,15 +57,14 @@ const QString VToolCubicBezier::ToolType = QStringLiteral("cubicBezier"); //--------------------------------------------------------------------------------------------------------------------- -VToolCubicBezier::VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, - const Source &typeCreation, QGraphicsItem *parent) - :VAbstractSpline(doc, data, id, parent) +VToolCubicBezier::VToolCubicBezier(const VToolCubicBezierInitData &initData, QGraphicsItem *parent) + :VAbstractSpline(initData.doc, initData.data, initData.id, parent) { sceneType = SceneObject::Spline; this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -88,11 +87,17 @@ VToolCubicBezier *VToolCubicBezier::Create(QSharedPointer dialog, VM QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - VCubicBezier *spline = new VCubicBezier(dialogTool->GetSpline()); - spline->SetColor(dialogTool->GetColor()); - spline->SetPenStyle(dialogTool->GetPenStyle()); + VToolCubicBezierInitData initData; + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + initData.spline = new VCubicBezier(dialogTool->GetSpline()); + initData.spline->SetColor(dialogTool->GetColor()); + initData.spline->SetPenStyle(dialogTool->GetPenStyle()); - auto spl = Create(0, spline, scene, doc, data, Document::FullParse, Source::FromGui); + auto spl = Create(initData); if (spl != nullptr) { @@ -102,37 +107,34 @@ VToolCubicBezier *VToolCubicBezier::Create(QSharedPointer dialog, VM } //--------------------------------------------------------------------------------------------------------------------- -VToolCubicBezier *VToolCubicBezier::Create(const quint32 _id, VCubicBezier *spline, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolCubicBezier *VToolCubicBezier::Create(VToolCubicBezierInitData initData) { - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(spline); - data->AddSpline(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(initData.spline); + initData.data->AddSpline(initData.data->GeometricObject(initData.id), initData.id); } else { - data->UpdateGObject(id, spline); - data->AddSpline(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, initData.spline); + initData.data->AddSpline(initData.data->GeometricObject(initData.id), initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::CubicBezier, doc); - auto _spl = new VToolCubicBezier(doc, data, id, typeCreation); - scene->addItem(_spl); - InitSplineToolConnections(scene, _spl); - VAbstractPattern::AddTool(id, _spl); - doc->IncrementReferens(spline->GetP1().getIdTool()); - doc->IncrementReferens(spline->GetP1().getIdTool()); - doc->IncrementReferens(spline->GetP1().getIdTool()); - doc->IncrementReferens(spline->GetP4().getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::CubicBezier, initData.doc); + auto _spl = new VToolCubicBezier(initData); + initData.scene->addItem(_spl); + InitSplineToolConnections(initData.scene, _spl); + VAbstractPattern::AddTool(initData.id, _spl); + initData.doc->IncrementReferens(initData.spline->GetP1().getIdTool()); + initData.doc->IncrementReferens(initData.spline->GetP1().getIdTool()); + initData.doc->IncrementReferens(initData.spline->GetP1().getIdTool()); + initData.doc->IncrementReferens(initData.spline->GetP4().getIdTool()); return _spl; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h index 8f3750f66..95e992a88 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.h @@ -43,6 +43,16 @@ class VCubicBezier; template class QSharedPointer; +struct VToolCubicBezierInitData : public VAbstractToolInitData +{ + VToolCubicBezierInitData() + : VAbstractToolInitData(), + spline(nullptr) + {} + + VCubicBezier *spline; +}; + class VToolCubicBezier : public VAbstractSpline { Q_OBJECT @@ -51,9 +61,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolCubicBezier *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCubicBezier *Create(const quint32 _id, VCubicBezier *spline, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolCubicBezier *Create(VToolCubicBezierInitData initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::CubicBezier)}; @@ -78,8 +86,7 @@ protected: private: Q_DISABLE_COPY(VToolCubicBezier) - VToolCubicBezier(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolCubicBezier(const VToolCubicBezierInitData &initData, QGraphicsItem *parent = nullptr); void SetSplineAttributes(QDomElement &domElement, const VCubicBezier &spl); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp index 56eb7bcbf..a8b0a6601 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp @@ -59,15 +59,14 @@ const QString VToolCubicBezierPath::ToolType = QStringLiteral("cubicBezierPath"); //--------------------------------------------------------------------------------------------------------------------- -VToolCubicBezierPath::VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, - const Source &typeCreation, QGraphicsItem *parent) - : VAbstractSpline(doc, data, id, parent) +VToolCubicBezierPath::VToolCubicBezierPath(const VToolCubicBezierPathInitData &initData, QGraphicsItem *parent) + : VAbstractSpline(initData.doc, initData.data, initData.id, parent) { sceneType = SceneObject::SplinePath; this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -89,17 +88,25 @@ VToolCubicBezierPath *VToolCubicBezierPath::Create(QSharedPointer di SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - auto path = new VCubicBezierPath(dialogTool->GetPath()); + + VToolCubicBezierPathInitData initData; + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + initData.path = new VCubicBezierPath(dialogTool->GetPath()); const QString color = dialogTool->GetColor(); const QString penStyle = dialogTool->GetPenStyle(); - for (qint32 i = 0; i < path->CountPoints(); ++i) + for (qint32 i = 0; i < initData.path->CountPoints(); ++i) { - doc->IncrementReferens((*path)[i].getIdTool()); + doc->IncrementReferens((*initData.path)[i].getIdTool()); } - path->SetColor(color); - path->SetPenStyle(penStyle); + initData.path->SetColor(color); + initData.path->SetPenStyle(penStyle); - VToolCubicBezierPath* spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui); + VToolCubicBezierPath* spl = Create(initData); if (spl != nullptr) { spl->m_dialog = dialogTool; @@ -108,33 +115,32 @@ VToolCubicBezierPath *VToolCubicBezierPath::Create(QSharedPointer di } //--------------------------------------------------------------------------------------------------------------------- -VToolCubicBezierPath *VToolCubicBezierPath::Create(const quint32 _id, VCubicBezierPath *path, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolCubicBezierPath *VToolCubicBezierPath::Create(VToolCubicBezierPathInitData initData) { - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(path); - data->AddCurveWithSegments(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(initData.path); + initData.data->AddCurveWithSegments(initData.data->GeometricObject(initData.id), + initData.id); } else { - data->UpdateGObject(id, path); - data->AddCurveWithSegments(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, initData.path); + initData.data->AddCurveWithSegments(initData.data->GeometricObject(initData.id), + initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::CubicBezierPath, doc); - VToolCubicBezierPath *spl = new VToolCubicBezierPath(doc, data, id, typeCreation); - scene->addItem(spl); - InitSplinePathToolConnections(scene, spl); - VAbstractPattern::AddTool(id, spl); + VAbstractTool::AddRecord(initData.id, Tool::CubicBezierPath, initData.doc); + VToolCubicBezierPath *spl = new VToolCubicBezierPath(initData); + initData.scene->addItem(spl); + InitSplinePathToolConnections(initData.scene, spl); + VAbstractPattern::AddTool(initData.id, spl); return spl; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h index 77ced21be..97cc6cf04 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.h @@ -43,6 +43,16 @@ class VCubicBezierPath; template class QSharedPointer; +struct VToolCubicBezierPathInitData : public VAbstractToolInitData +{ + VToolCubicBezierPathInitData() + : VAbstractToolInitData(), + path(nullptr) + {} + + VCubicBezierPath *path; +}; + class VToolCubicBezierPath:public VAbstractSpline { Q_OBJECT @@ -51,9 +61,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolCubicBezierPath *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCubicBezierPath *Create(const quint32 _id, VCubicBezierPath *path, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolCubicBezierPath *Create(VToolCubicBezierPathInitData initData); static const QString ToolType; static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VCubicBezierPath &path); @@ -75,8 +83,7 @@ protected: private: Q_DISABLE_COPY(VToolCubicBezierPath) - VToolCubicBezierPath(VAbstractPattern *doc, VContainer *data, quint32 id, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolCubicBezierPath(const VToolCubicBezierPathInitData &initData, QGraphicsItem * parent = nullptr); static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VPointF &splPoint); void SetSplinePathAttributes(QDomElement &domElement, const VCubicBezierPath &path); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp index 9f707d428..29ae8a164 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp @@ -61,21 +61,17 @@ const QString VToolEllipticalArc::ToolType = QStringLiteral("simple"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolEllipticalArc constuctor. - * @param doc dom document container - * @param data container with variables - * @param id object id in container - * @param typeCreation way we create this tool. + * @param initData init data * @param parent parent object */ -VToolEllipticalArc::VToolEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem *parent) - :VAbstractSpline(doc, data, id, parent) +VToolEllipticalArc::VToolEllipticalArc(const VToolEllipticalArcInitData &initData, QGraphicsItem *parent) + :VAbstractSpline(initData.doc, initData.data, initData.id, parent) { sceneType = SceneObject::ElArc; this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -113,16 +109,22 @@ VToolEllipticalArc* VToolEllipticalArc::Create(QSharedPointer dialog QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 center = dialogTool->GetCenter(); - QString radius1 = dialogTool->GetRadius1(); - QString radius2 = dialogTool->GetRadius2(); - QString f1 = dialogTool->GetF1(); - QString f2 = dialogTool->GetF2(); - QString rotationAngle = dialogTool->GetRotationAngle(); - const QString color = dialogTool->GetColor(); - const QString penStyle = dialogTool->GetPenStyle(); - VToolEllipticalArc* point = Create(0, center, radius1, radius2, f1, f2, rotationAngle, color, penStyle, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolEllipticalArcInitData initData; + initData.center = dialogTool->GetCenter(); + initData.radius1 = dialogTool->GetRadius1(); + initData.radius2 = dialogTool->GetRadius2(); + initData.f1 = dialogTool->GetF1(); + initData.f2 = dialogTool->GetF2(); + initData.rotationAngle = dialogTool->GetRotationAngle(); + initData.color = dialogTool->GetColor(); + initData.penStyle = dialogTool->GetPenStyle(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolEllipticalArc* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -134,63 +136,49 @@ VToolEllipticalArc* VToolEllipticalArc::Create(QSharedPointer dialog //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool form GUI. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param center id elliptical arc center point. - * @param radius1 elliptical arc radius1. - * @param radius2 elliptical arc radius2. - * @param f1 start angle of elliptical arc. - * @param f2 end angle of elliptical arc. - * @param rotationAngle rotation angle of elliptical arc. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolEllipticalArc* VToolEllipticalArc::Create(const quint32 _id, const quint32 ¢er, QString &radius1, - QString &radius2, QString &f1, QString &f2, QString &rotationAngle, - const QString &color, const QString &penStyle, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolEllipticalArc* VToolEllipticalArc::Create(VToolEllipticalArcInitData &initData) { qreal calcRadius1 = 0, calcRadius2 = 0, calcF1 = 0, calcF2 = 0, calcRotationAngle = 0; - calcRadius1 = qApp->toPixel(CheckFormula(_id, radius1, data)); - calcRadius2 = qApp->toPixel(CheckFormula(_id, radius2, data)); + calcRadius1 = qApp->toPixel(CheckFormula(initData.id, initData.radius1, initData.data)); + calcRadius2 = qApp->toPixel(CheckFormula(initData.id, initData.radius2, initData.data)); - calcF1 = CheckFormula(_id, f1, data); - calcF2 = CheckFormula(_id, f2, data); - calcRotationAngle = CheckFormula(_id, rotationAngle, data); + calcF1 = CheckFormula(initData.id, initData.f1, initData.data); + calcF2 = CheckFormula(initData.id, initData.f2, initData.data); + calcRotationAngle = CheckFormula(initData.id, initData.rotationAngle, initData.data); - const VPointF c = *data->GeometricObject(center); - VEllipticalArc *elArc = new VEllipticalArc(c, calcRadius1, calcRadius2, radius1, radius2, calcF1, f1, calcF2, f2, - calcRotationAngle, rotationAngle); - elArc->SetColor(color); - elArc->SetPenStyle(penStyle); - quint32 id = _id; - if (typeCreation == Source::FromGui) + const VPointF c = *initData.data->GeometricObject(initData.center); + VEllipticalArc *elArc = new VEllipticalArc(c, calcRadius1, calcRadius2, initData.radius1, initData.radius2, calcF1, + initData.f1, calcF2, initData.f2, calcRotationAngle, + initData.rotationAngle); + elArc->SetColor(initData.color); + elArc->SetPenStyle(initData.penStyle); + + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(elArc); - data->AddArc(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(elArc); + initData.data->AddArc(initData.data->GeometricObject(initData.id), initData.id); } else { - data->UpdateGObject(id, elArc); - data->AddArc(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, elArc); + initData.data->AddArc(initData.data->GeometricObject(initData.id), initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::EllipticalArc, doc); - VToolEllipticalArc *toolEllipticalArc = new VToolEllipticalArc(doc, data, id, typeCreation); - scene->addItem(toolEllipticalArc); - InitElArcToolConnections(scene, toolEllipticalArc); - VAbstractPattern::AddTool(id, toolEllipticalArc); - doc->IncrementReferens(c.getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::EllipticalArc, initData.doc); + VToolEllipticalArc *toolEllipticalArc = new VToolEllipticalArc(initData); + initData.scene->addItem(toolEllipticalArc); + InitElArcToolConnections(initData.scene, toolEllipticalArc); + VAbstractPattern::AddTool(initData.id, toolEllipticalArc); + initData.doc->IncrementReferens(c.getIdTool()); return toolEllipticalArc; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h index 4802c9643..dcd327a32 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.h @@ -43,6 +43,26 @@ class VFormula; template class QSharedPointer; +struct VToolEllipticalArcInitData : public VAbstractSplineInitData +{ + VToolEllipticalArcInitData() + : VAbstractSplineInitData(), + center(NULL_ID), + radius1("0"), + radius2("0"), + f1("0"), + f2("0"), + rotationAngle("0") + {} + + quint32 center; + QString radius1; + QString radius2; + QString f1; + QString f2; + QString rotationAngle; +}; + /** * @brief The VToolEllipticalArc class tool for creation elliptical arc. */ @@ -53,11 +73,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolEllipticalArc* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolEllipticalArc* Create(const quint32 _id, const quint32 ¢er, QString &radius1, QString &radius2, - QString &f1, QString &f2, QString &rotationAngle, const QString &color, - const QString &penStyle, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolEllipticalArc* Create(VToolEllipticalArcInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::EllipticalArc)}; @@ -95,8 +111,7 @@ protected: private: Q_DISABLE_COPY(VToolEllipticalArc) - VToolEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolEllipticalArc(const VToolEllipticalArcInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLELLIPTICALARC_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index b8903244c..b195cd143 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -74,22 +74,19 @@ const QString VToolSpline::OldToolType = QStringLiteral("simple"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolSpline constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem *parent) - :VAbstractSpline(doc, data, id, parent), oldPosition() +VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent) + : VAbstractSpline(initData.doc, initData.data, initData.id, parent), + oldPosition() { sceneType = SceneObject::Spline; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - const auto spl = VAbstractTool::data.GeometricObject(id); + const auto spl = VAbstractTool::data.GeometricObject(initData.id); const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula()); const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula()); @@ -119,7 +116,7 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co ShowHandles(false); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -153,11 +150,18 @@ VToolSpline* VToolSpline::Create(QSharedPointer dialog, VMainGraphic QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) + VToolSplineInitData initData; + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + VSpline *spline = new VSpline(dialogTool->GetSpline()); spline->SetColor(dialogTool->GetColor()); spline->SetPenStyle(dialogTool->GetPenStyle()); - auto spl = Create(0, spline, scene, doc, data, Document::FullParse, Source::FromGui); + auto spl = Create(initData, spline); if (spl != nullptr) { @@ -169,74 +173,64 @@ VToolSpline* VToolSpline::Create(QSharedPointer dialog, VMainGraphic //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. + * @param initData init data. * @param spline spline. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. * @return the created tool */ -VToolSpline* VToolSpline::Create(const quint32 _id, VSpline *spline, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolSpline* VToolSpline::Create(VToolSplineInitData &initData, VSpline *spline) { - quint32 id = _id; - - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(spline); - data->AddSpline(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(spline); + initData.data->AddSpline(initData.data->GeometricObject(initData.id), initData.id); } else { - data->UpdateGObject(id, spline); - data->AddSpline(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, spline); + initData.data->AddSpline(initData.data->GeometricObject(initData.id), initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Spline, doc); - auto _spl = new VToolSpline(doc, data, id, typeCreation); - scene->addItem(_spl); - InitSplineToolConnections(scene, _spl); - VAbstractPattern::AddTool(id, _spl); - doc->IncrementReferens(spline->GetP1().getIdTool()); - doc->IncrementReferens(spline->GetP4().getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::Spline, initData.doc); + auto _spl = new VToolSpline(initData); + initData.scene->addItem(_spl); + InitSplineToolConnections(initData.scene, _spl); + VAbstractPattern::AddTool(initData.id, _spl); + initData.doc->IncrementReferens(spline->GetP1().getIdTool()); + initData.doc->IncrementReferens(spline->GetP4().getIdTool()); return _spl; } return nullptr; } //--------------------------------------------------------------------------------------------------------------------- -VToolSpline *VToolSpline::Create(const quint32 _id, quint32 point1, quint32 point4, QString &a1, QString &a2, - QString &l1, QString &l2, quint32 duplicate, const QString &color, - const QString &penStyle, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolSpline *VToolSpline::Create(VToolSplineInitData &initData) { - const qreal calcAngle1 = CheckFormula(_id, a1, data); - const qreal calcAngle2 = CheckFormula(_id, a2, data); + const qreal calcAngle1 = CheckFormula(initData.id, initData.a1, initData.data); + const qreal calcAngle2 = CheckFormula(initData.id, initData.a2, initData.data); - const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1, data)); - const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2, data)); + const qreal calcLength1 = qApp->toPixel(CheckFormula(initData.id, initData.l1, initData.data)); + const qreal calcLength2 = qApp->toPixel(CheckFormula(initData.id, initData.l2, initData.data)); - auto p1 = data->GeometricObject(point1); - auto p4 = data->GeometricObject(point4); + auto p1 = initData.data->GeometricObject(initData.point1); + auto p4 = initData.data->GeometricObject(initData.point4); - auto spline = new VSpline(*p1, *p4, calcAngle1, a1, calcAngle2, a2, calcLength1, l1, calcLength2, l2); - if (duplicate > 0) + auto spline = new VSpline(*p1, *p4, calcAngle1, initData.a1, calcAngle2, initData.a2, calcLength1, initData.l1, + calcLength2, initData.l2); + if (initData.duplicate > 0) { - spline->SetDuplicate(duplicate); + spline->SetDuplicate(initData.duplicate); } - spline->SetColor(color); - spline->SetPenStyle(penStyle); + spline->SetColor(initData.color); + spline->SetPenStyle(initData.penStyle); - return VToolSpline::Create(_id, spline, scene, doc, data, parse, typeCreation); + return VToolSpline::Create(initData, spline); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index cddeaab28..6c1688827 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -44,6 +44,28 @@ template class QSharedPointer; +struct VToolSplineInitData : public VAbstractSplineInitData +{ + VToolSplineInitData() + : VAbstractSplineInitData(), + point1(NULL_ID), + point4(NULL_ID), + a1(), + a2(), + l1(), + l2(), + duplicate(0) + {} + + quint32 point1; + quint32 point4; + QString a1; + QString a2; + QString l1; + QString l2; + quint32 duplicate; +}; + /** * @brief The VToolSpline class tool for creation spline. I mean bezier curve. */ @@ -55,13 +77,8 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolSpline *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolSpline *Create(const quint32 _id, VSpline *spline, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); - static VToolSpline *Create(const quint32 _id, quint32 point1, quint32 point4, QString &a1, QString &a2, QString &l1, - QString &l2, quint32 duplicate, const QString &color, const QString &penStyle, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolSpline *Create(VToolSplineInitData &initData, VSpline *spline); + static VToolSpline *Create(VToolSplineInitData &initData); static const QString ToolType; static const QString OldToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -92,8 +109,7 @@ private: Q_DISABLE_COPY(VToolSpline) QPointF oldPosition; - VToolSpline (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem * parent = nullptr ); + VToolSpline (VToolSplineInitData initData, QGraphicsItem *parent = nullptr ); bool IsMovable() const; void SetSplineAttributes(QDomElement &domElement, const VSpline &spl); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index 619e130f5..025481e46 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -79,15 +79,11 @@ const QString VToolSplinePath::OldToolType = QStringLiteral("path"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolSplinePath constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem *parent) - : VAbstractSpline(doc, data, id, parent), +VToolSplinePath::VToolSplinePath(const VToolSplinePathInitData &initData, QGraphicsItem *parent) + : VAbstractSpline(initData.doc, initData.data, initData.id, parent), oldPosition(), splIndex(-1) { @@ -96,7 +92,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - const QSharedPointer splPath = data->GeometricObject(id); + const QSharedPointer splPath = initData.data->GeometricObject(initData.id); for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { const VSpline spl = splPath->GetSpline(i); @@ -128,7 +124,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 ShowHandles(false); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -160,6 +156,14 @@ VToolSplinePath* VToolSplinePath::Create(QSharedPointer dialog, VMai SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) + + VToolSplinePathInitData initData; + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + VSplinePath *path = new VSplinePath(dialogTool->GetPath()); for (qint32 i = 0; i < path->CountPoints(); ++i) { @@ -169,7 +173,7 @@ VToolSplinePath* VToolSplinePath::Create(QSharedPointer dialog, VMai path->SetColor(dialogTool->GetColor()); path->SetPenStyle(dialogTool->GetPenStyle()); - VToolSplinePath* spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui); + VToolSplinePath* spl = Create(initData, path); if (spl != nullptr) { spl->m_dialog = dialogTool; @@ -180,79 +184,69 @@ VToolSplinePath* VToolSplinePath::Create(QSharedPointer dialog, VMai //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. + * @param initData init data. * @param path spline path. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. * @param typeCreation way we create this tool. */ -VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolSplinePath* VToolSplinePath::Create(VToolSplinePathInitData &initData, VSplinePath *path) { - quint32 id = _id; - - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(path); - data->AddCurveWithSegments(data->GeometricObject(id), id); + initData.id = initData.data->AddGObject(path); + initData.data->AddCurveWithSegments(initData.data->GeometricObject(initData.id), + initData.id); } else { - data->UpdateGObject(id, path); - data->AddCurveWithSegments(data->GeometricObject(id), id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, path); + initData.data->AddCurveWithSegments(initData.data->GeometricObject(initData.id), + initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::SplinePath, doc); - VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); - scene->addItem(spl); - InitSplinePathToolConnections(scene, spl); - VAbstractPattern::AddTool(id, spl); + VAbstractTool::AddRecord(initData.id, Tool::SplinePath, initData.doc); + VToolSplinePath *spl = new VToolSplinePath(initData); + initData.scene->addItem(spl); + InitSplinePathToolConnections(initData.scene, spl); + VAbstractPattern::AddTool(initData.id, spl); return spl; } return nullptr; } //--------------------------------------------------------------------------------------------------------------------- -VToolSplinePath *VToolSplinePath::Create(const quint32 _id, const QVector &points, QVector &a1, - QVector &a2, QVector &l1, QVector &l2, - const QString &color, const QString &penStyle, quint32 duplicate, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolSplinePath *VToolSplinePath::Create(VToolSplinePathInitData &initData) { auto path = new VSplinePath(); - if (duplicate > 0) + if (initData.duplicate > 0) { - path->SetDuplicate(duplicate); + path->SetDuplicate(initData.duplicate); } - for (int i = 0; i < points.size(); ++i) + for (int i = 0; i < initData.points.size(); ++i) { - const qreal calcAngle1 = CheckFormula(_id, a1[i], data); - const qreal calcAngle2 = CheckFormula(_id, a2[i], data); + const qreal calcAngle1 = CheckFormula(initData.id, initData.a1[i], initData.data); + const qreal calcAngle2 = CheckFormula(initData.id, initData.a2[i], initData.data); - const qreal calcLength1 = qApp->toPixel(CheckFormula(_id, l1[i], data)); - const qreal calcLength2 = qApp->toPixel(CheckFormula(_id, l2[i], data)); + const qreal calcLength1 = qApp->toPixel(CheckFormula(initData.id, initData.l1[i], initData.data)); + const qreal calcLength2 = qApp->toPixel(CheckFormula(initData.id, initData.l2[i], initData.data)); - const auto p = *data->GeometricObject(points.at(i)); + const auto p = *initData.data->GeometricObject(initData.points.at(i)); - path->append(VSplinePoint(p, calcAngle1, a1.at(i), calcAngle2, a2.at(i), calcLength1, l1.at(i), calcLength2, - l2.at(i))); + path->append(VSplinePoint(p, calcAngle1, initData.a1.at(i), calcAngle2, initData.a2.at(i), calcLength1, + initData.l1.at(i), calcLength2, initData.l2.at(i))); } - path->SetColor(color); - path->SetPenStyle(penStyle); + path->SetColor(initData.color); + path->SetPenStyle(initData.penStyle); - return VToolSplinePath::Create(_id, path, scene, doc, data, parse, typeCreation); + return VToolSplinePath::Create(initData, path); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index c6cba6075..06548fe82 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -46,6 +46,26 @@ class VSplinePath; template class QSharedPointer; +struct VToolSplinePathInitData : public VAbstractSplineInitData +{ + VToolSplinePathInitData() + : VAbstractSplineInitData(), + points(), + a1(), + a2(), + l1(), + l2(), + duplicate(0) + {} + + QVector points; + QVector a1; + QVector a2; + QVector l1; + QVector l2; + quint32 duplicate; +}; + /** * @brief The VToolSplinePath class tool for creation spline path. */ @@ -57,14 +77,8 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolSplinePath *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); - static VToolSplinePath *Create(const quint32 _id, const QVector &points, QVector &a1, - QVector &a2, QVector &l1, QVector &l2, - const QString &color, const QString &penStyle, quint32 duplicate, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolSplinePath *Create(VToolSplinePathInitData &initData, VSplinePath *path); + static VToolSplinePath *Create(VToolSplinePathInitData &initData); static const QString ToolType; static const QString OldToolType; static void UpdatePathPoints(VAbstractPattern *doc, QDomElement &element, const VSplinePath &path); @@ -108,8 +122,7 @@ private: QPointF oldPosition; int splIndex; - VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - QGraphicsItem *parent = nullptr); + VToolSplinePath(const VToolSplinePathInitData &initData, QGraphicsItem *parent = nullptr); bool IsMovable(int index) const; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp index 438513ca4..38fa56219 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp @@ -55,26 +55,15 @@ template class QSharedPointer; const QString VToolTrueDarts::ToolType = QStringLiteral("trueDarts"); //--------------------------------------------------------------------------------------------------------------------- -VToolTrueDarts::VToolTrueDarts(VAbstractPattern *doc, - VContainer *data, - const quint32 &id, - const quint32 &p1id, - const quint32 &p2id, - const quint32 &baseLineP1Id, - const quint32 &baseLineP2Id, - const quint32 &dartP1Id, - const quint32 &dartP2Id, - const quint32 &dartP3Id, - const Source &typeCreation, - QGraphicsItem *parent) - :VToolDoublePoint(doc, data, id, p1id, p2id, parent), - baseLineP1Id (baseLineP1Id), - baseLineP2Id(baseLineP2Id), - dartP1Id(dartP1Id), - dartP2Id(dartP2Id), - dartP3Id(dartP3Id) +VToolTrueDarts::VToolTrueDarts(const VToolTrueDartsInitData &initData, QGraphicsItem *parent) + :VToolDoublePoint(initData.doc, initData.data, initData.id, initData.p1id, initData.p2id, parent), + baseLineP1Id (initData.baseLineP1Id), + baseLineP2Id(initData.baseLineP2Id), + dartP1Id(initData.dartP1Id), + dartP2Id(initData.dartP2Id), + dartP3Id(initData.dartP3Id) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -128,17 +117,21 @@ VToolTrueDarts *VToolTrueDarts::Create(QSharedPointer dialog, VMainG QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString point1Name = dialogTool->GetFirstNewDartPointName(); - const QString point2Name = dialogTool->GetSecondNewDartPointName(); - const quint32 baseLineP1Id = dialogTool->GetFirstBasePointId(); - const quint32 baseLineP2Id = dialogTool->GetSecondBasePointId(); - const quint32 dartP1Id = dialogTool->GetFirstDartPointId(); - const quint32 dartP2Id = dialogTool->GetSecondDartPointId(); - const quint32 dartP3Id = dialogTool->GetThirdDartPointId(); + VToolTrueDartsInitData initData; + initData.name1 = dialogTool->GetFirstNewDartPointName(); + initData.name2 = dialogTool->GetSecondNewDartPointName(); + initData.baseLineP1Id = dialogTool->GetFirstBasePointId(); + initData.baseLineP2Id = dialogTool->GetSecondBasePointId(); + initData.dartP1Id = dialogTool->GetFirstDartPointId(); + initData.dartP2Id = dialogTool->GetSecondDartPointId(); + initData.dartP3Id = dialogTool->GetThirdDartPointId(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; - VToolTrueDarts *point = Create(0, 0, 0, baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id, - point1Name, 5, 10, point2Name, 5, 10, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolTrueDarts *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -147,61 +140,52 @@ VToolTrueDarts *VToolTrueDarts::Create(QSharedPointer dialog, VMainG } //--------------------------------------------------------------------------------------------------------------------- -VToolTrueDarts *VToolTrueDarts::Create(quint32 _id, - const quint32 &_p1id, const quint32 &_p2id, - const quint32 &baseLineP1Id, - const quint32 &baseLineP2Id, - const quint32 &dartP1Id, - const quint32 &dartP2Id, - const quint32 &dartP3Id, - const QString &point1Name, const qreal &mx1, const qreal &my1, - const QString &point2Name, const qreal &mx2, const qreal &my2, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolTrueDarts *VToolTrueDarts::Create(VToolTrueDartsInitData initData) { - const QSharedPointer baseLineP1 = data->GeometricObject(baseLineP1Id); - const QSharedPointer baseLineP2 = data->GeometricObject(baseLineP2Id); - const QSharedPointer dartP1 = data->GeometricObject(dartP1Id); - const QSharedPointer dartP2 = data->GeometricObject(dartP2Id); - const QSharedPointer dartP3 = data->GeometricObject(dartP3Id); + const QSharedPointer baseLineP1 = initData.data->GeometricObject(initData.baseLineP1Id); + const QSharedPointer baseLineP2 = initData.data->GeometricObject(initData.baseLineP2Id); + const QSharedPointer dartP1 = initData.data->GeometricObject(initData.dartP1Id); + const QSharedPointer dartP2 = initData.data->GeometricObject(initData.dartP2Id); + const QSharedPointer dartP3 = initData.data->GeometricObject(initData.dartP3Id); QPointF fPoint1; QPointF fPoint2; VToolTrueDarts::FindPoint(static_cast(*baseLineP1), static_cast(*baseLineP2), static_cast(*dartP1), static_cast(*dartP2), static_cast(*dartP3), fPoint1, fPoint2); - quint32 id = _id; - quint32 p1id = _p1id; - quint32 p2id = _p2id; - if (typeCreation == Source::FromGui) + + if (initData.typeCreation == Source::FromGui) { - id = VContainer::getNextId();//Just reserve id for tool - p1id = data->AddGObject(new VPointF(fPoint1, point1Name, mx1, my1, id)); - p2id = data->AddGObject(new VPointF(fPoint2, point2Name, mx2, my2, id)); + initData.id = VContainer::getNextId();//Just reserve id for tool + initData.p1id = initData.data->AddGObject(new VPointF(fPoint1, initData.name1, initData.mx1, initData.my1, + initData.id)); + initData.p2id = initData.data->AddGObject(new VPointF(fPoint2, initData.name2, initData.mx2, initData.my2, + initData.id)); } else { - data->UpdateGObject(p1id, new VPointF(fPoint1, point1Name, mx1, my1, id)); - data->UpdateGObject(p2id, new VPointF(fPoint2, point2Name, mx2, my2, id)); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.p1id, new VPointF(fPoint1, initData.name1, initData.mx1, initData.my1, + initData.id)); + initData.data->UpdateGObject(initData.p2id, new VPointF(fPoint2, initData.name2, initData.mx2, initData.my2, + initData.id)); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::TrueDarts, doc); - VToolTrueDarts *points = new VToolTrueDarts(doc, data, id, p1id, p2id, baseLineP1Id, baseLineP2Id, - dartP1Id, dartP2Id, dartP3Id, typeCreation); - scene->addItem(points); - InitToolConnections(scene, points); - VAbstractPattern::AddTool(id, points); - doc->IncrementReferens(baseLineP1->getIdTool()); - doc->IncrementReferens(baseLineP2->getIdTool()); - doc->IncrementReferens(dartP1->getIdTool()); - doc->IncrementReferens(dartP2->getIdTool()); - doc->IncrementReferens(dartP3->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::TrueDarts, initData.doc); + VToolTrueDarts *points = new VToolTrueDarts(initData); + initData.scene->addItem(points); + InitToolConnections(initData.scene, points); + VAbstractPattern::AddTool(initData.id, points); + initData.doc->IncrementReferens(baseLineP1->getIdTool()); + initData.doc->IncrementReferens(baseLineP2->getIdTool()); + initData.doc->IncrementReferens(dartP1->getIdTool()); + initData.doc->IncrementReferens(dartP2->getIdTool()); + initData.doc->IncrementReferens(dartP3->getIdTool()); return points; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h index ab993334a..348a4341e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h @@ -44,6 +44,40 @@ template class QSharedPointer; +struct VToolTrueDartsInitData : public VAbstractToolInitData +{ + VToolTrueDartsInitData() + : VAbstractToolInitData(), + p1id(NULL_ID), + p2id(NULL_ID), + baseLineP1Id(NULL_ID), + baseLineP2Id(NULL_ID), + dartP1Id(NULL_ID), + dartP2Id(NULL_ID), + dartP3Id(NULL_ID), + name1(), + mx1(10), + my1(15), + name2(), + mx2(10), + my2(15) + {} + + quint32 p1id; + quint32 p2id; + quint32 baseLineP1Id; + quint32 baseLineP2Id; + quint32 dartP1Id; + quint32 dartP2Id; + quint32 dartP3Id; + QString name1; + qreal mx1; + qreal my1; + QString name2; + qreal mx2; + qreal my2; +}; + class VToolTrueDarts : public VToolDoublePoint { Q_OBJECT @@ -53,17 +87,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolTrueDarts* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolTrueDarts* Create(quint32 _id, - const quint32 &_p1id, const quint32 &_p2id, - const quint32 &baseLineP1Id, - const quint32 &baseLineP2Id, - const quint32 &dartP1Id, - const quint32 &dartP2Id, - const quint32 &dartP3Id, - const QString &point1Name, const qreal &mx1, const qreal &my1, - const QString &point2Name, const qreal &mx2, const qreal &my2, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolTrueDarts* Create(VToolTrueDartsInitData initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::TrueDarts)}; @@ -108,18 +132,7 @@ private: quint32 dartP2Id; quint32 dartP3Id; - VToolTrueDarts(VAbstractPattern *doc, - VContainer *data, - const quint32 &id, - const quint32 &p1id, - const quint32 &p2id, - const quint32 &baseLineP1Id, - const quint32 &baseLineP2Id, - const quint32 &dartP1Id, - const quint32 &dartP2Id, - const quint32 &dartP3Id, - const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolTrueDarts(const VToolTrueDartsInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLTRUEDARTS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 181f6b5f2..a867961e2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -59,19 +59,13 @@ const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolCutArc constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param formula string with formula length first arc. - * @param arcId id arc in data container. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolCutArc::VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &arcId, const Source &typeCreation, QGraphicsItem * parent) - :VToolCut(doc, data, id, formula, arcId, parent) +VToolCutArc::VToolCutArc(const VToolCutArcInitData &initData, QGraphicsItem * parent) + :VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.arcId, parent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -103,11 +97,18 @@ VToolCutArc* VToolCutArc::Create(QSharedPointer dialog, VMainGraphic SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - QString formula = dialogTool->GetFormula(); - const quint32 arcId = dialogTool->getArcId(); - VToolCutArc* point = Create(0, pointName, formula, arcId, 5, 10, true, scene, doc, data, Document::FullParse, - Source::FromGui); + + VToolCutArcInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.arcId = dialogTool->getArcId(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolCutArc* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -118,67 +119,54 @@ VToolCutArc* VToolCutArc::Create(QSharedPointer dialog, VMainGraphic //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. - * @param formula string with formula length first arc. - * @param arcId id arc in data container. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. + * @param initData init data. * @param typeCreation way we create this tool. */ -VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QString &formula, quint32 arcId, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData) { - const QSharedPointer arc = data->GeometricObject(arcId); + const QSharedPointer arc = initData.data->GeometricObject(initData.arcId); - const qreal result = CheckFormula(_id, formula, data); + const qreal result = CheckFormula(initData.id, initData.formula, initData.data); VArc arc1; VArc arc2; QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2); - quint32 id = _id; - - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); auto a1 = QSharedPointer(new VArc(arc1)); auto a2 = QSharedPointer(new VArc(arc2)); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); a1->setId(VContainer::getNextId()); a2->setId(VContainer::getNextId()); - data->AddArc(a1, a1->id(), id); - data->AddArc(a2, a2->id(), id); + initData.data->AddArc(a1, a1->id(), initData.id); + initData.data->AddArc(a2, a2->id(), initData.id); } else { - data->UpdateGObject(id, p); - a1->setId(id + 1); - a2->setId(id + 2); - data->AddArc(a1, a1->id(), id); - data->AddArc(a2, a2->id(), id); + initData.data->UpdateGObject(initData.id, p); + a1->setId(initData.id + 1); + a2->setId(initData.id + 2); + initData.data->AddArc(a1, a1->id(), initData.id); + initData.data->AddArc(a2, a2->id(), initData.id); - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::CutArc, doc); - VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(arc->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::CutArc, initData.doc); + VToolCutArc *point = new VToolCutArc(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(arc->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h index aa3eb0a53..92ffb4610 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h @@ -43,6 +43,18 @@ template class QSharedPointer; +struct VToolCutArcInitData : public VToolSinglePointInitData +{ + VToolCutArcInitData() + : VToolSinglePointInitData(), + formula(), + arcId(NULL_ID) + {} + + QString formula; + quint32 arcId; +}; + /** * @brief The VToolCutArc class tool for cutting arc. */ @@ -53,10 +65,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolCutArc* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCutArc* Create(const quint32 _id, const QString &pointName, QString &formula, quint32 arcId, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolCutArc* Create(VToolCutArcInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::CutArc)}; @@ -72,8 +81,7 @@ protected: private: Q_DISABLE_COPY(VToolCutArc) - VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &arcId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolCutArc(const VToolCutArcInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLCUTARC_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 9cff3d991..aa48d36ad 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -62,19 +62,13 @@ const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolCutSpline constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param formula string with formula length first spline. - * @param splineId id spline in data container. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolCutSpline::VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &splineId, const Source &typeCreation, QGraphicsItem *parent) - :VToolCut(doc, data, id, formula, splineId, parent) +VToolCutSpline::VToolCutSpline(const VToolCutSplineInitData &initData, QGraphicsItem *parent) + :VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.splineId, parent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -106,11 +100,18 @@ VToolCutSpline* VToolCutSpline::Create(QSharedPointer dialog, VMainG SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - QString formula = dialogTool->GetFormula(); - const quint32 splineId = dialogTool->getSplineId(); - VToolCutSpline* point = Create(0, pointName, formula, splineId, 5, 10, true, scene, doc, data, Document::FullParse, - Source::FromGui); + + VToolCutSplineInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.splineId = dialogTool->getSplineId(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolCutSpline* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -121,64 +122,49 @@ VToolCutSpline* VToolCutSpline::Create(QSharedPointer dialog, VMainG //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. - * @param formula string with formula length first spline. - * @param splineId id spline in data container. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula, - quint32 splineId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolCutSpline* VToolCutSpline::Create(VToolCutSplineInitData &initData) { - const auto spl = data->GeometricObject(splineId); + const auto spl = initData.data->GeometricObject(initData.splineId); - const qreal result = CheckFormula(_id, formula, data); + const qreal result = CheckFormula(initData.id, initData.formula, initData.data); QPointF spl1p2, spl1p3, spl2p2, spl2p3; QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3); - quint32 id = _id; - - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); auto spline1 = QSharedPointer(new VSpline(spl->GetP1(), spl1p2, spl1p3, *p)); auto spline2 = QSharedPointer(new VSpline(*p, spl2p2, spl2p3, spl->GetP4())); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddSpline(spline1, NULL_ID, id); - data->AddSpline(spline2, NULL_ID, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddSpline(spline1, NULL_ID, initData.id); + initData.data->AddSpline(spline2, NULL_ID, initData.id); } else { - data->UpdateGObject(id, p); - data->AddSpline(spline1, NULL_ID, id); - data->AddSpline(spline2, NULL_ID, id); + initData.data->UpdateGObject(initData.id, p); + initData.data->AddSpline(spline1, NULL_ID, initData.id); + initData.data->AddSpline(spline2, NULL_ID, initData.id); - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::CutSpline, doc); - VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(spl->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::CutSpline, initData.doc); + VToolCutSpline *point = new VToolCutSpline(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(spl->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h index 0c62c260e..793345cfe 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h @@ -43,6 +43,18 @@ template class QSharedPointer; +struct VToolCutSplineInitData : public VToolSinglePointInitData +{ + VToolCutSplineInitData() + : VToolSinglePointInitData(), + formula(), + splineId(NULL_ID) + {} + + QString formula; + quint32 splineId; +}; + /** * @brief The VToolCutSpline class for tool CutSpline. This tool find point on spline and cut spline on two. */ @@ -53,11 +65,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolCutSpline *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCutSpline *Create(const quint32 _id, const QString &pointName, QString &formula, - quint32 splineId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation); + static VToolCutSpline *Create(VToolCutSplineInitData &initData); static const QString ToolType; static const QString AttrSpline; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -74,8 +82,7 @@ protected: private: Q_DISABLE_COPY(VToolCutSpline) - VToolCutSpline(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &splineId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolCutSpline(const VToolCutSplineInitData &initData, QGraphicsItem * parent = nullptr); }; #endif // VTOOLCUTSPLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index b49029f07..37e4c744f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -65,20 +65,13 @@ const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolCutSplinePath constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param formula string with formula length first splinePath. - * @param splinePathId id splinePath (we cut this splinePath) in data container. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolCutSplinePath::VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const QString &formula, const quint32 &splinePathId, - const Source &typeCreation, QGraphicsItem *parent) - :VToolCut(doc, data, id, formula, splinePathId, parent) +VToolCutSplinePath::VToolCutSplinePath(const VToolCutSplinePathInitData &initData, QGraphicsItem *parent) + :VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.splinePathId, parent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -110,11 +103,18 @@ VToolCutSplinePath* VToolCutSplinePath::Create(QSharedPointer dialog SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - QString formula = dialogTool->GetFormula(); - const quint32 splinePathId = dialogTool->getSplinePathId(); - VToolCutSplinePath* point = Create(0, pointName, formula, splinePathId, 5, 10, true, scene, doc, data, - Document::FullParse, Source::FromGui); + + VToolCutSplinePathInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.splinePathId = dialogTool->getSplinePathId(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolCutSplinePath* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -125,69 +125,55 @@ VToolCutSplinePath* VToolCutSplinePath::Create(QSharedPointer dialog //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. - * @param formula string with formula length first splinePath. - * @param splinePathId id of splinePath in data container. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula, - quint32 splinePathId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutSplinePathInitData &initData) { - const auto splPath = data->GeometricObject(splinePathId); + const auto splPath = initData.data->GeometricObject(initData.splinePathId); SCASSERT(splPath != nullptr) - const qreal result = CheckFormula(_id, formula, data); + const qreal result = CheckFormula(initData.id, initData.formula, initData.data); - quint32 id = _id; VSplinePath *splPath1 = nullptr; VSplinePath *splPath2 = nullptr; - VPointF *p = VToolCutSplinePath::CutSplinePath(qApp->toPixel(result), splPath, pointName, &splPath1, &splPath2); - p->SetShowLabel(showLabel); + VPointF *p = VToolCutSplinePath::CutSplinePath(qApp->toPixel(result), splPath, initData.name, &splPath1, &splPath2); + p->SetShowLabel(initData.showLabel); SCASSERT(splPath1 != nullptr) SCASSERT(splPath2 != nullptr) SCASSERT(p != nullptr) - p->setMx(mx); - p->setMy(my); + p->setMx(initData.mx); + p->setMy(initData.my); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); - data->AddSpline(QSharedPointer(splPath1), NULL_ID, id); - data->AddSpline(QSharedPointer(splPath2), NULL_ID, id); + initData.data->AddSpline(QSharedPointer(splPath1), NULL_ID, initData.id); + initData.data->AddSpline(QSharedPointer(splPath2), NULL_ID, initData.id); } else { - data->UpdateGObject(id, p); + initData.data->UpdateGObject(initData.id, p); - data->AddSpline(QSharedPointer(splPath1), NULL_ID, id); - data->AddSpline(QSharedPointer(splPath2), NULL_ID, id); + initData.data->AddSpline(QSharedPointer(splPath1), NULL_ID, initData.id); + initData.data->AddSpline(QSharedPointer(splPath2), NULL_ID, initData.id); - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::CutSplinePath, doc); - VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(splPath->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::CutSplinePath, initData.doc); + VToolCutSplinePath *point = new VToolCutSplinePath(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(splPath->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h index 8e98848f8..d9630c902 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h @@ -44,6 +44,18 @@ class VSplinePath; template class QSharedPointer; +struct VToolCutSplinePathInitData : public VToolSinglePointInitData +{ + VToolCutSplinePathInitData() + : VToolSinglePointInitData(), + formula(), + splinePathId(NULL_ID) + {} + + QString formula; + quint32 splinePathId; +}; + /** * @brief The VToolCutSplinePath class for tool CutSplinePath. This tool find point on splinePath and cut splinePath on * two. @@ -55,10 +67,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolCutSplinePath *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCutSplinePath *Create(const quint32 _id, const QString &pointName, QString &formula, - quint32 splinePathId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolCutSplinePath *Create(VToolCutSplinePathInitData &initData); static const QString ToolType; static const QString AttrSplinePath; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -80,8 +89,7 @@ protected: private: Q_DISABLE_COPY(VToolCutSplinePath) - VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &splinePathId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolCutSplinePath(const VToolCutSplinePathInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLCUTSPLINEPATH_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 8d3e7c03e..ec7c3b953 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -71,13 +71,12 @@ const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); * @param typeCreation way we create this tool. * @param parent parent object. */ -VToolAlongLine::VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formula, - const quint32 &firstPointId, const quint32 &secondPointId, - const QString &typeLine, const QString &lineColor, const Source &typeCreation, - QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, formula, firstPointId, 0, parent), secondPointId(secondPointId) +VToolAlongLine::VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula, + initData.firstPointId, 0, parent), + secondPointId(initData.secondPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -244,14 +243,21 @@ VToolAlongLine* VToolAlongLine::Create(QSharedPointer dialog, VMainG SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - QString formula = dialogTool->GetFormula(); - const quint32 firstPointId = dialogTool->GetFirstPointId(); - const quint32 secondPointId = dialogTool->GetSecondPointId(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - const QString pointName = dialogTool->getPointName(); - VToolAlongLine *point = Create(0, pointName, typeLine, lineColor, formula, firstPointId, secondPointId, - 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui); + + VToolAlongLineInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.firstPointId = dialogTool->GetFirstPointId(); + initData.secondPointId = dialogTool->GetSecondPointId(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolAlongLine *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -262,75 +268,55 @@ VToolAlongLine* VToolAlongLine::Create(QSharedPointer dialog, VMainG //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. point name. - * @param typeLine line type. - * @param formula string with length formula. - * @param firstPointId id first point of line. - * @param secondPointId id second point of line. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param showLabel show/hide label. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, QString &formula, const quint32 &firstPointId, - quint32 secondPointId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData) { - const QSharedPointer firstPoint = data->GeometricObject(firstPointId); - const QSharedPointer secondPoint = data->GeometricObject(secondPointId); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); QLineF line = QLineF(static_cast(*firstPoint), static_cast(*secondPoint)); //Declare special variable "CurrentLength" - VLengthLine *length = new VLengthLine(firstPoint.data(), firstPointId, secondPoint.data(), - secondPointId, *data->GetPatternUnit()); + VLengthLine *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(), + initData.secondPointId, *initData.data->GetPatternUnit()); length->SetName(currentLength); - data->AddVariable(currentLength, length); + initData.data->AddVariable(currentLength, length); - line.setLength(qApp->toPixel(CheckFormula(_id, formula, data))); + line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formula, initData.data))); - quint32 id = _id; + VPointF *p = new VPointF(line.p2(), initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - VPointF *p = new VPointF(line.p2(), pointName, mx, my); - p->SetShowLabel(showLabel); - - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(firstPointId, id); - data->AddLine(id, secondPointId); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.firstPointId, initData.id); + initData.data->AddLine(initData.id, initData.secondPointId); } else { - data->UpdateGObject(id, p); - data->AddLine(firstPointId, id); - data->AddLine(id, secondPointId); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.firstPointId, initData.id); + initData.data->AddLine(initData.id, initData.secondPointId); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } VToolAlongLine *point = nullptr; - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::AlongLine, doc); - point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, lineColor, - typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::AlongLine, initData.doc); + point = new VToolAlongLine(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); } //Very important to delete it. Only this tool need this special variable. - data->RemoveVariable(currentLength); + initData.data->RemoveVariable(currentLength); return point; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h index 260f99bef..99387deaf 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h @@ -43,6 +43,20 @@ template class QSharedPointer; +struct VToolAlongLineInitData : public VToolLinePointInitData +{ + VToolAlongLineInitData() + : VToolLinePointInitData(), + formula("100.0"), + firstPointId(NULL_ID), + secondPointId(NULL_ID) + {} + + QString formula; + quint32 firstPointId; + quint32 secondPointId; +}; + /** * @brief The VToolAlongLine class tool for creation point along line. */ @@ -53,12 +67,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolAlongLine* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolAlongLine* Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, QString &formula, const quint32 &firstPointId, - quint32 secondPointId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation); + static VToolAlongLine* Create(VToolAlongLineInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::AlongLine)}; @@ -83,10 +92,7 @@ private: /** @brief secondPointId id second point of line. */ quint32 secondPointId; - VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &formula, - const quint32 &firstPointId, - const quint32 &secondPointId, const QString &typeLine, const QString &lineColor, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolAlongLine(const VToolAlongLineInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLALONGLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp index be1c5f055..576805748 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp @@ -59,25 +59,15 @@ const QString VToolBisector::ToolType = QStringLiteral("bisector"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolBisector constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeLine line type. - * @param formula string with formula length of bisector. - * @param firstPointId id first point of angle. - * @param secondPointId id second point of angle. - * @param thirdPointId id third point of angle. - * @param typeCreation way we create this tool. - * @param parent parent object. + * @param initData init data. */ -VToolBisector::VToolBisector(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formula, const quint32 &firstPointId, - const quint32 &secondPointId, const quint32 &thirdPointId, const Source &typeCreation, - QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, formula, secondPointId, 0, parent), firstPointId(firstPointId), - thirdPointId(thirdPointId) +VToolBisector::VToolBisector(const VToolBisectorInitData &initData, QGraphicsItem *parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula, + initData.secondPointId, 0, parent), + firstPointId(initData.firstPointId), + thirdPointId(initData.thirdPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -148,15 +138,22 @@ VToolBisector* VToolBisector::Create(QSharedPointer dialog, VMainGra SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - QString formula = dialogTool->GetFormula(); - const quint32 firstPointId = dialogTool->GetFirstPointId(); - const quint32 secondPointId = dialogTool->GetSecondPointId(); - const quint32 thirdPointId = dialogTool->GetThirdPointId(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - const QString pointName = dialogTool->getPointName(); - VToolBisector *point = Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, lineColor, - pointName, 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui); + + VToolBisectorInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.firstPointId = dialogTool->GetFirstPointId(); + initData.secondPointId = dialogTool->GetSecondPointId(); + initData.thirdPointId = dialogTool->GetThirdPointId(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolBisector *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -167,67 +164,47 @@ VToolBisector* VToolBisector::Create(QSharedPointer dialog, VMainGra //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param formula string with formula. - * @param firstPointId id first point of angle. - * @param secondPointId id second point of angle. - * @param thirdPointId id third point of angle. - * @param typeLine line type. - * @param pointName point name. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param showLabel show/hide label. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, quint32 firstPointId, quint32 secondPointId, - quint32 thirdPointId, const QString &typeLine, const QString &lineColor, - const QString &pointName, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolBisector* VToolBisector::Create(VToolBisectorInitData &initData) { - const QSharedPointer firstPoint = data->GeometricObject(firstPointId); - const QSharedPointer secondPoint = data->GeometricObject(secondPointId); - const QSharedPointer thirdPoint = data->GeometricObject(thirdPointId); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); + const QSharedPointer thirdPoint = initData.data->GeometricObject(initData.thirdPointId); - const qreal result = CheckFormula(_id, formula, data); + const qreal result = CheckFormula(initData.id, initData.formula, initData.data); QPointF fPoint = VToolBisector::FindPoint(static_cast(*firstPoint), static_cast(*secondPoint), static_cast(*thirdPoint), qApp->toPixel(result)); - quint32 id = _id; - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(secondPointId, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.secondPointId, initData.id); } else { - data->UpdateGObject(id, p); - data->AddLine(secondPointId, id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.secondPointId, initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Bisector, doc); - VToolBisector *point = new VToolBisector(doc, data, id, typeLine, lineColor, formula, firstPointId, - secondPointId, thirdPointId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); - doc->IncrementReferens(thirdPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::Bisector, initData.doc); + VToolBisector *point = new VToolBisector(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); + initData.doc->IncrementReferens(thirdPoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h index 05c11acf0..b90e3c0b8 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h @@ -44,6 +44,22 @@ template class QSharedPointer; +struct VToolBisectorInitData : public VToolLinePointInitData +{ + VToolBisectorInitData() + : VToolLinePointInitData(), + formula("100.0"), + firstPointId(NULL_ID), + secondPointId(NULL_ID), + thirdPointId(NULL_ID) + {} + + QString formula; + quint32 firstPointId; + quint32 secondPointId; + quint32 thirdPointId; +}; + /** * @brief The VToolBisector class tool for creation bisector point. */ @@ -57,11 +73,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolBisector* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolBisector* Create(const quint32 _id, QString &formula, quint32 firstPointId, quint32 secondPointId, - quint32 thirdPointId, const QString &typeLine, const QString &lineColor, - const QString &pointName, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolBisector* Create(VToolBisectorInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Bisector)}; @@ -93,10 +105,7 @@ private: /** @brief thirdPointId id third point of angle. */ quint32 thirdPointId; - VToolBisector(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const QString &formula, const quint32 &firstPointId, const quint32 &secondPointId, - const quint32 &thirdPointId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolBisector(const VToolBisectorInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLBISECTOR_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index 8a04dd63d..d9e39596f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -70,15 +70,14 @@ template class QSharedPointer; const QString VToolCurveIntersectAxis::ToolType = QStringLiteral("curveIntersectAxis"); //--------------------------------------------------------------------------------------------------------------------- -VToolCurveIntersectAxis::VToolCurveIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const QString &typeLine, const QString &lineColor, - const QString &formulaAngle, const quint32 &basePointId, - const quint32 &curveId, const Source &typeCreation, +VToolCurveIntersectAxis::VToolCurveIntersectAxis(const VToolCurveIntersectAxisInitData &initData, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, QString(), basePointId, 0, parent), formulaAngle(formulaAngle), - curveId(curveId) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, QString(), + initData.basePointId, 0, parent), + formulaAngle(initData.formulaAngle), + curveId(initData.curveId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,16 +104,21 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - QString formulaAngle = dialogTool->GetAngle(); - const quint32 basePointId = dialogTool->GetBasePointId(); - const quint32 curveId = dialogTool->getCurveId(); - VToolCurveIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, basePointId, - curveId, 5, 10, true, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolCurveIntersectAxisInitData initData; + initData.formulaAngle = dialogTool->GetAngle(); + initData.basePointId = dialogTool->GetBasePointId(); + initData.curveId = dialogTool->getCurveId(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolCurveIntersectAxis *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -123,57 +127,49 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(QSharedPointer basePoint = data->GeometricObject(basePointId); - const qreal angle = CheckFormula(_id, formulaAngle, data); - const QSharedPointer curve = data->GeometricObject(curveId); + const QSharedPointer basePoint = initData.data->GeometricObject(initData.basePointId); + const qreal angle = CheckFormula(initData.id, initData.formulaAngle, initData.data); + const QSharedPointer curve = initData.data->GeometricObject(initData.curveId); const QPointF fPoint = FindPoint(static_cast(*basePoint), angle, curve); const qreal segLength = curve->GetLengthByPoint(fPoint); - quint32 id = _id; - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(basePointId, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.basePointId, initData.id); VContainer::getNextId(); VContainer::getNextId(); - InitSegments(curve->getType(), segLength, p, curveId, data); + InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); } else { - data->UpdateGObject(id, p); - data->AddLine(basePointId, id); + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.basePointId, initData.id); - InitSegments(curve->getType(), segLength, p, curveId, data); + InitSegments(curve->getType(), segLength, p, initData.curveId, initData.data); - if (parse != Document::FullParse) + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::CurveIntersectAxis, doc); - VToolCurveIntersectAxis *point = new VToolCurveIntersectAxis(doc, data, id, typeLine, lineColor, formulaAngle, - basePointId, curveId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(basePoint->getIdTool()); - doc->IncrementReferens(curve->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::CurveIntersectAxis, initData.doc); + VToolCurveIntersectAxis *point = new VToolCurveIntersectAxis(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(basePoint->getIdTool()); + initData.doc->IncrementReferens(curve->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h index 2df2fb29e..5dcd41537 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.h @@ -46,6 +46,20 @@ template class QSharedPointer; +struct VToolCurveIntersectAxisInitData : public VToolLinePointInitData +{ + VToolCurveIntersectAxisInitData() + : VToolLinePointInitData(), + formulaAngle("0"), + basePointId(NULL_ID), + curveId(NULL_ID) + {} + + QString formulaAngle; + quint32 basePointId; + quint32 curveId; +}; + class VToolCurveIntersectAxis : public VToolLinePoint { Q_OBJECT @@ -55,11 +69,7 @@ public: static VToolCurveIntersectAxis *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCurveIntersectAxis *Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, QString &formulaAngle, quint32 basePointId, - quint32 curveId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolCurveIntersectAxis *Create(VToolCurveIntersectAxisInitData &initData); static QPointF FindPoint(const QPointF &point, qreal angle, const QSharedPointer &curve); @@ -88,9 +98,7 @@ private: QString formulaAngle; quint32 curveId; - VToolCurveIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId, - const quint32 &curveId, const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolCurveIntersectAxis(const VToolCurveIntersectAxisInitData &initData, QGraphicsItem *parent = nullptr); template static void InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp index b896febd8..f3251b67e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp @@ -59,23 +59,15 @@ const QString VToolEndLine::ToolType = QStringLiteral("endLine"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolEndLine constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeLine line type. - * @param formulaLength string with formula length of line. - * @param formulaAngle formula angle of line. - * @param basePointId id first point of line. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolEndLine::VToolEndLine(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formulaLength, const QString &formulaAngle, - const quint32 &basePointId, const Source &typeCreation, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, formulaLength, basePointId, 0, parent), - formulaAngle(formulaAngle) +VToolEndLine::VToolEndLine(const VToolEndLineInitData &initData, QGraphicsItem *parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, + initData.formulaLength, initData.basePointId, 0, parent), + formulaAngle(initData.formulaAngle) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -112,15 +104,21 @@ VToolEndLine* VToolEndLine::Create(QSharedPointer dialog, VMainGraph SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - QString formulaLength = dialogTool->GetFormula(); - QString formulaAngle = dialogTool->GetAngle(); - const quint32 basePointId = dialogTool->GetBasePointId(); - VToolEndLine *point = Create(0, pointName, typeLine, lineColor, formulaLength, formulaAngle, - basePointId, 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui); + VToolEndLineInitData initData; + initData.formulaLength = dialogTool->GetFormula(); + initData.formulaAngle = dialogTool->GetAngle(); + initData.basePointId = dialogTool->GetBasePointId(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolEndLine *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -131,63 +129,42 @@ VToolEndLine* VToolEndLine::Create(QSharedPointer dialog, VMainGraph //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. - * @param typeLine line type. - * @param lineColor line color. - * @param formulaLength string with formula length of line. - * @param formulaAngle formula angle of line. - * @param basePointId id first point of line. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param showLabel show/hide label - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. - * @return the created tool + * @param initData init data. */ -VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, QString &formulaLength, QString &formulaAngle, - quint32 basePointId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolEndLine* VToolEndLine::Create(VToolEndLineInitData &initData) { - const QSharedPointer basePoint = data->GeometricObject(basePointId); + const QSharedPointer basePoint = initData.data->GeometricObject(initData.basePointId); QLineF line = QLineF(static_cast(*basePoint), QPointF(basePoint->x()+100, basePoint->y())); - line.setAngle(CheckFormula(_id, formulaAngle, data)); //First set angle. - line.setLength(qApp->toPixel(CheckFormula(_id, formulaLength, data))); - quint32 id = _id; + line.setAngle(CheckFormula(initData.id, initData.formulaAngle, initData.data)); //First set angle. + line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formulaLength, initData.data))); - VPointF *p = new VPointF(line.p2(), pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(line.p2(), initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(basePointId, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.basePointId, initData.id); } else { - data->UpdateGObject(id, p); - data->AddLine(basePointId, id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.basePointId, initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::EndLine, doc); - VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, lineColor, formulaLength, formulaAngle, - basePointId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(basePoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::EndLine, initData.doc); + VToolEndLine *point = new VToolEndLine(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(basePoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h index c063ab959..3e594ca4b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.h @@ -44,6 +44,20 @@ template class QSharedPointer; +struct VToolEndLineInitData : public VToolLinePointInitData +{ + VToolEndLineInitData() + : VToolLinePointInitData(), + formulaLength(), + formulaAngle(), + basePointId(NULL_ID) + {} + + QString formulaLength; + QString formulaAngle; + quint32 basePointId; +}; + /** * @brief The VToolEndLine class tool for creation point on the line end. */ @@ -55,12 +69,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolEndLine *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolEndLine *Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, QString &formulaLength, QString &formulaAngle, - quint32 basePointId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation); + static VToolEndLine *Create(VToolEndLineInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::EndLine)}; @@ -80,10 +89,7 @@ private: QString formulaAngle; - VToolEndLine(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const QString &formulaLength, const QString &formulaAngle, const quint32 &basePointId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolEndLine(const VToolEndLineInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLENDLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp index c9a3d541a..3baf4a16b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp @@ -55,23 +55,16 @@ const QString VToolHeight::ToolType = QStringLiteral("height"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolHeight constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeLine line type. - * @param basePointId id base point of projection. - * @param p1LineId id first point of line. - * @param p2LineId id second point of line. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolHeight::VToolHeight(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const quint32 &basePointId, const quint32 &p1LineId, - const quint32 &p2LineId, const Source &typeCreation, QGraphicsItem * parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, QString(), basePointId, 0, parent), p1LineId(p1LineId), - p2LineId(p2LineId) +VToolHeight::VToolHeight(const VToolHeightInitData &initData, QGraphicsItem * parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, QString(), + initData.basePointId, 0, parent), + p1LineId(initData.p1LineId), + p2LineId(initData.p2LineId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -107,15 +100,21 @@ VToolHeight* VToolHeight::Create(QSharedPointer dialog, VMainGraphic SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - const quint32 basePointId = dialogTool->GetBasePointId(); - const quint32 p1LineId = dialogTool->GetP1LineId(); - const quint32 p2LineId = dialogTool->GetP2LineId(); - VToolHeight *point = Create(0, pointName, typeLine, lineColor, basePointId, p1LineId, p2LineId, 5, 10, true, scene, - doc, data, Document::FullParse, Source::FromGui); + VToolHeightInitData initData; + initData.basePointId = dialogTool->GetBasePointId(); + initData.p1LineId = dialogTool->GetP1LineId(); + initData.p2LineId = dialogTool->GetP2LineId(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolHeight *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -126,68 +125,49 @@ VToolHeight* VToolHeight::Create(QSharedPointer dialog, VMainGraphic //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. - * @param typeLine line type. - * @param basePointId id base point of projection. - * @param p1LineId id first point of line. - * @param p2LineId id second point of line. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. - * @return the created tool + * @param initData init data. */ -VToolHeight* VToolHeight::Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, quint32 basePointId, quint32 p1LineId, - quint32 p2LineId, qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolHeight* VToolHeight::Create(VToolHeightInitData initData) { - const QSharedPointer basePoint = data->GeometricObject(basePointId); - const QSharedPointer p1Line = data->GeometricObject(p1LineId); - const QSharedPointer p2Line = data->GeometricObject(p2LineId); + const QSharedPointer basePoint = initData.data->GeometricObject(initData.basePointId); + const QSharedPointer p1Line = initData.data->GeometricObject(initData.p1LineId); + const QSharedPointer p2Line = initData.data->GeometricObject(initData.p2LineId); QPointF pHeight = FindPoint(QLineF(static_cast(*p1Line), static_cast(*p2Line)), static_cast(*basePoint)); - quint32 id = _id; - VPointF *p = new VPointF(pHeight, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(pHeight, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(basePointId, id); - data->AddLine(p1LineId, id); - data->AddLine(p2LineId, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.basePointId, initData.id); + initData.data->AddLine(initData.p1LineId, initData.id); + initData.data->AddLine(initData.p2LineId, initData.id); } else { - data->UpdateGObject(id, p); - data->AddLine(basePointId, id); - data->AddLine(p1LineId, id); - data->AddLine(p2LineId, id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.basePointId, initData.id); + initData.data->AddLine(initData.p1LineId, initData.id); + initData.data->AddLine(initData.p2LineId, initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Height, doc); - VToolHeight *point = new VToolHeight(doc, data, id, typeLine, lineColor, basePointId, p1LineId, p2LineId, - typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(basePoint->getIdTool()); - doc->IncrementReferens(p1Line->getIdTool()); - doc->IncrementReferens(p2Line->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::Height, initData.doc); + VToolHeight *point = new VToolHeight(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(basePoint->getIdTool()); + initData.doc->IncrementReferens(p1Line->getIdTool()); + initData.doc->IncrementReferens(p2Line->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h index b66d0682e..e4ca01e92 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.h @@ -45,6 +45,20 @@ template class QSharedPointer; +struct VToolHeightInitData : public VToolLinePointInitData +{ + VToolHeightInitData() + : VToolLinePointInitData(), + basePointId(NULL_ID), + p1LineId(NULL_ID), + p2LineId(NULL_ID) + {} + + quint32 basePointId; + quint32 p1LineId; + quint32 p2LineId; +}; + /** * @brief The VToolHeight class tool for creation point of height. Help find point of projection onto line. */ @@ -55,11 +69,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolHeight *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolHeight *Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, quint32 basePointId, quint32 p1LineId, - quint32 p2LineId, qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolHeight *Create(VToolHeightInitData initData); static QPointF FindPoint(const QLineF &line, const QPointF &point); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -92,10 +102,7 @@ private: /** @brief p2LineId id second point of line. */ quint32 p2LineId; - VToolHeight(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const quint32 &basePointId, const quint32 &p1LineId, const quint32 &p2LineId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolHeight(const VToolHeightInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLHEIGHT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index d185c708c..8fcf8eb17 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -56,15 +56,14 @@ template class QSharedPointer; const QString VToolLineIntersectAxis::ToolType = QStringLiteral("lineIntersectAxis"); //--------------------------------------------------------------------------------------------------------------------- -VToolLineIntersectAxis::VToolLineIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const QString &typeLine, const QString &lineColor, - const QString &formulaAngle, const quint32 &basePointId, - const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, QString(), basePointId, 0, parent), formulaAngle(formulaAngle), - firstPointId(firstPointId), secondPointId(secondPointId) +VToolLineIntersectAxis::VToolLineIntersectAxis(const VToolLineIntersectAxisInitData &initData, QGraphicsItem *parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, QString(), + initData.basePointId, 0, parent), + formulaAngle(initData.formulaAngle), + firstPointId(initData.firstPointId), + secondPointId(initData.secondPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -91,17 +90,22 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const QString pointName = dialogTool->getPointName(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - QString formulaAngle = dialogTool->GetAngle(); - const quint32 basePointId = dialogTool->GetBasePointId(); - const quint32 firstPointId = dialogTool->GetFirstPointId(); - const quint32 secondPointId = dialogTool->GetSecondPointId(); - VToolLineIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, - basePointId, firstPointId, secondPointId, 5, 10, true, - scene, doc, data, Document::FullParse, Source::FromGui); + VToolLineIntersectAxisInitData initData; + initData.formulaAngle = dialogTool->GetAngle(); + initData.basePointId = dialogTool->GetBasePointId(); + initData.firstPointId = dialogTool->GetFirstPointId(); + initData.secondPointId = dialogTool->GetSecondPointId(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolLineIntersectAxis *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -110,59 +114,50 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(QSharedPointer basePoint = data->GeometricObject(basePointId); + const QSharedPointer basePoint = initData.data->GeometricObject(initData.basePointId); QLineF axis = QLineF(static_cast(*basePoint), QPointF(basePoint->x()+100, basePoint->y())); - axis.setAngle(CheckFormula(_id, formulaAngle, data)); + axis.setAngle(CheckFormula(initData.id, initData.formulaAngle, initData.data)); - const QSharedPointer firstPoint = data->GeometricObject(firstPointId); - const QSharedPointer secondPoint = data->GeometricObject(secondPointId); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); QLineF line(static_cast(*firstPoint), static_cast(*secondPoint)); QPointF fPoint = FindPoint(axis, line); - quint32 id = _id; - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(basePointId, id); - data->AddLine(firstPointId, id); - data->AddLine(id, secondPointId); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.basePointId, initData.id); + initData.data->AddLine(initData.firstPointId, initData.id); + initData.data->AddLine(initData.id, initData.secondPointId); } else { - data->UpdateGObject(id, p); - data->AddLine(basePointId, id); - data->AddLine(firstPointId, id); - data->AddLine(id, secondPointId); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.basePointId, initData.id); + initData.data->AddLine(initData.firstPointId, initData.id); + initData.data->AddLine(initData.id, initData.secondPointId); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::LineIntersectAxis, doc); - VToolLineIntersectAxis *point = new VToolLineIntersectAxis(doc, data, id, typeLine, lineColor, formulaAngle, - basePointId, firstPointId, secondPointId, - typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(basePoint->getIdTool()); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::LineIntersectAxis, initData.doc); + VToolLineIntersectAxis *point = new VToolLineIntersectAxis(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(basePoint->getIdTool()); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h index 33f06fcb1..1b431a16a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.h @@ -46,6 +46,22 @@ template class QSharedPointer; +struct VToolLineIntersectAxisInitData : public VToolLinePointInitData +{ + VToolLineIntersectAxisInitData() + : VToolLinePointInitData(), + formulaAngle("0"), + basePointId(NULL_ID), + firstPointId(NULL_ID), + secondPointId(NULL_ID) + {} + + QString formulaAngle; + quint32 basePointId; + quint32 firstPointId; + quint32 secondPointId; +}; + class VToolLineIntersectAxis : public VToolLinePoint { Q_OBJECT @@ -55,12 +71,7 @@ public: static VToolLineIntersectAxis *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolLineIntersectAxis *Create(const quint32 _id, const QString &pointName, const QString &typeLine, - const QString &lineColor, QString &formulaAngle, quint32 basePointId, - quint32 firstPointId, quint32 secondPointId, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); + static VToolLineIntersectAxis *Create(VToolLineIntersectAxisInitData &initData); static QPointF FindPoint(const QLineF &axis, const QLineF &line); @@ -96,10 +107,7 @@ private: quint32 firstPointId; quint32 secondPointId; - VToolLineIntersectAxis(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formulaAngle, const quint32 &basePointId, - const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolLineIntersectAxis(const VToolLineIntersectAxisInitData &initData, QGraphicsItem * parent = nullptr); }; #endif // VTOOLLINEINTERSECTAXIS_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h index c81856f30..41e575161 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h @@ -42,6 +42,18 @@ template class QSharedPointer; +struct VToolLinePointInitData : public VToolSinglePointInitData +{ + VToolLinePointInitData() + : VToolSinglePointInitData(), + typeLine(TypeLineLine), + lineColor(ColorBlack) + {} + + QString typeLine; + QString lineColor; +}; + /** * @brief The VToolLinePoint class parent for all tools what create point with line. */ diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp index c576b04ff..25515df21 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp @@ -59,26 +59,16 @@ const QString VToolNormal::ToolType = QStringLiteral("normal"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolNormal constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeLine line type. - * @param formula string with formula normal length. - * @param angle additional angle. - * @param firstPointId id first line point. - * @param secondPointId id second line point. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolNormal::VToolNormal(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formula, const qreal &angle, - const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, formula, firstPointId, angle, parent), - secondPointId(secondPointId) +VToolNormal::VToolNormal(const VToolNormalInitData &initData, QGraphicsItem *parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula, + initData.firstPointId, initData.angle, parent), + secondPointId(initData.secondPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -113,15 +103,22 @@ VToolNormal* VToolNormal::Create(QSharedPointer dialog, VMainGraphic SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - QString formula = dialogTool->GetFormula(); - const quint32 firstPointId = dialogTool->GetFirstPointId(); - const quint32 secondPointId = dialogTool->GetSecondPointId(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - const QString pointName = dialogTool->getPointName(); - const qreal angle = dialogTool->GetAngle(); - VToolNormal *point = Create(0, formula, firstPointId, secondPointId, typeLine, lineColor, pointName, angle, 5, 10, - true, scene, doc, data, Document::FullParse, Source::FromGui); + + VToolNormalInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.firstPointId = dialogTool->GetFirstPointId(); + initData.secondPointId = dialogTool->GetSecondPointId(); + initData.angle = dialogTool->GetAngle(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolNormal *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -132,65 +129,45 @@ VToolNormal* VToolNormal::Create(QSharedPointer dialog, VMainGraphic //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param formula string with formula normal length. - * @param firstPointId id first line point. - * @param secondPointId id second line point. - * @param typeLine line type. - * @param pointName point name. - * @param angle additional angle. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param showLabel show/hide label. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, quint32 firstPointId, quint32 secondPointId, - const QString &typeLine, const QString &lineColor, - const QString &pointName, qreal angle, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolNormal* VToolNormal::Create(VToolNormalInitData initData) { - const QSharedPointer firstPoint = data->GeometricObject(firstPointId); - const QSharedPointer secondPoint = data->GeometricObject(secondPointId); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); - const qreal result = CheckFormula(_id, formula, data); + const qreal result = CheckFormula(initData.id, initData.formula, initData.data); QPointF fPoint = VToolNormal::FindPoint(static_cast(*firstPoint), static_cast(*secondPoint), - qApp->toPixel(result), angle); - quint32 id = _id; + qApp->toPixel(result), initData.angle); - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(firstPointId, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.firstPointId, initData.id); } else { - data->UpdateGObject(id, p); - data->AddLine(firstPointId, id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.firstPointId, initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Normal, doc); - VToolNormal *point = new VToolNormal(doc, data, id, typeLine, lineColor, formula, angle, firstPointId, - secondPointId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::Normal, initData.doc); + VToolNormal *point = new VToolNormal(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h index bbfcd32d2..7e72f93ed 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h @@ -44,6 +44,22 @@ template class QSharedPointer; +struct VToolNormalInitData : public VToolLinePointInitData +{ + VToolNormalInitData() + : VToolLinePointInitData(), + formula(), + firstPointId(NULL_ID), + secondPointId(NULL_ID), + angle(0) + {} + + QString formula; + quint32 firstPointId; + quint32 secondPointId; + qreal angle; +}; + /** * @brief The VToolNormal class tool for creation point on normal. Normal begin from first point of line. */ @@ -54,11 +70,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolNormal* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolNormal* Create(const quint32 _id, QString &formula, quint32 firstPointId, - quint32 secondPointId, const QString &typeLine, const QString &lineColor, - const QString &pointName, const qreal angle, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolNormal* Create(VToolNormalInitData initData); static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, const qreal &angle = 0); static const QString ToolType; @@ -85,10 +97,7 @@ private: /** @brief secondPointId id second line point. */ quint32 secondPointId; - VToolNormal(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, - const QString &formula, const qreal &angle, const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolNormal(const VToolNormalInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLNORMAL_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp index 496f0fc06..f3520996a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp @@ -61,26 +61,16 @@ const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolShoulderPoint constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeLine line type. - * @param formula string with formula length. - * @param p1Line id first line point. - * @param p2Line id second line point. - * @param pShoulder id shoulder point. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolShoulderPoint::VToolShoulderPoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const QString &typeLine, - const QString &lineColor, const QString &formula, const quint32 &p1Line, - const quint32 &p2Line, const quint32 &pShoulder, const Source &typeCreation, - QGraphicsItem * parent) - :VToolLinePoint(doc, data, id, typeLine, lineColor, formula, p1Line, 0, parent), p2Line(p2Line), - pShoulder(pShoulder) +VToolShoulderPoint::VToolShoulderPoint(const VToolShoulderPointInitData &initData, QGraphicsItem * parent) + :VToolLinePoint(initData.doc, initData.data, initData.id, initData.typeLine, initData.lineColor, initData.formula, + initData.p1Line, 0, parent), + p2Line(initData.p2Line), + pShoulder(initData.pShoulder) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -162,15 +152,22 @@ VToolShoulderPoint* VToolShoulderPoint::Create(QSharedPointer dialog SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - QString formula = dialogTool->GetFormula(); - const quint32 p1Line = dialogTool->GetP1Line(); - const quint32 p2Line = dialogTool->GetP2Line(); - const quint32 pShoulder = dialogTool->GetP3(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - const QString pointName = dialogTool->getPointName(); - VToolShoulderPoint * point = Create(0, formula, p1Line, p2Line, pShoulder, typeLine, lineColor, pointName, 5, - 10, true, scene, doc, data, Document::FullParse, Source::FromGui); + + VToolShoulderPointInitData initData; + initData.formula = dialogTool->GetFormula(); + initData.p1Line = dialogTool->GetP1Line(); + initData.p2Line = dialogTool->GetP2Line(); + initData.pShoulder = dialogTool->GetP3(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolShoulderPoint * point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -181,72 +178,51 @@ VToolShoulderPoint* VToolShoulderPoint::Create(QSharedPointer dialog //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param formula string with formula length. - * @param p1Line id first line point. - * @param p2Line id second line point. - * @param pShoulder id shoulder point. - * @param typeLine line type. - * @param pointName point name. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param showLabel show/hide label. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. * @return the created tool */ -VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formula, quint32 p1Line, quint32 p2Line, - quint32 pShoulder, const QString &typeLine, const QString &lineColor, - const QString &pointName, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolShoulderPoint* VToolShoulderPoint::Create(VToolShoulderPointInitData &initData) { - const QSharedPointer firstPoint = data->GeometricObject(p1Line); - const QSharedPointer secondPoint = data->GeometricObject(p2Line); - const QSharedPointer shoulderPoint = data->GeometricObject(pShoulder); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.p1Line); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.p2Line); + const QSharedPointer shoulderPoint = initData.data->GeometricObject(initData.pShoulder); - const qreal result = CheckFormula(_id, formula, data); + const qreal result = CheckFormula(initData.id, initData.formula, initData.data); QPointF fPoint = VToolShoulderPoint::FindPoint(static_cast(*firstPoint), static_cast(*secondPoint), static_cast(*shoulderPoint), qApp->toPixel(result)); - quint32 id = _id; - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(p1Line, id); - data->AddLine(p2Line, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.p1Line, initData.id); + initData.data->AddLine(initData.p2Line, initData.id); } else { - data->UpdateGObject(id, p); - data->AddLine(p1Line, id); - data->AddLine(p2Line, id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.p1Line, initData.id); + initData.data->AddLine(initData.p2Line, initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::ShoulderPoint, doc); - VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, lineColor, formula, - p1Line, p2Line, pShoulder, - typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); - doc->IncrementReferens(shoulderPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::ShoulderPoint, initData.doc); + VToolShoulderPoint *point = new VToolShoulderPoint(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); + initData.doc->IncrementReferens(shoulderPoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h index 23897c804..2f6f8f3d2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h @@ -44,6 +44,22 @@ template class QSharedPointer; +struct VToolShoulderPointInitData : public VToolLinePointInitData +{ + VToolShoulderPointInitData() + : VToolLinePointInitData(), + formula(), + p1Line(NULL_ID), + p2Line(NULL_ID), + pShoulder(NULL_ID) + {} + + QString formula; + quint32 p1Line; + quint32 p2Line; + quint32 pShoulder; +}; + /** * @brief The VToolShoulderPoint class tool for creation point on shoulder. This tool for special situation, when you * want find point along line, but have only length from another point (shoulder). @@ -57,12 +73,7 @@ public: const qreal &length); static VToolShoulderPoint* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolShoulderPoint* Create(const quint32 _id, QString &formula, quint32 p1Line, quint32 p2Line, - quint32 pShoulder, const QString &typeLine, const QString &lineColor, - const QString &pointName, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation); + static VToolShoulderPoint* Create(VToolShoulderPointInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::ShoulderPoint) }; @@ -95,9 +106,7 @@ private: /** @brief pShoulder id shoulder line point. */ quint32 pShoulder; - VToolShoulderPoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &lineColor, const QString &formula, const quint32 &p1Line, const quint32 &p2Line, - const quint32 &pShoulder, const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolShoulderPoint(const VToolShoulderPointInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLSHOULDERPOINT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index bb0792f0c..d23337335 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -73,21 +73,17 @@ const QString VToolBasePoint::ToolType = QStringLiteral("single"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolBasePoint constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolBasePoint::VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - const QString &namePP, QGraphicsItem * parent ) - :VToolSinglePoint(doc, data, id, parent), namePP(namePP) +VToolBasePoint::VToolBasePoint (const VToolBasePointInitData &initData, QGraphicsItem * parent ) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), namePP(initData.nameActivPP) { m_baseColor = Qt::red; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); m_namePoint->setBrush(Qt::black); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -104,33 +100,31 @@ void VToolBasePoint::setDialog() } //--------------------------------------------------------------------------------------------------------------------- -VToolBasePoint *VToolBasePoint::Create(quint32 _id, const QString &nameActivPP, VPointF *point, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolBasePoint *VToolBasePoint::Create(VToolBasePointInitData initData) { - SCASSERT(point != nullptr) + VPointF *point = new VPointF(initData.x, initData.y, initData.name, initData.mx, initData.my); + point->SetShowLabel(initData.showLabel); - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(point); + initData.id = initData.data->AddGObject(point); } else { - data->UpdateGObject(id, point); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, point); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::BasePoint, doc); - VToolBasePoint *spoint = new VToolBasePoint(doc, data, id, typeCreation, nameActivPP); - scene->addItem(spoint); - InitToolConnections(scene, spoint); - VAbstractPattern::AddTool(id, spoint); + VAbstractTool::AddRecord(initData.id, Tool::BasePoint, initData.doc); + VToolBasePoint *spoint = new VToolBasePoint(initData); + initData.scene->addItem(spoint); + InitToolConnections(initData.scene, spoint); + VAbstractPattern::AddTool(initData.id, spoint); return spoint; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index 893cbfab1..95f4b43b7 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -45,6 +45,20 @@ template class QSharedPointer; +struct VToolBasePointInitData : public VToolSinglePointInitData +{ + VToolBasePointInitData() + : VToolSinglePointInitData(), + nameActivPP(), + x(10), + y(10) + {} + + QString nameActivPP; + qreal x; + qreal y; +}; + /** * @brief The VToolBasePoint class tool for creation pattern base point. Only base point can move. All object * pattern peace depend on base point. @@ -55,9 +69,7 @@ class VToolBasePoint : public VToolSinglePoint public: virtual ~VToolBasePoint() =default; virtual void setDialog() Q_DECL_OVERRIDE; - static VToolBasePoint *Create(quint32 _id, const QString &nameActivPP, VPointF *point, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolBasePoint *Create(VToolBasePointInitData initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::BasePoint)}; @@ -94,8 +106,7 @@ private: QString namePP; - VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, - const QString &namePP, QGraphicsItem * parent = nullptr ); + VToolBasePoint (const VToolBasePointInitData &initData, QGraphicsItem * parent = nullptr ); }; #endif // VTOOLBASEPOINT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp index baa90523c..64978f195 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp @@ -58,24 +58,17 @@ const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolLineIntersect constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param p1Line1 id first point first line. - * @param p2Line1 id second point first line. - * @param p1Line2 id first point second line. - * @param p2Line2 id second point second line. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolLineIntersect::VToolLineIntersect(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const quint32 &p1Line1, const quint32 &p2Line1, const quint32 &p1Line2, - const quint32 &p2Line2, const Source &typeCreation, - QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), - p2Line2(p2Line2) +VToolLineIntersect::VToolLineIntersect(const VToolLineIntersectInitData &initData, QGraphicsItem *parent) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + p1Line1(initData.p1Line1Id), + p2Line1(initData.p2Line1Id), + p1Line2(initData.p1Line2Id), + p2Line2(initData.p2Line2Id) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -86,7 +79,7 @@ void VToolLineIntersect::setDialog() { SCASSERT(not m_dialog.isNull()) QSharedPointer dialogTool = m_dialog.objectCast(); - SCASSERT(not dialogTool.isNull()) + SCASSERT(not dialogTool.isNull()) const QSharedPointer p = VAbstractTool::data.GeometricObject(m_id); dialogTool->SetP1Line1(p1Line1); dialogTool->SetP2Line1(p2Line1); @@ -110,13 +103,20 @@ VToolLineIntersect* VToolLineIntersect::Create(QSharedPointer dialog SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 p1Line1Id = dialogTool->GetP1Line1(); - const quint32 p2Line1Id = dialogTool->GetP2Line1(); - const quint32 p1Line2Id = dialogTool->GetP1Line2(); - const quint32 p2Line2Id = dialogTool->GetP2Line2(); - const QString pointName = dialogTool->getPointName(); - VToolLineIntersect* point = Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, true, scene, - doc, data, Document::FullParse, Source::FromGui); + + VToolLineIntersectInitData initData; + initData.p1Line1Id = dialogTool->GetP1Line1(); + initData.p2Line1Id = dialogTool->GetP2Line1(); + initData.p1Line2Id = dialogTool->GetP1Line2(); + initData.p2Line2Id = dialogTool->GetP2Line2(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolLineIntersect* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -127,31 +127,15 @@ VToolLineIntersect* VToolLineIntersect::Create(QSharedPointer dialog //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param p1Line1Id id first point first line. - * @param p2Line1Id id second point first line. - * @param p1Line2Id id first point second line. - * @param p2Line2Id id second point second line. - * @param pointName point name. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. * @return the created tool */ -VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, quint32 p1Line1Id, quint32 p2Line1Id, - quint32 p1Line2Id, quint32 p2Line2Id, const QString &pointName, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolLineIntersect* VToolLineIntersect::Create(VToolLineIntersectInitData initData) { - const QSharedPointer p1Line1 = data->GeometricObject(p1Line1Id); - const QSharedPointer p2Line1 = data->GeometricObject(p2Line1Id); - const QSharedPointer p1Line2 = data->GeometricObject(p1Line2Id); - const QSharedPointer p2Line2 = data->GeometricObject(p2Line2Id); + const QSharedPointer p1Line1 = initData.data->GeometricObject(initData.p1Line1Id); + const QSharedPointer p2Line1 = initData.data->GeometricObject(initData.p2Line1Id); + const QSharedPointer p1Line2 = initData.data->GeometricObject(initData.p1Line2Id); + const QSharedPointer p2Line2 = initData.data->GeometricObject(initData.p2Line2Id); QLineF line1(static_cast(*p1Line1), static_cast(*p2Line1)); QLineF line2(static_cast(*p1Line2), static_cast(*p2Line2)); @@ -159,44 +143,41 @@ VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, quint32 p1Line QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) { - quint32 id = _id; + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); - - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(p1Line1Id, id); - data->AddLine(id, p2Line1Id); - data->AddLine(p1Line2Id, id); - data->AddLine(id, p2Line2Id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.p1Line1Id, initData.id); + initData.data->AddLine(initData.id, initData.p2Line1Id); + initData.data->AddLine(initData.p1Line2Id, initData.id); + initData.data->AddLine(initData.id, initData.p2Line2Id); } else { - data->UpdateGObject(id, p); - data->AddLine(p1Line1Id, id); - data->AddLine(id, p2Line1Id); - data->AddLine(p1Line2Id, id); - data->AddLine(id, p2Line2Id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.p1Line1Id, initData.id); + initData.data->AddLine(initData.id, initData.p2Line1Id); + initData.data->AddLine(initData.p1Line2Id, initData.id); + initData.data->AddLine(initData.id, initData.p2Line2Id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::LineIntersect, doc); - VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, - p2Line2Id, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(p1Line1->getIdTool()); - doc->IncrementReferens(p2Line1->getIdTool()); - doc->IncrementReferens(p1Line2->getIdTool()); - doc->IncrementReferens(p2Line2->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::LineIntersect, initData.doc); + VToolLineIntersect *point = new VToolLineIntersect(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(p1Line1->getIdTool()); + initData.doc->IncrementReferens(p2Line1->getIdTool()); + initData.doc->IncrementReferens(p1Line2->getIdTool()); + initData.doc->IncrementReferens(p2Line2->getIdTool()); return point; } } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h index 5db39bfe8..c7d448a48 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h @@ -43,6 +43,22 @@ template class QSharedPointer; +struct VToolLineIntersectInitData : public VToolSinglePointInitData +{ + VToolLineIntersectInitData() + : VToolSinglePointInitData(), + p1Line1Id(NULL_ID), + p2Line1Id(NULL_ID), + p1Line2Id(NULL_ID), + p2Line2Id(NULL_ID) + {} + + quint32 p1Line1Id; + quint32 p2Line1Id; + quint32 p1Line2Id; + quint32 p2Line2Id; +}; + /** * @brief The VToolLineIntersect class help find point intersection lines. */ @@ -53,11 +69,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolLineIntersect *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolLineIntersect *Create(const quint32 _id, quint32 p1Line1Id, quint32 p2Line1Id, - quint32 p1Line2Id, quint32 p2Line2Id, const QString &pointName, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); + static VToolLineIntersect *Create(VToolLineIntersectInitData initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::LineIntersect)}; @@ -104,9 +116,7 @@ private: /** @brief p2Line2 id second point second line.*/ quint32 p2Line2; - VToolLineIntersect(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &p1Line1, - const quint32 &p2Line1, const quint32 &p1Line2, const quint32 &p2Line2, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolLineIntersect(const VToolLineIntersectInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLLINEINTERSECT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp index f722b4803..38d2dab79 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp @@ -55,13 +55,14 @@ template class QSharedPointer; const QString VToolPointFromArcAndTangent::ToolType = QStringLiteral("pointFromArcAndTangent"); //--------------------------------------------------------------------------------------------------------------------- -VToolPointFromArcAndTangent::VToolPointFromArcAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, - quint32 arcId, quint32 tangentPointId, - CrossCirclesPoint crossPoint, const Source &typeCreation, +VToolPointFromArcAndTangent::VToolPointFromArcAndTangent(const VToolPointFromArcAndTangentInitData &initData, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), arcId(arcId), tangentPointId(tangentPointId), crossPoint(crossPoint) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + arcId(initData.arcId), + tangentPointId(initData.tangentPointId), + crossPoint(initData.crossPoint) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -85,12 +86,19 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(QSharedPointer< SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 arcId = dialogTool->GetArcId(); - const quint32 tangentPointId = dialogTool->GetTangentPointId(); - const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint(); - const QString pointName = dialogTool->getPointName(); - VToolPointFromArcAndTangent *point = Create(0, pointName, arcId, tangentPointId, pType, 5, 10, true, scene, doc, - data, Document::FullParse, Source::FromGui); + + VToolPointFromArcAndTangentInitData initData; + initData.arcId = dialogTool->GetArcId(); + initData.tangentPointId = dialogTool->GetTangentPointId(); + initData.crossPoint = dialogTool->GetCrossCirclesPoint(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointFromArcAndTangent *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -99,45 +107,39 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(QSharedPointer< } //--------------------------------------------------------------------------------------------------------------------- -VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(const quint32 _id, const QString &pointName, - quint32 arcId, quint32 tangentPointId, - CrossCirclesPoint crossPoint, qreal mx, - qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromArcAndTangentInitData initData) { - const VArc arc = *data->GeometricObject(arcId); - const VPointF tPoint = *data->GeometricObject(tangentPointId); + const VArc arc = *initData.data->GeometricObject(initData.arcId); + const VPointF tPoint = *initData.data->GeometricObject(initData.tangentPointId); - const QPointF point = VToolPointFromArcAndTangent::FindPoint(static_cast(tPoint), &arc, crossPoint); - quint32 id = _id; + const QPointF point = VToolPointFromArcAndTangent::FindPoint(static_cast(tPoint), &arc, + initData.crossPoint); - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointFromArcAndTangent, doc); - VToolPointFromArcAndTangent *point = new VToolPointFromArcAndTangent(doc, data, id, arcId, tangentPointId, - crossPoint, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(arc.getIdTool()); - doc->IncrementReferens(tPoint.getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointFromArcAndTangent, initData.doc); + VToolPointFromArcAndTangent *point = new VToolPointFromArcAndTangent(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(arc.getIdTool()); + initData.doc->IncrementReferens(tPoint.getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h index 0fec16103..b96d9af39 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h @@ -44,6 +44,20 @@ template class QSharedPointer; +struct VToolPointFromArcAndTangentInitData : public VToolSinglePointInitData +{ + VToolPointFromArcAndTangentInitData() + : VToolSinglePointInitData(), + arcId(NULL_ID), + tangentPointId(NULL_ID), + crossPoint(CrossCirclesPoint::FirstPoint) + {} + + quint32 arcId; + quint32 tangentPointId; + CrossCirclesPoint crossPoint; +}; + class VToolPointFromArcAndTangent : public VToolSinglePoint { Q_OBJECT @@ -51,11 +65,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointFromArcAndTangent *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointFromArcAndTangent *Create(const quint32 _id, const QString &pointName, quint32 arcId, - quint32 tangentPointId, CrossCirclesPoint crossPoint, qreal mx, - qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolPointFromArcAndTangent *Create(VToolPointFromArcAndTangentInitData initData); static QPointF FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -89,9 +99,7 @@ private: quint32 tangentPointId; CrossCirclesPoint crossPoint; - VToolPointFromArcAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 arcId, - quint32 tangentPointId, CrossCirclesPoint crossPoint, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolPointFromArcAndTangent(const VToolPointFromArcAndTangentInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLPOINTFROMARCANDTANGENT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index e26dc783c..4895e526a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -56,15 +56,15 @@ template class QSharedPointer; const QString VToolPointFromCircleAndTangent::ToolType = QStringLiteral("pointFromCircleAndTangent"); //--------------------------------------------------------------------------------------------------------------------- -VToolPointFromCircleAndTangent::VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data, - const quint32 &id, - quint32 circleCenterId, const QString &circleRadius, - quint32 tangentPointId, CrossCirclesPoint crossPoint, - const Source &typeCreation, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), circleCenterId(circleCenterId), tangentPointId(tangentPointId), - circleRadius(circleRadius), crossPoint(crossPoint) +VToolPointFromCircleAndTangent::VToolPointFromCircleAndTangent(const VToolPointFromCircleAndTangentInitData &initData, + QGraphicsItem *parent) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + circleCenterId(initData.circleCenterId), + tangentPointId(initData.tangentPointId), + circleRadius(initData.circleRadius), + crossPoint(initData.crossPoint) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -89,13 +89,20 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(QSharedPo SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 circleCenterId = dialogTool->GetCircleCenterId(); - QString circleRadius = dialogTool->GetCircleRadius(); - const quint32 tangentPointId = dialogTool->GetTangentPointId(); - const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint(); - const QString pointName = dialogTool->getPointName(); - VToolPointFromCircleAndTangent *point = Create(0, pointName, circleCenterId, circleRadius, tangentPointId, pType, - 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui); + + VToolPointFromCircleAndTangentInitData initData; + initData.circleCenterId = dialogTool->GetCircleCenterId(); + initData.circleRadius = dialogTool->GetCircleRadius(); + initData.tangentPointId = dialogTool->GetTangentPointId(); + initData.crossPoint = dialogTool->GetCrossCirclesPoint(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointFromCircleAndTangent *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -104,51 +111,41 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(QSharedPo } //--------------------------------------------------------------------------------------------------------------------- -VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(const quint32 _id, const QString &pointName, - quint32 circleCenterId, QString &circleRadius, - quint32 tangentPointId, - CrossCirclesPoint crossPoint, qreal mx, - qreal my, bool showLabel, - VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation) +VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPointFromCircleAndTangentInitData &initData) { - const qreal radius = qApp->toPixel(CheckFormula(_id, circleRadius, data)); - const VPointF cPoint = *data->GeometricObject(circleCenterId); - const VPointF tPoint = *data->GeometricObject(tangentPointId); + const qreal radius = qApp->toPixel(CheckFormula(initData.id, initData.circleRadius, initData.data)); + const VPointF cPoint = *initData.data->GeometricObject(initData.circleCenterId); + const VPointF tPoint = *initData.data->GeometricObject(initData.tangentPointId); const QPointF point = VToolPointFromCircleAndTangent::FindPoint(static_cast(tPoint), - static_cast(cPoint), radius, crossPoint); - quint32 id = _id; + static_cast(cPoint), radius, + initData.crossPoint); - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointFromCircleAndTangent, doc); - VToolPointFromCircleAndTangent *point = new VToolPointFromCircleAndTangent(doc, data, id, circleCenterId, - circleRadius, tangentPointId, - crossPoint, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(cPoint.getIdTool()); - doc->IncrementReferens(tPoint.getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointFromCircleAndTangent, initData.doc); + VToolPointFromCircleAndTangent *point = new VToolPointFromCircleAndTangent(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(cPoint.getIdTool()); + initData.doc->IncrementReferens(tPoint.getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h index 769c1b823..bbea0433a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h @@ -45,6 +45,22 @@ class VFormula; template class QSharedPointer; +struct VToolPointFromCircleAndTangentInitData : public VToolSinglePointInitData +{ + VToolPointFromCircleAndTangentInitData() + : VToolSinglePointInitData(), + circleCenterId(NULL_ID), + circleRadius("0"), + tangentPointId(NULL_ID), + crossPoint(CrossCirclesPoint::FirstPoint) + {} + + quint32 circleCenterId; + QString circleRadius; + quint32 tangentPointId; + CrossCirclesPoint crossPoint; +}; + class VToolPointFromCircleAndTangent : public VToolSinglePoint { Q_OBJECT @@ -52,11 +68,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointFromCircleAndTangent *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointFromCircleAndTangent *Create(const quint32 _id, const QString &pointName, - quint32 circleCenterId, QString &circleRadius, quint32 tangentPointId, - CrossCirclesPoint crossPoint, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolPointFromCircleAndTangent *Create(VToolPointFromCircleAndTangentInitData &initData); static QPointF FindPoint(const QPointF &p, const QPointF ¢er, qreal radius, const CrossCirclesPoint crossPoint); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -94,9 +106,8 @@ private: QString circleRadius; CrossCirclesPoint crossPoint; - VToolPointFromCircleAndTangent(VAbstractPattern *doc, VContainer *data, const quint32 &id, quint32 circleCenterId, - const QString &circleRadius, quint32 tangentPointId, CrossCirclesPoint crossPoint, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolPointFromCircleAndTangent(const VToolPointFromCircleAndTangentInitData &initData, + QGraphicsItem *parent = nullptr); }; #endif // VTOOLPOINTFROMCIRCLEANDTANGENT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index ef2dec366..3200e5674 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -63,24 +63,17 @@ const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolPointOfContact constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param radius string with formula radius arc. - * @param center id center arc point. - * @param firstPointId id first line point. - * @param secondPointId id second line point. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolPointOfContact::VToolPointOfContact(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const QString &radius, const quint32 ¢er, - const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem *parent) - : VToolSinglePoint(doc, data, id, parent), arcRadius(radius), center(center), firstPointId(firstPointId), - secondPointId(secondPointId) +VToolPointOfContact::VToolPointOfContact(const VToolPointOfContactInitData &initData, QGraphicsItem *parent) + : VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + arcRadius(initData.radius), + center(initData.center), + firstPointId(initData.firstPointId), + secondPointId(initData.secondPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -170,13 +163,20 @@ VToolPointOfContact* VToolPointOfContact::Create(QSharedPointer dial SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - QString radius = dialogTool->getRadius(); - const quint32 center = dialogTool->getCenter(); - const quint32 firstPointId = dialogTool->GetFirstPoint(); - const quint32 secondPointId = dialogTool->GetSecondPoint(); - const QString pointName = dialogTool->getPointName(); - VToolPointOfContact *point = Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, true, scene, - doc, data, Document::FullParse, Source::FromGui); + + VToolPointOfContactInitData initData; + initData.radius = dialogTool->getRadius(); + initData.center = dialogTool->getCenter(); + initData.firstPointId = dialogTool->GetFirstPoint(); + initData.secondPointId = dialogTool->GetSecondPoint(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointOfContact *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -187,69 +187,51 @@ VToolPointOfContact* VToolPointOfContact::Create(QSharedPointer dial //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param radius string with formula radius arc. - * @param center id center arc point. - * @param firstPointId id first line point. - * @param secondPointId id second line point. - * @param pointName point name. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. */ -VToolPointOfContact* VToolPointOfContact::Create(const quint32 _id, QString &radius, quint32 center, - quint32 firstPointId, quint32 secondPointId, - const QString &pointName, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolPointOfContact* VToolPointOfContact::Create(VToolPointOfContactInitData &initData) { - const QSharedPointer centerP = data->GeometricObject(center); - const QSharedPointer firstP = data->GeometricObject(firstPointId); - const QSharedPointer secondP = data->GeometricObject(secondPointId); + const QSharedPointer centerP = initData.data->GeometricObject(initData.center); + const QSharedPointer firstP = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondP = initData.data->GeometricObject(initData.secondPointId); - const qreal result = CheckFormula(_id, radius, data); + const qreal result = CheckFormula(initData.id, initData.radius, initData.data); QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), static_cast(*centerP), static_cast(*firstP), static_cast(*secondP)); - quint32 id = _id; - VPointF *p = new VPointF(fPoint, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); - data->AddLine(firstPointId, id); - data->AddLine(secondPointId, id); - data->AddLine(center, id); + initData.id = initData.data->AddGObject(p); + initData.data->AddLine(initData.firstPointId, initData.id); + initData.data->AddLine(initData.secondPointId, initData.id); + initData.data->AddLine(initData.center, initData.id); } else { - data->UpdateGObject(id, p); - data->AddLine(firstPointId, id); - data->AddLine(secondPointId, id); - data->AddLine(center, id); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + initData.data->AddLine(initData.firstPointId, initData.id); + initData.data->AddLine(initData.secondPointId, initData.id); + initData.data->AddLine(initData.center, initData.id); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointOfContact, doc); - VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center, - firstPointId, secondPointId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(centerP->getIdTool()); - doc->IncrementReferens(firstP->getIdTool()); - doc->IncrementReferens(secondP->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointOfContact, initData.doc); + VToolPointOfContact *point = new VToolPointOfContact(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(centerP->getIdTool()); + initData.doc->IncrementReferens(firstP->getIdTool()); + initData.doc->IncrementReferens(secondP->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h index 545542090..1e99a46af 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h @@ -45,6 +45,22 @@ class VFormula; template class QSharedPointer; +struct VToolPointOfContactInitData : public VToolSinglePointInitData +{ + VToolPointOfContactInitData() + : VToolSinglePointInitData(), + radius("0"), + center(NULL_ID), + firstPointId(NULL_ID), + secondPointId(NULL_ID) + {} + + QString radius; + quint32 center; + quint32 firstPointId; + quint32 secondPointId; +}; + /** * @brief The VToolPointOfContact class tool for creation point intersection line and arc. */ @@ -57,12 +73,7 @@ public: const QPointF &secondPoint); static VToolPointOfContact* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointOfContact* Create(const quint32 _id, QString &radius, quint32 center, - quint32 firstPointId, quint32 secondPointId, - const QString &pointName, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); + static VToolPointOfContact* Create(VToolPointOfContactInitData &initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::PointOfContact) }; @@ -108,9 +119,7 @@ private: /** @brief secondPointId id second line point. */ quint32 secondPointId; - VToolPointOfContact(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &radius, - const quint32 ¢er, const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + VToolPointOfContact(const VToolPointOfContactInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLPOINTOFCONTACT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp index 5e859b528..b28cc52a8 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp @@ -56,20 +56,16 @@ const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfInters //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolPointOfIntersection constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param firstPointId id first line point. - * @param secondPointId id second line point. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolPointOfIntersection::VToolPointOfIntersection(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId) +VToolPointOfIntersection::VToolPointOfIntersection(const VToolPointOfIntersectionInitData &initData, + QGraphicsItem *parent) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + firstPointId(initData.firstPointId), + secondPointId(initData.secondPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -102,11 +98,18 @@ VToolPointOfIntersection *VToolPointOfIntersection::Create(QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 firstPointId = dialogTool->GetFirstPointId(); - const quint32 secondPointId = dialogTool->GetSecondPointId(); - const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersection *point = Create(0, pointName, firstPointId, secondPointId, 5, 10, true, scene, doc, - data, Document::FullParse, Source::FromGui); + + VToolPointOfIntersectionInitData initData; + initData.firstPointId = dialogTool->GetFirstPointId(); + initData.secondPointId = dialogTool->GetSecondPointId(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointOfIntersection *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -117,57 +120,41 @@ VToolPointOfIntersection *VToolPointOfIntersection::Create(QSharedPointer firstPoint = data->GeometricObject(firstPointId); - const QSharedPointer secondPoint = data->GeometricObject(secondPointId); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); QPointF point(firstPoint->x(), secondPoint->y()); - quint32 id = _id; - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointOfIntersection, doc); - VToolPointOfIntersection *point = new VToolPointOfIntersection(doc, data, id, firstPointId, - secondPointId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersection, initData.doc); + VToolPointOfIntersection *point = new VToolPointOfIntersection(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h index 800282974..fafc52a5e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.h @@ -43,6 +43,18 @@ template class QSharedPointer; +struct VToolPointOfIntersectionInitData : public VToolSinglePointInitData +{ + VToolPointOfIntersectionInitData() + : VToolSinglePointInitData(), + firstPointId(NULL_ID), + secondPointId(NULL_ID) + {} + + quint32 firstPointId; + quint32 secondPointId; +}; + /** * @brief The VToolPointOfIntersection class tool for creation point intersection two lines. */ @@ -53,10 +65,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersection *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointOfIntersection *Create(const quint32 _id, const QString &pointName, quint32 firstPointId, - quint32 secondPointId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolPointOfIntersection *Create(VToolPointOfIntersectionInitData initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::PointOfIntersection) }; @@ -88,9 +97,7 @@ private: /** @brief secondPointId id second line point. */ quint32 secondPointId; - VToolPointOfIntersection(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstPointId, - const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolPointOfIntersection(const VToolPointOfIntersectionInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLPOINTOFINTERSECTION_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp index a0a24032b..b5ccd0270 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp @@ -55,13 +55,14 @@ template class QSharedPointer; const QString VToolPointOfIntersectionArcs::ToolType = QStringLiteral("pointOfIntersectionArcs"); //--------------------------------------------------------------------------------------------------------------------- -VToolPointOfIntersectionArcs::VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const quint32 &firstArcId, const quint32 &secondArcId, - CrossCirclesPoint pType, const Source &typeCreation, +VToolPointOfIntersectionArcs::VToolPointOfIntersectionArcs(const VToolPointOfIntersectionArcsInitData &initData, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), firstArcId(firstArcId), secondArcId(secondArcId), crossPoint(pType) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + firstArcId(initData.firstArcId), + secondArcId(initData.secondArcId), + crossPoint(initData.pType) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -85,12 +86,19 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(QSharedPointe SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 firstArcId = dialogTool->GetFirstArcId(); - const quint32 secondArcId = dialogTool->GetSecondArcId(); - const CrossCirclesPoint pType = dialogTool->GetCrossArcPoint(); - const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersectionArcs *point = Create(0, pointName, firstArcId, secondArcId, pType, 5, 10, true, scene, doc, - data, Document::FullParse, Source::FromGui); + + VToolPointOfIntersectionArcsInitData initData; + initData.firstArcId = dialogTool->GetFirstArcId(); + initData.secondArcId = dialogTool->GetSecondArcId(); + initData.pType = dialogTool->GetCrossArcPoint(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointOfIntersectionArcs *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -99,45 +107,38 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(QSharedPointe } //--------------------------------------------------------------------------------------------------------------------- -VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(const quint32 _id, const QString &pointName, - quint32 firstArcId, quint32 secondArcId, - CrossCirclesPoint pType, qreal mx, qreal my, - bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(VToolPointOfIntersectionArcsInitData initData) { - const QSharedPointer firstArc = data->GeometricObject(firstArcId); - const QSharedPointer secondArc = data->GeometricObject(secondArcId); + const QSharedPointer firstArc = initData.data->GeometricObject(initData.firstArcId); + const QSharedPointer secondArc = initData.data->GeometricObject(initData.secondArcId); - const QPointF point = FindPoint(firstArc.data(), secondArc.data(), pType); - quint32 id = _id; + const QPointF point = FindPoint(firstArc.data(), secondArc.data(), initData.pType); - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointOfIntersectionArcs, doc); - VToolPointOfIntersectionArcs *point = new VToolPointOfIntersectionArcs(doc, data, id, firstArcId, - secondArcId, pType, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(firstArc->getIdTool()); - doc->IncrementReferens(secondArc->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersectionArcs, initData.doc); + VToolPointOfIntersectionArcs *point = new VToolPointOfIntersectionArcs(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(firstArc->getIdTool()); + initData.doc->IncrementReferens(secondArc->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h index b4cc84af8..42ce8431c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.h @@ -44,6 +44,20 @@ template class QSharedPointer; +struct VToolPointOfIntersectionArcsInitData : public VToolSinglePointInitData +{ + VToolPointOfIntersectionArcsInitData() + : VToolSinglePointInitData(), + firstArcId(NULL_ID), + secondArcId(NULL_ID), + pType(CrossCirclesPoint::FirstPoint) + {} + + quint32 firstArcId; + quint32 secondArcId; + CrossCirclesPoint pType; +}; + class VToolPointOfIntersectionArcs : public VToolSinglePoint { Q_OBJECT @@ -52,11 +66,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersectionArcs *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointOfIntersectionArcs *Create(const quint32 _id, const QString &pointName, quint32 firstArcId, - quint32 secondArcId, CrossCirclesPoint pType, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolPointOfIntersectionArcs *Create(VToolPointOfIntersectionArcsInitData initData); static QPointF FindPoint(const VArc *arc1, const VArc *arc2, const CrossCirclesPoint pType); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -94,8 +104,7 @@ private: CrossCirclesPoint crossPoint; - VToolPointOfIntersectionArcs(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &firstArcId, - const quint32 &secondArcId, CrossCirclesPoint pType, const Source &typeCreation, + VToolPointOfIntersectionArcs(const VToolPointOfIntersectionArcsInitData &initData, QGraphicsItem * parent = nullptr); }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp index 68e7cb236..1920a0f66 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp @@ -56,19 +56,16 @@ template class QSharedPointer; const QString VToolPointOfIntersectionCircles::ToolType = QStringLiteral("pointOfIntersectionCircles"); //--------------------------------------------------------------------------------------------------------------------- -VToolPointOfIntersectionCircles::VToolPointOfIntersectionCircles(VAbstractPattern *doc, VContainer *data, - const quint32 &id, - quint32 firstCircleCenterId, - quint32 secondCircleCenterId, - const QString &firstCircleRadius, - const QString &secondCircleRadius, - CrossCirclesPoint crossPoint, - const Source &typeCreation, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), firstCircleCenterId(firstCircleCenterId), - secondCircleCenterId(secondCircleCenterId), firstCircleRadius(firstCircleRadius), - secondCircleRadius(secondCircleRadius), crossPoint(crossPoint) +VToolPointOfIntersectionCircles::VToolPointOfIntersectionCircles( + const VToolPointOfIntersectionCirclesInitData &initData, QGraphicsItem *parent) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + firstCircleCenterId(initData.firstCircleCenterId), + secondCircleCenterId(initData.secondCircleCenterId), + firstCircleRadius(initData.firstCircleRadius), + secondCircleRadius(initData.secondCircleRadius), + crossPoint(initData.crossPoint) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -93,18 +90,23 @@ VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(QShared VAbstractPattern *doc, VContainer *data) { SCASSERT(not dialog.isNull()) - QSharedPointer dialogTool = - dialog.objectCast(); + QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 firstCircleCenterId = dialogTool->GetFirstCircleCenterId(); - const quint32 secondCircleCenterId = dialogTool->GetSecondCircleCenterId(); - QString firstCircleRadius = dialogTool->GetFirstCircleRadius(); - QString secondCircleRadius = dialogTool->GetSecondCircleRadius(); - const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint(); - const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersectionCircles *point = Create(0, pointName, firstCircleCenterId, secondCircleCenterId, - firstCircleRadius, secondCircleRadius, pType, 5, 10, true, scene, - doc, data, Document::FullParse, Source::FromGui); + + VToolPointOfIntersectionCirclesInitData initData; + initData.firstCircleCenterId = dialogTool->GetFirstCircleCenterId(); + initData.secondCircleCenterId = dialogTool->GetSecondCircleCenterId(); + initData.firstCircleRadius = dialogTool->GetFirstCircleRadius(); + initData.secondCircleRadius = dialogTool->GetSecondCircleRadius(); + initData.crossPoint = dialogTool->GetCrossCirclesPoint(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointOfIntersectionCircles *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -113,57 +115,43 @@ VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(QShared } //--------------------------------------------------------------------------------------------------------------------- -VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(const quint32 _id, const QString &pointName, - quint32 firstCircleCenterId, - quint32 secondCircleCenterId, - QString &firstCircleRadius, - QString &secondCircleRadius, - CrossCirclesPoint crossPoint, qreal mx, - qreal my, bool showLabel, - VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation) +VToolPointOfIntersectionCircles * +VToolPointOfIntersectionCircles::Create(VToolPointOfIntersectionCirclesInitData &initData) { - const qreal calcC1Radius = qApp->toPixel(CheckFormula(_id, firstCircleRadius, data)); - const qreal calcC2Radius = qApp->toPixel(CheckFormula(_id, secondCircleRadius, data)); + const qreal calcC1Radius = qApp->toPixel(CheckFormula(initData.id, initData.firstCircleRadius, initData.data)); + const qreal calcC2Radius = qApp->toPixel(CheckFormula(initData.id, initData.secondCircleRadius, initData.data)); - const VPointF c1Point = *data->GeometricObject(firstCircleCenterId); - const VPointF c2Point = *data->GeometricObject(secondCircleCenterId); + const VPointF c1Point = *initData.data->GeometricObject(initData.firstCircleCenterId); + const VPointF c2Point = *initData.data->GeometricObject(initData.secondCircleCenterId); const QPointF point = FindPoint(static_cast(c1Point), static_cast(c2Point), calcC1Radius, - calcC2Radius, crossPoint); - quint32 id = _id; + calcC2Radius, initData.crossPoint); - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointOfIntersectionCircles, doc); - VToolPointOfIntersectionCircles *point = new VToolPointOfIntersectionCircles(doc, data, id, firstCircleCenterId, - secondCircleCenterId, - firstCircleRadius, - secondCircleRadius, crossPoint, - typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(c1Point.getIdTool()); - doc->IncrementReferens(c2Point.getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersectionCircles, initData.doc); + VToolPointOfIntersectionCircles *point = new VToolPointOfIntersectionCircles(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(c1Point.getIdTool()); + initData.doc->IncrementReferens(c2Point.getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h index 75f42229e..80e265fa4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.h @@ -45,6 +45,24 @@ class VFormula; template class QSharedPointer; +struct VToolPointOfIntersectionCirclesInitData : public VToolSinglePointInitData +{ + VToolPointOfIntersectionCirclesInitData() + : VToolSinglePointInitData(), + firstCircleCenterId(NULL_ID), + secondCircleCenterId(NULL_ID), + firstCircleRadius("0"), + secondCircleRadius("0"), + crossPoint(CrossCirclesPoint::FirstPoint) + {} + + quint32 firstCircleCenterId; + quint32 secondCircleCenterId; + QString firstCircleRadius; + QString secondCircleRadius; + CrossCirclesPoint crossPoint; +}; + class VToolPointOfIntersectionCircles : public VToolSinglePoint { Q_OBJECT @@ -52,13 +70,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersectionCircles *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointOfIntersectionCircles *Create(const quint32 _id, const QString &pointName, - quint32 firstCircleCenterId, quint32 secondCircleCenterId, - QString &firstCircleRadius, QString &secondCircleRadius, - CrossCirclesPoint crossPoint, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolPointOfIntersectionCircles *Create(VToolPointOfIntersectionCirclesInitData &initData); static QPointF FindPoint(const QPointF &c1Point, const QPointF &c2Point, qreal c1Radius, qreal c2Radius, const CrossCirclesPoint crossPoint); static const QString ToolType; @@ -103,10 +115,7 @@ private: CrossCirclesPoint crossPoint; - VToolPointOfIntersectionCircles(VAbstractPattern *doc, VContainer *data, const quint32 &id, const - quint32 firstCircleCenterId, quint32 secondCircleCenterId, - const QString &firstCircleRadius, const QString &secondCircleRadius, - CrossCirclesPoint crossPoint, const Source &typeCreation, + VToolPointOfIntersectionCircles(const VToolPointOfIntersectionCirclesInitData &initData, QGraphicsItem * parent = nullptr); }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp index 5e704cb72..18e396e57 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp @@ -55,18 +55,15 @@ template class QSharedPointer; const QString VToolPointOfIntersectionCurves::ToolType = QStringLiteral("pointOfIntersectionCurves"); //--------------------------------------------------------------------------------------------------------------------- -VToolPointOfIntersectionCurves::VToolPointOfIntersectionCurves(VAbstractPattern *doc, VContainer *data, - const quint32 &id, const quint32 firstCurveId, - quint32 secondCurveId, VCrossCurvesPoint vCrossPoint, - HCrossCurvesPoint hCrossPoint, const Source &typeCreation, +VToolPointOfIntersectionCurves::VToolPointOfIntersectionCurves(const VToolPointOfIntersectionCurvesInitData &initData, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), - firstCurveId(firstCurveId), - secondCurveId(secondCurveId), - vCrossPoint(vCrossPoint), - hCrossPoint(hCrossPoint) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + firstCurveId(initData.firstCurveId), + secondCurveId(initData.secondCurveId), + vCrossPoint(initData.vCrossPoint), + hCrossPoint(initData.hCrossPoint) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -91,13 +88,20 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(QSharedPo SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 firstCurveId = dialogTool->GetFirstCurveId(); - const quint32 secondCurveId = dialogTool->GetSecondCurveId(); - const VCrossCurvesPoint vCrossPoint = dialogTool->GetVCrossPoint(); - const HCrossCurvesPoint hCrossPoint = dialogTool->GetHCrossPoint(); - const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersectionCurves *point = Create(0, pointName, firstCurveId, secondCurveId, vCrossPoint, hCrossPoint, - 5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui); + + VToolPointOfIntersectionCurvesInitData initData; + initData.firstCurveId = dialogTool->GetFirstCurveId(); + initData.secondCurveId = dialogTool->GetSecondCurveId(); + initData.vCrossPoint = dialogTool->GetVCrossPoint(); + initData.hCrossPoint = dialogTool->GetHCrossPoint(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolPointOfIntersectionCurves *point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -106,49 +110,39 @@ VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(QSharedPo } //--------------------------------------------------------------------------------------------------------------------- -VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(const quint32 _id, const QString &pointName, - quint32 firstCurveId, quint32 secondCurveId, - VCrossCurvesPoint vCrossPoint, - HCrossCurvesPoint hCrossPoint,qreal mx, - qreal my, bool showLabel, - VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, - const Document &parse, - const Source &typeCreation) +VToolPointOfIntersectionCurves *VToolPointOfIntersectionCurves::Create(VToolPointOfIntersectionCurvesInitData initData) { - auto curve1 = data->GeometricObject(firstCurveId); - auto curve2 = data->GeometricObject(secondCurveId); + auto curve1 = initData.data->GeometricObject(initData.firstCurveId); + auto curve2 = initData.data->GeometricObject(initData.secondCurveId); const QPointF point = VToolPointOfIntersectionCurves::FindPoint(curve1->GetPoints(), curve2->GetPoints(), - vCrossPoint, hCrossPoint); - quint32 id = _id; + initData.vCrossPoint, initData.hCrossPoint); - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PointOfIntersectionCurves, doc); - auto point = new VToolPointOfIntersectionCurves(doc, data, id, firstCurveId, secondCurveId, vCrossPoint, - hCrossPoint, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(curve1->getIdTool()); - doc->IncrementReferens(curve2->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::PointOfIntersectionCurves, initData.doc); + auto point = new VToolPointOfIntersectionCurves(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(curve1->getIdTool()); + initData.doc->IncrementReferens(curve2->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h index 2db1b7dba..492ff896c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h @@ -45,6 +45,22 @@ template class QSharedPointer; +struct VToolPointOfIntersectionCurvesInitData : public VToolSinglePointInitData +{ + VToolPointOfIntersectionCurvesInitData() + : VToolSinglePointInitData(), + firstCurveId(NULL_ID), + secondCurveId(NULL_ID), + vCrossPoint(VCrossCurvesPoint::HighestPoint), + hCrossPoint(HCrossCurvesPoint::LeftmostPoint) + {} + + quint32 firstCurveId; + quint32 secondCurveId; + VCrossCurvesPoint vCrossPoint; + HCrossCurvesPoint hCrossPoint; +}; + class VToolPointOfIntersectionCurves : public VToolSinglePoint { Q_OBJECT @@ -52,12 +68,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolPointOfIntersectionCurves *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPointOfIntersectionCurves *Create(const quint32 _id, const QString &pointName, - quint32 firstCurveId, quint32 secondCurveId, - VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolPointOfIntersectionCurves *Create(VToolPointOfIntersectionCurvesInitData initData); static QPointF FindPoint(const QVector &curve1Points, const QVector &curve2Points, VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint); static const QString ToolType; @@ -97,10 +108,8 @@ private: VCrossCurvesPoint vCrossPoint; HCrossCurvesPoint hCrossPoint; - explicit VToolPointOfIntersectionCurves(VAbstractPattern *doc, VContainer *data, const quint32 &id, const - quint32 firstCurveId, quint32 secondCurveId, - VCrossCurvesPoint vCrossPoint, HCrossCurvesPoint hCrossPoint, - const Source &typeCreation, QGraphicsItem * parent = nullptr); + explicit VToolPointOfIntersectionCurves(const VToolPointOfIntersectionCurvesInitData &initData, + QGraphicsItem *parent = nullptr); }; #endif // VTOOLPOINTOFINTERSECTIONCURVES_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index cb4479bbb..5d21c18b3 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -44,6 +44,22 @@ template class QSharedPointer; +struct VToolSinglePointInitData : public VAbstractToolInitData +{ + VToolSinglePointInitData() + : VAbstractToolInitData(), + name(), + mx(5), + my(10), + showLabel(true) + {} + + QString name; + qreal mx; + qreal my; + bool showLabel; +}; + /** * @brief The VToolSinglePoint class parent for all tools what create points. */ diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp index 73a616a60..0b6ed9249 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp @@ -58,23 +58,17 @@ const QString VToolTriangle::ToolType = QStringLiteral("triangle"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolTriangle constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param axisP1Id id first axis point. - * @param axisP2Id id second axis point. - * @param firstPointId id first triangle point, what lies on the hypotenuse. - * @param secondPointId id second triangle point, what lies on the hypotenuse. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolTriangle::VToolTriangle(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id, - const quint32 &axisP2Id, const quint32 &firstPointId, const quint32 &secondPointId, - const Source &typeCreation, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId), - secondPointId(secondPointId) +VToolTriangle::VToolTriangle(const VToolTriangleInitData &initData, QGraphicsItem *parent) + :VToolSinglePoint(initData.doc, initData.data, initData.id, parent), + axisP1Id(initData.axisP1Id), + axisP2Id(initData.axisP2Id), + firstPointId(initData.firstPointId), + secondPointId(initData.secondPointId) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -109,13 +103,20 @@ VToolTriangle* VToolTriangle::Create(QSharedPointer dialog, VMainGra SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 axisP1Id = dialogTool->GetAxisP1Id(); - const quint32 axisP2Id = dialogTool->GetAxisP2Id(); - const quint32 firstPointId = dialogTool->GetFirstPointId(); - const quint32 secondPointId = dialogTool->GetSecondPointId(); - const QString pointName = dialogTool->getPointName(); - VToolTriangle* point = Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, true, - scene, doc, data, Document::FullParse, Source::FromGui); + + VToolTriangleInitData initData; + initData.axisP1Id = dialogTool->GetAxisP1Id(); + initData.axisP2Id = dialogTool->GetAxisP2Id(); + initData.firstPointId = dialogTool->GetFirstPointId(); + initData.secondPointId = dialogTool->GetSecondPointId(); + initData.name = dialogTool->getPointName(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolTriangle* point = Create(initData); if (point != nullptr) { point->m_dialog = dialogTool; @@ -126,63 +127,46 @@ VToolTriangle* VToolTriangle::Create(QSharedPointer dialog, VMainGra //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. - * @param pointName point name. - * @param axisP1Id id first axis point. - * @param axisP2Id id second axis point. - * @param firstPointId id first triangle point, what lies on the hypotenuse. - * @param secondPointId id second triangle point, what lies on the hypotenuse. - * @param mx label bias x axis. - * @param my label bias y axis. - * @param scene pointer to scene. - * @param doc dom document container. - * @param data container with variables. - * @param parse parser file mode. - * @param typeCreation way we create this tool. + * @param initData init data. * @return the created tool */ -VToolTriangle* VToolTriangle::Create(const quint32 _id, const QString &pointName, quint32 axisP1Id, quint32 axisP2Id, - quint32 firstPointId, quint32 secondPointId, qreal mx, qreal my, bool showLabel, - VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData) { - const QSharedPointer axisP1 = data->GeometricObject(axisP1Id); - const QSharedPointer axisP2 = data->GeometricObject(axisP2Id); - const QSharedPointer firstPoint = data->GeometricObject(firstPointId); - const QSharedPointer secondPoint = data->GeometricObject(secondPointId); + const QSharedPointer axisP1 = initData.data->GeometricObject(initData.axisP1Id); + const QSharedPointer axisP2 = initData.data->GeometricObject(initData.axisP2Id); + const QSharedPointer firstPoint = initData.data->GeometricObject(initData.firstPointId); + const QSharedPointer secondPoint = initData.data->GeometricObject(initData.secondPointId); QPointF point = FindPoint(static_cast(*axisP1), static_cast(*axisP2), static_cast(*firstPoint), static_cast(*secondPoint)); - quint32 id = _id; - VPointF *p = new VPointF(point, pointName, mx, my); - p->SetShowLabel(showLabel); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); + p->SetShowLabel(initData.showLabel); - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddGObject(p); + initData.id = initData.data->AddGObject(p); } else { - data->UpdateGObject(id, p); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, p); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Triangle, doc); - VToolTriangle *point = new VToolTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId, - secondPointId, typeCreation); - scene->addItem(point); - InitToolConnections(scene, point); - VAbstractPattern::AddTool(id, point); - doc->IncrementReferens(axisP1->getIdTool()); - doc->IncrementReferens(axisP2->getIdTool()); - doc->IncrementReferens(firstPoint->getIdTool()); - doc->IncrementReferens(secondPoint->getIdTool()); + VAbstractTool::AddRecord(initData.id, Tool::Triangle, initData.doc); + VToolTriangle *point = new VToolTriangle(initData); + initData.scene->addItem(point); + InitToolConnections(initData.scene, point); + VAbstractPattern::AddTool(initData.id, point); + initData.doc->IncrementReferens(axisP1->getIdTool()); + initData.doc->IncrementReferens(axisP2->getIdTool()); + initData.doc->IncrementReferens(firstPoint->getIdTool()); + initData.doc->IncrementReferens(secondPoint->getIdTool()); return point; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h index d0b1d9b86..e601958d9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.h @@ -44,6 +44,22 @@ template class QSharedPointer; +struct VToolTriangleInitData : public VToolSinglePointInitData +{ + VToolTriangleInitData() + : VToolSinglePointInitData(), + axisP1Id(NULL_ID), + axisP2Id(NULL_ID), + firstPointId(NULL_ID), + secondPointId(NULL_ID) + {} + + quint32 axisP1Id; + quint32 axisP2Id; + quint32 firstPointId; + quint32 secondPointId; +}; + /** * @brief The VToolTriangle class for tool that find point intersection two foots right triangle * (triangle with 90 degree). @@ -55,10 +71,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolTriangle *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolTriangle *Create(const quint32 _id, const QString &pointName, quint32 axisP1Id, - quint32 axisP2Id, quint32 firstPointId, quint32 secondPointId, - qreal mx, qreal my, bool showLabel, VMainGraphicsScene *scene, VAbstractPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); + static VToolTriangle *Create(VToolTriangleInitData initData); static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, const QPointF &secondPoint); static const QString ToolType; @@ -105,10 +118,7 @@ private: /** @brief secondPointId id second triangle point, what lies on the hypotenuse. */ quint32 secondPointId; - VToolTriangle(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &axisP1Id, - const quint32 &axisP2Id, - const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolTriangle(const VToolTriangleInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLTRIANGLE_H diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index 80314bd5d..a86f4ba20 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -57,33 +57,25 @@ template class QSharedPointer; //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolLine constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param firstPoint id first line point. - * @param secondPoint id second line point. - * @param typeLine line type. - * @param typeCreation way we create this tool. + * @param initData init data. * @param parent parent object. */ -VToolLine::VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, - const QString &typeLine, const QString &lineColor, const Source &typeCreation, - QGraphicsItem *parent) - :VDrawTool(doc, data, id), +VToolLine::VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent) + :VDrawTool(initData.doc, initData.data, initData.id), QGraphicsLineItem(parent), - firstPoint(firstPoint), - secondPoint(secondPoint), - lineColor(lineColor), + firstPoint(initData.firstPoint), + secondPoint(initData.secondPoint), + lineColor(initData.lineColor), m_isHovered(false) { - this->m_lineType = typeLine; + this->m_lineType = initData.typeLine; //Line RefreshGeometry(); this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setAcceptHoverEvents(true); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- @@ -115,13 +107,19 @@ VToolLine *VToolLine::Create(QSharedPointer dialog, VMainGraphicsSce SCASSERT(not dialog.isNull()) QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 firstPoint = dialogTool->GetFirstPoint(); - const quint32 secondPoint = dialogTool->GetSecondPoint(); - const QString typeLine = dialogTool->GetTypeLine(); - const QString lineColor = dialogTool->GetLineColor(); - VToolLine *line = Create(0, firstPoint, secondPoint, typeLine, lineColor, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolLineInitData initData; + initData.firstPoint = dialogTool->GetFirstPoint(); + initData.secondPoint = dialogTool->GetSecondPoint(); + initData.typeLine = dialogTool->GetTypeLine(); + initData.lineColor = dialogTool->GetLineColor(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + VToolLine *line = Create(initData); if (line != nullptr) { line->m_dialog = dialogTool; @@ -142,45 +140,41 @@ VToolLine *VToolLine::Create(QSharedPointer dialog, VMainGraphicsSce * @param parse parser file mode. * @param typeCreation way we create this tool. */ -VToolLine * VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint, - const QString &typeLine, const QString &lineColor, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation) +VToolLine * VToolLine::Create(VToolLineInitData initData) { - SCASSERT(scene != nullptr) - SCASSERT(doc != nullptr) - SCASSERT(data != nullptr) - quint32 id = _id; - if (typeCreation == Source::FromGui) + SCASSERT(initData.scene != nullptr) + SCASSERT(initData.doc != nullptr) + SCASSERT(initData.data != nullptr) + if (initData.typeCreation == Source::FromGui) { - id = VContainer::getNextId(); - data->AddLine(firstPoint, secondPoint); + initData.id = VContainer::getNextId(); + initData.data->AddLine(initData.firstPoint, initData.secondPoint); } else { - VContainer::UpdateId(id); - data->AddLine(firstPoint, secondPoint); - if (parse != Document::FullParse) + VContainer::UpdateId(initData.id); + initData.data->AddLine(initData.firstPoint, initData.secondPoint); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Line, doc); - VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, lineColor, typeCreation); - scene->addItem(line); - InitDrawToolConnections(scene, line); - connect(scene, &VMainGraphicsScene::EnableLineItemSelection, line, &VToolLine::AllowSelecting); - connect(scene, &VMainGraphicsScene::EnableLineItemHover, line, &VToolLine::AllowHover); - VAbstractPattern::AddTool(id, line); + VAbstractTool::AddRecord(initData.id, Tool::Line, initData.doc); + VToolLine *line = new VToolLine(initData); + initData.scene->addItem(line); + InitDrawToolConnections(initData.scene, line); + connect(initData.scene, &VMainGraphicsScene::EnableLineItemSelection, line, &VToolLine::AllowSelecting); + connect(initData.scene, &VMainGraphicsScene::EnableLineItemHover, line, &VToolLine::AllowHover); + VAbstractPattern::AddTool(initData.id, line); - const QSharedPointer first = data->GeometricObject(firstPoint); - const QSharedPointer second = data->GeometricObject(secondPoint); + const QSharedPointer first = initData.data->GeometricObject(initData.firstPoint); + const QSharedPointer second = initData.data->GeometricObject(initData.secondPoint); - doc->IncrementReferens(first->getIdTool()); - doc->IncrementReferens(second->getIdTool()); + initData.doc->IncrementReferens(first->getIdTool()); + initData.doc->IncrementReferens(second->getIdTool()); return line; } return nullptr; diff --git a/src/libs/vtools/tools/drawTools/vtoolline.h b/src/libs/vtools/tools/drawTools/vtoolline.h index 9bca1b25a..b05718adb 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.h +++ b/src/libs/vtools/tools/drawTools/vtoolline.h @@ -45,6 +45,22 @@ template class QSharedPointer; +struct VToolLineInitData : public VAbstractToolInitData +{ + VToolLineInitData() + : VAbstractToolInitData(), + firstPoint(NULL_ID), + secondPoint(NULL_ID), + typeLine(TypeLineLine), + lineColor(ColorBlack) + {} + + quint32 firstPoint; + quint32 secondPoint; + QString typeLine; + QString lineColor; +}; + /** * @brief The VToolLine class tool for creation line. */ @@ -55,10 +71,7 @@ public: virtual void setDialog() Q_DECL_OVERRIDE; static VToolLine *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolLine *Create(const quint32 &_id, const quint32 &firstPoint, const quint32 &secondPoint, - const QString &typeLine, const QString &lineColor, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolLine *Create(VToolLineInitData initData); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::Line)}; @@ -118,9 +131,7 @@ private: bool m_isHovered; - VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, - const QString &typeLine, const QString &lineColor, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent = nullptr); void RefreshGeometry(); }; diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index 42fe59a36..d833e946e 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -41,6 +41,20 @@ enum class ParentType : bool {Scene, Item}; +struct VAbstractNodeInitData : public VAbstractToolInitData +{ + VAbstractNodeInitData() + : VAbstractToolInitData(), + idObject(NULL_ID), + drawName(), + idTool(NULL_ID) + {} + + quint32 idObject; + QString drawName; + quint32 idTool; +}; + /** * @brief The VAbstractNode class parent class for all detail node. */ diff --git a/src/libs/vtools/tools/nodeDetails/vnodearc.cpp b/src/libs/vtools/tools/nodeDetails/vnodearc.cpp index 49d79847a..dd804f721 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodearc.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodearc.cpp @@ -44,57 +44,45 @@ const QString VNodeArc::ToolType = QStringLiteral("modeling"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VNodeArc constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idArc object id in containerArc. - * @param typeCreation way we create this tool. - * @param idTool tool id. + * @param initData init data. * @param qoParent QObject parent */ -VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, - const QString &drawName, const quint32 &idTool, QObject *qoParent) - :VAbstractNode(doc, data, id, idArc, drawName, idTool, qoParent) +VNodeArc::VNodeArc(const VAbstractNodeInitData &initData, QObject *qoParent) + :VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool, + qoParent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idArc object id in containerArc. - * @param parse parser file mode. - * @param typeCreation way we create this tool. - * @param idTool tool id. + * @param initData init data. */ -void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, - const Document &parse, const Source &typeCreation, const QString &drawName, const quint32 &idTool) +void VNodeArc::Create(VAbstractNodeInitData initData) { - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::NodeArc, doc); - VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, drawName, idTool, doc); + VAbstractTool::AddRecord(initData.id, Tool::NodeArc, initData.doc); + VNodeArc *arc = new VNodeArc(initData); - VAbstractPattern::AddTool(id, arc); - if (idTool != NULL_ID) + VAbstractPattern::AddTool(initData.id, arc); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr) arc->setParent(tool);// Adopted by a tool } else { // Help to delete the node before each FullParse - doc->AddToolOnRemove(arc); + initData.doc->AddToolOnRemove(arc); } } else { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } diff --git a/src/libs/vtools/tools/nodeDetails/vnodearc.h b/src/libs/vtools/tools/nodeDetails/vnodearc.h index 151f224f8..62556d28d 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodearc.h +++ b/src/libs/vtools/tools/nodeDetails/vnodearc.h @@ -47,8 +47,7 @@ class VNodeArc :public VAbstractNode { Q_OBJECT public: - static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse, - const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0); + static void Create(VAbstractNodeInitData initData); static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -63,8 +62,7 @@ protected: private: Q_DISABLE_COPY(VNodeArc) - VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, - const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr); + VNodeArc(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr); }; #endif // VNODEARC_H4 diff --git a/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.cpp b/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.cpp index cb66e0ba1..78934e027 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.cpp @@ -42,32 +42,30 @@ const QString VNodeEllipticalArc::ToolType = QStringLiteral("modeling"); //--------------------------------------------------------------------------------------------------------------------- -void VNodeEllipticalArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, - const Document &parse, const Source &typeCreation, const QString &drawName, - const quint32 &idTool) +void VNodeEllipticalArc::Create(VAbstractNodeInitData initData) { - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::NodeElArc, doc); - VNodeEllipticalArc *arc = new VNodeEllipticalArc(doc, data, id, idArc, typeCreation, drawName, idTool, doc); + VAbstractTool::AddRecord(initData.id, Tool::NodeElArc, initData.doc); + VNodeEllipticalArc *arc = new VNodeEllipticalArc(initData); - VAbstractPattern::AddTool(id, arc); - if (idTool != NULL_ID) + VAbstractPattern::AddTool(initData.id, arc); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr) arc->setParent(tool);// Adopted by a tool } else { // Help to delete the node before each FullParse - doc->AddToolOnRemove(arc); + initData.doc->AddToolOnRemove(arc); } } else { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } @@ -108,10 +106,9 @@ void VNodeEllipticalArc::AddToFile() } //--------------------------------------------------------------------------------------------------------------------- -VNodeEllipticalArc::VNodeEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, - const Source &typeCreation, const QString &drawName, const quint32 &idTool, - QObject *qoParent) - :VAbstractNode(doc, data, id, idArc, drawName, idTool, qoParent) +VNodeEllipticalArc::VNodeEllipticalArc(const VAbstractNodeInitData &initData, QObject *qoParent) + :VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool, + qoParent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } diff --git a/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.h b/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.h index f7933e922..6c84d07cc 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.h +++ b/src/libs/vtools/tools/nodeDetails/vnodeellipticalarc.h @@ -44,9 +44,7 @@ class VNodeEllipticalArc :public VAbstractNode { Q_OBJECT public: - static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse, - const Source &typeCreation, const QString &drawName = QString(), - const quint32 &idTool = NULL_ID); + static void Create(VAbstractNodeInitData initData); static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -61,8 +59,7 @@ protected: private: Q_DISABLE_COPY(VNodeEllipticalArc) - VNodeEllipticalArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, - const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr); + VNodeEllipticalArc(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr); }; #endif // VNODEELLIPTICALARC_H diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index fe61d8783..7aaafb66a 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -60,18 +60,12 @@ const QString VNodePoint::ToolType = QStringLiteral("modeling"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VNodePoint constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idPoint object id in containerPoint. - * @param typeCreation way we create this tool. - * @param idTool tool id. - * @param qoParent QObject parent + * @param initData init data. * @param parent parent object. */ -VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation, - const QString &drawName, const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent) - : VAbstractNode(doc, data, id, idPoint, drawName, idTool, qoParent), +VNodePoint::VNodePoint(const VAbstractNodeInitData &initData, QObject *qoParent, QGraphicsItem *parent) + : VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool, + qoParent), VScenePoint(parent) { connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VNodePoint::PointChoosed); @@ -81,56 +75,48 @@ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quin { emit ShowContextMenu(event); }); - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); - ToolCreation(typeCreation); + RefreshPointGeometry(*VAbstractTool::data.GeometricObject(initData.id)); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idPoint object id in containerPoint. - * @param parse parser file mode. - * @param typeCreation way we create this tool. - * @param idTool tool id. + * @param initData init data. */ -void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, - quint32 id, quint32 idPoint, const Document &parse, - const Source &typeCreation, const QString &drawName, const quint32 &idTool) +void VNodePoint::Create(VAbstractNodeInitData initData) { - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::NodePoint, doc); + VAbstractTool::AddRecord(initData.id, Tool::NodePoint, initData.doc); //TODO Need create garbage collector and remove all nodes, what we don't use. //Better check garbage before each saving file. Check only modeling tags. - VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, drawName, idTool, doc); + VNodePoint *point = new VNodePoint(initData); - connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove); - connect(scene, &VMainGraphicsScene::EnablePointItemHover, point, &VNodePoint::AllowHover); - connect(scene, &VMainGraphicsScene::EnablePointItemSelection, point, &VNodePoint::AllowSelecting); - connect(scene, &VMainGraphicsScene::EnableLabelItemHover, point, &VNodePoint::AllowLabelHover); - connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, point, &VNodePoint::AllowLabelSelecting); - VAbstractPattern::AddTool(id, point); - if (idTool != NULL_ID) + connect(initData.scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove); + connect(initData.scene, &VMainGraphicsScene::EnablePointItemHover, point, &VNodePoint::AllowHover); + connect(initData.scene, &VMainGraphicsScene::EnablePointItemSelection, point, &VNodePoint::AllowSelecting); + connect(initData.scene, &VMainGraphicsScene::EnableLabelItemHover, point, &VNodePoint::AllowLabelHover); + connect(initData.scene, &VMainGraphicsScene::EnableLabelItemSelection, point, &VNodePoint::AllowLabelSelecting); + VAbstractPattern::AddTool(initData.id, point); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr) point->setParent(tool);// Adopted by a tool } else { // Try to prevent memory leak - scene->addItem(point);// First adopted by scene + initData.scene->addItem(point);// First adopted by scene point->hide();// If no one will use node, it will stay hidden point->SetParentType(ParentType::Scene); } } else { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 4921a8083..203e01437 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -50,9 +50,7 @@ class VNodePoint: public VAbstractNode, public VScenePoint { Q_OBJECT public: - static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, - quint32 id, quint32 idPoint, const Document &parse, - const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0); + static void Create(VAbstractNodeInitData initData); static const QString ToolType; virtual int type() const Q_DECL_OVERRIDE {return Type;} @@ -86,9 +84,7 @@ protected: private: Q_DISABLE_COPY(VNodePoint) - VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation, - const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr, - QGraphicsItem * parent = nullptr ); + VNodePoint(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr, QGraphicsItem *parent = nullptr); }; #endif // VNODEPOINT_H diff --git a/src/libs/vtools/tools/nodeDetails/vnodespline.cpp b/src/libs/vtools/tools/nodeDetails/vnodespline.cpp index 6d45d4868..0759b551f 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodespline.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodespline.cpp @@ -44,60 +44,47 @@ const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VNodeSpline constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idSpline object id in containerSpline. - * @param typeCreation way we create this tool. - * @param idTool id node. + * @param initData init data. * @param qoParent QObject parent. */ -VNodeSpline::VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, - const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent) - :VAbstractNode(doc, data, id, idSpline, drawName, idTool, qoParent) +VNodeSpline::VNodeSpline(const VAbstractNodeInitData &initData, QObject *qoParent) + :VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool, + qoParent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idSpline object id in containerSpline. - * @param parse parser file mode. - * @param typeCreation way we create this tool. - * @param idTool id node. + * @param initData init data. * @return pointer to node. */ -VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint32 id, - quint32 idSpline, const Document &parse, - const Source &typeCreation, const QString &drawName, const quint32 &idTool) +VNodeSpline *VNodeSpline::Create(VAbstractNodeInitData initData) { VNodeSpline *spl = nullptr; - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::NodeSpline, doc); - spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, drawName, idTool, doc); + VAbstractTool::AddRecord(initData.id, Tool::NodeSpline, initData.doc); + spl = new VNodeSpline(initData); - VAbstractPattern::AddTool(id, spl); - if (idTool != NULL_ID) + VAbstractPattern::AddTool(initData.id, spl); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr) spl->setParent(tool);// Adopted by a tool } else { // Help to delete the node before each FullParse - doc->AddToolOnRemove(spl); + initData.doc->AddToolOnRemove(spl); } } else { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } return spl; } diff --git a/src/libs/vtools/tools/nodeDetails/vnodespline.h b/src/libs/vtools/tools/nodeDetails/vnodespline.h index 51b11ec5f..56e26c4b1 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodespline.h +++ b/src/libs/vtools/tools/nodeDetails/vnodespline.h @@ -47,10 +47,7 @@ class VNodeSpline:public VAbstractNode { Q_OBJECT public: - static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, quint32 id, - quint32 idSpline, const Document &parse, - const Source &typeCreation, const QString &drawName = QString(), - const quint32 &idTool = 0); + static VNodeSpline *Create(VAbstractNodeInitData initData); static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -65,8 +62,7 @@ protected: private: Q_DISABLE_COPY(VNodeSpline) - VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, - const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr); + VNodeSpline(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr); }; #endif // VNODESPLINE_H diff --git a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp index 90477d5a9..2832d8acc 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp @@ -44,59 +44,45 @@ const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath"); //--------------------------------------------------------------------------------------------------------------------- /** * @brief VNodeSplinePath constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idSpline object id in containerSpline. - * @param typeCreation way we create this tool. - * @param idTool tool id. + * @param initData init data. * @param qoParent QObject parent. */ -VNodeSplinePath::VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, - const Source &typeCreation, const QString &drawName, const quint32 &idTool, - QObject *qoParent) - :VAbstractNode(doc, data, id, idSpline, drawName, idTool, qoParent) +VNodeSplinePath::VNodeSplinePath(const VAbstractNodeInitData &initData, QObject *qoParent) + :VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool, + qoParent) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param doc dom document container. - * @param data container with variables. - * @param id object id in container. - * @param idSpline object id in containerSpline. - * @param parse parser file mode. - * @param typeCreation way we create this tool. - * @param idTool tool id. + * @param initData init data. */ -void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id, - quint32 idSpline, const Document &parse, const Source &typeCreation, - const QString &drawName, const quint32 &idTool) +void VNodeSplinePath::Create(VAbstractNodeInitData initData) { - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc); - VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, drawName, idTool, doc); + VAbstractTool::AddRecord(initData.id, Tool::NodeSplinePath, initData.doc); + VNodeSplinePath *splPath = new VNodeSplinePath(initData); - VAbstractPattern::AddTool(id, splPath); - if (idTool != NULL_ID) + VAbstractPattern::AddTool(initData.id, splPath); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr) splPath->setParent(tool);// Adopted by a tool } else { // Help to delete the node before each FullParse - doc->AddToolOnRemove(splPath); + initData.doc->AddToolOnRemove(splPath); } } else { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } diff --git a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h index 50b69f81a..ce0e02be8 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h +++ b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h @@ -47,9 +47,7 @@ class VNodeSplinePath : public VAbstractNode { Q_OBJECT public: - static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, - quint32 idSpline, const Document &parse, - const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0); + static void Create(VAbstractNodeInitData initData); static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -64,8 +62,7 @@ protected: private: Q_DISABLE_COPY(VNodeSplinePath) - VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, - const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr); + VNodeSplinePath(const VAbstractNodeInitData &initData, QObject *qoParent = nullptr); }; #endif // VNODESPLINEPATH_H diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 7efd911b7..8fe01e516 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -40,55 +40,61 @@ VToolPiecePath *VToolPiecePath::Create(QSharedPointer dialog, VMainG SCASSERT(not dialog.isNull()); QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - VPiecePath path = dialogTool->GetPiecePath(); - const quint32 pieceId = dialogTool->GetPieceId(); - qApp->getUndoStack()->beginMacro("add path"); - path.SetNodes(PrepareNodes(path, scene, doc, data)); - VToolPiecePath *pathTool = Create(0, path, pieceId, scene, doc, data, Document::FullParse, Source::FromGui); + VToolPiecePathInitData initData; + initData.path = dialogTool->GetPiecePath(); + initData.idObject = dialogTool->GetPieceId(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + qApp->getUndoStack()->beginMacro("add path"); + initData.path.SetNodes(PrepareNodes(initData.path, scene, doc, data)); + + VToolPiecePath *pathTool = Create(initData); return pathTool; } //--------------------------------------------------------------------------------------------------------------------- -VToolPiecePath *VToolPiecePath::Create(quint32 _id, const VPiecePath &path, quint32 pieceId, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation, const QString &drawName, const quint32 &idTool) +VToolPiecePath *VToolPiecePath::Create(VToolPiecePathInitData initData) { - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = data->AddPiecePath(path); + initData.id = initData.data->AddPiecePath(initData.path); } else { - data->UpdatePiecePath(id, path); - if (parse != Document::FullParse) + initData.data->UpdatePiecePath(initData.id, initData.path); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::PiecePath, doc); + VAbstractTool::AddRecord(initData.id, Tool::PiecePath, initData.doc); //TODO Need create garbage collector and remove all nodes, that we don't use. //Better check garbage before each saving file. Check only modeling tags. - VToolPiecePath *pathTool = new VToolPiecePath(doc, data, id, pieceId, typeCreation, drawName, idTool, doc); + VToolPiecePath *pathTool = new VToolPiecePath(initData); - VAbstractPattern::AddTool(id, pathTool); - if (idTool != NULL_ID) + VAbstractPattern::AddTool(initData.id, pathTool); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr); pathTool->setParent(tool);// Adopted by a tool } else { - if (typeCreation == Source::FromGui && path.GetType() == PiecePathType::InternalPath) + if (initData.typeCreation == Source::FromGui && initData.path.GetType() == PiecePathType::InternalPath) { // Seam allowance tool already initializated and can't init the path - SCASSERT(pieceId > NULL_ID); - VToolSeamAllowance *saTool = qobject_cast(VAbstractPattern::getTool(pieceId)); + SCASSERT(initData.idObject > NULL_ID); + VToolSeamAllowance *saTool = + qobject_cast(VAbstractPattern::getTool(initData.idObject)); SCASSERT(saTool != nullptr); pathTool->setParentItem(saTool); pathTool->SetParentType(ParentType::Item); @@ -96,7 +102,7 @@ VToolPiecePath *VToolPiecePath::Create(quint32 _id, const VPiecePath &path, quin else { // Try to prevent memory leak - scene->addItem(pathTool);// First adopted by scene + initData.scene->addItem(pathTool);// First adopted by scene pathTool->hide();// If no one will use node, it will stay hidden pathTool->SetParentType(ParentType::Scene); } @@ -285,16 +291,14 @@ void VToolPiecePath::ToolCreation(const Source &typeCreation) } //--------------------------------------------------------------------------------------------------------------------- -VToolPiecePath::VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId, - const Source &typeCreation, const QString &drawName, const quint32 &idTool, - QObject *qoParent, QGraphicsItem *parent) - :VAbstractNode(doc, data, id, 0, drawName, idTool, qoParent), +VToolPiecePath::VToolPiecePath(const VToolPiecePathInitData &initData, QObject *qoParent, QGraphicsItem *parent) + :VAbstractNode(initData.doc, initData.data, initData.id, NULL_ID, initData.drawName, initData.idTool, qoParent), QGraphicsPathItem(parent), - m_pieceId(pieceId) + m_pieceId(initData.idObject) { - IncrementNodes(VAbstractTool::data.GetPiecePath(id)); + IncrementNodes(VAbstractTool::data.GetPiecePath(initData.id)); RefreshGeometry(); - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h index 4aa231702..ae6bd0607 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h @@ -35,16 +35,23 @@ class DialogTool; +struct VToolPiecePathInitData : public VAbstractNodeInitData +{ + VToolPiecePathInitData() + : VAbstractNodeInitData(), + path() + {} + + VPiecePath path; +}; + class VToolPiecePath : public VAbstractNode, public QGraphicsPathItem { Q_OBJECT public: static VToolPiecePath* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolPiecePath *Create(quint32 _id, const VPiecePath &path, quint32 pieceId, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation, const QString &drawName = QString(), - const quint32 &idTool = 0); + static VToolPiecePath *Create(VToolPiecePathInitData initData); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::PiecePath)}; @@ -71,9 +78,8 @@ private: quint32 m_pieceId; - VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId, const Source &typeCreation, - const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr, - QGraphicsItem * parent = nullptr ); + VToolPiecePath(const VToolPiecePathInitData &initData, QObject *qoParent = nullptr, + QGraphicsItem *parent = nullptr); void RefreshGeometry(); diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp index 320fda85e..c21e3f6a8 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.cpp @@ -40,28 +40,31 @@ VToolPin *VToolPin::Create(QSharedPointer dialog, VAbstractPattern * SCASSERT(not dialog.isNull()); QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - const quint32 pointId = dialogTool->GetPointId(); - const quint32 pieceId = dialogTool->GetPieceId(); - return Create(0, pointId, pieceId, doc, data, Document::FullParse, Source::FromGui); + VToolPinInitData initData; + initData.pointId = dialogTool->GetPointId(); + initData.idObject = dialogTool->GetPieceId(); + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + return Create(initData); } //--------------------------------------------------------------------------------------------------------------------- -VToolPin *VToolPin::Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation, const QString &drawName, - const quint32 &idTool) +VToolPin *VToolPin::Create(VToolPinInitData initData) { - quint32 id = _id; - if (typeCreation == Source::FromGui) + if (initData.typeCreation == Source::FromGui) { - id = CreateNode(data, pointId); + initData.id = CreateNode(initData.data, initData.pointId); } else { QSharedPointer point; try { - point = data->GeometricObject(pointId); + point = initData.data->GeometricObject(initData.pointId); } catch (const VExceptionBadId &e) { // Possible case. Parent was deleted, but the node object is still here. @@ -70,35 +73,35 @@ VToolPin *VToolPin::Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstr } VPointF *pinPoint = new VPointF(*point); pinPoint->setMode(Draw::Modeling); - data->UpdateGObject(id, pinPoint); - if (parse != Document::FullParse) + initData.data->UpdateGObject(initData.id, pinPoint); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } - VAbstractTool::AddRecord(id, Tool::Pin, doc); + VAbstractTool::AddRecord(initData.id, Tool::Pin, initData.doc); VToolPin *point = nullptr; - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - point = new VToolPin(doc, data, id, pointId, pieceId, typeCreation, drawName, idTool, doc); + point = new VToolPin(initData); - VAbstractPattern::AddTool(id, point); - if (idTool != NULL_ID) + VAbstractPattern::AddTool(initData.id, point); + if (initData.idTool != NULL_ID) { //Some nodes we don't show on scene. Tool that create this nodes must free memory. - VDataTool *tool = VAbstractPattern::getTool(idTool); + VDataTool *tool = VAbstractPattern::getTool(initData.idTool); SCASSERT(tool != nullptr) point->setParent(tool);// Adopted by a tool } else { // Help to delete the node before each FullParse - doc->AddToolOnRemove(point); + initData.doc->AddToolOnRemove(point); } } else { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } return point; } @@ -153,10 +156,10 @@ void VToolPin::AddToFile() } //--------------------------------------------------------------------------------------------------------------------- -VToolPin::VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId, - const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent) - : VAbstractNode(doc, data, id, pointId, drawName, idTool, qoParent), - m_pieceId(pieceId) +VToolPin::VToolPin(const VToolPinInitData &initData, QObject *qoParent) + : VAbstractNode(initData.doc, initData.data, initData.id, initData.pointId, initData.drawName, initData.idTool, + qoParent), + m_pieceId(initData.idObject) { - ToolCreation(typeCreation); + ToolCreation(initData.typeCreation); } diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpin.h b/src/libs/vtools/tools/nodeDetails/vtoolpin.h index 801f5e9a3..4d6c615cc 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpin.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolpin.h @@ -35,14 +35,22 @@ class DialogTool; +struct VToolPinInitData : public VAbstractNodeInitData +{ + VToolPinInitData() + : VAbstractNodeInitData(), + pointId(NULL_ID) + {} + + quint32 pointId; +}; + class VToolPin : public VAbstractNode { Q_OBJECT public: static VToolPin* Create(QSharedPointer dialog, VAbstractPattern *doc, VContainer *data); - static VToolPin *Create(quint32 _id, quint32 pointId, quint32 pieceId, VAbstractPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation, const QString &drawName = QString(), - const quint32 &idTool = 0); + static VToolPin *Create(VToolPinInitData initData); static const QString ToolType; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -59,9 +67,7 @@ private: quint32 m_pieceId; - VToolPin(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pointId, quint32 pieceId, - const Source &typeCreation, const QString &drawName = QString(), const quint32 &idTool = 0, - QObject *qoParent = nullptr); + VToolPin(const VToolPinInitData &initData, QObject *qoParent = nullptr); }; #endif // VTOOLPIN_H diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 7cd8ef53f..1d972fbba 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -618,32 +618,38 @@ quint32 VAbstractTool::PrepareNode(const VPieceNode &node, VMainGraphicsScene *s SCASSERT(doc != nullptr) SCASSERT(data != nullptr) - quint32 id = NULL_ID; + VAbstractNodeInitData initData; + initData.idObject = node.GetId(); + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + switch (node.GetTypeTool()) { case (Tool::NodePoint): - id = CreateNode(data, node.GetId()); - VNodePoint::Create(doc, data, scene, id, node.GetId(), Document::FullParse, Source::FromGui); + initData.id = CreateNode(data, node.GetId()); + VNodePoint::Create(initData); break; case (Tool::NodeArc): - id = CreateNode(data, node.GetId()); - VNodeArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + initData.id = CreateNode(data, node.GetId()); + VNodeArc::Create(initData); break; case (Tool::NodeElArc): - id = CreateNode(data, node.GetId()); - VNodeEllipticalArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + initData.id = CreateNode(data, node.GetId()); + VNodeEllipticalArc::Create(initData); break; case (Tool::NodeSpline): - id = CreateNodeSpline(data, node.GetId()); - VNodeSpline::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + initData.id = CreateNodeSpline(data, node.GetId()); + VNodeSpline::Create(initData); break; case (Tool::NodeSplinePath): - id = CreateNodeSplinePath(data, node.GetId()); - VNodeSplinePath::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + initData.id = CreateNodeSplinePath(data, node.GetId()); + VNodeSplinePath::Create(initData); break; default: qDebug()<<"May be wrong tool type!!! Ignoring."< dialog SCASSERT(not dialog.isNull()); QSharedPointer dialogTool = dialog.objectCast(); SCASSERT(not dialogTool.isNull()) - VPiece detail = dialogTool->GetPiece(); - QString width = detail.GetFormulaSAWidth(); - qApp->getUndoStack()->beginMacro("add detail"); - detail.GetPath().SetNodes(PrepareNodes(detail.GetPath(), scene, doc, data)); - VToolSeamAllowance *piece = Create(0, detail, width, scene, doc, data, Document::FullParse, Source::FromGui); + VToolSeamAllowanceInitData initData; + initData.detail = dialogTool->GetPiece(); + initData.width = initData.detail.GetFormulaSAWidth(); + initData.scene = scene; + initData.doc = doc; + initData.data = data; + initData.parse = Document::FullParse; + initData.typeCreation = Source::FromGui; + + qApp->getUndoStack()->beginMacro("add detail"); + initData.detail.GetPath().SetNodes(PrepareNodes(initData.detail.GetPath(), scene, doc, data)); + + VToolSeamAllowance *piece = Create(initData); if (piece != nullptr) { @@ -106,45 +114,47 @@ VToolSeamAllowance *VToolSeamAllowance::Create(QSharedPointer dialog } //--------------------------------------------------------------------------------------------------------------------- -VToolSeamAllowance *VToolSeamAllowance::Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation, const QString &drawName) +VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initData) { - if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) + if (initData.typeCreation == Source::FromGui || initData.typeCreation == Source::FromTool) { - data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, newPiece.GetSAWidth(), - width, true, tr("Current seam allowance"))); - id = data->AddPiece(newPiece); + initData.data->AddVariable(currentSeamAllowance, new VIncrement(initData.data, currentSeamAllowance, 0, + initData.detail.GetSAWidth(), + initData.width, true, + tr("Current seam allowance"))); + initData.id = initData.data->AddPiece(initData.detail); } else { - const qreal calcWidth = CheckFormula(id, width, data); - newPiece.SetFormulaSAWidth(width, calcWidth); + const qreal calcWidth = CheckFormula(initData.id, initData.width, initData.data); + initData.detail.SetFormulaSAWidth(initData.width, calcWidth); - data->AddVariable(currentSeamAllowance, new VIncrement(data, currentSeamAllowance, 0, calcWidth, - width, true, tr("Current seam allowance"))); + initData.data->AddVariable(currentSeamAllowance, new VIncrement(initData.data, currentSeamAllowance, 0, + calcWidth, initData.width, true, + tr("Current seam allowance"))); - data->UpdatePiece(id, newPiece); - if (parse != Document::FullParse) + initData.data->UpdatePiece(initData.id, initData.detail); + if (initData.parse != Document::FullParse) { - doc->UpdateToolData(id, data); + initData.doc->UpdateToolData(initData.id, initData.data); } } VToolSeamAllowance *piece = nullptr; - if (parse == Document::FullParse) + if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::Piece, doc); - piece = new VToolSeamAllowance(doc, data, id, typeCreation, scene, drawName); - scene->addItem(piece); - connect(piece, &VToolSeamAllowance::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(scene, &VMainGraphicsScene::EnableDetailItemHover, piece, &VToolSeamAllowance::AllowHover); - connect(scene, &VMainGraphicsScene::EnableDetailItemSelection, piece, &VToolSeamAllowance::AllowSelecting); - connect(scene, &VMainGraphicsScene::HighlightDetail, piece, &VToolSeamAllowance::Highlight); - VAbstractPattern::AddTool(id, piece); + VAbstractTool::AddRecord(initData.id, Tool::Piece, initData.doc); + piece = new VToolSeamAllowance(initData); + initData.scene->addItem(piece); + connect(piece, &VToolSeamAllowance::ChoosedTool, initData.scene, &VMainGraphicsScene::ChoosedItem); + connect(initData.scene, &VMainGraphicsScene::EnableDetailItemHover, piece, &VToolSeamAllowance::AllowHover); + connect(initData.scene, &VMainGraphicsScene::EnableDetailItemSelection, piece, + &VToolSeamAllowance::AllowSelecting); + connect(initData.scene, &VMainGraphicsScene::HighlightDetail, piece, &VToolSeamAllowance::Highlight); + VAbstractPattern::AddTool(initData.id, piece); } //Very important to delete it. Only this tool need this special variable. - data->RemoveVariable(currentSeamAllowance); + initData.data->RemoveVariable(currentSeamAllowance); return piece; } @@ -1103,23 +1113,21 @@ void VToolSeamAllowance::SetDialog() } //--------------------------------------------------------------------------------------------------------------------- -VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id, - const Source &typeCreation, VMainGraphicsScene *scene, - const QString &drawName, QGraphicsItem *parent) - : VInteractiveTool(doc, data, id), +VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem *parent) + : VInteractiveTool(initData.doc, initData.data, initData.id), QGraphicsPathItem(parent), m_mainPath(), m_mainPathRect(), - m_sceneDetails(scene), - m_drawName(drawName), + m_sceneDetails(initData.scene), + m_drawName(initData.drawName), m_seamAllowance(new VNoBrushScalePathItem(this)), m_dataLabel(new VTextGraphicsItem(this)), m_patternInfo(new VTextGraphicsItem(this)), m_grainLine(new VGrainlineItem(this)), m_passmarks(new QGraphicsPathItem(this)) { - VPiece detail = data->GetPiece(id); - InitNodes(detail, scene); + VPiece detail = initData.data->GetPiece(initData.id); + InitNodes(detail, initData.scene); InitCSAPaths(detail); InitInternalPaths(detail); InitPins(detail); @@ -1130,9 +1138,9 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove); - connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren); - ToolCreation(typeCreation); + connect(initData.scene, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove); + connect(initData.scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren); + ToolCreation(initData.typeCreation); setAcceptHoverEvents(true); connect(m_dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolSeamAllowance::SaveMoveDetail); diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 502286a95..d71834f44 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -41,6 +41,20 @@ class DialogTool; class VNoBrushScalePathItem; +struct VToolSeamAllowanceInitData : public VAbstractToolInitData +{ + VToolSeamAllowanceInitData() + : VAbstractToolInitData(), + detail(), + width("0"), + drawName() + {} + + VPiece detail; + QString width; + QString drawName; +}; + class VToolSeamAllowance : public VInteractiveTool, public QGraphicsPathItem { Q_OBJECT @@ -49,9 +63,7 @@ public: static VToolSeamAllowance* Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolSeamAllowance* Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene, - VAbstractPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation, const QString &drawName = QString()); + static VToolSeamAllowance* Create(VToolSeamAllowanceInitData &initData); static const quint8 pieceVersion; @@ -152,8 +164,7 @@ private: VGrainlineItem *m_grainLine; QGraphicsPathItem *m_passmarks; - VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, - VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); + VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr); void UpdateExcludeState(); void RefreshGeometry(); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index e19d876fd..6027f0a0a 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -359,7 +359,7 @@ void UnionInitParameters(const VToolUnionDetailsInitData &initData, const VPiece } //--------------------------------------------------------------------------------------------------------------------- -quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool, +quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -378,13 +378,23 @@ quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &in children.append(idObject); point1->setMode(Draw::Modeling); const quint32 id = initData.data->AddGObject(point1.take()); - VNodePoint::Create(initData.doc, initData.data, initData.scene, id, idObject, Document::FullParse, Source::FromTool, - drawName, idTool); + + VAbstractNodeInitData initNodeData; + initNodeData.id = id; + initNodeData.idObject = idObject; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VNodePoint::Create(initNodeData); return id; } //--------------------------------------------------------------------------------------------------------------------- -quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, quint32 idTool, QVector &children, +quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) { QScopedPointer point(new VPointF(*initData.data->GeometricObject(id))); @@ -402,13 +412,24 @@ quint32 AddPin(quint32 id, const VToolUnionDetailsInitData &initData, quint32 id children.append(idObject); point1->setMode(Draw::Modeling); const quint32 idPin = initData.data->AddGObject(point1.take()); - VToolPin::Create(idPin, idObject, 0, initData.doc, initData.data, Document::FullParse, Source::FromTool, drawName, - idTool); + + VToolPinInitData initNodeData; + initNodeData.id = idPin; + initNodeData.pointId = idObject; + initNodeData.idObject = NULL_ID; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VToolPin::Create(initNodeData); return idPin; } //--------------------------------------------------------------------------------------------------------------------- -quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool, +quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -444,13 +465,22 @@ quint32 AddNodeArc(const VPieceNode &node, const VToolUnionDetailsInitData &init arc2->setMode(Draw::Modeling); const quint32 id = initData.data->AddGObject(arc2.take()); - VNodeArc::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, drawName, - idTool); + VAbstractNodeInitData initNodeData; + initNodeData.id = id; + initNodeData.idObject = idObject; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VNodeArc::Create(initNodeData); return id; } //--------------------------------------------------------------------------------------------------------------------- -quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool, +quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -488,13 +518,22 @@ quint32 AddNodeElArc(const VPieceNode &node, const VToolUnionDetailsInitData &in arc2->setMode(Draw::Modeling); const quint32 id = initData.data->AddGObject(arc2.take()); - VNodeEllipticalArc::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, - drawName, idTool); + VAbstractNodeInitData initNodeData; + initNodeData.id = id; + initNodeData.idObject = idObject; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VNodeEllipticalArc::Create(initNodeData); return id; } //--------------------------------------------------------------------------------------------------------------------- -quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool, +quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -523,13 +562,23 @@ quint32 AddNodeSpline(const VPieceNode &node, const VToolUnionDetailsInitData &i VSpline *spl1 = new VSpline(*spl); spl1->setMode(Draw::Modeling); const quint32 id = initData.data->AddGObject(spl1); - VNodeSpline::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, drawName, - idTool); + + VAbstractNodeInitData initNodeData; + initNodeData.id = id; + initNodeData.idObject = idObject; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VNodeSpline::Create(initNodeData); return id; } //--------------------------------------------------------------------------------------------------------------------- -quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitData &initData, quint32 idTool, +quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitData &initData, QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -587,8 +636,17 @@ quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitDat path1->setMode(Draw::Modeling); const quint32 id = initData.data->AddGObject(path1.take()); - VNodeSplinePath::Create(initData.doc, initData.data, id, idObject, Document::FullParse, Source::FromTool, drawName, - idTool); + VAbstractNodeInitData initNodeData; + initNodeData.id = id; + initNodeData.idObject = idObject; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + + VNodeSplinePath::Create(initNodeData); return id; } @@ -597,30 +655,30 @@ quint32 AddNodeSplinePath(const VPieceNode &node, const VToolUnionDetailsInitDat * @brief AddToNewDetail create united detail adding one node per time. */ void AddNodeToNewPath(const VToolUnionDetailsInitData &initData, VPiecePath &newPath, VPieceNode node, - quint32 idTool, QVector &children, const QString &drawName, qreal dx = 0, qreal dy = 0, + QVector &children, const QString &drawName, qreal dx = 0, qreal dy = 0, quint32 pRotate = NULL_ID, qreal angle = 0); void AddNodeToNewPath(const VToolUnionDetailsInitData &initData, VPiecePath &newPath, VPieceNode node, - quint32 idTool, QVector &children, const QString &drawName, qreal dx, qreal dy, - quint32 pRotate, qreal angle) + QVector &children, const QString &drawName, qreal dx, qreal dy, quint32 pRotate, + qreal angle) { quint32 id = 0; switch (node.GetTypeTool()) { case (Tool::NodePoint): - id = AddNodePoint(node, initData, idTool, children, drawName, dx, dy, pRotate, angle); + id = AddNodePoint(node, initData, children, drawName, dx, dy, pRotate, angle); break; case (Tool::NodeArc): - id = AddNodeArc(node, initData, idTool, children, drawName, dx, dy, pRotate, angle); + id = AddNodeArc(node, initData, children, drawName, dx, dy, pRotate, angle); break; case (Tool::NodeElArc): - id = AddNodeElArc(node, initData, idTool, children, drawName, dx, dy, pRotate, angle); + id = AddNodeElArc(node, initData, children, drawName, dx, dy, pRotate, angle); break; case (Tool::NodeSpline): - id = AddNodeSpline(node, initData, idTool, children, drawName, dx, dy, pRotate, angle); + id = AddNodeSpline(node, initData, children, drawName, dx, dy, pRotate, angle); break; case (Tool::NodeSplinePath): - id = AddNodeSplinePath(node, initData, idTool, children, drawName, dx, dy, pRotate, angle); + id = AddNodeSplinePath(node, initData, children, drawName, dx, dy, pRotate, angle); break; default: qDebug()<<"May be wrong tool type!!! Ignoring."< & } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, +void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { const VPiecePath d1Path = d1.GetPath().RemoveEdge(initData.indexD1); @@ -995,23 +1053,22 @@ void CreateUnitedNodes(VPiece &newDetail, const VPiece &d1, const VPiece &d2, qu { if (unitedPath.at(i).first) {// first piece - AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, id, children, drawName); + AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, children, drawName); } else {// second piece - AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, id, children, drawName, dx, dy, pRotate, - angle); + AddNodeToNewPath(initData, newPath, unitedPath.at(i).second, children, drawName, dx, dy, pRotate, angle); } } newDetail.SetPath(newPath); SCASSERT(not children.isEmpty()) - SaveNodesChildren(initData.doc, id, children); + SaveNodesChildren(initData.doc, initData.id, children); } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector &children, quint32 id, +void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector &children, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -1024,11 +1081,23 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector newPath.Clear();//Clear nodes for (int i=0; i < path.CountNodes(); ++i) { - AddNodeToNewPath(initData, newPath, path.at(i), id, nodeChildren, drawName, dx, dy, pRotate, angle); + AddNodeToNewPath(initData, newPath, path.at(i), nodeChildren, drawName, dx, dy, pRotate, angle); } const quint32 idPath = initData.data->AddPiecePath(newPath); - VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, - Source::FromTool, drawName, id); + + VToolPiecePathInitData initNodeData; + initNodeData.id = idPath; + initNodeData.idObject = NULL_ID; + initNodeData.scene = initData.scene; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + initNodeData.path = newPath; + + VToolPiecePath::Create(initNodeData); record.path = idPath; newDetail.GetCustomSARecords().append(record); nodeChildren.prepend(idPath); @@ -1037,7 +1106,7 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, +void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { for (int i = 0; i < d1.GetCustomSARecords().size(); ++i) @@ -1046,12 +1115,12 @@ void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quin } QVector children; - CreateUnitedDetailCSA(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle); - SaveCSAChildren(initData.doc, id, children); + CreateUnitedDetailCSA(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle); + SaveCSAChildren(initData.doc, initData.id, children); } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector &children, quint32 id, +void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector &children, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { @@ -1064,11 +1133,23 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector for (int i=0; i < path.CountNodes(); ++i) { - AddNodeToNewPath(initData, newPath, path.at(i), id, nodeChildren, drawName, dx, dy, pRotate, angle); + AddNodeToNewPath(initData, newPath, path.at(i), nodeChildren, drawName, dx, dy, pRotate, angle); } const quint32 idPath = initData.data->AddPiecePath(newPath); - VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, - Source::FromTool, drawName, id); + + VToolPiecePathInitData initNodeData; + initNodeData.id = idPath; + initNodeData.idObject = NULL_ID; + initNodeData.scene = initData.scene; + initNodeData.doc = initData.doc; + initNodeData.data = initData.data; + initNodeData.parse = Document::FullParse; + initNodeData.typeCreation = Source::FromTool; + initNodeData.idTool = initData.id; + initNodeData.drawName = drawName; + initNodeData.path = newPath; + + VToolPiecePath::Create(initNodeData); newDetail.GetInternalPaths().append(idPath); nodeChildren.prepend(idPath); } @@ -1076,9 +1157,9 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, - const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, - quint32 pRotate, qreal angle) +void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName, + const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, + qreal angle) { for (int i = 0; i < d1.GetInternalPaths().size(); ++i) { @@ -1086,20 +1167,20 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece } QVector children; - CreateUnitedDetailInternalPaths(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedDetailInternalPaths(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle); - SaveInternalPathsChildren(initData.doc, id, children); + SaveInternalPathsChildren(initData.doc, initData.id, children); } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector &children, quint32 idTool, +void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector &children, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { QVector nodeChildren; for(int i=0; i < d.GetPins().size(); ++i) { - const quint32 id = AddPin(d.GetPins().at(i), initData, idTool, children, drawName, dx, dy, pRotate, angle); + const quint32 id = AddPin(d.GetPins().at(i), initData, children, drawName, dx, dy, pRotate, angle); newDetail.GetPins().append(id); nodeChildren.prepend(id); } @@ -1107,7 +1188,7 @@ void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, +void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { for (int i = 0; i < d1.GetPins().size(); ++i) @@ -1116,21 +1197,20 @@ void CreateUnitedPins(VPiece &newDetail, const VPiece &d1, const VPiece &d2, qui } QVector children; - CreateUnitedDetailPins(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle); - SavePinsChildren(initData.doc, id, children); + CreateUnitedDetailPins(newDetail, d2, children, drawName, initData, dx, dy, pRotate, angle); + SavePinsChildren(initData.doc, initData.id, children); } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, - qreal angle) +void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - const VPiecePath d1REPath = GetPiece1MainPath(initData.doc, id).RemoveEdge(initData.indexD1); - const VPiecePath d2REPath = GetPiece2MainPath(initData.doc, id).RemoveEdge(initData.indexD2); + const VPiecePath d1REPath = GetPiece1MainPath(initData.doc, initData.id).RemoveEdge(initData.indexD1); + const VPiecePath d2REPath = GetPiece2MainPath(initData.doc, initData.id).RemoveEdge(initData.indexD2); const qint32 countNodeD1 = d1REPath.CountNodes(); const qint32 countNodeD2 = d2REPath.CountNodes(); - QVector children = GetNodesChildren(initData.doc, id); + QVector children = GetNodesChildren(initData.doc, initData.id); if (not children.isEmpty()) { // This check need for backward compatibility @@ -1210,7 +1290,7 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedDetailCSA(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, +void UpdateUnitedDetailCSA(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle, const QVector &records) { QVector idRecords; @@ -1218,21 +1298,22 @@ void UpdateUnitedDetailCSA(quint32 id, const VToolUnionDetailsInitData &initData { idRecords.append(records.at(i).path); } - UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, idRecords, GetCSAChildren(initData.doc, id)); + UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, idRecords, GetCSAChildren(initData.doc, initData.id)); } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedDetailInternalPaths(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, +void UpdateUnitedDetailInternalPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle, const QVector &records) { - UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records, GetInternalPathsChildren(initData.doc, id)); + UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records, + GetInternalPathsChildren(initData.doc, initData.id)); } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedDetailPins(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, - quint32 pRotate, qreal angle, const QVector &records) +void UpdateUnitedDetailPins(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle, + const QVector &records) { - QVector children = GetPinChildren(initData.doc, id); + QVector children = GetPinChildren(initData.doc, initData.id); for (int i = 0; i < records.size(); ++i) { @@ -1248,8 +1329,7 @@ void UpdateUnitedDetailPins(quint32 id, const VToolUnionDetailsInitData &initDat } //--------------------------------------------------------------------------------------------------------------------- -void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, - qreal angle) +void CreateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { const QString drawName = DrawName(initData.doc, initData.d1id, initData.d2id); SCASSERT(not drawName.isEmpty()) @@ -1259,10 +1339,10 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q VPiece newDetail; - CreateUnitedNodes(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); - CreateUnitedCSA(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); - CreateUnitedInternalPaths(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); - CreateUnitedPins(newDetail, d1, d2, id, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedNodes(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedCSA(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedInternalPaths(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); + CreateUnitedPins(newDetail, d1, d2, drawName, initData, dx, dy, pRotate, angle); newDetail.SetName(QObject::tr("United detail")); QString formulaSAWidth = d1.GetFormulaSAWidth(); @@ -1270,8 +1350,18 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q newDetail.SetMx(d1.GetMx()); newDetail.SetMy(d1.GetMy()); newDetail.SetUnited(true); - VToolSeamAllowance::Create(0, newDetail, formulaSAWidth, initData.scene, initData.doc, initData.data, - initData.parse, Source::FromTool, drawName); + + VToolSeamAllowanceInitData pieceInitData; + pieceInitData.detail = newDetail; + pieceInitData.width = formulaSAWidth; + pieceInitData.scene = initData.scene; + pieceInitData.doc = initData.doc; + pieceInitData.data = initData.data; + pieceInitData.parse = initData.parse; + pieceInitData.typeCreation = Source::FromTool; + pieceInitData.drawName = drawName; + + VToolSeamAllowance::Create(pieceInitData); auto RemoveDetail = [initData](quint32 id) { @@ -1292,17 +1382,17 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, - qreal angle) +void UpdateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - UpdateUnitedNodes(id, initData, dx, dy, pRotate, angle); - UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, id)); - UpdateUnitedDetailInternalPaths(id, initData, dx, dy, pRotate, angle, GetPiece2InternalPaths(initData.doc, id)); - UpdateUnitedDetailPins(id, initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, id)); + UpdateUnitedNodes(initData, dx, dy, pRotate, angle); + UpdateUnitedDetailCSA(initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, initData.id)); + UpdateUnitedDetailInternalPaths(initData, dx, dy, pRotate, angle, + GetPiece2InternalPaths(initData.doc, initData.id)); + UpdateUnitedDetailPins(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id)); } //--------------------------------------------------------------------------------------------------------------------- -void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData) +void UniteDetails(const VToolUnionDetailsInitData &initData) { VPieceNode det1p1; qreal dx = 0; @@ -1314,14 +1404,14 @@ void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData) const VPiece d1 = initData.data->GetPiece(initData.d1id); const VPiece d2 = initData.data->GetPiece(initData.d2id); UnionInitParameters(initData, d1.GetPath(), d2.GetPath(), det1p1, dx, dy, angle); - CreateUnitedDetail(id, initData, dx, dy, det1p1.GetId(), angle); + CreateUnitedDetail(initData, dx, dy, det1p1.GetId(), angle); } else { - const VPiecePath d1Path = GetPiece1MainPath(initData.doc, id); - const VPiecePath d2Path = GetPiece2MainPath(initData.doc, id); + const VPiecePath d1Path = GetPiece1MainPath(initData.doc, initData.id); + const VPiecePath d2Path = GetPiece2MainPath(initData.doc, initData.id); UnionInitParameters(initData, d1Path, d2Path, det1p1, dx, dy, angle); - UpdateUnitedDetail(id, initData, dx, dy, det1p1.GetId(), angle); + UpdateUnitedDetail(initData, dx, dy, det1p1.GetId(), angle); } } } // static functions @@ -1329,13 +1419,11 @@ void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData) //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolUnionDetails costructor. - * @param id object id in container. * @param initData global init data. * @param parent parent object. */ -VToolUnionDetails::VToolUnionDetails(quint32 id, const VToolUnionDetailsInitData &initData, - QObject *parent) - : VAbstractTool(initData.doc, initData.data, id, parent), +VToolUnionDetails::VToolUnionDetails(const VToolUnionDetailsInitData &initData, QObject *parent) + : VAbstractTool(initData.doc, initData.data, initData.id, parent), d1id(initData.d1id), d2id(initData.d2id), indexD1(initData.indexD1), @@ -1431,7 +1519,7 @@ VToolUnionDetails* VToolUnionDetails::Create(QSharedPointer dialog, initData.retainPieces = dialogTool->RetainPieces(); qApp->getUndoStack()->beginMacro(tr("union details")); - VToolUnionDetails* tool = Create(0, initData); + VToolUnionDetails* tool = Create(initData); qApp->getUndoStack()->endMacro(); return tool; } @@ -1439,36 +1527,34 @@ VToolUnionDetails* VToolUnionDetails::Create(QSharedPointer dialog, //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool. - * @param _id tool id, 0 if tool doesn't exist yet. * @param initData contains all init data. */ -VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VToolUnionDetailsInitData &initData) +VToolUnionDetails* VToolUnionDetails::Create(VToolUnionDetailsInitData initData) { VToolUnionDetails *unionDetails = nullptr; - quint32 id = _id; if (initData.typeCreation == Source::FromGui) { - id = VContainer::getNextId(); + initData.id = VContainer::getNextId(); } else { if (initData.parse != Document::FullParse) { - initData.doc->UpdateToolData(id, initData.data); + initData.doc->UpdateToolData(initData.id, initData.data); } } //First add tool to file if (initData.parse == Document::FullParse) { - VAbstractTool::AddRecord(id, Tool::UnionDetails, initData.doc); + VAbstractTool::AddRecord(initData.id, Tool::UnionDetails, initData.doc); //Scene doesn't show this tool, so doc will destroy this object. - unionDetails = new VToolUnionDetails(id, initData); - VAbstractPattern::AddTool(id, unionDetails); + unionDetails = new VToolUnionDetails(initData); + VAbstractPattern::AddTool(initData.id, unionDetails); // Unfortunatelly doc will destroy all objects only in the end, but we should delete them before each FullParse initData.doc->AddToolOnRemove(unionDetails); } - UniteDetails(id, initData); + UniteDetails(initData); return unionDetails; } diff --git a/src/libs/vtools/tools/vtooluniondetails.h b/src/libs/vtools/tools/vtooluniondetails.h index 33729c1db..a135dd8e6 100644 --- a/src/libs/vtools/tools/vtooluniondetails.h +++ b/src/libs/vtools/tools/vtooluniondetails.h @@ -47,18 +47,14 @@ class DialogTool; -struct VToolUnionDetailsInitData +struct VToolUnionDetailsInitData : public VAbstractToolInitData { VToolUnionDetailsInitData() - : d1id(NULL_ID), + : VAbstractToolInitData(), + d1id(NULL_ID), d2id(NULL_ID), indexD1(NULL_ID), indexD2(NULL_ID), - scene(nullptr), - doc(nullptr), - data(nullptr), - parse(Document::FullParse), - typeCreation(Source::FromFile), retainPieces(false) {} @@ -66,11 +62,6 @@ struct VToolUnionDetailsInitData quint32 d2id; quint32 indexD1; quint32 indexD2; - VMainGraphicsScene *scene; - VAbstractPattern *doc; - VContainer *data; - Document parse; - Source typeCreation; bool retainPieces; }; @@ -83,7 +74,7 @@ class VToolUnionDetails : public VAbstractTool public: static VToolUnionDetails *Create(QSharedPointer dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolUnionDetails *Create(const quint32 _id, const VToolUnionDetailsInitData &initData); + static VToolUnionDetails *Create(VToolUnionDetailsInitData initData); static const QString ToolType; static const QString TagDetail; @@ -129,7 +120,7 @@ private: /** @brief indexD2 index edge in second detail. */ quint32 indexD2; - VToolUnionDetails(quint32 id, const VToolUnionDetailsInitData &initData, QObject *parent = nullptr); + VToolUnionDetails(const VToolUnionDetailsInitData &initData, QObject *parent = nullptr); void AddDetail(QDomElement &domElement, const VPiece &d) const; void AddToModeling(const QDomElement &domElement);