ICF 3.1.1.10
Technical documentation of ICF Libraries
TDataNodePolyline.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// STL includes
10#include <vector>
11
12// ICF includes
14#include <istd/CChangeGroup.h>
16
17
18namespace i2d
19{
20
21
26template<class NodeData>
28{
29public:
31
35 const NodeData& GetTNodeData(int nodeIndex) const;
36
40 NodeData& GetTNodeDataRef(int nodeIndex);
41
42 // reimplemented (i2d::CDataNodePolylineBase)
43 const iser::ISerializable& GetNodeData(int nodeIndex) const override;
44 iser::ISerializable& GetNodeDataRef(int nodeIndex) override;
45
46 // reimplemented (i2d::CPolypoint)
47 void Clear() override;
48 void SetNodesCount(int nodesCount) override;
49 bool InsertNode(const i2d::CVector2d& position) override;
50 bool InsertNode(int index, const i2d::CVector2d& position) override;
51 bool RemoveNode(int index) override;
52
53 // reimplemented istd::IChangeable
54 bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
55
56private:
57 typedef std::vector<NodeData> NodesData;
58 NodesData m_nodesData;
59};
60
61
62template<class NodeData>
63inline const NodeData& TDataNodePolyline<NodeData>::GetTNodeData(int nodeIndex) const
64{
65 Q_ASSERT(nodeIndex >= 0);
66 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
67
68 return m_nodesData[nodeIndex];
69}
70
71
72template<class NodeData>
73inline NodeData& TDataNodePolyline<NodeData>::GetTNodeDataRef(int nodeIndex)
74{
75 Q_ASSERT(nodeIndex >= 0);
76 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
77
78 return m_nodesData[nodeIndex];
79}
80
81
82// reimplemented (i2d::CDataNodePolylineBase)
83
84template<class NodeData>
86{
87 Q_ASSERT(nodeIndex >= 0);
88 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
89
90 return m_nodesData[nodeIndex];
91}
92
93
94template<class NodeData>
96{
97 Q_ASSERT(nodeIndex >= 0);
98 Q_ASSERT(nodeIndex < int(m_nodesData.size()));
99
100 return m_nodesData[nodeIndex];
101}
102
103
104// reimplemented (i2d::CPolypoint)
105
106template<class NodeData>
108{
109 if (!m_nodesData.empty()) {
110 istd::CChangeNotifier changeNotifier(this, &s_clearAllNodesChange);
111
112 m_nodesData.clear();
113
114 BaseClass::Clear();
115 }
116}
117
118
119template<class NodeData>
121{
122 istd::CChangeNotifier changeNotifier(this, &s_createPolygonNodesChange);
123
124 m_nodesData.resize(nodesCount);
125
126 BaseClass::SetNodesCount(nodesCount);
127}
128
129
130template<class NodeData>
132{
133 istd::CChangeNotifier changeNotifier(this, &s_insertPolygonNodeChange);
134
135 m_nodesData.insert(m_nodesData.end(), NodeData());
136
137 return BaseClass::InsertNode(position);
138}
139
140
141template<class NodeData>
142inline bool TDataNodePolyline<NodeData>::InsertNode(int index, const i2d::CVector2d& position)
143{
144 istd::CChangeNotifier changeNotifier(this, &s_insertPolygonNodeChange);
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
159 typename NodesData::iterator iter = m_nodesData.begin();
160 iter += index;
161 m_nodesData.erase(iter);
162
163 return BaseClass::RemoveNode(index);
164}
165
166
167// reimplemented istd::IChangeable
168
169template<class NodeData>
170bool TDataNodePolyline<NodeData>::CopyFrom(const IChangeable& object, CompatibilityMode mode)
171{
172 istd::CChangeGroup changeGroup(this);
173
174 Clear();
175
176 const TDataNodePolyline<NodeData>* polygonPtr = dynamic_cast<const TDataNodePolyline<NodeData>*>(&object);
177
178 if (polygonPtr != nullptr) {
179 istd::CChangeNotifier changeNotifier(this);
180
181 int sourceNodesCount = polygonPtr->GetNodesCount();
182 for (int nodesIndex = 0; nodesIndex < sourceNodesCount; nodesIndex++) {
183 InsertNode(polygonPtr->GetNodePos(nodesIndex));
184
185 m_nodesData[nodesIndex] = polygonPtr->m_nodesData[nodesIndex];
186 }
187
188 CObject2dBase::CopyFrom(object, mode);
189
190 return true;
191 }
192
193 return false;
194}
195
196
197} // namespace i2d
198
199
Base class for polylines with additional data stored in each node.
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:164
virtual int GetNodesCount() const
Return size of node table.
Definition CPolypoint.h:152
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Generic polyline implementation with additional information stored for each node.
bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
NodeData & GetTNodeDataRef(int nodeIndex)
Get reference of user data in the given node.
CDataNodePolylineBase BaseClass
bool RemoveNode(int index) override
Remove a node at specified index.
void SetNodesCount(int nodesCount) override
Set new nodes count.
const iser::ISerializable & GetNodeData(int nodeIndex) const override
Get user data from the given node.
void Clear() override
Removes all nodes.
const NodeData & GetTNodeData(int nodeIndex) const
Get user data from the given node.
iser::ISerializable & GetNodeDataRef(int nodeIndex) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool InsertNode(const i2d::CVector2d &position) override
Insert a node at the end of node table.
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.
Contains the 2D objects.
Definition CAffine2d.h:15

© Witold Gantzke and Kirill Lepskiy