From 20ccbaae019b92a3e0846345d498d123d3d3672f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 21 Mar 2017 18:00:31 +0200 Subject: [PATCH] Create modeling items before insert new node. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 2 +- src/libs/vtools/tools/vabstracttool.cpp | 69 +++++++++------ src/libs/vtools/tools/vabstracttool.h | 3 + src/libs/vtools/tools/vtoolseamallowance.cpp | 89 ++++++++++++-------- src/libs/vtools/tools/vtoolseamallowance.h | 8 +- 5 files changed, 103 insertions(+), 68 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 600549224..43753ccee 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1171,7 +1171,7 @@ void MainWindow::ClosedDialogInsertNode(int result) { DialogInsertNode *dTool = qobject_cast(dialogTool); SCASSERT(dTool != nullptr); - VToolSeamAllowance::InsertNode(dTool->GetNode(), dTool->GetPieceId(), pattern, doc); + VToolSeamAllowance::InsertNode(dTool->GetNode(), dTool->GetPieceId(), sceneDetails, pattern, doc); } ArrowTool(); doc->LiteParseTree(Document::LiteParse); diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 28da1944f..eb3036c03 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -679,36 +679,51 @@ QVector VAbstractTool::PrepareNodes(const VPiecePath &path, VMainGra QVector nodes; for (int i = 0; i< path.CountNodes(); ++i) { - quint32 id = 0; VPieceNode nodeD = path.at(i); - switch (nodeD.GetTypeTool()) + const quint32 id = PrepareNode(nodeD, scene, doc, data); + if (id > NULL_ID) { - 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."<(data, node.GetId()); + VNodePoint::Create(doc, data, scene, id, node.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeArc): + id = CreateNode(data, node.GetId()); + VNodeArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeElArc): + id = CreateNode(data, node.GetId()); + VNodeEllipticalArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeSpline): + id = CreateNodeSpline(data, node.GetId()); + VNodeSpline::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + break; + case (Tool::NodeSplinePath): + id = CreateNodeSplinePath(data, node.GetId()); + VNodeSplinePath::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui); + break; + default: + qDebug()<<"May be wrong tool type!!! Ignoring."< PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); + static quint32 PrepareNode(const VPieceNode &node, 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 e005b1976..d0788a5cc 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -167,9 +167,12 @@ void VToolSeamAllowance::Remove(bool ask) } //--------------------------------------------------------------------------------------------------------------------- -void VToolSeamAllowance::InsertNode(const VPieceNode &node, quint32 pieceId, VContainer *data, VAbstractPattern *doc) +void VToolSeamAllowance::InsertNode(VPieceNode node, quint32 pieceId, VMainGraphicsScene *scene, + VContainer *data, VAbstractPattern *doc) { - SCASSERT(data != nullptr); + SCASSERT(scene != nullptr) + SCASSERT(data != nullptr) + SCASSERT(doc != nullptr) if (pieceId > NULL_ID) { @@ -185,8 +188,21 @@ void VToolSeamAllowance::InsertNode(const VPieceNode &node, quint32 pieceId, VCo VPiece newDet = oldDet; + const quint32 id = PrepareNode(node, scene, doc, data); + if (id == NULL_ID) + { + return; + } + + node.SetId(id); newDet.GetPath().Append(node); + // Seam allowance tool already initializated and can't init the node + VToolSeamAllowance *saTool = qobject_cast(doc->getTool(pieceId)); + SCASSERT(saTool != nullptr); + + InitNode(node, scene, data, doc, saTool); + SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, pieceId); qApp->getUndoStack()->push(saveCommand);// First push then make a connect data->UpdatePiece(pieceId, newDet);// Update piece because first save will not call lite update @@ -1422,24 +1438,43 @@ void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *sce { for (int i = 0; i< detail.GetPath().CountNodes(); ++i) { - switch (detail.GetPath().at(i).GetTypeTool()) + InitNode(detail.GetPath().at(i), scene, &(VAbstractTool::data), doc, this); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data, + VAbstractPattern *doc, VToolSeamAllowance *parent) +{ + SCASSERT(scene != nullptr) + SCASSERT(data != nullptr) + SCASSERT(doc != nullptr) + SCASSERT(parent != nullptr) + + switch (node.GetTypeTool()) + { + case (Tool::NodePoint): { - case (Tool::NodePoint): - { - VNodePoint *tool = InitTool(scene, detail.GetPath().at(i).GetId()); - connect(tool, &VNodePoint::ShowContextMenu, this, &VToolSeamAllowance::contextMenuEvent); - break; - } - case (Tool::NodeArc): - case (Tool::NodeElArc): - case (Tool::NodeSpline): - case (Tool::NodeSplinePath): - doc->IncrementReferens(VAbstractTool::data.GetGObject(detail.GetPath().at(i).GetId())->getIdTool()); - break; - default: - qDebug()<<"Get wrong tool type. Ignore."; - break; + VNodePoint *tool = qobject_cast(doc->getTool(node.GetId())); + SCASSERT(tool != nullptr); + + connect(tool, &VNodePoint::ShowContextMenu, parent, &VToolSeamAllowance::contextMenuEvent); + connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + tool->setParentItem(parent); + tool->SetParentType(ParentType::Item); + tool->setVisible(not node.IsExcluded());//Hide excluded point + doc->IncrementReferens(node.GetId()); + break; } + case (Tool::NodeArc): + case (Tool::NodeElArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + doc->IncrementReferens(data->GetGObject(node.GetId())->getIdTool()); + break; + default: + qDebug()<<"Get wrong tool type. Ignore."; + break; } } @@ -1528,21 +1563,3 @@ void VToolSeamAllowance::ToolCreation(const Source &typeCreation) RefreshDataInFile(); } } - -//--------------------------------------------------------------------------------------------------------------------- -template -/** - * @brief InitTool initial node item on scene - * @param scene pointer to scene. - * @param toolId if of tool object. - */ -Tool *VToolSeamAllowance::InitTool(VMainGraphicsScene *scene, quint32 toolId) -{ - Tool *tool = qobject_cast(doc->getTool(toolId)); - SCASSERT(tool != nullptr); - connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - tool->setParentItem(this); - tool->SetParentType(ParentType::Item); - doc->IncrementReferens(toolId); - return tool; -} diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 023e1fdec..4eab60d9e 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -74,7 +74,8 @@ public: void Remove(bool ask); - static void InsertNode(const VPieceNode &node, quint32 pieceId, VContainer *data, VAbstractPattern *doc); + static void InsertNode(VPieceNode node, quint32 pieceId, VMainGraphicsScene *scene, VContainer *data, + VAbstractPattern *doc); static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece); static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record); @@ -160,12 +161,11 @@ private: QPointF &pos); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); + static void InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data, VAbstractPattern *doc, + VToolSeamAllowance *parent); void InitCSAPaths(const VPiece &detail); void InitInternalPaths(const VPiece &detail); void InitPins(const VPiece &detail); - - template - Tool* InitTool(VMainGraphicsScene *scene, quint32 toolId); }; #endif // VTOOLSEAMALLOWANCE_H