Seamly2D
Code documentation
dialogspline.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 dialogspline.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 "dialogspline.h"
53 
54 #include <QColor>
55 #include <QComboBox>
56 #include <QDialog>
57 #include <QHash>
58 #include <QLabel>
59 #include <QLineEdit>
60 #include <QPlainTextEdit>
61 #include <QPointer>
62 #include <QPushButton>
63 #include <QSet>
64 #include <QTimer>
65 #include <QToolButton>
66 #include <Qt>
67 #include <new>
68 
69 #include "../../tools/vabstracttool.h"
70 #include "../../visualization/visualization.h"
71 #include "../../visualization/path/vistoolspline.h"
72 #include "../ifc/xml/vdomdocument.h"
73 #include "../support/edit_formula_dialog.h"
74 #include "../vgeometry/vpointf.h"
75 #include "../vgeometry/vspline.h"
76 #include "../vmisc/vabstractapplication.h"
77 #include "../vmisc/vcommonsettings.h"
78 #include "../vpatterndb/vcontainer.h"
79 #include "../vwidgets/vmaingraphicsscene.h"
80 #include "ui_dialogspline.h"
81 #include "vtranslatevars.h"
82 
83 //---------------------------------------------------------------------------------------------------------------------
84 /**
85  * @brief DialogSpline create dialog
86  * @param data container with data
87  * @param parent parent widget
88  */
89 DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
90  : DialogTool(data, toolId, parent)
91  , ui(new Ui::DialogSpline)
92  , spl()
93  , newDuplicate(-1)
94  , formulaBaseHeightAngle1(0)
95  , formulaBaseHeightAngle2(0)
96  , formulaBaseHeightLength1(0)
97  , formulaBaseHeightLength2(0)
98  , timerAngle1(new QTimer(this))
99  , timerAngle2(new QTimer(this))
100  , timerLength1(new QTimer(this))
101  , timerLength2(new QTimer(this))
102  , flagAngle1(false)
103  , flagAngle2(false)
104  , flagLength1(false)
105  , flagLength2(false)
106 {
107  ui->setupUi(this);
108  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
109  setWindowIcon(QIcon(":/toolicon/32x32/spline.png"));
110 
111  plainTextEditFormula = ui->plainTextEditAngle1F;
112 
113  formulaBaseHeightAngle1 = ui->plainTextEditAngle1F->height();
114  formulaBaseHeightAngle2 = ui->plainTextEditAngle2F->height();
115  formulaBaseHeightLength1 = ui->plainTextEditLength1F->height();
116  formulaBaseHeightLength2 = ui->plainTextEditLength2F->height();
117 
118  ui->plainTextEditAngle1F->installEventFilter(this);
119  ui->plainTextEditAngle2F->installEventFilter(this);
120  ui->plainTextEditLength1F->installEventFilter(this);
121  ui->plainTextEditLength2F->installEventFilter(this);
122 
123  connect(timerAngle1, &QTimer::timeout, this, &DialogSpline::EvalAngle1);
124  connect(timerAngle2, &QTimer::timeout, this, &DialogSpline::EvalAngle2);
125  connect(timerLength1, &QTimer::timeout, this, &DialogSpline::EvalLength1);
126  connect(timerLength2, &QTimer::timeout, this, &DialogSpline::EvalLength2);
127 
129 
130  FillComboBoxPoints(ui->comboBoxP1);
131  FillComboBoxPoints(ui->comboBoxP4);
132 
133  int index = ui->lineType_ComboBox->findData(LineTypeNone);
134  if (index != -1)
135  {
136  ui->lineType_ComboBox->removeItem(index);
137  }
138 
139  index = ui->lineColor_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineColor());
140  if (index != -1)
141  {
142  ui->lineColor_ComboBox->setCurrentIndex(index);
143  }
144 
145  index = ui->lineWeight_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineWeight());
146  if (index != -1)
147  {
148  ui->lineWeight_ComboBox->setCurrentIndex(index);
149  }
150 
151  index = ui->lineType_ComboBox->findData(qApp->getCurrentDocument()->getDefaultLineType());
152  if (index != -1)
153  {
154  ui->lineType_ComboBox->setCurrentIndex(index);
155  }
156 
157  CheckState();
158 
159  connect(ui->comboBoxP1, &QComboBox::currentTextChanged, this, &DialogSpline::PointNameChanged);
160  connect(ui->comboBoxP4, &QComboBox::currentTextChanged, this, &DialogSpline::PointNameChanged);
161 
162  connect(ui->toolButtonExprAngle1, &QPushButton::clicked, this, &DialogSpline::FXAngle1);
163  connect(ui->toolButtonExprAngle2, &QPushButton::clicked, this, &DialogSpline::FXAngle2);
164  connect(ui->toolButtonExprLength1, &QPushButton::clicked, this, &DialogSpline::FXLength1);
165  connect(ui->toolButtonExprLength2, &QPushButton::clicked, this, &DialogSpline::FXLength2);
166 
167  connect(ui->plainTextEditAngle1F, &QPlainTextEdit::textChanged, this, &DialogSpline::Angle1Changed);
168  connect(ui->plainTextEditAngle2F, &QPlainTextEdit::textChanged, this, &DialogSpline::Angle2Changed);
169  connect(ui->plainTextEditLength1F, &QPlainTextEdit::textChanged, this, &DialogSpline::Length1Changed);
170  connect(ui->plainTextEditLength2F, &QPlainTextEdit::textChanged, this, &DialogSpline::Length2Changed);
171 
172  connect(ui->pushButtonGrowAngle1, &QPushButton::clicked, this, &DialogSpline::DeployAngle1TextEdit);
173  connect(ui->pushButtonGrowAngle2, &QPushButton::clicked, this, &DialogSpline::DeployAngle2TextEdit);
174  connect(ui->pushButtonGrowLength1, &QPushButton::clicked, this, &DialogSpline::DeployLength1TextEdit);
175  connect(ui->pushButtonGrowLength2, &QPushButton::clicked, this, &DialogSpline::DeployLength2TextEdit);
176 
177  vis = new VisToolSpline(data);
178  auto path = qobject_cast<VisToolSpline *>(vis);
179  SCASSERT(path != nullptr)
180 
181  auto scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
182  SCASSERT(scene != nullptr)
185 }
186 
187 //---------------------------------------------------------------------------------------------------------------------
189 {
190  delete ui;
191 }
192 
193 //---------------------------------------------------------------------------------------------------------------------
194 /**
195  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
196  * @param id id of point or detail
197  * @param type type of object
198  */
199 void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
200 {
201  if (prepare == false)// After first choose we ignore all objects
202  {
203  if (type == SceneObject::Point)
204  {
205  auto *path = qobject_cast<VisToolSpline *>(vis);
206  SCASSERT(path != nullptr)
207 
208  switch (number)
209  {
210  case 0:
211  if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
212  {
213  ++number;
214  path->VisualMode(id);
215  }
216  break;
217  case 1:
218  {
219  if (getCurrentObjectId(ui->comboBoxP1) != id)
220  {
221  if (SetObject(id, ui->comboBoxP4, ""))
222  {
223  ++number;
224 
225  path->setObject4Id(id);
226  path->RefreshGeometry();
227  prepare = true;
228  }
229  }
230  break;
231  }
232  default:
233  break;
234  }
235  }
236  }
237 }
238 
239 //---------------------------------------------------------------------------------------------------------------------
241 {
242  const quint32 d = spl.GetDuplicate();//Save previous value
243  spl = CurrentSpline();
244 
245  newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast<quint32>(newDuplicate));
246 
247  auto path = qobject_cast<VisToolSpline *>(vis);
248  SCASSERT(path != nullptr)
249 
250  path->setObject1Id(GetP1()->id());
251  path->setObject4Id(GetP4()->id());
252  path->SetAngle1(spl.GetStartAngle());
253  path->SetAngle2(spl.GetEndAngle());
254  path->SetKAsm1(spl.GetKasm1());
255  path->SetKAsm2(spl.GetKasm2());
256  path->SetKCurve(spl.GetKcurve());
257  path->SetMode(Mode::Show);
258  path->RefreshGeometry();
259 }
260 
261 //---------------------------------------------------------------------------------------------------------------------
262 void DialogSpline::closeEvent(QCloseEvent *event)
263 {
264  ui->plainTextEditAngle1F->blockSignals(true);
265  ui->plainTextEditAngle2F->blockSignals(true);
266  ui->plainTextEditLength1F->blockSignals(true);
267  ui->plainTextEditLength2F->blockSignals(true);
268  DialogTool::closeEvent(event);
269 }
270 
271 //---------------------------------------------------------------------------------------------------------------------
273 {
274  DeployFormula(ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1);
275 }
276 
277 //---------------------------------------------------------------------------------------------------------------------
279 {
280  DeployFormula(ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2);
281 }
282 
283 //---------------------------------------------------------------------------------------------------------------------
285 {
286  DeployFormula(ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1);
287 }
288 
289 //---------------------------------------------------------------------------------------------------------------------
291 {
292  DeployFormula(ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2);
293 }
294 
295 //---------------------------------------------------------------------------------------------------------------------
297 {
298  labelEditFormula = ui->labelEditAngle1;
299  labelResultCalculation = ui->labelResultAngle1;
300  ValFormulaChanged(flagAngle1, ui->plainTextEditAngle1F, timerAngle1, degreeSymbol);
301 }
302 
303 //---------------------------------------------------------------------------------------------------------------------
305 {
306  labelEditFormula = ui->labelEditAngle2;
307  labelResultCalculation = ui->labelResultAngle2;
308  ValFormulaChanged(flagAngle2, ui->plainTextEditAngle2F, timerAngle2, degreeSymbol);
309 }
310 
311 //---------------------------------------------------------------------------------------------------------------------
313 {
314  labelEditFormula = ui->labelEditLength1;
315  labelResultCalculation = ui->labelResultLength1;
316  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
317  ValFormulaChanged(flagLength1, ui->plainTextEditLength1F, timerLength1, postfix);
318 }
319 
320 //---------------------------------------------------------------------------------------------------------------------
322 {
323  labelEditFormula = ui->labelEditLength2;
324  labelResultCalculation = ui->labelResultLength2;
325  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
326  ValFormulaChanged(flagLength2, ui->plainTextEditLength2F, timerLength2, postfix);
327 }
328 
329 //---------------------------------------------------------------------------------------------------------------------
331 {
332  auto dialog = new EditFormulaDialog(data, toolId, this);
333  dialog->setWindowTitle(tr("Edit first control point angle"));
334  QString angle1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText(),
335  qApp->Settings()->GetOsSeparator());
336  dialog->SetFormula(angle1F);
337  dialog->setPostfix(degreeSymbol);
338  if (dialog->exec() == QDialog::Accepted)
339  {
340  angle1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
341  // increase height if needed.
342  if (angle1F.length() > 80)
343  {
345  }
346  ui->plainTextEditAngle1F->setPlainText(angle1F);
347  MoveCursorToEnd(ui->plainTextEditAngle1F);
348  }
349  delete dialog;
350 }
351 
352 //---------------------------------------------------------------------------------------------------------------------
354 {
355  auto dialog = new EditFormulaDialog(data, toolId, this);
356  dialog->setWindowTitle(tr("Edit second control point angle"));
357  QString angle2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText(),
358  qApp->Settings()->GetOsSeparator());
359  dialog->SetFormula(angle2F);
360  dialog->setPostfix(degreeSymbol);
361  if (dialog->exec() == QDialog::Accepted)
362  {
363  angle2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
364  // increase height if needed.
365  if (angle2F.length() > 80)
366  {
368  }
369  ui->plainTextEditAngle2F->setPlainText(angle2F);
370  MoveCursorToEnd(ui->plainTextEditAngle2F);
371  }
372  delete dialog;
373 }
374 
375 //---------------------------------------------------------------------------------------------------------------------
377 {
378  auto dialog = new EditFormulaDialog(data, toolId, this);
379  dialog->setWindowTitle(tr("Edit first control point length"));
380  QString length1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText(),
381  qApp->Settings()->GetOsSeparator());
382  dialog->SetFormula(length1F);
383  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
384  if (dialog->exec() == QDialog::Accepted)
385  {
386  length1F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
387  // increase height if needed.
388  if (length1F.length() > 80)
389  {
391  }
392  ui->plainTextEditLength1F->setPlainText(length1F);
393  MoveCursorToEnd(ui->plainTextEditLength1F);
394  }
395  delete dialog;
396 }
397 
398 //---------------------------------------------------------------------------------------------------------------------
400 {
401  auto dialog = new EditFormulaDialog(data, toolId, this);
402  dialog->setWindowTitle(tr("Edit second control point length"));
403  QString length2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText(),
404  qApp->Settings()->GetOsSeparator());
405  dialog->SetFormula(length2F);
406  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
407  if (dialog->exec() == QDialog::Accepted)
408  {
409  length2F = qApp->TrVars()->FormulaToUser(dialog->GetFormula(), qApp->Settings()->GetOsSeparator());
410  // increase height if needed.
411  if (length2F.length() > 80)
412  {
414  }
415  ui->plainTextEditLength2F->setPlainText(length2F);
416  MoveCursorToEnd(ui->plainTextEditLength2F);
417  }
418  delete dialog;
419 }
420 
421 //---------------------------------------------------------------------------------------------------------------------
423 {
424  return data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP1));
425 }
426 
427 //---------------------------------------------------------------------------------------------------------------------
429 {
430  return data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP4));
431 }
432 
433 //---------------------------------------------------------------------------------------------------------------------
435 {
436  labelEditFormula = ui->labelEditAngle1;
437  Eval(ui->plainTextEditAngle1F->toPlainText(), flagAngle1, ui->labelResultAngle1, degreeSymbol, false);
438 }
439 
440 //---------------------------------------------------------------------------------------------------------------------
442 {
443  labelEditFormula = ui->labelEditAngle2;
444  Eval(ui->plainTextEditAngle2F->toPlainText(), flagAngle2, ui->labelResultAngle2, degreeSymbol, false);
445 }
446 
447 //---------------------------------------------------------------------------------------------------------------------
449 {
450  labelEditFormula = ui->labelEditLength1;
451  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
452  const qreal length1 = Eval(ui->plainTextEditLength1F->toPlainText(), flagLength1, ui->labelResultLength1, postfix,
453  false);
454 
455  if (length1 < 0)
456  {
457  flagLength1 = false;
458  ChangeColor(labelEditFormula, Qt::red);
459  ui->labelResultLength1->setText(tr("Error") + " (" + postfix + ")");
460  ui->labelResultLength1->setToolTip(tr("Length can't be negative"));
461 
463  }
464 }
465 
466 //---------------------------------------------------------------------------------------------------------------------
468 {
469  labelEditFormula = ui->labelEditLength2;
470  const QString postfix = UnitsToStr(qApp->patternUnit(), true);
471  const qreal length2 = Eval(ui->plainTextEditLength2F->toPlainText(), flagLength2, ui->labelResultLength2, postfix,
472  false);
473 
474  if (length2 < 0)
475  {
476  flagLength2 = false;
477  ChangeColor(labelEditFormula, Qt::red);
478  ui->labelResultLength2->setText(tr("Error") + " (" + postfix + ")");
479  ui->labelResultLength2->setToolTip(tr("Length can't be negative"));
480 
482  }
483 }
484 
485 //---------------------------------------------------------------------------------------------------------------------
487 {
488  QString angle1F = ui->plainTextEditAngle1F->toPlainText();
489  angle1F.replace("\n", " ");
490 
491  QString angle2F = ui->plainTextEditAngle2F->toPlainText();
492  angle2F.replace("\n", " ");
493 
494  QString length1F = ui->plainTextEditLength1F->toPlainText();
495  length1F.replace("\n", " ");
496 
497  QString length2F = ui->plainTextEditLength2F->toPlainText();
498  length2F.replace("\n", " ");
499 
501 
502  const qreal angle1 = Visualization::FindVal(angle1F, vars);
503  const qreal angle2 = Visualization::FindVal(angle2F, vars);
504  const qreal length1 = Visualization::FindLength(length1F, vars);
505  const qreal length2 = Visualization::FindLength(length2F, vars);
506 
507  const bool separator = qApp->Settings()->GetOsSeparator();
508 
509  angle1F = qApp->TrVars()->TryFormulaFromUser(angle1F, separator);
510  angle2F = qApp->TrVars()->TryFormulaFromUser(angle2F, separator);
511  length1F = qApp->TrVars()->TryFormulaFromUser(length1F, separator);
512  length2F = qApp->TrVars()->TryFormulaFromUser(length2F, separator);
513 
514  VSpline spline(*GetP1(), *GetP4(), angle1, angle1F, angle2, angle2F, length1, length1F, length2, length2F);
515 
516  return spline;
517 }
518 
519 //---------------------------------------------------------------------------------------------------------------------
521 {
522  QSet<quint32> set;
523  set.insert(getCurrentObjectId(ui->comboBoxP1));
524  set.insert(getCurrentObjectId(ui->comboBoxP4));
525 
526  QColor color = okColor;
527  if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4))
528  {
529  flagError = false;
530  color = errorColor;
531 
532  ui->lineEditSplineName->setText(tr("Invalid spline"));
533  }
534  else
535  {
536  flagError = true;
537  color = okColor;
538 
539  if (getCurrentObjectId(ui->comboBoxP1) == spl.GetP1().id() &&
540  getCurrentObjectId(ui->comboBoxP4) == spl.GetP4().id())
541  {
542  newDuplicate = -1;
543  ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
544  }
545  else
546  {
548  spl.GetKcurve());
549 
550  if (not data->IsUnique(spline.name()))
551  {
552  newDuplicate = static_cast<qint32>(DNumber(spline.name()));
553  spline.SetDuplicate(static_cast<quint32>(newDuplicate));
554  }
555  ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spline.name()));
556  }
557  }
558  ChangeColor(ui->labelName, color);
559  ChangeColor(ui->labelFirstPoint, color);
560  ChangeColor(ui->labelSecondPoint, color);
561  CheckState();
562 }
563 
564 //---------------------------------------------------------------------------------------------------------------------
565 void DialogSpline::ShowDialog(bool click)
566 {
567  if (prepare && click)
568  {
569  auto *path = qobject_cast<VisToolSpline *>(vis);
570  SCASSERT(path != nullptr)
571 
572  spl = VSpline(*GetP1(), path->GetP2(), path->GetP3(), *GetP4());
573 
574  const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula(),
575  qApp->Settings()->GetOsSeparator());
576  const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula(),
577  qApp->Settings()->GetOsSeparator());
578 
579  ui->plainTextEditAngle1F->setPlainText(angle1F);
580  ui->plainTextEditAngle2F->setPlainText(angle2F);
581  ui->plainTextEditLength1F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula(),
582  qApp->Settings()->GetOsSeparator()));
583  ui->plainTextEditLength2F->setPlainText(qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula(),
584  qApp->Settings()->GetOsSeparator()));
585 
586  if (not data->IsUnique(spl.name()))
587  {
589  }
590 
591  ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
592 
593  DialogAccepted();
594  }
595 }
596 
597 //---------------------------------------------------------------------------------------------------------------------
599 {
600  SCASSERT(ok_Button != nullptr)
602  // In case dialog hasn't apply button
603  if (apply_Button != nullptr)
604  {
605  apply_Button->setEnabled(ok_Button->isEnabled());
606  }
607 }
608 
609 //---------------------------------------------------------------------------------------------------------------------
611 {
612  AddVisualization<VisToolSpline>();
613 }
614 
615 //---------------------------------------------------------------------------------------------------------------------
617 {
618  return spl;
619 }
620 
621 //---------------------------------------------------------------------------------------------------------------------
622 void DialogSpline::SetSpline(const VSpline &spline)
623 {
624  spl = spline;
625 
626  setCurrentPointId(ui->comboBoxP1, spl.GetP1().id());
627  setCurrentPointId(ui->comboBoxP4, spl.GetP4().id());
628 
629  const QString angle1F = qApp->TrVars()->FormulaToUser(spl.GetStartAngleFormula(),
630  qApp->Settings()->GetOsSeparator());
631  const QString angle2F = qApp->TrVars()->FormulaToUser(spl.GetEndAngleFormula(),
632  qApp->Settings()->GetOsSeparator());
633 
634  ui->plainTextEditAngle1F->setPlainText(angle1F);
635  ui->plainTextEditAngle2F->setPlainText(angle2F);
636 
637  const QString length1F = qApp->TrVars()->FormulaToUser(spl.GetC1LengthFormula(),
638  qApp->Settings()->GetOsSeparator());
639  const QString length2F = qApp->TrVars()->FormulaToUser(spl.GetC2LengthFormula(),
640  qApp->Settings()->GetOsSeparator());
641 
642  ui->plainTextEditLength1F->setPlainText(length1F);
643  ui->plainTextEditLength2F->setPlainText(length2F);
644  ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name()));
645 
646  auto path = qobject_cast<VisToolSpline *>(vis);
647  SCASSERT(path != nullptr)
648 
649  path->setObject1Id(spl.GetP1().id());
650  path->setObject4Id(spl.GetP4().id());
651  path->SetAngle1(spl.GetStartAngle());
652  path->SetAngle2(spl.GetEndAngle());
653  path->SetKAsm1(spl.GetKasm1());
654  path->SetKAsm2(spl.GetKasm2());
655  path->SetKCurve(spl.GetKcurve());
656 }
657 
658 //---------------------------------------------------------------------------------------------------------------------
660 {
661  return GetComboBoxCurrentData(ui->lineType_ComboBox, LineTypeSolidLine);
662 }
663 
664 //---------------------------------------------------------------------------------------------------------------------
665 void DialogSpline::setPenStyle(const QString &value)
666 {
667  ChangeCurrentData(ui->lineType_ComboBox, value);
668 }
669 
670 //---------------------------------------------------------------------------------------------------------------------
672 {
673  return GetComboBoxCurrentData(ui->lineColor_ComboBox, ColorBlack);
674 }
675 
676 //---------------------------------------------------------------------------------------------------------------------
677 void DialogSpline::setLineColor(const QString &value)
678 {
679  ChangeCurrentData(ui->lineColor_ComboBox, value);
680 }
681 
682 //---------------------------------------------------------------------------------------------------------------------
683 /**
684  * @brief getLineWeight return weight of the lines
685  * @return type
686  */
688 {
689  return GetComboBoxCurrentData(ui->lineWeight_ComboBox, "0.35");
690 }
691 
692 //---------------------------------------------------------------------------------------------------------------------
693 /**
694  * @brief setLineWeight set weight of the lines
695  * @param value type
696  */
697 void DialogSpline::setLineWeight(const QString &value)
698 {
699  ChangeCurrentData(ui->lineWeight_ComboBox, value);
700  vis->setLineWeight(value);
701 }
The DialogSpline class dialog for ToolSpline. Help create spline and edit option.
Definition: dialogspline.h:77
void Angle1Changed()
virtual void ShowVisualization() Q_DECL_OVERRIDE
void setPenStyle(const QString &value)
int formulaBaseHeightAngle1
formulaBaseHeight base height defined by dialogui
Definition: dialogspline.h:133
DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogSpline create dialog.
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
virtual ~DialogSpline() Q_DECL_OVERRIDE
void DeployAngle2TextEdit()
QTimer * timerLength2
Definition: dialogspline.h:142
const QSharedPointer< VPointF > GetP4() const
qint32 newDuplicate
spl spline
Definition: dialogspline.h:130
virtual void CheckState() Q_DECL_FINAL
CheckState enable, when all is correct, or disable, when something wrong, button ok.
bool flagAngle1
flagAngle1 true if value of first angle is correct
Definition: dialogspline.h:145
QString getLineWeight() const
getLineWeight return weight of the lines
void EvalLength2()
VSpline CurrentSpline() const
QString getLineColor() const
void EvalLength1()
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE
void setLineColor(const QString &value)
void SetSpline(const VSpline &spline)
void Angle2Changed()
QTimer * timerAngle1
timerAngle1 timer of check first angle formula
Definition: dialogspline.h:139
VSpline GetSpline() const
Ui::DialogSpline * ui
Definition: dialogspline.h:128
void setLineWeight(const QString &value)
setLineWeight set weight of the lines
const QSharedPointer< VPointF > GetP1() const
QTimer * timerAngle2
Definition: dialogspline.h:140
void Length1Changed()
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.
int formulaBaseHeightAngle2
Definition: dialogspline.h:134
QTimer * timerLength1
Definition: dialogspline.h:141
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
void Length2Changed()
virtual void PointNameChanged() Q_DECL_OVERRIDE
QString getPenStyle() const
void DeployAngle1TextEdit()
VSpline spl
ui keeps information about user interface
Definition: dialogspline.h:129
void DeployLength1TextEdit()
int formulaBaseHeightLength1
Definition: dialogspline.h:135
int formulaBaseHeightLength2
Definition: dialogspline.h:136
void DeployLength2TextEdit()
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
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
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
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
virtual void DialogAccepted()
DialogAccepted save data and emit signal about closed dialog.
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
QPlainTextEdit * plainTextEditFormula
plainTextEditFormula formula
Definition: dialogtool.h:208
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.
void SetDuplicate(quint32 number)
quint32 GetDuplicate() const
The VContainer class container of all variables.
Definition: vcontainer.h:141
static bool IsUnique(const QString &name)
Definition: vcontainer.cpp:585
const QHash< QString, QSharedPointer< VInternalVariable > > * DataVariables() const
Definition: vcontainer.cpp:718
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
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
VSpline class that implements the spline.
Definition: vspline.h:75
virtual VPointF GetP4() const Q_DECL_OVERRIDE
GetP4 return last spline point.
Definition: vspline.cpp:321
QString GetC1LengthFormula() const
Definition: vspline.cpp:391
qreal GetKcurve() const
GetKcurve return coefficient of curvature spline.
Definition: vspline.cpp:443
virtual qreal GetStartAngle() const Q_DECL_OVERRIDE
GetAngle1 return first angle control line.
Definition: vspline.cpp:337
virtual VPointF GetP1() const Q_DECL_OVERRIDE
GetP1 return first spline point.
Definition: vspline.cpp:281
QString GetStartAngleFormula() const
Definition: vspline.cpp:353
QString GetEndAngleFormula() const
Definition: vspline.cpp:359
qreal GetKasm1() const
GetKasm1 return coefficient of length first control line.
Definition: vspline.cpp:421
QString GetC2LengthFormula() const
Definition: vspline.cpp:397
virtual qreal GetEndAngle() const Q_DECL_OVERRIDE
GetAngle2 return second angle control line.
Definition: vspline.cpp:347
qreal GetKasm2() const
GetKasm2 return coefficient of length second control line.
Definition: vspline.cpp:432
void MouseLeftReleased()
void MouseLeftPressed()
static qreal FindLength(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
static qreal FindVal(const QString &expression, const QHash< QString, QSharedPointer< VInternalVariable > > *vars)
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
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