diff --git a/src/libs/vlayout/vlayout.pri b/src/libs/vlayout/vlayout.pri index 11a46ad9c..7d12980f9 100644 --- a/src/libs/vlayout/vlayout.pri +++ b/src/libs/vlayout/vlayout.pri @@ -18,7 +18,9 @@ HEADERS += \ $$PWD/vabstractpiece.h \ $$PWD/vabstractpiece_p.h \ $$PWD/vlayoutpiece.h \ - $$PWD/vlayoutpiece_p.h + $$PWD/vlayoutpiece_p.h \ + $$PWD/vlayoutpiecepath.h \ + $$PWD/vlayoutpiecepath_p.h SOURCES += \ $$PWD/vlayoutgenerator.cpp \ @@ -31,6 +33,7 @@ SOURCES += \ $$PWD/vposter.cpp \ $$PWD/vgraphicsfillitem.cpp \ $$PWD/vabstractpiece.cpp \ - $$PWD/vlayoutpiece.cpp + $$PWD/vlayoutpiece.cpp \ + $$PWD/vlayoutpiecepath.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index e8585188e..c3d65acd8 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -57,6 +57,24 @@ class QGraphicsPathItem; class QLineF; class VAbstractPattern; +namespace +{ +QVector ConvertInternalPaths(const VPiece &piece, const VContainer *pattern) +{ + QVector paths; + const QVector pathsId = piece.GetInternalPaths(); + for (int i = 0; i < pathsId.size(); ++i) + { + const VPiecePath path = pattern->GetPiecePath(pathsId.at(i)); + if (path.GetType() == PiecePathType::InternalPath) + { + paths.append(VLayoutPiecePath(path.PathPoints(pattern), path.GetPenType())); + } + } + return paths; +} +} + //--------------------------------------------------------------------------------------------------------------------- VLayoutPiece::VLayoutPiece() :VAbstractPiece(), d(new VLayoutPieceData) @@ -89,7 +107,8 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern VLayoutPiece det; det.SetCountourPoints(piece.MainPathPoints(pattern)); det.SetSeamAllowancePoints(piece.SeamAllowancePoints(pattern), piece.IsSeamAllowance()); - det.SetInternlaPathsPoints(piece.GetInternalPathsPoints(pattern)); + det.SetInternalPaths(ConvertInternalPaths(piece, pattern)); + det.SetName(piece.GetName()); const VPatternPieceData& data = piece.GetPatternPieceData(); if (data.IsVisible() == true) @@ -500,15 +519,15 @@ void VLayoutPiece::SetLayoutAllowancePoints() } //--------------------------------------------------------------------------------------------------------------------- -QVector> VLayoutPiece::GetInternlaPathsPoints() const +QVector VLayoutPiece::GetInternalPaths() const { return d->m_internalPaths; } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutPiece::SetInternlaPathsPoints(const QVector> &internalPathsPoints) +void VLayoutPiece::SetInternalPaths(const QVector &internalPaths) { - d->m_internalPaths = internalPathsPoints; + d->m_internalPaths = internalPaths; } //--------------------------------------------------------------------------------------------------------------------- @@ -708,6 +727,18 @@ void VLayoutPiece::CreateTextItems() } } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::CreateInternalPathItem(int i, QGraphicsItem *parent) const +{ + SCASSERT(parent != nullptr) + QGraphicsPathItem* item = new QGraphicsPathItem(parent); + item->setPath(d->matrix.map(d->m_internalPaths.at(i).GetPainterPath())); + + QPen pen = item->pen(); + pen.setStyle(d->m_internalPaths.at(i).PenStyle()); + item->setPen(pen); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CreateTextItem Creates the i-th text item @@ -719,9 +750,7 @@ void VLayoutPiece::CreateTextItem(int i, QGraphicsItem *parent) const SCASSERT(parent != nullptr) QGraphicsPathItem* item = new QGraphicsPathItem(parent); - QTransform transform = d->matrix; - - QPainterPath path = transform.map(d->m_liPP[i]); + QPainterPath path = d->matrix.map(d->m_liPP.at(i)); if (d->mirror == true) { @@ -735,7 +764,8 @@ void VLayoutPiece::CreateTextItem(int i, QGraphicsItem *parent) const points = Map(Mirror(d->patternInfo)); } QPointF ptCenter = (points.at(1) + points.at(3))/2; - qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x())); + qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(), + points.at(1).x() - points.at(0).x())); // we need to move the center back to the origin, rotate it to align it with x axis, // then mirror it to obtain the proper text direction, rotate it and translate it back to original position. @@ -779,9 +809,12 @@ QPainterPath VLayoutPiece::LayoutAllowancePath() const QGraphicsItem *VLayoutPiece::GetItem() const { QGraphicsPathItem *item = new QGraphicsPathItem(); - QPainterPath contour = ContourPath(); - contour.addPath(InternalPathsPath()); - item->setPath(contour); + item->setPath(ContourPath()); + + for (int i = 0; i < d->m_internalPaths.count(); ++i) + { + CreateInternalPathItem(i, item); + } for (int i = 0; i < d->m_liPP.count(); ++i) { @@ -813,29 +846,6 @@ void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const item->setPath(path); } -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VLayoutPiece::InternalPathsPath() const -{ - QPainterPath allPaths; - allPaths.setFillRule(Qt::WindingFill); - - for (qint32 i = 0; i < d->m_internalPaths.count(); ++i) - { - const QVector points = Map(d->m_internalPaths.at(i)); - QPainterPath path; - path.setFillRule(Qt::WindingFill); - path.moveTo(points.at(0)); - for (qint32 j = 1; j < points.count(); ++j) - { - path.lineTo(points.at(j)); - } - path.lineTo(points.at(0)); - allPaths.addPath(path); - } - - return allPaths; -} - //--------------------------------------------------------------------------------------------------------------------- QVector VLayoutPiece::DetailPath() const { diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 5bd966a0a..aa05c637c 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -59,6 +59,7 @@ class VLayoutPieceData; class VPatternInfoGeometry; class VPatternPieceData; class VGrainlineGeometry; +class VLayoutPiecePath; class VLayoutPiece :public VAbstractPiece { @@ -79,8 +80,8 @@ public: QVector GetLayoutAllowancePoints() const; void SetLayoutAllowancePoints(); - QVector> GetInternlaPathsPoints() const; - void SetInternlaPathsPoints(const QVector> &internalPathsPoints); + QVector GetInternalPaths() const; + void SetInternalPaths(const QVector &internalPaths); void SetDetail(const QString &qsName, const VPatternPieceData& data, const QFont& font); @@ -130,11 +131,10 @@ private: void ClearTextItems(); void CreateTextItems(); + void CreateInternalPathItem(int i, QGraphicsItem *parent) const; void CreateTextItem(int i, QGraphicsItem *parent) const; void CreateGrainlineItem(QGraphicsItem *parent) const; - QPainterPath InternalPathsPath() const; - static QVector PrepareAllowance(const QVector &points); QVector Map(const QVector &points) const; static QVector RoundPoints(const QVector &points); diff --git a/src/libs/vlayout/vlayoutpiece_p.h b/src/libs/vlayout/vlayoutpiece_p.h index aab150348..bd3f504be 100644 --- a/src/libs/vlayout/vlayoutpiece_p.h +++ b/src/libs/vlayout/vlayoutpiece_p.h @@ -37,6 +37,8 @@ #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vgrainlinegeometry.h" +#include "../vmisc/diagnostic.h" +#include "vlayoutpiecepath.h" #include "vtextmanager.h" @@ -96,8 +98,8 @@ public: /** @brief layoutAllowance list of layout allowance points. */ QVector layoutAllowance; - /** @brief m_internalPaths list of internal paths points. */ - QVector> m_internalPaths; + /** @brief m_internalPaths list of internal paths. */ + QVector m_internalPaths; /** @brief matrix transformation matrix*/ QTransform matrix; diff --git a/src/libs/vlayout/vlayoutpiecepath.cpp b/src/libs/vlayout/vlayoutpiecepath.cpp new file mode 100644 index 000000000..a6883e7c5 --- /dev/null +++ b/src/libs/vlayout/vlayoutpiecepath.cpp @@ -0,0 +1,107 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 8 2, 2017 + ** + ** @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) 2017 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 "vlayoutpiecepath.h" +#include "vlayoutpiecepath_p.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VLayoutPiecePath::VLayoutPiecePath() + : d(new VLayoutPiecePathData) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VLayoutPiecePath::VLayoutPiecePath(const QVector &points, Qt::PenStyle penStyle) + : d(new VLayoutPiecePathData(points, penStyle)) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VLayoutPiecePath::VLayoutPiecePath(const VLayoutPiecePath &path) + : d(path.d) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VLayoutPiecePath &VLayoutPiecePath::operator=(const VLayoutPiecePath &path) +{ + if ( &path == this ) + { + return *this; + } + d = path.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VLayoutPiecePath::~VLayoutPiecePath() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VLayoutPiecePath::GetPainterPath() const +{ + QPainterPath path; + path.setFillRule(Qt::WindingFill); + if (not d->m_points.isEmpty()) + { + path.moveTo(d->m_points.at(0)); + for (qint32 j = 1; j < d->m_points.count(); ++j) + { + path.lineTo(d->m_points.at(j)); + } + path.lineTo(d->m_points.at(0)); + } + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VLayoutPiecePath::Points() const +{ + return d->m_points; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiecePath::SetPoints(const QVector &points) +{ + d->m_points = points; +} + +//--------------------------------------------------------------------------------------------------------------------- +Qt::PenStyle VLayoutPiecePath::PenStyle() const +{ + return d->m_penStyle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiecePath::SetPenStyle(const Qt::PenStyle &penStyle) +{ + d->m_penStyle = penStyle; +} diff --git a/src/libs/vlayout/vlayoutpiecepath.h b/src/libs/vlayout/vlayoutpiecepath.h new file mode 100644 index 000000000..b2d9da454 --- /dev/null +++ b/src/libs/vlayout/vlayoutpiecepath.h @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 8 2, 2017 + ** + ** @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) 2017 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 VLAYOUTPIECEPATH_H +#define VLAYOUTPIECEPATH_H + +#include +#include + +class VLayoutPiecePathData; +class QPainterPath; + +class VLayoutPiecePath +{ +public: + VLayoutPiecePath(); + VLayoutPiecePath(const QVector &points, Qt::PenStyle penStyle = Qt::SolidLine); + VLayoutPiecePath(const VLayoutPiecePath &path); + VLayoutPiecePath &operator=(const VLayoutPiecePath &path); + virtual ~VLayoutPiecePath(); + + QPainterPath GetPainterPath() const; + + QVector Points() const; + void SetPoints(const QVector &points); + + Qt::PenStyle PenStyle() const; + void SetPenStyle(const Qt::PenStyle &PenStyle); + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_TYPEINFO(VLayoutPiecePath, Q_MOVABLE_TYPE); + +#endif // VLAYOUTPIECEPATH_H diff --git a/src/libs/vlayout/vlayoutpiecepath_p.h b/src/libs/vlayout/vlayoutpiecepath_p.h new file mode 100644 index 000000000..17c4fe8bc --- /dev/null +++ b/src/libs/vlayout/vlayoutpiecepath_p.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 8 2, 2017 + ** + ** @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) 2017 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 VLAYOUTPIECEPATH_P_H +#define VLAYOUTPIECEPATH_P_H + +#include +#include +#include + +#include "../vmisc/diagnostic.h" + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +class VLayoutPiecePathData : public QSharedData +{ +public: + VLayoutPiecePathData() + : m_points(), + m_penStyle(Qt::SolidLine) + {} + + VLayoutPiecePathData(const QVector points, Qt::PenStyle penStyle) + : m_points(points), + m_penStyle(penStyle) + {} + + VLayoutPiecePathData(const VLayoutPiecePathData &path) + : QSharedData(path), + m_points(path.m_points), + m_penStyle(path.m_penStyle) + {} + + ~VLayoutPiecePathData(); + + /** @brief m_points list of path points. */ + QVector m_points; + + /** @brief m_penStyle path pen style. */ + Qt::PenStyle m_penStyle; + +private: + VLayoutPiecePathData &operator=(const VLayoutPiecePathData &) Q_DECL_EQ_DELETE; +}; + +VLayoutPiecePathData::~VLayoutPiecePathData() +{} + +QT_WARNING_POP + +#endif // VLAYOUTPIECEPATH_P_H + diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 704921167..85200418d 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -177,21 +177,6 @@ QVector VPiece::SeamAllowancePoints(const VContainer *data) const return Equidistant(pointsEkv, width); } -//--------------------------------------------------------------------------------------------------------------------- -QVector> VPiece::GetInternalPathsPoints(const VContainer *data) const -{ - QVector> pathsPoints; - for (int i = 0; i < d->m_internalPaths.size(); ++i) - { - const VPiecePath path = data->GetPiecePath(d->m_internalPaths.at(i)); - if (path.GetType() == PiecePathType::InternalPath) - { - pathsPoints.append(path.PathPoints(data)); - } - } - return pathsPoints; -} - //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiece::MainPathPath(const VContainer *data) const { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 111d368c7..0ea0180e4 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -64,8 +64,6 @@ public: QVector MainPathNodePoints(const VContainer *data) const; QVector SeamAllowancePoints(const VContainer *data) const; - QVector> GetInternalPathsPoints(const VContainer *data) const; - QPainterPath MainPathPath(const VContainer *data) const; QPainterPath SeamAllowancePath(const VContainer *data) const;