Seamly2D
Code documentation
dialogcutspline.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 dialogcutspline.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 15 12, 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 "dialogcutspline.h"
53 
54 #include <QDialog>
55 #include <QLineEdit>
56 #include <QPlainTextEdit>
57 #include <QPointer>
58 #include <QPushButton>
59 #include <QToolButton>
60 
61 #include "../vpatterndb/vtranslatevars.h"
62 #include "../../visualization/path/vistoolcutspline.h"
63 #include "../../visualization/visualization.h"
64 #include "../ifc/xml/vabstractpattern.h"
65 #include "../ifc/xml/vdomdocument.h"
66 #include "../support/edit_formula_dialog.h"
67 #include "../vmisc/vabstractapplication.h"
68 #include "../vmisc/vcommonsettings.h"
69 #include "ui_dialogcutspline.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
72 /**
73  * @brief DialogCutSpline create dialog.
74  * @param data container with data
75  * @param parent parent widget
76  */
77 DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
78  : DialogTool(data, toolId, parent)
79  , ui(new Ui::DialogCutSpline)
80  , formula(QString())
81  , formulaBaseHeight(0)
82 {
83  ui->setupUi(this);
84  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
85  setWindowIcon(QIcon(":/toolicon/32x32/spline_cut_point.png"));
86 
87  ui->lineEditNamePoint->setClearButtonEnabled(true);
88 
90  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
91  labelEditNamePoint = ui->labelEditNamePoint;
92  this->formulaBaseHeight = ui->plainTextEditFormula->height();
93  ui->plainTextEditFormula->installEventFilter(this);
94 
96  flagFormula = false;
98 
99  FillComboBoxSplines(ui->comboBoxSpline);
100 
101  connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSpline::FXLength);
102  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged);
103  connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged);
104  connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit);
105 
106  vis = new VisToolCutSpline(data);
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {
112  delete ui;
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
116 /**
117  * @brief SetPointName set name of point
118  * @param value name
119  */
120 void DialogCutSpline::SetPointName(const QString &value)
121 {
122  pointName = value;
123  ui->lineEditNamePoint->setText(pointName);
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
127 /**
128  * @brief SetFormula set string of formula
129  * @param value formula
130  */
131 void DialogCutSpline::SetFormula(const QString &value)
132 {
133  formula = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
134  // increase height if needed. TODO : see if I can get the max number of caracters in one line
135  // of this PlainTextEdit to change 80 to this value
136  if (formula.length() > 80)
137  {
138  this->DeployFormulaTextEdit();
139  }
140  ui->plainTextEditFormula->setPlainText(formula);
141 
142  VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
143  SCASSERT(path != nullptr)
144  path->setLength(formula);
145 
146  MoveCursorToEnd(ui->plainTextEditFormula);
147 }
148 
149 //---------------------------------------------------------------------------------------------------------------------
150 /**
151  * @brief setSplineId set id spline
152  * @param value id
153  */
154 void DialogCutSpline::setSplineId(const quint32 &value)
155 {
156  setCurrentSplineId(ui->comboBoxSpline, value);
157 
158  VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
159  SCASSERT(path != nullptr)
160  path->setObject1Id(value);
161 }
162 
163 //---------------------------------------------------------------------------------------------------------------------
164 /**
165  * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
166  * @param id id of point or detail
167  * @param type type of object
168  */
169 void DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type)
170 {
171  if (prepare == false)// After first choose we ignore all objects
172  {
173  if (type == SceneObject::Spline)
174  {
175  if (SetObject(id, ui->comboBoxSpline, ""))
176  {
177  vis->VisualMode(id);
178  prepare = true;
179  this->setModal(true);
180  this->show();
181  }
182  }
183  }
184 }
185 
186 //---------------------------------------------------------------------------------------------------------------------
188 {
189  pointName = ui->lineEditNamePoint->text();
190  formula = ui->plainTextEditFormula->toPlainText();
191  formula.replace("\n", " ");
192 
193  VisToolCutSpline *path = qobject_cast<VisToolCutSpline *>(vis);
194  SCASSERT(path != nullptr)
195 
196  path->setObject1Id(getSplineId());
197  path->setLength(formula);
198  path->RefreshGeometry();
199 }
200 
201 //---------------------------------------------------------------------------------------------------------------------
202 void DialogCutSpline::closeEvent(QCloseEvent *event)
203 {
204  ui->plainTextEditFormula->blockSignals(true);
205  DialogTool::closeEvent(event);
206 }
207 
208 //---------------------------------------------------------------------------------------------------------------------
210 {
211  DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
212 }
213 
214 //---------------------------------------------------------------------------------------------------------------------
216 {
217  EditFormulaDialog *dialog = new EditFormulaDialog(data, toolId, this);
218  dialog->setWindowTitle(tr("Edit length"));
219  dialog->SetFormula(GetFormula());
220  dialog->setPostfix(UnitsToStr(qApp->patternUnit(), true));
221  if (dialog->exec() == QDialog::Accepted)
222  {
223  SetFormula(dialog->GetFormula());
224  }
225  delete dialog;
226 }
227 
228 //---------------------------------------------------------------------------------------------------------------------
230 {
231  AddVisualization<VisToolCutSpline>();
232 }
233 
234 //---------------------------------------------------------------------------------------------------------------------
235 /**
236  * @brief GetFormula return string of formula
237  * @return formula
238  */
240 {
241  return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
242 }
243 
244 //---------------------------------------------------------------------------------------------------------------------
245 /**
246  * @brief getSplineId return id base point of line
247  * @return id
248  */
250 {
251  return getCurrentObjectId(ui->comboBoxSpline);
252 }
The DialogCutSpline class dialog for ToolCutSpline.
void SetPointName(const QString &value)
SetPointName set name of point.
int formulaBaseHeight
formulaBaseHeight base height defined by dialogui
void DeployFormulaTextEdit()
DeployFormulaTextEdit grow or shrink formula input.
void SetFormula(const QString &value)
SetFormula set string of formula.
virtual ~DialogCutSpline() Q_DECL_OVERRIDE
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.
Ui::DialogCutSpline * ui
ui keeps information about user interface
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
QString formula
formula string with formula
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
void setSplineId(const quint32 &value)
setSplineId set id spline
DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogCutSpline create dialog.
virtual void ShowVisualization() Q_DECL_OVERRIDE
QString GetFormula() const
GetFormula return string of formula.
quint32 getSplineId() const
getSplineId return id base point of line
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
virtual void CheckState()
CheckState enable, when all is correct, or disable, when something wrong, button ok.
void NamePointChanged()
NamePointChanged check name of point.
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
Definition: dialogtool.cpp:432
void FormulaChanged()
formula check formula
bool flagFormula
flagFormula true if formula correct
Definition: dialogtool.h:186
void setCurrentSplineId(QComboBox *box, const quint32 &value) const
setCurrentSplineId set current spline id in combobox
Definition: dialogtool.cpp:913
QString pointName
pointName name of point
Definition: dialogtool.h:231
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
void FillComboBoxSplines(QComboBox *box) const
Definition: dialogtool.cpp:254
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
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 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
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setLength(const QString &expression)
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