Seamly2D
Code documentation
dialogtriangle.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 dialogtriangle.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 "dialogtriangle.h"
53 
54 #include <QColor>
55 #include <QComboBox>
56 #include <QLabel>
57 #include <QLineEdit>
58 #include <QPointer>
59 #include <QSet>
60 
61 #include "../../visualization/visualization.h"
62 #include "../../visualization/line/vistooltriangle.h"
63 #include "../ifc/xml/vabstractpattern.h"
64 #include "../vmisc/vabstractapplication.h"
65 #include "dialogtool.h"
66 #include "ui_dialogtriangle.h"
67 
68 //---------------------------------------------------------------------------------------------------------------------
69 /**
70  * @brief DialogTriangle create dialog
71  * @param data container with data
72  * @param parent parent widget
73  */
74 DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent)
75  : DialogTool(data, toolId, parent)
76  , ui(new Ui::DialogTriangle)
77 {
78  ui->setupUi(this);
79  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
80  setWindowIcon(QIcon(":/toolicon/32x32/triangle.png"));
81 
82  ui->lineEditNamePoint->setClearButtonEnabled(true);
83 
84  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
85  labelEditNamePoint = ui->labelEditNamePoint;
86 
89 
90  FillComboBoxPoints(ui->comboBoxAxisP1);
91  FillComboBoxPoints(ui->comboBoxAxisP2);
92  FillComboBoxPoints(ui->comboBoxFirstPoint);
93  FillComboBoxPoints(ui->comboBoxSecondPoint);
94 
95  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogTriangle::NamePointChanged);
96  connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged, this, &DialogTriangle::PointNameChanged);
97  connect(ui->comboBoxSecondPoint, &QComboBox::currentTextChanged, this, &DialogTriangle::PointNameChanged);
98  connect(ui->comboBoxAxisP1, &QComboBox::currentTextChanged, this, &DialogTriangle::PointNameChanged);
99  connect(ui->comboBoxAxisP2, &QComboBox::currentTextChanged, this, &DialogTriangle::PointNameChanged);
100 
101  vis = new VisToolTriangle(data);
102 }
103 
104 //---------------------------------------------------------------------------------------------------------------------
106 {
107  delete ui;
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
111 /**
112  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
113  * @param id id of point or detail
114  * @param type type of object
115  */
116 void DialogTriangle::ChosenObject(quint32 id, const SceneObject &type)
117 {
118  if (prepare == false)// After first choose we ignore all objects
119  {
120  if (type == SceneObject::Point)
121  {
122  VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
123  SCASSERT(line != nullptr)
124 
125  switch (number)
126  {
127  case (0):
128  if (SetObject(id, ui->comboBoxAxisP1, tr("Select second point of axis")))
129  {
130  number++;
131  line->VisualMode(id);
132  }
133  break;
134  case (1):
135  if (getCurrentObjectId(ui->comboBoxAxisP1) != id)
136  {
137  if (SetObject(id, ui->comboBoxAxisP2, tr("Select first point")))
138  {
139  number++;
140  line->setObject2Id(id);
141  line->RefreshGeometry();
142  }
143  }
144  break;
145  case (2):
146  {
147  QSet<quint32> set;
148  set.insert(getCurrentObjectId(ui->comboBoxAxisP1));
149  set.insert(getCurrentObjectId(ui->comboBoxAxisP2));
150  set.insert(id);
151 
152  if (set.size() == 3)
153  {
154  if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point")))
155  {
156  number++;
157  line->setHypotenuseP1Id(id);
158  line->RefreshGeometry();
159  }
160  }
161  }
162  break;
163  case (3):
164  {
165  QSet<quint32> set;
166  set.insert(getCurrentObjectId(ui->comboBoxAxisP1));
167  set.insert(getCurrentObjectId(ui->comboBoxAxisP2));
168  set.insert(getCurrentObjectId(ui->comboBoxFirstPoint));
169  set.insert(id);
170 
171  if (set.size() == 4)
172  {
173  if (SetObject(id, ui->comboBoxSecondPoint, ""))
174  {
175  line->setHypotenuseP2Id(id);
176  line->RefreshGeometry();
177  prepare = true;
178  DialogAccepted();
179  }
180  }
181  }
182  break;
183  default:
184  break;
185  }
186  }
187  }
188 }
189 
190 //---------------------------------------------------------------------------------------------------------------------
192 {
193  pointName = ui->lineEditNamePoint->text();
194 
195  VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
196  SCASSERT(line != nullptr)
197 
198  line->setObject1Id(GetAxisP1Id());
199  line->setObject2Id(GetAxisP2Id());
202  line->RefreshGeometry();
203 }
204 
205 //---------------------------------------------------------------------------------------------------------------------
207 {
208  QSet<quint32> set;
209  set.insert(getCurrentObjectId(ui->comboBoxFirstPoint));
210  set.insert(getCurrentObjectId(ui->comboBoxSecondPoint));
211  set.insert(getCurrentObjectId(ui->comboBoxAxisP1));
212  set.insert(getCurrentObjectId(ui->comboBoxAxisP2));
213 
214  QColor color = okColor;
215  if (set.size() < 3)//Need tree or more unique points for creation triangle
216  {
217  flagError = false;
218  color = errorColor;
219  }
220  else
221  {
222  flagError = true;
223  color = okColor;
224  }
225  ChangeColor(ui->labelFirstPoint, color);
226  ChangeColor(ui->labelSecondPoint, color);
227  ChangeColor(ui->labelAxisP1, color);
228  ChangeColor(ui->labelAxisP2, color);
229  CheckState();
230 }
231 
232 //---------------------------------------------------------------------------------------------------------------------
234 {
235  AddVisualization<VisToolTriangle>();
236 }
237 
238 //---------------------------------------------------------------------------------------------------------------------
239 /**
240  * @brief SetPointName set name of point
241  * @param value name
242  */
243 void DialogTriangle::SetPointName(const QString &value)
244 {
245  pointName = value;
246  ui->lineEditNamePoint->setText(pointName);
247 }
248 
249 //---------------------------------------------------------------------------------------------------------------------
250 /**
251  * @brief SetSecondPointId set id of second point
252  * @param value id
253  */
254 void DialogTriangle::SetSecondPointId(const quint32 &value)
255 {
256  setCurrentPointId(ui->comboBoxSecondPoint, value);
257 
258  VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
259  SCASSERT(line != nullptr)
260  line->setHypotenuseP2Id(value);
261 }
262 
263 //---------------------------------------------------------------------------------------------------------------------
264 /**
265  * @brief SetFirstPointId set id of first point
266  * @param value id
267  */
268 void DialogTriangle::SetFirstPointId(const quint32 &value)
269 {
270  setCurrentPointId(ui->comboBoxFirstPoint, value);
271 
272  VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
273  SCASSERT(line != nullptr)
274  line->setHypotenuseP1Id(value);
275 }
276 
277 //---------------------------------------------------------------------------------------------------------------------
278 /**
279  * @brief SetAxisP2Id set id second point of axis
280  * @param value id
281  */
282 void DialogTriangle::SetAxisP2Id(const quint32 &value)
283 {
284  setCurrentPointId(ui->comboBoxAxisP2, value);
285 
286  VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
287  SCASSERT(line != nullptr)
288  line->setObject2Id(value);
289 }
290 
291 //---------------------------------------------------------------------------------------------------------------------
292 /**
293  * @brief SetAxisP1Id set id first point of axis
294  * @param value id
295  */
296 void DialogTriangle::SetAxisP1Id(const quint32 &value)
297 {
298  setCurrentPointId(ui->comboBoxAxisP1, value);
299 
300  VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
301  SCASSERT(line != nullptr)
302  line->setObject1Id(value);
303 }
304 
305 //---------------------------------------------------------------------------------------------------------------------
306 /**
307  * @brief GetAxisP1Id return id first point of axis
308  * @return id
309  */
311 {
312  return getCurrentObjectId(ui->comboBoxAxisP1);
313 }
314 
315 //---------------------------------------------------------------------------------------------------------------------
316 /**
317  * @brief GetAxisP2Id return id second point of axis
318  * @return id
319  */
321 {
322  return getCurrentObjectId(ui->comboBoxAxisP2);
323 }
324 
325 //---------------------------------------------------------------------------------------------------------------------
326 /**
327  * @brief GetFirstPointId return id of first point
328  * @return id
329  */
331 {
332  return getCurrentObjectId(ui->comboBoxFirstPoint);
333 }
334 
335 //---------------------------------------------------------------------------------------------------------------------
336 /**
337  * @brief GetSecondPointId return id of second point
338  * @return id
339  */
341 {
342  return getCurrentObjectId(ui->comboBoxSecondPoint);
343 }
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule=FillComboBox::NoChildren, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
Definition: dialogtool.cpp:896
const QColor okColor
Definition: dialogtool.h:219
virtual void CheckState()
CheckState enable, when all is correct, or disable, when something wrong, button ok.
void FillComboBoxPoints(QComboBox *box, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
FillComboBoxPoints fill comboBox list of points.
Definition: dialogtool.cpp:242
void NamePointChanged()
NamePointChanged check name of point.
QString pointName
pointName name of point
Definition: dialogtool.h:231
const QColor errorColor
Definition: dialogtool.h:220
qint32 number
number number of handled objects
Definition: dialogtool.h:234
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
virtual void DialogAccepted()
DialogAccepted save data and emit signal about closed dialog.
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
void initializeOkCancelApply(T *ui)
initializeOkCancelApply initialize OK / Cancel and Apply buttons
Definition: dialogtool.h:365
bool flagError
flagError use this flag if for you do not enought
Definition: dialogtool.h:193
const VContainer * data
data container with data
Definition: dialogtool.h:177
bool prepare
prepare show if we prepare. Show dialog after finish working with visual part of tool
Definition: dialogtool.h:228
QPointer< Visualization > vis
Definition: dialogtool.h:236
void ChangeColor(QWidget *widget, const QColor &color)
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
The DialogTriangle class dialog for ToolTriangle. Help create point and edit option.
virtual void PointNameChanged() Q_DECL_OVERRIDE
quint32 GetSecondPointId() const
GetSecondPointId return id of second point.
quint32 GetFirstPointId() const
GetFirstPointId return id of first point.
DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogTriangle create dialog.
Ui::DialogTriangle * ui
ui keeps information about user interface
virtual void ShowVisualization() Q_DECL_OVERRIDE
quint32 GetAxisP2Id() const
GetAxisP2Id return id second point of axis.
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
virtual ~DialogTriangle() Q_DECL_OVERRIDE
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
void SetAxisP2Id(const quint32 &value)
SetAxisP2Id set id second point of axis.
void SetFirstPointId(const quint32 &value)
SetFirstPointId set id of first point.
quint32 GetAxisP1Id() const
GetAxisP1Id return id first point of axis.
void SetSecondPointId(const quint32 &value)
SetSecondPointId set id of second point.
void SetPointName(const QString &value)
SetPointName set name of point.
void SetAxisP1Id(const quint32 &value)
SetAxisP1Id set id first point of axis.
The VContainer class container of all variables.
Definition: vcontainer.h:141
void setObject2Id(const quint32 &value)
void setHypotenuseP1Id(const quint32 &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setHypotenuseP2Id(const quint32 &value)
virtual void VisualMode(const quint32 &pointId)
void setObject1Id(const quint32 &value)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
#define qApp
Definition: vapplication.h:67