Seamly2D
Code documentation
dialogpointfromarcandtangent.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 dialogpointfromarcandtangent.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 5 6, 2015
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) 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 
53 
54 #include <QComboBox>
55 #include <QLineEdit>
56 #include <QPointer>
57 
58 #include "../../visualization/visualization.h"
59 #include "../../visualization/line/vistoolpointfromarcandtangent.h"
60 #include "../vmisc/vabstractapplication.h"
62 #include "ui_dialogpointfromarcandtangent.h"
63 
64 //---------------------------------------------------------------------------------------------------------------------
66  QWidget *parent)
67  : DialogTool(data, toolId, parent)
69 {
70  ui->setupUi(this);
71  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
72  setWindowIcon(QIcon(":/toolicon/32x32/point_from_arc_and_tangent.png"));
73 
74  ui->lineEditNamePoint->setClearButtonEnabled(true);
75 
76  ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
77  labelEditNamePoint = ui->labelEditNamePoint;
78 
81 
82  FillComboBoxPoints(ui->comboBoxTangentPoint);
83  FillComboBoxArcs(ui->comboBoxArc);
84  FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
85 
86  connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointFromArcAndTangent::NamePointChanged);
87 
89 }
90 
91 //---------------------------------------------------------------------------------------------------------------------
93 {
94  delete ui;
95 }
96 
97 //---------------------------------------------------------------------------------------------------------------------
99 {
100  pointName = value;
101  ui->lineEditNamePoint->setText(pointName);
102 }
103 
104 //---------------------------------------------------------------------------------------------------------------------
106 {
107  return getCurrentObjectId(ui->comboBoxArc);
108 }
109 
110 //---------------------------------------------------------------------------------------------------------------------
111 void DialogPointFromArcAndTangent::SetArcId(const quint32 &value)
112 {
113  setCurrentArcId(ui->comboBoxArc, value);
114 
115  VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
116  SCASSERT(point != nullptr)
117  point->setArcId(value);
118 }
119 
120 //---------------------------------------------------------------------------------------------------------------------
122 {
123  return getCurrentObjectId(ui->comboBoxTangentPoint);
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
128 {
129  setCurrentPointId(ui->comboBoxTangentPoint, value);
130 
131  VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
132  SCASSERT(point != nullptr)
133  point->setObject1Id(value);
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
138 {
139  return getCurrentCrossPoint<CrossCirclesPoint>(ui->comboBoxResult);
140 }
141 
142 //---------------------------------------------------------------------------------------------------------------------
144 {
145  const qint32 index = ui->comboBoxResult->findData(static_cast<int>(p));
146  if (index != -1)
147  {
148  ui->comboBoxResult->setCurrentIndex(index);
149 
150  VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
151  SCASSERT(point != nullptr)
152  point->setCrossPoint(p);
153  }
154 }
155 
156 //---------------------------------------------------------------------------------------------------------------------
158 {
159  if (prepare == false)// After first choose we ignore all objects
160  {
161  if (type == SceneObject::Point || type == SceneObject::Arc)
162  {
163  VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
164  SCASSERT(point != nullptr)
165 
166  switch (number)
167  {
168  case 0:
169  if (type == SceneObject::Point)
170  {
171  if (SetObject(id, ui->comboBoxTangentPoint, tr("Select an arc")))
172  {
173  number++;
174  point->VisualMode(id);
175  }
176  }
177  break;
178  case 1:
179  if (type == SceneObject::Arc)
180  {
181  if (SetObject(id, ui->comboBoxArc, ""))
182  {
183  number = 0;
184  point->setArcId(id);
185  point->RefreshGeometry();
186  prepare = true;
187  DialogAccepted();
188  }
189  }
190  break;
191  default:
192  break;
193  }
194  }
195  }
196 }
197 
198 //---------------------------------------------------------------------------------------------------------------------
200 {
201  AddVisualization<VisToolPointFromArcAndTangent>();
202 }
203 
204 //---------------------------------------------------------------------------------------------------------------------
206 {
207  pointName = ui->lineEditNamePoint->text();
208 
209  VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
210  SCASSERT(point != nullptr)
211 
213  point->setArcId(GetArcId());
215  point->RefreshGeometry();
216 }
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
virtual void ShowVisualization() Q_DECL_OVERRIDE
void setCirclesCrossPoint(const CrossCirclesPoint &p)
CrossCirclesPoint GetCrossCirclesPoint() const
DialogPointFromArcAndTangent(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
Ui::DialogPointFromArcAndTangent * ui
void SetTangentPointId(const quint32 &value)
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 setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule=FillComboBox::NoChildren, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
setCurrentArcId
Definition: dialogtool.cpp:924
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 FillComboBoxCrossCirclesPoints(QComboBox *box) const
Definition: dialogtool.cpp:373
QString pointName
pointName name of point
Definition: dialogtool.h:231
qint32 number
number number of handled objects
Definition: dialogtool.h:234
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip)
Definition: dialogtool.cpp:974
virtual void DialogAccepted()
DialogAccepted save data and emit signal about closed dialog.
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
void FillComboBoxArcs(QComboBox *box, FillComboBox rule=FillComboBox::Whole, const quint32 &ch1=NULL_ID, const quint32 &ch2=NULL_ID) const
Definition: dialogtool.cpp:248
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
QPointer< Visualization > vis
Definition: dialogtool.h:236
quint32 getCurrentObjectId(QComboBox *box) const
getCurrentPointId return current point id stored in combobox
Definition: dialogtool.cpp:959
The VContainer class container of all variables.
Definition: vcontainer.h:141
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setCrossPoint(const CrossCirclesPoint &value)
virtual void VisualMode(const quint32 &pointId)
void setObject1Id(const quint32 &value)
#define SCASSERT(cond)
Definition: def.h:317
SceneObject
Definition: def.h:103
CrossCirclesPoint
#define qApp
Definition: vapplication.h:67