Seamly2D
Code documentation
union_dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file union_dialog.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 27, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file dialoguniondetails.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 23 12, 2013
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2013-2015 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #include "union_dialog.h"
54 
55 #include <QCheckBox>
56 #include <QVector>
57 
58 #include "../ifc/ifcdef.h"
59 #include "../vpatterndb/vcontainer.h"
60 #include "../vpatterndb/vpiece.h"
61 #include "../vpatterndb/vpiecenode.h"
62 #include "dialogtool.h"
63 #include "ui_union_dialog.h"
64 
65 //---------------------------------------------------------------------------------------------------------------------
66 /**
67  * @brief UnionDialog create dialog
68  * @param data container with data
69  * @param parent parent widget
70  */
71 UnionDialog::UnionDialog(const VContainer *data, const quint32 &toolId, QWidget *parent)
72  : DialogTool(data, toolId, parent)
73  , ui(new Ui::UnionDialog)
74  , piece1_Index(0)
75  , piece2_Index(0)
76  , d1(NULL_ID)
77  , d2(NULL_ID)
78  , numberD(0)
79  , numberP(0)
80  , p1(NULL_ID)
81  , p2(NULL_ID)
82  , m_beep(new QSound(qApp->Settings()->getSelectionSound()))
83 {
84  ui->setupUi(this);
86 }
87 
88 //---------------------------------------------------------------------------------------------------------------------
90 {
91  delete ui;
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
96 {
97  return ui->checkBox->isChecked();
98 }
99 
100 //---------------------------------------------------------------------------------------------------------------------
101 /**
102  * @brief ChoosedObject gets id and type of selected object. Save correct data and ignore wrong.
103  * @param id id of point or piece
104  * @param type type of object
105  */
106 void UnionDialog::ChosenObject(quint32 id, const SceneObject &type)
107 {
108  if (numberD == 0)
109  {
110  chosenPiece(id, type, d1, piece1_Index);
111  }
112  else
113  {
114  chosenPiece(id, type, d2, piece2_Index);
115  }
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
119 /**
120  * @brief CheckObject check if piece contains this id
121  * @param id id of item
122  * @param pieceId piece id
123  * @return true if contain
124  */
125 bool UnionDialog::CheckObject(const quint32 &id, const quint32 &pieceId) const
126 {
127  if (pieceId == NULL_ID)
128  {
129  return false;
130  }
131  const VPiece piece = data->GetPiece(pieceId);
132  return piece.GetPath().Contains(id);
133 }
134 
135 //---------------------------------------------------------------------------------------------------------------------
136 bool UnionDialog::checkPiece(const quint32 &pieceId) const
137 {
138  if (pieceId == NULL_ID)
139  {
140  return false;
141  }
142  const VPiece piece = data->GetPiece(pieceId);
143  if (piece.isLocked())
144  {
145  ui->checkBox->setChecked(true);
146  ui->checkBox->setEnabled(false);
147  }
148  if (piece.GetPath().CountNodes() >= 3 && piece.GetPath().ListNodePoint().size() >= 2)
149  {
150  return true;
151  }
152  else
153  {
154  return false;
155  }
156 }
157 
158 //---------------------------------------------------------------------------------------------------------------------
159 /**
160  * @brief chosenPiece help save information about piece and points on piece
161  * @param id id selected object
162  * @param type type selected object
163  * @param pieceId id of piece
164  * @param index index of edge
165  */
166 void UnionDialog::chosenPiece(const quint32 &id, const SceneObject &type, quint32 &pieceId,
167  int &index)
168 {
169  if (pieceId == NULL_ID)
170  {
171  if (type == SceneObject::Piece)
172  {
173  m_beep->play();
174  if (checkPiece(id))
175  {
176  pieceId = id;
177  emit ToolTip(tr("Select the first point"));
178  return;
179  }
180  else
181  {
182  emit ToolTip(tr("Pattern piece should have at least two points and three objects"));
183  return;
184  }
185  }
186  }
187  if (CheckObject(id, pieceId) == false)
188  {
189  return;
190  }
191  if (type == SceneObject::Point)
192  {
193  m_beep->play();
194  if (numberP == 0)
195  {
196  p1 = id;
197  ++numberP;
198  emit ToolTip(tr("Select a second point"));
199  return;
200  }
201  if (numberP == 1)
202  {
203  if (id == p1)
204  {
205  emit ToolTip(tr("Select a unique point"));
206  return;
207  }
208  VPiece piece = data->GetPiece(pieceId);
209  if (piece.GetPath().OnEdge(p1, id))
210  {
211  p2 = id;
212  index = piece.GetPath().Edge(p1, p2);
213  ++numberD;
214  if (numberD > 1)
215  {
216  ++numberP;
217  emit ToolTip("");
218  this->setModal(true);
219  this->show();
220  return;
221  }
222  else
223  {
224  numberP = 0;
225  p1 = 0;
226  p2 = 0;
227  emit ToolTip(tr("Select a piece"));
228  return;
229  }
230  }
231  else
232  {
233  emit ToolTip(tr("Select a point on edge"));
234  return;
235  }
236  }
237  }
238 }
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void ToolTip(const QString &toolTip)
ToolTip emit tooltipe for tool.
void initializeOkCancel(T *ui)
initializeOkCancel initialize OK and Cancel buttons
Definition: dialogtool.h:379
const VContainer * data
data container with data
Definition: dialogtool.h:177
The UnionDialog class dialog for Union Tool.
Definition: union_dialog.h:75
qint32 numberP
numberD number of piece, what we already have
Definition: union_dialog.h:102
virtual ~UnionDialog() Q_DECL_OVERRIDE
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE
ChoosedObject gets id and type of selected object. Save correct data and ignore wrong.
void chosenPiece(const quint32 &id, const SceneObject &type, quint32 &pieceId, int &index)
chosenPiece help save information about piece and points on piece
qint32 numberD
d2 id second piece
Definition: union_dialog.h:101
int piece2_Index
piece1_Index index edge first piece
Definition: union_dialog.h:98
QSound * m_beep
p2 id second point of piece
Definition: union_dialog.h:105
quint32 p2
p1 id first point of piece
Definition: union_dialog.h:104
bool retainPieces() const
bool CheckObject(const quint32 &id, const quint32 &pieceId) const
CheckObject check if piece contains this id.
UnionDialog(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
UnionDialog create dialog.
bool checkPiece(const quint32 &pieceId) const
quint32 d1
piece2_Index index edge second piece
Definition: union_dialog.h:99
quint32 p1
numberP number of points, what we already have
Definition: union_dialog.h:103
quint32 d2
d1 id first piece
Definition: union_dialog.h:100
int piece1_Index
ui keeps information about user interface
Definition: union_dialog.h:97
Ui::UnionDialog * ui
Definition: union_dialog.h:96
The VContainer class container of all variables.
Definition: vcontainer.h:141
VPiece GetPiece(quint32 id) const
Definition: vcontainer.cpp:185
bool Contains(quint32 id) const
Definition: vpiecepath.cpp:539
qint32 CountNodes() const
Definition: vpiecepath.cpp:209
int Edge(quint32 p1, quint32 p2) const
Edge return edge index in detail. Edge is line between two points. If between two points located arcs...
Definition: vpiecepath.cpp:604
bool OnEdge(quint32 p1, quint32 p2) const
OnEdge checks if two poins located on the edge. Edge is line between two points. If between two point...
Definition: vpiecepath.cpp:559
QVector< VPieceNode > ListNodePoint() const
listNodePoint return list nodes only with points.
Definition: vpiecepath.cpp:633
Definition: vpiece.h:88
bool isLocked() const
Definition: vpiece.cpp:388
VPiecePath GetPath() const
Definition: vpiece.cpp:156
SceneObject
Definition: def.h:103
#define NULL_ID
Definition: ifcdef.h:76
#define qApp
Definition: vapplication.h:67