Seamly2D
Code documentation
visoperation.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
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 12 9, 2016
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) 2016 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 "visoperation.h"
53 #include "../vgeometry/vabstractcurve.h"
54 #include "../vgeometry/varc.h"
55 #include "../vgeometry/vcubicbezier.h"
56 #include "../vgeometry/vcubicbezierpath.h"
57 #include "../vgeometry/vellipticalarc.h"
58 #include "../vgeometry/vgeometrydef.h"
59 #include "../vgeometry/vgobject.h"
60 #include "../vgeometry/vpointf.h"
61 #include "../vgeometry/vspline.h"
62 #include "../vgeometry/vsplinepath.h"
63 #include "../vmisc/vcommonsettings.h"
64 
65 //---------------------------------------------------------------------------------------------------------------------
66 VisOperation::VisOperation(const VContainer *data, QGraphicsItem *parent)
67  : VisLine(data, parent),
68  objects(),
69  supportColor2(QColor(qApp->Settings()->getSecondarySupportColor())),
70  supportColor3(QColor(qApp->Settings()->getTertiarySupportColor())),
71  points(),
72  curves()
73 {
74 }
75 
76 //---------------------------------------------------------------------------------------------------------------------
78 {
79  qDeleteAll(points);
80  qDeleteAll(curves);
81 }
82 
83 //---------------------------------------------------------------------------------------------------------------------
85 {
86  this->objects = objects;
87 }
88 
89 //---------------------------------------------------------------------------------------------------------------------
90 void VisOperation::VisualMode(const quint32 &pointId)
91 {
92  Q_UNUSED(pointId)
93  VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
94  SCASSERT(scene != nullptr)
95 
98 
99  AddOnScene();
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
103 VScaledEllipse *VisOperation::GetPoint(quint32 i, const QColor &color)
104 {
105  return GetPointItem(points, i, color, this);
106 }
107 
108 //---------------------------------------------------------------------------------------------------------------------
109 VCurvePathItem *VisOperation::GetCurve(quint32 i, const QColor &color)
110 {
111  if (not curves.isEmpty() && static_cast<quint32>(curves.size() - 1) >= i)
112  {
113  return curves.at(static_cast<int>(i));
114  }
115  else
116  {
117  auto curve = InitItem<VCurvePathItem>(color, this);
118  curves.append(curve);
119  return curve;
120  }
121  return nullptr;
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
125 QT_WARNING_PUSH
126 QT_WARNING_DISABLE_GCC("-Wswitch-default")
127 void VisOperation::refreshMirroredObjects(const QPointF &firstPoint, const QPointF &secondPoint)
128 {
129  int iPoint = -1;
130  int iCurve = -1;
131  for (int i = 0; i < objects.size(); ++i)
132  {
133  const quint32 id = objects.at(i);
135 
136  // This check helps to find missed objects in the switch
137  Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
138 
139  switch(static_cast<GOType>(obj->getType()))
140  {
141  case GOType::Point:
142  {
144 
145  ++iPoint;
146  VScaledEllipse *point = GetPoint(static_cast<quint32>(iPoint), supportColor2);
147  DrawPoint(point, static_cast<QPointF>(*p), supportColor2);
148 
149  ++iPoint;
150  point = GetPoint(static_cast<quint32>(iPoint), supportColor);
151 
152  if (object1Id != NULL_ID)
153  {
154  DrawPoint(point, static_cast<QPointF>(p->Flip(QLineF(firstPoint, secondPoint))), supportColor);
155  }
156  break;
157  }
158  case GOType::Arc:
159  {
160  iCurve = addFlippedCurve<VArc>(firstPoint, secondPoint, id, iCurve);
161  break;
162  }
164  {
165  iCurve = addFlippedCurve<VEllipticalArc>(firstPoint, secondPoint, id, iCurve);
166  break;
167  }
168  case GOType::Spline:
169  {
170  iCurve = addFlippedCurve<VSpline>(firstPoint, secondPoint, id, iCurve);
171  break;
172  }
173  case GOType::SplinePath:
174  {
175  iCurve = addFlippedCurve<VSplinePath>(firstPoint, secondPoint, id, iCurve);
176  break;
177  }
178  case GOType::CubicBezier:
179  {
180  iCurve = addFlippedCurve<VCubicBezier>(firstPoint, secondPoint, id, iCurve);
181  break;
182  }
184  {
185  iCurve = addFlippedCurve<VCubicBezierPath>(firstPoint, secondPoint, id, iCurve);
186  break;
187  }
188  case GOType::Unknown:
189  case GOType::Curve:
190  case GOType::Path:
191  case GOType::AllCurves:
192  default:
193  break;
194  }
195  }
196 }
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
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
The VMainGraphicsScene class main scene.
QPointF getScenePos() const
The VPointF class keep data of point.
Definition: vpointf.h:75
virtual void AddOnScene() Q_DECL_OVERRIDE
Definition: visline.cpp:149
void setObjects(QVector< quint32 > objects)
virtual void VisualMode(const quint32 &pointId=NULL_ID) Q_DECL_OVERRIDE
QVector< VScaledEllipse * > points
Definition: visoperation.h:78
VCurvePathItem * GetCurve(quint32 i, const QColor &color)
VisOperation(const VContainer *data, QGraphicsItem *parent=nullptr)
VScaledEllipse * GetPoint(quint32 i, const QColor &color)
QVector< quint32 > objects
Definition: visoperation.h:74
QVector< VCurvePathItem * > curves
Definition: visoperation.h:79
virtual ~VisOperation()
const VContainer * data
Definition: visualization.h:97
static VScaledEllipse * GetPointItem(QVector< VScaledEllipse * > &points, quint32 i, const QColor &color, QGraphicsItem *parent)
QPointF scenePos
Definition: visualization.h:98
virtual void RefreshGeometry()=0
#define SCASSERT(cond)
Definition: def.h:317
#define NULL_ID
Definition: ifcdef.h:76
#define qApp
Definition: vapplication.h:67
GOType
Definition: vgeometrydef.h:56
@ CubicBezierPath
@ SplinePath
@ EllipticalArc
@ CubicBezier