ACF $AcfVersion:0$
TDataNodePolyline.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// STL includes
6#include <vector>
7
8// ACF includes
10#include <istd/CChangeGroup.h>
12
13
14namespace i2d
15{
16
17
22template<class NodeData>
24{
25public:
27
31 const NodeData& GetTNodeData(int nodeIndex) const;
32
36 NodeData& GetTNodeDataRef(int nodeIndex);
37
38 // reimplemented (i2d::CDataNodePolylineBase)
39 virtual const iser::ISerializable& GetNodeData(int nodeIndex) const override;
40 virtual iser::ISerializable& GetNodeDataRef(int nodeIndex) override;
41
42 // reimplemented (i2d::CPolypoint)
43 virtual void Clear() override;
44 virtual void SetNodesCount(int nodesCount) override;
45 virtual bool InsertNode(const i2d::CVector2d& position) override;
46 virtual bool InsertNode(int index, const i2d::CVector2d& position) override;
47 virtual bool RemoveNode(int index) override;
48
49 // reimplemented istd::IChangeable
50 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
51
52private:
53 typedef std::vector<NodeData> NodesData;
54 NodesData m_nodesData;
55};
56
57
58template<class NodeData>
59inline const NodeData& TDataNodePolyline<NodeData>::GetTNodeData(int nodeIndex) const
60{
61 Q_ASSERT(nodeIndex >= 0);
62 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
63
64 return m_nodesData[nodeIndex];
65}
66
67
68template<class NodeData>
69inline NodeData& TDataNodePolyline<NodeData>::GetTNodeDataRef(int nodeIndex)
70{
71 Q_ASSERT(nodeIndex >= 0);
72 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
73
74 return m_nodesData[nodeIndex];
75}
76
77
78// reimplemented (i2d::CDataNodePolylineBase)
79
80template<class NodeData>
82{
83 Q_ASSERT(nodeIndex >= 0);
84 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
85
86 return m_nodesData[nodeIndex];
87}
88
89
90template<class NodeData>
92{
93 Q_ASSERT(nodeIndex >= 0);
94 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
95
96 return m_nodesData[nodeIndex];
97}
98
99
100// reimplemented (i2d::CPolypoint)
101
102template<class NodeData>
104{
105 if (!m_nodesData.empty()){
106 istd::CChangeNotifier changeNotifier(this, &s_clearAllNodesChange);
107 Q_UNUSED(changeNotifier);
108
109 m_nodesData.clear();
110
111 BaseClass::Clear();
112 }
113}
114
115
116template<class NodeData>
118{
119 istd::CChangeNotifier changeNotifier(this, &s_createPolygonNodesChange);
120 Q_UNUSED(changeNotifier);
121
122 m_nodesData.resize(nodesCount);
123
124 BaseClass::SetNodesCount(nodesCount);
125}
126
127
128template<class NodeData>
130{
131 istd::CChangeNotifier changeNotifier(this, &s_insertPolygonNodeChange);
132 Q_UNUSED(changeNotifier);
133
134 m_nodesData.insert(m_nodesData.end(), NodeData());
135
136 return BaseClass::InsertNode(position);
137}
138
139
140template<class NodeData>
141inline bool TDataNodePolyline<NodeData>::InsertNode(int index, const i2d::CVector2d& position)
142{
143 istd::CChangeNotifier changeNotifier(this, &s_insertPolygonNodeChange);
144 Q_UNUSED(changeNotifier);
145
146 typename NodesData::iterator iter = m_nodesData.begin();
147 iter += index;
148 m_nodesData.insert(iter, NodeData());
149
150 return BaseClass::InsertNode(index, position);
151}
152
153
154template<class NodeData>
156{
157 istd::CChangeNotifier changeNotifier(this, &s_removePolygonNodeChange);
158 Q_UNUSED(changeNotifier);
159
160 typename NodesData::iterator iter = m_nodesData.begin();
161 iter += index;
162 m_nodesData.erase(iter);
163
164 return BaseClass::RemoveNode(index);
165}
166
167
168// reimplemented istd::IChangeable
169
170template<class NodeData>
171bool TDataNodePolyline<NodeData>::CopyFrom(const IChangeable& object, CompatibilityMode mode)
172{
173 istd::CChangeGroup changeGroup(this);
174
175 Clear();
176
177 const TDataNodePolyline<NodeData>* polygonPtr = dynamic_cast<const TDataNodePolyline<NodeData>*>(&object);
178
179 if (polygonPtr != NULL){
180 istd::CChangeNotifier changeNotifier(this);
181
182 int sourceNodesCount = polygonPtr->GetNodesCount();
183 for (int nodesIndex = 0; nodesIndex < sourceNodesCount; nodesIndex++){
184 InsertNode(polygonPtr->GetNodePos(nodesIndex));
185
186 m_nodesData[nodesIndex] = polygonPtr->m_nodesData[nodesIndex];
187 }
188
189 CObject2dBase::CopyFrom(object, mode);
190
191 return true;
192 }
193
194 return false;
195}
196
197
198} // namespace i2d
199
200
201
202
Base class for polylines with additional data stored in each node.
virtual bool CopyFrom(const istd::IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
Copy this object from another one.
virtual const i2d::CVector2d & GetNodePos(int index) const
Return position of node at specified index.
Definition CPolypoint.h:160
virtual int GetNodesCount() const
Return size of node table.
Definition CPolypoint.h:148
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Generic polyline implementation with additional information stored for each node.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
NodeData & GetTNodeDataRef(int nodeIndex)
Get reference of user data in the given node.
virtual bool RemoveNode(int index) override
Remove a node at specified index.
CDataNodePolylineBase BaseClass
virtual void SetNodesCount(int nodesCount) override
Set new nodes count.
virtual const iser::ISerializable & GetNodeData(int nodeIndex) const override
Get user data from the given node.
virtual void Clear() override
Removes all nodes.
const NodeData & GetTNodeData(int nodeIndex) const
Get user data from the given node.
virtual iser::ISerializable & GetNodeDataRef(int nodeIndex) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual bool InsertNode(const i2d::CVector2d &position) override
Insert a node at the end of node table.
virtual bool InsertNode(int index, const i2d::CVector2d &position) override
Insert a node at specified index.
Common class for all classes which objects can be archived or restored from archive.
Help class which provides the group of changes for update mechanism of the model.
Help class which provides the automatic update mechanism of the model.
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
#define NULL
Definition istd.h:74
Contains the 2D objects.
Definition CAffine2d.h:11