Show piece's internal paths on a layout.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-22 14:32:25 +02:00
parent b99bdc4742
commit 8c1bd37491
8 changed files with 142 additions and 60 deletions

View File

@ -29,8 +29,8 @@
#include "vgraphicsfillitem.h"
//---------------------------------------------------------------------------------------------------------------------
VGraphicsFillItem::VGraphicsFillItem()
:QGraphicsPathItem()
VGraphicsFillItem::VGraphicsFillItem(QGraphicsItem *parent)
:QGraphicsPathItem(parent)
{}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -38,7 +38,7 @@ public:
/**
* @brief VGraphicsFillItem Constructor
*/
VGraphicsFillItem();
VGraphicsFillItem(QGraphicsItem *parent = nullptr);
/**
* @brief ~VGraphicsFillItem Destructor
*/

View File

@ -354,16 +354,6 @@ QList<QGraphicsItem *> VLayoutPaper::GetItemDetails() const
for (int i=0; i < d->details.count(); ++i)
{
list.append(d->details.at(i).GetItem());
for (int iT = 0; iT < d->details.at(i).GetTextItemsCount(); ++iT)
{
list.append(d->details.at(i).GetTextItem(iT));
}
QGraphicsItem* pItem = d->details.at(i).GetGrainlineItem();
if (pItem != 0)
{
list.append(pItem);
}
}
return list;
}

View File

@ -86,9 +86,10 @@ VLayoutPiece::~VLayoutPiece()
//---------------------------------------------------------------------------------------------------------------------
VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern)
{
VLayoutPiece det = VLayoutPiece();
VLayoutPiece det;
det.SetCountourPoints(piece.MainPathPoints(pattern));
det.SetSeamAllowencePoints(piece.SeamAllowancePoints(pattern), piece.IsSeamAllowance());
det.SetInternlaPathsPoints(piece.GetInternalPathsPoints(pattern));
det.SetName(piece.GetName());
const VPatternPieceData& data = piece.GetPatternPieceData();
if (data.IsVisible() == true)
@ -498,6 +499,18 @@ void VLayoutPiece::SetLayoutAllowencePoints()
}
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QVector<QPointF>> VLayoutPiece::GetInternlaPathsPoints() const
{
return d->m_internalPaths;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::SetInternlaPathsPoints(const QVector<QVector<QPointF>> &internalPathsPoints)
{
d->m_internalPaths = internalPathsPoints;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VLayoutPiece::Map(const QVector<QPointF> &points) const
{
@ -695,21 +708,17 @@ void VLayoutPiece::CreateTextItems()
}
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutPiece::GetTextItemsCount() const
{
return d->m_liPP.count();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VLayoutDetail::GetTextItem Creates and returns the i-th text item
* @brief CreateTextItem Creates the i-th text item
* @param i index of the requested item
* @return pointer to the newly created item. The caller is responsible to delete it.
* @param parent parent of this text item. Can't be null.
*/
QGraphicsItem* VLayoutPiece::GetTextItem(int i) const
void VLayoutPiece::CreateTextItem(int i, QGraphicsItem *parent) const
{
QGraphicsPathItem* item = new QGraphicsPathItem();
SCASSERT(parent != nullptr)
QGraphicsPathItem* item = new QGraphicsPathItem(parent);
QTransform transform = d->matrix;
QPainterPath path = transform.map(d->m_liPP[i]);
@ -747,7 +756,6 @@ QGraphicsItem* VLayoutPiece::GetTextItem(int i) const
item->setPath(path);
item->setBrush(QBrush(Qt::black));
return item;
}
//---------------------------------------------------------------------------------------------------------------------
@ -771,18 +779,30 @@ QPainterPath VLayoutPiece::LayoutAllowencePath() const
QGraphicsItem *VLayoutPiece::GetItem() const
{
QGraphicsPathItem *item = new QGraphicsPathItem();
item->setPath(ContourPath());
QPainterPath contour = ContourPath();
contour.addPath(InternalPathsPath());
item->setPath(contour);
for (int i = 0; i < d->m_liPP.count(); ++i)
{
CreateTextItem(i, item);
}
CreateGrainlineItem(item);
return item;
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsItem* VLayoutPiece::GetGrainlineItem() const
void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const
{
SCASSERT(parent != nullptr)
if (d->grainlinePoints.count() < 2)
{
return 0;
return;
}
VGraphicsFillItem* item = new VGraphicsFillItem();
VGraphicsFillItem* item = new VGraphicsFillItem(parent);
QPainterPath path;
QVector<QPointF> v = Map(d->grainlinePoints);
path.moveTo(v.at(0));
@ -791,7 +811,29 @@ QGraphicsItem* VLayoutPiece::GetGrainlineItem() const
path.lineTo(v.at(i));
}
item->setPath(path);
return item;
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VLayoutPiece::InternalPathsPath() const
{
QPainterPath allPaths;
allPaths.setFillRule(Qt::WindingFill);
for (qint32 i = 0; i < d->m_internalPaths.count(); ++i)
{
const QVector<QPointF> points = Map(d->m_internalPaths.at(i));
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.moveTo(points.at(0));
for (qint32 j = 1; j < points.count(); ++j)
{
path.lineTo(points.at(j));
}
path.lineTo(points.at(0));
allPaths.addPath(path);
}
return allPaths;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -79,6 +79,9 @@ public:
QVector<QPointF> GetLayoutAllowencePoints() const;
void SetLayoutAllowencePoints();
QVector<QVector<QPointF>> GetInternlaPathsPoints() const;
void SetInternlaPathsPoints(const QVector<QVector<QPointF>> &internalPathsPoints);
void SetDetail(const QString &qsName, const VPatternPieceData& data, const QFont& font);
void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font,
@ -115,19 +118,23 @@ public:
bool isNull() const;
qint64 Square() const;
QPainterPath ContourPath() const;
void ClearTextItems();
void CreateTextItems();
int GetTextItemsCount() const Q_REQUIRED_RESULT;
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<VLayoutPieceData> d;
QVector<QPointF> DetailPath() const;
void ClearTextItems();
void CreateTextItems();
void CreateTextItem(int i, QGraphicsItem *parent) const;
void CreateGrainlineItem(QGraphicsItem *parent) const;
QPainterPath InternalPathsPath() const;
static QVector<VSAPoint> PrepareAllowance(const QVector<QPointF> &points);
QVector<QPointF> Map(const QVector<QPointF> &points) const;
static QVector<QPointF> RoundPoints(const QVector<QPointF> &points);

View File

@ -47,58 +47,84 @@ class VLayoutPieceData : public QSharedData
{
public:
VLayoutPieceData()
:contour(QVector<QPointF>()), seamAllowence(QVector<QPointF>()), layoutAllowence(QVector<QPointF>()),
matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector<QPointF>()),
patternInfo(QVector<QPointF>()), grainlinePoints(QVector<QPointF>()), detailData(), patternGeom(),
grainlineGeom(), m_tmDetail(), m_tmPattern(), m_liPP(QList<QPainterPath>())
: contour(),
seamAllowence(),
layoutAllowence(),
m_internalPaths(),
matrix(),
layoutWidth(0),
mirror(false),
detailLabel(),
patternInfo(),
grainlinePoints(),
detailData(),
patternGeom(),
grainlineGeom(),
m_tmDetail(),
m_tmPattern(),
m_liPP()
{}
VLayoutPieceData(const VLayoutPieceData &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), 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)
: QSharedData(detail),
contour(detail.contour),
seamAllowence(detail.seamAllowence),
layoutAllowence(detail.layoutAllowence),
m_internalPaths(detail.m_internalPaths),
matrix(detail.matrix),
layoutWidth(detail.layoutWidth),
mirror(detail.mirror),
detailLabel(detail.detailLabel),
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)
{}
~VLayoutPieceData() {}
/** @brief contour list of contour points. */
QVector<QPointF> contour;
QVector<QPointF> contour;
/** @brief seamAllowence list of seam allowence points. */
QVector<QPointF> seamAllowence;
QVector<QPointF> seamAllowence;
/** @brief layoutAllowence list of layout allowence points. */
QVector<QPointF> layoutAllowence;
QVector<QPointF> layoutAllowence;
/** @brief m_layoutAllowence list of internal paths points. */
QVector<QVector<QPointF>> m_internalPaths;
/** @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<QPointF> detailLabel;
QVector<QPointF> detailLabel;
/** @brief patternInfo pattern info rectangle */
QVector<QPointF> patternInfo;
QVector<QPointF> patternInfo;
/** @brief grainlineInfo line */
QVector<QPointF> grainlinePoints;
QVector<QPointF> grainlinePoints;
/** @brief detailData detail data */
VPatternPieceData detailData;
VPatternPieceData detailData;
/** @brief patternGeom pattern geometry */
VPatternInfoGeometry patternGeom;
VPatternInfoGeometry patternGeom;
/** @brief grainlineGeom grainline geometry */
VGrainlineGeometry grainlineGeom;
VGrainlineGeometry grainlineGeom;
/** @brief m_tmDetail text manager for laying out detail info */
VTextManager m_tmDetail;
VTextManager m_tmDetail;
/** @brief m_tmPattern text manager for laying out pattern info */
VTextManager m_tmPattern;
VTextManager m_tmPattern;
/** @bried m_liPP list of generated text painter paths */
QList<QPainterPath> m_liPP;
QList<QPainterPath> m_liPP;
private:
VLayoutPieceData &operator=(const VLayoutPieceData &) Q_DECL_EQ_DELETE;

View File

@ -177,6 +177,21 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
return Equidistant(pointsEkv, width);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QVector<QPointF>> VPiece::GetInternalPathsPoints(const VContainer *data) const
{
QVector<QVector<QPointF>> pathsPoints;
for (int i = 0; i < d->m_internalPaths.size(); ++i)
{
const VPiecePath path = data->GetPiecePath(d->m_internalPaths.at(i));
if (path.GetType() == PiecePathType::InternalPath)
{
pathsPoints.append(path.PathPoints(data));
}
}
return pathsPoints;
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VPiece::MainPathPath(const VContainer *data) const
{

View File

@ -64,6 +64,8 @@ public:
QVector<VPointF> MainPathNodePoints(const VContainer *data) const;
QVector<QPointF> SeamAllowancePoints(const VContainer *data) const;
QVector<QVector<QPointF>> GetInternalPathsPoints(const VContainer *data) const;
QPainterPath MainPathPath(const VContainer *data) const;
QPainterPath SeamAllowancePath(const VContainer *data) const;