diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 3a8dd9c27..c6354948e 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -463,10 +463,21 @@ QVector VPiece::PlaceLabelPoints(const VContainer *data) const return points; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::CurvesPainterPath(const VContainer *data) const +{ + return GetPath().CurvesPainterPath(data); +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiece::MainPathPath(const VContainer *data) const { - const QVector points = MainPathPoints(data); + return MainPathPath(MainPathPoints(data)); +} + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VPiece::MainPathPath(const QVector &points) const +{ QPainterPath path; if (not points.isEmpty()) diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index dbaa7c01b..b372c7056 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -74,7 +74,10 @@ public: const QVector &seamAllowance = QVector()) const; QVector PlaceLabelPoints(const VContainer *data) const; + QVector CurvesPainterPath(const VContainer *data) const; + QPainterPath MainPathPath(const VContainer *data) const; + QPainterPath MainPathPath(const QVector &points) const; QPainterPath SeamAllowancePath(const VContainer *data) const; QPainterPath SeamAllowancePath(const QVector &points) const; QPainterPath PassmarksPath(const VContainer *data, diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 24fbd649c..9b3723970 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -128,6 +128,20 @@ int IndexOfNode(const QVector &list, quint32 id) qDebug()<<"Can't find node."; return -1; } + +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath MakePainterPath(const QVector &points) +{ + QPainterPath path; + + if (not points.isEmpty()) + { + path.addPolygon(QPolygonF(points)); + path.setFillRule(Qt::WindingFill); + } + + return path; +} } //--------------------------------------------------------------------------------------------------------------------- @@ -332,6 +346,41 @@ QVector VPiecePath::PathNodePoints(const VContainer *data, bool showExc return points; } +//--------------------------------------------------------------------------------------------------------------------- +QVector > VPiecePath::PathCurvePoints(const VContainer *data) const +{ + QVector > curves; + for (int i = 0; i < CountNodes(); ++i) + { + if (at(i).IsExcluded()) + { + continue;// skip excluded node + } + + switch (at(i).GetTypeTool()) + { + case (Tool::NodeArc): + case (Tool::NodeElArc): + 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()); + + curves.append(curve->GetSegmentPoints(begin, end, at(i).GetReverse())); + break; + } + case (Tool::NodePoint): + default: + break; + } + } + + return curves; +} + //--------------------------------------------------------------------------------------------------------------------- QVector VPiecePath::SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const { @@ -374,16 +423,20 @@ QVector VPiecePath::SeamAllowancePoints(const VContainer *data, qreal //--------------------------------------------------------------------------------------------------------------------- QPainterPath VPiecePath::PainterPath(const VContainer *data) const { - const QVector points = PathPoints(data); - QPainterPath path; + return MakePainterPath(PathPoints(data)); +} - if (not points.isEmpty()) +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiecePath::CurvesPainterPath(const VContainer *data) const +{ + const QVector > curves = PathCurvePoints(data); + QVector paths(curves.size()); + + for(auto &curve : curves) { - path.addPolygon(QPolygonF(points)); - path.setFillRule(Qt::WindingFill); + paths.append(MakePainterPath(curve)); } - - return path; + return paths; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 04fbb9b6e..a107a4eeb 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -85,11 +85,13 @@ public: QString GetVisibilityTrigger() const; void SetVisibilityTrigger(const QString &formula); - QVector PathPoints(const VContainer *data) const; - QVector PathNodePoints(const VContainer *data, bool showExcluded = true) const; - QVector SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const; + QVector PathPoints(const VContainer *data) const; + QVector PathNodePoints(const VContainer *data, bool showExcluded = true) const; + QVector > PathCurvePoints(const VContainer *data) const; + QVector SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const; - QPainterPath PainterPath(const VContainer *data) const; + QPainterPath PainterPath(const VContainer *data) const; + QVector CurvesPainterPath(const VContainer *data) const; QList Dependencies() const; QVector MissingNodes(const VPiecePath &path) const; diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 9eb7daa91..67de20401 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -163,11 +163,6 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & flagMainPathIsValid = MainPathIsValid(); CheckState(); - if (not applyAllowed) - { - vis = new VisToolPiece(data); - } - m_ftb->SetCurrentIndex(TabOrder::Paths);// Show always first tab active on start. } @@ -203,6 +198,11 @@ void DialogSeamAllowance::EnableApply(bool enable) m_ftb->SetTabEnabled(TabOrder::Grainline, applyAllowed); m_ftb->SetTabEnabled(TabOrder::Passmarks, applyAllowed); m_ftb->SetTabEnabled(TabOrder::PlaceLabels, applyAllowed); + + if (not applyAllowed && vis.isNull()) + { + vis = new VisToolPiece(data); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -3028,10 +3028,13 @@ void DialogSeamAllowance::SetFormulaSAWidth(const QString &formula) } uiTabPaths->plainTextEditFormulaWidth->setPlainText(width); - VisToolPiece *path = qobject_cast(vis); - SCASSERT(path != nullptr) - const VPiece p = CreatePiece(); - path->SetPiece(p); + if (not applyAllowed) + { + VisToolPiece *path = qobject_cast(vis); + SCASSERT(path != nullptr) + const VPiece p = CreatePiece(); + path->SetPiece(p); + } MoveCursorToEnd(uiTabPaths->plainTextEditFormulaWidth); } diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index e9c0ef4f0..edc784cb3 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1355,7 +1355,9 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren) this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); const VPiece detail = VAbstractTool::data.GetPiece(m_id); - QFuture futurePath = QtConcurrent::run(detail, &VPiece::MainPathPath, this->getData()); + QFuture futurePath = QtConcurrent::run(detail, + QOverload::of(&VPiece::MainPathPath), + this->getData()); QFuture > futureSeamAllowance; if (detail.IsSeamAllowance()) diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp index 486e5afa3..256950208 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -35,13 +35,15 @@ VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) : VisPath(data, parent), m_points(), + m_curves(), m_line1(nullptr), m_line2(nullptr), m_piece(), m_pieceCached(false), m_cachedMainPath(), m_cachedNodes(), - m_cachedMainPathPoints() + m_cachedMainPathPoints(), + m_cachedCurvesPath() { m_line1 = InitItem(supportColor, this); m_line2 = InitItem(supportColor, this); @@ -56,11 +58,16 @@ void VisToolPiece::RefreshGeometry() { if (not m_pieceCached) { - m_cachedMainPath = m_piece.MainPathPath(Visualization::data); m_cachedNodes = m_piece.MainPathNodePoints(Visualization::data); if (mode == Mode::Creation) { + m_cachedCurvesPath = m_piece.CurvesPainterPath(Visualization::data); m_cachedMainPathPoints = m_piece.MainPathPoints(Visualization::data); + m_cachedMainPath = m_piece.MainPathPath(m_cachedMainPathPoints); + } + else + { + m_cachedMainPath = m_piece.MainPathPath(Visualization::data); } m_pieceCached = true; } @@ -75,6 +82,12 @@ void VisToolPiece::RefreshGeometry() if (mode == Mode::Creation) { + for (int i = 0; i < m_cachedCurvesPath.size(); ++i) + { + VCurvePathItem *path = GetCurve(static_cast(i), supportColor); + DrawPath(path, m_cachedCurvesPath.at(i), supportColor); + } + DrawLine(m_line1, QLineF(m_cachedMainPathPoints.first(), Visualization::scenePos), supportColor, Qt::DashLine); @@ -100,6 +113,12 @@ VScaledEllipse *VisToolPiece::GetPoint(quint32 i, const QColor &color) return GetPointItem(m_points, i, color, this); } +//--------------------------------------------------------------------------------------------------------------------- +VCurvePathItem *VisToolPiece::GetCurve(quint32 i, const QColor &color) +{ + return GetCurveItem(m_curves, i, color, this); +} + //--------------------------------------------------------------------------------------------------------------------- void VisToolPiece::HideAllItems() { @@ -113,9 +132,17 @@ void VisToolPiece::HideAllItems() m_line2->setVisible(false); } - for (int i=0; i < m_points.size(); ++i) + for(QGraphicsEllipseItem *item : qAsConst(m_points)) { - if (QGraphicsEllipseItem *item = m_points.at(i)) + if (item) + { + item->setVisible(false); + } + } + + for(QGraphicsPathItem *item : qAsConst(m_curves)) + { + if (item) { item->setVisible(false); } diff --git a/src/libs/vtools/visualization/path/vistoolpiece.h b/src/libs/vtools/visualization/path/vistoolpiece.h index dae2be9a3..39eb52c04 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.h +++ b/src/libs/vtools/visualization/path/vistoolpiece.h @@ -50,6 +50,7 @@ public: private: Q_DISABLE_COPY(VisToolPiece) QVector m_points; + QVector m_curves; VScaledLine *m_line1; VScaledLine *m_line2; @@ -58,8 +59,10 @@ private: QPainterPath m_cachedMainPath; QVector m_cachedNodes; QVector m_cachedMainPathPoints; + QVector m_cachedCurvesPath; VScaledEllipse* GetPoint(quint32 i, const QColor &color); + VCurvePathItem *GetCurve(quint32 i, const QColor &color); void HideAllItems(); }; diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index 657b13ce2..d0f84bbf7 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -59,6 +59,44 @@ template class QHash; Q_LOGGING_CATEGORY(vVis, "v.visualization") +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +VScaledEllipse *InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0) +{ + VScaledEllipse *point = new VScaledEllipse(parent); + point->setZValue(1); + point->setBrush(QBrush(Qt::NoBrush)); + + QPen visPen = point->pen(); + visPen.setColor(color); + + point->setPen(visPen); + point->setRect(PointRect(ScaledRadius(SceneScale(qApp->getCurrentScene())))); + point->setPos(QPointF()); + point->setFlags(QGraphicsItem::ItemStacksBehindParent); + point->setZValue(z); + point->setVisible(false); + return point; +} + +//--------------------------------------------------------------------------------------------------------------------- +VCurvePathItem *InitCurveItem(const QColor &color, QGraphicsItem *parent, qreal z = 0) +{ + VCurvePathItem *curve = new VCurvePathItem(parent); + curve->setBrush(QBrush(Qt::NoBrush)); + + QPen visPen = curve->pen(); + visPen.setColor(color); + curve->setPen(visPen); + + curve->setFlags(QGraphicsItem::ItemStacksBehindParent); + curve->setZValue(z); + curve->setVisible(false); + return curve; +} +} + //--------------------------------------------------------------------------------------------------------------------- Visualization::Visualization(const VContainer *data) :QObject(), @@ -261,22 +299,19 @@ VScaledEllipse *Visualization::GetPointItem(QVector &points, q } //--------------------------------------------------------------------------------------------------------------------- -VScaledEllipse *Visualization::InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z) +VCurvePathItem *Visualization::GetCurveItem(QVector &curves, quint32 i, const QColor &color, + QGraphicsItem *parent) { - VScaledEllipse *point = new VScaledEllipse(parent); - point->setZValue(1); - point->setBrush(QBrush(Qt::NoBrush)); - - QPen visPen = point->pen(); - visPen.setColor(color); - - point->setPen(visPen); - point->setRect(PointRect(ScaledRadius(SceneScale(qApp->getCurrentScene())))); - point->setPos(QPointF()); - point->setFlags(QGraphicsItem::ItemStacksBehindParent); - point->setZValue(z); - point->setVisible(false); - return point; + if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) + { + return curves.at(static_cast(i)); + } + else + { + auto point = InitCurveItem(color, parent); + curves.append(point); + return point; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index c10b7b4a9..106a7d557 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -114,10 +114,10 @@ protected: static VScaledEllipse *GetPointItem(QVector &points, quint32 i, const QColor &color, QGraphicsItem *parent); + static VCurvePathItem *GetCurveItem(QVector &curves, quint32 i, const QColor &color, + QGraphicsItem *parent); private: Q_DISABLE_COPY(Visualization) - - static VScaledEllipse* InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0); }; //---------------------------------------------------------------------------------------------------------------------