New class VToolPiecePath.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-24 21:35:54 +02:00
parent 0e78efc714
commit 39b27e4b24
7 changed files with 464 additions and 3 deletions

View File

@ -586,7 +586,13 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
{ {
scene = sceneDetail; 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 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)
@ -620,6 +626,10 @@ void VPattern::ParseDrawMode(const QDomNode &node, const Document &parse, const
qCDebug(vXML, "Tag operation."); qCDebug(vXML, "Tag operation.");
ParseOperationElement(scene, domElement, parse, domElement.attribute(AttrType, "")); ParseOperationElement(scene, domElement, parse, domElement.attribute(AttrType, ""));
break; break;
case 6: // TagPath
qCDebug(vXML, "Tag path.");
ParsePathElement(scene, domElement, parse);
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;
@ -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<int>(PiecePathType::CustomSeamAllowance));
const PiecePathType type = static_cast<PiecePathType>(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. * @brief ParseIncrementsElement parse increments tag.

View File

@ -132,6 +132,10 @@ private:
const Document &parse, const QString& type); const Document &parse, const QString& type);
void ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse, void ParseOperationElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse,
const QString& type); 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 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);

View File

@ -307,6 +307,29 @@
<xs:attribute name="inUse" type="xs:boolean"></xs:attribute> <xs:attribute name="inUse" type="xs:boolean"></xs:attribute>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="path" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nodes" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="node" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="type" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="reverse" type="xs:unsignedInt"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="type" type="piecePathType"></xs:attribute>
<xs:attribute name="idTool" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="inUse" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="tools" minOccurs="0" maxOccurs="unbounded"> <xs:element name="tools" minOccurs="0" maxOccurs="unbounded">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
@ -650,4 +673,10 @@
<xs:enumeration value="5"/><!--by first edge right angle--> <xs:enumeration value="5"/><!--by first edge right angle-->
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="piecePathType">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="1"/><!--custom seam allowance-->
<xs:enumeration value="2"/><!--internal path-->
</xs:restriction>
</xs:simpleType>
</xs:schema> </xs:schema>

View File

@ -33,5 +33,6 @@
#include "vnodepoint.h" #include "vnodepoint.h"
#include "vnodespline.h" #include "vnodespline.h"
#include "vnodesplinepath.h" #include "vnodesplinepath.h"
#include "vtoolpiecepath.h"
#endif // NODEDETAILS_H #endif // NODEDETAILS_H

View File

@ -0,0 +1,264 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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<DialogPiecePath*>(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<quint8>(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."<<Q_FUNC_INFO;
break;
}
domElement.appendChild(nod);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolPiecePath::AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path)
{
if (path.CountNodes() > 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<int>(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);
}
}

View File

@ -0,0 +1,76 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VTOOLPIECEPATH_H
#define VTOOLPIECEPATH_H
#include <QtGlobal>
#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<int>(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

View File

@ -58,7 +58,8 @@ HEADERS += \
$$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \
$$PWD/drawTools/operation/flipping/vabstractflipping.h \ $$PWD/drawTools/operation/flipping/vabstractflipping.h \
$$PWD/drawTools/operation/vtoolmove.h \ $$PWD/drawTools/operation/vtoolmove.h \
$$PWD/vtoolseamallowance.h $$PWD/vtoolseamallowance.h \
$$PWD/nodeDetails/vtoolpiecepath.h
SOURCES += \ SOURCES += \
$$PWD/vtooldetail.cpp \ $$PWD/vtooldetail.cpp \
@ -114,4 +115,5 @@ SOURCES += \
$$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \
$$PWD/drawTools/operation/flipping/vabstractflipping.cpp \ $$PWD/drawTools/operation/flipping/vabstractflipping.cpp \
$$PWD/drawTools/operation/vtoolmove.cpp \ $$PWD/drawTools/operation/vtoolmove.cpp \
$$PWD/vtoolseamallowance.cpp $$PWD/vtoolseamallowance.cpp \
$$PWD/nodeDetails/vtoolpiecepath.cpp