From d2ff75dedceed2033669f08c71f2537dbc6d355a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 18 Jan 2017 10:17:18 +0200 Subject: [PATCH] Tool Union Details now works. --HG-- branch : feature --- src/libs/vpatterndb/vpiece.cpp | 12 ++ src/libs/vpatterndb/vpiece.h | 2 + .../tools/nodeDetails/vtoolpiecepath.cpp | 33 ++- .../vtools/tools/nodeDetails/vtoolpiecepath.h | 1 + src/libs/vtools/tools/vabstracttool.cpp | 93 ++++++++- src/libs/vtools/tools/vabstracttool.h | 5 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 106 ++-------- src/libs/vtools/tools/vtoolseamallowance.h | 4 +- src/libs/vtools/tools/vtooluniondetails.cpp | 192 +++++++++--------- src/libs/vtools/tools/vtooluniondetails.h | 2 +- 10 files changed, 247 insertions(+), 203 deletions(-) diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 398866c27..9fc8a2a10 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -281,6 +281,12 @@ void VPiece::SetInternalPaths(const QVector &iPaths) d->m_internalPaths = iPaths; } +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::AppendInternalPath(quint32 path) +{ + d->m_internalPaths.append(path); +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::GetCustomSARecords() const { @@ -293,6 +299,12 @@ void VPiece::SetCustomSARecords(const QVector &records) d->m_customSARecords = records; } +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::AppendCustomSARecord(const CustomSARecord &record) +{ + d->m_customSARecords.append(record); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief MissingNodes find missing nodes in detail. When we deleted object in detail and return this detail need diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 47bc31f05..fcd2c9948 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -81,9 +81,11 @@ public: QVector GetInternalPaths() const; void SetInternalPaths(const QVector &iPaths); + void AppendInternalPath(quint32 path); QVector GetCustomSARecords() const; void SetCustomSARecords(const QVector &records); + void AppendCustomSARecord(const CustomSARecord &record); QVector MissingNodes(const VPiece &det) const; QVector MissingCSAPath(const VPiece &det) const; diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index d1f806fb7..0a3cb028c 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -40,8 +40,10 @@ VToolPiecePath *VToolPiecePath::Create(DialogTool *dialog, VMainGraphicsScene *s SCASSERT(dialog != nullptr); DialogPiecePath *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); - const VPiecePath path = dialogTool->GetPiecePath(); + 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); return pathTool; @@ -90,7 +92,6 @@ VToolPiecePath *VToolPiecePath::Create(quint32 _id, const VPiecePath &path, quin SCASSERT(saTool != nullptr); pathTool->setParentItem(saTool); pathTool->SetParentType(ParentType::Item); - doc->IncrementReferens(id); } else { @@ -201,8 +202,6 @@ void VToolPiecePath::AddToFile() AddNodes(doc, domElement, path); - qApp->getUndoStack()->beginMacro(tr("new path")); - AddToModeling(domElement); if (m_pieceId > NULL_ID) @@ -230,8 +229,6 @@ void VToolPiecePath::AddToFile() qApp->getUndoStack()->push(saveCommand);// First push then make a connect VAbstractTool::data.UpdatePiece(m_pieceId, newDet);// Update piece because first save will not call lite update connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - - qApp->getUndoStack()->endMacro(); } } @@ -263,6 +260,23 @@ void VToolPiecePath::HideNode() hide(); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::ToolCreation(const Source &typeCreation) +{ + if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) + { + AddToFile(); + if (typeCreation != Source::FromTool) + { + qApp->getUndoStack()->endMacro(); + } + } + else + { + RefreshDataInFile(); + } +} + //--------------------------------------------------------------------------------------------------------------------- VToolPiecePath::VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId, const Source &typeCreation, const QString &drawName, const quint32 &idTool, @@ -271,6 +285,7 @@ VToolPiecePath::VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 QGraphicsPathItem(parent), m_pieceId(pieceId) { + IncrementNodes(VAbstractTool::data.GetPiecePath(id)); RefreshGeometry(); ToolCreation(typeCreation); } @@ -296,8 +311,7 @@ void VToolPiecePath::IncrementNodes(const VPiecePath &path) const { for (int i = 0; i < path.CountNodes(); ++i) { - const QSharedPointer node = VAbstractTool::data.GetGObject(path.at(i).GetId()); - doc->IncrementReferens(node->getIdTool()); + doc->IncrementReferens(VAbstractTool::data.GetGObject(path.at(i).GetId())->getIdTool()); } } @@ -306,7 +320,6 @@ void VToolPiecePath::DecrementNodes(const VPiecePath &path) const { for (int i = 0; i < path.CountNodes(); ++i) { - const QSharedPointer node = VAbstractTool::data.GetGObject(path.at(i).GetId()); - doc->DecrementReferens(node->getIdTool()); + doc->DecrementReferens(VAbstractTool::data.GetGObject(path.at(i).GetId())->getIdTool()); } } diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h index 6360e4b3f..2b1f4fca8 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h @@ -63,6 +63,7 @@ protected: virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual void ShowNode() Q_DECL_OVERRIDE; virtual void HideNode() Q_DECL_OVERRIDE; + virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolPiecePath) diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index ec513ae87..1198a0683 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -62,12 +62,17 @@ #include "../vgeometry/../ifc/ifcdef.h" #include "../vgeometry/vgeometrydef.h" #include "../vgeometry/vgobject.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vgeometry/vsplinepath.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vellipticalarc.h" #include "../vmisc/vcommonsettings.h" #include "../vmisc/logging.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vpiecenode.h" #include "../vwidgets/vgraphicssimpletextitem.h" -#include "vdatatool.h" +#include "nodeDetails/nodedetails.h" class QGraphicsEllipseItem; class QGraphicsLineItem; @@ -75,6 +80,51 @@ template class QSharedPointer; const QString VAbstractTool::AttrInUse = QStringLiteral("inUse"); +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +template +/** + * @brief CreateNode create new node for detail. + * @param data container. + * @param id id parent object. + * @return id for new object. + */ +quint32 CreateNode(VContainer *data, quint32 id) +{ + //We can't use exist object. Need create new. + T *node = new T(*data->GeometricObject(id).data()); + node->setMode(Draw::Modeling); + return data->AddGObject(node); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 CreateNodeSpline(VContainer *data, quint32 id) +{ + if (data->GetGObject(id)->getType() == GOType::Spline) + { + return CreateNode(data, id); + } + else + { + return CreateNode(data, id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 CreateNodeSplinePath(VContainer *data, quint32 id) +{ + if (data->GetGObject(id)->getType() == GOType::SplinePath) + { + return CreateNode(data, id); + } + else + { + return CreateNode(data, id); + } +} +}//static functions + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VAbstractTool container. @@ -533,3 +583,44 @@ void VAbstractTool::AddNode(VAbstractPattern *doc, QDomElement &domElement, cons { domElement.appendChild(AddSANode(doc, VAbstractPattern::TagNode, node)); } + +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractTool::PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data) +{ + QVector nodes; + for (int i = 0; i< path.CountNodes(); ++i) + { + quint32 id = 0; + VPieceNode nodeD = path.at(i); + switch (nodeD.GetTypeTool()) + { + case (Tool::NodePoint): + id = CreateNode(data, nodeD.GetId()); + VNodePoint::Create(doc, data, scene, id, nodeD.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeArc): + id = CreateNode(data, nodeD.GetId()); + VNodeArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeElArc): + id = CreateNode(data, nodeD.GetId()); + VNodeEllipticalArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeSpline): + id = CreateNodeSpline(data, nodeD.GetId()); + VNodeSpline::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeSplinePath): + id = CreateNodeSplinePath(data, nodeD.GetId()); + VNodeSplinePath::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); + break; + default: + qDebug()<<"May be wrong tool type!!! Ignoring."< PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); private: Q_DISABLE_COPY(VAbstractTool) }; diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index ee48d5312..be6b1c712 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -90,69 +90,8 @@ VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphics DialogSeamAllowance *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); VPiece detail = dialogTool->GetPiece(); - QVector nodes; qApp->getUndoStack()->beginMacro("add detail"); - for (int i = 0; i< detail.GetPath().CountNodes(); ++i) - { - quint32 id = 0; - VPieceNode nodeD = detail.GetPath().at(i); - switch (nodeD.GetTypeTool()) - { - case (Tool::NodePoint): - { - id = CreateNode(data, nodeD.GetId()); - VNodePoint::Create(doc, data, scene, id, nodeD.GetId(), Document::FullParse, Source::FromGui); - } - break; - case (Tool::NodeArc): - { - id = CreateNode(data, nodeD.GetId()); - VNodeArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); - } - break; - case (Tool::NodeElArc): - { - id = CreateNode(data, nodeD.GetId()); - VNodeEllipticalArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); - } - break; - case (Tool::NodeSpline): - { - const auto obj = data->GetGObject(nodeD.GetId()); - if (obj->getType() == GOType::Spline) - { - id = CreateNode(data, nodeD.GetId()); - } - else - { - id = CreateNode(data, nodeD.GetId()); - } - VNodeSpline::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); - } - break; - case (Tool::NodeSplinePath): - { - const auto obj = data->GetGObject(nodeD.GetId()); - if (obj->getType() == GOType::SplinePath) - { - id = CreateNode(data, nodeD.GetId()); - } - else - { - id = CreateNode(data, nodeD.GetId()); - } - VNodeSplinePath::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); - } - break; - default: - qDebug()<<"May be wrong tool type!!! Ignoring."<setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove); - //connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren); - if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) - { - AddToFile(); - if (typeCreation != Source::FromTool) - { - qApp->getUndoStack()->endMacro(); - } - } - else - { - RefreshDataInFile(); - } + connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolSeamAllowance::ResetChildren); + ToolCreation(typeCreation); setAcceptHoverEvents(true); connect(m_dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolSeamAllowance::SaveMoveDetail); @@ -1165,7 +1093,7 @@ void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *sce case (Tool::NodeElArc): case (Tool::NodeSpline): case (Tool::NodeSplinePath): - doc->IncrementReferens(detail.GetPath().at(i).GetId()); + doc->IncrementReferens(VAbstractTool::data.GetGObject(detail.GetPath().at(i).GetId())->getIdTool()); break; default: qDebug()<<"Get wrong tool type. Ignore."; @@ -1194,6 +1122,7 @@ void VToolSeamAllowance::InitInternalPaths(const VPiece &detail) SCASSERT(tool != nullptr); tool->setParentItem(this); tool->SetParentType(ParentType::Item); + tool->show(); doc->IncrementReferens(records.at(i)); } } @@ -1219,19 +1148,20 @@ void VToolSeamAllowance::DeleteTool(bool ask) } //--------------------------------------------------------------------------------------------------------------------- -template -/** - * @brief CreateNode create new node for detail. - * @param data container. - * @param id id parent object. - * @return id for new object. - */ -quint32 VToolSeamAllowance::CreateNode(VContainer *data, const quint32 &id) +void VToolSeamAllowance::ToolCreation(const Source &typeCreation) { - //We can't use exist object. Need create new. - T *node = new T(*data->GeometricObject(id).data()); - node->setMode(Draw::Modeling); - return data->AddGObject(node); + if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) + { + AddToFile(); + if (typeCreation != Source::FromTool) + { + qApp->getUndoStack()->endMacro(); + } + } + else + { + RefreshDataInFile(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 4b25acc00..1c8b1a2e3 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -125,6 +125,7 @@ protected: virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} virtual void DeleteTool(bool ask = true) Q_DECL_OVERRIDE; + virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolSeamAllowance) @@ -143,9 +144,6 @@ private: void SetDialog(); - template - static quint32 CreateNode(VContainer *data, const quint32 &id); - VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &m_drawName, QGraphicsItem * parent = nullptr); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 7a2ec2d05..9cd040617 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -111,13 +111,13 @@ VPiecePath GetPiecePath(int piece, VAbstractPattern *doc, quint32 id) for (qint32 i = 0; i < nodesList.size(); ++i) { const QDomElement element = nodesList.at(i).toElement(); - if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail) + if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == piece) { const QDomNodeList detList = element.childNodes(); for (qint32 j = 0; j < detList.size(); ++j) { const QDomElement element = detList.at(j).toElement(); - if (not element.isNull() && element.tagName() == VAbstractPattern::TagNodes && j+1 == piece) + if (not element.isNull() && element.tagName() == VAbstractPattern::TagNodes) { return VAbstractPattern::ParsePieceNodes(element); } @@ -141,7 +141,7 @@ VPiecePath GetPiece2MainPath(VAbstractPattern *doc, quint32 id) } //--------------------------------------------------------------------------------------------------------------------- -QVector GetPieceCSAList(int piece, VAbstractPattern *doc, quint32 id) +QVector GetPiece2CSAPaths(VAbstractPattern *doc, quint32 id) { const QDomElement tool = doc->elementById(id); if (tool.isNull()) @@ -154,13 +154,13 @@ QVector GetPieceCSAList(int piece, VAbstractPattern *doc, quint3 for (qint32 i = 0; i < nodesList.size(); ++i) { const QDomElement element = nodesList.at(i).toElement(); - if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail) + if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2) { const QDomNodeList detList = element.childNodes(); for (qint32 j = 0; j < detList.size(); ++j) { const QDomElement element = detList.at(j).toElement(); - if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagCSA && j+1 == piece) + if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagCSA) { return VAbstractPattern::ParsePieceCSARecords(element); } @@ -172,19 +172,7 @@ QVector GetPieceCSAList(int piece, VAbstractPattern *doc, quint3 } //--------------------------------------------------------------------------------------------------------------------- -QVector GetPiece1CSAPaths(VAbstractPattern *doc, quint32 id) -{ - return GetPieceCSAList(1, doc, id); -} - -//--------------------------------------------------------------------------------------------------------------------- -QVector GetPiece2CSAPaths(VAbstractPattern *doc, quint32 id) -{ - return GetPieceCSAList(2, doc, id); -} - -//--------------------------------------------------------------------------------------------------------------------- -QVector GetPieceInternalPathList(int piece, VAbstractPattern *doc, quint32 id) +QVector GetPiece2InternalPaths(VAbstractPattern *doc, quint32 id) { const QDomElement tool = doc->elementById(id); if (tool.isNull()) @@ -197,13 +185,13 @@ QVector GetPieceInternalPathList(int piece, VAbstractPattern *doc, quin for (qint32 i = 0; i < nodesList.size(); ++i) { const QDomElement element = nodesList.at(i).toElement(); - if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail) + if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2) { const QDomNodeList detList = element.childNodes(); for (qint32 j = 0; j < detList.size(); ++j) { const QDomElement element = detList.at(j).toElement(); - if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagIPaths && j+1 == piece) + if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagIPaths) { return VAbstractPattern::ParsePieceInternalPaths(element); } @@ -214,18 +202,6 @@ QVector GetPieceInternalPathList(int piece, VAbstractPattern *doc, quin return QVector(); } -//--------------------------------------------------------------------------------------------------------------------- -QVector GetPiece1InternalPaths(VAbstractPattern *doc, quint32 id) -{ - return GetPieceInternalPathList(1, doc, id); -} - -//--------------------------------------------------------------------------------------------------------------------- -QVector GetPiece2InternalPaths(VAbstractPattern *doc, quint32 id) -{ - return GetPieceInternalPathList(2, doc, id); -} - //--------------------------------------------------------------------------------------------------------------------- QString DrawName(VAbstractPattern *doc, quint32 d1id, quint32 d2id) { @@ -314,32 +290,30 @@ void BiasRotatePoint(VPointF *point, qreal dx, qreal dy, const QPointF &pRotate, } //--------------------------------------------------------------------------------------------------------------------- -void PointsOnEdge(const VPiece &d, quint32 index, VPointF &p1, VPointF &p2, VContainer *data) +void PointsOnEdge(const VPiecePath &path, quint32 index, VPointF &p1, VPointF &p2, VContainer *data) { VPieceNode det2p1; VPieceNode det2p2; - d.GetPath().NodeOnEdge(index, det2p1, det2p2); + path.NodeOnEdge(index, det2p1, det2p2); p1 = VPointF(*data->GeometricObject(det2p1.GetId())); p2 = VPointF(*data->GeometricObject(det2p2.GetId())); } //--------------------------------------------------------------------------------------------------------------------- -void UnionInitParameters(const VToolUnionDetailsInitData &initData, VPieceNode &det1p1, qreal &dx, qreal &dy, - qreal &angle) +void UnionInitParameters(const VToolUnionDetailsInitData &initData, const VPiecePath &d1Path, const VPiecePath &d2Path, + VPieceNode &det1p1, qreal &dx, qreal &dy, qreal &angle) { - const VPiece d1 = initData.data->GetPiece(initData.d1id); VPieceNode det1p2; - d1.GetPath().NodeOnEdge(initData.indexD1, det1p1, det1p2); + d1Path.NodeOnEdge(initData.indexD1, det1p1, det1p2); Q_UNUSED(det1p2) VPointF point1; VPointF point2; - PointsOnEdge(d1, initData.indexD1, point1, point2, initData.data); + PointsOnEdge(d1Path, initData.indexD1, point1, point2, initData.data); VPointF point3; VPointF point4; - const VPiece d2 = initData.data->GetPiece(initData.d2id); - PointsOnEdge(d2, initData.indexD2, point3, point4, initData.data); + PointsOnEdge(d2Path, initData.indexD2, point3, point4, initData.data); dx = point1.x() - point4.x(); dy = point1.y() - point4.y(); @@ -987,6 +961,7 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector { QVector newList = newDetail.GetCustomSARecords(); const QVector oldList = d.GetCustomSARecords(); + QVector nodeChildren; for(int i=0; i < oldList.size(); ++i) { CustomSARecord record = oldList.at(i); @@ -995,14 +970,16 @@ 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, children, drawName, dx, dy, pRotate, angle); + AddNodeToNewPath(initData, newPath, path.at(i), id, nodeChildren, drawName, dx, dy, pRotate, angle); } - VToolPiecePath *pathTool = VToolPiecePath::Create(0, newPath, NULL_ID, initData.scene, initData.doc, - initData.data, initData.parse, Source::FromTool, drawName, - id); - record.path = pathTool->getId(); + 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); + record.path = idPath; newList.append(record); + nodeChildren.prepend(idPath); } + children += nodeChildren; newDetail.SetCustomSARecords(newList); } @@ -1010,8 +987,13 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { + const QVector d1Records = d1.GetCustomSARecords(); + for (int i = 0; i < d1Records.size(); ++i) + { + newDetail.AppendCustomSARecord(d1Records.at(i)); + } + QVector children; - CreateUnitedDetailCSA(newDetail, d1, children, id, drawName, initData, dx, dy, pRotate, angle); CreateUnitedDetailCSA(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle); SCASSERT(not children.isEmpty()) @@ -1025,6 +1007,7 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector { QVector newList = newDetail.GetInternalPaths(); const QVector oldList = d.GetInternalPaths(); + QVector nodeChildren; for(int i=0; i < oldList.size(); ++i) { const VPiecePath path = initData.data->GetPiecePath(oldList.at(i)); @@ -1033,13 +1016,15 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector for (int i=0; i < path.CountNodes(); ++i) { - AddNodeToNewPath(initData, newPath, path.at(i), id, children, drawName, dx, dy, pRotate, angle); + AddNodeToNewPath(initData, newPath, path.at(i), id, nodeChildren, drawName, dx, dy, pRotate, angle); } - VToolPiecePath *pathTool = VToolPiecePath::Create(0, newPath, NULL_ID, initData.scene, initData.doc, - initData.data, initData.parse, Source::FromTool, drawName, - id); - newList.append(pathTool->getId()); + 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); + newList.append(idPath); + nodeChildren.prepend(idPath); } + children += nodeChildren; newDetail.SetInternalPaths(newList); } @@ -1048,8 +1033,13 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { + const QVector d1Internal = d1.GetInternalPaths(); + for (int i = 0; i < d1Internal.size(); ++i) + { + newDetail.AppendInternalPath(d1Internal.at(i)); + } + QVector children; - CreateUnitedDetailInternalPaths(newDetail, d1, children, id, drawName, initData, dx, dy, pRotate, angle); CreateUnitedDetailInternalPaths(newDetail, d2, children, id, drawName, initData, dx, dy, pRotate, angle); SCASSERT(not children.isEmpty()) @@ -1060,10 +1050,10 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - const VPiecePath d1Path = GetPiece1MainPath(initData.doc, initData.d1id); + const VPiecePath d1Path = GetPiece1MainPath(initData.doc, id); const VPiecePath d1REPath = d1Path.RemoveEdge(initData.indexD1); - const VPiecePath d2Path = GetPiece2MainPath(initData.doc, initData.d2id); + const VPiecePath d2Path = GetPiece2MainPath(initData.doc, id); const VPiecePath d2REPath = d2Path.RemoveEdge(initData.indexD2); const qint32 countNodeD1 = d1REPath.CountNodes(); @@ -1133,43 +1123,46 @@ void UpdateUnitedNodes(quint32 id, const VToolUnionDetailsInitData &initData, qr } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedDetailCSA(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, - qreal angle, const QVector &records) +void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, + qreal angle, const QVector &records, QVector children) { - QVector children = GetCSAChildren(initData.doc, id); for (int i=0; i < records.size(); ++i) { - VPiecePath path = initData.data->GetPiecePath(records.at(i).path); - UpdatePathNode(initData.data, path.at(i), children, dx, dy, pRotate, angle); + const VPiecePath path = initData.data->GetPiecePath(records.at(i)); + const quint32 updatedId = TakeNextId(children); + + VPiecePath updatedPath(path); + updatedPath.Clear(); + + for (int j=0; j < path.CountNodes(); ++j) + { + const VPieceNode &node = path.at(j); + const quint32 id = TakeNextId(children); + updatedPath.Append(VPieceNode(id, node.GetTypeTool(), node.GetReverse())); + QVector nodeChildren = {id}; + UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle); + } + initData.data->UpdatePiecePath(updatedId, updatedPath); } } //--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedCSA(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, - qreal angle) +void UpdateUnitedDetailCSA(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, + qreal angle, const QVector &records) { - UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece1CSAPaths(initData.doc, id)); - UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, id)); + QVector idRecords; + for (int i = 0; i < records.size(); ++i) + { + idRecords.append(records.at(i).path); + } + UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, idRecords, GetCSAChildren(initData.doc, id)); } //--------------------------------------------------------------------------------------------------------------------- void UpdateUnitedDetailInternalPaths(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle, const QVector &records) { - QVector children = GetInternalPathsChildren(initData.doc, id); - for (int i=0; i < records.size(); ++i) - { - VPiecePath path = initData.data->GetPiecePath(records.at(i)); - UpdatePathNode(initData.data, path.at(i), children, dx, dy, pRotate, angle); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void UpdateUnitedInternalPaths(quint32 id, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, - quint32 pRotate, qreal angle) -{ - UpdateUnitedDetailInternalPaths(id, initData, dx, dy, pRotate, angle, GetPiece1InternalPaths(initData.doc, id)); - UpdateUnitedDetailInternalPaths(id, initData, dx, dy, pRotate, angle, GetPiece2InternalPaths(initData.doc, id)); + UpdateUnitedDetailPaths(initData, dx, dy, pRotate, angle, records, GetInternalPathsChildren(initData.doc, id)); } //--------------------------------------------------------------------------------------------------------------------- @@ -1215,8 +1208,8 @@ void UpdateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q qreal angle) { UpdateUnitedNodes(id, initData, dx, dy, pRotate, angle); - UpdateUnitedCSA(id, initData, dx, dy, pRotate, angle); - UpdateUnitedInternalPaths(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)); } //--------------------------------------------------------------------------------------------------------------------- @@ -1226,14 +1219,19 @@ void UniteDetails(quint32 id, const VToolUnionDetailsInitData &initData) qreal dx = 0; qreal dy = 0; qreal angle = 0; - UnionInitParameters(initData, det1p1, dx, dy, angle); if (initData.typeCreation == Source::FromGui) { - CreateUnitedDetail(id, initData, dx, dy, det1p1.GetId(), angle); + 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); } else { + const VPiecePath d1Path = GetPiece1MainPath(initData.doc, id); + const VPiecePath d2Path = GetPiece2MainPath(initData.doc, id); + UnionInitParameters(initData, d1Path, d2Path, det1p1, dx, dy, angle); UpdateUnitedDetail(id, initData, dx, dy, det1p1.GetId(), angle); } } @@ -1493,18 +1491,13 @@ QVector VToolUnionDetails::GetReferenceObjects() const switch (parts.indexOf(element.tagName())) { case 0://VAbstractPattern::TagNodes - list += NodesReferenceObjects(element); + list += ReferenceObjects(element, TagNode, AttrIdObject); break; case 1://VToolSeamAllowance::TagCSA case 2://VToolSeamAllowance::TagIPaths - { - const quint32 id = doc->GetParametrUInt(element, VAbstractPattern::AttrPath, NULL_ID_STR); - if (id > NULL_ID) - { - list.append(id); - } + list += ReferenceObjects(element, VToolSeamAllowance::TagRecord, + VAbstractPattern::AttrPath); break; - } default: break; } @@ -1516,23 +1509,24 @@ QVector VToolUnionDetails::GetReferenceObjects() const } //--------------------------------------------------------------------------------------------------------------------- -QVector VToolUnionDetails::NodesReferenceObjects(const QDomElement &nodes) const +QVector VToolUnionDetails::ReferenceObjects(const QDomElement &root, const QString &tag, + const QString &attribute) const { - QVector list; + QVector objects; - const QDomNodeList nodeList = nodes.childNodes(); - for (qint32 i = 0; i < nodeList.size(); ++i) + const QDomNodeList list = root.childNodes(); + for (qint32 i = 0; i < list.size(); ++i) { - const QDomElement element = nodeList.at(i).toElement(); - if (not element.isNull() && element.tagName() == VToolUnionDetails::TagNode) + const QDomElement element = list.at(i).toElement(); + if (not element.isNull() && element.tagName() == tag) { - const quint32 id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + const quint32 id = doc->GetParametrUInt(element, attribute, NULL_ID_STR); if (id > NULL_ID) { - list.append(id); + objects.append(id); } } } - return list; + return objects; } diff --git a/src/libs/vtools/tools/vtooluniondetails.h b/src/libs/vtools/tools/vtooluniondetails.h index 2265a0677..b8c3c5649 100644 --- a/src/libs/vtools/tools/vtooluniondetails.h +++ b/src/libs/vtools/tools/vtooluniondetails.h @@ -143,7 +143,7 @@ private: void AddDetail(QDomElement &domElement, const VPiece &d) const; void AddToModeling(const QDomElement &domElement); QVector GetReferenceObjects() const; - QVector NodesReferenceObjects(const QDomElement &nodes) const; + QVector ReferenceObjects(const QDomElement &root, const QString &tag, const QString &attribute) const; }; #endif // VTOOLUNIONDETAILS_H