Seamly2D
Code documentation
vabstracttool.h
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 vabstracttool.h
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 #ifndef VABSTRACTTOOL_H
53 #define VABSTRACTTOOL_H
54 
55 #include <qcompilerdetection.h>
56 #include <QMap>
57 #include <QMetaObject>
58 #include <QObject>
59 #include <QString>
60 #include <QStringList>
61 #include <Qt>
62 #include <QtGlobal>
63 #include <QPixmap>
64 
65 #include "../ifc/xml/vabstractpattern.h"
66 #include "../ifc/xml/vabstractpattern.h"
67 #include "../vtools/visualization/visualization.h"
68 #include "../vmisc/vabstractapplication.h"
69 #include "../vmisc/def.h"
70 #include "../vwidgets/vmaingraphicsscene.h"
71 #include "vdatatool.h"
72 
74 class VAbstractNode;
75 
76 /**
77  * @brief The VAbstractTool abstract class for all tools.
78  */
79 class VAbstractTool: public VDataTool
80 {
81  Q_OBJECT
82 public:
83  VAbstractTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr);
84  virtual ~VAbstractTool() Q_DECL_OVERRIDE;
85  quint32 getId() const;
86 
87  static bool m_suppressContextMenu;
88 
89  static const QString AttrInUse;
90 
91  static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data);
92 
93  static const QStringList Colors();
97  static QPixmap createColorIcon(const int w, const int h, const QString &color);
98  static const QStringList fills();
99 
100  static void AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc);
101  static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path);
102  static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
103 
104  const VContainer *getData() const;
105 
107  virtual QString getTagName() const =0;
108  virtual void ShowVisualization(bool show) =0;
109  virtual void setPointNamePosition(quint32 id, const QPointF &pos);
110  virtual void setPointNameVisiblity(quint32 id, bool visible);
111 
112  template<typename T>
113  static quint32 CreateNode(VContainer *data, quint32 id);
114 
115 public slots:
116  /**
117  * @brief FullUpdateFromFile update tool data form file.
118  */
119  virtual void FullUpdateFromFile()=0;
120  virtual void AllowHover(bool enabled)=0;
121  virtual void AllowSelecting(bool enabled)=0;
122  virtual void ToolSelectionType(const SelectionType &type);
123 
124 signals:
125  /**
126  * @brief toolHasChanges emit if tool create change that need save.
127  */
129  /**
130  * @brief chosenTool emit if object was clicked.
131  * @param id object id in container.
132  * @param type type of scene object.
133  */
134  void chosenTool(quint32 id, SceneObject type);
135  /**
136  * @brief FullUpdateTree emit if need reparse pattern file.
137  */
138  void LiteUpdateTree(const Document &parse);
139 
140  void ToolTip(const QString &toolTip);
141 
142 protected:
143  /** @brief doc dom document container */
145 
146  /** @brief id object id. */
147  const quint32 m_id;
148 
149  QPointer<Visualization> vis;
151 
152  /**
153  * @brief AddToFile add tag with Information about tool into file.
154  */
155  virtual void AddToFile()=0;
156  /**
157  * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
158  */
159  virtual void RefreshDataInFile();
160  /**
161  * @brief RemoveReferens decrement value of reference.
162  */
163  virtual void RemoveReferens() {}
164  virtual void deleteTool(bool ask = true);
165  static int ConfirmDeletion();
166 
167  template <typename T>
168  void AddVisualization();
169 
170  virtual void SetVisualization()=0;
171  virtual void ToolCreation(const Source &typeCreation);
172 
173  static QDomElement AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node);
174  static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node);
175 
177  VContainer *data);
178  static quint32 PrepareNode(const VPieceNode &node, VMainGraphicsScene *scene, VAbstractPattern *doc,
179  VContainer *data);
180 private:
181  Q_DISABLE_COPY(VAbstractTool)
182 };
183 
184 //---------------------------------------------------------------------------------------------------------------------
185 /**
186  * @brief getId return object id.
187  * @return id.
188  */
189 inline quint32 VAbstractTool::getId() const
190 {
191  return m_id;
192 }
193 
194 //---------------------------------------------------------------------------------------------------------------------
195 /**
196  * @brief getData return pointer to data container.
197  * @return container.
198  */
199 inline const VContainer *VAbstractTool::getData() const
200 {
201  return &data;
202 }
203 
204 //---------------------------------------------------------------------------------------------------------------------
205 template <typename T>
207 {
208  T *visual = new T(getData());
209  VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
210  SCASSERT(scene != nullptr)
211  scene->addItem(visual);
212 
213  connect(visual, &Visualization::ToolTip, this, &VAbstractTool::ToolTip);
214  vis = visual;
215 }
216 
217 //---------------------------------------------------------------------------------------------------------------------
218 template<typename T>
219 /**
220  * @brief CreateNode create new node for detail.
221  * @param data container.
222  * @param id id parent object.
223  * @return id for new object.
224  */
225 quint32 VAbstractTool::CreateNode(VContainer *data, quint32 id)
226 {
227  //We can't use exist object. Need create new.
228  T *node = new T(*data->GeometricObject<T>(id).data());
229  node->setMode(Draw::Modeling);
230  return data->AddGObject(node);
231 }
232 
233 #endif // VABSTRACTTOOL_H
The VAbstractNode class parent class for all detail node.
Definition: vabstractnode.h:71
The VAbstractTool abstract class for all tools.
Definition: vabstracttool.h:80
static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path)
static const QString AttrInUse
Definition: vabstracttool.h:89
VAbstractPattern * doc
doc dom document container
static quint32 CreateNode(VContainer *data, quint32 id)
CreateNode create new node for detail.
virtual void AddToFile()=0
AddToFile add tag with Information about tool into file.
virtual void setPointNamePosition(quint32 id, const QPointF &pos)
QPointer< Visualization > vis
void AddVisualization()
virtual void FullUpdateFromFile()=0
FullUpdateFromFile update tool data form file.
virtual void AllowSelecting(bool enabled)=0
virtual void deleteTool(bool ask=true)
deleteTool full delete object form scene and file.
static bool m_suppressContextMenu
Definition: vabstracttool.h:87
static QVector< VPieceNode > PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
void toolHasChanges()
toolHasChanges emit if tool create change that need save.
static QDomElement AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node)
const VContainer * getData() const
getData return pointer to data container.
VAbstractTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent=nullptr)
VAbstractTool container.
void ToolTip(const QString &toolTip)
virtual void RemoveReferens()
RemoveReferens decrement value of reference.
virtual void AllowHover(bool enabled)=0
static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node)
static const QStringList Colors()
void chosenTool(quint32 id, SceneObject type)
chosenTool emit if object was clicked.
virtual QString getTagName() const =0
virtual void ShowVisualization(bool show)=0
virtual void ToolCreation(const Source &typeCreation)
static int ConfirmDeletion()
static QMap< QString, QString > supportColorsList()
static QMap< QString, QString > ColorsList()
static void AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
AddRecord add record about tool in history.
static const QStringList fills()
QMap< QString, quint32 > PointsList() const
quint32 getId() const
getId return object id.
void LiteUpdateTree(const Document &parse)
FullUpdateTree emit if need reparse pattern file.
static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data)
CheckFormula check formula.
const quint32 m_id
id object id.
virtual ~VAbstractTool() Q_DECL_OVERRIDE
static quint32 PrepareNode(const VPieceNode &node, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
virtual void RefreshDataInFile()
RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
static QPixmap createColorIcon(const int w, const int h, const QString &color)
virtual void SetVisualization()=0
virtual void ToolSelectionType(const SelectionType &type)
SelectionType selectionType
virtual void setPointNameVisiblity(quint32 id, bool visible)
static QMap< QString, QString > backgroundColorsList()
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
quint32 AddGObject(VGObject *obj)
AddGObject add new GObject to container.
Definition: vcontainer.cpp:216
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
The VGraphicsSimpleTextItem class pointer label.
The VMainGraphicsScene class main scene.
Definition: vpiece.h:88
void ToolTip(const QString &toolTip)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
Tool
Definition: def.h:161
SelectionType
Definition: def.h:108
Source
Definition: def.h:106
Document
#define qApp
Definition: vapplication.h:67
@ Modeling