Seamly2D
Code documentation
vabstractnode.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 vabstractnode.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 "vabstractnode.h"
53 
54 #include <QSharedPointer>
55 #include <QStaticStringData>
56 #include <QStringData>
57 #include <QStringDataPtr>
58 #include <QUndoStack>
59 #include <Qt>
60 
61 #include "../../undocommands/adddetnode.h"
62 #include "../ifc/ifcdef.h"
63 #include "../ifc/xml/vabstractpattern.h"
64 #include "../vgeometry/vgobject.h"
65 #include "../vmisc/vabstractapplication.h"
66 #include "../vmisc/def.h"
67 #include "../vpatterndb/vcontainer.h"
68 #include "../vabstracttool.h"
69 
70 const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
71 
72 //---------------------------------------------------------------------------------------------------------------------
73 /**
74  * @brief VAbstractNode constructor.
75  * @param doc dom document container.
76  * @param data container with variables.
77  * @param id object id in container.
78  * @param idNode object id in containerNode.
79  * @param idTool id tool.
80  * @param parent parent object.
81  */
82 VAbstractNode::VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode,
83  const QString &blockName, const quint32 &idTool, QObject *parent)
84  : VAbstractTool(doc, data, id, parent)
85  , parentType(ParentType::Item)
86  , idNode(idNode)
87  , idTool(idTool)
88  , m_blockName(blockName)
89  , m_exluded(false)
90 {
91  _referens = 0;
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
96 {
97  Q_UNUSED(show)
98 }
99 
100 //---------------------------------------------------------------------------------------------------------------------
102 {
104  if (_referens == 1)
105  {
106  if (idTool != NULL_ID)
107  {
109  }
110  else
111  {
113  doc->IncrementReferens(node->getIdTool());
114  }
115  ShowNode();
116  QDomElement domElement = doc->elementById(m_id, getTagName());
117  if (domElement.isElement())
118  {
120  }
121  }
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
125 /**
126  * @brief decrementReferens decrement reference for all parent objects.
127  */
129 {
131  if (_referens == 0)
132  {
133  if (idTool != NULL_ID)
134  {
136  }
137  else
138  {
140  doc->DecrementReferens(node->getIdTool());
141  }
142  HideNode();
143  QDomElement domElement = doc->elementById(m_id, getTagName());
144  if (domElement.isElement())
145  {
147  }
148  }
149 }
150 
151 //---------------------------------------------------------------------------------------------------------------------
153 {
154  return parentType;
155 }
156 
157 //---------------------------------------------------------------------------------------------------------------------
159 {
160  parentType = value;
161 }
162 
163 //---------------------------------------------------------------------------------------------------------------------
164 void VAbstractNode::GroupVisibility(quint32 object, bool visible)
165 {
166  Q_UNUSED(object)
167  Q_UNUSED(visible)
168 }
169 
170 //---------------------------------------------------------------------------------------------------------------------
172 {
173  return m_exluded;
174 }
175 
176 //---------------------------------------------------------------------------------------------------------------------
177 void VAbstractNode::SetExluded(bool exluded)
178 {
179  m_exluded = exluded;
180 }
181 
182 //---------------------------------------------------------------------------------------------------------------------
183 void VAbstractNode::ToolCreation(const Source &typeCreation)
184 {
185  if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
186  {
187  AddToFile();
188  }
189  else
190  {
192  }
193 }
194 
195 //---------------------------------------------------------------------------------------------------------------------
196 /**
197  * @brief AddToModeling add tag to modeling tag current pattern peace.
198  * @param domElement tag.
199  */
200 void VAbstractNode::AddToModeling(const QDomElement &domElement)
201 {
202  AddDetNode *addNode = new AddDetNode(domElement, doc, m_blockName);
203  qApp->getUndoStack()->push(addNode);
204 }
virtual void HideNode()=0
ParentType parentType
Definition: vabstractnode.h:91
static const QString AttrIdTool
Definition: vabstractnode.h:77
quint32 idTool
idTool id tool.
Definition: vabstractnode.h:97
void SetExluded(bool exluded)
QString m_blockName
Definition: vabstractnode.h:99
ParentType GetParentType() const
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE
VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode, const QString &blockName=QString(), const quint32 &idTool=0, QObject *parent=nullptr)
VAbstractNode constructor.
virtual void incrementReferens() Q_DECL_OVERRIDE
incrementReferens increment referens.
virtual void ShowNode()=0
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.
bool IsExluded() const
void SetParentType(const ParentType &value)
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE
virtual void decrementReferens() Q_DECL_OVERRIDE
decrementReferens decrement reference for all parent objects.
virtual void IncrementReferens(quint32 id) const =0
virtual void DecrementReferens(quint32 id) const =0
The VAbstractTool abstract class for all tools.
Definition: vabstracttool.h:80
static const QString AttrInUse
Definition: vabstracttool.h:89
VAbstractPattern * doc
doc dom document container
virtual void AddToFile()=0
AddToFile add tag with Information about tool into file.
virtual QString getTagName() const =0
const quint32 m_id
id object id.
virtual void RefreshDataInFile()
RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
Definition: vcontainer.cpp:150
virtual void decrementReferens()
decrementReferens decrement referens.
Definition: vdatatool.cpp:74
quint32 _referens
_referens keep count tools what use this tool. If value more than 1 you can't delete tool.
Definition: vdatatool.h:87
virtual void incrementReferens()
incrementReferens increment referens.
Definition: vdatatool.h:126
VContainer data
data container with data
Definition: vdatatool.h:84
QDomElement elementById(quint32 id, const QString &tagName=QString())
static void SetParametrUsage(QDomElement &domElement, const QString &name, const NodeUsage &value)
Source
Definition: def.h:106
#define NULL_ID
Definition: ifcdef.h:76
ParentType
Definition: vabstractnode.h:65
#define qApp
Definition: vapplication.h:67