Move methods to class VAbstractPattern to be able to use them for tool Unite
Details. --HG-- branch : feature
This commit is contained in:
parent
4cc232fc74
commit
5442eb40b9
|
@ -562,53 +562,6 @@ VNodeDetail VPattern::ParseDetailNode(const QDomElement &domElement) const
|
||||||
return VNodeDetail(id, tool, nodeType, mx, my, reverse);
|
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.
|
* @brief ParseDrawElement parse draw tag.
|
||||||
|
@ -782,7 +735,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ParsePieceNodes(element, detail);
|
detail.SetPath(ParsePieceNodes(element));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:// TagData
|
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));
|
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
|
void VPattern::ParsePieceCSARecords(const QDomElement &domElement, VPiece &detail) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -115,13 +115,11 @@ private:
|
||||||
VMainGraphicsScene *sceneDetail;
|
VMainGraphicsScene *sceneDetail;
|
||||||
|
|
||||||
VNodeDetail ParseDetailNode(const QDomElement &domElement) const;
|
VNodeDetail ParseDetailNode(const QDomElement &domElement) const;
|
||||||
VPieceNode ParseSANode(const QDomElement &domElement) const;
|
|
||||||
|
|
||||||
void ParseDrawElement(const QDomNode& node, const Document &parse);
|
void ParseDrawElement(const QDomNode& node, const Document &parse);
|
||||||
void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode);
|
void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode);
|
||||||
void ParseDetailElement(const QDomElement &domElement, const Document &parse);
|
void ParseDetailElement(const QDomElement &domElement, const Document &parse);
|
||||||
void ParseDetailNodes(const QDomElement &domElement, VPiece &detail, bool closed) const;
|
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 ParsePieceCSARecords(const QDomElement &domElement, VPiece &detail) const;
|
||||||
void ParsePieceInternalPaths(const QDomElement &domElement, VPiece &detail) const;
|
void ParsePieceInternalPaths(const QDomElement &domElement, VPiece &detail) const;
|
||||||
void ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const;
|
void ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const;
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "../ifc/exception/vexceptionbadid.h"
|
#include "../ifc/exception/vexceptionbadid.h"
|
||||||
#include "../ifc/ifcdef.h"
|
#include "../ifc/ifcdef.h"
|
||||||
#include "../vpatterndb/vcontainer.h"
|
#include "../vpatterndb/vcontainer.h"
|
||||||
|
#include "../vpatterndb/vpiecenode.h"
|
||||||
#include "../vtools/tools/vdatatool.h"
|
#include "../vtools/tools/vdatatool.h"
|
||||||
#include "vpatternconverter.h"
|
#include "vpatternconverter.h"
|
||||||
#include "vdomdocument.h"
|
#include "vdomdocument.h"
|
||||||
|
@ -555,7 +556,70 @@ void VAbstractPattern::AddTool(const quint32 &id, VDataTool *tool)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(id != 0, Q_FUNC_INFO, "id == 0");
|
Q_ASSERT_X(id != 0, Q_FUNC_INFO, "id == 0");
|
||||||
SCASSERT(tool != nullptr)
|
SCASSERT(tool != nullptr)
|
||||||
tools.insert(id, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -45,6 +45,8 @@
|
||||||
#include "vtoolrecord.h"
|
#include "vtoolrecord.h"
|
||||||
|
|
||||||
class QDomElement;
|
class QDomElement;
|
||||||
|
class VPiecePath;
|
||||||
|
class VPieceNode;
|
||||||
|
|
||||||
enum class Document : char { LiteParse, LitePPParse, FullParse };
|
enum class Document : char { LiteParse, LitePPParse, FullParse };
|
||||||
enum class LabelType : char {NewPatternPiece, NewLabel};
|
enum class LabelType : char {NewPatternPiece, NewLabel};
|
||||||
|
@ -93,6 +95,8 @@ public:
|
||||||
static VDataTool* getTool(const quint32 &id);
|
static VDataTool* getTool(const quint32 &id);
|
||||||
static void AddTool(const quint32 &id, VDataTool *tool);
|
static void AddTool(const quint32 &id, VDataTool *tool);
|
||||||
|
|
||||||
|
static VPiecePath ParsePieceNodes(const QDomElement &domElement);
|
||||||
|
|
||||||
void AddToolOnRemove(VDataTool *tool);
|
void AddToolOnRemove(VDataTool *tool);
|
||||||
|
|
||||||
QVector<VToolRecord> *getHistory();
|
QVector<VToolRecord> *getHistory();
|
||||||
|
@ -344,7 +348,8 @@ protected:
|
||||||
/** @brief tools list with pointer on tools. */
|
/** @brief tools list with pointer on tools. */
|
||||||
static QHash<quint32, VDataTool*> tools;
|
static QHash<quint32, VDataTool*> tools;
|
||||||
|
|
||||||
static void ToolExists(const quint32 &id);
|
static void ToolExists(const quint32 &id);
|
||||||
|
static VPieceNode ParseSANode(const QDomElement &domElement);
|
||||||
|
|
||||||
void SetActivPP(const QString& name);
|
void SetActivPP(const QString& name);
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ bool VDomDocument::find(const QDomElement &node, const QString& id)
|
||||||
* @param name attribute name
|
* @param name attribute name
|
||||||
* @return long long value
|
* @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 name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
|
||||||
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); //-V591
|
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;
|
QString parametr;
|
||||||
quint32 id = 0;
|
quint32 id = 0;
|
||||||
|
|
||||||
QString message = tr("Can't convert toUInt parameter");
|
const QString message = QObject::tr("Can't convert toUInt parameter");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parametr = GetParametrString(domElement, name, defValue);
|
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 name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
|
||||||
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
|
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;
|
QString parametr;
|
||||||
bool val = true;
|
bool val = true;
|
||||||
|
|
||||||
QString message = tr("Can't convert toBool parameter");
|
const QString message = QObject::tr("Can't convert toBool parameter");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parametr = GetParametrString(domElement, name, defValue);
|
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);
|
const bool value = GetParametrBool(domElement, name, trueStr);
|
||||||
if (value)
|
if (value)
|
||||||
|
@ -315,7 +315,7 @@ void VDomDocument::SetParametrUsage(QDomElement &domElement, const QString &name
|
||||||
* @throw VExceptionEmptyParameter when attribute is empty
|
* @throw VExceptionEmptyParameter when attribute is empty
|
||||||
*/
|
*/
|
||||||
QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name,
|
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 name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
|
||||||
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
|
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())
|
if (defValue.isEmpty())
|
||||||
{
|
{
|
||||||
throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement);
|
throw VExceptionEmptyParameter(QObject::tr("Got empty parameter"), name, domElement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -341,7 +341,7 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt
|
||||||
* @param name attribute name
|
* @param name attribute name
|
||||||
* @return double value
|
* @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 name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
|
||||||
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
|
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;
|
bool ok = false;
|
||||||
qreal param = 0;
|
qreal param = 0;
|
||||||
|
|
||||||
QString message = tr("Can't convert toDouble parameter");
|
const QString message = QObject::tr("Can't convert toDouble parameter");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QString parametr = GetParametrString(domElement, name, defValue);
|
QString parametr = GetParametrString(domElement, name, defValue);
|
||||||
|
@ -374,13 +374,13 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
|
||||||
* @param domElement tag in xml tree.
|
* @param domElement tag in xml tree.
|
||||||
* @return id value.
|
* @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");
|
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
|
||||||
|
|
||||||
quint32 id = NULL_ID;
|
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
|
try
|
||||||
{
|
{
|
||||||
id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR);
|
id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR);
|
||||||
|
|
|
@ -96,16 +96,16 @@ public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
|
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
|
||||||
|
|
||||||
quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const;
|
static quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue);
|
||||||
bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const;
|
static bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue);
|
||||||
|
|
||||||
NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name) const;
|
static NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name);
|
||||||
void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value);
|
static void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value);
|
||||||
|
|
||||||
QString GetParametrString(const QDomElement& domElement, const QString &name,
|
static QString GetParametrString(const QDomElement& domElement, const QString &name,
|
||||||
const QString &defValue = QString()) const;
|
const QString &defValue = QString());
|
||||||
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
|
static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue);
|
||||||
quint32 GetParametrId(const QDomElement& domElement) const;
|
static quint32 GetParametrId(const QDomElement& domElement);
|
||||||
|
|
||||||
static void ValidateXML(const QString &schema, const QString &fileName);
|
static void ValidateXML(const QString &schema, const QString &fileName);
|
||||||
virtual void setXMLContent(const QString &fileName);
|
virtual void setXMLContent(const QString &fileName);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user