Seamly2D
Code documentation
vnodearc.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vnodearc.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "vnodearc.h"
53 
54 #include <QDomElement>
55 #include <QStaticStringData>
56 #include <QStringData>
57 #include <QStringDataPtr>
58 
59 #include "../ifc/xml/vdomdocument.h"
60 #include "../ifc/ifcdef.h"
61 #include "../vabstracttool.h"
62 #include "../vdatatool.h"
63 #include "vabstractnode.h"
64 
65 const QString VNodeArc::ToolType = QStringLiteral("modeling");
66 
67 //---------------------------------------------------------------------------------------------------------------------
68 /**
69  * @brief VNodeArc constructor.
70  * @param doc dom document container.
71  * @param data container with variables.
72  * @param id object id in container.
73  * @param idArc object id in containerArc.
74  * @param typeCreation way we create this tool.
75  * @param idTool tool id.
76  * @param qoParent QObject parent
77  */
78 VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
79  const QString &blockName, const quint32 &idTool, QObject *qoParent)
80  :VAbstractNode(doc, data, id, idArc, blockName, idTool, qoParent)
81 {
82  ToolCreation(typeCreation);
83 }
84 
85 //---------------------------------------------------------------------------------------------------------------------
86 /**
87  * @brief Create help create tool.
88  * @param doc dom document container.
89  * @param data container with variables.
90  * @param id object id in container.
91  * @param idArc object id in containerArc.
92  * @param parse parser file mode.
93  * @param typeCreation way we create this tool.
94  * @param idTool tool id.
95  */
96 void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc,
97  const Document &parse, const Source &typeCreation, const QString &blockName, const quint32 &idTool)
98 {
99  if (parse == Document::FullParse)
100  {
102  VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, blockName, idTool, doc);
103 
104  VAbstractPattern::AddTool(id, arc);
105  if (idTool != NULL_ID)
106  {
107  //Some nodes we don't show on scene. Tool that create this nodes must free memory.
109  SCASSERT(tool != nullptr)
110  arc->setParent(tool);// Adopted by a tool
111  }
112  else
113  {
114  // Help to delete the node before each FullParse
115  doc->AddToolOnRemove(arc);
116  }
117  }
118  else
119  {
120  doc->UpdateToolData(id, data);
121  }
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
125 QString VNodeArc::getTagName() const
126 {
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
131 void VNodeArc::AllowHover(bool enabled)
132 {
133  Q_UNUSED(enabled)
134  // do nothing
135 }
136 
137 //---------------------------------------------------------------------------------------------------------------------
138 void VNodeArc::AllowSelecting(bool enabled)
139 {
140  Q_UNUSED(enabled)
141  // do nothing
142 }
143 
144 //---------------------------------------------------------------------------------------------------------------------
145 /**
146  * @brief AddToFile add tag with Information about tool into file.
147  */
149 {
150  QDomElement domElement = doc->createElement(getTagName());
151 
152  doc->SetAttribute(domElement, VDomDocument::AttrId, m_id);
153  doc->SetAttribute(domElement, AttrType, ToolType);
154  doc->SetAttribute(domElement, AttrIdObject, idNode);
155  if (idTool != NULL_ID)
156  {
157  doc->SetAttribute(domElement, AttrIdTool, idTool);
158  }
159 
160  AddToModeling(domElement);
161 }
The VAbstractNode class parent class for all detail node.
Definition: vabstractnode.h:71
static const QString AttrIdTool
Definition: vabstractnode.h:77
quint32 idTool
idTool id tool.
Definition: vabstractnode.h:97
quint32 idNode
idNodenode id.
Definition: vabstractnode.h:94
virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE
void AddToModeling(const QDomElement &domElement)
AddToModeling add tag to modeling tag current pattern peace.
void AddToolOnRemove(VDataTool *tool)
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0
static const QString TagArc
static void AddTool(quint32 id, VDataTool *tool)
AddTool add tool to list tools.
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
VAbstractPattern * doc
doc dom document container
static void AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
AddRecord add record about tool in history.
const quint32 m_id
id object id.
The VContainer class container of all variables.
Definition: vcontainer.h:141
The VDataTool class need for getting access to data container of tool.
Definition: vdatatool.h:71
VContainer data
data container with data
Definition: vdatatool.h:84
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
static const QString AttrId
Definition: vdomdocument.h:108
The VNodeArc class arc detail node.
Definition: vnodearc.h:70
virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE
Definition: vnodearc.cpp:138
VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, const QString &blockName=QString(), const quint32 &idTool=0, QObject *qoParent=nullptr)
VNodeArc constructor.
Definition: vnodearc.cpp:78
static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse, const Source &typeCreation, const QString &blockName=QString(), const quint32 &idTool=0)
Create help create tool.
Definition: vnodearc.cpp:96
virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE
Definition: vnodearc.cpp:131
static const QString ToolType
Definition: vnodearc.h:76
virtual QString getTagName() const Q_DECL_OVERRIDE
Definition: vnodearc.cpp:125
virtual void AddToFile() Q_DECL_OVERRIDE
AddToFile add tag with Information about tool into file.
Definition: vnodearc.cpp:148
#define SCASSERT(cond)
Definition: def.h:317
@ NodeArc
Source
Definition: def.h:106
const QString AttrType
Definition: ifcdef.cpp:73
const QString AttrIdObject
Definition: ifcdef.cpp:148
#define NULL_ID
Definition: ifcdef.h:76
Document