Tool Union Details now works.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-18 10:17:18 +02:00
parent 8b839c7002
commit d2ff75dedc
10 changed files with 247 additions and 203 deletions

View File

@ -281,6 +281,12 @@ void VPiece::SetInternalPaths(const QVector<quint32> &iPaths)
d->m_internalPaths = iPaths;
}
//---------------------------------------------------------------------------------------------------------------------
void VPiece::AppendInternalPath(quint32 path)
{
d->m_internalPaths.append(path);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<CustomSARecord> VPiece::GetCustomSARecords() const
{
@ -293,6 +299,12 @@ void VPiece::SetCustomSARecords(const QVector<CustomSARecord> &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

View File

@ -81,9 +81,11 @@ public:
QVector<quint32> GetInternalPaths() const;
void SetInternalPaths(const QVector<quint32> &iPaths);
void AppendInternalPath(quint32 path);
QVector<CustomSARecord> GetCustomSARecords() const;
void SetCustomSARecords(const QVector<CustomSARecord> &records);
void AppendCustomSARecord(const CustomSARecord &record);
QVector<quint32> MissingNodes(const VPiece &det) const;
QVector<quint32> MissingCSAPath(const VPiece &det) const;

View File

@ -40,8 +40,10 @@ VToolPiecePath *VToolPiecePath::Create(DialogTool *dialog, VMainGraphicsScene *s
SCASSERT(dialog != nullptr);
DialogPiecePath *dialogTool = qobject_cast<DialogPiecePath*>(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<VGObject> 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<VGObject> node = VAbstractTool::data.GetGObject(path.at(i).GetId());
doc->DecrementReferens(node->getIdTool());
doc->DecrementReferens(VAbstractTool::data.GetGObject(path.at(i).GetId())->getIdTool());
}
}

View File

@ -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)

View File

@ -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 T> class QSharedPointer;
const QString VAbstractTool::AttrInUse = QStringLiteral("inUse");
namespace
{
//---------------------------------------------------------------------------------------------------------------------
template<typename T>
/**
* @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<T>(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<VSpline>(data, id);
}
else
{
return CreateNode<VCubicBezier>(data, id);
}
}
//---------------------------------------------------------------------------------------------------------------------
quint32 CreateNodeSplinePath(VContainer *data, quint32 id)
{
if (data->GetGObject(id)->getType() == GOType::SplinePath)
{
return CreateNode<VSplinePath>(data, id);
}
else
{
return CreateNode<VCubicBezierPath>(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<VPieceNode> VAbstractTool::PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data)
{
QVector<VPieceNode> 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<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);
}
return nodes;
}

View File

@ -147,13 +147,16 @@ protected:
void AddVisualization();
virtual void SetVisualization()=0;
void ToolCreation(const Source &typeCreation);
virtual void ToolCreation(const Source &typeCreation);
static void RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint,
QGraphicsLineItem *lineName, const qreal radius);
static QDomElement AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node);
static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node);
static QVector<VPieceNode> PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
private:
Q_DISABLE_COPY(VAbstractTool)
};

View File

@ -90,69 +90,8 @@ VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphics
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(dialog);
SCASSERT(dialogTool != nullptr);
VPiece detail = dialogTool->GetPiece();
QVector<VPieceNode> 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<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):
{
const auto obj = data->GetGObject(nodeD.GetId());
if (obj->getType() == GOType::Spline)
{
id = CreateNode<VSpline>(data, nodeD.GetId());
}
else
{
id = CreateNode<VCubicBezier>(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<VSplinePath>(data, nodeD.GetId());
}
else
{
id = CreateNode<VCubicBezierPath>(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);
}
detail.GetPath().SetNodes(nodes);
detail.GetPath().SetNodes(PrepareNodes(detail.GetPath(), scene, doc, data));
VToolSeamAllowance *piece = Create(0, detail, scene, doc, data, Document::FullParse, Source::FromGui);
@ -1068,19 +1007,8 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data,
this->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<typename T>
/**
* @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<T>(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();
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<typename T>
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);

View File

@ -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<CustomSARecord> GetPieceCSAList(int piece, VAbstractPattern *doc, quint32 id)
QVector<CustomSARecord> GetPiece2CSAPaths(VAbstractPattern *doc, quint32 id)
{
const QDomElement tool = doc->elementById(id);
if (tool.isNull())
@ -154,13 +154,13 @@ QVector<CustomSARecord> 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<CustomSARecord> GetPieceCSAList(int piece, VAbstractPattern *doc, quint3
}
//---------------------------------------------------------------------------------------------------------------------
QVector<CustomSARecord> GetPiece1CSAPaths(VAbstractPattern *doc, quint32 id)
{
return GetPieceCSAList(1, doc, id);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<CustomSARecord> GetPiece2CSAPaths(VAbstractPattern *doc, quint32 id)
{
return GetPieceCSAList(2, doc, id);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> GetPieceInternalPathList(int piece, VAbstractPattern *doc, quint32 id)
QVector<quint32> GetPiece2InternalPaths(VAbstractPattern *doc, quint32 id)
{
const QDomElement tool = doc->elementById(id);
if (tool.isNull())
@ -197,13 +185,13 @@ QVector<quint32> 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<quint32> GetPieceInternalPathList(int piece, VAbstractPattern *doc, quin
return QVector<quint32>();
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> GetPiece1InternalPaths(VAbstractPattern *doc, quint32 id)
{
return GetPieceInternalPathList(1, doc, id);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> 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<VPointF>(det2p1.GetId()));
p2 = VPointF(*data->GeometricObject<VPointF>(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<quint32>
{
QVector<CustomSARecord> newList = newDetail.GetCustomSARecords();
const QVector<CustomSARecord> oldList = d.GetCustomSARecords();
QVector<quint32> 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<quint32>
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<quint32>
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<CustomSARecord> d1Records = d1.GetCustomSARecords();
for (int i = 0; i < d1Records.size(); ++i)
{
newDetail.AppendCustomSARecord(d1Records.at(i));
}
QVector<quint32> 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<quint32> newList = newDetail.GetInternalPaths();
const QVector<quint32> oldList = d.GetInternalPaths();
QVector<quint32> 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<quint32> d1Internal = d1.GetInternalPaths();
for (int i = 0; i < d1Internal.size(); ++i)
{
newDetail.AppendInternalPath(d1Internal.at(i));
}
QVector<quint32> 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<CustomSARecord> &records)
void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate,
qreal angle, const QVector<quint32> &records, QVector<quint32> children)
{
QVector<quint32> 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<quint32> 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<CustomSARecord> &records)
{
UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece1CSAPaths(initData.doc, id));
UpdateUnitedDetailCSA(id, initData, dx, dy, pRotate, angle, GetPiece2CSAPaths(initData.doc, id));
QVector<quint32> 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<quint32> &records)
{
QVector<quint32> 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<quint32> 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<quint32> VToolUnionDetails::GetReferenceObjects() const
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> VToolUnionDetails::NodesReferenceObjects(const QDomElement &nodes) const
QVector<quint32> VToolUnionDetails::ReferenceObjects(const QDomElement &root, const QString &tag,
const QString &attribute) const
{
QVector<quint32> list;
QVector<quint32> 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;
}

View File

@ -143,7 +143,7 @@ private:
void AddDetail(QDomElement &domElement, const VPiece &d) const;
void AddToModeling(const QDomElement &domElement);
QVector<quint32> GetReferenceObjects() const;
QVector<quint32> NodesReferenceObjects(const QDomElement &nodes) const;
QVector<quint32> ReferenceObjects(const QDomElement &root, const QString &tag, const QString &attribute) const;
};
#endif // VTOOLUNIONDETAILS_H