Seamly2D
Code documentation
point_intersectxy_tool.cpp
Go to the documentation of this file.
1 /**************************************************************************
2  **
3  ** @file point_intersectxy_tool.cpp
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date November 15, 2013
6  **
7  ** @author Douglas S Caskey
8  ** @date 7.21.2022
9  **
10  ** @brief
11  ** @copyright
12  ** This source code is part of the Valentine project, a pattern making
13  ** program, whose allow create and modeling patterns of clothing.
14  ** Copyright (C) 2013-2022 Seamly2D project
15  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
16  **
17  ** Seamly2D is free software: you can redistribute it and/or modify
18  ** it under the terms of the GNU General Public License as published by
19  ** the Free Software Foundation, either version 3 of the License, or
20  ** (at your option) any later version.
21  **
22  ** Seamly2D is distributed in the hope that it will be useful,
23  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
24  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  ** GNU General Public License for more details.
26  **
27  ** You should have received a copy of the GNU General Public License
28  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
29  **
30  *************************************************************************/
31 
32 #include "point_intersectxy_tool.h"
33 
35 #include "../ifc/exception/vexception.h"
36 #include "../ifc/ifcdef.h"
37 #include "../vgeometry/vgobject.h"
38 #include "../vgeometry/vpointf.h"
39 #include "../vmisc/vabstractapplication.h"
40 #include "../vpatterndb/vcontainer.h"
41 #include "../vwidgets/vmaingraphicsscene.h"
42 #include "../../vdrawtool.h"
43 #include "../../../vabstracttool.h"
44 #include "../../../../dialogs/tools/dialogtool.h"
45 #include "../../../../dialogs/tools/point_intersectxy_dialog.h"
46 #include "../../../../visualization/visualization.h"
47 #include "../../../../visualization/line/point_intersectxy_visual.h"
48 
49 #include <QPointF>
50 #include <QSharedPointer>
51 #include <QStaticStringData>
52 #include <QStringData>
53 #include <QStringDataPtr>
54 #include <new>
55 
56 template <class T> class QSharedPointer;
57 
58 const QString PointIntersectXYTool::ToolType = QStringLiteral("intersectXY");
59 
60 //---------------------------------------------------------------------------------------------------------------------
61 /**
62  * @brief PointIntersectXYTool constructor.
63  * @param doc dom document container.
64  * @param data container with variables.
65  * @param id object id in container.
66  * @param lineType line type.
67  * @param lineWeight line weight.
68  * @param lineColor line color.
69  * @param firstPointId id first line point.
70  * @param secondPointId id second line point.
71  * @param typeCreation way we create this tool.
72  * @param parent parent object.
73  */
75  const QString &lineType, const QString &lineWeight,
76  const QString &lineColor,
77  const quint32 &firstPointId, const quint32 &secondPointId,
78  const Source &typeCreation, QGraphicsItem *parent)
79  : DoubleLinePointTool(doc, data, id, lineType, lineWeight, lineColor, firstPointId, secondPointId, parent)
80 {
81  ToolCreation(typeCreation);
82 }
83 
84 //---------------------------------------------------------------------------------------------------------------------
85 /**
86  * @brief setDialog set dialog when user want change tool option.
87  */
89 {
90  SCASSERT(not m_dialog.isNull())
92  SCASSERT(not dialogTool.isNull())
94  dialogTool->setPointName(point->name());
95  dialogTool->setFirstPointId(firstPointId);
96  dialogTool->setSecondPointId(secondPointId);
97  dialogTool->setLineType(m_lineType);
98  dialogTool->setLineWeight(m_lineWeight);
99  dialogTool->setLineColor(lineColor);
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
103 /**
104  * @brief Create help create tool from GUI.
105  * @param dialog dialog.
106  * @param scene pointer to scene.
107  * @param doc dom document container.
108  * @param data container with variables.
109  * @return the created tool
110  */
112  VAbstractPattern *doc, VContainer *data)
113 {
114  SCASSERT(not dialog.isNull())
115  QSharedPointer<PointIntersectXYDialog> dialogTool = dialog.objectCast<PointIntersectXYDialog>();
116  SCASSERT(not dialogTool.isNull())
117  const QString pointName = dialogTool->getPointName();
118  const quint32 firstPointId = dialogTool->getFirstPointId();
119  const quint32 secondPointId = dialogTool->getSecondPointId();
120  const QString lineType = dialogTool->getLineType();
121  const QString lineWeight = dialogTool->getLineWeight();
122  const QString lineColor = dialogTool->getLineColor();
123  PointIntersectXYTool *point = Create(0, pointName, lineType, lineWeight, lineColor, firstPointId, secondPointId,
124  5, 10, true, scene, doc, data, Document::FullParse, Source::FromGui);
125  if (point != nullptr)
126  {
127  point->m_dialog = dialogTool;
128  }
129  return point;
130 }
131 
132 //---------------------------------------------------------------------------------------------------------------------
133 /**
134  * @brief Create help create tool.
135  * @param _id tool id, 0 if tool doesn't exist yet.
136  * @param pointName point name.
137  * @param lineType line type.
138  * @param lineWeight line weight.
139  * @param lineColor line color.
140  * @param firstPointId id first line point.
141  * @param secondPointId id second line point.
142  * @param mx label bias x axis.
143  * @param my label bias y axis.
144  * @param scene pointer to scene.
145  * @param doc dom document container.
146  * @param data container with variables.
147  * @param parse parser file mode.
148  * @param typeCreation way we create this tool.
149  * @return the created tool
150  */
151 PointIntersectXYTool *PointIntersectXYTool::Create(const quint32 _id, const QString &pointName,
152  const QString &lineType, const QString &lineWeight,
153  const QString &lineColor,
154  const quint32 &firstPointId, const quint32 &secondPointId,
155  qreal mx, qreal my, bool showPointName,
157  VContainer *data, const Document &parse,
158  const Source &typeCreation)
159 {
162 
163  QPointF point(firstPoint->x(), secondPoint->y());
164  quint32 id = _id;
165  VPointF *p = new VPointF(point, pointName, mx, my);
166  p->setShowPointName(showPointName);
167 
168  if (typeCreation == Source::FromGui)
169  {
170  id = data->AddGObject(p);
171  data->AddLine(firstPointId, id);
172  data->AddLine(secondPointId, id);
173  }
174  else
175  {
176  data->UpdateGObject(id, p);
177  data->AddLine(firstPointId, id);
178  data->AddLine(secondPointId, id);
179  if (parse != Document::FullParse)
180  {
181  doc->UpdateToolData(id, data);
182  }
183  }
184 
185  if (parse == Document::FullParse)
186  {
188  PointIntersectXYTool *point = new PointIntersectXYTool(doc, data, id, lineType, lineWeight, lineColor,
189  firstPointId, secondPointId, typeCreation);
190  scene->addItem(point);
191  InitToolConnections(scene, point);
192  VAbstractPattern::AddTool(id, point);
193  doc->IncrementReferens(firstPoint->getIdTool());
194  doc->IncrementReferens(secondPoint->getIdTool());
195  return point;
196  }
197  return nullptr;
198 }
199 
200 //---------------------------------------------------------------------------------------------------------------------
202 {
204 }
205 
206 //---------------------------------------------------------------------------------------------------------------------
208 {
210 }
211 
212 //---------------------------------------------------------------------------------------------------------------------
213 /**
214  * @brief RemoveReferens decrement value of reference.
215  */
217 {
218  const auto firstPoint = VAbstractTool::data.GetGObject(firstPointId);
219  const auto secondPoint = VAbstractTool::data.GetGObject(secondPointId);
220 
221  doc->DecrementReferens(firstPoint->getIdTool());
222  doc->DecrementReferens(secondPoint->getIdTool());
224 }
225 
226 //---------------------------------------------------------------------------------------------------------------------
227 /**
228  * @brief contextMenuEvent handle context menu events.
229  * @param event context menu event.
230  */
231 void PointIntersectXYTool::showContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id)
232 {
233  try
234  {
235  ContextMenu<PointIntersectXYDialog>(event, id);
236  }
237  catch(const VExceptionToolWasDeleted &e)
238  {
239  Q_UNUSED(e)
240  return;//Leave this method immediately!!!
241  }
242 }
243 
244 //---------------------------------------------------------------------------------------------------------------------
245 /**
246  * @brief SaveDialog save options into file after change in dialog.
247  */
248 void PointIntersectXYTool::SaveDialog(QDomElement &domElement)
249 {
250  SCASSERT(not m_dialog.isNull())
252  SCASSERT(not dialogTool.isNull())
253  doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
254  doc->SetAttribute(domElement, AttrLineType, dialogTool->getLineType());
255  doc->SetAttribute(domElement, AttrLineWeight, dialogTool->getLineWeight());
256  doc->SetAttribute(domElement, AttrLineColor, dialogTool->getLineColor());
257  doc->SetAttribute(domElement, AttrFirstPoint, dialogTool->getFirstPointId());
258  doc->SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId());
259 }
260 
261 //---------------------------------------------------------------------------------------------------------------------
263 {
265 
269 }
270 
271 //---------------------------------------------------------------------------------------------------------------------
272 void PointIntersectXYTool::ReadToolAttributes(const QDomElement &domElement)
273 {
275  m_lineWeight = doc->GetParametrString(domElement, AttrLineWeight, "0.35");
279 }
280 
281 //---------------------------------------------------------------------------------------------------------------------
283 {
284  if (not vis.isNull())
285  {
286  PointIntersectXYVisual *visual = qobject_cast<PointIntersectXYVisual *>(vis);
287  SCASSERT(visual != nullptr)
288 
289  visual->setObject1Id(firstPointId);
290  visual->setPoint2Id(secondPointId);
292  visual->setLineWeight(m_lineWeight);
293  visual->RefreshGeometry();
294  }
295 }
296 
297 //---------------------------------------------------------------------------------------------------------------------
299 {
300  ShowToolVisualization<PointIntersectXYVisual>(show);
301 }
The DoubleLinePointTool class parent for all tools what creates a point with 2 lines.
virtual void RemoveReferens() Q_DECL_OVERRIDE
RemoveReferens decrement value of reference.
quint32 secondPointId
firstPointId id first line point.
QString lineColor
secondLine second line item.
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
The PointIntersectXYDialog class dialog for ToolPointOfIntersection. Help create point and edit optio...
The PointIntersectXYTool class tool for creation point intersection two lines.
static const QString ToolType
virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE
virtual void RemoveReferens() Q_DECL_OVERRIDE
RemoveReferens decrement value of reference.
static PointIntersectXYTool * Create(QSharedPointer< DialogTool > dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
Create help create tool from GUI.
virtual void SetVisualization() Q_DECL_OVERRIDE
virtual void setDialog() Q_DECL_OVERRIDE
setDialog set dialog when user want change tool option.
virtual void SaveOptions(QDomElement &tag, QSharedPointer< VGObject > &obj) Q_DECL_OVERRIDE
PointIntersectXYTool(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &lineType, const QString &lineWeight, const QString &lineColor, const quint32 &firstPointId, const quint32 &secondPointId, const Source &typeCreation, QGraphicsItem *parent=nullptr)
PointIntersectXYTool constructor.
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE
virtual void showContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id=NULL_ID) Q_DECL_OVERRIDE
contextMenuEvent handle context menu events.
virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE
SaveDialog save options into file after change in dialog.
virtual void RefreshGeometry() Q_DECL_OVERRIDE
void setPoint2Id(const quint32 &value)
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0
virtual void IncrementReferens(quint32 id) const =0
static void AddTool(quint32 id, VDataTool *tool)
AddTool add tool to list tools.
virtual void DecrementReferens(quint32 id) const =0
static void InitToolConnections(VMainGraphicsScene *scene, T *tool)
VAbstractPattern * doc
doc dom document container
QPointer< Visualization > vis
virtual void ToolCreation(const Source &typeCreation)
static void AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
AddRecord add record about tool in history.
const quint32 m_id
id object id.
The VContainer class container of all variables.
Definition: vcontainer.h:141
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId)
AddLine add line to container.
Definition: vcontainer.cpp:382
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
Definition: vcontainer.cpp:150
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
quint32 AddGObject(VGObject *obj)
AddGObject add new GObject to container.
Definition: vcontainer.cpp:216
void UpdateGObject(quint32 id, T *obj)
UpdateGObject update GObject by id.
Definition: vcontainer.h:374
VContainer data
data container with data
Definition: vdatatool.h:84
static QString GetParametrString(const QDomElement &domElement, const QString &name, const QString &defValue=QString())
Returns the string value of the given attribute. RENAME: see above.
static quint32 GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue)
Returns the long long value of the given attribute. RENAME: GetParameterLongLong?
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
QString m_lineWeight
typeLine line type.
Definition: vdrawtool.h:104
QString m_lineType
activeBlockName name of tool's pattern peace.
Definition: vdrawtool.h:103
QSharedPointer< DialogTool > m_dialog
m_dialog tool's dialog options.
The VMainGraphicsScene class main scene.
The VPointF class keep data of point.
Definition: vpointf.h:75
void setShowPointName(bool show)
Definition: vpointf.cpp:265
void setLineWeight(const QString &value)
void setObject1Id(const quint32 &value)
void setLineStyle(const Qt::PenStyle &value)
#define SCASSERT(cond)
Definition: def.h:317
@ PointOfIntersection
Source
Definition: def.h:106
const QString AttrName
Definition: ifcdef.cpp:76
const QString AttrLineType
Definition: ifcdef.cpp:90
const QString AttrSecondPoint
Definition: ifcdef.cpp:97
const QString AttrFirstPoint
Definition: ifcdef.cpp:96
const QString AttrLineWeight
Definition: ifcdef.cpp:91
const QString LineTypeDashLine
Definition: ifcdef.cpp:160
const QString ColorBlack
Definition: ifcdef.cpp:373
const QString AttrType
Definition: ifcdef.cpp:73
const QString AttrLineColor
Definition: ifcdef.cpp:130
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.
Definition: ifcdef.cpp:183
#define NULL_ID_STR
Definition: ifcdef.h:77
Document