Parse the tool in a file.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-05-16 20:27:51 +03:00
parent 02eb12ba3e
commit 7dbba35919
10 changed files with 131 additions and 13 deletions

View File

@ -527,7 +527,7 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
{ {
scene = sceneDetail; scene = sceneDetail;
} }
QStringList tags = QStringList() << TagPoint << TagLine << TagSpline << TagArc << TagTools; const QStringList tags = QStringList() << TagPoint << TagLine << TagSpline << TagArc << TagTools << TagOperation;
const QDomNodeList nodeList = node.childNodes(); const QDomNodeList nodeList = node.childNodes();
const qint32 num = nodeList.size(); const qint32 num = nodeList.size();
for (qint32 i = 0; i < num; ++i) for (qint32 i = 0; i < num; ++i)
@ -557,6 +557,10 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
qCDebug(vXML, "Tag tools."); qCDebug(vXML, "Tag tools.");
ParseToolsElement(scene, domElement, parse, domElement.attribute(AttrType, "")); ParseToolsElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break; break;
case 5: // TagOperation
qCDebug(vXML, "Tag operation.");
ParseOperationElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break;
default: default:
VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName())); VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName()));
throw e; throw e;
@ -596,7 +600,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
{ {
if (element.tagName() == VToolDetail::TagNode) if (element.tagName() == VToolDetail::TagNode)
{ {
const quint32 id = GetParametrUInt(element, VToolDetail::AttrIdObject, NULL_ID_STR); const quint32 id = GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
const qreal mx = qApp->toPixel(GetParametrDouble(element, AttrMx, "0.0")); const qreal mx = qApp->toPixel(GetParametrDouble(element, AttrMx, "0.0"));
const qreal my = qApp->toPixel(GetParametrDouble(element, AttrMy, "0.0")); const qreal my = qApp->toPixel(GetParametrDouble(element, AttrMy, "0.0"));
const bool reverse = GetParametrUInt(element, VToolDetail::AttrReverse, "0"); const bool reverse = GetParametrUInt(element, VToolDetail::AttrReverse, "0");
@ -2400,6 +2404,49 @@ void VPattern::ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &do
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse)
{
SCASSERT(scene != nullptr);
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
try
{
quint32 id = NULL_ID;
ToolsCommonAttributes(domElement, id);
const quint32 center = GetParametrUInt(domElement, AttrCenter, NULL_ID_STR);
const QString angle = GetParametrString(domElement, AttrAngle, "10");
QString a = angle;//need for saving fixed formula;
const QString suffix = GetParametrString(domElement, AttrSuffix, "");
QVector<quint32> source;
QVector<DestinationItem> destination;
VToolRotation::ExtractData(this, domElement, source, destination);
VToolRotation::Create(id, center, a, suffix, source, destination, scene, this, data, parse, Source::FromFile);
//Rewrite attribute formula. Need for situation when we have wrong formula.
if (a != angle)
{
SetAttribute(domElement, AttrAngle, a);
modified = true;
haveLiteChange();
}
}
catch (const VExceptionBadId &e)
{
VExceptionObjectError excep(tr("Error creating or updating operation of rotation"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
catch (qmu::QmuParserError &e)
{
VExceptionObjectError excep(tr("Error creating or updating operation of rotation"), domElement);
excep.AddMoreInformation(QString("Message: " + e.GetMsg() + "\n"+ "Expression: " + e.GetExpr()));
throw excep;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) const
{ {
@ -2643,6 +2690,27 @@ void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &d
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse,
const QString &type)
{
SCASSERT(scene != nullptr);
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(not type.isEmpty(), Q_FUNC_INFO, "type of operation is empty");
const QStringList opers = QStringList() << VToolRotation::ToolType; /*0*/
switch (opers.indexOf(type))
{
case 0: //VToolRotation::ToolType
ParseToolRotation(scene, domElement, parse);
break;
default:
VException e(tr("Unknown operation type '%1'.").arg(type));
throw e;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ParseIncrementsElement parse increments tag. * @brief ParseIncrementsElement parse increments tag.

View File

@ -125,6 +125,8 @@ private:
const Document &parse, const QString& type); const Document &parse, const QString& type);
void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document &parse, const QString& type); const Document &parse, const QString& type);
void ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse,
const QString& type);
void ParseIncrementsElement(const QDomNode& node); void ParseIncrementsElement(const QDomNode& node);
void PrepareForParse(const Document &parse); void PrepareForParse(const Document &parse);
void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id); void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id);
@ -185,6 +187,8 @@ private:
void ParseNodeArc(const QDomElement &domElement, const Document &parse); void ParseNodeArc(const QDomElement &domElement, const Document &parse);
void ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseToolRotation(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const; qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const;
QDomElement MakeEmptyIncrement(const QString &name); QDomElement MakeEmptyIncrement(const QString &name);

View File

@ -201,6 +201,7 @@
<xs:attribute name="center" type="xs:unsignedInt"></xs:attribute> <xs:attribute name="center" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="angle" type="xs:string"></xs:attribute> <xs:attribute name="angle" type="xs:string"></xs:attribute>
<xs:attribute name="suffix" type="xs:string"></xs:attribute> <xs:attribute name="suffix" type="xs:string"></xs:attribute>
<xs:attribute name="type" type="xs:string" use="required"></xs:attribute>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="arc" minOccurs="0" maxOccurs="unbounded"> <xs:element name="arc" minOccurs="0" maxOccurs="unbounded">

View File

@ -54,6 +54,7 @@ const QString VAbstractPattern::TagLine = QStringLiteral("line");
const QString VAbstractPattern::TagSpline = QStringLiteral("spline"); const QString VAbstractPattern::TagSpline = QStringLiteral("spline");
const QString VAbstractPattern::TagArc = QStringLiteral("arc"); const QString VAbstractPattern::TagArc = QStringLiteral("arc");
const QString VAbstractPattern::TagTools = QStringLiteral("tools"); const QString VAbstractPattern::TagTools = QStringLiteral("tools");
const QString VAbstractPattern::TagOperation = QStringLiteral("operation");
const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); const QString VAbstractPattern::TagGradation = QStringLiteral("gradation");
const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagHeights = QStringLiteral("heights");
const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes");

View File

@ -148,6 +148,7 @@ public:
static const QString TagSpline; static const QString TagSpline;
static const QString TagArc; static const QString TagArc;
static const QString TagTools; static const QString TagTools;
static const QString TagOperation;
static const QString TagGradation; static const QString TagGradation;
static const QString TagHeights; static const QString TagHeights;
static const QString TagSizes; static const QString TagSizes;

View File

@ -40,7 +40,7 @@
#include "../vwidgets/vsimplecurve.h" #include "../vwidgets/vsimplecurve.h"
#include "../../../undocommands/label/rotationmovelabel.h" #include "../../../undocommands/label/rotationmovelabel.h"
const QString VToolRotation::TagName = QStringLiteral("operation"); const QString VToolRotation::ToolType = QStringLiteral("rotation");
const QString VToolRotation::TagItem = QStringLiteral("item"); const QString VToolRotation::TagItem = QStringLiteral("item");
const QString VToolRotation::TagSource = QStringLiteral("source"); const QString VToolRotation::TagSource = QStringLiteral("source");
const QString VToolRotation::TagDestination = QStringLiteral("destination"); const QString VToolRotation::TagDestination = QStringLiteral("destination");
@ -308,13 +308,56 @@ VToolRotation *VToolRotation::Create(const quint32 _id, const quint32 &origin, Q
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolRotation::getTagName() const void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector<quint32> &source,
QVector<DestinationItem> &destination)
{ {
return VToolRotation::TagName; SCASSERT(doc != nullptr)
const QDomNodeList nodeList = domElement.childNodes();
for (qint32 i = 0; i < nodeList.size(); ++i)
{
const QDomElement dataElement = nodeList.at(i).toElement();
if (not dataElement.isNull() && dataElement.tagName() == TagSource)
{
source.clear();
const QDomNodeList srcList = dataElement.childNodes();
for (qint32 j = 0; j < srcList.size(); ++j)
{
const QDomElement element = srcList.at(j).toElement();
if (not element.isNull())
{
source.append(doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR));
}
}
}
if (not dataElement.isNull() && dataElement.tagName() == TagDestination)
{
destination.clear();
const QDomNodeList srcList = dataElement.childNodes();
for (qint32 j = 0; j < srcList.size(); ++j)
{
const QDomElement element = srcList.at(j).toElement();
if (not element.isNull())
{
DestinationItem d;
d.id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
d.mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0"));
d.my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0"));
destination.append(d);
}
}
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolRotation::setEnabled(bool enabled) QString VToolRotation::getTagName() const
{
return VAbstractPattern::TagOperation;
}
//---------------------------------------------------------------------------------------------------------------------
void VToolRotation::SetEnabled(bool enabled)
{ {
this->setEnabled(enabled); this->setEnabled(enabled);
} }
@ -585,7 +628,7 @@ void VToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
void VToolRotation::Disable(bool disable, const QString &namePP) void VToolRotation::Disable(bool disable, const QString &namePP)
{ {
enabled = !CorrectDisable(disable, namePP); enabled = !CorrectDisable(disable, namePP);
setEnabled(enabled); SetEnabled(enabled);
QMapIterator<quint32, VAbstractSimple *> i(rObjects); QMapIterator<quint32, VAbstractSimple *> i(rObjects);
while (i.hasNext()) while (i.hasNext())
@ -661,6 +704,7 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
{ {
VDrawTool::SaveOptions(tag, obj); VDrawTool::SaveOptions(tag, obj);
doc->SetAttribute(tag, AttrType, ToolType);
doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId)); doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId));
doc->SetAttribute(tag, AttrAngle, angle); doc->SetAttribute(tag, AttrAngle, angle);
doc->SetAttribute(tag, AttrSuffix, suffix); doc->SetAttribute(tag, AttrSuffix, suffix);

View File

@ -56,8 +56,9 @@ public:
const QVector<quint32> &source, const QVector<DestinationItem> &destination, const QVector<quint32> &source, const QVector<DestinationItem> &destination,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation); const Document &parse, const Source &typeCreation);
// cppcheck-suppress duplInheritedMember static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector<quint32> &source,
static const QString TagName; QVector<DestinationItem> &destination);
static const QString ToolType;
static const QString TagItem; static const QString TagItem;
static const QString TagSource; static const QString TagSource;
static const QString TagDestination; static const QString TagDestination;
@ -65,7 +66,7 @@ public:
enum { Type = UserType + static_cast<int>(Tool::Rotation)}; enum { Type = UserType + static_cast<int>(Tool::Rotation)};
virtual QString getTagName() const Q_DECL_OVERRIDE; virtual QString getTagName() const Q_DECL_OVERRIDE;
void setEnabled(bool enabled); void SetEnabled(bool enabled);
QString Suffix() const; QString Suffix() const;

View File

@ -54,7 +54,6 @@ const QString VToolDetail::TagNode = QStringLiteral("node");
const QString VToolDetail::AttrSupplement = QStringLiteral("supplement"); const QString VToolDetail::AttrSupplement = QStringLiteral("supplement");
const QString VToolDetail::AttrClosed = QStringLiteral("closed"); const QString VToolDetail::AttrClosed = QStringLiteral("closed");
const QString VToolDetail::AttrWidth = QStringLiteral("width"); const QString VToolDetail::AttrWidth = QStringLiteral("width");
const QString VToolDetail::AttrIdObject = QStringLiteral("idObject");
const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType");
const QString VToolDetail::AttrReverse = QStringLiteral("reverse"); const QString VToolDetail::AttrReverse = QStringLiteral("reverse");

View File

@ -69,7 +69,6 @@ public:
static const QString AttrSupplement; static const QString AttrSupplement;
static const QString AttrClosed; static const QString AttrClosed;
static const QString AttrWidth; static const QString AttrWidth;
static const QString AttrIdObject;
static const QString AttrNodeType; static const QString AttrNodeType;
static const QString AttrReverse; static const QString AttrReverse;
static const QString NodeTypeContour; static const QString NodeTypeContour;

View File

@ -738,7 +738,7 @@ QVector<VDetail> VToolUnionDetails::GetDetailFromFile(VAbstractPattern *doc, con
{ {
if (element.tagName() == VToolUnionDetails::TagNode) if (element.tagName() == VToolUnionDetails::TagNode)
{ {
quint32 id = doc->GetParametrUInt(element, VToolDetail::AttrIdObject, NULL_ID_STR); quint32 id = doc->GetParametrUInt(element, AttrIdObject, NULL_ID_STR);
qreal mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0")); qreal mx = qApp->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0"));
qreal my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0")); qreal my = qApp->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0"));
const bool reversed = doc->GetParametrUInt(element, VToolDetail::AttrReverse, "0"); const bool reversed = doc->GetParametrUInt(element, VToolDetail::AttrReverse, "0");