diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index e2f3a8ae1..debc5166b 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -158,7 +158,8 @@ enum class Vis : ToolVisHolderType ToolRotation, ToolFlippingByLine, ToolFlippingByAxis, - ToolMove + ToolMove, + ToolPiece }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle, diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index ef57752f0..6c7c31709 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -34,6 +34,7 @@ #include #include +#include //--------------------------------------------------------------------------------------------------------------------- VPiece::VPiece() @@ -174,6 +175,51 @@ QVector VPiece::MainPathPoints(const VContainer *data) const return points; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPiece::MainPathNodePoints(const VContainer *data) const +{ + QVector points; + for (int i = 0; i < CountNode(); ++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 VPiece::MainPathPath(const VContainer *data) const +{ + const QVector points = MainPathPoints(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.lineTo(points.at(0)); + path.setFillRule(Qt::WindingFill); + } + + return path; +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VPiece::StartSegment(const VContainer *data, const int &i, bool reverse) const { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 18c093f6a..13541f829 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -34,6 +34,7 @@ #include "../vlayout/vabstractpiece.h" +class QPainterPath; class VPieceData; class VPieceNode; class QPointF; @@ -60,6 +61,9 @@ public: void SetNodes(const QVector &nodes); QVector MainPathPoints(const VContainer *data) const; + QVector MainPathNodePoints(const VContainer *data) const; + + QPainterPath MainPathPath(const VContainer *data) const; private: QSharedDataPointer d; diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp index c581fc91e..b80f78d34 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.cpp +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -78,17 +78,7 @@ void VisOperation::VisualMode(const quint32 &pointId) //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) { - if (not points.isEmpty() && static_cast(points.size() - 1) >= i) - { - return points.at(static_cast(i)); - } - else - { - auto point = InitPoint(color, this); - points.append(point); - return point; - } - return nullptr; + return GetPointItem(Visualization::data, factor, points, i, color, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp new file mode 100644 index 000000000..8507dd41a --- /dev/null +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -0,0 +1,72 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 5 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 "vistoolpiece.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), + m_points(), + m_piece() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPiece::~VisToolPiece() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPiece::RefreshGeometry() +{ + if (m_piece.CountNode() > 0) + { + DrawPath(this, m_piece.MainPathPath(Visualization::data), mainColor, Qt::SolidLine, Qt::RoundCap); + + const QVector nodes = m_piece.MainPathNodePoints(Visualization::data); + + for (int i = 0; i < nodes.size(); ++i) + { + QGraphicsEllipseItem *point = GetPoint(static_cast(i), supportColor); + DrawPoint(point, nodes.at(i), supportColor); + } + + Visualization::toolTip = tr("Select main path objects, Shift - reverse direction curves, " + "Enter - finish creation"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPiece::SetPiece(const VPiece &piece) +{ + m_piece = piece; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolPiece::GetPoint(quint32 i, const QColor &color) +{ + return GetPointItem(Visualization::data, factor, m_points, i, color, this); +} diff --git a/src/libs/vtools/visualization/path/vistoolpiece.h b/src/libs/vtools/visualization/path/vistoolpiece.h new file mode 100644 index 000000000..da9e23919 --- /dev/null +++ b/src/libs/vtools/visualization/path/vistoolpiece.h @@ -0,0 +1,57 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 5 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 VISTOOLPIECE_H +#define VISTOOLPIECE_H + +#include +#include + +#include "vispath.h" +#include "../vpatterndb/vpiece.h" + +class VisToolPiece : public VisPath +{ + Q_OBJECT +public: + VisToolPiece(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPiece(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + void SetPiece(const VPiece &piece); + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPiece)}; +private: + Q_DISABLE_COPY(VisToolPiece) + QVector m_points; + VPiece m_piece; + + QGraphicsEllipseItem* GetPoint(quint32 i, const QColor &color); +}; + +#endif // VISTOOLPIECE_H diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index fabfca5f5..e77ca4089 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -141,20 +141,11 @@ void Visualization::MousePos(const QPointF &scenePos) //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const { - QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent); - point->setZValue(1); - point->setBrush(QBrush(Qt::NoBrush)); - point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor)); - point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); - point->setPos(QPointF()); - point->setFlags(QGraphicsItem::ItemStacksBehindParent); - point->setZValue(z); - point->setVisible(false); - return point; + return InitPointItem(Visualization::data, factor, color, parent, z); } //--------------------------------------------------------------------------------------------------------------------- -QRectF Visualization::PointRect(const qreal &radius) const +QRectF Visualization::PointRect(qreal radius) { QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); @@ -236,6 +227,39 @@ void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &pa pathItem->setVisible(true); } +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *Visualization::GetPointItem(const VContainer *data, qreal factor, + QVector &points, quint32 i, + const QColor &color, QGraphicsItem *parent) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPointItem(data, factor, color, parent); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *Visualization::InitPointItem(const VContainer *data, qreal factor, const QColor &color, + QGraphicsItem *parent, qreal z) +{ + QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent); + point->setZValue(1); + point->setBrush(QBrush(Qt::NoBrush)); + point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*data->GetPatternUnit()))/factor)); + point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); + point->setPos(QPointF()); + point->setFlags(QGraphicsItem::ItemStacksBehindParent); + point->setZValue(z); + point->setVisible(false); + return point; +} //--------------------------------------------------------------------------------------------------------------------- Mode Visualization::GetMode() const diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index d2e08ccd0..5a18d1a4b 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -84,7 +84,6 @@ protected: virtual void AddOnScene()=0; QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const; - QRectF PointRect(const qreal &radius) const; void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, Qt::PenStyle style = Qt::SolidLine); virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, @@ -97,8 +96,16 @@ protected: template Item *InitItem(const QColor &color, QGraphicsItem *parent); + + static QRectF PointRect(qreal radius); + static QGraphicsEllipseItem* GetPointItem(const VContainer *data, qreal factor, + QVector &points, quint32 i, const QColor &color, + QGraphicsItem *parent); private: Q_DISABLE_COPY(Visualization) + + static QGraphicsEllipseItem* InitPointItem(const VContainer *data, qreal factor, const QColor &color, + QGraphicsItem *parent, qreal z = 0); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 7eee605f6..7f16b5713 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -37,7 +37,8 @@ HEADERS += \ $$PWD/path/vistoolcubicbezierpath.h \ $$PWD/line/operation/visoperation.h \ $$PWD/line/operation/vistoolflippingbyaxis.h \ - $$PWD/line/operation/vistoolmove.h + $$PWD/line/operation/vistoolmove.h \ + $$PWD/path/vistoolpiece.h SOURCES += \ $$PWD/visualization.cpp \ @@ -75,4 +76,5 @@ SOURCES += \ $$PWD/path/vistoolcubicbezierpath.cpp \ $$PWD/line/operation/visoperation.cpp \ $$PWD/line/operation/vistoolflippingbyaxis.cpp \ - $$PWD/line/operation/vistoolmove.cpp + $$PWD/line/operation/vistoolmove.cpp \ + $$PWD/path/vistoolpiece.cpp