1 /************************************************************************
2 **
3 ** @file dialogpointfromarcandtangent.cpp
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 5 6, 2015
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2015 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "dialogpointfromarcandtangent.h"
30
31 #include <QComboBox>
32 #include <QLineEdit>
33 #include <QPointer>
34
35 #include "../../visualization/visualization.h"
36 #include "../../visualization/line/vistoolpointfromarcandtangent.h"
37 #include "../vmisc/vabstractapplication.h"
38 #include "dialogs/tools/dialogtool.h"
39 #include "ui_dialogpointfromarcandtangent.h"
40
41 //---------------------------------------------------------------------------------------------------------------------
DialogPointFromArcAndTangent(const VContainer * data,quint32 toolId,QWidget * parent)42 DialogPointFromArcAndTangent::DialogPointFromArcAndTangent(const VContainer *data, quint32 toolId, QWidget *parent)
43 : DialogTool(data, toolId, parent),
44 ui(new Ui::DialogPointFromArcAndTangent),
45 pointName(),
46 flagName(true)
47 {
48 ui->setupUi(this);
49
50 ui->lineEditNamePoint->setClearButtonEnabled(true);
51
52 ui->lineEditNamePoint->setText(
53 VAbstractValApplication::VApp()->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
54
55 InitOkCancelApply(ui);
56
57 FillComboBoxPoints(ui->comboBoxTangentPoint);
58 FillComboBoxArcs(ui->comboBoxArc);
59 FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
60
61 connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
62 {
63 CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
64 CheckState();
65 });
66
67 vis = new VisToolPointFromArcAndTangent(data);
68
69 ui->tabWidget->setCurrentIndex(0);
70 SetTabStopDistance(ui->plainTextEditToolNotes);
71 }
72
73 //---------------------------------------------------------------------------------------------------------------------
~DialogPointFromArcAndTangent()74 DialogPointFromArcAndTangent::~DialogPointFromArcAndTangent()
75 {
76 delete ui;
77 }
78
79 //---------------------------------------------------------------------------------------------------------------------
GetPointName() const80 QString DialogPointFromArcAndTangent::GetPointName() const
81 {
82 return pointName;
83 }
84
85 //---------------------------------------------------------------------------------------------------------------------
SetPointName(const QString & value)86 void DialogPointFromArcAndTangent::SetPointName(const QString &value)
87 {
88 pointName = value;
89 ui->lineEditNamePoint->setText(pointName);
90 }
91
92 //---------------------------------------------------------------------------------------------------------------------
GetArcId() const93 quint32 DialogPointFromArcAndTangent::GetArcId() const
94 {
95 return getCurrentObjectId(ui->comboBoxArc);
96 }
97
98 //---------------------------------------------------------------------------------------------------------------------
SetArcId(quint32 value)99 void DialogPointFromArcAndTangent::SetArcId(quint32 value)
100 {
101 setCurrentArcId(ui->comboBoxArc, value);
102
103 VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
104 SCASSERT(point != nullptr)
105 point->setArcId(value);
106 }
107
108 //---------------------------------------------------------------------------------------------------------------------
GetTangentPointId() const109 quint32 DialogPointFromArcAndTangent::GetTangentPointId() const
110 {
111 return getCurrentObjectId(ui->comboBoxTangentPoint);
112 }
113
114 //---------------------------------------------------------------------------------------------------------------------
SetTangentPointId(quint32 value)115 void DialogPointFromArcAndTangent::SetTangentPointId(quint32 value)
116 {
117 setCurrentPointId(ui->comboBoxTangentPoint, value);
118
119 VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
120 SCASSERT(point != nullptr)
121 point->setObject1Id(value);
122 }
123
124 //---------------------------------------------------------------------------------------------------------------------
GetCrossCirclesPoint() const125 CrossCirclesPoint DialogPointFromArcAndTangent::GetCrossCirclesPoint() const
126 {
127 return getCurrentCrossPoint<CrossCirclesPoint>(ui->comboBoxResult);
128 }
129
130 //---------------------------------------------------------------------------------------------------------------------
SetCrossCirclesPoint(CrossCirclesPoint p)131 void DialogPointFromArcAndTangent::SetCrossCirclesPoint(CrossCirclesPoint p)
132 {
133 const qint32 index = ui->comboBoxResult->findData(static_cast<int>(p));
134 if (index != -1)
135 {
136 ui->comboBoxResult->setCurrentIndex(index);
137
138 VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
139 SCASSERT(point != nullptr)
140 point->setCrossPoint(p);
141 }
142 }
143
144 //---------------------------------------------------------------------------------------------------------------------
ChosenObject(quint32 id,const SceneObject & type)145 void DialogPointFromArcAndTangent::ChosenObject(quint32 id, const SceneObject &type)
146 {
147 if (prepare == false)// After first choose we ignore all objects
148 {
149 if (type == SceneObject::Point || type == SceneObject::Arc)
150 {
151 VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
152 SCASSERT(point != nullptr)
153
154 switch (number)
155 {
156 case 0:
157 if (type == SceneObject::Point)
158 {
159 if (SetObject(id, ui->comboBoxTangentPoint, tr("Select an arc")))
160 {
161 number++;
162 point->VisualMode(id);
163 }
164 }
165 break;
166 case 1:
167 if (type == SceneObject::Arc)
168 {
169 if (SetObject(id, ui->comboBoxArc, QString()))
170 {
171 number = 0;
172 point->setArcId(id);
173 point->RefreshGeometry();
174 prepare = true;
175 DialogAccepted();
176 }
177 }
178 break;
179 default:
180 break;
181 }
182 }
183 }
184 }
185
186 //---------------------------------------------------------------------------------------------------------------------
ShowVisualization()187 void DialogPointFromArcAndTangent::ShowVisualization()
188 {
189 AddVisualization<VisToolPointFromArcAndTangent>();
190 }
191
192 //---------------------------------------------------------------------------------------------------------------------
SaveData()193 void DialogPointFromArcAndTangent::SaveData()
194 {
195 pointName = ui->lineEditNamePoint->text();
196
197 VisToolPointFromArcAndTangent *point = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
198 SCASSERT(point != nullptr)
199
200 point->setObject1Id(GetTangentPointId());
201 point->setArcId(GetArcId());
202 point->setCrossPoint(GetCrossCirclesPoint());
203 point->RefreshGeometry();
204 }
205
206 //---------------------------------------------------------------------------------------------------------------------
SetNotes(const QString & notes)207 void DialogPointFromArcAndTangent::SetNotes(const QString ¬es)
208 {
209 ui->plainTextEditToolNotes->setPlainText(notes);
210 }
211
212 //---------------------------------------------------------------------------------------------------------------------
GetNotes() const213 QString DialogPointFromArcAndTangent::GetNotes() const
214 {
215 return ui->plainTextEditToolNotes->toPlainText();
216 }
217