Added class VisToolPiece.
Show visualization creating piece main path. --HG-- branch : feature
This commit is contained in:
parent
f8ee078ef7
commit
65a38141de
|
@ -158,7 +158,8 @@ enum class Vis : ToolVisHolderType
|
||||||
ToolRotation,
|
ToolRotation,
|
||||||
ToolFlippingByLine,
|
ToolFlippingByLine,
|
||||||
ToolFlippingByAxis,
|
ToolFlippingByAxis,
|
||||||
ToolMove
|
ToolMove,
|
||||||
|
ToolPiece
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle,
|
enum class VarType : char { Measurement, Increment, LineLength, CurveLength, CurveCLength, LineAngle, CurveAngle,
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPiece::VPiece()
|
VPiece::VPiece()
|
||||||
|
@ -174,6 +175,51 @@ QVector<QPointF> VPiece::MainPathPoints(const VContainer *data) const
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QPointF> VPiece::MainPathNodePoints(const VContainer *data) const
|
||||||
|
{
|
||||||
|
QVector<QPointF> points;
|
||||||
|
for (int i = 0; i < CountNode(); ++i)
|
||||||
|
{
|
||||||
|
switch (at(i).GetTypeTool())
|
||||||
|
{
|
||||||
|
case Tool::NodePoint:
|
||||||
|
{
|
||||||
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(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<QPointF> 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
|
QPointF VPiece::StartSegment(const VContainer *data, const int &i, bool reverse) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "../vlayout/vabstractpiece.h"
|
#include "../vlayout/vabstractpiece.h"
|
||||||
|
|
||||||
|
class QPainterPath;
|
||||||
class VPieceData;
|
class VPieceData;
|
||||||
class VPieceNode;
|
class VPieceNode;
|
||||||
class QPointF;
|
class QPointF;
|
||||||
|
@ -60,6 +61,9 @@ public:
|
||||||
void SetNodes(const QVector<VPieceNode> &nodes);
|
void SetNodes(const QVector<VPieceNode> &nodes);
|
||||||
|
|
||||||
QVector<QPointF> MainPathPoints(const VContainer *data) const;
|
QVector<QPointF> MainPathPoints(const VContainer *data) const;
|
||||||
|
QVector<QPointF> MainPathNodePoints(const VContainer *data) const;
|
||||||
|
|
||||||
|
QPainterPath MainPathPath(const VContainer *data) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<VPieceData> d;
|
QSharedDataPointer<VPieceData> d;
|
||||||
|
|
|
@ -78,17 +78,7 @@ void VisOperation::VisualMode(const quint32 &pointId)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color)
|
QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color)
|
||||||
{
|
{
|
||||||
if (not points.isEmpty() && static_cast<quint32>(points.size() - 1) >= i)
|
return GetPointItem(Visualization::data, factor, points, i, color, this);
|
||||||
{
|
|
||||||
return points.at(static_cast<int>(i));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto point = InitPoint(color, this);
|
|
||||||
points.append(point);
|
|
||||||
return point;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
72
src/libs/vtools/visualization/path/vistoolpiece.cpp
Normal file
72
src/libs/vtools/visualization/path/vistoolpiece.cpp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @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
|
||||||
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#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<QPointF> nodes = m_piece.MainPathNodePoints(Visualization::data);
|
||||||
|
|
||||||
|
for (int i = 0; i < nodes.size(); ++i)
|
||||||
|
{
|
||||||
|
QGraphicsEllipseItem *point = GetPoint(static_cast<quint32>(i), supportColor);
|
||||||
|
DrawPoint(point, nodes.at(i), supportColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
Visualization::toolTip = tr("Select main path objects, <b>Shift</b> - reverse direction curves, "
|
||||||
|
"<b>Enter</b> - 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);
|
||||||
|
}
|
57
src/libs/vtools/visualization/path/vistoolpiece.h
Normal file
57
src/libs/vtools/visualization/path/vistoolpiece.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @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
|
||||||
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VISTOOLPIECE_H
|
||||||
|
#define VISTOOLPIECE_H
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#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<int>(Vis::ToolPiece)};
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VisToolPiece)
|
||||||
|
QVector<QGraphicsEllipseItem *> m_points;
|
||||||
|
VPiece m_piece;
|
||||||
|
|
||||||
|
QGraphicsEllipseItem* GetPoint(quint32 i, const QColor &color);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VISTOOLPIECE_H
|
|
@ -141,20 +141,11 @@ void Visualization::MousePos(const QPointF &scenePos)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const
|
QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const
|
||||||
{
|
{
|
||||||
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent);
|
return InitPointItem(Visualization::data, factor, color, parent, z);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QRectF Visualization::PointRect(const qreal &radius) const
|
QRectF Visualization::PointRect(qreal radius)
|
||||||
{
|
{
|
||||||
QRectF rec = QRectF(0, 0, radius*2, radius*2);
|
QRectF rec = QRectF(0, 0, radius*2, radius*2);
|
||||||
rec.translate(-rec.center().x(), -rec.center().y());
|
rec.translate(-rec.center().x(), -rec.center().y());
|
||||||
|
@ -236,6 +227,39 @@ void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &pa
|
||||||
pathItem->setVisible(true);
|
pathItem->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QGraphicsEllipseItem *Visualization::GetPointItem(const VContainer *data, qreal factor,
|
||||||
|
QVector<QGraphicsEllipseItem *> &points, quint32 i,
|
||||||
|
const QColor &color, QGraphicsItem *parent)
|
||||||
|
{
|
||||||
|
if (not points.isEmpty() && static_cast<quint32>(points.size() - 1) >= i)
|
||||||
|
{
|
||||||
|
return points.at(static_cast<int>(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
|
Mode Visualization::GetMode() const
|
||||||
|
|
|
@ -84,7 +84,6 @@ protected:
|
||||||
virtual void AddOnScene()=0;
|
virtual void AddOnScene()=0;
|
||||||
|
|
||||||
QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const;
|
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,
|
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color,
|
||||||
Qt::PenStyle style = Qt::SolidLine);
|
Qt::PenStyle style = Qt::SolidLine);
|
||||||
virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||||
|
@ -97,8 +96,16 @@ protected:
|
||||||
|
|
||||||
template <class Item>
|
template <class Item>
|
||||||
Item *InitItem(const QColor &color, QGraphicsItem *parent);
|
Item *InitItem(const QColor &color, QGraphicsItem *parent);
|
||||||
|
|
||||||
|
static QRectF PointRect(qreal radius);
|
||||||
|
static QGraphicsEllipseItem* GetPointItem(const VContainer *data, qreal factor,
|
||||||
|
QVector<QGraphicsEllipseItem *> &points, quint32 i, const QColor &color,
|
||||||
|
QGraphicsItem *parent);
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Visualization)
|
Q_DISABLE_COPY(Visualization)
|
||||||
|
|
||||||
|
static QGraphicsEllipseItem* InitPointItem(const VContainer *data, qreal factor, const QColor &color,
|
||||||
|
QGraphicsItem *parent, qreal z = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -37,7 +37,8 @@ HEADERS += \
|
||||||
$$PWD/path/vistoolcubicbezierpath.h \
|
$$PWD/path/vistoolcubicbezierpath.h \
|
||||||
$$PWD/line/operation/visoperation.h \
|
$$PWD/line/operation/visoperation.h \
|
||||||
$$PWD/line/operation/vistoolflippingbyaxis.h \
|
$$PWD/line/operation/vistoolflippingbyaxis.h \
|
||||||
$$PWD/line/operation/vistoolmove.h
|
$$PWD/line/operation/vistoolmove.h \
|
||||||
|
$$PWD/path/vistoolpiece.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/visualization.cpp \
|
$$PWD/visualization.cpp \
|
||||||
|
@ -75,4 +76,5 @@ SOURCES += \
|
||||||
$$PWD/path/vistoolcubicbezierpath.cpp \
|
$$PWD/path/vistoolcubicbezierpath.cpp \
|
||||||
$$PWD/line/operation/visoperation.cpp \
|
$$PWD/line/operation/visoperation.cpp \
|
||||||
$$PWD/line/operation/vistoolflippingbyaxis.cpp \
|
$$PWD/line/operation/vistoolflippingbyaxis.cpp \
|
||||||
$$PWD/line/operation/vistoolmove.cpp
|
$$PWD/line/operation/vistoolmove.cpp \
|
||||||
|
$$PWD/path/vistoolpiece.cpp
|
||||||
|
|
Loading…
Reference in New Issue
Block a user