Move methods to class VAbstractPattern to be able to use them for tool Unite

Details.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-16 11:59:02 +02:00
parent 4cc232fc74
commit 5442eb40b9
6 changed files with 91 additions and 85 deletions

View File

@ -562,53 +562,6 @@ VNodeDetail VPattern::ParseDetailNode(const QDomElement &domElement) const
return VNodeDetail(id, tool, nodeType, mx, my, reverse);
}
//---------------------------------------------------------------------------------------------------------------------
VPieceNode VPattern::ParseSANode(const QDomElement &domElement) const
{
const quint32 id = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR);
const bool reverse = GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0");
const qreal saBefore = GetParametrDouble(domElement, VAbstractPattern::AttrSABefore, "-1");
const qreal saAfter = GetParametrDouble(domElement, VAbstractPattern::AttrSAAfter, "-1");
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(GetParametrUInt(domElement, AttrAngle, "0"));
const QString t = GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint);
Tool tool;
const QStringList types = QStringList() << VAbstractPattern::NodePoint
<< VAbstractPattern::NodeArc
<< VAbstractPattern::NodeSpline
<< VAbstractPattern::NodeSplinePath
<< VAbstractPattern::NodeElArc;
switch (types.indexOf(t))
{
case 0: // VAbstractPattern::NodePoint
tool = Tool::NodePoint;
break;
case 1: // VAbstractPattern::NodeArc
tool = Tool::NodeArc;
break;
case 2: // VAbstractPattern::NodeSpline
tool = Tool::NodeSpline;
break;
case 3: // VAbstractPattern::NodeSplinePath
tool = Tool::NodeSplinePath;
break;
case 4: // NodeElArc
tool = Tool::NodeElArc;
break;
default:
VException e(tr("Wrong tag name '%1'.").arg(t));
throw e;
}
VPieceNode node(id, tool, reverse);
node.SetSABefore(saBefore);
node.SetSAAfter(saAfter);
node.SetAngleType(angle);
return node;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ParseDrawElement parse draw tag.
@ -782,7 +735,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
}
else
{
ParsePieceNodes(element, detail);
detail.SetPath(ParsePieceNodes(element));
}
break;
case 1:// TagData
@ -832,20 +785,6 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, b
detail.GetPath().SetNodes(VNodeDetail::Convert(data, oldNodes, detail.GetSAWidth(), closed));
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParsePieceNodes(const QDomElement &domElement, VPiece &detail) 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())
{
detail.GetPath().Append(ParseSANode(element));
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParsePieceCSARecords(const QDomElement &domElement, VPiece &detail) const
{

View File

@ -115,13 +115,11 @@ private:
VMainGraphicsScene *sceneDetail;
VNodeDetail ParseDetailNode(const QDomElement &domElement) const;
VPieceNode ParseSANode(const QDomElement &domElement) const;
void ParseDrawElement(const QDomNode& node, const Document &parse);
void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode);
void ParseDetailElement(const QDomElement &domElement, const Document &parse);
void ParseDetailNodes(const QDomElement &domElement, VPiece &detail, bool closed) const;
void ParsePieceNodes(const QDomElement &domElement, VPiece &detail) const;
void ParsePieceCSARecords(const QDomElement &domElement, VPiece &detail) const;
void ParsePieceInternalPaths(const QDomElement &domElement, VPiece &detail) const;
void ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const;

View File

@ -45,6 +45,7 @@
#include "../ifc/exception/vexceptionbadid.h"
#include "../ifc/ifcdef.h"
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vpiecenode.h"
#include "../vtools/tools/vdatatool.h"
#include "vpatternconverter.h"
#include "vdomdocument.h"
@ -558,6 +559,69 @@ void VAbstractPattern::AddTool(const quint32 &id, VDataTool *tool)
tools.insert(id, tool);
}
//---------------------------------------------------------------------------------------------------------------------
VPiecePath VAbstractPattern::ParsePieceNodes(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())
{
path.Append(ParseSANode(element));
}
}
return path;
}
//---------------------------------------------------------------------------------------------------------------------
VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement)
{
const quint32 id = VDomDocument::GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR);
const bool reverse = VDomDocument::GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0");
const qreal saBefore = VDomDocument::GetParametrDouble(domElement, VAbstractPattern::AttrSABefore, "-1");
const qreal saAfter = VDomDocument::GetParametrDouble(domElement, VAbstractPattern::AttrSAAfter, "-1");
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(VDomDocument::GetParametrUInt(domElement, AttrAngle, "0"));
const QString t = VDomDocument::GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint);
Tool tool;
const QStringList types = QStringList() << VAbstractPattern::NodePoint
<< VAbstractPattern::NodeArc
<< VAbstractPattern::NodeSpline
<< VAbstractPattern::NodeSplinePath
<< VAbstractPattern::NodeElArc;
switch (types.indexOf(t))
{
case 0: // VAbstractPattern::NodePoint
tool = Tool::NodePoint;
break;
case 1: // VAbstractPattern::NodeArc
tool = Tool::NodeArc;
break;
case 2: // VAbstractPattern::NodeSpline
tool = Tool::NodeSpline;
break;
case 3: // VAbstractPattern::NodeSplinePath
tool = Tool::NodeSplinePath;
break;
case 4: // NodeElArc
tool = Tool::NodeElArc;
break;
default:
VException e(QObject::tr("Wrong tag name '%1'.").arg(t));
throw e;
}
VPieceNode node(id, tool, reverse);
node.SetSABefore(saBefore);
node.SetSAAfter(saAfter);
node.SetAngleType(angle);
return node;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::AddToolOnRemove(VDataTool *tool)
{

View File

@ -45,6 +45,8 @@
#include "vtoolrecord.h"
class QDomElement;
class VPiecePath;
class VPieceNode;
enum class Document : char { LiteParse, LitePPParse, FullParse };
enum class LabelType : char {NewPatternPiece, NewLabel};
@ -93,6 +95,8 @@ public:
static VDataTool* getTool(const quint32 &id);
static void AddTool(const quint32 &id, VDataTool *tool);
static VPiecePath ParsePieceNodes(const QDomElement &domElement);
void AddToolOnRemove(VDataTool *tool);
QVector<VToolRecord> *getHistory();
@ -345,6 +349,7 @@ protected:
static QHash<quint32, VDataTool*> tools;
static void ToolExists(const quint32 &id);
static VPieceNode ParseSANode(const QDomElement &domElement);
void SetActivPP(const QString& name);

View File

@ -203,7 +203,7 @@ bool VDomDocument::find(const QDomElement &node, const QString& id)
* @param name attribute name
* @return long long value
*/
quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue) const
quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue)
{
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); //-V591
@ -212,7 +212,7 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri
QString parametr;
quint32 id = 0;
QString message = tr("Can't convert toUInt parameter");
const QString message = QObject::tr("Can't convert toUInt parameter");
try
{
parametr = GetParametrString(domElement, name, defValue);
@ -233,7 +233,7 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri
}
//---------------------------------------------------------------------------------------------------------------------
bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue) const
bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue)
{
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
@ -241,7 +241,7 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString
QString parametr;
bool val = true;
QString message = tr("Can't convert toBool parameter");
const QString message = QObject::tr("Can't convert toBool parameter");
try
{
parametr = GetParametrString(domElement, name, defValue);
@ -280,7 +280,7 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString
}
//---------------------------------------------------------------------------------------------------------------------
NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name) const
NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name)
{
const bool value = GetParametrBool(domElement, name, trueStr);
if (value)
@ -315,7 +315,7 @@ void VDomDocument::SetParametrUsage(QDomElement &domElement, const QString &name
* @throw VExceptionEmptyParameter when attribute is empty
*/
QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name,
const QString &defValue) const
const QString &defValue)
{
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
@ -324,7 +324,7 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt
{
if (defValue.isEmpty())
{
throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement);
throw VExceptionEmptyParameter(QObject::tr("Got empty parameter"), name, domElement);
}
else
{
@ -341,7 +341,7 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt
* @param name attribute name
* @return double value
*/
qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue) const
qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue)
{
Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
@ -349,7 +349,7 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
bool ok = false;
qreal param = 0;
QString message = tr("Can't convert toDouble parameter");
const QString message = QObject::tr("Can't convert toDouble parameter");
try
{
QString parametr = GetParametrString(domElement, name, defValue);
@ -374,13 +374,13 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
* @param domElement tag in xml tree.
* @return id value.
*/
quint32 VDomDocument::GetParametrId(const QDomElement &domElement) const
quint32 VDomDocument::GetParametrId(const QDomElement &domElement)
{
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
quint32 id = NULL_ID;
const QString message = tr("Got wrong parameter id. Need only id > 0.");
const QString message = QObject::tr("Got wrong parameter id. Need only id > 0.");
try
{
id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR);

View File

@ -96,16 +96,16 @@ public:
template <typename T>
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const;
bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const;
static quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue);
static bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue);
NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name) const;
void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value);
static NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name);
static void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value);
QString GetParametrString(const QDomElement& domElement, const QString &name,
const QString &defValue = QString()) const;
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
quint32 GetParametrId(const QDomElement& domElement) const;
static QString GetParametrString(const QDomElement& domElement, const QString &name,
const QString &defValue = QString());
static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue);
static quint32 GetParametrId(const QDomElement& domElement);
static void ValidateXML(const QString &schema, const QString &fileName);
virtual void setXMLContent(const QString &fileName);