Seamly2D
Code documentation
point_intersectxy_dialog.cpp
Go to the documentation of this file.
1 /**************************************************************************
2  **
3  ** @file point_intersectxy_dialog.cpp
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date November 15, 2013
6  **
7  ** @author Douglas S Caskey
8  ** @date 7.20.2022
9  **
10  ** @brief
11  ** @copyright
12  ** This source code is part of the Valentine project, a pattern making
13  ** program, whose allow create and modeling patterns of clothing.
14  ** Copyright (C) 2013-2022 Seamly2D project
15  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
16  **
17  ** Seamly2D is free software: you can redistribute it and/or modify
18  ** it under the terms of the GNU General Public License as published by
19  ** the Free Software Foundation, either version 3 of the License, or
20  ** (at your option) any later version.
21  **
22  ** Seamly2D is distributed in the hope that it will be useful,
23  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
24  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  ** GNU General Public License for more details.
26  **
27  ** You should have received a copy of the GNU General Public License
28  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
29  **
30  *************************************************************************/
31 
33 #include "ui_point_intersectxy_dialog.h"
34 
35 #include "dialogtool.h"
36 #include "../ifc/xml/vabstractpattern.h"
37 #include "../ifc/ifcdef.h"
38 #include "../vmisc/vabstractapplication.h"
39 #include "../vmisc/vcommonsettings.h"
40 #include "../../visualization/visualization.h"
41 #include "../../visualization/line/point_intersectxy_visual.h"
42 
43 #include <QColor>
44 #include <QComboBox>
45 #include <QLabel>
46 #include <QLineEdit>
47 #include <QPointer>
48 
49 //---------------------------------------------------------------------------------------------------------------------
50 /**
51  * @brief PointIntersectXYDialog create dialog
52  * @param data container with data
53  * @param parent parent widget
54  */
55 PointIntersectXYDialog::PointIntersectXYDialog(const VContainer *data, const quint32 &toolId, QWidget *parent)
56  : DialogTool(data, toolId, parent)
57  , ui(new Ui::PointIntersectXYDialog)
58 {
59  ui->setupUi(this);
60  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
61  setWindowIcon(QIcon(":/toolicon/32x32/point_intersectxy_icon.png"));
62 
63  ui->pointName_LineEdit->setClearButtonEnabled(true);
64 
65  ui->pointName_LineEdit->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
66  labelEditNamePoint = ui->pointName_Label;
67 
69  CheckState();
70 
71  FillComboBoxPoints(ui->firstPoint_ComboBox);
72  FillComboBoxPoints(ui->secondPoint_ComboBox);
73 
74  int index = ui->lineColor_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineColor());
75  if (index != -1)
76  {
77  ui->lineColor_ComboBox->setCurrentIndex(index);
78  }
79 
80  index = ui->lineWeight_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineWeight());
81  if (index != -1)
82  {
83  ui->lineWeight_ComboBox->setCurrentIndex(index);
84  }
85 
86  index = ui->lineType_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineType());
87  if (index != -1)
88  {
89  ui->lineType_ComboBox->setCurrentIndex(index);
90  }
91 
92  connect(ui->pointName_LineEdit, &QLineEdit::textChanged, this, &PointIntersectXYDialog::NamePointChanged);
93  connect(ui->firstPoint_ComboBox, &QComboBox::currentTextChanged, this, &PointIntersectXYDialog::pointChanged);
94  connect(ui->secondPoint_ComboBox, &QComboBox::currentTextChanged, this, &PointIntersectXYDialog::pointChanged);
95 
97  vis->VisualMode(NULL_ID);//Show vertical axis
98 
99  // Call after initialization vis!!!!
101  setLineWeight("0.35");
102 }
103 
104 //---------------------------------------------------------------------------------------------------------------------
106 {
107  delete ui;
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
111 /**
112  * @brief setPointName set name of point
113  * @param value name
114  */
115 void PointIntersectXYDialog::setPointName(const QString &value)
116 {
117  pointName = value;
118  ui->pointName_LineEdit->setText(pointName);
119 }
120 
121 //---------------------------------------------------------------------------------------------------------------------
122 /**
123  * @brief getFirstPointId return id of first point
124  * @return id
125  */
127 {
128  return getCurrentObjectId(ui->firstPoint_ComboBox);
129 }
130 
131 //---------------------------------------------------------------------------------------------------------------------
132 /**
133  * @brief setFirstPointId set id of first point
134  * @param value id
135  */
136 void PointIntersectXYDialog::setFirstPointId(const quint32 &value)
137 {
138  setCurrentPointId(ui->firstPoint_ComboBox, value);
139 
140  PointIntersectXYVisual *visual = qobject_cast<PointIntersectXYVisual *>(vis);
141  SCASSERT(visual != nullptr)
142  visual->setPoint1Id(value);
143 }
144 
145 //---------------------------------------------------------------------------------------------------------------------
146 /**
147  * @brief getSecondPointId return id of second point
148  * @return id
149  */
151 {
152  return getCurrentObjectId(ui->secondPoint_ComboBox);
153 }
154 
155 //---------------------------------------------------------------------------------------------------------------------
156 /**
157  * @brief setSecondPointId set id of second point
158  * @param value id
159  */
161 {
162  setCurrentPointId(ui->secondPoint_ComboBox, value);
163 
164  PointIntersectXYVisual *visual = qobject_cast<PointIntersectXYVisual *>(vis);
165  SCASSERT(visual != nullptr)
166  visual->setPoint2Id(value);
167 }
168 
169 //---------------------------------------------------------------------------------------------------------------------
170 /**
171  * @brief getLineType return type of the lines
172  * @return type
173  */
175 {
176  return GetComboBoxCurrentData(ui->lineType_ComboBox, LineTypeDashLine);
177 }
178 
179 //---------------------------------------------------------------------------------------------------------------------
180 /**
181  * @brief setLineType set type of the lines
182  * @param value type
183  */
184 void PointIntersectXYDialog::setLineType(const QString &value)
185 {
186  ChangeCurrentData(ui->lineType_ComboBox, value);
187  vis->setLineStyle(lineTypeToPenStyle(value));
188 }
189 
190 //---------------------------------------------------------------------------------------------------------------------
191 /**
192  * @brief getLineWeight return weight of the lines
193  * @return type
194  */
196 {
197  return GetComboBoxCurrentData(ui->lineWeight_ComboBox, "0.35");
198 }
199 
200 //---------------------------------------------------------------------------------------------------------------------
201 /**
202  * @brief setLineWeight set weight of the lines
203  * @param value type
204  */
205 void PointIntersectXYDialog::setLineWeight(const QString &value)
206 {
207  ChangeCurrentData(ui->lineWeight_ComboBox, value);
208  vis->setLineWeight(value);
209 }
210 
211 //---------------------------------------------------------------------------------------------------------------------
212 /**
213  * @brief getLineColor get the color of lines
214  * @param value type
215  */
216 //---------------------------------------------------------------------------------------------------------------------
218 {
219  return GetComboBoxCurrentData(ui->lineColor_ComboBox, qApp->Settings()->getSecondarySupportColor());
220 }
221 
222 //---------------------------------------------------------------------------------------------------------------------
223 /**
224  * @brief setLineColor set color of the lines
225  * @param value type
226  */
227 //---------------------------------------------------------------------------------------------------------------------
228 void PointIntersectXYDialog::setLineColor(const QString &value)
229 {
230  ChangeCurrentData(ui->lineColor_ComboBox, value);
231 }
232 
233 //---------------------------------------------------------------------------------------------------------------------
234 /**
235  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
236  * @param id id of point or detail
237  * @param type type of object
238  */
240 {
241  if (prepare == false)// After first choose we ignore all objects
242  {
243  if (type == SceneObject::Point)
244  {
245  PointIntersectXYVisual *visual = qobject_cast<PointIntersectXYVisual *>(vis);
246  SCASSERT(visual != nullptr)
247 
248  switch (number)
249  {
250  case 0:
251  if (SetObject(id, ui->firstPoint_ComboBox, tr("Select point for Y value (horizontal)")))
252  {
253  number++;
254  visual->setPoint1Id(id);
255  visual->RefreshGeometry();
256  }
257  break;
258  case 1:
259  if (getCurrentObjectId(ui->firstPoint_ComboBox) != id)
260  {
261  if (SetObject(id, ui->secondPoint_ComboBox, ""))
262  {
263  visual->setPoint2Id(id);
264  visual->RefreshGeometry();
265  prepare = true;
266  DialogAccepted();
267  }
268  }
269  break;
270  default:
271  break;
272  }
273  }
274  }
275 }
276 
277 //---------------------------------------------------------------------------------------------------------------------
279 {
280  QColor color = okColor;
282  {
283  flagError = false;
284  color = errorColor;
285  }
286  else
287  {
288  flagError = true;
289  color = okColor;
290  }
291  ChangeColor(ui->firstPoint_Label, color);
292  ChangeColor(ui->secondPoint_Label, color);
293  CheckState();
294 }
295 
296 //---------------------------------------------------------------------------------------------------------------------
298 {
299  AddVisualization<PointIntersectXYVisual>();
300 }
301 
302 //---------------------------------------------------------------------------------------------------------------------
303 /**
304  * @brief SaveData Put dialog data in local variables
305  */
307 {
308  pointName = ui->pointName_LineEdit->text();
309 
310  PointIntersectXYVisual *visual = qobject_cast<PointIntersectXYVisual *>(vis);
311  SCASSERT(visual != nullptr)
312 
313  visual->setPoint1Id(getFirstPointId());
314  visual->setPoint2Id(getSecondPointId());
316  visual->setLineWeight(getLineWeight());
317  visual->RefreshGeometry();
318 }
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 PointIntersectXYDialog class dialog for ToolPointOfIntersection. Help create point and edit optio...
virtual void ShowVisualization() Q_DECL_OVERRIDE
virtual ~PointIntersectXYDialog() Q_DECL_OVERRIDE
void setLineType(const QString &value)
setLineType set type of the lines
quint32 getSecondPointId() const
getSecondPointId return id of second point
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 void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
void setSecondPointId(const quint32 &value)
setSecondPointId set id of second point
void setLineWeight(const QString &value)
setLineWeight set weight of the lines
QString getLineType() const
getLineType return type of the lines
QString getLineColor() const
getLineColor get the color of lines
void setFirstPointId(const quint32 &value)
setFirstPointId set id of first point
quint32 getFirstPointId() const
getFirstPointId return id of first point
QString getLineWeight() const
getLineWeight return weight of the lines
PointIntersectXYDialog(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
PointIntersectXYDialog create dialog.
void setLineColor(const QString &value)
setLineColor set color of the lines
void setPointName(const QString &value)
setPointName set name of point
Ui::PointIntersectXYDialog * ui
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setPoint1Id(const quint32 &value)
void setPoint2Id(const quint32 &value)
The VContainer class container of all variables.
Definition: vcontainer.h:141
void setLineWeight(const QString &value)
void setLineStyle(const Qt::PenStyle &value)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
const QString LineTypeDashLine
Definition: ifcdef.cpp:160
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.
Definition: ifcdef.cpp:183
#define NULL_ID
Definition: ifcdef.h:76
#define qApp
Definition: vapplication.h:67