OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
EntityResultTable.hpp
Go to the documentation of this file.
1#pragma once
2#include "EntityResultTable.h"
4#include "DataBase.h"
5#include "OldTreeIcon.h"
6
7#include <bsoncxx/builder/basic/array.hpp>
8
11
12template <class T>
13EntityResultTable<T>::EntityResultTable(ot::UID ID, EntityBase *parent, EntityObserver *obs, ModelState *ms, ClassFactoryHandler* factory, const std::string &owner) :
14 EntityBase(ID, parent, obs, ms, factory, owner),
15 tableDataStorageId(-1),
16 tableDataStorageVersion(-1)
17{
18 className = "EntityResultTable_" + ot::TemplateTypeName<T>::getTypeName();
19}
20
21template <class T>
22EntityResultTable<T>::~EntityResultTable()
23{
24}
25
26template <class T>
27bool EntityResultTable<T>::getEntityBox(double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax)
28{
29 return false;
30}
31
32template <class T>
33void EntityResultTable<T>::StoreToDataBase(void)
34{
35 EntityBase::StoreToDataBase();
36}
37
38template <class T>
39void EntityResultTable<T>::AddStorageData(bsoncxx::builder::basic::document &storage)
40{
41 // We store the parent class information first
42 EntityBase::AddStorageData(storage);
43
44 // Now we store the particular information about the current object
45 storage.append(
46 bsoncxx::builder::basic::kvp("TableDataID", tableDataStorageId),
47 bsoncxx::builder::basic::kvp("TableDataVersion", tableDataStorageVersion),
48 bsoncxx::builder::basic::kvp("MinCol", _minCol),
49 bsoncxx::builder::basic::kvp("MaxCol", _maxCol),
50 bsoncxx::builder::basic::kvp("MinRow", _minRow),
51 bsoncxx::builder::basic::kvp("MaxRow", _maxRow)
52 );
53}
54
55
56template <class T>
57void EntityResultTable<T>::readSpecificDataFromDataBase(bsoncxx::document::view &doc_view, std::map<ot::UID, EntityBase *> &entityMap)
58{
59 // We read the parent class information first
60 EntityBase::readSpecificDataFromDataBase(doc_view, entityMap);
61
62 if (tableData.use_count() == 0 && tableData != nullptr)
63 {
64 tableData = nullptr;
65 }
66
67 // Here we can load any special information about the entity
68 tableDataStorageId = doc_view["TableDataID"].get_int64();
69 tableDataStorageVersion = doc_view["TableDataVersion"].get_int64();
70 _minCol = doc_view["MinCol"].get_int32();
71 _maxCol = doc_view["MaxCol"].get_int32();
72 _minRow = doc_view["MinRow"].get_int32();
73 _maxRow = doc_view["MaxRow"].get_int32();
74
75 resetModified();
76}
77
78template <class T>
79void EntityResultTable<T>::addVisualizationNodes()
80{
81 OldTreeIcon treeIcons;
82 treeIcons.size = 32;
83 treeIcons.visibleIcon = "TableVisible";
84 treeIcons.hiddenIcon = "TableHidden";
85
87 doc.AddMember(OT_ACTION_MEMBER, ot::JsonString(OT_ACTION_CMD_UI_VIEW_AddContainerNode, doc.GetAllocator()), doc.GetAllocator());
88 doc.AddMember(OT_ACTION_PARAM_UI_TREE_Name, ot::JsonString(this->getName(), doc.GetAllocator()), doc.GetAllocator());
89 doc.AddMember(OT_ACTION_PARAM_MODEL_EntityID, this->getEntityID(), doc.GetAllocator());
90 doc.AddMember(OT_ACTION_PARAM_MODEL_ITM_IsEditable, this->getEditable(), doc.GetAllocator());
91
92 treeIcons.addToJsonDoc(doc);
93
94 getObserver()->sendMessageToViewer(doc);
95
96 //addVisualizationItem(getInitiallyHidden());
97
98 EntityBase::addVisualizationNodes();
99}
100
101/*Legacy code. Required in model service.*/
102template <class T>
103void EntityResultTable<T>::addVisualizationItem(bool isHidden)
104{
105 OldTreeIcon treeIcons;
106 treeIcons.size = 32;
107 treeIcons.visibleIcon = "TableVisible";
108 treeIcons.hiddenIcon = "TableHidden";
109
111 doc.AddMember(OT_ACTION_MEMBER, ot::JsonString(OT_ACTION_CMD_UI_VIEW_OBJ_AddSceneNode, doc.GetAllocator()), doc.GetAllocator());
112 doc.AddMember(OT_ACTION_PARAM_UI_TREE_Name, ot::JsonString(this->getName(), doc.GetAllocator()), doc.GetAllocator());
113 doc.AddMember(OT_ACTION_PARAM_MODEL_EntityID, this->getEntityID(), doc.GetAllocator());
114 doc.AddMember(OT_ACTION_PARAM_MODEL_ITM_IsEditable, this->getEditable(), doc.GetAllocator());
115
117 visType.addTableVisualisation();
118 visType.addToJsonObject(doc, doc.GetAllocator());
119
120 treeIcons.addToJsonDoc(doc);
121
122 getObserver()->sendMessageToViewer(doc);
123}
124
125
126template <class T>
127void EntityResultTable<T>::createProperties()
128{
129 const std::string visibleTableSize = "Visible Table Dimensions";
130
131 EntityPropertiesInteger::createProperty(visibleTableSize, "Min Row", _minRow, "default", getProperties());
132 EntityPropertiesInteger::createProperty(visibleTableSize, "Max Row", _maxRow, "default", getProperties());
133 EntityPropertiesInteger::createProperty(visibleTableSize, "Min Column", _minCol, "default", getProperties());
134 EntityPropertiesInteger::createProperty(visibleTableSize, "Max Column", _maxCol, "default", getProperties());
135 getProperties().forceResetUpdateForAllProperties();
136}
137
138template <class T>
139bool EntityResultTable<T>::updateFromProperties()
140{
141 // Now we need to update the entity after a property change
142 assert(getProperties().anyPropertyNeedsUpdate());
143
144 // Since there is a change now, we need to set the modified flag
145 setModified();
146
147 getProperties().forceResetUpdateForAllProperties();
148
149 return false; // Notify, whether property grid update is necessary
150}
151
152template <class T>
153std::shared_ptr<EntityResultTableData<T>> EntityResultTable<T>::getTableData()
154{
155 EnsureTableDataLoaded();
156 return tableData;
157}
158
159template <class T>
160void EntityResultTable<T>::EnsureTableDataLoaded()
161{
162 if (tableData == nullptr)
163 {
164 if (tableDataStorageId != -1)
165 {
166 if (tableDataStorageVersion != -1)
167 {
168 std::map<ot::UID, EntityBase*> entitymap;
169 auto tempPtr = dynamic_cast<EntityResultTableData<T>*>(readEntityFromEntityIDAndVersion(this, tableDataStorageId, tableDataStorageVersion, entitymap));
170 if (tempPtr != nullptr)
171 {
172 tableData = std::shared_ptr <EntityResultTableData<T>>(tempPtr);
173 }
174 else
175 {
176 throw std::exception("Failed to load the Table Data.");
177 }
178 }
179 }
180
181 assert(tableData != nullptr);
182 }
183}
184
185template<class T>
186void EntityResultTable<T>::setTableData(std::shared_ptr<EntityResultTableData<T>> data)
187{
188 if (data != nullptr)
189 {
190 setModified();
191 }
192 tableData = data;
193 tableDataStorageId = tableData->getEntityID();
194 tableDataStorageVersion = tableData->getEntityStorageVersion();
195}
196
197
198template<class T>
199inline int EntityResultTable<T>::getMinColumn()
200{
201 auto propBase = getProperties().getProperty("Min Column");
202 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
203 return intProp->getValue();
204}
205
206template<class T>
207inline int EntityResultTable<T>::getMinRow()
208{
209 auto propBase = getProperties().getProperty("Min Row");
210 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
211 return intProp->getValue();
212}
213
214template<class T>
215inline int EntityResultTable<T>::getMaxColumn()
216{
217 auto propBase = getProperties().getProperty("Max Column");
218 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
219 return intProp->getValue();
220}
221
222template<class T>
223inline int EntityResultTable<T>::getMaxRow()
224{
225 auto propBase = getProperties().getProperty("Max Row");
226 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
227 return intProp->getValue();
228}
229
230template<class T>
231inline void EntityResultTable<T>::setMinColumn(int minCol)
232{
233 auto propBase = getProperties().getProperty("Min Column");
234 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
235 intProp->setValue(minCol);
236 intProp->setNeedsUpdate();
237}
238
239template<class T>
240inline void EntityResultTable<T>::setMinRow(int minRow)
241{
242 auto propBase = getProperties().getProperty("Min Row");
243 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
244 intProp->setValue(minRow);
245 intProp->setNeedsUpdate();
246}
247
248template<class T>
249inline void EntityResultTable<T>::setMaxColumn(int maxCol)
250{
251 auto propBase = getProperties().getProperty("Max Column");
252 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
253 intProp->setValue(maxCol);
254 intProp->setNeedsUpdate();
255}
256
257template<class T>
258inline void EntityResultTable<T>::setMaxRow(int maxRow)
259{
260 auto propBase = getProperties().getProperty("Max Row");
261 auto intProp = dynamic_cast<EntityPropertiesInteger*>(propBase);
262 intProp->setValue(maxRow);
263 intProp->setNeedsUpdate();
264}
265
266template <class T>
267void EntityResultTable<T>::deleteTableData(void)
268{
269 tableData = nullptr;
270 tableDataStorageId = -1;
271 tableDataStorageVersion = -1;
272
273 setModified();
274}
275
276template <class T>
277void EntityResultTable<T>::releaseTableData(void)
278{
279 if (tableData == nullptr)
280 {
281 return;
282 };
283 tableData = nullptr;
284}
285
#define OT_ACTION_MEMBER
Definition ActionTypes.h:11
#define OT_ACTION_CMD_UI_VIEW_OBJ_AddSceneNode
Definition ActionTypes.h:255
#define OT_ACTION_PARAM_MODEL_EntityID
Definition ActionTypes.h:477
#define OT_ACTION_PARAM_UI_TREE_Name
Definition ActionTypes.h:380
#define OT_ACTION_PARAM_MODEL_ITM_IsEditable
Definition ActionTypes.h:517
#define OT_ACTION_CMD_UI_VIEW_AddContainerNode
Definition ActionTypes.h:228
JSON document.
Definition JSON.h:276
JSON String value.
Definition JSON.h:84
static std::string getTypeName()
Definition TemplateTypeName.hpp:9
Definition VisualisationTypes.h:13
void addToJsonObject(ot::JsonValue &_object, ot::JsonAllocator &_allocator) const override
Add the object contents to the provided JSON object.
Definition VisualisationTypes.cpp:26
void addTableVisualisation()
Definition VisualisationTypes.cpp:9
int ID
The ID datatype used for items.
Definition globalDataTypes.h:68
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27