diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 77962e3ea..c2c9ddf2b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -586,7 +586,13 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const { scene = sceneDetail; } - const QStringList tags = QStringList() << TagPoint << TagLine << TagSpline << TagArc << TagTools << TagOperation; + const QStringList tags = QStringList() << TagPoint + << TagLine + << TagSpline + << TagArc + << TagTools + << TagOperation + << TagPath; const QDomNodeList nodeList = node.childNodes(); const qint32 num = nodeList.size(); for (qint32 i = 0; i < num; ++i) @@ -620,6 +626,10 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const qCDebug(vXML, "Tag operation."); ParseOperationElement(scene, domElement, parse, domElement.attribute(AttrType, "")); break; + case 6: // TagPath + qCDebug(vXML, "Tag path."); + ParsePathElement(scene, domElement, parse); + break; default: VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName())); throw e; @@ -3005,6 +3015,81 @@ void VPattern::ParseOperationElement(VMainGraphicsScene *scene, QDomElement &dom } } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParsePathElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse) +{ + SCASSERT(scene != nullptr); + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + try + { + quint32 id = 0; + ToolsCommonAttributes(domElement, id); + const QString defType = QString().setNum(static_cast(PiecePathType::CustomSeamAllowance)); + const PiecePathType type = static_cast(GetParametrUInt(domElement, AttrType, defType)); + const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + + VPiecePath path; + const QDomElement element = domElement.firstChildElement(VAbstractPattern::TagNodes); + if (not element.isNull()) + { + ParsePathNodes(element, path); + } + + path.SetType(type); + + VToolPiecePath::Create(id, path, 0, scene, this, data, parse, Source::FromFile, "", idTool); + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating a piece path"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ParsePathNodes(const QDomElement &domElement, VPiecePath &path) const +{ + const QStringList types = QStringList() << VAbstractPattern::NodePoint + << VAbstractPattern::NodeArc + << VAbstractPattern::NodeSpline + << VAbstractPattern::NodeSplinePath; + + 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) + { + const quint32 id = GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + const bool reverse = GetParametrUInt(element, VAbstractPattern::AttrNodeReverse, "0"); + + const QString t = GetParametrString(element, AttrType, VAbstractPattern::NodePoint); + Tool tool; + + 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; + default: + VException e(tr("Wrong tag name '%1'.").arg(t)); + throw e; + } + path.Append(VPieceNode(id, tool, reverse)); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseIncrementsElement parse increments tag. diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 0992f1a68..e96387b05 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -132,6 +132,10 @@ private: const Document &parse, const QString& type); void ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse, const QString& type); + + void ParsePathElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); + void ParsePathNodes(const QDomElement &domElement, VPiecePath &path) const; + void ParseIncrementsElement(const QDomNode& node); void PrepareForParse(const Document &parse); void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id); diff --git a/src/libs/ifc/schema/pattern/v0.4.0.xsd b/src/libs/ifc/schema/pattern/v0.4.0.xsd index fb24ee3e9..40b3dc2f5 100644 --- a/src/libs/ifc/schema/pattern/v0.4.0.xsd +++ b/src/libs/ifc/schema/pattern/v0.4.0.xsd @@ -307,6 +307,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -650,4 +673,10 @@ + + + + + + diff --git a/src/libs/vtools/tools/nodeDetails/nodedetails.h b/src/libs/vtools/tools/nodeDetails/nodedetails.h index 497136c6e..3f410f313 100644 --- a/src/libs/vtools/tools/nodeDetails/nodedetails.h +++ b/src/libs/vtools/tools/nodeDetails/nodedetails.h @@ -33,5 +33,6 @@ #include "vnodepoint.h" #include "vnodespline.h" #include "vnodesplinepath.h" +#include "vtoolpiecepath.h" #endif // NODEDETAILS_H diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp new file mode 100644 index 000000000..f3274f560 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -0,0 +1,264 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 24 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtoolpiecepath.h" +#include "../../dialogs/tools/dialogpiecepath.h" +#include "../vpatterndb/vpiecepath.h" +#include "../vpatterndb/vpiecenode.h" +#include "../../undocommands/savepieceoptions.h" + +//--------------------------------------------------------------------------------------------------------------------- +VToolPiecePath *VToolPiecePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogPiecePath *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const VPiecePath path = dialogTool->GetPiecePath(); + const quint32 pieceId = dialogTool->GetPieceId(); + + VToolPiecePath *pathTool = Create(0, path, pieceId, scene, doc, data, Document::FullParse, Source::FromGui); + return pathTool; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPiecePath *VToolPiecePath::Create(quint32 _id, const VPiecePath &path, quint32 pieceId, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation, const QString &drawName, const quint32 &idTool) +{ + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + id = data->AddPiecePath(path); + } + else + { + data->UpdatePiecePath(id, path); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + + VAbstractTool::AddRecord(id, Tool::PiecePath, doc); + if (parse == Document::FullParse) + { + //TODO Need create garbage collector and remove all nodes, that we don't use. + //Better check garbage before each saving file. Check only modeling tags. + VToolPiecePath *pathTool = new VToolPiecePath(doc, data, id, pieceId, typeCreation, drawName, idTool, doc); + + doc->AddTool(id, pathTool); + if (idTool != NULL_ID) + { + //Some nodes we don't show on scene. Tool that create this nodes must free memory. + VDataTool *tool = doc->getTool(idTool); + SCASSERT(tool != nullptr); + pathTool->setParent(tool);// Adopted by a tool + } + else + { + // Try to prevent memory leak + scene->addItem(pathTool);// First adopted by scene + pathTool->hide();// If no one will use node, it will stay hidden + pathTool->SetParentType(ParentType::Scene); + } + return pathTool; + } + else + { + doc->UpdateToolData(id, data); + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPiecePath::getTagName() const +{ + return VAbstractPattern::TagPath; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node) +{ + QDomElement nod = doc->createElement(VAbstractPattern::TagNode); + + doc->SetAttribute(nod, AttrIdObject, node.GetId()); + + const Tool type = node.GetTypeTool(); + if (type != Tool::NodePoint) + { + doc->SetAttribute(nod, VAbstractPattern::AttrNodeReverse, static_cast(node.GetReverse())); + } + + switch (type) + { + case (Tool::NodeArc): + doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeArc); + break; + case (Tool::NodePoint): + doc->SetAttribute(nod, AttrType, VAbstractPattern::NodePoint); + break; + case (Tool::NodeSpline): + doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSpline); + break; + case (Tool::NodeSplinePath): + doc->SetAttribute(nod, AttrType, VAbstractPattern::NodeSplinePath); + break; + default: + qDebug()<<"May be wrong tool type!!! Ignoring."< 0) + { + QDomElement nodesElement = doc->createElement(VAbstractPattern::TagNodes); + for (int i = 0; i < path.CountNodes(); ++i) + { + AddNode(doc, nodesElement, path.at(i)); + } + domElement.appendChild(nodesElement); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::FullUpdateFromFile() +{ + RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::AllowHover(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::AllowSelecting(bool enabled) +{ + Q_UNUSED(enabled) + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + + doc->SetAttribute(domElement, VDomDocument::AttrId, id); + + const VPiecePath path = VAbstractTool::data.GetPiecePath(id); + doc->SetAttribute(domElement, AttrType, static_cast(path.GetType())); + + if (idTool != NULL_ID) + { + doc->SetAttribute(domElement, AttrIdTool, idTool); + } + + AddNodes(doc, domElement, path); + + qApp->getUndoStack()->beginMacro(tr("new path")); + + AddToModeling(domElement); + + VPiece oldDet = VAbstractTool::data.GetPiece(m_pieceId); + VPiece newDet = oldDet; + + if (path.GetType() == PiecePathType::InternalPath) + { + + } + else if (path.GetType() == PiecePathType::CustomSeamAllowance) + { + + } + + SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); + connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(saveCommand); + + qApp->getUndoStack()->endMacro(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + if (idTool != NULL_ID) + { + doc->SetAttribute(domElement, AttrIdTool, idTool); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::ShowNode() +{ + if (parentType != ParentType::Scene) + { + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::HideNode() +{ + hide(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolPiecePath::VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId, + const Source &typeCreation, const QString &drawName, const quint32 &idTool, + QObject *qoParent, QGraphicsItem *parent) + :VAbstractNode(doc, data, id, 0, drawName, idTool, qoParent), + QGraphicsPathItem(parent), + m_pieceId(pieceId) +{ + RefreshGeometry(); + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::RefreshGeometry() +{ + const VPiecePath path = VAbstractTool::data.GetPiecePath(id); + if (path.GetType() == PiecePathType::InternalPath) + { + QPainterPath p = path.PainterPath(this->getData()); + p.setFillRule(Qt::OddEvenFill); + this->setPath(p); + } +} diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h new file mode 100644 index 000000000..c204dac34 --- /dev/null +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h @@ -0,0 +1,76 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 24 11, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLPIECEPATH_H +#define VTOOLPIECEPATH_H + +#include + +#include "vabstractnode.h" + +class DialogTool; + +class VToolPiecePath : public VAbstractNode, public QGraphicsPathItem +{ + Q_OBJECT +public: + static VToolPiecePath* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolPiecePath *Create(quint32 _id, const VPiecePath &path, quint32 pieceId, VMainGraphicsScene *scene, + VAbstractPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation, const QString &drawName = QString(), + const quint32 &idTool = 0); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::PiecePath)}; + virtual QString getTagName() const Q_DECL_OVERRIDE; + + static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node); + static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path); +public slots: + virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; +protected: + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE; + virtual void HideNode() Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VToolPiecePath) + + quint32 m_pieceId; + + VToolPiecePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 pieceId, const Source &typeCreation, + const QString &drawName = QString(), const quint32 &idTool = 0, QObject *qoParent = nullptr, + QGraphicsItem * parent = nullptr ); + + void RefreshGeometry(); +}; + +#endif // VTOOLPIECEPATH_H diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 563ab6573..aa0251e7c 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -58,7 +58,8 @@ HEADERS += \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \ $$PWD/drawTools/operation/flipping/vabstractflipping.h \ $$PWD/drawTools/operation/vtoolmove.h \ - $$PWD/vtoolseamallowance.h + $$PWD/vtoolseamallowance.h \ + $$PWD/nodeDetails/vtoolpiecepath.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -114,4 +115,5 @@ SOURCES += \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \ $$PWD/drawTools/operation/flipping/vabstractflipping.cpp \ $$PWD/drawTools/operation/vtoolmove.cpp \ - $$PWD/vtoolseamallowance.cpp + $$PWD/vtoolseamallowance.cpp \ + $$PWD/nodeDetails/vtoolpiecepath.cpp