Duplicate from GUI.
--HG-- branch : feature
This commit is contained in:
parent
e8ca7f575d
commit
51e670bd84
|
@ -1127,8 +1127,7 @@ void MainWindow::ClosedDialogDuplicateDetail(int result)
|
|||
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
|
||||
SCASSERT(scene != nullptr)
|
||||
|
||||
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(VToolSeamAllowance::Duplicate(dialogTool, scene, doc,
|
||||
pattern));
|
||||
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(VToolSeamAllowance::Duplicate(dialogTool, scene, doc));
|
||||
// Do not check for nullptr! See issue #719.
|
||||
ui->view->itemClicked(tool);
|
||||
}
|
||||
|
|
|
@ -2420,3 +2420,21 @@ void VAbstractPattern::SetGroupVisivility(quint32 id, bool visible)
|
|||
qDebug("Can't get group by id = %u.", id);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VAbstractPattern::PieceDrawName(quint32 id)
|
||||
{
|
||||
const QDomElement detail = elementById(id, VAbstractPattern::TagDetail);
|
||||
if (detail.isNull())
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
const QDomElement draw = detail.parentNode().parentNode().toElement();
|
||||
if (draw.isNull() || not draw.hasAttribute(VAbstractPattern::AttrName))
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
return draw.attribute(VAbstractPattern::AttrName);
|
||||
}
|
||||
|
|
|
@ -198,6 +198,8 @@ public:
|
|||
bool GetGroupVisivility(quint32 id);
|
||||
void SetGroupVisivility(quint32 id, bool visible);
|
||||
|
||||
QString PieceDrawName(quint32 id);
|
||||
|
||||
static const QString TagPattern;
|
||||
static const QString TagCalculation;
|
||||
static const QString TagModeling;
|
||||
|
|
|
@ -59,7 +59,7 @@ VNodeArc::VNodeArc(const VAbstractNodeInitData &initData, QObject *qoParent)
|
|||
* @brief Create help create tool.
|
||||
* @param initData init data.
|
||||
*/
|
||||
void VNodeArc::Create(VAbstractNodeInitData initData)
|
||||
void VNodeArc::Create(const VAbstractNodeInitData &initData)
|
||||
{
|
||||
if (initData.parse == Document::FullParse)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ class VNodeArc :public VAbstractNode
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void Create(VAbstractNodeInitData initData);
|
||||
static void Create(const VAbstractNodeInitData &initData);
|
||||
|
||||
static const QString ToolType;
|
||||
virtual QString getTagName() const Q_DECL_OVERRIDE;
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
const QString VNodeEllipticalArc::ToolType = QStringLiteral("modeling");
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VNodeEllipticalArc::Create(VAbstractNodeInitData initData)
|
||||
void VNodeEllipticalArc::Create(const VAbstractNodeInitData &initData)
|
||||
{
|
||||
if (initData.parse == Document::FullParse)
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ class VNodeEllipticalArc :public VAbstractNode
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void Create(VAbstractNodeInitData initData);
|
||||
static void Create(const VAbstractNodeInitData &initData);
|
||||
|
||||
static const QString ToolType;
|
||||
virtual QString getTagName() const Q_DECL_OVERRIDE;
|
||||
|
|
|
@ -85,7 +85,7 @@ VNodePoint::VNodePoint(const VAbstractNodeInitData &initData, QObject *qoParent,
|
|||
* @brief Create help create tool.
|
||||
* @param initData init data.
|
||||
*/
|
||||
void VNodePoint::Create(VAbstractNodeInitData initData)
|
||||
void VNodePoint::Create(const VAbstractNodeInitData &initData)
|
||||
{
|
||||
if (initData.parse == Document::FullParse)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ class VNodePoint: public VAbstractNode, public VScenePoint
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void Create(VAbstractNodeInitData initData);
|
||||
static void Create(const VAbstractNodeInitData &initData);
|
||||
|
||||
static const QString ToolType;
|
||||
virtual int type() const Q_DECL_OVERRIDE {return Type;}
|
||||
|
|
|
@ -60,7 +60,7 @@ VNodeSpline::VNodeSpline(const VAbstractNodeInitData &initData, QObject *qoParen
|
|||
* @param initData init data.
|
||||
* @return pointer to node.
|
||||
*/
|
||||
VNodeSpline *VNodeSpline::Create(VAbstractNodeInitData initData)
|
||||
VNodeSpline *VNodeSpline::Create(const VAbstractNodeInitData &initData)
|
||||
{
|
||||
VNodeSpline *spl = nullptr;
|
||||
if (initData.parse == Document::FullParse)
|
||||
|
|
|
@ -47,7 +47,7 @@ class VNodeSpline:public VAbstractNode
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static VNodeSpline *Create(VAbstractNodeInitData initData);
|
||||
static VNodeSpline *Create(const VAbstractNodeInitData &initData);
|
||||
|
||||
static const QString ToolType;
|
||||
virtual QString getTagName() const Q_DECL_OVERRIDE;
|
||||
|
|
|
@ -59,7 +59,7 @@ VNodeSplinePath::VNodeSplinePath(const VAbstractNodeInitData &initData, QObject
|
|||
* @brief Create help create tool.
|
||||
* @param initData init data.
|
||||
*/
|
||||
void VNodeSplinePath::Create(VAbstractNodeInitData initData)
|
||||
void VNodeSplinePath::Create(const VAbstractNodeInitData &initData)
|
||||
{
|
||||
if (initData.parse == Document::FullParse)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ class VNodeSplinePath : public VAbstractNode
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void Create(VAbstractNodeInitData initData);
|
||||
static void Create(const VAbstractNodeInitData &initData);
|
||||
|
||||
static const QString ToolType;
|
||||
virtual QString getTagName() const Q_DECL_OVERRIDE;
|
||||
|
|
|
@ -110,8 +110,6 @@ public:
|
|||
virtual void ShowVisualization(bool show) =0;
|
||||
virtual void ChangeLabelPosition(quint32 id, const QPointF &pos);
|
||||
|
||||
template<typename T>
|
||||
static quint32 CreateNode(VContainer *data, quint32 id);
|
||||
public slots:
|
||||
/**
|
||||
* @brief FullUpdateFromFile update tool data form file.
|
||||
|
@ -162,6 +160,11 @@ protected:
|
|||
virtual void DeleteToolWithConfirm(bool ask = true);
|
||||
static int ConfirmDeletion();
|
||||
|
||||
template<typename T>
|
||||
static quint32 CreateNode(VContainer *data, quint32 id);
|
||||
static quint32 CreateNodeSpline(VContainer *data, quint32 id);
|
||||
static quint32 CreateNodeSplinePath(VContainer *data, quint32 id);
|
||||
|
||||
template <typename T>
|
||||
void AddVisualization();
|
||||
|
||||
|
|
|
@ -34,12 +34,7 @@
|
|||
#include "../vpatterndb/calculator.h"
|
||||
#include "../vpatterndb/floatItemData/vpatternlabeldata.h"
|
||||
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
||||
#include "nodeDetails/vnodearc.h"
|
||||
#include "nodeDetails/vnodeellipticalarc.h"
|
||||
#include "nodeDetails/vnodepoint.h"
|
||||
#include "nodeDetails/vnodespline.h"
|
||||
#include "nodeDetails/vnodesplinepath.h"
|
||||
#include "nodeDetails/vtoolpiecepath.h"
|
||||
#include "nodeDetails/nodedetails.h"
|
||||
#include "../vgeometry/varc.h"
|
||||
#include "../vgeometry/vellipticalarc.h"
|
||||
#include "../vgeometry/vcubicbezier.h"
|
||||
|
@ -47,6 +42,7 @@
|
|||
#include "../vgeometry/vpointf.h"
|
||||
#include "../vgeometry/vspline.h"
|
||||
#include "../vgeometry/vsplinepath.h"
|
||||
#include "../vgeometry/vplacelabelitem.h"
|
||||
#include "../ifc/xml/vpatternconverter.h"
|
||||
#include "../undocommands/addpiece.h"
|
||||
#include "../undocommands/deletepiece.h"
|
||||
|
@ -154,7 +150,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VToolSeamAllowance *VToolSeamAllowance::Duplicate(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
|
||||
VAbstractPattern *doc, VContainer *data)
|
||||
VAbstractPattern *doc)
|
||||
{
|
||||
SCASSERT(not dialog.isNull());
|
||||
QSharedPointer<DialogDuplicateDetail> dialogTool = dialog.objectCast<DialogDuplicateDetail>();
|
||||
|
@ -163,22 +159,37 @@ VToolSeamAllowance *VToolSeamAllowance::Duplicate(QSharedPointer<DialogTool> dia
|
|||
VToolSeamAllowanceInitData initData;
|
||||
initData.scene = scene;
|
||||
initData.doc = doc;
|
||||
initData.data = data;
|
||||
initData.parse = Document::FullParse;
|
||||
initData.typeCreation = Source::FromGui;
|
||||
initData.drawName = doc->PieceDrawName(dialogTool->Duplicate());
|
||||
|
||||
// initData.detail = dialogTool->GetPiece();
|
||||
VContainer toolData = VAbstractPattern::getTool(dialogTool->Duplicate())->getData();
|
||||
initData.data = &toolData;
|
||||
|
||||
VPiece detail = initData.data->GetPiece(dialogTool->Duplicate());
|
||||
detail.SetMx(dialogTool->MoveDuplicateX());
|
||||
detail.SetMy(dialogTool->MoveDuplicateY());
|
||||
initData.detail = detail;
|
||||
initData.width = initData.detail.GetFormulaSAWidth();
|
||||
|
||||
// initData.detail.GetPath().SetNodes(PrepareNodes(initData.detail.GetPath(), scene, doc, data));
|
||||
|
||||
return Duplicate(initData);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VToolSeamAllowance *VToolSeamAllowance::Duplicate(VToolSeamAllowanceInitData &initData)
|
||||
{
|
||||
return nullptr;
|
||||
VPiece dupDetail = initData.detail;
|
||||
|
||||
QMap<quint32, quint32> replacements;
|
||||
dupDetail.GetPath().SetNodes(DuplicateNodes(initData.detail.GetPath(), initData, replacements));
|
||||
dupDetail.SetCustomSARecords(DuplicateCustomSARecords(initData.detail.GetCustomSARecords(), initData,
|
||||
replacements));
|
||||
dupDetail.SetInternalPaths(DuplicateInternalPaths(initData.detail.GetInternalPaths(), initData));
|
||||
dupDetail.SetPins(DuplicatePins(initData.detail.GetPins(), initData));
|
||||
dupDetail.SetPlaceLabels(DuplicatePlaceLabels(initData.detail.GetPlaceLabels(), initData));
|
||||
|
||||
initData.detail = dupDetail;
|
||||
return VToolSeamAllowance::Create(initData);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -1766,3 +1777,179 @@ void VToolSeamAllowance::AddPointRecords(VAbstractPattern *doc, QDomElement &dom
|
|||
domElement.appendChild(pinsElement);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
quint32 VToolSeamAllowance::DuplicateNode(const VPieceNode &node, const VToolSeamAllowanceInitData &initData)
|
||||
{
|
||||
SCASSERT(initData.scene != nullptr)
|
||||
SCASSERT(initData.doc != nullptr)
|
||||
SCASSERT(initData.data != nullptr)
|
||||
|
||||
const QSharedPointer<VGObject> gobj = initData.data->GetGObject(node.GetId());
|
||||
|
||||
VAbstractNodeInitData initNodeData;
|
||||
initNodeData.idObject = gobj->getIdObject();
|
||||
initNodeData.doc = initData.doc;
|
||||
initNodeData.data = initData.data;
|
||||
initNodeData.parse = Document::FullParse;
|
||||
initNodeData.typeCreation = Source::FromGui;
|
||||
initNodeData.scene = initData.scene;
|
||||
initNodeData.drawName = initData.drawName;
|
||||
|
||||
switch (node.GetTypeTool())
|
||||
{
|
||||
case (Tool::NodePoint):
|
||||
initNodeData.id = VAbstractTool::CreateNode<VPointF>(initData.data, gobj->getIdObject());
|
||||
VNodePoint::Create(initNodeData);
|
||||
break;
|
||||
case (Tool::NodeArc):
|
||||
initNodeData.id = VAbstractTool::CreateNode<VArc>(initData.data, gobj->getIdObject());
|
||||
VNodeArc::Create(initNodeData);
|
||||
break;
|
||||
case (Tool::NodeElArc):
|
||||
initNodeData.id = VAbstractTool::CreateNode<VEllipticalArc>(initData.data, gobj->getIdObject());
|
||||
VNodeEllipticalArc::Create(initNodeData);
|
||||
break;
|
||||
case (Tool::NodeSpline):
|
||||
initNodeData.id = VAbstractTool::CreateNodeSpline(initData.data, gobj->getIdObject());
|
||||
VNodeSpline::Create(initNodeData);
|
||||
break;
|
||||
case (Tool::NodeSplinePath):
|
||||
initNodeData.id = VAbstractTool::CreateNodeSplinePath(initData.data, gobj->getIdObject());
|
||||
VNodeSplinePath::Create(initNodeData);
|
||||
break;
|
||||
default:
|
||||
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
||||
break;
|
||||
}
|
||||
return initNodeData.id;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
quint32 VToolSeamAllowance::DuplicatePiecePath(quint32 id, const VToolSeamAllowanceInitData &initData)
|
||||
{
|
||||
VPiecePath path = initData.data->GetPiecePath(id);
|
||||
VPiecePath newPath = path;
|
||||
QMap<quint32, quint32> recordReplacements; // Not used
|
||||
newPath.SetNodes(DuplicateNodes(path, initData, recordReplacements));
|
||||
|
||||
const quint32 idPath = initData.data->AddPiecePath(newPath);
|
||||
|
||||
VToolPiecePathInitData initNodeData;
|
||||
initNodeData.id = idPath;
|
||||
initNodeData.idObject = NULL_ID; // piece id
|
||||
initNodeData.scene = initData.scene;
|
||||
initNodeData.doc = initData.doc;
|
||||
initNodeData.data = initData.data;
|
||||
initNodeData.parse = Document::FullParse;
|
||||
initNodeData.typeCreation = Source::FromTool;
|
||||
initNodeData.drawName = initData.drawName;
|
||||
initNodeData.path = newPath;
|
||||
|
||||
VToolPiecePath::Create(initNodeData);
|
||||
return idPath;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QVector<CustomSARecord> VToolSeamAllowance::DuplicateCustomSARecords(const QVector<CustomSARecord> &records,
|
||||
const VToolSeamAllowanceInitData &initData,
|
||||
const QMap<quint32, quint32> &replacements)
|
||||
{
|
||||
QVector<CustomSARecord> newRecords;
|
||||
for(int i=0; i < records.size(); ++i)
|
||||
{
|
||||
CustomSARecord record = records.at(i);
|
||||
record.path = DuplicatePiecePath(record.path, initData);
|
||||
record.startPoint = replacements.value(record.startPoint, NULL_ID);
|
||||
record.endPoint = replacements.value(record.endPoint, NULL_ID);
|
||||
newRecords.append(record);
|
||||
}
|
||||
return newRecords;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QVector<quint32> VToolSeamAllowance::DuplicateInternalPaths(const QVector<quint32> &iPaths,
|
||||
const VToolSeamAllowanceInitData &initData)
|
||||
{
|
||||
QVector<quint32> newPaths;
|
||||
for(int i=0; i < iPaths.size(); ++i)
|
||||
{
|
||||
newPaths.append(DuplicatePiecePath(iPaths.at(i), initData));
|
||||
}
|
||||
return newPaths;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QVector<quint32> VToolSeamAllowance::DuplicatePins(const QVector<quint32> &pins,
|
||||
const VToolSeamAllowanceInitData &initData)
|
||||
{
|
||||
QVector<quint32> newPins;
|
||||
for(int i=0; i < pins.size(); ++i)
|
||||
{
|
||||
QSharedPointer<VPointF> pin = initData.data->GeometricObject<VPointF>(pins.at(i));
|
||||
|
||||
VToolPinInitData initNodeData;
|
||||
initNodeData.id = initData.data->AddGObject(new VPointF(*pin));
|
||||
initNodeData.pointId = pin->getIdObject();
|
||||
initNodeData.idObject = NULL_ID; // piece id
|
||||
initNodeData.doc = initData.doc;
|
||||
initNodeData.data = initData.data;
|
||||
initNodeData.parse = Document::FullParse;
|
||||
initNodeData.typeCreation = Source::FromTool;
|
||||
initNodeData.drawName = initData.drawName;
|
||||
|
||||
VToolPin::Create(initNodeData);
|
||||
newPins.append(initNodeData.id);
|
||||
}
|
||||
return newPins;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QVector<quint32> VToolSeamAllowance::DuplicatePlaceLabels(const QVector<quint32> &placeLabels,
|
||||
const VToolSeamAllowanceInitData &initData)
|
||||
{
|
||||
QVector<quint32> newPlaceLabels;
|
||||
for(int i=0; i < placeLabels.size(); ++i)
|
||||
{
|
||||
QSharedPointer<VPlaceLabelItem> label = initData.data->GeometricObject<VPlaceLabelItem>(placeLabels.at(i));
|
||||
|
||||
VToolPlaceLabelInitData initNodeData;
|
||||
initNodeData.idObject = NULL_ID; // piece id
|
||||
initNodeData.doc = initData.doc;
|
||||
initNodeData.data = initData.data;
|
||||
initNodeData.parse = Document::FullParse;
|
||||
initNodeData.typeCreation = Source::FromTool;
|
||||
initNodeData.drawName = initData.drawName;
|
||||
initNodeData.width = label->GetWidthFormula();
|
||||
initNodeData.height = label->GetHeightFormula();
|
||||
initNodeData.angle = label->GetAngleFormula();
|
||||
initNodeData.type = label->GetLabelType();
|
||||
initNodeData.centerPoint = label->GetCenterPoint();
|
||||
initNodeData.id = initNodeData.data->AddGObject(new VPlaceLabelItem(*label));
|
||||
|
||||
VToolPlaceLabel::Create(initNodeData);
|
||||
newPlaceLabels.append(initNodeData.id);
|
||||
}
|
||||
return newPlaceLabels;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QVector<VPieceNode> VToolSeamAllowance::DuplicateNodes(const VPiecePath &path,
|
||||
const VToolSeamAllowanceInitData &initData,
|
||||
QMap<quint32, quint32> &replacements)
|
||||
{
|
||||
QVector<VPieceNode> nodes;
|
||||
for (int i = 0; i< path.CountNodes(); ++i)
|
||||
{
|
||||
VPieceNode nodeD = path.at(i);
|
||||
const quint32 oldId = nodeD.GetId();
|
||||
const quint32 id = DuplicateNode(nodeD, initData);
|
||||
if (id > NULL_ID)
|
||||
{
|
||||
nodeD.SetId(id);
|
||||
nodes.append(nodeD);
|
||||
replacements.insert(oldId, id);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
VAbstractPattern *doc, VContainer *data);
|
||||
static VToolSeamAllowance* Create(VToolSeamAllowanceInitData &initData);
|
||||
static VToolSeamAllowance* Duplicate(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
|
||||
VAbstractPattern *doc, VContainer *data);
|
||||
VAbstractPattern *doc);
|
||||
static VToolSeamAllowance* Duplicate(VToolSeamAllowanceInitData &initData);
|
||||
|
||||
static const quint8 pieceVersion;
|
||||
|
@ -200,6 +200,22 @@ private:
|
|||
|
||||
static void AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &records,
|
||||
const QString &tag);
|
||||
|
||||
static QVector<VPieceNode> DuplicateNodes(const VPiecePath &path, const VToolSeamAllowanceInitData &initData,
|
||||
QMap<quint32, quint32> &replacements);
|
||||
static quint32 DuplicateNode(const VPieceNode &node, const VToolSeamAllowanceInitData &initData);
|
||||
|
||||
static quint32 DuplicatePiecePath(quint32 id, const VToolSeamAllowanceInitData &initData);
|
||||
|
||||
static QVector<CustomSARecord> DuplicateCustomSARecords(const QVector<CustomSARecord> &records,
|
||||
const VToolSeamAllowanceInitData &initData,
|
||||
const QMap<quint32, quint32> &replacements);
|
||||
|
||||
static QVector<quint32> DuplicateInternalPaths(const QVector<quint32> &iPaths,
|
||||
const VToolSeamAllowanceInitData &initData);
|
||||
static QVector<quint32> DuplicatePins(const QVector<quint32> &pins, const VToolSeamAllowanceInitData &initData);
|
||||
static QVector<quint32> DuplicatePlaceLabels(const QVector<quint32> &placeLabels,
|
||||
const VToolSeamAllowanceInitData &initData);
|
||||
};
|
||||
|
||||
#endif // VTOOLSEAMALLOWANCE_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user