Added detail texts to layout mode
--HG-- branch : feature
This commit is contained in:
parent
c9ee648cb8
commit
9368978039
|
@ -477,7 +477,7 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VDetail> *de
|
||||||
const VPatternPieceData& data = d.GetPatternPieceData();
|
const VPatternPieceData& data = d.GetPatternPieceData();
|
||||||
if (data.IsVisible() == true)
|
if (data.IsVisible() == true)
|
||||||
{
|
{
|
||||||
det.SetDetailLabelPoints(data.GetPos(), data.GetLabelWidth(), data.GetLabelHeight(), data.GetRotation());
|
det.SetDetail(d.getName(), data);
|
||||||
}
|
}
|
||||||
const VPatternInfoGeometry& geom = d.GetPatternInfo();
|
const VPatternInfoGeometry& geom = d.GetPatternInfo();
|
||||||
if (geom.IsVisible() == true)
|
if (geom.IsVisible() == true)
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QFontMetrics>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
||||||
# include "../vmisc/vmath.h"
|
# include "../vmisc/vmath.h"
|
||||||
|
@ -43,12 +45,12 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VLayoutDetail::VLayoutDetail()
|
VLayoutDetail::VLayoutDetail()
|
||||||
:VAbstractDetail(), d(new VLayoutDetailData)
|
:VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail)
|
VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail)
|
||||||
:VAbstractDetail(detail), d (detail.d)
|
:VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -60,6 +62,7 @@ VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail)
|
||||||
}
|
}
|
||||||
VAbstractDetail::operator=(detail);
|
VAbstractDetail::operator=(detail);
|
||||||
d = detail.d;
|
d = detail.d;
|
||||||
|
m_tmDetail = detail.m_tmDetail;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,22 +117,63 @@ QVector<QPointF> VLayoutDetail::GetLayoutAllowencePoints() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QVector<QPointF> VLayoutDetail::GetDetailLabelPoints() const
|
void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& data)
|
||||||
{
|
{
|
||||||
return d->detailLabel;
|
d->detailData = data;
|
||||||
}
|
qreal dAng = qDegreesToRadians(data.GetRotation());
|
||||||
|
QPointF ptCenter(data.GetPos().x() + data.GetLabelWidth()/2, data.GetPos().y() + data.GetLabelHeight()/2);
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
QPointF ptPos = data.GetPos();
|
||||||
void VLayoutDetail::SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot)
|
|
||||||
{
|
|
||||||
qreal dAng = qDegreesToRadians(dRot);
|
|
||||||
QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2);
|
|
||||||
QVector<QPointF> v;
|
QVector<QPointF> v;
|
||||||
v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight)
|
v << ptPos << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y())
|
||||||
<< QPointF(ptPos.x(), ptPos.y() + dHeight);
|
<< QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y() + data.GetLabelHeight())
|
||||||
|
<< QPointF(ptPos.x(), ptPos.y() + data.GetLabelHeight());
|
||||||
for (int i = 0; i < v.count(); ++i)
|
for (int i = 0; i < v.count(); ++i)
|
||||||
v[i] = RotatePoint(ptCenter, v[i], dAng);
|
v[i] = RotatePoint(ptCenter, v[i], dAng);
|
||||||
d->detailLabel = RoundPoints(v);
|
d->detailLabel = RoundPoints(v);
|
||||||
|
|
||||||
|
// generate text
|
||||||
|
QFont fnt = QApplication::font();
|
||||||
|
m_tmDetail.SetFont(fnt);
|
||||||
|
m_tmDetail.SetFontSize(data.GetFontSize());
|
||||||
|
m_tmDetail.Clear();
|
||||||
|
TextLine tl;
|
||||||
|
// letter
|
||||||
|
tl.m_qsText = data.GetLetter();
|
||||||
|
if (tl.m_qsText.isEmpty() == false)
|
||||||
|
{
|
||||||
|
tl.m_eAlign = Qt::AlignCenter;
|
||||||
|
tl.m_eFontWeight = QFont::Bold;
|
||||||
|
tl.m_eStyle = QFont::StyleNormal;
|
||||||
|
tl.m_iFontSize = 6;
|
||||||
|
m_tmDetail.AddLine(tl);
|
||||||
|
}
|
||||||
|
// name
|
||||||
|
if (qsName.isEmpty() == false)
|
||||||
|
{
|
||||||
|
tl.m_qsText = qsName;
|
||||||
|
tl.m_eFontWeight = QFont::DemiBold;
|
||||||
|
tl.m_iFontSize = 2;
|
||||||
|
m_tmDetail.AddLine(tl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCP
|
||||||
|
QString qsText = "Cut %1 of %2%3";
|
||||||
|
QStringList qslPlace;
|
||||||
|
qslPlace << "" << " on Fold";
|
||||||
|
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
|
||||||
|
tl.m_eFontWeight = QFont::Normal;
|
||||||
|
tl.m_iFontSize = 0;
|
||||||
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||||
|
{
|
||||||
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
||||||
|
if (mcp.m_iCutNumber > 0)
|
||||||
|
{
|
||||||
|
tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]);
|
||||||
|
m_tmDetail.AddLine(tl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// will generate the lines of text
|
||||||
|
m_tmDetail.IsBigEnough(data.GetLabelWidth(), data.GetLabelHeight(), data.GetFontSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -461,7 +505,7 @@ QPainterPath VLayoutDetail::ContourPath() const
|
||||||
|
|
||||||
if (d->detailLabel.count() > 0)
|
if (d->detailLabel.count() > 0)
|
||||||
{
|
{
|
||||||
points = Map(d->detailLabel);
|
points = Map(Mirror(d->detailLabel));
|
||||||
points.push_back(points.at(0));
|
points.push_back(points.at(0));
|
||||||
|
|
||||||
QPainterPath pathDet;
|
QPainterPath pathDet;
|
||||||
|
@ -472,11 +516,46 @@ QPainterPath VLayoutDetail::ContourPath() const
|
||||||
}
|
}
|
||||||
|
|
||||||
path.addPath(pathDet);
|
path.addPath(pathDet);
|
||||||
|
|
||||||
|
|
||||||
|
qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x());
|
||||||
|
qreal dW = GetDistance(points.at(0), points.at(1));
|
||||||
|
qreal dY = 0;
|
||||||
|
qreal dX;
|
||||||
|
for (int i = 0; i < m_tmDetail.GetCount(); ++i)
|
||||||
|
{
|
||||||
|
const TextLine& tl = m_tmDetail.GetLine(i);
|
||||||
|
QFont fnt = m_tmDetail.GetFont();
|
||||||
|
fnt.setPixelSize(m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize);
|
||||||
|
fnt.setWeight(tl.m_eFontWeight);
|
||||||
|
fnt.setStyle(tl.m_eStyle);
|
||||||
|
dY += tl.m_iHeight;
|
||||||
|
QMatrix mat;
|
||||||
|
mat.translate(points.at(0).x(), points.at(0).y());
|
||||||
|
mat.rotate(qRadiansToDegrees(dAng));
|
||||||
|
QFontMetrics fm(fnt);
|
||||||
|
if ((tl.m_eAlign & Qt::AlignLeft) > 0)
|
||||||
|
{
|
||||||
|
dX = 0;
|
||||||
|
}
|
||||||
|
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
|
||||||
|
{
|
||||||
|
dX = (dW - fm.width(tl.m_qsText))/2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dX = dW - fm.width(tl.m_qsText);
|
||||||
|
}
|
||||||
|
QPainterPath pathText;
|
||||||
|
pathText.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText);
|
||||||
|
path.addPath(mat.map(pathText));
|
||||||
|
dY += m_tmDetail.GetSpacing();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->patternInfo.count() > 0)
|
if (d->patternInfo.count() > 0)
|
||||||
{
|
{
|
||||||
points = Map(d->patternInfo);
|
points = Map(Mirror(d->patternInfo));
|
||||||
points.push_back(points.at(0));
|
points.push_back(points.at(0));
|
||||||
|
|
||||||
QPainterPath pathDet;
|
QPainterPath pathDet;
|
||||||
|
@ -540,3 +619,30 @@ QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, q
|
||||||
return ptDest + ptCenter;
|
return ptDest + ptCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QPointF> VLayoutDetail::Mirror(const QVector<QPointF> &points) const
|
||||||
|
{
|
||||||
|
// should only call this method with rectangular shapes
|
||||||
|
Q_ASSERT(points.count() == 4);
|
||||||
|
if (d->mirror == false)
|
||||||
|
{
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QPointF> v;
|
||||||
|
v.resize(4);
|
||||||
|
v[0] = points.at(2);
|
||||||
|
v[1] = points.at(3);
|
||||||
|
v[2] = points.at(0);
|
||||||
|
v[3] = points.at(1);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2) const
|
||||||
|
{
|
||||||
|
qreal dX = pt1.x() - pt2.x();
|
||||||
|
qreal dY = pt1.y() - pt2.y();
|
||||||
|
|
||||||
|
return qSqrt(dX*dX + dY*dY);
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#define VLAYOUTDETAIL_H
|
#define VLAYOUTDETAIL_H
|
||||||
|
|
||||||
#include "vabstractdetail.h"
|
#include "vabstractdetail.h"
|
||||||
|
#include "../vpatterndb/vpatternpiecedata.h"
|
||||||
|
#include "../vtools/tools/vtextmanager.h"
|
||||||
|
|
||||||
#include <QMatrix>
|
#include <QMatrix>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
|
@ -54,8 +56,7 @@ public:
|
||||||
QVector<QPointF> GetLayoutAllowencePoints() const;
|
QVector<QPointF> GetLayoutAllowencePoints() const;
|
||||||
void SetLayoutAllowencePoints();
|
void SetLayoutAllowencePoints();
|
||||||
|
|
||||||
QVector<QPointF> GetDetailLabelPoints() const;
|
void SetDetail(const QString &qsName, const VPatternPieceData& data);
|
||||||
void SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot);
|
|
||||||
|
|
||||||
QVector<QPointF> GetPatternInfoPoints() const;
|
QVector<QPointF> GetPatternInfoPoints() const;
|
||||||
void SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot);
|
void SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot);
|
||||||
|
@ -88,12 +89,15 @@ public:
|
||||||
QGraphicsItem *GetItem() const Q_REQUIRED_RESULT;
|
QGraphicsItem *GetItem() const Q_REQUIRED_RESULT;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<VLayoutDetailData> d;
|
QSharedDataPointer<VLayoutDetailData> d;
|
||||||
|
VTextManager m_tmDetail;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng) const;
|
QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng) const;
|
||||||
|
QVector<QPointF> Mirror(const QVector<QPointF>& points) const;
|
||||||
|
qreal GetDistance(const QPointF& pt1, const QPointF& pt2) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE);
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
|
|
||||||
|
#include "../vpatterndb/vpatternpiecedata.h"
|
||||||
|
|
||||||
#ifdef Q_CC_GNU
|
#ifdef Q_CC_GNU
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Weffc++"
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
@ -45,13 +47,14 @@ public:
|
||||||
VLayoutDetailData()
|
VLayoutDetailData()
|
||||||
:contour(QVector<QPointF>()), seamAllowence(QVector<QPointF>()), layoutAllowence(QVector<QPointF>()),
|
:contour(QVector<QPointF>()), seamAllowence(QVector<QPointF>()), layoutAllowence(QVector<QPointF>()),
|
||||||
matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector<QPointF>()),
|
matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector<QPointF>()),
|
||||||
patternInfo(QVector<QPointF>())
|
patternInfo(QVector<QPointF>()), detailData()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
VLayoutDetailData(const VLayoutDetailData &detail)
|
VLayoutDetailData(const VLayoutDetailData &detail)
|
||||||
:QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence),
|
:QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence),
|
||||||
layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth),
|
layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth),
|
||||||
mirror(detail.mirror), detailLabel(detail.detailLabel), patternInfo(detail.patternInfo)
|
mirror(detail.mirror), detailLabel(detail.detailLabel), patternInfo(detail.patternInfo),
|
||||||
|
detailData(detail.detailData)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~VLayoutDetailData() {}
|
~VLayoutDetailData() {}
|
||||||
|
@ -77,6 +80,8 @@ public:
|
||||||
QVector<QPointF> detailLabel;
|
QVector<QPointF> detailLabel;
|
||||||
/** @brief pattern info rectangle */
|
/** @brief pattern info rectangle */
|
||||||
QVector<QPointF> patternInfo;
|
QVector<QPointF> patternInfo;
|
||||||
|
/** @brief detail data */
|
||||||
|
VPatternPieceData detailData;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VLayoutDetailData &operator=(const VLayoutDetailData &) Q_DECL_EQ_DELETE;
|
VLayoutDetailData &operator=(const VLayoutDetailData &) Q_DECL_EQ_DELETE;
|
||||||
|
|
|
@ -20,36 +20,57 @@ VTextManager::~VTextManager()
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int VTextManager::GetSpacing() const
|
int VTextManager::GetSpacing() const
|
||||||
{ return 2; }
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VTextManager::SetFont(const QFont& font)
|
void VTextManager::SetFont(const QFont& font)
|
||||||
{ m_font = font; }
|
{
|
||||||
|
m_font = font;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
const QFont& VTextManager::GetFont() const
|
const QFont& VTextManager::GetFont() const
|
||||||
{ return m_font; }
|
{
|
||||||
|
return m_font;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VTextManager::SetFontSize(int iFS)
|
void VTextManager::SetFontSize(int iFS)
|
||||||
{ m_font.setPixelSize(iFS); }
|
{
|
||||||
|
m_font.setPixelSize(iFS);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VTextManager::AddLine(const TextLine& tl)
|
void VTextManager::AddLine(const TextLine& tl)
|
||||||
{ m_liLines << tl; }
|
{
|
||||||
|
m_liLines << tl;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VTextManager::Clear()
|
void VTextManager::Clear()
|
||||||
{ m_liLines.clear(); }
|
{
|
||||||
|
m_liLines.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int VTextManager::GetCount() const
|
int VTextManager::GetCount() const
|
||||||
{ return m_liOutput.count(); }
|
{
|
||||||
|
return m_liOutput.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VTextManager::GetSourceLineCount() const
|
||||||
|
{
|
||||||
|
return m_liLines.count();
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
const TextLine& VTextManager::GetLine(int i) const
|
const TextLine& VTextManager::GetLine(int i) const
|
||||||
{ return m_liOutput[i]; }
|
{
|
||||||
|
return m_liOutput[i];
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize)
|
bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize)
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
void AddLine(const TextLine& tl);
|
void AddLine(const TextLine& tl);
|
||||||
void Clear();
|
void Clear();
|
||||||
int GetCount() const;
|
int GetCount() const;
|
||||||
|
int GetSourceLineCount() const;
|
||||||
const TextLine& GetLine(int i) const;
|
const TextLine& GetLine(int i) const;
|
||||||
bool IsBigEnough(qreal fW, qreal fH, int iFontSize);
|
bool IsBigEnough(qreal fW, qreal fH, int iFontSize);
|
||||||
|
|
||||||
|
|
|
@ -712,7 +712,8 @@ void VToolDetail::UpdateLabel()
|
||||||
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
|
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
tl.m_eFontWeight = QFont::Normal;
|
||||||
tl.m_iFontSize = 0;
|
tl.m_iFontSize = 0;
|
||||||
for (int i = 0; i < data.GetMCPCount(); ++i) {
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||||
|
{
|
||||||
MaterialCutPlacement mcp = data.GetMCP(i);
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
||||||
if (mcp.m_iCutNumber > 0)
|
if (mcp.m_iCutNumber > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user