From 5d5e677e2cbdf60c5b2283d7a0cdbb0a349447c5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 23 Nov 2016 12:54:46 +0200 Subject: [PATCH] Added class VPiecePath. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 3 +- src/libs/vpatterndb/vpatterndb.pri | 7 +- src/libs/vpatterndb/vpiece.cpp | 253 ++------------- src/libs/vpatterndb/vpiece.h | 16 +- src/libs/vpatterndb/vpiece_p.h | 7 +- src/libs/vpatterndb/vpiecepath.cpp | 287 ++++++++++++++++++ src/libs/vpatterndb/vpiecepath.h | 74 +++++ src/libs/vpatterndb/vpiecepath_p.h | 67 ++++ .../dialogs/tools/dialogseamallowance.cpp | 15 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 25 +- src/libs/vtools/undocommands/addpiece.cpp | 3 +- src/libs/vtools/undocommands/deletepiece.cpp | 3 +- .../visualization/path/vistoolpiece.cpp | 4 +- 13 files changed, 491 insertions(+), 273 deletions(-) create mode 100644 src/libs/vpatterndb/vpiecepath.cpp create mode 100644 src/libs/vpatterndb/vpiecepath.h create mode 100644 src/libs/vpatterndb/vpiecepath_p.h diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 4f9fd1722..595fbae13 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -54,6 +54,7 @@ #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vgrainlinegeometry.h" +#include "../vpatterndb/vpiecepath.h" #include #include @@ -778,7 +779,7 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail) c node.SetSABefore(saBefore); node.SetSAAfter(saAfter); node.SetAngleType(angle); - detail.Append(node); + detail.GetPath().Append(node); } } } diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index 49256369c..b0d026efe 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -23,7 +23,8 @@ SOURCES += \ $$PWD/vgrainlinegeometry.cpp \ $$PWD/variables/vcurveclength.cpp \ $$PWD/vpiece.cpp \ - $$PWD/vpiecenode.cpp + $$PWD/vpiecenode.cpp \ + $$PWD/vpiecepath.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -63,4 +64,6 @@ HEADERS += \ $$PWD/vpiece.h \ $$PWD/vpiece_p.h \ $$PWD/vpiecenode.h \ - $$PWD/vpiecenode_p.h + $$PWD/vpiecenode_p.h \ + $$PWD/vpiecepath.h \ + $$PWD/vpiecepath_p.h diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index bbc201647..1d0fafc0d 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -63,114 +63,27 @@ VPiece::~VPiece() {} //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief append append in the end of list node. - * @param node new node. - */ -void VPiece::Append(const VPieceNode &node) +VPiecePath VPiece::GetPath() const { - d->m_nodes.append(node); + return d->m_path; } //--------------------------------------------------------------------------------------------------------------------- -/** @brief Clear detail full clear. */ -void VPiece::Clear() +VPiecePath &VPiece::GetPath() { - ClearNodes(); + return d->m_path; } //--------------------------------------------------------------------------------------------------------------------- -/** @brief ClearNodes clear list of nodes. */ -void VPiece::ClearNodes() +void VPiece::SetPath(const VPiecePath &path) { - d->m_nodes.clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CountNode return count nodes. - * @return count. - */ -qint32 VPiece::CountNodes() const -{ - return d->m_nodes.size(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief operator [] find node by index in list. - * @param indx index node in list. - * @return node - */ -VPieceNode &VPiece::operator [](int indx) -{ - return d->m_nodes[indx]; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief at find node by index in list. - * @param indx index node in list. - * @return const node. - */ -const VPieceNode &VPiece::at(int indx) const -{ - return d->m_nodes.at(indx); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief getNodes return list of nodes. - * @return list of nodes. - */ -QVector VPiece::GetNodes() const -{ - return d->m_nodes; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setNodes set list of nodes - * @param value list of nodes - */ -// cppcheck-suppress unusedFunction -void VPiece::SetNodes(const QVector &nodes) -{ - d->m_nodes = nodes; + d->m_path = path; } //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::MainPathPoints(const VContainer *data) const { - QVector points; - for (int i = 0; i < CountNodes(); ++i) - { - switch (at(i).GetTypeTool()) - { - case (Tool::NodePoint): - { - const QSharedPointer point = data->GeometricObject(at(i).GetId()); - points.append(*point); - } - break; - case (Tool::NodeArc): - case (Tool::NodeSpline): - case (Tool::NodeSplinePath): - { - const QSharedPointer curve = data->GeometricObject(at(i).GetId()); - - const QPointF begin = StartSegment(data, i, at(i).GetReverse()); - const QPointF end = EndSegment(data, i, at(i).GetReverse()); - - points << curve->GetSegmentPoints(begin, end, at(i).GetReverse()); - } - break; - default: - qDebug()<<"Get wrong tool type. Ignore."<< static_cast(at(i).GetTypeTool()); - break; - } - } - + QVector points = GetPath().PathPoints(data); points = CheckLoops(CorrectEquidistantPoints(points));//A path can contains loops return points; } @@ -178,26 +91,7 @@ QVector VPiece::MainPathPoints(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::MainPathNodePoints(const VContainer *data) const { - QVector points; - for (int i = 0; i < CountNodes(); ++i) - { - switch (at(i).GetTypeTool()) - { - case Tool::NodePoint: - { - const QSharedPointer point = data->GeometricObject(at(i).GetId()); - points.append(*point); - } - break; - case Tool::NodeArc: - case Tool::NodeSpline: - case Tool::NodeSplinePath: - default: - break; - } - } - - return points; + return GetPath().PathNodePoints(data); } //--------------------------------------------------------------------------------------------------------------------- @@ -212,9 +106,9 @@ QVector VPiece::SeamAllowancePoints(const VContainer *data) const } QVector pointsEkv; - for (int i = 0; i< CountNodes(); ++i) + for (int i = 0; i< d->m_path.CountNodes(); ++i) { - const VPieceNode &node = at(i); + const VPieceNode &node = d->m_path.at(i); switch (node.GetTypeTool()) { case (Tool::NodePoint): @@ -334,31 +228,32 @@ void VPiece::SetInLayout(bool inLayout) */ QVector VPiece::Missing(const VPiece &det) const { - if (d->m_nodes.size() == det.CountNodes()) //-V807 + const QVector pNodes = d->m_path.GetNodes(); + if (pNodes.size() == det.GetPath().CountNodes()) //-V807 { return QVector(); } QSet set1; - for (qint32 i = 0; i < d->m_nodes.size(); ++i) + for (qint32 i = 0; i < pNodes.size(); ++i) { - set1.insert(d->m_nodes.at(i).GetId()); + set1.insert(pNodes.at(i).GetId()); } QSet set2; - for (qint32 j = 0; j < det.CountNodes(); ++j) + for (qint32 j = 0; j < det.GetPath().CountNodes(); ++j) { - set2.insert(det.at(j).GetId()); + set2.insert(det.GetPath().at(j).GetId()); } const QList set3 = set1.subtract(set2).toList(); QVector nodes; for (qint32 i = 0; i < set3.size(); ++i) { - const int index = indexOfNode(d->m_nodes, set3.at(i)); + const int index = indexOfNode(pNodes, set3.at(i)); if (index != -1) { - nodes.append(d->m_nodes.at(index)); + nodes.append(pNodes.at(index)); } } @@ -373,15 +268,15 @@ QVector VPiece::Missing(const VPiece &det) const */ int VPiece::indexOfNode(const quint32 &id) const { - return indexOfNode(d->m_nodes, id); + return indexOfNode(d->m_path.GetNodes(), id); } //--------------------------------------------------------------------------------------------------------------------- void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VContainer *data, const QSharedPointer &curve, int i, bool reverse) const { - const VSAPoint begin = StartSegment(data, i, reverse); - const VSAPoint end = EndSegment(data, i, reverse); + const VSAPoint begin = d->m_path.StartSegment(data, i, reverse); + const VSAPoint end = d->m_path.EndSegment(data, i, reverse); const QVector points = curve->GetSegmentPoints(begin, end, reverse); if (points.isEmpty()) @@ -461,112 +356,6 @@ void VPiece::CurveSeamAllowanceSegment(QVector &pointsEkv, const VCont } } -//--------------------------------------------------------------------------------------------------------------------- -VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const -{ - if (i < 0 && i > CountNodes()-1) - { - return VSAPoint(); - } - - const QSharedPointer curve = data->GeometricObject(at(i).GetId()); - - QVector points = curve->GetPoints(); - if (reverse) - { - points = VGObject::GetReversePoints(points); - } - - VSAPoint begin = VSAPoint(points.first()); - if (CountNodes() > 1) - { - if (i == 0) - { - if (at(CountNodes()-1).GetTypeTool() == Tool::NodePoint) - { - const VPieceNode &node = at(CountNodes()-1); - const QPointF p = *data->GeometricObject(node.GetId()); - if (curve->IsPointOnCurve(p)) - { - begin = VSAPoint(p); - begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); - begin.SetAngleType(node.GetAngleType()); - } - } - } - else - { - if (at(i-1).GetTypeTool() == Tool::NodePoint) - { - const VPieceNode &node = at(i-1); - const QPointF p = *data->GeometricObject(node.GetId()); - if (curve->IsPointOnCurve(p)) - { - begin = VSAPoint(p); - begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); - begin.SetAngleType(node.GetAngleType()); - } - } - } - } - return begin; -} - -//--------------------------------------------------------------------------------------------------------------------- -VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const -{ - if (i < 0 && i > CountNodes()-1) - { - return VSAPoint(); - } - - const QSharedPointer curve = data->GeometricObject(at(i).GetId()); - - QVector points = curve->GetPoints(); - if (reverse) - { - points = VGObject::GetReversePoints(points); - } - - VSAPoint end = VSAPoint(points.last()); - if (CountNodes() > 2) - { - if (i == CountNodes() - 1) - { - if (at(0).GetTypeTool() == Tool::NodePoint) - { - const VPieceNode &node = at(0); - const QPointF p = *data->GeometricObject(node.GetId()); - if (curve->IsPointOnCurve(p)) - { - end = VSAPoint(p); - end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); - end.SetAngleType(node.GetAngleType()); - } - } - } - else - { - if (at(i+1).GetTypeTool() == Tool::NodePoint) - { - const VPieceNode &node = at(i+1); - const QPointF p = *data->GeometricObject(node.GetId()); - if (curve->IsPointOnCurve(p)) - { - end = VSAPoint(p); - end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); - end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); - end.SetAngleType(node.GetAngleType()); - } - } - } - } - return end; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief indexOfNode return index in list node using id object. diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 0ebf87e4d..243332d8d 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -42,6 +42,7 @@ class VContainer; template class QVector; template class QSharedPointer; class VAbstractCurve; +class VPiecePath; class VPiece : public VAbstractPiece { @@ -51,16 +52,9 @@ public: VPiece &operator=(const VPiece &piece); virtual ~VPiece(); - void Append(const VPieceNode &node); - void Clear(); - void ClearNodes(); - qint32 CountNodes() const; - - VPieceNode & operator[](int indx); - const VPieceNode & at ( int indx ) const; - - QVector GetNodes() const; - void SetNodes(const QVector &nodes); + VPiecePath GetPath() const; + VPiecePath &GetPath(); + void SetPath(const VPiecePath &path); QVector MainPathPoints(const VContainer *data) const; QVector MainPathNodePoints(const VContainer *data) const; @@ -87,8 +81,6 @@ private: void CurveSeamAllowanceSegment(QVector &pointsEkv, const VContainer *data, const QSharedPointer &curve, int i, bool reverse) const; - VSAPoint StartSegment(const VContainer *data, int i, bool reverse) const; - VSAPoint EndSegment(const VContainer *data, int i, bool reverse) const; static int indexOfNode(const QVector &list, quint32 id); }; diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index 6ddf9fd80..ebb7acd6c 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -34,6 +34,7 @@ #include "../vmisc/diagnostic.h" #include "vpiecenode.h" +#include "vpiecepath.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -42,7 +43,7 @@ class VPieceData : public QSharedData { public: VPieceData() - : m_nodes(), + : m_path(), m_mx(0), m_my(0), m_inLayout(true) @@ -50,7 +51,7 @@ public: VPieceData(const VPieceData &detail) : QSharedData(detail), - m_nodes(detail.m_nodes), + m_path(detail.m_path), m_mx(detail.m_mx), m_my(detail.m_my), m_inLayout(detail.m_inLayout) @@ -59,7 +60,7 @@ public: ~VPieceData(); /** @brief nodes list detail nodes. */ - QVector m_nodes; + VPiecePath m_path; qreal m_mx; qreal m_my; diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp new file mode 100644 index 000000000..d9445cff3 --- /dev/null +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -0,0 +1,287 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 22 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vpiecepath.h" +#include "vpiecepath_p.h" +#include "vcontainer.h" +#include "../vgeometry/vpointf.h" +#include "../vlayout/vabstractpiece.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VPiecePath::VPiecePath() + : d(new VPiecePathData) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPiecePath::VPiecePath(const VPiecePath &path) + : d (path.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPiecePath &VPiecePath::operator=(const VPiecePath &path) +{ + if ( &path == this ) + { + return *this; + } + d = path.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPiecePath::~VPiecePath() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiecePath::Append(const VPieceNode &node) +{ + d->m_nodes.append(node); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiecePath::Clear() +{ + d->m_nodes.clear(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qint32 VPiecePath::CountNodes() const +{ + return d->m_nodes.size(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPieceNode &VPiecePath::operator[](int indx) +{ + return d->m_nodes[indx]; +} + +//--------------------------------------------------------------------------------------------------------------------- +const VPieceNode &VPiecePath::at(int indx) const +{ + return d->m_nodes.at(indx); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiecePath::GetNodes() const +{ + return d->m_nodes; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiecePath::SetNodes(const QVector &nodes) +{ + d->m_nodes = nodes; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiecePath::PathPoints(const VContainer *data) const +{ + QVector points; + for (int i = 0; i < CountNodes(); ++i) + { + switch (at(i).GetTypeTool()) + { + case (Tool::NodePoint): + { + const QSharedPointer point = data->GeometricObject(at(i).GetId()); + points.append(*point); + } + break; + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + { + const QSharedPointer curve = data->GeometricObject(at(i).GetId()); + + const QPointF begin = StartSegment(data, i, at(i).GetReverse()); + const QPointF end = EndSegment(data, i, at(i).GetReverse()); + + points << curve->GetSegmentPoints(begin, end, at(i).GetReverse()); + } + break; + default: + qDebug()<<"Get wrong tool type. Ignore."<< static_cast(at(i).GetTypeTool()); + break; + } + } + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiecePath::PathNodePoints(const VContainer *data) const +{ + QVector points; + for (int i = 0; i < CountNodes(); ++i) + { + switch (at(i).GetTypeTool()) + { + case Tool::NodePoint: + { + const QSharedPointer point = data->GeometricObject(at(i).GetId()); + points.append(*point); + } + break; + case Tool::NodeArc: + case Tool::NodeSpline: + case Tool::NodeSplinePath: + default: + break; + } + } + + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VPiecePath::PainterPath(const VContainer *data) const +{ + const QVector points = PathPoints(data); + QPainterPath path; + + if (not points.isEmpty()) + { + path.moveTo(points[0]); + for (qint32 i = 1; i < points.count(); ++i) + { + path.lineTo(points.at(i)); + } + path.setFillRule(Qt::WindingFill); + } + + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +VSAPoint VPiecePath::StartSegment(const VContainer *data, int i, bool reverse) const +{ + if (i < 0 && i > CountNodes()-1) + { + return VSAPoint(); + } + + const QSharedPointer curve = data->GeometricObject(at(i).GetId()); + + QVector points = curve->GetPoints(); + if (reverse) + { + points = VGObject::GetReversePoints(points); + } + + VSAPoint begin = VSAPoint(points.first()); + if (CountNodes() > 1) + { + if (i == 0) + { + if (at(CountNodes()-1).GetTypeTool() == Tool::NodePoint) + { + const VPieceNode &node = at(CountNodes()-1); + const QPointF p = *data->GeometricObject(node.GetId()); + if (curve->IsPointOnCurve(p)) + { + begin = VSAPoint(p); + begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + begin.SetAngleType(node.GetAngleType()); + } + } + } + else + { + if (at(i-1).GetTypeTool() == Tool::NodePoint) + { + const VPieceNode &node = at(i-1); + const QPointF p = *data->GeometricObject(node.GetId()); + if (curve->IsPointOnCurve(p)) + { + begin = VSAPoint(p); + begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + begin.SetAngleType(node.GetAngleType()); + } + } + } + } + return begin; +} + +//--------------------------------------------------------------------------------------------------------------------- +VSAPoint VPiecePath::EndSegment(const VContainer *data, int i, bool reverse) const +{ + if (i < 0 && i > CountNodes()-1) + { + return VSAPoint(); + } + + const QSharedPointer curve = data->GeometricObject(at(i).GetId()); + + QVector points = curve->GetPoints(); + if (reverse) + { + points = VGObject::GetReversePoints(points); + } + + VSAPoint end = VSAPoint(points.last()); + if (CountNodes() > 2) + { + if (i == CountNodes() - 1) + { + if (at(0).GetTypeTool() == Tool::NodePoint) + { + const VPieceNode &node = at(0); + const QPointF p = *data->GeometricObject(node.GetId()); + if (curve->IsPointOnCurve(p)) + { + end = VSAPoint(p); + end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + end.SetAngleType(node.GetAngleType()); + } + } + } + else + { + if (at(i+1).GetTypeTool() == Tool::NodePoint) + { + const VPieceNode &node = at(i+1); + const QPointF p = *data->GeometricObject(node.GetId()); + if (curve->IsPointOnCurve(p)) + { + end = VSAPoint(p); + end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit())); + end.SetSABefore(node.GetSABefore(*data->GetPatternUnit())); + end.SetAngleType(node.GetAngleType()); + } + } + } + } + return end; +} diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h new file mode 100644 index 000000000..b85c34c6d --- /dev/null +++ b/src/libs/vpatterndb/vpiecepath.h @@ -0,0 +1,74 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 22 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPIECEPATH_H +#define VPIECEPATH_H + +#include +#include + +class VPiecePathData; +class VPieceNode; +class QPointF; +class VContainer; +class VSAPoint; +class QPainterPath; + +class VPiecePath +{ +public: + VPiecePath(); + VPiecePath(const VPiecePath &path); + VPiecePath &operator=(const VPiecePath &path); + ~VPiecePath(); + + void Append(const VPieceNode &node); + void Clear(); + qint32 CountNodes() const; + + VPieceNode & operator[](int indx); + const VPieceNode & at ( int indx ) const; + + QVector GetNodes() const; + void SetNodes(const QVector &nodes); + + QVector PathPoints(const VContainer *data) const; + QVector PathNodePoints(const VContainer *data) const; + + QPainterPath PainterPath(const VContainer *data) const; + + VSAPoint StartSegment(const VContainer *data, int i, bool reverse) const; + VSAPoint EndSegment(const VContainer *data, int i, bool reverse) const; + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_TYPEINFO(VPiecePath, Q_MOVABLE_TYPE); + +#endif // VPIECEPATH_H diff --git a/src/libs/vpatterndb/vpiecepath_p.h b/src/libs/vpatterndb/vpiecepath_p.h new file mode 100644 index 000000000..de8efc3b7 --- /dev/null +++ b/src/libs/vpatterndb/vpiecepath_p.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 22 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPIECEPATH_P_H +#define VPIECEPATH_P_H + +#include +#include + +#include "../vmisc/diagnostic.h" +#include "vpiecenode.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VPiecePathData : public QSharedData +{ +public: + VPiecePathData() + : m_nodes() + {} + + VPiecePathData(const VPiecePathData &path) + : QSharedData(path), + m_nodes(path.m_nodes) + {} + + ~VPiecePathData(); + + QVector m_nodes; + +private: + VPiecePathData &operator=(const VPiecePathData &) Q_DECL_EQ_DELETE; +}; + +VPiecePathData::~VPiecePathData() +{} + +QT_WARNING_POP + +#endif // VPIECEPATH_P_H + diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 870061ff1..653e21f4a 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -29,6 +29,7 @@ #include "dialogseamallowance.h" #include "ui_dialogseamallowance.h" #include "../vpatterndb/vpiecenode.h" +#include "../vpatterndb/vpiecepath.h" #include "visualization/path/vistoolpiece.h" #include @@ -123,9 +124,9 @@ VPiece DialogSeamAllowance::GetPiece() const void DialogSeamAllowance::SetPiece(const VPiece &piece) { ui->listWidget->clear(); - for (int i = 0; i < piece.CountNodes(); ++i) + for (int i = 0; i < piece.GetPath().CountNodes(); ++i) { - NewItem(piece.at(i)); + NewItem(piece.GetPath().at(i)); } ui->checkBoxForbidFlipping->setChecked(piece.IsForbidFlipping()); @@ -186,7 +187,7 @@ void DialogSeamAllowance::ChosenObject(quint32 id, const SceneObject &type) const VPiece p = CreatePiece(); visPath->SetPiece(p); - if (p.CountNodes() == 1) + if (p.GetPath().CountNodes() == 1) { emit ToolTip(tr("Select main path objects clockwise, Shift - reverse direction curve, " "Enter - finish creation")); @@ -329,7 +330,7 @@ void DialogSeamAllowance::NodeChanged(int index) const int nodeIndex = piece.indexOfNode(id); if (nodeIndex != -1) { - const VPieceNode &node = piece.at(nodeIndex); + const VPieceNode &node = piece.GetPath().at(nodeIndex); ui->doubleSpinBoxSABefore->setEnabled(true); ui->doubleSpinBoxSAAfter->setEnabled(true); @@ -437,7 +438,7 @@ VPiece DialogSeamAllowance::CreatePiece() const for (qint32 i = 0; i < ui->listWidget->count(); ++i) { QListWidgetItem *item = ui->listWidget->item(i); - piece.Append(qvariant_cast(item->data(Qt::UserRole))); + piece.GetPath().Append(qvariant_cast(item->data(Qt::UserRole))); } piece.SetForbidFlipping(ui->checkBoxForbidFlipping->isChecked()); @@ -530,9 +531,9 @@ void DialogSeamAllowance::InitNodesList() const VPiece piece = CreatePiece(); - for (int i = 0; i < piece.CountNodes(); ++i) + for (int i = 0; i < piece.GetPath().CountNodes(); ++i) { - const VPieceNode node = piece.at(i); + const VPieceNode node = piece.GetPath().at(i); if (node.GetTypeTool() == Tool::NodePoint) { const QString name = GetNodeName(node); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 1bf5663b4..cfdc2892d 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -29,6 +29,7 @@ #include "vtoolseamallowance.h" #include "../dialogs/tools/dialogseamallowance.h" #include "../vpatterndb/vpiecenode.h" +#include "../vpatterndb/vpiecepath.h" #include "nodeDetails/vnodearc.h" #include "nodeDetails/vnodepoint.h" #include "nodeDetails/vnodespline.h" @@ -88,10 +89,10 @@ VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphics VPiece detail = dialogTool->GetPiece(); QVector nodes; qApp->getUndoStack()->beginMacro("add detail"); - for (int i = 0; i< detail.CountNodes(); ++i) + for (int i = 0; i< detail.GetPath().CountNodes(); ++i) { quint32 id = 0; - VPieceNode nodeD = detail.at(i); + VPieceNode nodeD = detail.GetPath().at(i); switch (nodeD.GetTypeTool()) { case (Tool::NodePoint): @@ -142,7 +143,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(DialogTool *dialog, VMainGraphics nodes.append(nodeD); } - detail.SetNodes(nodes); + detail.GetPath().SetNodes(nodes); VToolSeamAllowance *piece = Create(0, detail, scene, doc, data, Document::FullParse, Source::FromGui); if (piece != nullptr) @@ -252,12 +253,12 @@ void VToolSeamAllowance::AddNode(VAbstractPattern *doc, QDomElement &domElement, //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece) { - if (piece.CountNodes() > 0) + if (piece.GetPath().CountNodes() > 0) { QDomElement nodesElement = doc->createElement(TagNodes); - for (int i = 0; i < piece.CountNodes(); ++i) + for (int i = 0; i < piece.GetPath().CountNodes(); ++i) { - AddNode(doc, nodesElement, piece.at(i)); + AddNode(doc, nodesElement, piece.GetPath().at(i)); } domElement.appendChild(nodesElement); } @@ -635,24 +636,24 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, m_seamAllowance(new VNoBrushScalePathItem(this)) { VPiece detail = data->GetPiece(id); - for (int i = 0; i< detail.CountNodes(); ++i) + for (int i = 0; i< detail.GetPath().CountNodes(); ++i) { - switch (detail.at(i).GetTypeTool()) + switch (detail.GetPath().at(i).GetTypeTool()) { case (Tool::NodePoint): { - VNodePoint *tool = InitTool(scene, detail.at(i)); + VNodePoint *tool = InitTool(scene, detail.GetPath().at(i)); connect(tool, &VNodePoint::ShowContextMenu, this, &VToolSeamAllowance::contextMenuEvent); break; } case (Tool::NodeArc): - doc->IncrementReferens(detail.at(i).GetId()); + doc->IncrementReferens(detail.GetPath().at(i).GetId()); break; case (Tool::NodeSpline): - doc->IncrementReferens(detail.at(i).GetId()); + doc->IncrementReferens(detail.GetPath().at(i).GetId()); break; case (Tool::NodeSplinePath): - doc->IncrementReferens(detail.at(i).GetId()); + doc->IncrementReferens(detail.GetPath().at(i).GetId()); break; default: qDebug()<<"Get wrong tool type. Ignore."; diff --git a/src/libs/vtools/undocommands/addpiece.cpp b/src/libs/vtools/undocommands/addpiece.cpp index e9d96e56c..185ac804f 100644 --- a/src/libs/vtools/undocommands/addpiece.cpp +++ b/src/libs/vtools/undocommands/addpiece.cpp @@ -28,6 +28,7 @@ #include "addpiece.h" #include "../vpatterndb/vpiecenode.h" +#include "../vpatterndb/vpiecepath.h" //--------------------------------------------------------------------------------------------------------------------- AddPiece::AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &detail, const QString &drawName, @@ -61,7 +62,7 @@ void AddPiece::undo() return; } - DecrementReferences(m_detail.GetNodes()); + DecrementReferences(m_detail.GetPath().GetNodes()); } else { diff --git a/src/libs/vtools/undocommands/deletepiece.cpp b/src/libs/vtools/undocommands/deletepiece.cpp index 44d79a54e..1aea7088c 100644 --- a/src/libs/vtools/undocommands/deletepiece.cpp +++ b/src/libs/vtools/undocommands/deletepiece.cpp @@ -39,6 +39,7 @@ #include "../tools/vdatatool.h" #include "vundocommand.h" #include "../vpatterndb/vpiecenode.h" +#include "../vpatterndb/vpiecepath.h" class QUndoCommand; @@ -105,7 +106,7 @@ void DeletePiece::redo() SCASSERT(toolDet != nullptr); toolDet->hide(); - DecrementReferences(m_detail.GetNodes()); + DecrementReferences(m_detail.GetPath().GetNodes()); emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail. } else diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp index 695c9cb9a..f2457842b 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vistoolpiece.h" +#include "../vpatterndb/vpiecepath.h" //--------------------------------------------------------------------------------------------------------------------- VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) @@ -49,7 +50,7 @@ void VisToolPiece::RefreshGeometry() { HideAllItems(); - if (m_piece.CountNodes() > 0) + if (m_piece.GetPath().CountNodes() > 0) { DrawPath(this, m_piece.MainPathPath(Visualization::data), mainColor, Qt::SolidLine, Qt::RoundCap); @@ -99,7 +100,6 @@ void VisToolPiece::HideAllItems() m_line2->setVisible(false); } - QVector m_points; for (int i=0; i < m_points.size(); ++i) { if (QGraphicsEllipseItem *item = m_points.at(i))