Seamly2D
Code documentation
dialogpointofcontact.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 dialogpointofcontact.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 "dialogpointofcontact.h"
53 
54 #include <QColor>
55 #include <QComboBox>
56 #include <QDialog>
57 #include <QLabel>
58 #include <QLineEdit>
59 #include <QPlainTextEdit>
60 #include <QPointer>
61 #include <QPushButton>
62 #include <QSet>
63 #include <QToolButton>
64 
65 #include "../vpatterndb/vtranslatevars.h"
66 #include "../../visualization/visualization.h"
67 #include "../../visualization/line/vistoolpointofcontact.h"
68 #include "../ifc/xml/vabstractpattern.h"
69 #include "../ifc/xml/vdomdocument.h"
70 #include "../support/edit_formula_dialog.h"
71 #include "../vmisc/vabstractapplication.h"
72 #include "../vmisc/vcommonsettings.h"
73 #include "ui_dialogpointofcontact.h"
74 
75 //---------------------------------------------------------------------------------------------------------------------
76 /**
77  * @brief DialogPointOfContact create dialog
78  * @param data container with data
79  * @param parent parent widget
80  */
81 DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent)
82  : DialogTool(data, toolId, parent)
83  , ui(new Ui::DialogPointOfContact)
84  , radius(QString())
85  , formulaBaseHeight(0)
86 {
87  ui->setupUi(this);
88  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
89  setWindowIcon(QIcon(":/toolicon/32x32/point_of_contact.png"));
90 
91  ui->lineEditNamePoint->setClearButtonEnabled(true);
92 
94  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
95  labelEditNamePoint = ui->labelEditNamePoint;
96  this->formulaBaseHeight = ui->plainTextEditFormula->height();
97  ui->plainTextEditFormula->installEventFilter(this);
98 
100  flagFormula = false;
102 
103  FillComboBoxPoints(ui->comboBoxFirstPoint);
104  FillComboBoxPoints(ui->comboBoxSecondPoint);
105  FillComboBoxPoints(ui->comboBoxCenter);
106 
107  connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogPointOfContact::FXRadius);
108  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfContact::NamePointChanged);
109  connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogPointOfContact::FormulaTextChanged);
110  connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogPointOfContact::DeployFormulaTextEdit);
111  connect(ui->comboBoxFirstPoint, &QComboBox::currentTextChanged, this, &DialogPointOfContact::PointNameChanged);
112  connect(ui->comboBoxSecondPoint, &QComboBox::currentTextChanged, this, &DialogPointOfContact::PointNameChanged);
113  connect(ui->comboBoxCenter, &QComboBox::currentTextChanged, this, &DialogPointOfContact::PointNameChanged);
114 
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
120 {
121  delete ui;
122 }
123 
124 //---------------------------------------------------------------------------------------------------------------------
126 {
127  this->FormulaChangedPlainText();
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------
132 {
133  QSet<quint32> set;
134  set.insert(getCurrentObjectId(ui->comboBoxFirstPoint));
135  set.insert(getCurrentObjectId(ui->comboBoxSecondPoint));
136  set.insert(getCurrentObjectId(ui->comboBoxCenter));
137 
138  QColor color = okColor;
139  if (set.size() != 3)
140  {
141  flagError = false;
142  color = errorColor;
143  }
144  else
145  {
146  flagError = true;
147  color = okColor;
148  }
149  ChangeColor(ui->labelFirstPoint, color);
150  ChangeColor(ui->labelSecondPoint, color);
151  ChangeColor(ui->labelArcCenter, color);
152  CheckState();
153 }
154 
155 //---------------------------------------------------------------------------------------------------------------------
157 {
158  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
159  dialog->setWindowTitle(tr("Edit radius"));
160  dialog->SetFormula(getRadius());
161  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
162  if (dialog->exec() == QDialog::Accepted)
163  {
164  setRadius(dialog->GetFormula());
165  }
166  delete dialog;
167 }
168 
169 //---------------------------------------------------------------------------------------------------------------------
171 {
172  AddVisualization<VisToolPointOfContact>();
173 }
174 
175 //---------------------------------------------------------------------------------------------------------------------
177 {
178  DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
179 }
180 
181 //---------------------------------------------------------------------------------------------------------------------
182 /**
183  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
184  * @param id id of point or detail
185  * @param type type of object
186  */
187 void DialogPointOfContact::ChosenObject(quint32 id, const SceneObject &type)
188 {
189  if (prepare == false)// After first choose we ignore all objects
190  {
191  if (type == SceneObject::Point)
192  {
193  VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
194  SCASSERT(line != nullptr)
195 
196  switch (number)
197  {
198  case 0:
199  if (SetObject(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
200  {
201  number++;
202  line->VisualMode(id);
203  }
204  break;
205  case 1:
206  if (getCurrentObjectId(ui->comboBoxFirstPoint) != id)
207  {
208  if (SetObject(id, ui->comboBoxSecondPoint, tr("Select point of center of arc")))
209  {
210  number++;
211  line->setLineP2Id(id);
212  line->RefreshGeometry();
213  }
214  }
215  break;
216  case 2:
217  {
218  QSet<quint32> set;
219  set.insert(getCurrentObjectId(ui->comboBoxFirstPoint));
220  set.insert(getCurrentObjectId(ui->comboBoxSecondPoint));
221  set.insert(id);
222 
223  if (set.size() == 3)
224  {
225  if (SetObject(id, ui->comboBoxCenter, ""))
226  {
227  line->setRadiusId(id);
228  line->RefreshGeometry();
229  prepare = true;
230  this->setModal(true);
231  this->show();
232  }
233  }
234  }
235  break;
236  default:
237  break;
238  }
239  }
240  }
241 }
242 
243 //---------------------------------------------------------------------------------------------------------------------
245 {
246  pointName = ui->lineEditNamePoint->text();
247  radius = ui->plainTextEditFormula->toPlainText();
248  radius.replace("\n", " ");
249 
250  VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
251  SCASSERT(line != nullptr)
252 
253  line->setObject1Id(GetFirstPoint());
254  line->setLineP2Id(GetSecondPoint());
255  line->setRadiusId(getCenter());
256  line->setRadius(radius);
257  line->RefreshGeometry();
258 }
259 
260 //---------------------------------------------------------------------------------------------------------------------
261 void DialogPointOfContact::closeEvent(QCloseEvent *event)
262 {
263  ui->plainTextEditFormula->blockSignals(true);
264  DialogTool::closeEvent(event);
265 }
266 
267 //---------------------------------------------------------------------------------------------------------------------
268 /**
269  * @brief SetSecondPoint set id second point
270  * @param value id
271  */
272 void DialogPointOfContact::SetSecondPoint(const quint32 &value)
273 {
274  setCurrentPointId(ui->comboBoxSecondPoint, value);
275 
276  VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
277  SCASSERT(line != nullptr)
278  line->setLineP2Id(value);
279 }
280 
281 //---------------------------------------------------------------------------------------------------------------------
282 /**
283  * @brief SetFirstPoint set id first point
284  * @param value id
285  */
286 void DialogPointOfContact::SetFirstPoint(const quint32 &value)
287 {
288  setCurrentPointId(ui->comboBoxFirstPoint, value);
289 
290  VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
291  SCASSERT(line != nullptr)
292  line->setObject1Id(value);
293 }
294 
295 //---------------------------------------------------------------------------------------------------------------------
296 /**
297  * @brief SetCenter set id of center point
298  * @param value id
299  */
300 void DialogPointOfContact::setCenter(const quint32 &value)
301 {
302  setCurrentPointId(ui->comboBoxCenter, value);
303 
304  VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
305  SCASSERT(line != nullptr)
306  line->setRadiusId(value);
307 }
308 
309 //---------------------------------------------------------------------------------------------------------------------
310 /**
311  * @brief setRadius set formula radius of arc
312  * @param value formula
313  */
314 void DialogPointOfContact::setRadius(const QString &value)
315 {
316  radius = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
317  // increase height if needed.
318  if (radius.length() > 80)
319  {
320  this->DeployFormulaTextEdit();
321  }
322  ui->plainTextEditFormula->setPlainText(radius);
323 
324  VisToolPointOfContact *line = qobject_cast<VisToolPointOfContact *>(vis);
325  SCASSERT(line != nullptr)
326  line->setRadius(radius);
327 
328  MoveCursorToEnd(ui->plainTextEditFormula);
329 }
330 
331 //---------------------------------------------------------------------------------------------------------------------
332 /**
333  * @brief SetPointName set name of point
334  * @param value name
335  */
336 void DialogPointOfContact::SetPointName(const QString &value)
337 {
338  pointName = value;
339  ui->lineEditNamePoint->setText(pointName);
340 }
341 
342 //---------------------------------------------------------------------------------------------------------------------
343 /**
344  * @brief getRadius return formula radius of arc
345  * @return formula
346  */
348 {
349  return qApp->TrVars()->TryFormulaFromUser(radius, qApp->Settings()->GetOsSeparator());
350 }
351 
352 //---------------------------------------------------------------------------------------------------------------------
353 /**
354  * @brief GetCenter return id of center point
355  * @return id
356  */
358 {
359  return getCurrentObjectId(ui->comboBoxCenter);
360 }
361 
362 //---------------------------------------------------------------------------------------------------------------------
363 /**
364  * @brief GetFirstPoint return id first point
365  * @return id
366  */
368 {
369  return getCurrentObjectId(ui->comboBoxFirstPoint);
370 }
371 
372 //---------------------------------------------------------------------------------------------------------------------
373 /**
374  * @brief GetSecondPoint return id second point
375  * @return id
376  */
378 {
379  return getCurrentObjectId(ui->comboBoxSecondPoint);
380 }
The DialogPointOfContact class dialog for ToolPointOfContact. Help create point and edit option.
quint32 getCenter() const
GetCenter return id of center point.
DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogPointOfContact create dialog.
void SetSecondPoint(const quint32 &value)
SetSecondPoint set id second point.
int formulaBaseHeight
formulaBaseHeight base height defined by dialogui
void setCenter(const quint32 &value)
SetCenter set id of center point.
QString getRadius() const
getRadius return formula radius of arc
virtual ~DialogPointOfContact() Q_DECL_OVERRIDE
void SetPointName(const QString &value)
SetPointName set name of point.
QString radius
radius radius of arc
void setRadius(const QString &value)
setRadius set formula radius of arc
quint32 GetFirstPoint() const
GetFirstPoint return id first point.
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
Ui::DialogPointOfContact * ui
ui keeps information about user interface
quint32 GetSecondPoint() const
GetSecondPoint return id second point.
virtual void PointNameChanged() Q_DECL_OVERRIDE
void DeployFormulaTextEdit()
DeployFormulaTextEdit grow or shrink formula input.
virtual void ShowVisualization() Q_DECL_OVERRIDE
void FormulaTextChanged()
FormulaTextChanged when formula text changes for validation and calc.
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
void SetFirstPoint(const quint32 &value)
SetFirstPoint set id first 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.
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.
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
Definition: dialogtool.cpp:432
bool flagFormula
flagFormula true if formula correct
Definition: dialogtool.h:186
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
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
Definition: dialogtool.cpp:192
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
quint32 toolId
Definition: dialogtool.h:225
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
void initializeFormulaUi(T *ui)
initializeFormulaUi initialize ui object for the formula field
Definition: dialogtool.h:398
QPointer< Visualization > vis
Definition: dialogtool.h:236
void FormulaChangedPlainText()
FormulaChangedPlainText check formula (plain text editor editor)
void ChangeColor(QWidget *widget, const QColor &color)
void DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight)
Definition: dialogtool.cpp:992
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
The EditFormulaDialog class dialog for editing wrong formula.
QString GetFormula() const
void SetFormula(const QString &value)
void setPostfix(const QString &value)
The VContainer class container of all variables.
Definition: vcontainer.h:141
void setLineP2Id(const quint32 &value)
void setRadiusId(const quint32 &value)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setRadius(const QString &expression)
virtual void VisualMode(const quint32 &pointId)
void setObject1Id(const quint32 &value)
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
#define qApp
Definition: vapplication.h:67