Seamly2D
Code documentation
vtoolcut.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 vtoolcut.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 25 6, 2014
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 VTOOLCUT_H
53 #define VTOOLCUT_H
54 
55 #include <qcompilerdetection.h>
56 #include <QGraphicsItem>
57 #include <QMetaObject>
58 #include <QObject>
59 #include <QString>
60 #include <QtGlobal>
61 
62 #include "../../../toolcurve/vabstractspline.h"
63 #include "../ifc/xml/vabstractpattern.h"
64 #include "../vtoolsinglepoint.h"
65 #include "../vmisc/def.h"
66 #include "../../../../vdatatool.h"
67 #include "../../../../../visualization/visualization.h"
68 
69 class VFormula;
70 
71 class VToolCut : public VToolSinglePoint
72 {
73  Q_OBJECT
74 public:
75  VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula,
76  const quint32 &curveCutId, QGraphicsItem * parent = nullptr);
77 
78  virtual int type() const Q_DECL_OVERRIDE {return Type;}
79  enum { Type = UserType + static_cast<int>(Tool::Cut)};
80 
81  VFormula GetFormula() const;
82  void SetFormula(const VFormula &value);
83 
84  QString CurveName() const;
85 
86  quint32 getCurveCutId() const;
87  void setCurveCutId(const quint32 &value);
88 
89 public slots:
90  virtual void Disable(bool disable, const QString &draftBlockName) Q_DECL_OVERRIDE;
91  virtual void piecesMode(bool mode) Q_DECL_OVERRIDE;
92  virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
93 
94 protected:
95  /** @brief formula keep formula of length */
96  QString formula;
97 
98  quint32 curveCutId;
100 
101  void RefreshGeometry();
102  virtual void RemoveReferens() Q_DECL_OVERRIDE;
103 
104  template <typename T>
105  void ShowToolVisualization(bool show);
106 
107 private:
108  Q_DISABLE_COPY(VToolCut)
109 };
110 
111 //---------------------------------------------------------------------------------------------------------------------
112 template <typename T>
113 inline void VToolCut::ShowToolVisualization(bool show)
114 {
115  if (show)
116  {
117  if (vis.isNull())
118  {
119  AddVisualization<T>();
121  }
122  else
123  {
124  if (T *visual = qobject_cast<T *>(vis))
125  {
126  visual->show();
127  }
128  }
129  }
130  else
131  {
132  delete vis;
133  }
134 
135  VDataTool *parent = VAbstractPattern::getTool(VAbstractTool::data.GetGObject(curveCutId)->getIdTool());
136  if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(parent))
137  {
138  m_piecesMode ? parentCurve->ShowHandles(m_piecesMode) : parentCurve->ShowHandles(show);
139  }
140 }
141 #endif // VTOOLCUT_H
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
VAbstractPattern * doc
doc dom document container
QPointer< Visualization > vis
virtual void SetVisualization()=0
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
QString formula
formula keep formula of length
Definition: vtoolcut.h:96
virtual void RemoveReferens() Q_DECL_OVERRIDE
RemoveReferens decrement referens value for used objects.
Definition: vtoolcut.cpp:163
quint32 getCurveCutId() const
Definition: vtoolcut.cpp:105
virtual int type() const Q_DECL_OVERRIDE
Definition: vtoolcut.h:78
void SetFormula(const VFormula &value)
Definition: vtoolcut.cpp:133
@ Type
Definition: vtoolcut.h:79
void setCurveCutId(const quint32 &value)
Definition: vtoolcut.cpp:112
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE
FullUpdateFromFile update tool data form file.
Definition: vtoolcut.cpp:96
void RefreshGeometry()
RefreshGeometry refresh item on scene.
Definition: vtoolcut.cpp:154
virtual void Disable(bool disable, const QString &draftBlockName) Q_DECL_OVERRIDE
Definition: vtoolcut.cpp:81
virtual void piecesMode(bool mode) Q_DECL_OVERRIDE
Definition: vtoolcut.cpp:87
VFormula GetFormula() const
Definition: vtoolcut.cpp:123
void ShowToolVisualization(bool show)
Definition: vtoolcut.h:113
bool m_piecesMode
Definition: vtoolcut.h:99
VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &curveCutId, QGraphicsItem *parent=nullptr)
Definition: vtoolcut.cpp:70
QString CurveName() const
Definition: vtoolcut.cpp:145
quint32 curveCutId
Definition: vtoolcut.h:98
The VToolSinglePoint class parent for all tools what create points.