Seamly2D
Code documentation
vdrawtool.cpp
Go to the documentation of this file.
1 /**************************************************************************
2  **
3  ** @file vdrawtool.cpp
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date November 15, 2013
6  **
7  ** @author Douglas S Caskey
8  ** @date 7.23.2022
9  **
10  ** @brief
11  ** @copyright
12  ** This source code is part of the Valentine project, a pattern making
13  ** program, whose allow create and modeling patterns of clothing.
14  ** Copyright (C) 2013-2022 Seamly2D project
15  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
16  **
17  ** Seamly2D is free software: you can redistribute it and/or modify
18  ** it under the terms of the GNU General Public License as published by
19  ** the Free Software Foundation, either version 3 of the License, or
20  ** (at your option) any later version.
21  **
22  ** Seamly2D is distributed in the hope that it will be useful,
23  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
24  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  ** GNU General Public License for more details.
26  **
27  ** You should have received a copy of the GNU General Public License
28  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
29  **
30  *************************************************************************/
31 
32 #include "vdrawtool.h"
33 
34 #include "../vabstracttool.h"
35 #include "../ifc/ifcdef.h"
36 #include "../ifc/xml/vdomdocument.h"
37 #include "../ifc/xml/vabstractpattern.h"
38 #include "../qmuparser/qmuparsererror.h"
39 #include "../vmisc/logging.h"
40 #include "../vpatterndb/vcontainer.h"
41 #include "../../undocommands/addtocalc.h"
42 #include "../../undocommands/savetooloptions.h"
43 
44 #include <QDialog>
45 #include <QDomNode>
46 #include <QMessageLogger>
47 #include <QScopedPointer>
48 #include <QSharedPointer>
49 #include <QUndoStack>
50 #include <Qt>
51 #include <QtDebug>
52 
53 template <class T> class QSharedPointer;
54 
55 //---------------------------------------------------------------------------------------------------------------------
56 /**
57  * @brief VDrawTool constructor.
58  * @param doc dom document container.
59  * @param data container with variables.
60  * @param id object id in container.
61  */
62 VDrawTool::VDrawTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent)
63  : VInteractiveTool(doc, data, id, parent)
64  , activeBlockName(doc->getActiveDraftBlockName())
65  , m_lineType(LineTypeSolidLine)
66  , m_lineWeight("0.35")
67 {
70  connect(this->doc, &VAbstractPattern::ShowTool, this, &VDrawTool::ShowTool);
71 }
72 
73 //---------------------------------------------------------------------------------------------------------------------
74 /**
75  * @brief ShowTool highlight tool.
76  * @param id object id in container.
77  * @param enable enable or disable highlight.
78  */
79 void VDrawTool::ShowTool(quint32 id, bool enable)
80 {
81  Q_UNUSED(id)
82  Q_UNUSED(enable)
83 }
84 
85 //---------------------------------------------------------------------------------------------------------------------
86 /**
87  * @brief activeBlockChanged disable or enable context menu after change active draft block.
88  * @param newName new name active draft block.
89  */
90 void VDrawTool::activeBlockChanged(const QString &newName)
91 {
92  Disable(!(activeBlockName == newName), newName);
93 }
94 
95 //---------------------------------------------------------------------------------------------------------------------
96 /**
97  * @brief blockNameChanged save new name active draft block.
98  * @param oldName old name.
99  * @param newName new name active draft block. new name.
100  */
101 void VDrawTool::blockNameChanged(const QString &oldName, const QString &newName)
102 {
103  if (activeBlockName == oldName)
104  {
105  activeBlockName = newName;
106  }
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {
112  qCDebug(vTool, "Saving tool options after using dialog");
113  QDomElement oldDomElement = doc->elementById(m_id, getTagName());
114  if (oldDomElement.isElement())
115  {
116  QDomElement newDomElement = oldDomElement.cloneNode().toElement();
117  SaveDialog(newDomElement);
118 
119  SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, m_id);
121  qApp->getUndoStack()->push(saveOptions);
122  }
123  else
124  {
125  qCDebug(vTool, "Can't find tool with id = %u", m_id);
126  }
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
130 /**
131  * @brief AddToFile add tag with Information about tool into file.
132  */
134 {
135  QDomElement domElement = doc->createElement(getTagName());
137  SaveOptions(domElement, obj);
138  AddToCalculation(domElement);
139 }
140 
141 //---------------------------------------------------------------------------------------------------------------------
143 {
144  qCDebug(vTool, "Saving tool options");
145  QDomElement oldDomElement = doc->elementById(m_id, getTagName());
146  if (oldDomElement.isElement())
147  {
148  QDomElement newDomElement = oldDomElement.cloneNode().toElement();
149 
150  SaveOptions(newDomElement, obj);
151 
152  SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, m_id);
154  qApp->getUndoStack()->push(saveOptions);
155  }
156  else
157  {
158  qCDebug(vTool, "Can't find tool with id = %u", m_id);
159  }
160 }
161 
162 //---------------------------------------------------------------------------------------------------------------------
164 {
165  Q_UNUSED(obj)
166 
168 }
169 
170 //---------------------------------------------------------------------------------------------------------------------
171 QString VDrawTool::makeToolTip() const
172 {
173  return QString();
174 }
175 
176 //---------------------------------------------------------------------------------------------------------------------
177 bool VDrawTool::CorrectDisable(bool disable, const QString &draftBlockName) const
178 {
179  if (disable)
180  {
181  return disable;
182  }
183  else
184  {
185  return !(activeBlockName == draftBlockName);
186  }
187 }
188 
189 //---------------------------------------------------------------------------------------------------------------------
191 {
192  const QDomElement domElement = doc->elementById(m_id, getTagName());
193  if (domElement.isElement())
194  {
195  ReadToolAttributes(domElement);
196  }
197  else
198  {
199  qCDebug(vTool, "Can't find tool with id = %u", m_id);
200  }
201 }
202 
203 //---------------------------------------------------------------------------------------------------------------------
204 void VDrawTool::updatePointNameVisibility(quint32 id, bool visible)
205 {
206  Q_UNUSED(id)
207  Q_UNUSED(visible)
208 }
209 
210 //---------------------------------------------------------------------------------------------------------------------
212 {
213  Q_UNUSED(move)
214  // Do nothing.
215 }
216 
217 //---------------------------------------------------------------------------------------------------------------------
218 void VDrawTool::piecesMode(bool mode)
219 {
220  Q_UNUSED(mode)
221  // Do nothing.
222 }
223 
224 //---------------------------------------------------------------------------------------------------------------------
225 /**
226  * @brief AddToCalculation add tool to calculation tag in pattern file.
227  * @param domElement tag in xml tree.
228  */
229 void VDrawTool::AddToCalculation(const QDomElement &domElement)
230 {
231  AddToCalc *addToCal = new AddToCalc(domElement, doc);
233  qApp->getUndoStack()->push(addToCal);
234 }
235 
236 //---------------------------------------------------------------------------------------------------------------------
237 void VDrawTool::addDependence(QList<quint32> &list, quint32 objectId) const
238 {
239  if (objectId != NULL_ID)
240  {
241  auto originPoint = VAbstractTool::data.GetGObject(objectId);
242  list.append(originPoint->getIdTool());
243  }
244 }
245 
246 //---------------------------------------------------------------------------------------------------------------------
247 QString VDrawTool::getLineType() const
248 {
249  return m_lineType;
250 }
251 
252 //---------------------------------------------------------------------------------------------------------------------
253 void VDrawTool::setLineType(const QString &value)
254 {
255  m_lineType = value;
256 
258  SaveOption(obj);
259 }
260 
261 //---------------------------------------------------------------------------------------------------------------------
263 {
264  return m_lineWeight;
265 }
266 
267 //---------------------------------------------------------------------------------------------------------------------
268 void VDrawTool::setLineWeight(const QString &value)
269 {
270  m_lineWeight = value;
271 
273  SaveOption(obj);
274 }
275 
276 //---------------------------------------------------------------------------------------------------------------------
277 bool VDrawTool::isPointNameVisible(quint32 id) const
278 {
279  Q_UNUSED(id)
280  return false;
281 }
virtual void LiteParseTree(const Document &parse)=0
void draftBlockNameChanged(const QString &oldName, const QString &newName)
draftBlockNameChanged save new name draft block.
void ShowTool(quint32 id, bool enable)
ShowTool highlight tool.
void activeDraftBlockChanged(const QString &newName)
activeDraftBlockChanged change active draft block.
VAbstractPattern * doc
doc dom document container
virtual QString getTagName() const =0
const quint32 m_id
id object id.
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
VContainer data
data container with data
Definition: vdatatool.h:84
QDomElement elementById(quint32 id, const QString &tagName=QString())
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
virtual void activeBlockChanged(const QString &newName)
activeBlockChanged disable or enable context menu after change active draft block.
Definition: vdrawtool.cpp:90
virtual bool isPointNameVisible(quint32 id) const
Definition: vdrawtool.cpp:277
QString m_lineWeight
typeLine line type.
Definition: vdrawtool.h:104
virtual QString makeToolTip() const
Definition: vdrawtool.cpp:171
VDrawTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent=nullptr)
VDrawTool constructor.
Definition: vdrawtool.cpp:62
virtual void setLineType(const QString &value)
Definition: vdrawtool.cpp:253
QString activeBlockName
Definition: vdrawtool.h:102
virtual void SaveDialog(QDomElement &domElement)=0
SaveDialog save options into file after change in dialog.
virtual void SaveDialogChange() Q_DECL_FINAL
Definition: vdrawtool.cpp:110
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj)
Definition: vdrawtool.cpp:163
virtual void piecesMode(bool mode)
Definition: vdrawtool.cpp:218
void addDependence(QList< quint32 > &list, quint32 objectId) const
Definition: vdrawtool.cpp:237
QString m_lineType
activeBlockName name of tool's pattern peace.
Definition: vdrawtool.h:103
virtual void ReadToolAttributes(const QDomElement &domElement)=0
virtual void setLineWeight(const QString &value)
Definition: vdrawtool.cpp:268
virtual void Disable(bool disable, const QString &draftBlockName)=0
void SaveOption(QSharedPointer< VGObject > &obj)
Definition: vdrawtool.cpp:142
virtual void updatePointNameVisibility(quint32 id, bool visible)
Definition: vdrawtool.cpp:204
void AddToCalculation(const QDomElement &domElement)
typeLine line weight.
Definition: vdrawtool.cpp:229
virtual void ShowTool(quint32 id, bool enable)
ShowTool highlight tool.
Definition: vdrawtool.cpp:79
QString getLineWeight() const
Definition: vdrawtool.cpp:262
virtual void EnableToolMove(bool move)
Definition: vdrawtool.cpp:211
virtual void AddToFile() Q_DECL_OVERRIDE
AddToFile add tag with Information about tool into file.
Definition: vdrawtool.cpp:133
void blockNameChanged(const QString &oldName, const QString &newName)
blockNameChanged save new name active draft block.
Definition: vdrawtool.cpp:101
bool CorrectDisable(bool disable, const QString &draftBlockName) const
Definition: vdrawtool.cpp:177
QString getLineType() const
Definition: vdrawtool.cpp:247
void ReadAttributes()
Definition: vdrawtool.cpp:190
void NeedFullParsing()
void NeedLiteParsing(const Document &parse)
const QString LineTypeSolidLine
Definition: ifcdef.cpp:159
#define NULL_ID
Definition: ifcdef.h:76
#define qApp
Definition: vapplication.h:67