Create modeling items before insert new node.
--HG-- branch : feature
This commit is contained in:
parent
7fe86bc319
commit
20ccbaae01
|
@ -1171,7 +1171,7 @@ void MainWindow::ClosedDialogInsertNode(int result)
|
|||
{
|
||||
DialogInsertNode *dTool = qobject_cast<DialogInsertNode*>(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);
|
||||
|
|
|
@ -679,36 +679,51 @@ QVector<VPieceNode> VAbstractTool::PrepareNodes(const VPiecePath &path, VMainGra
|
|||
QVector<VPieceNode> 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<VPointF>(data, nodeD.GetId());
|
||||
VNodePoint::Create(doc, data, scene, id, nodeD.GetId(), Document::FullParse, Source::FromGui);
|
||||
break;
|
||||
case (Tool::NodeArc):
|
||||
id = CreateNode<VArc>(data, nodeD.GetId());
|
||||
VNodeArc::Create(doc, data, id, nodeD.GetId(), Document::FullParse, Source::FromGui);
|
||||
break;
|
||||
case (Tool::NodeElArc):
|
||||
id = CreateNode<VEllipticalArc>(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."<<Q_FUNC_INFO;
|
||||
break;
|
||||
nodeD.SetId(id);
|
||||
nodes.append(nodeD);
|
||||
}
|
||||
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):
|
||||
id = CreateNode<VPointF>(data, node.GetId());
|
||||
VNodePoint::Create(doc, data, scene, id, node.GetId(), Document::FullParse, Source::FromGui);
|
||||
break;
|
||||
case (Tool::NodeArc):
|
||||
id = CreateNode<VArc>(data, node.GetId());
|
||||
VNodeArc::Create(doc, data, id, node.GetId(), Document::FullParse, Source::FromGui);
|
||||
break;
|
||||
case (Tool::NodeElArc):
|
||||
id = CreateNode<VEllipticalArc>(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."<<Q_FUNC_INFO;
|
||||
break;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "vdatatool.h"
|
||||
|
||||
class VGraphicsSimpleTextItem;
|
||||
class VAbstractNode;
|
||||
|
||||
/**
|
||||
* @brief The VAbstractTool abstract class for all tools.
|
||||
|
@ -150,6 +151,8 @@ protected:
|
|||
|
||||
static QVector<VPieceNode> 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)
|
||||
};
|
||||
|
|
|
@ -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<VToolSeamAllowance*>(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<VNodePoint>(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<VNodePoint*>(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 <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;
|
||||
}
|
||||
|
|
|
@ -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 <typename Tool>
|
||||
Tool* InitTool(VMainGraphicsScene *scene, quint32 toolId);
|
||||
};
|
||||
|
||||
#endif // VTOOLSEAMALLOWANCE_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user