Tool path and piece now bring formulas, should cover this fact.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-21 17:32:08 +02:00
parent ef9411cf5a
commit 8b1e9e24d4
6 changed files with 149 additions and 33 deletions

View File

@ -706,7 +706,7 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr)); detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr));
detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr)); detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr));
const QString width = GetParametrString(domElement, VToolSeamAllowance::AttrWidth, "0.0"); const QString width = GetParametrString(domElement, AttrWidth, "0.0");
QString w = width;//need for saving fixed formula; QString w = width;//need for saving fixed formula;
const uint version = GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1"); const uint version = GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1");
@ -762,7 +762,7 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
//Rewrite attribute formula. Need for situation when we have wrong formula. //Rewrite attribute formula. Need for situation when we have wrong formula.
if (w != width) if (w != width)
{ {
SetAttribute(domElement, VToolSeamAllowance::AttrWidth, w); SetAttribute(domElement, AttrWidth, w);
modified = true; modified = true;
haveLiteChange(); haveLiteChange();
} }
@ -811,13 +811,13 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail)
ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); ptPos.setX(GetParametrDouble(domElement, AttrMx, "0"));
ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); ptPos.setY(GetParametrDouble(domElement, AttrMy, "0"));
detail.GetPatternPieceData().SetPos(ptPos); detail.GetPatternPieceData().SetPos(ptPos);
qreal dLW = GetParametrDouble(domElement, VToolSeamAllowance::AttrWidth, "0"); qreal dLW = GetParametrDouble(domElement, AttrWidth, "0");
detail.GetPatternPieceData().SetLabelWidth(dLW); detail.GetPatternPieceData().SetLabelWidth(dLW);
qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0"); qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0");
detail.GetPatternPieceData().SetLabelHeight(dLH); detail.GetPatternPieceData().SetLabelHeight(dLH);
int iFS = static_cast<int>(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0")); int iFS = static_cast<int>(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"));
detail.GetPatternPieceData().SetFontSize(iFS); detail.GetPatternPieceData().SetFontSize(iFS);
qreal dRot = GetParametrDouble(domElement, VToolSeamAllowance::AttrRotation, "0"); qreal dRot = GetParametrDouble(domElement, AttrRotation, "0");
detail.GetPatternPieceData().SetRotation(dRot); detail.GetPatternPieceData().SetRotation(dRot);
QDomNodeList nodeListMCP = domElement.childNodes(); QDomNodeList nodeListMCP = domElement.childNodes();
@ -844,13 +844,13 @@ void VPattern::ParsePiecePatternInfo(const QDomElement &domElement, VPiece &deta
ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); ptPos.setX(GetParametrDouble(domElement, AttrMx, "0"));
ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); ptPos.setY(GetParametrDouble(domElement, AttrMy, "0"));
detail.GetPatternInfo().SetPos(ptPos); detail.GetPatternInfo().SetPos(ptPos);
qreal dLW = GetParametrDouble(domElement, VToolSeamAllowance::AttrWidth, "0"); qreal dLW = GetParametrDouble(domElement, AttrWidth, "0");
detail.GetPatternInfo().SetLabelWidth(dLW); detail.GetPatternInfo().SetLabelWidth(dLW);
qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0"); qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0");
detail.GetPatternInfo().SetLabelHeight(dLH); detail.GetPatternInfo().SetLabelHeight(dLH);
int iFS = static_cast<int>(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0")); int iFS = static_cast<int>(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"));
detail.GetPatternInfo().SetFontSize(iFS); detail.GetPatternInfo().SetFontSize(iFS);
qreal dRot = GetParametrDouble(domElement, VToolSeamAllowance::AttrRotation, "0"); qreal dRot = GetParametrDouble(domElement, AttrRotation, "0");
detail.GetPatternInfo().SetRotation(dRot); detail.GetPatternInfo().SetRotation(dRot);
} }
@ -864,7 +864,7 @@ void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &detail
detail.GetGrainlineGeometry().SetPos(ptPos); detail.GetGrainlineGeometry().SetPos(ptPos);
QString qsLength = GetParametrString(domElement, AttrLength, "0"); QString qsLength = GetParametrString(domElement, AttrLength, "0");
detail.GetGrainlineGeometry().SetLength(qsLength); detail.GetGrainlineGeometry().SetLength(qsLength);
QString qsRot = GetParametrString(domElement, VToolSeamAllowance::AttrRotation, "90"); QString qsRot = GetParametrString(domElement, AttrRotation, "90");
detail.GetGrainlineGeometry().SetRotation(qsRot); detail.GetGrainlineGeometry().SetRotation(qsRot);
VGrainlineGeometry::ArrowType eAT = VGrainlineGeometry::ArrowType eAT =
VGrainlineGeometry::ArrowType(GetParametrUInt(domElement, AttrArrows, "0")); VGrainlineGeometry::ArrowType(GetParametrUInt(domElement, AttrArrows, "0"));
@ -3205,7 +3205,7 @@ void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domEleme
const QDomElement element = domElement.firstChildElement(VAbstractPattern::TagNodes); const QDomElement element = domElement.firstChildElement(VAbstractPattern::TagNodes);
if (not element.isNull()) if (not element.isNull())
{ {
ParsePathNodes(element, path); path = ParsePathNodes(element);
} }
path.SetType(type); path.SetType(type);
@ -3222,20 +3222,6 @@ void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domEleme
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParsePathNodes(const QDomElement &domElement, VPiecePath &path) const
{
const QDomNodeList nodeList = domElement.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
{
const QDomElement element = nodeList.at(i).toElement();
if (not element.isNull() && element.tagName() == VAbstractPattern::TagNode)
{
path.Append(ParseSANode(element));
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ParseIncrementsElement parse increments tag. * @brief ParseIncrementsElement parse increments tag.

View File

@ -141,7 +141,6 @@ private:
const QString& type); const QString& type);
void ParsePathElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParsePathElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParsePathNodes(const QDomElement &domElement, VPiecePath &path) const;
void ParseIncrementsElement(const QDomNode& node); void ParseIncrementsElement(const QDomNode& node);
void PrepareForParse(const Document &parse); void PrepareForParse(const Document &parse);

View File

@ -113,6 +113,8 @@ const QString VAbstractPattern::AttrStart = QStringLiteral("start");
const QString VAbstractPattern::AttrPath = QStringLiteral("path"); const QString VAbstractPattern::AttrPath = QStringLiteral("path");
const QString VAbstractPattern::AttrEnd = QStringLiteral("end"); const QString VAbstractPattern::AttrEnd = QStringLiteral("end");
const QString VAbstractPattern::AttrIncludeAs = QStringLiteral("includeAs"); const QString VAbstractPattern::AttrIncludeAs = QStringLiteral("includeAs");
const QString VAbstractPattern::AttrWidth = QStringLiteral("width");
const QString VAbstractPattern::AttrRotation = QStringLiteral("rotation");
const QString VAbstractPattern::AttrAll = QStringLiteral("all"); const QString VAbstractPattern::AttrAll = QStringLiteral("all");
@ -1402,6 +1404,22 @@ void VAbstractPattern::ToolExists(const quint32 &id)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
VPiecePath VAbstractPattern::ParsePathNodes(const QDomElement &domElement)
{
VPiecePath path;
const QDomNodeList nodeList = domElement.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
{
const QDomElement element = nodeList.at(i).toElement();
if (not element.isNull() && element.tagName() == VAbstractPattern::TagNode)
{
path.Append(ParseSANode(element));
}
}
return path;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief SetActivPP set current pattern piece. * @brief SetActivPP set current pattern piece.
@ -1550,12 +1568,16 @@ QStringList VAbstractPattern::ListExpressions() const
QStringList list; QStringList list;
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
// Note. Tool Union Details also contains formulas, but we don't use them for union and keep only to simplifying
// working with nodes. Same code for saving reading.
list << ListPointExpressions(); list << ListPointExpressions();
list << ListArcExpressions(); list << ListArcExpressions();
list << ListElArcExpressions(); list << ListElArcExpressions();
list << ListSplineExpressions(); list << ListSplineExpressions();
list << ListIncrementExpressions(); list << ListIncrementExpressions();
list << ListOperationExpressions(); list << ListOperationExpressions();
list << ListPathExpressions();
list << ListPieceExpressions();
return list; return list;
} }
@ -1861,6 +1883,112 @@ QStringList VAbstractPattern::ListOperationExpressions() const
return expressions; return expressions;
} }
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListNodesExpressions(const QDomElement &nodes) const
{
QStringList expressions;
VPiecePath path;
if (not nodes.isNull())
{
path = ParsePathNodes(nodes);
}
for(int i = 0; i < path.CountNodes(); ++i)
{
expressions.append(path.at(i).GetFormulaSABefore());
expressions.append(path.at(i).GetFormulaSAAfter());
}
return expressions;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListPathExpressions() const
{
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 51);
QStringList expressions;
const QDomNodeList list = elementsByTagName(TagPath);
for (int i=0; i < list.size(); ++i)
{
const QDomElement dom = list.at(i).toElement();
if (dom.isNull())
{
continue;
}
expressions << ListNodesExpressions(dom.firstChildElement(TagNodes));
}
return expressions;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListGrainlineExpressions(const QDomElement &element) const
{
QStringList expressions;
if (not element.isNull())
{
// Each tag can contains several attributes.
try
{
expressions.append(GetParametrString(element, AttrRotation));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
try
{
expressions.append(GetParametrString(element, AttrLength));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
}
return expressions;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListPieceExpressions() const
{
// Check if new tool doesn't bring new attribute with a formula.
// If no just increment number.
// If new tool bring absolutely new type and has formula(s) create new method to cover it.
Q_STATIC_ASSERT(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 51);
QStringList expressions;
const QDomNodeList list = elementsByTagName(TagDetail);
for (int i=0; i < list.size(); ++i)
{
const QDomElement dom = list.at(i).toElement();
if (dom.isNull())
{
continue;
}
// Each tag can contains several attributes.
try
{
expressions.append(GetParametrString(dom, AttrWidth));
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
}
expressions << ListNodesExpressions(dom.firstChildElement(TagNodes));
expressions << ListGrainlineExpressions(dom.firstChildElement(TagGrainline));
}
return expressions;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VAbstractPattern::IsVariable(const QString &token) const bool VAbstractPattern::IsVariable(const QString &token) const
{ {

View File

@ -222,6 +222,8 @@ public:
static const QString AttrPath; static const QString AttrPath;
static const QString AttrEnd; static const QString AttrEnd;
static const QString AttrIncludeAs; static const QString AttrIncludeAs;
static const QString AttrWidth;
static const QString AttrRotation;
static const QString AttrAll; static const QString AttrAll;
@ -356,6 +358,7 @@ protected:
static QHash<quint32, VDataTool*> tools; static QHash<quint32, VDataTool*> tools;
static void ToolExists(const quint32 &id); static void ToolExists(const quint32 &id);
static VPiecePath ParsePathNodes(const QDomElement &domElement);
static VPieceNode ParseSANode(const QDomElement &domElement); static VPieceNode ParseSANode(const QDomElement &domElement);
void SetActivPP(const QString& name); void SetActivPP(const QString& name);
@ -379,6 +382,10 @@ private:
QStringList ListPathPointExpressions() const; QStringList ListPathPointExpressions() const;
QStringList ListIncrementExpressions() const; QStringList ListIncrementExpressions() const;
QStringList ListOperationExpressions() const; QStringList ListOperationExpressions() const;
QStringList ListNodesExpressions(const QDomElement &nodes) const;
QStringList ListPathExpressions() const;
QStringList ListGrainlineExpressions(const QDomElement &element) const;
QStringList ListPieceExpressions() const;
bool IsVariable(const QString& token) const; bool IsVariable(const QString& token) const;
bool IsPostfixOperator(const QString& token) const; bool IsPostfixOperator(const QString& token) const;

View File

@ -71,11 +71,9 @@ const QString VToolSeamAllowance::TagIPaths = QStringLiteral("iPaths");
const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version"); const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version");
const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping"); const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping");
const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance"); const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance");
const QString VToolSeamAllowance::AttrWidth = QStringLiteral("width");
const QString VToolSeamAllowance::AttrHeight = QStringLiteral("height"); const QString VToolSeamAllowance::AttrHeight = QStringLiteral("height");
const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united"); const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united");
const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize"); const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize");
const QString VToolSeamAllowance::AttrRotation = QStringLiteral("rotation");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VToolSeamAllowance::~VToolSeamAllowance() VToolSeamAllowance::~VToolSeamAllowance()
@ -173,7 +171,7 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl
doc->SetAttribute(domElement, AttrInLayout, piece.IsInLayout()); doc->SetAttribute(domElement, AttrInLayout, piece.IsInLayout());
doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping()); doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping());
doc->SetAttribute(domElement, AttrSeamAllowance, piece.IsSeamAllowance()); doc->SetAttribute(domElement, AttrSeamAllowance, piece.IsSeamAllowance());
doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth()); doc->SetAttribute(domElement, VAbstractPattern::AttrWidth, piece.GetFormulaSAWidth());
doc->SetAttribute(domElement, AttrUnited, piece.IsUnited()); doc->SetAttribute(domElement, AttrUnited, piece.IsUnited());
} }
@ -231,10 +229,10 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr);
doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMx, data.GetPos().x());
doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrMy, data.GetPos().y());
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); doc->SetAttribute(domData, VAbstractPattern::AttrWidth, data.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttribute(domData, AttrFont, data.GetFontSize());
doc->SetAttribute(domData, AttrRotation, data.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
for (int i = 0; i < data.GetMCPCount(); ++i) for (int i = 0; i < data.GetMCPCount(); ++i)
{ {
@ -260,10 +258,10 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE
doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true ? trueStr : falseStr); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true ? trueStr : falseStr);
doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMx, geom.GetPos().x());
doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y());
doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); doc->SetAttribute(domData, VAbstractPattern::AttrWidth, geom.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight()); doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, AttrFont, geom.GetFontSize());
doc->SetAttribute(domData, AttrRotation, geom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation());
domElement.appendChild(domData); domElement.appendChild(domData);
} }
@ -277,7 +275,7 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x());
doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y());
doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); doc->SetAttribute(domData, AttrLength, glGeom.GetLength());
doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation());
doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType())); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType()));
domElement.appendChild(domData); domElement.appendChild(domData);
} }

View File

@ -64,11 +64,9 @@ public:
static const QString AttrVersion; static const QString AttrVersion;
static const QString AttrForbidFlipping; static const QString AttrForbidFlipping;
static const QString AttrSeamAllowance; static const QString AttrSeamAllowance;
static const QString AttrWidth;
static const QString AttrHeight; static const QString AttrHeight;
static const QString AttrUnited; static const QString AttrUnited;
static const QString AttrFont; static const QString AttrFont;
static const QString AttrRotation;
void Remove(bool ask); void Remove(bool ask);