Seamly2D
Code documentation
dialogellipticalarc.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * @file dialogellipticalarc.cpp
3  ** @author Douglas S Caskey
4  ** @date 21 Mar, 2023
5  **
6  ** @brief
7  ** @copyright
8  ** This source code is part of the Seamly2D project, a pattern making
9  ** program to create and model patterns of clothing.
10  ** Copyright (C) 2017-2023 Seamly2D project
11  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
12  **
13  ** Seamly2D is free software: you can redistribute it and/or modify
14  ** You should have received a copy of the GNU General Public License
15  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
16  **
17  *****************************************************************************/
18 /************************************************************************
19  **
20  ** @file dialogellipticalarc.cpp
21  ** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
22  ** @date 15 9, 2016
23  **
24  ** @brief
25  ** @copyright
26  ** This source code is part of the Valentine project, a pattern making
27  ** program, whose allow create and modeling patterns of clothing.
28  ** Copyright (C) 2016 Seamly2D project
29  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
30  **
31  ** Seamly2D is free software: you can redistribute it and/or modify
32  ** it under the terms of the GNU General Public License as published by
33  ** the Free Software Foundation, either version 3 of the License, or
34  ** (at your option) any later version.
35  **
36  ** Seamly2D is distributed in the hope that it will be useful,
37  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
38  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39  ** GNU General Public License for more details.
40  **
41  ** You should have received a copy of the GNU General Public License
42  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
43  **
44  *************************************************************************/
45 
46 #include "dialogellipticalarc.h"
47 
48 #include <limits.h>
49 #include <QDialog>
50 #include <QLabel>
51 #include <QPlainTextEdit>
52 #include <QPointer>
53 #include <QPushButton>
54 #include <QTimer>
55 #include <QToolButton>
56 #include <Qt>
57 
58 #include "../../tools/vabstracttool.h"
59 #include "../ifc/xml/vdomdocument.h"
60 #include "../vpatterndb/vtranslatevars.h"
61 #include "../../visualization/path/vistoolellipticalarc.h"
62 #include "../../visualization/visualization.h"
63 #include "../support/edit_formula_dialog.h"
64 #include "../vmisc/vabstractapplication.h"
65 #include "../vmisc/vcommonsettings.h"
66 #include "ui_dialogellipticalarc.h"
67 
68 //---------------------------------------------------------------------------------------------------------------------
69 /**
70  * @brief DialogEllipticalArc create dialog
71  * @param data container with data
72  * @param parent parent widget
73  */
74 DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
75  : DialogTool(data, toolId, parent)
76  , ui(new Ui::DialogEllipticalArc)
77  , flagRadius1(false)
78  , flagRadius2(false)
79  , flagF1(false)
80  , flagF2(false)
81  , flagRotationAngle(false)
82  , timerRadius1(nullptr)
83  , timerRadius2(nullptr)
84  , timerF1(nullptr)
85  , timerF2(nullptr)
86  , timerRotationAngle(nullptr)
87  , radius1()
88  , radius2()
89  , f1()
90  , f2()
91  , rotationAngle()
92  , formulaBaseHeightRadius1(0)
93  , formulaBaseHeightRadius2(0)
94  , formulaBaseHeightF1(0)
95  , formulaBaseHeightF2(0)
96  , formulaBaseHeightRotationAngle(0)
97  , angleF1(INT_MIN)
98  , angleF2(INT_MIN)
99  , angleRotation(INT_MIN)
100  , m_arc()
101  , m_Id()
102  , newDuplicate(-1)
103 {
104  ui->setupUi(this);
105  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
106  setWindowIcon(QIcon(":/toolicon/32x32/el_arc.png"));
107 
108  m_Id = data->getId() + 1;
109 
110  this->formulaBaseHeightRadius1 = ui->plainTextEditRadius1->height();
111  this->formulaBaseHeightRadius2 = ui->plainTextEditRadius2->height();
112  this->formulaBaseHeightF1 = ui->plainTextEditF1->height();
113  this->formulaBaseHeightF2 = ui->plainTextEditF2->height();
114  this->formulaBaseHeightRotationAngle = ui->plainTextEditRotationAngle->height();
115 
116  ui->plainTextEditRadius1->installEventFilter(this);
117  ui->plainTextEditRadius2->installEventFilter(this);
118  ui->plainTextEditF1->installEventFilter(this);
119  ui->plainTextEditF2->installEventFilter(this);
120  ui->plainTextEditRotationAngle->installEventFilter(this);
121 
122  timerRadius1 = new QTimer(this);
123  connect(timerRadius1, &QTimer::timeout, this, &DialogEllipticalArc::EvalRadiuses);
124 
125  timerRadius2 = new QTimer(this);
126  connect(timerRadius2, &QTimer::timeout, this, &DialogEllipticalArc::EvalRadiuses);
127 
128  timerF1 = new QTimer(this);
129  connect(timerF1, &QTimer::timeout, this, &DialogEllipticalArc::EvalAngles);
130 
131  timerF2 = new QTimer(this);
132  connect(timerF2, &QTimer::timeout, this, &DialogEllipticalArc::EvalAngles);
133 
134  timerRotationAngle = new QTimer(this);
135  connect(timerRotationAngle, &QTimer::timeout, this, &DialogEllipticalArc::EvalAngles);
136 
138 
139  FillComboBoxPoints(ui->centerPoint_ComboBox);
140 
141  int index = ui->lineType_ComboBox->findData(LineTypeNone);
142  if (index != -1)
143  {
144  ui->lineType_ComboBox->removeItem(index);
145  }
146 
147  index = ui->lineColor_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineColor());
148  if (index != -1)
149  {
150  ui->lineColor_ComboBox->setCurrentIndex(index);
151  }
152 
153  index = ui->lineWeight_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineWeight());
154  if (index != -1)
155  {
156  ui->lineWeight_ComboBox->setCurrentIndex(index);
157  }
158 
159  index = ui->lineType_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineType());
160  if (index != -1)
161  {
162  ui->lineType_ComboBox->setCurrentIndex(index);
163  }
164 
165  CheckState();
166 
167  connect(ui->toolButtonExprRadius1, &QPushButton::clicked, this, &DialogEllipticalArc::FXRadius1);
168  connect(ui->toolButtonExprRadius2, &QPushButton::clicked, this, &DialogEllipticalArc::FXRadius2);
169  connect(ui->toolButtonExprF1, &QPushButton::clicked, this, &DialogEllipticalArc::FXF1);
170  connect(ui->toolButtonExprF2, &QPushButton::clicked, this, &DialogEllipticalArc::FXF2);
171  connect(ui->toolButtonExprRotationAngle, &QPushButton::clicked, this, &DialogEllipticalArc::FXRotationAngle);
172 
173  connect(ui->plainTextEditRadius1, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::Radius1Changed);
174  connect(ui->plainTextEditRadius2, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::Radius2Changed);
175  connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::F1Changed);
176  connect(ui->plainTextEditF2, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::F2Changed);
177  connect(ui->plainTextEditRotationAngle, &QPlainTextEdit::textChanged,
179 
180  connect(ui->pushButtonGrowLengthRadius1, &QPushButton::clicked, this, &DialogEllipticalArc::DeployRadius1TextEdit);
181  connect(ui->pushButtonGrowLengthRadius2, &QPushButton::clicked, this, &DialogEllipticalArc::DeployRadius2TextEdit);
182  connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogEllipticalArc::DeployF1TextEdit);
183  connect(ui->pushButtonGrowLengthF2, &QPushButton::clicked, this, &DialogEllipticalArc::DeployF2TextEdit);
184  connect(ui->pushButtonGrowLengthRotationAngle, &QPushButton::clicked,
186 
187  connect(ui->centerPoint_ComboBox, &QComboBox::currentTextChanged, this, &DialogEllipticalArc::pointNameChanged);
188 
190 }
191 
192 //---------------------------------------------------------------------------------------------------------------------
194 {
195  delete ui;
196 }
197 
198 //---------------------------------------------------------------------------------------------------------------------
200 {
201  return m_arc;
202 }
203 
204 //---------------------------------------------------------------------------------------------------------------------
206 {
207  m_arc = arc;
208  ui->name_LineEdit->setText(qApp->TrVars()->VarToUser(m_arc.name()));
209 }
210 
211 //---------------------------------------------------------------------------------------------------------------------
212 /**
213  * @brief GetCenter return id of center point
214  * @return id id
215  */
217 {
218  return getCurrentObjectId(ui->centerPoint_ComboBox);
219 }
220 
221 //---------------------------------------------------------------------------------------------------------------------
222 /**
223  * @brief SetCenter set id of center point
224  * @param value id
225  */
226 void DialogEllipticalArc::SetCenter(const quint32 &value)
227 {
228  ChangeCurrentData(ui->centerPoint_ComboBox, value);
229  vis->setObject1Id(value);
230 }
231 
232 //---------------------------------------------------------------------------------------------------------------------
233 /**
234  * @brief GetRadius1 return formula of radius1
235  * @return formula
236  */
238 {
239  return qApp->TrVars()->TryFormulaFromUser(radius1, qApp->Settings()->GetOsSeparator());
240 }
241 
242 //---------------------------------------------------------------------------------------------------------------------
243 /**
244  * @brief SetRadius1 set formula of radius1
245  * @param value formula
246  */
247 void DialogEllipticalArc::SetRadius1(const QString &value)
248 {
249  radius1 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
250  // increase height if needed.
251  if (radius1.length() > 80)
252  {
253  this->DeployRadius1TextEdit();
254  }
255  ui->plainTextEditRadius1->setPlainText(radius1);
256 
257  VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
258  SCASSERT(path != nullptr)
259  path->setRadius1(radius1);
260 
261  MoveCursorToEnd(ui->plainTextEditRadius1);
262 }
263 
264 //---------------------------------------------------------------------------------------------------------------------
265 /**
266  * @brief GetRadius2 return formula of radius2
267  * @return formula
268  */
270 {
271  return qApp->TrVars()->TryFormulaFromUser(radius2, qApp->Settings()->GetOsSeparator());
272 }
273 
274 //---------------------------------------------------------------------------------------------------------------------
275 /**
276  * @brief SetRadius2 set formula of radius2
277  * @param value formula
278  */
279 void DialogEllipticalArc::SetRadius2(const QString &value)
280 {
281  radius2 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
282  // increase height if needed.
283  if (radius2.length() > 80)
284  {
285  this->DeployRadius2TextEdit();
286  }
287  ui->plainTextEditRadius2->setPlainText(radius2);
288 
289  VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
290  SCASSERT(path != nullptr)
291  path->setRadius2(radius2);
292 
293  MoveCursorToEnd(ui->plainTextEditRadius2);
294 }
295 
296 //---------------------------------------------------------------------------------------------------------------------
297 /**
298  * @brief GetF1 return formula first angle of elliptical arc
299  * @return formula
300  */
302 {
303  return qApp->TrVars()->TryFormulaFromUser(f1, qApp->Settings()->GetOsSeparator());
304 }
305 
306 //---------------------------------------------------------------------------------------------------------------------
307 /**
308  * @brief SetF1 set formula first angle of elliptical arc
309  * @param value formula
310  */
311 void DialogEllipticalArc::SetF1(const QString &value)
312 {
313  f1 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
314  // increase height if needed.
315  if (f1.length() > 80)
316  {
317  this->DeployF1TextEdit();
318  }
319  ui->plainTextEditF1->setPlainText(f1);
320 
321  VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
322  SCASSERT(path != nullptr)
323  path->setF1(f1);
324 
325  MoveCursorToEnd(ui->plainTextEditF1);
326 }
327 
328 //---------------------------------------------------------------------------------------------------------------------
329 /**
330  * @brief GetF2 return formula second angle of elliptical arc
331  * @return formula
332  */
334 {
335  return qApp->TrVars()->TryFormulaFromUser(f2, qApp->Settings()->GetOsSeparator());
336 }
337 
338 //---------------------------------------------------------------------------------------------------------------------
339 /**
340  * @brief SetF2 set formula second angle of elliptical arc
341  * @param value formula
342  */
343 void DialogEllipticalArc::SetF2(const QString &value)
344 {
345  f2 = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
346  // increase height if needed.
347  if (f2.length() > 80)
348  {
349  this->DeployF2TextEdit();
350  }
351  ui->plainTextEditF2->setPlainText(f2);
352 
353  VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
354  SCASSERT(path != nullptr)
355  path->setF2(f2);
356 
357  MoveCursorToEnd(ui->plainTextEditF2);
358 }
359 
360 //---------------------------------------------------------------------------------------------------------------------
361 /**
362  * @brief GetRotationAngle return formula rotation angle of elliptical arc
363  * @return formula
364  */
366 {
367  return qApp->TrVars()->TryFormulaFromUser(rotationAngle, qApp->Settings()->GetOsSeparator());
368 }
369 
370 //---------------------------------------------------------------------------------------------------------------------
371 /**
372  * @brief SetRotationAngle set formula rotation angle of elliptical arc
373  * @param value formula
374  */
375 void DialogEllipticalArc::SetRotationAngle(const QString &value)
376 {
377  rotationAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
378  // increase height if needed.
379  if (rotationAngle.length() > 80)
380  {
382  }
383  ui->plainTextEditRotationAngle->setPlainText(rotationAngle);
384 
385  VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
386  SCASSERT(path != nullptr)
388 
389  MoveCursorToEnd(ui->plainTextEditRotationAngle);
390 }
391 
392 //---------------------------------------------------------------------------------------------------------------------
394 {
395  return GetComboBoxCurrentData(ui->lineType_ComboBox, LineTypeSolidLine);
396 }
397 
398 //---------------------------------------------------------------------------------------------------------------------
399 void DialogEllipticalArc::setPenStyle(const QString &value)
400 {
401  ChangeCurrentData(ui->lineType_ComboBox, value);
402 }
403 
404 //---------------------------------------------------------------------------------------------------------------------
405 /**
406  * @brief getLineWeight return weight of the lines
407  * @return type
408  */
410 {
411  return GetComboBoxCurrentData(ui->lineWeight_ComboBox, "0.35");
412 }
413 
414 //---------------------------------------------------------------------------------------------------------------------
415 /**
416  * @brief setLineWeight set weight of the lines
417  * @param value type
418  */
419 void DialogEllipticalArc::setLineWeight(const QString &value)
420 {
421  ChangeCurrentData(ui->lineWeight_ComboBox, value);
422  vis->setLineWeight(value);
423 }
424 //---------------------------------------------------------------------------------------------------------------------
425 /**
426  * @brief GetColor return color of elliptical arc
427  * @return formula
428  */
430 {
431  return GetComboBoxCurrentData(ui->lineColor_ComboBox, ColorBlack);
432 }
433 
434 //---------------------------------------------------------------------------------------------------------------------
435 /**
436  * @brief setLineColor set color of elliptical arc
437  * @param value formula
438  */
439 void DialogEllipticalArc::setLineColor(const QString &value)
440 {
441  ChangeCurrentData(ui->lineColor_ComboBox, value);
442 }
443 
444 //---------------------------------------------------------------------------------------------------------------------
445 /**
446  * @brief EvalRadiuses calculate value of radiuses
447  */
449 {
450  labelEditFormula = ui->labelEditRadius1;
451  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
452  const qreal radius_1 = Eval(ui->plainTextEditRadius1->toPlainText(), flagRadius1, ui->labelResultRadius1, postfix);
453 
454  if (radius_1 < 0)
455  {
456  flagRadius1 = false;
457  ChangeColor(labelEditFormula, Qt::red);
458  ui->labelResultRadius1->setText(tr("Error"));
459  ui->labelResultRadius1->setToolTip(tr("Radius can't be negative"));
460 
462  }
463 
464  labelEditFormula = ui->labelEditRadius2;
465  const qreal radius_2 = Eval(ui->plainTextEditRadius2->toPlainText(), flagRadius2, ui->labelResultRadius2, postfix);
466  if (radius_2 < 0)
467  {
468  flagRadius2 = false;
469  ChangeColor(labelEditFormula, Qt::red);
470  ui->labelResultRadius2->setText(tr("Error"));
471  ui->labelResultRadius2->setToolTip(tr("Radius can't be negative"));
472 
474  }
475 }
476 
477 //---------------------------------------------------------------------------------------------------------------------
478 /**
479  * @brief EvalAngles calculate value of angles
480  */
482 {
483  labelEditFormula = ui->labelEditF1;
484  angleF1 = Eval(ui->plainTextEditF1->toPlainText(), flagF1, ui->labelResultF1, degreeSymbol, false);
485 
486  labelEditFormula = ui->labelEditF2;
487  angleF2 = Eval(ui->plainTextEditF2->toPlainText(), flagF2, ui->labelResultF2, degreeSymbol, false);
488 
489  labelEditFormula = ui->labelEditRotationAngle;
490  angleRotation = Eval(ui->plainTextEditRotationAngle->toPlainText(), flagRotationAngle,
491  ui->labelResultRotationAngle, degreeSymbol, false);
492 
493  CheckAngles();
494 }
495 
496 //---------------------------------------------------------------------------------------------------------------------
498 {
499  if (static_cast<int>(angleF1) == INT_MIN || static_cast<int>(angleF2) == INT_MIN)
500  {
501  return;
502  }
503 
505  {
506  flagF1 = false;
507  ChangeColor(ui->labelEditF1, Qt::red);
508  ui->labelResultF1->setText(tr("Error"));
509  ui->labelResultF1->setToolTip(tr("Angles equal"));
510 
511  flagF2 = false;
512  ChangeColor(ui->labelEditF2, Qt::red);
513  ui->labelResultF2->setText(tr("Error"));
514  ui->labelResultF2->setToolTip(tr("Angles equal"));
515  }
516 
518 }
519 
520 //---------------------------------------------------------------------------------------------------------------------
522 {
523  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
524  dialog->setWindowTitle(tr("Edit radius1"));
525  dialog->SetFormula(GetRadius1());
526  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
527  if (dialog->exec() == QDialog::Accepted)
528  {
529  SetRadius1(dialog->GetFormula());
530  }
531  delete dialog;
532 }
533 
534 //---------------------------------------------------------------------------------------------------------------------
536 {
537  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
538  dialog->setWindowTitle(tr("Edit radius2"));
539  dialog->SetFormula(GetRadius2());
540  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
541  if (dialog->exec() == QDialog::Accepted)
542  {
543  SetRadius2(dialog->GetFormula());
544  }
545  delete dialog;
546 }
547 
548 //---------------------------------------------------------------------------------------------------------------------
550 {
551  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
552  dialog->setWindowTitle(tr("Edit first angle"));
553  dialog->SetFormula(GetF1());
554  dialog->setPostfix(degreeSymbol);
555  if (dialog->exec() == QDialog::Accepted)
556  {
557  SetF1(dialog->GetFormula());
558  }
559  delete dialog;
560 }
561 
562 //---------------------------------------------------------------------------------------------------------------------
564 {
565  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
566  dialog->setWindowTitle(tr("Edit second angle"));
567  dialog->SetFormula(GetF2());
568  dialog->setPostfix(degreeSymbol);
569  if (dialog->exec() == QDialog::Accepted)
570  {
571  SetF2(dialog->GetFormula());
572  }
573  delete dialog;
574 }
575 
576 //---------------------------------------------------------------------------------------------------------------------
578 {
579  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
580  dialog->setWindowTitle(tr("Edit rotation angle"));
581  dialog->SetFormula(GetRotationAngle());
582  dialog->setPostfix(degreeSymbol);
583  if (dialog->exec() == QDialog::Accepted)
584  {
585  SetRotationAngle(dialog->GetFormula());
586  }
587  delete dialog;
588 }
589 
590 //---------------------------------------------------------------------------------------------------------------------
591 /**
592  * @brief Radius1Changed after change formula of radius1 calculate value and show result
593  */
595 {
596  labelEditFormula = ui->labelEditRadius1;
597  labelResultCalculation = ui->labelResultRadius1;
598  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
599  ValFormulaChanged(flagRadius1, ui->plainTextEditRadius1, timerRadius1, postfix);
600 }
601 
602 //---------------------------------------------------------------------------------------------------------------------
603 /**
604  * @brief Radius2Changed after change formula of radius2 calculate value and show result
605  */
607 {
608  labelEditFormula = ui->labelEditRadius2;
609  labelResultCalculation = ui->labelResultRadius2;
610  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
611  ValFormulaChanged(flagRadius2, ui->plainTextEditRadius2, timerRadius2, postfix);
612 }
613 
614 //---------------------------------------------------------------------------------------------------------------------
615 /**
616  * @brief F1Changed after change formula of first angle calculate value and show result
617  */
619 {
620  labelEditFormula = ui->labelEditF1;
621  labelResultCalculation = ui->labelResultF1;
622  ValFormulaChanged(flagF1, ui->plainTextEditF1, timerF1, degreeSymbol);
623 }
624 
625 //---------------------------------------------------------------------------------------------------------------------
626 /**
627  * @brief F2Changed after change formula of second angle calculate value and show result
628  */
630 {
631  labelEditFormula = ui->labelEditF2;
632  labelResultCalculation = ui->labelResultF2;
633  ValFormulaChanged(flagF2, ui->plainTextEditF2, timerF2, degreeSymbol);
634 }
635 
636 //---------------------------------------------------------------------------------------------------------------------
637 /**
638  * @brief RotationAngleChanged after change formula of rotation angle calculate value and show result
639  */
641 {
642  labelEditFormula = ui->labelEditRotationAngle;
643  labelResultCalculation = ui->labelResultF2;
644  ValFormulaChanged(flagRotationAngle, ui->plainTextEditRotationAngle, timerRotationAngle, degreeSymbol);
645 }
646 
647 //---------------------------------------------------------------------------------------------------------------------
649 {
650  DeployFormula(ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
651  collapseFormula(ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
652  collapseFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
653  collapseFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
654  collapseFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
655 }
656 
657 //---------------------------------------------------------------------------------------------------------------------
659 {
660  collapseFormula(ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
661  DeployFormula(ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
662  collapseFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
663  collapseFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
664  collapseFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
665 }
666 
667 //---------------------------------------------------------------------------------------------------------------------
669 {
670  collapseFormula(ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
671  collapseFormula(ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
672  DeployFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
673  collapseFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
674  collapseFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
675 }
676 
677 //---------------------------------------------------------------------------------------------------------------------
679 {
680  collapseFormula(ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
681  collapseFormula(ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
682  collapseFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
683  DeployFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
684  collapseFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
685 }
686 
687 //---------------------------------------------------------------------------------------------------------------------
689 {
690  collapseFormula(ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
691  collapseFormula(ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
692  collapseFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
693  collapseFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
694  DeployFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
695 }
696 
697 //---------------------------------------------------------------------------------------------------------------------
698 /**
699  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
700  * @param id id of point or detail
701  * @param type type of object
702  */
703 void DialogEllipticalArc::ChosenObject(quint32 id, const SceneObject &type)
704 {
705  if (prepare == false)// After first choose we ignore all objects
706  {
707  if (type == SceneObject::Point)
708  {
709  if (SetObject(id, ui->centerPoint_ComboBox, ""))
710  {
711  vis->VisualMode(id);
712  prepare = true;
713  this->setModal(true);
714  this->show();
715  }
716  }
717  }
718 }
719 
720 //---------------------------------------------------------------------------------------------------------------------
722 {
723  QColor color = okColor;
724 
725  flagError = true;
726  color = okColor;
727 
728  if (getCurrentObjectId(ui->centerPoint_ComboBox) == m_arc.GetCenter().id())
729  {
730  newDuplicate = -1;
731  ui->name_LineEdit->setText(qApp->TrVars()->VarToUser(m_arc.name()));
732  }
733  else
734  {
735  VEllipticalArc arc(*data->GeometricObject<VPointF>(getCurrentObjectId(ui->centerPoint_ComboBox)),
736  GetRadius1().toDouble(),
737  GetRadius2().toDouble(),
738  GetF1().toDouble(),
739  GetF2().toDouble(),
740  GetRotationAngle().toDouble());
741 
742  if (!data->IsUnique(arc.name()))
743  {
744  newDuplicate = static_cast<qint32>(DNumber(arc.name()));
745  arc.SetDuplicate(static_cast<quint32>(newDuplicate));
746  }
747  ui->name_LineEdit->setText(qApp->TrVars()->VarToUser(arc.name() + "_" + QString().setNum(m_Id)));
748  }
749 
750  ChangeColor(ui->name_Label, color);
751  ChangeColor(ui->centerPoint_Label, color);
752  CheckState();
753 }
754 
755 //---------------------------------------------------------------------------------------------------------------------
756 /**
757  * @brief CheckState if all is right enable button ok
758  */
760 {
761  SCASSERT(ok_Button != nullptr)
763  SCASSERT(apply_Button != nullptr)
765 }
766 
767 //---------------------------------------------------------------------------------------------------------------------
769 {
770  AddVisualization<VisToolEllipticalArc>();
771 }
772 
773 //---------------------------------------------------------------------------------------------------------------------
775 {
776  radius1 = ui->plainTextEditRadius1->toPlainText();
777  radius1.replace("\n", " ");
778  radius2 = ui->plainTextEditRadius2->toPlainText();
779  radius2.replace("\n", " ");
780  f1 = ui->plainTextEditF1->toPlainText();
781  f1.replace("\n", " ");
782  f2 = ui->plainTextEditF2->toPlainText();
783  f2.replace("\n", " ");
784  rotationAngle = ui->plainTextEditRotationAngle->toPlainText();
785  rotationAngle.replace("\n", " ");
786 
787  VisToolEllipticalArc *path = qobject_cast<VisToolEllipticalArc *>(vis);
788  SCASSERT(path != nullptr)
789 
790  path->setObject1Id(GetCenter());
791  path->setRadius1(radius1);
792  path->setRadius2(radius2);
793  path->setF1(f1);
794  path->setF2(f2);
796  path->RefreshGeometry();
797 }
798 
799 //---------------------------------------------------------------------------------------------------------------------
800 void DialogEllipticalArc::closeEvent(QCloseEvent *event)
801 {
802  ui->plainTextEditRadius1->blockSignals(true);
803  ui->plainTextEditRadius2->blockSignals(true);
804  ui->plainTextEditF1->blockSignals(true);
805  ui->plainTextEditF2->blockSignals(true);
806  ui->plainTextEditRotationAngle->blockSignals(true);
807  DialogTool::closeEvent(event);
808 }
809 
810 //---------------------------------------------------------------------------------------------------------------------
811 void DialogEllipticalArc::collapseFormula(QPlainTextEdit *textEdit, QPushButton *pushButton, int height)
812 {
813  SCASSERT(textEdit != nullptr)
814  SCASSERT(pushButton != nullptr)
815 
816  const QTextCursor cursor = textEdit->textCursor();
817 
818  setMaximumWidth(260);
819  textEdit->setFixedHeight(height);
820  pushButton->setIcon(QIcon::fromTheme("go-down", QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
821  setUpdatesEnabled(false);
822  repaint();
823  setUpdatesEnabled(true);
824  textEdit->setFocus();
825  textEdit->setTextCursor(cursor);
826 }
QString rotationAngle
rotationAngle formula of rotation angle
void DeployRadius1TextEdit()
DeployFormulaTextEdit grow or shrink formula input.
void collapseFormula(QPlainTextEdit *textEdit, QPushButton *pushButton, int height)
void SetRadius1(const QString &value)
SetRadius1 set formula of radius1.
void Radius1Changed()
Radius1Changed after change formula of radius1 calculate value and show result.
quint32 GetCenter() const
GetCenter return id of center point.
void SetF1(const QString &value)
SetF1 set formula first angle of elliptical arc.
void setPenStyle(const QString &value)
void SetCenter(const quint32 &value)
SetCenter set id of center point.
DialogEllipticalArc(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogEllipticalArc create dialog.
virtual void CheckState() Q_DECL_FINAL
CheckState if all is right enable button ok.
void SetRotationAngle(const QString &value)
SetRotationAngle set formula rotation angle of elliptical arc.
VEllipticalArc getArc() const
void F1Changed()
F1Changed after change formula of first angle calculate value and show result.
QString radius2
radius2 formula of radius2
QString GetF2() const
GetF2 return formula second angle of elliptical arc.
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
void setArc(const VEllipticalArc &arc)
QTimer * timerRadius1
timerRadius1 timer of check formula of radius1
Ui::DialogEllipticalArc * ui
ui keeps information about user interface
int formulaBaseHeightRadius1
formulaBaseHeight base height defined by dialogui
void RotationAngleChanged()
RotationAngleChanged after change formula of rotation angle calculate value and show result.
QString GetRadius1() const
GetRadius1 return formula of radius1.
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.
QString f2
f2 formula of second angle
QString getLineColor() const
GetColor return color of elliptical arc.
QTimer * timerRotationAngle
timerRotationAngle timer of check formula of rotation angle
void SetF2(const QString &value)
SetF2 set formula second angle of elliptical arc.
void setLineWeight(const QString &value)
setLineWeight set weight of the lines
QString getLineWeight() const
getLineWeight return weight of the lines
QTimer * timerF2
timerF2 timer of check formula of second angle
void EvalAngles()
EvalAngles calculate value of angles.
bool flagRotationAngle
flagRotationAngle true if value of rotation angle is correct
QString f1
f1 formula of first angle
bool flagRadius1
flagRadius1 true if value of radius1 is correct
void Radius2Changed()
Radius2Changed after change formula of radius2 calculate value and show result.
bool flagF2
flagF2 true if value of second angle is correct
virtual void ShowVisualization() Q_DECL_OVERRIDE
QTimer * timerF1
timerF1 timer of check formula of first angle
QString GetF1() const
GetF1 return formula first angle of elliptical arc.
void F2Changed()
F2Changed after change formula of second angle calculate value and show result.
QTimer * timerRadius2
timerRadius2 timer of check formula of radius2
QString GetRotationAngle() const
GetRotationAngle return formula rotation angle of elliptical arc.
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
void setLineColor(const QString &value)
setLineColor set color of elliptical arc
void EvalRadiuses()
EvalRadiuses calculate value of radiuses.
bool flagF1
flagF1 true if value of first angle is correct
virtual ~DialogEllipticalArc() Q_DECL_OVERRIDE
bool flagRadius2
flagRadius2 true if value of radius2 is correct
QString GetRadius2() const
GetRadius2 return formula of radius2.
QString radius1
radius1 formula of radius1
void SetRadius2(const QString &value)
SetRadius2 set formula of radius2.
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void ChangeCurrentData(QComboBox *box, const QVariant &value) const
ChangeCurrentData select item in combobox by id.
Definition: dialogtool.cpp:419
quint32 DNumber(const QString &baseName) const
Definition: dialogtool.cpp:476
const QColor okColor
Definition: dialogtool.h:219
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 MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
Definition: dialogtool.cpp:432
QPushButton * ok_Button
ok_Button button ok
Definition: dialogtool.h:199
qreal Eval(const QString &text, bool &flag, QLabel *label, const QString &postfix, bool checkZero=true, bool checkLessThanZero=false)
Eval evaluate formula and show result.
Definition: dialogtool.cpp:805
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
Definition: dialogtool.cpp:192
void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer, const QString &postfix=QString())
ValFormulaChanged handle change formula.
Definition: dialogtool.cpp:744
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
QPushButton * apply_Button
apply_Button button apply
Definition: dialogtool.h:202
quint32 toolId
Definition: dialogtool.h:225
QLabel * labelEditFormula
labelEditFormula label used when need show wrong formula
Definition: dialogtool.h:217
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
QLabel * labelResultCalculation
labelResultCalculation label with result of calculation
Definition: dialogtool.h:211
QPointer< Visualization > vis
Definition: dialogtool.h:236
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)
void SetDuplicate(quint32 number)
The VContainer class container of all variables.
Definition: vcontainer.h:141
static bool IsUnique(const QString &name)
Definition: vcontainer.cpp:585
static quint32 getId()
Definition: vcontainer.cpp:241
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
virtual VPointF GetCenter() const Q_DECL_OVERRIDE
virtual QString name() const
name return name graphical object.
Definition: vgobject.cpp:148
quint32 id() const
id return id object.
Definition: vgobject.cpp:205
The VPointF class keep data of point.
Definition: vpointf.h:75
void setF1(const QString &expression)
void setRadius2(const QString &expression)
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setF2(const QString &expression)
void setRadius1(const QString &expression)
void setRotationAngle(const QString &expression)
void setObject1Id(const quint32 &value)
const QString degreeSymbol
Definition: def.cpp:196
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define SCASSERT(cond)
Definition: def.h:317
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
Definition: def.h:490
SceneObject
Definition: def.h:103
const QString LineTypeSolidLine
Definition: ifcdef.cpp:159
const QString ColorBlack
Definition: ifcdef.cpp:373
const QString LineTypeNone
Definition: ifcdef.cpp:158
#define qApp
Definition: vapplication.h:67