1 /************************************************************************
2  **
3  **  @file   vnodesplinepath.cpp
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   November 15, 2013
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) 2013-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 "vnodesplinepath.h"
30 
31 #include <QDomElement>
32 #include <QStaticStringData>
33 #include <QStringData>
34 #include <QStringDataPtr>
35 
36 #include "../ifc/xml/vdomdocument.h"
37 #include "../ifc/ifcdef.h"
38 #include "../vabstracttool.h"
39 #include "../vdatatool.h"
40 #include "vabstractnode.h"
41 
42 const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath");
43 
44 //---------------------------------------------------------------------------------------------------------------------
45 /**
46  * @brief VNodeSplinePath constructor.
47  * @param initData init data.
48  * @param qoParent QObject parent.
49  */
VNodeSplinePath(const VAbstractNodeInitData & initData,QObject * qoParent)50 VNodeSplinePath::VNodeSplinePath(const VAbstractNodeInitData &initData, QObject *qoParent)
51     :VAbstractNode(initData.doc, initData.data, initData.id, initData.idObject, initData.drawName, initData.idTool,
52                    qoParent)
53 {
54     ToolCreation(initData.typeCreation);
55 }
56 
57 //---------------------------------------------------------------------------------------------------------------------
58 /**
59  * @brief Create help create tool.
60  * @param initData init data.
61  */
Create(const VAbstractNodeInitData & initData)62 void VNodeSplinePath::Create(const VAbstractNodeInitData &initData)
63 {
64     if (initData.parse == Document::FullParse)
65     {
66         VAbstractTool::AddRecord(initData.id, Tool::NodeSplinePath, initData.doc);
67         VNodeSplinePath *splPath = new VNodeSplinePath(initData);
68 
69         VAbstractPattern::AddTool(initData.id, splPath);
70         if (initData.idTool != NULL_ID)
71         {
72             //Some nodes we don't show on scene. Tool that create this nodes must free memory.
73             VDataTool *tool = VAbstractPattern::getTool(initData.idTool);
74             SCASSERT(tool != nullptr)
75             splPath->setParent(tool);// Adopted by a tool
76         }
77         else
78         {
79             // Help to delete the node before each FullParse
80             initData.doc->AddToolOnRemove(splPath);
81         }
82     }
83     else
84     {
85         initData.doc->UpdateToolData(initData.id, initData.data);
86     }
87 }
88 
89 //---------------------------------------------------------------------------------------------------------------------
getTagName() const90 QString VNodeSplinePath::getTagName() const
91 {
92     return VAbstractPattern::TagSpline;
93 }
94 
95 //---------------------------------------------------------------------------------------------------------------------
AllowHover(bool enabled)96 void VNodeSplinePath::AllowHover(bool enabled)
97 {
98     Q_UNUSED(enabled)
99     // do nothing
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
AllowSelecting(bool enabled)103 void VNodeSplinePath::AllowSelecting(bool enabled)
104 {
105     Q_UNUSED(enabled)
106     // do nothing
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
110 /**
111  * @brief AddToFile add tag with informations about tool into file.
112  */
AddToFile()113 void VNodeSplinePath::AddToFile()
114 {
115     QDomElement domElement = doc->createElement(getTagName());
116 
117     doc->SetAttribute(domElement, VDomDocument::AttrId, m_id);
118     doc->SetAttribute(domElement, AttrType, ToolType);
119     doc->SetAttribute(domElement, AttrIdObject, idNode);
120     if (idTool != 0)
121     {
122         doc->SetAttribute(domElement, AttrIdTool, idTool);
123     }
124 
125     AddToModeling(domElement);
126 }
127