Added class VisToolPiece.

Show visualization creating piece main path.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-05 10:56:44 +02:00
parent f8ee078ef7
commit 65a38141de
9 changed files with 229 additions and 26 deletions

View File

@ -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,

View File

@ -34,6 +34,7 @@
#include <QSharedPointer>
#include <QDebug>
#include <QPainterPath>
//---------------------------------------------------------------------------------------------------------------------
VPiece::VPiece()
@ -174,6 +175,51 @@ QVector<QPointF> VPiece::MainPathPoints(const VContainer *data) const
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
{

View File

@ -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<VPieceNode> &nodes);
QVector<QPointF> MainPathPoints(const VContainer *data) const;
QVector<QPointF> MainPathNodePoints(const VContainer *data) const;
QPainterPath MainPathPath(const VContainer *data) const;
private:
QSharedDataPointer<VPieceData> d;

View File

@ -78,17 +78,7 @@ void VisOperation::VisualMode(const quint32 &pointId)
//---------------------------------------------------------------------------------------------------------------------
QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color)
{
if (not points.isEmpty() && static_cast<quint32>(points.size() - 1) >= i)
{
return points.at(static_cast<int>(i));
}
else
{
auto point = InitPoint(color, this);
points.append(point);
return point;
}
return nullptr;
return GetPointItem(Visualization::data, factor, points, i, color, this);
}
//---------------------------------------------------------------------------------------------------------------------

View 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);
}

View 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

View File

@ -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<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

View File

@ -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 <class Item>
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:
Q_DISABLE_COPY(Visualization)
static QGraphicsEllipseItem* InitPointItem(const VContainer *data, qreal factor, const QColor &color,
QGraphicsItem *parent, qreal z = 0);
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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