Resolved issue #830. Seam allowance tool - object selection and preview.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-04-02 16:49:53 +03:00
parent fe5a58beef
commit 218c2cc518
10 changed files with 182 additions and 43 deletions

View File

@ -463,10 +463,21 @@ QVector<PlaceLabelImg> VPiece::PlaceLabelPoints(const VContainer *data) const
return points; return points;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QPainterPath> VPiece::CurvesPainterPath(const VContainer *data) const
{
return GetPath().CurvesPainterPath(data);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPainterPath VPiece::MainPathPath(const VContainer *data) const QPainterPath VPiece::MainPathPath(const VContainer *data) const
{ {
const QVector<QPointF> points = MainPathPoints(data); return MainPathPath(MainPathPoints(data));
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VPiece::MainPathPath(const QVector<QPointF> &points) const
{
QPainterPath path; QPainterPath path;
if (not points.isEmpty()) if (not points.isEmpty())

View File

@ -74,7 +74,10 @@ public:
const QVector<QPointF> &seamAllowance = QVector<QPointF>()) const; const QVector<QPointF> &seamAllowance = QVector<QPointF>()) const;
QVector<PlaceLabelImg> PlaceLabelPoints(const VContainer *data) const; QVector<PlaceLabelImg> PlaceLabelPoints(const VContainer *data) const;
QVector<QPainterPath> CurvesPainterPath(const VContainer *data) const;
QPainterPath MainPathPath(const VContainer *data) const; QPainterPath MainPathPath(const VContainer *data) const;
QPainterPath MainPathPath(const QVector<QPointF> &points) const;
QPainterPath SeamAllowancePath(const VContainer *data) const; QPainterPath SeamAllowancePath(const VContainer *data) const;
QPainterPath SeamAllowancePath(const QVector<QPointF> &points) const; QPainterPath SeamAllowancePath(const QVector<QPointF> &points) const;
QPainterPath PassmarksPath(const VContainer *data, QPainterPath PassmarksPath(const VContainer *data,

View File

@ -128,6 +128,20 @@ int IndexOfNode(const QVector<VPieceNode> &list, quint32 id)
qDebug()<<"Can't find node."; qDebug()<<"Can't find node.";
return -1; return -1;
} }
//---------------------------------------------------------------------------------------------------------------------
QPainterPath MakePainterPath(const QVector<QPointF> &points)
{
QPainterPath path;
if (not points.isEmpty())
{
path.addPolygon(QPolygonF(points));
path.setFillRule(Qt::WindingFill);
}
return path;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -332,6 +346,41 @@ QVector<VPointF> VPiecePath::PathNodePoints(const VContainer *data, bool showExc
return points; return points;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<QVector<QPointF> > VPiecePath::PathCurvePoints(const VContainer *data) const
{
QVector<QVector<QPointF> > 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<VAbstractCurve> curve = data->GeometricObject<VAbstractCurve>(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<VSAPoint> VPiecePath::SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const QVector<VSAPoint> VPiecePath::SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const
{ {
@ -374,16 +423,20 @@ QVector<VSAPoint> VPiecePath::SeamAllowancePoints(const VContainer *data, qreal
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPainterPath VPiecePath::PainterPath(const VContainer *data) const QPainterPath VPiecePath::PainterPath(const VContainer *data) const
{ {
const QVector<QPointF> points = PathPoints(data); return MakePainterPath(PathPoints(data));
QPainterPath path; }
if (not points.isEmpty()) //---------------------------------------------------------------------------------------------------------------------
QVector<QPainterPath> VPiecePath::CurvesPainterPath(const VContainer *data) const
{
const QVector<QVector<QPointF> > curves = PathCurvePoints(data);
QVector<QPainterPath> paths(curves.size());
for(auto &curve : curves)
{ {
path.addPolygon(QPolygonF(points)); paths.append(MakePainterPath(curve));
path.setFillRule(Qt::WindingFill);
} }
return paths;
return path;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -85,11 +85,13 @@ public:
QString GetVisibilityTrigger() const; QString GetVisibilityTrigger() const;
void SetVisibilityTrigger(const QString &formula); void SetVisibilityTrigger(const QString &formula);
QVector<QPointF> PathPoints(const VContainer *data) const; QVector<QPointF> PathPoints(const VContainer *data) const;
QVector<VPointF> PathNodePoints(const VContainer *data, bool showExcluded = true) const; QVector<VPointF> PathNodePoints(const VContainer *data, bool showExcluded = true) const;
QVector<VSAPoint> SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const; QVector<QVector<QPointF> > PathCurvePoints(const VContainer *data) const;
QVector<VSAPoint> SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const;
QPainterPath PainterPath(const VContainer *data) const; QPainterPath PainterPath(const VContainer *data) const;
QVector<QPainterPath> CurvesPainterPath(const VContainer *data) const;
QList<quint32> Dependencies() const; QList<quint32> Dependencies() const;
QVector<quint32> MissingNodes(const VPiecePath &path) const; QVector<quint32> MissingNodes(const VPiecePath &path) const;

View File

@ -163,11 +163,6 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
flagMainPathIsValid = MainPathIsValid(); flagMainPathIsValid = MainPathIsValid();
CheckState(); CheckState();
if (not applyAllowed)
{
vis = new VisToolPiece(data);
}
m_ftb->SetCurrentIndex(TabOrder::Paths);// Show always first tab active on start. 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::Grainline, applyAllowed);
m_ftb->SetTabEnabled(TabOrder::Passmarks, applyAllowed); m_ftb->SetTabEnabled(TabOrder::Passmarks, applyAllowed);
m_ftb->SetTabEnabled(TabOrder::PlaceLabels, 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); uiTabPaths->plainTextEditFormulaWidth->setPlainText(width);
VisToolPiece *path = qobject_cast<VisToolPiece *>(vis); if (not applyAllowed)
SCASSERT(path != nullptr) {
const VPiece p = CreatePiece(); VisToolPiece *path = qobject_cast<VisToolPiece *>(vis);
path->SetPiece(p); SCASSERT(path != nullptr)
const VPiece p = CreatePiece();
path->SetPiece(p);
}
MoveCursorToEnd(uiTabPaths->plainTextEditFormulaWidth); MoveCursorToEnd(uiTabPaths->plainTextEditFormulaWidth);
} }

View File

@ -1355,7 +1355,9 @@ void VToolSeamAllowance::RefreshGeometry(bool updateChildren)
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
const VPiece detail = VAbstractTool::data.GetPiece(m_id); const VPiece detail = VAbstractTool::data.GetPiece(m_id);
QFuture<QPainterPath > futurePath = QtConcurrent::run(detail, &VPiece::MainPathPath, this->getData()); QFuture<QPainterPath > futurePath = QtConcurrent::run(detail,
QOverload<const VContainer *>::of(&VPiece::MainPathPath),
this->getData());
QFuture<QVector<QPointF> > futureSeamAllowance; QFuture<QVector<QPointF> > futureSeamAllowance;
if (detail.IsSeamAllowance()) if (detail.IsSeamAllowance())

View File

@ -35,13 +35,15 @@
VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent), : VisPath(data, parent),
m_points(), m_points(),
m_curves(),
m_line1(nullptr), m_line1(nullptr),
m_line2(nullptr), m_line2(nullptr),
m_piece(), m_piece(),
m_pieceCached(false), m_pieceCached(false),
m_cachedMainPath(), m_cachedMainPath(),
m_cachedNodes(), m_cachedNodes(),
m_cachedMainPathPoints() m_cachedMainPathPoints(),
m_cachedCurvesPath()
{ {
m_line1 = InitItem<VScaledLine>(supportColor, this); m_line1 = InitItem<VScaledLine>(supportColor, this);
m_line2 = InitItem<VScaledLine>(supportColor, this); m_line2 = InitItem<VScaledLine>(supportColor, this);
@ -56,11 +58,16 @@ void VisToolPiece::RefreshGeometry()
{ {
if (not m_pieceCached) if (not m_pieceCached)
{ {
m_cachedMainPath = m_piece.MainPathPath(Visualization::data);
m_cachedNodes = m_piece.MainPathNodePoints(Visualization::data); m_cachedNodes = m_piece.MainPathNodePoints(Visualization::data);
if (mode == Mode::Creation) if (mode == Mode::Creation)
{ {
m_cachedCurvesPath = m_piece.CurvesPainterPath(Visualization::data);
m_cachedMainPathPoints = m_piece.MainPathPoints(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; m_pieceCached = true;
} }
@ -75,6 +82,12 @@ void VisToolPiece::RefreshGeometry()
if (mode == Mode::Creation) if (mode == Mode::Creation)
{ {
for (int i = 0; i < m_cachedCurvesPath.size(); ++i)
{
VCurvePathItem *path = GetCurve(static_cast<quint32>(i), supportColor);
DrawPath(path, m_cachedCurvesPath.at(i), supportColor);
}
DrawLine(m_line1, QLineF(m_cachedMainPathPoints.first(), Visualization::scenePos), supportColor, DrawLine(m_line1, QLineF(m_cachedMainPathPoints.first(), Visualization::scenePos), supportColor,
Qt::DashLine); Qt::DashLine);
@ -100,6 +113,12 @@ VScaledEllipse *VisToolPiece::GetPoint(quint32 i, const QColor &color)
return GetPointItem(m_points, i, color, this); 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() void VisToolPiece::HideAllItems()
{ {
@ -113,9 +132,17 @@ void VisToolPiece::HideAllItems()
m_line2->setVisible(false); 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); item->setVisible(false);
} }

View File

@ -50,6 +50,7 @@ public:
private: private:
Q_DISABLE_COPY(VisToolPiece) Q_DISABLE_COPY(VisToolPiece)
QVector<VScaledEllipse *> m_points; QVector<VScaledEllipse *> m_points;
QVector<VCurvePathItem *> m_curves;
VScaledLine *m_line1; VScaledLine *m_line1;
VScaledLine *m_line2; VScaledLine *m_line2;
@ -58,8 +59,10 @@ private:
QPainterPath m_cachedMainPath; QPainterPath m_cachedMainPath;
QVector<VPointF> m_cachedNodes; QVector<VPointF> m_cachedNodes;
QVector<QPointF> m_cachedMainPathPoints; QVector<QPointF> m_cachedMainPathPoints;
QVector<QPainterPath> m_cachedCurvesPath;
VScaledEllipse* GetPoint(quint32 i, const QColor &color); VScaledEllipse* GetPoint(quint32 i, const QColor &color);
VCurvePathItem *GetCurve(quint32 i, const QColor &color);
void HideAllItems(); void HideAllItems();
}; };

View File

@ -59,6 +59,44 @@ template <class K, class V> class QHash;
Q_LOGGING_CATEGORY(vVis, "v.visualization") 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) Visualization::Visualization(const VContainer *data)
:QObject(), :QObject(),
@ -261,22 +299,19 @@ VScaledEllipse *Visualization::GetPointItem(QVector<VScaledEllipse *> &points, q
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VScaledEllipse *Visualization::InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z) VCurvePathItem *Visualization::GetCurveItem(QVector<VCurvePathItem *> &curves, quint32 i, const QColor &color,
QGraphicsItem *parent)
{ {
VScaledEllipse *point = new VScaledEllipse(parent); if (not curves.isEmpty() && static_cast<quint32>(curves.size() - 1) >= i)
point->setZValue(1); {
point->setBrush(QBrush(Qt::NoBrush)); return curves.at(static_cast<int>(i));
}
QPen visPen = point->pen(); else
visPen.setColor(color); {
auto point = InitCurveItem(color, parent);
point->setPen(visPen); curves.append(point);
point->setRect(PointRect(ScaledRadius(SceneScale(qApp->getCurrentScene())))); return point;
point->setPos(QPointF()); }
point->setFlags(QGraphicsItem::ItemStacksBehindParent);
point->setZValue(z);
point->setVisible(false);
return point;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -114,10 +114,10 @@ protected:
static VScaledEllipse *GetPointItem(QVector<VScaledEllipse *> &points, quint32 i, const QColor &color, static VScaledEllipse *GetPointItem(QVector<VScaledEllipse *> &points, quint32 i, const QColor &color,
QGraphicsItem *parent); QGraphicsItem *parent);
static VCurvePathItem *GetCurveItem(QVector<VCurvePathItem *> &curves, quint32 i, const QColor &color,
QGraphicsItem *parent);
private: private:
Q_DISABLE_COPY(Visualization) Q_DISABLE_COPY(Visualization)
static VScaledEllipse* InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0);
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------