Create modeling items before insert new node.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-03-21 18:00:31 +02:00
parent 7fe86bc319
commit 20ccbaae01
5 changed files with 103 additions and 68 deletions

View File

@ -1171,7 +1171,7 @@ void MainWindow::ClosedDialogInsertNode(int result)
{ {
DialogInsertNode *dTool = qobject_cast<DialogInsertNode*>(dialogTool); DialogInsertNode *dTool = qobject_cast<DialogInsertNode*>(dialogTool);
SCASSERT(dTool != nullptr); SCASSERT(dTool != nullptr);
VToolSeamAllowance::InsertNode(dTool->GetNode(), dTool->GetPieceId(), pattern, doc); VToolSeamAllowance::InsertNode(dTool->GetNode(), dTool->GetPieceId(), sceneDetails, pattern, doc);
} }
ArrowTool(); ArrowTool();
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);

View File

@ -679,36 +679,51 @@ QVector<VPieceNode> VAbstractTool::PrepareNodes(const VPiecePath &path, VMainGra
QVector<VPieceNode> nodes; QVector<VPieceNode> nodes;
for (int i = 0; i< path.CountNodes(); ++i) for (int i = 0; i< path.CountNodes(); ++i)
{ {
quint32 id = 0;
VPieceNode nodeD = path.at(i); VPieceNode nodeD = path.at(i);
switch (nodeD.GetTypeTool()) const quint32 id = PrepareNode(nodeD, scene, doc, data);
if (id > NULL_ID)
{
nodeD.SetId(id);
nodes.append(nodeD);
}
}
return nodes;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VAbstractTool::PrepareNode(const VPieceNode &node, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data)
{
SCASSERT(scene != nullptr)
SCASSERT(doc != nullptr)
SCASSERT(data != nullptr)
quint32 id = NULL_ID;
switch (node.GetTypeTool())
{ {
case (Tool::NodePoint): case (Tool::NodePoint):
id = CreateNode<VPointF>(data, nodeD.GetId()); id = CreateNode<VPointF>(data, node.GetId());
VNodePoint::Create(doc, data, scene, id, nodeD.GetId(), Document::FullParse, Source::FromGui); VNodePoint::Create(doc, data, scene, id, node.GetId(), Document::FullParse, Source::FromGui);
break; break;
case (Tool::NodeArc): case (Tool::NodeArc):
id = CreateNode<VArc>(data, nodeD.GetId()); id = CreateNode<VArc>(data, node.GetId());
VNodeArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); VNodeArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
break; break;
case (Tool::NodeElArc): case (Tool::NodeElArc):
id = CreateNode<VEllipticalArc>(data, nodeD.GetId()); id = CreateNode<VEllipticalArc>(data, node.GetId());
VNodeEllipticalArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); VNodeEllipticalArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
break; break;
case (Tool::NodeSpline): case (Tool::NodeSpline):
id = CreateNodeSpline(data, nodeD.GetId()); id = CreateNodeSpline(data, node.GetId());
VNodeSpline::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); VNodeSpline::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
break; break;
case (Tool::NodeSplinePath): case (Tool::NodeSplinePath):
id = CreateNodeSplinePath(data, nodeD.GetId()); id = CreateNodeSplinePath(data, node.GetId());
VNodeSplinePath::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui); VNodeSplinePath::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
break; break;
default: default:
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO; qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break; break;
} }
nodeD.SetId(id); return id;
nodes.append(nodeD);
}
return nodes;
} }

View File

@ -47,6 +47,7 @@
#include "vdatatool.h" #include "vdatatool.h"
class VGraphicsSimpleTextItem; class VGraphicsSimpleTextItem;
class VAbstractNode;
/** /**
* @brief The VAbstractTool abstract class for all tools. * @brief The VAbstractTool abstract class for all tools.
@ -150,6 +151,8 @@ protected:
static QVector<VPieceNode> PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc, static QVector<VPieceNode> PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data); VContainer *data);
static quint32 PrepareNode(const VPieceNode &node, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
private: private:
Q_DISABLE_COPY(VAbstractTool) Q_DISABLE_COPY(VAbstractTool)
}; };

View File

@ -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) if (pieceId > NULL_ID)
{ {
@ -185,8 +188,21 @@ void VToolSeamAllowance::InsertNode(const VPieceNode &node, quint32 pieceId, VCo
VPiece newDet = oldDet; VPiece newDet = oldDet;
const quint32 id = PrepareNode(node, scene, doc, data);
if (id == NULL_ID)
{
return;
}
node.SetId(id);
newDet.GetPath().Append(node); newDet.GetPath().Append(node);
// Seam allowance tool already initializated and can't init the node
VToolSeamAllowance *saTool = qobject_cast<VToolSeamAllowance*>(doc->getTool(pieceId));
SCASSERT(saTool != nullptr);
InitNode(node, scene, data, doc, saTool);
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, pieceId); SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, pieceId);
qApp->getUndoStack()->push(saveCommand);// First push then make a connect qApp->getUndoStack()->push(saveCommand);// First push then make a connect
data->UpdatePiece(pieceId, newDet);// Update piece because first save will not call lite update data->UpdatePiece(pieceId, newDet);// Update piece because first save will not call lite update
@ -1422,26 +1438,45 @@ void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *sce
{ {
for (int i = 0; i< detail.GetPath().CountNodes(); ++i) 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<VNodePoint>(scene, detail.GetPath().at(i).GetId()); VNodePoint *tool = qobject_cast<VNodePoint*>(doc->getTool(node.GetId()));
connect(tool, &VNodePoint::ShowContextMenu, this, &VToolSeamAllowance::contextMenuEvent); 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; break;
} }
case (Tool::NodeArc): case (Tool::NodeArc):
case (Tool::NodeElArc): case (Tool::NodeElArc):
case (Tool::NodeSpline): case (Tool::NodeSpline):
case (Tool::NodeSplinePath): case (Tool::NodeSplinePath):
doc->IncrementReferens(VAbstractTool::data.GetGObject(detail.GetPath().at(i).GetId())->getIdTool()); doc->IncrementReferens(data->GetGObject(node.GetId())->getIdTool());
break; break;
default: default:
qDebug()<<"Get wrong tool type. Ignore."; qDebug()<<"Get wrong tool type. Ignore.";
break; break;
} }
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::InitCSAPaths(const VPiece &detail) void VToolSeamAllowance::InitCSAPaths(const VPiece &detail)
@ -1528,21 +1563,3 @@ void VToolSeamAllowance::ToolCreation(const Source &typeCreation)
RefreshDataInFile(); RefreshDataInFile();
} }
} }
//---------------------------------------------------------------------------------------------------------------------
template <typename Tool>
/**
* @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<Tool*>(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;
}

View File

@ -74,7 +74,8 @@ public:
void Remove(bool ask); 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 AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece);
static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record); static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record);
@ -160,12 +161,11 @@ private:
QPointF &pos); QPointF &pos);
void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); 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 InitCSAPaths(const VPiece &detail);
void InitInternalPaths(const VPiece &detail); void InitInternalPaths(const VPiece &detail);
void InitPins(const VPiece &detail); void InitPins(const VPiece &detail);
template <typename Tool>
Tool* InitTool(VMainGraphicsScene *scene, quint32 toolId);
}; };
#endif // VTOOLSEAMALLOWANCE_H #endif // VTOOLSEAMALLOWANCE_H