Seamly2D
Code documentation
dialogheight.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 dialogheight.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 "dialogheight.h"
53 
54 #include <QColor>
55 #include <QComboBox>
56 #include <QLabel>
57 #include <QLineEdit>
58 #include <QLineF>
59 #include <QPoint>
60 #include <QPointF>
61 #include <QPointer>
62 #include <QSet>
63 #include <QSharedPointer>
64 #include <new>
65 
66 #include "../../visualization/line/vistoolheight.h"
67 #include "../../visualization/visualization.h"
68 #include "../../visualization/line/visline.h"
69 #include "../ifc/xml/vabstractpattern.h"
70 #include "../vgeometry/vgobject.h"
71 #include "../vgeometry/vpointf.h"
72 #include "../vmisc/vabstractapplication.h"
73 #include "../vpatterndb/vcontainer.h"
74 #include "dialogtool.h"
75 #include "ui_dialogheight.h"
76 
77 //---------------------------------------------------------------------------------------------------------------------
78 /**
79  * @brief DialogHeight create dialog
80  * @param data container with data
81  * @param parent parent widget
82  */
83 DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent)
84  : DialogTool(data, toolId, parent), ui(new Ui::DialogHeight)
85 {
86  ui->setupUi(this);
87  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
88  setWindowIcon(QIcon(":/toolicon/32x32/height.png"));
89 
90  ui->lineEditNamePoint->setClearButtonEnabled(true);
91 
92  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
93  labelEditNamePoint = ui->labelEditNamePoint;
96 
97  FillComboBoxPoints(ui->comboBoxBasePoint);
98  FillComboBoxPoints(ui->comboBoxP1Line);
99  FillComboBoxPoints(ui->comboBoxP2Line);
100 
101  int index = ui->lineColor_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineColor());
102  if (index != -1)
103  {
104  ui->lineColor_ComboBox->setCurrentIndex(index);
105  }
106 
107  index = ui->lineWeight_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineWeight());
108  if (index != -1)
109  {
110  ui->lineWeight_ComboBox->setCurrentIndex(index);
111  }
112 
113  index = ui->lineType_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineType());
114  if (index != -1)
115  {
116  ui->lineType_ComboBox->setCurrentIndex(index);
117  }
118 
119  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogHeight::NamePointChanged);
120  connect(ui->comboBoxBasePoint, &QComboBox::currentTextChanged, this, &DialogHeight::PointNameChanged);
121  connect(ui->comboBoxP1Line, &QComboBox::currentTextChanged, this, &DialogHeight::PointNameChanged);
122  connect(ui->comboBoxP2Line, &QComboBox::currentTextChanged, this, &DialogHeight::PointNameChanged);
123 
124  vis = new VisToolHeight(data);
125  // Call after initialization vis!!!!
127  setLineWeight("0.35");
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
132 {
133  delete ui;
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
137 /**
138  * @brief SetPointName set name of point
139  * @param value name
140  */
141 void DialogHeight::SetPointName(const QString &value)
142 {
143  pointName = value;
144  ui->lineEditNamePoint->setText(pointName);
145 }
146 
147 //---------------------------------------------------------------------------------------------------------------------
148 /**
149  * @brief getLineType return type of line
150  * @return type
151  */
153 {
154  return GetComboBoxCurrentData(ui->lineType_ComboBox, LineTypeSolidLine);
155 }
156 
157 //---------------------------------------------------------------------------------------------------------------------
158 /**
159  * @brief setLineType set type of line
160  * @param value type
161  */
162 void DialogHeight::setLineType(const QString &value)
163 {
164  ChangeCurrentData(ui->lineType_ComboBox, value);
165  vis->setLineStyle(lineTypeToPenStyle(value));
166 }
167 
168 //---------------------------------------------------------------------------------------------------------------------
169 /**
170  * @brief getLineWeight return weight of the lines
171  * @return type
172  */
174 {
175  return GetComboBoxCurrentData(ui->lineWeight_ComboBox, "0.35");
176 }
177 
178 //---------------------------------------------------------------------------------------------------------------------
179 /**
180  * @brief setLineWeight set weight of the lines
181  * @param value type
182  */
183 void DialogHeight::setLineWeight(const QString &value)
184 {
185  ChangeCurrentData(ui->lineWeight_ComboBox, value);
186  vis->setLineWeight(value);
187 }
188 
189 //---------------------------------------------------------------------------------------------------------------------
191 {
192  return GetComboBoxCurrentData(ui->lineColor_ComboBox, ColorBlack);
193 }
194 
195 //---------------------------------------------------------------------------------------------------------------------
196 void DialogHeight::setLineColor(const QString &value)
197 {
198  ChangeCurrentData(ui->lineColor_ComboBox, value);
199 }
200 
201 //---------------------------------------------------------------------------------------------------------------------
202 /**
203  * @brief SetBasePointId set id base point of height
204  * @param value id
205  */
206 void DialogHeight::SetBasePointId(const quint32 &value)
207 {
208  setCurrentPointId(ui->comboBoxBasePoint, value);
209 
210  VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
211  SCASSERT(line != nullptr)
212  line->setObject1Id(value);
213 }
214 
215 //---------------------------------------------------------------------------------------------------------------------
216 /**
217  * @brief SetP1LineId set id first point of line
218  * @param value id
219  */
220 void DialogHeight::SetP1LineId(const quint32 &value)
221 {
222  setCurrentPointId(ui->comboBoxP1Line, value);
223 
224  VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
225  SCASSERT(line != nullptr)
226  line->setLineP1Id(value);
227 }
228 
229 //---------------------------------------------------------------------------------------------------------------------
230 /**
231  * @brief SetP2LineId set id second point of line
232  * @param value id
233  */
234 void DialogHeight::SetP2LineId(const quint32 &value)
235 {
236  setCurrentPointId(ui->comboBoxP2Line, value);
237 
238  VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
239  SCASSERT(line != nullptr)
240  line->setLineP2Id(value);
241 }
242 
243 //---------------------------------------------------------------------------------------------------------------------
244 /**
245  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
246  * @param id id of point or detail
247  * @param type type of object
248  */
249 void DialogHeight::ChosenObject(quint32 id, const SceneObject &type)
250 {
251  if (prepare == false)// After first choose we ignore all objects
252  {
253  if (type == SceneObject::Point)
254  {
255  VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
256  SCASSERT(line != nullptr)
257 
258  switch (number)
259  {
260  case (0):
261  if (SetObject(id, ui->comboBoxBasePoint, tr("Select first point of line")))
262  {
263  number++;
264  line->VisualMode(id);
265  }
266  break;
267  case (1):
268  if (getCurrentObjectId(ui->comboBoxBasePoint) != id)
269  {
270  if (SetObject(id, ui->comboBoxP1Line, tr("Select second point of line")))
271  {
272  number++;
273  line->setLineP1Id(id);
274  line->RefreshGeometry();
275  }
276  }
277  break;
278  case (2):
279  {
280  QSet<quint32> set;
281  set.insert(getCurrentObjectId(ui->comboBoxBasePoint));
282  set.insert(getCurrentObjectId(ui->comboBoxP1Line));
283  set.insert(id);
284 
285  if (set.size() == 3)
286  {
287  if (SetObject(id, ui->comboBoxP2Line, ""))
288  {
289  line->setLineP2Id(id);
290  line->RefreshGeometry();
291  prepare = true;
292  DialogAccepted();
293  }
294  }
295  }
296  break;
297  default:
298  break;
299  }
300  }
301  }
302 }
303 
304 //---------------------------------------------------------------------------------------------------------------------
306 {
307  pointName = ui->lineEditNamePoint->text();
308 
309  VisToolHeight *line = qobject_cast<VisToolHeight *>(vis);
310  SCASSERT(line != nullptr)
311 
312  line->setObject1Id(GetBasePointId());
313  line->setLineP1Id(GetP1LineId());
314  line->setLineP2Id(GetP2LineId());
316  line->setLineWeight(getLineWeight());
317  line->RefreshGeometry();
318 }
319 
320 //---------------------------------------------------------------------------------------------------------------------
322 {
323  QSet<quint32> set;
324  const quint32 basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
325  const quint32 p1LineId = getCurrentObjectId(ui->comboBoxP1Line);
326  const quint32 p2LineId = getCurrentObjectId(ui->comboBoxP2Line);
327 
328  set.insert(basePointId);
329  set.insert(p1LineId);
330  set.insert(p2LineId);
331 
332  const QPointF basePoint = static_cast<QPointF>(*data->GeometricObject<VPointF>(basePointId));
333  const QPointF p1Line = static_cast<QPointF>(*data->GeometricObject<VPointF>(p1LineId));
334  const QPointF p2Line = static_cast<QPointF>(*data->GeometricObject<VPointF>(p2LineId));
335 
336  QColor color = okColor;
337  if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line, p2Line), basePoint) == QPointF())
338  {
339  flagError = false;
340  color = errorColor;
341  }
342  else
343  {
344  flagError = true;
345  color = okColor;
346  }
347  ChangeColor(ui->labelBasePoint, color);
348  ChangeColor(ui->labelFirstLinePoint, color);
349  ChangeColor(ui->labelSecondLinePoint, color);
350  CheckState();
351 }
352 
353 //---------------------------------------------------------------------------------------------------------------------
355 {
356  AddVisualization<VisLine>();
357 }
358 
359 //---------------------------------------------------------------------------------------------------------------------
360 /**
361  * @brief GetBasePointId return id base point of height
362  * @return id
363  */
365 {
366  return getCurrentObjectId(ui->comboBoxBasePoint);
367 }
368 
369 //---------------------------------------------------------------------------------------------------------------------
370 /**
371  * @brief GetP1LineId return id first point of line
372  * @return id id
373  */
375 {
376  return getCurrentObjectId(ui->comboBoxP1Line);
377 }
378 
379 //---------------------------------------------------------------------------------------------------------------------
380 /**
381  * @brief GetP2LineId return id second point of line
382  * @return id
383  */
385 {
386  return getCurrentObjectId(ui->comboBoxP2Line);
387 }
The DialogHeight class dialog for ToolHeight. Help create point and edit option.
Definition: dialogheight.h:73
virtual void ShowVisualization() Q_DECL_OVERRIDE
DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogHeight create dialog.
QString getLineType() const
getLineType return type of line
virtual ~DialogHeight() Q_DECL_OVERRIDE
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
void SetP1LineId(const quint32 &value)
SetP1LineId set id first point of line.
void setLineColor(const QString &value)
void setLineWeight(const QString &value)
setLineWeight set weight of the lines
void SetPointName(const QString &value)
SetPointName set name of point.
Ui::DialogHeight * ui
ui keeps information about user interface
Definition: dialogheight.h:114
void SetP2LineId(const quint32 &value)
SetP2LineId set id second point of line.
QString getLineWeight() const
getLineWeight return weight of the lines
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.
void setLineType(const QString &value)
setLineType set type of line
quint32 GetP1LineId() const
GetP1LineId return id first point of line.
quint32 GetBasePointId() const
GetBasePointId return id base point of height.
QString getLineColor() const
void SetBasePointId(const quint32 &value)
SetBasePointId set id base point of height.
virtual void PointNameChanged() Q_DECL_OVERRIDE
quint32 GetP2LineId() const
GetP2LineId return id second point of line.
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
void ChangeCurrentData(QComboBox *box, const QVariant &value) const
ChangeCurrentData select item in combobox by id.
Definition: dialogtool.cpp:419
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
QString GetComboBoxCurrentData(const QComboBox *box, const QString &def) const
Definition: dialogtool.cpp:400
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 VContainer class container of all variables.
Definition: vcontainer.h:141
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
static QPointF ClosestPoint(const QLineF &line, const QPointF &point)
ClosestPoint find point projection of point onto line.
Definition: vgobject.cpp:436
The VPointF class keep data of point.
Definition: vpointf.h:75
void setLineP2Id(const quint32 &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setLineP1Id(const quint32 &value)
void setLineWeight(const QString &value)
virtual void VisualMode(const quint32 &pointId)
void setObject1Id(const quint32 &value)
void setLineStyle(const Qt::PenStyle &value)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
const QString LineTypeSolidLine
Definition: ifcdef.cpp:159
const QString LineTypeDashLine
Definition: ifcdef.cpp:160
const QString ColorBlack
Definition: ifcdef.cpp:373
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.
Definition: ifcdef.cpp:183
#define qApp
Definition: vapplication.h:67