From 46eb6dfaa34a7961aef69afb22796162821e1876 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 16 Oct 2016 11:38:08 +0200 Subject: [PATCH] Added grainline to layout --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 6 +++ src/libs/vlayout/vlayoutdetail.cpp | 56 ++++++++++++++++++++++++++ src/libs/vlayout/vlayoutdetail.h | 5 +++ src/libs/vlayout/vlayoutdetail_p.h | 35 +++++++++------- src/libs/vlayout/vlayoutpaper.cpp | 6 +++ 5 files changed, 94 insertions(+), 14 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 8dd23ae17..141bf9f81 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -39,6 +39,7 @@ #include "../vlayout/vposter.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" +#include "../vpatterndb/vgrainlinegeometry.h" #include #include @@ -476,6 +477,11 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de } det.SetPatternInfo(pDoc, geom, qApp->font(), pattern->size(), pattern->height()); } + const VGrainlineGeometry& grainlineGeom = d.GetGrainlineGeometry(); + if (grainlineGeom.IsVisible() == true) + { + det.SetGrainline(grainlineGeom, *pattern); + } det.setWidth(qApp->toPixel(d.getWidth())); det.CreateTextItems(); det.setForbidFlipping(d.getForbidFlipping()); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index fc4de3307..16204c087 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -46,6 +46,8 @@ #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vmisc/vmath.h" +#include "../vmisc/vabstractapplication.h" +#include "../vpatterndb/calculator.h" #include "vlayoutdef.h" #include "vlayoutdetail_p.h" #include "vtextmanager.h" @@ -180,6 +182,41 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutDetail::SetGrainline(const VGrainlineGeometry& geom, const VContainer& rPattern) +{ + d->grainlineGeom = geom; + qreal dAng; + qreal dLen; + + try + { + QString qsFormula = geom.GetRotation().replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal1; + dAng = cal1.EvalFormula(rPattern.PlainVariables(), qsFormula); + dAng = qDegreesToRadians(dAng); + + qsFormula = geom.GetLength().replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal2; + dLen = cal2.EvalFormula(rPattern.PlainVariables(), qsFormula); + dLen = ToPixel(dLen, *rPattern.GetPatternUnit()); + } + catch(...) + { + return; + } + + QPointF pt1 = geom.GetPos(); + QPointF pt2; + pt2.setX(pt1.x() + dLen * qCos(dAng)); + pt2.setY(pt1.y() - dLen * qSin(dAng)); + QVector v; + v << pt1 << pt2; + d->grainlinePoints = RoundPoints(v); +} + //--------------------------------------------------------------------------------------------------------------------- QTransform VLayoutDetail::GetMatrix() const { @@ -673,6 +710,25 @@ QGraphicsItem *VLayoutDetail::GetItem() const return item; } +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsItem* VLayoutDetail::GetGrainlineItem() const +{ + if (d->grainlinePoints.count() < 2) + { + return 0; + } + QGraphicsPathItem* item = new QGraphicsPathItem(); + QPainterPath path; + QVector v = Map(d->grainlinePoints); + path.moveTo(v.at(0)); + for (int i = 1; i < v.count(); ++i) + { + path.lineTo(v.at(i)); + } + item->setPath(path); + return item; +} + //--------------------------------------------------------------------------------------------------------------------- bool VLayoutDetail::IsMirror() const { diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index ef9cbd5cb..1c85855a9 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -44,6 +44,7 @@ #include "../ifc/xml/vabstractpattern.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vcontainer.h" #include "vabstractdetail.h" class QFont; @@ -57,6 +58,7 @@ class VAbstractPattern; class VLayoutDetailData; class VPatternInfoGeometry; class VPatternPieceData; +class VGrainlineGeometry; class VLayoutDetail :public VAbstractDetail { @@ -80,6 +82,8 @@ public: void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font, qreal dSize, qreal dHeight); + void SetGrainline(const VGrainlineGeometry& geom, const VContainer& rPattern); + QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); @@ -110,6 +114,7 @@ public: QGraphicsItem* GetTextItem(int i) const Q_REQUIRED_RESULT; QPainterPath LayoutAllowencePath() const; QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; + QGraphicsItem* GetGrainlineItem() const Q_REQUIRED_RESULT; private: QSharedDataPointer d; diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index efbdf8ca6..289af3275 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -36,6 +36,8 @@ #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" +#include "../vpatterndb/vgrainlinegeometry.h" + #include "vtextmanager.h" QT_WARNING_PUSH @@ -47,45 +49,50 @@ public: VLayoutDetailData() :contour(QVector()), seamAllowence(QVector()), layoutAllowence(QVector()), matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector()), - patternInfo(QVector()), detailData(), patternGeom(), m_tmDetail(), - m_tmPattern(), m_liPP(QList()) + patternInfo(QVector()), grainlinePoints(QVector()), detailData(), patternGeom(), + grainlineGeom(), m_tmDetail(), m_tmPattern(), m_liPP(QList()) {} VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), mirror(detail.mirror), detailLabel(detail.detailLabel), - patternInfo(detail.patternInfo), detailData(detail.detailData), patternGeom(detail.patternGeom), - m_tmDetail(detail.m_tmDetail), m_tmPattern(detail.m_tmPattern), m_liPP(detail.m_liPP) + patternInfo(detail.patternInfo), grainlinePoints(detail.grainlinePoints), detailData(detail.detailData), + patternGeom(detail.patternGeom), grainlineGeom(detail.grainlineGeom), m_tmDetail(detail.m_tmDetail), + m_tmPattern(detail.m_tmPattern), m_liPP(detail.m_liPP) {} ~VLayoutDetailData() {} /** @brief contour list of contour points. */ - QVector contour; + QVector contour; /** @brief seamAllowence list of seam allowence points. */ - QVector seamAllowence; + QVector seamAllowence; /** @brief layoutAllowence list of layout allowence points. */ - QVector layoutAllowence; + QVector layoutAllowence; /** @brief matrix transformation matrix*/ - QTransform matrix; + QTransform matrix; /** @brief layoutWidth value layout allowence width in pixels. */ - qreal layoutWidth; + qreal layoutWidth; - bool mirror; + bool mirror; /** @brief detailLabel detail label rectangle */ - QVector detailLabel; + QVector detailLabel; /** @brief patternInfo pattern info rectangle */ - QVector patternInfo; + QVector patternInfo; + /** @brief grainlineInfo line */ + QVector grainlinePoints; /** @brief detailData detail data */ - VPatternPieceData detailData; + VPatternPieceData detailData; /** @brief patternGeom pattern geometry */ - VPatternInfoGeometry patternGeom; + VPatternInfoGeometry patternGeom; + /** @brief grainlineGeom grainline geometry */ + VGrainlineGeometry grainlineGeom; /** @brief m_tmDetail text manager for laying out detail info */ VTextManager m_tmDetail; /** @brief m_tmPattern text manager for laying out pattern info */ diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 638d43503..169c51457 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -348,6 +348,12 @@ QList VLayoutPaper::GetItemDetails() const { list.append(d->details.at(i).GetTextItem(iT)); } + + QGraphicsItem* pItem = d->details.at(i).GetGrainlineItem(); + if (pItem != 0) + { + list.append(pItem); + } } return list; }