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" #include "vgraphicsfillitem.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VGraphicsFillItem::VGraphicsFillItem() VGraphicsFillItem::VGraphicsFillItem(QGraphicsItem *parent)
:QGraphicsPathItem() :QGraphicsPathItem(parent)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

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

View File

@ -354,16 +354,6 @@ QList<QGraphicsItem *> VLayoutPaper::GetItemDetails() const
for (int i=0; i < d->details.count(); ++i) for (int i=0; i < d->details.count(); ++i)
{ {
list.append(d->details.at(i).GetItem()); 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; return list;
} }

View File

@ -86,9 +86,10 @@ VLayoutPiece::~VLayoutPiece()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern) VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern)
{ {
VLayoutPiece det = VLayoutPiece(); VLayoutPiece det;
det.SetCountourPoints(piece.MainPathPoints(pattern)); det.SetCountourPoints(piece.MainPathPoints(pattern));
det.SetSeamAllowencePoints(piece.SeamAllowancePoints(pattern), piece.IsSeamAllowance()); det.SetSeamAllowencePoints(piece.SeamAllowancePoints(pattern), piece.IsSeamAllowance());
det.SetInternlaPathsPoints(piece.GetInternalPathsPoints(pattern));
det.SetName(piece.GetName()); det.SetName(piece.GetName());
const VPatternPieceData& data = piece.GetPatternPieceData(); const VPatternPieceData& data = piece.GetPatternPieceData();
if (data.IsVisible() == true) 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 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 * @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; QTransform transform = d->matrix;
QPainterPath path = transform.map(d->m_liPP[i]); QPainterPath path = transform.map(d->m_liPP[i]);
@ -747,7 +756,6 @@ QGraphicsItem* VLayoutPiece::GetTextItem(int i) const
item->setPath(path); item->setPath(path);
item->setBrush(QBrush(Qt::black)); item->setBrush(QBrush(Qt::black));
return item;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -771,18 +779,30 @@ QPainterPath VLayoutPiece::LayoutAllowencePath() const
QGraphicsItem *VLayoutPiece::GetItem() const QGraphicsItem *VLayoutPiece::GetItem() const
{ {
QGraphicsPathItem *item = new QGraphicsPathItem(); 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; return item;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QGraphicsItem* VLayoutPiece::GetGrainlineItem() const void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const
{ {
SCASSERT(parent != nullptr)
if (d->grainlinePoints.count() < 2) if (d->grainlinePoints.count() < 2)
{ {
return 0; return;
} }
VGraphicsFillItem* item = new VGraphicsFillItem(); VGraphicsFillItem* item = new VGraphicsFillItem(parent);
QPainterPath path; QPainterPath path;
QVector<QPointF> v = Map(d->grainlinePoints); QVector<QPointF> v = Map(d->grainlinePoints);
path.moveTo(v.at(0)); path.moveTo(v.at(0));
@ -791,7 +811,29 @@ QGraphicsItem* VLayoutPiece::GetGrainlineItem() const
path.lineTo(v.at(i)); path.lineTo(v.at(i));
} }
item->setPath(path); 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; QVector<QPointF> GetLayoutAllowencePoints() const;
void SetLayoutAllowencePoints(); 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 SetDetail(const QString &qsName, const VPatternPieceData& data, const QFont& font);
void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font, void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font,
@ -115,19 +118,23 @@ public:
bool isNull() const; bool isNull() const;
qint64 Square() const; qint64 Square() const;
QPainterPath ContourPath() 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; QPainterPath LayoutAllowencePath() const;
QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; QGraphicsItem *GetItem() const Q_REQUIRED_RESULT;
QGraphicsItem* GetGrainlineItem() const Q_REQUIRED_RESULT;
private: private:
QSharedDataPointer<VLayoutPieceData> d; QSharedDataPointer<VLayoutPieceData> d;
QVector<QPointF> DetailPath() const; 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); static QVector<VSAPoint> PrepareAllowance(const QVector<QPointF> &points);
QVector<QPointF> Map(const QVector<QPointF> &points) const; QVector<QPointF> Map(const QVector<QPointF> &points) const;
static QVector<QPointF> RoundPoints(const QVector<QPointF> &points); static QVector<QPointF> RoundPoints(const QVector<QPointF> &points);

View File

@ -47,19 +47,42 @@ class VLayoutPieceData : public QSharedData
{ {
public: public:
VLayoutPieceData() VLayoutPieceData()
:contour(QVector<QPointF>()), seamAllowence(QVector<QPointF>()), layoutAllowence(QVector<QPointF>()), : contour(),
matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector<QPointF>()), seamAllowence(),
patternInfo(QVector<QPointF>()), grainlinePoints(QVector<QPointF>()), detailData(), patternGeom(), layoutAllowence(),
grainlineGeom(), m_tmDetail(), m_tmPattern(), m_liPP(QList<QPainterPath>()) m_internalPaths(),
matrix(),
layoutWidth(0),
mirror(false),
detailLabel(),
patternInfo(),
grainlinePoints(),
detailData(),
patternGeom(),
grainlineGeom(),
m_tmDetail(),
m_tmPattern(),
m_liPP()
{} {}
VLayoutPieceData(const VLayoutPieceData &detail) VLayoutPieceData(const VLayoutPieceData &detail)
:QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), : QSharedData(detail),
layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), contour(detail.contour),
layoutWidth(detail.layoutWidth), mirror(detail.mirror), detailLabel(detail.detailLabel), seamAllowence(detail.seamAllowence),
patternInfo(detail.patternInfo), grainlinePoints(detail.grainlinePoints), detailData(detail.detailData), layoutAllowence(detail.layoutAllowence),
patternGeom(detail.patternGeom), grainlineGeom(detail.grainlineGeom), m_tmDetail(detail.m_tmDetail), m_internalPaths(detail.m_internalPaths),
m_tmPattern(detail.m_tmPattern), m_liPP(detail.m_liPP) 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() {} ~VLayoutPieceData() {}
@ -73,6 +96,9 @@ public:
/** @brief layoutAllowence list of layout allowence points. */ /** @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*/ /** @brief matrix transformation matrix*/
QTransform matrix; QTransform matrix;

View File

@ -177,6 +177,21 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
return Equidistant(pointsEkv, width); 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 QPainterPath VPiece::MainPathPath(const VContainer *data) const
{ {

View File

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