OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
EntityBase.h
Go to the documentation of this file.
1#pragma once
2#pragma warning(disable : 4251)
3
4#include <string>
5#include <list>
6
7#include <bsoncxx/builder/stream/document.hpp>
8#include <bsoncxx/json.hpp>
9#include <bsoncxx/builder/basic/document.hpp>
10
11#include "EntityProperties.h"
12#include "ModelState.h"
13#include "OldTreeIcon.h"
14
15class EntityBase;
16class ClassFactoryHandler;
17
18class __declspec(dllexport) EntityObserver
19{
20public:
21 EntityObserver() {};
22 virtual ~EntityObserver() {};
23
24 virtual void entityRemoved(EntityBase *entity) {};
25 virtual void entityModified(EntityBase *entity) {};
26
27 virtual void sendMessageToViewer(ot::JsonDocument& doc) { std::list<std::pair<ot::UID, ot::UID>> prefetchIds; sendMessageToViewer(doc, prefetchIds); };
28 virtual void sendMessageToViewer(ot::JsonDocument& doc, std::list<std::pair<ot::UID, ot::UID>> &prefetchIds) {};
29
30};
31
33class __declspec(dllexport) EntityBase
34{
35public:
36 EntityBase(ot::UID _ID, EntityBase* _parent, EntityObserver* _obs, ModelState* _ms, ClassFactoryHandler* _factory, const std::string& _owner);
37 virtual ~EntityBase();
38
39 static void setUidGenerator(DataStorageAPI::UniqueUIDGenerator *_uidGenerator);
40 static DataStorageAPI::UniqueUIDGenerator *getUidGenerator(void);
41
42 void setName(std::string n) { m_name = n; setModified(); };
43 std::string getName(void) const { return m_name; };
44
47 std::string getNameOnly() const;
48
49 void setEntityID(ot::UID id) { m_entityID = id; setModified(); };
50 ot::UID getEntityID(void) const { return m_entityID; };
51
52 ot::UID getEntityStorageVersion(void) const { return m_entityStorageVersion; };
53
54 void setInitiallyHidden(bool flag) { m_initiallyHidden = flag; };
55 bool getInitiallyHidden(void) { return m_initiallyHidden; };
56
57 void setEditable(bool flag) { m_isEditable = flag; }
58 bool getEditable(void) { return m_isEditable; }
59
60 void setSelectChildren(bool flag) { m_selectChildren = flag; }
61 bool getSelectChildren(void) { return m_selectChildren; }
62
63 void setManageParentVisibility(bool flag) { m_manageParentVisibility = flag; }
64 bool getManageParentVisibility(void) { return m_manageParentVisibility; }
65
66 void setManageChildVisibility(bool flag) { m_manageChildVisibility = flag; }
67 bool getManageChildVisibility(void) { return m_manageChildVisibility; }
68
69 virtual bool getEntityBox(double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax) = 0;
70
71 virtual void removeChild(EntityBase *child) {};
72
73 virtual bool updateFromProperties(void);
74
75 void setModelState(ModelState *ms) { m_modelState = ms; };
76 ModelState *getModelState(void) { return m_modelState; };
77
78 EntityBase *getParent(void) { return m_parentEntity; };
79 void setParent(EntityBase *parent) { m_parentEntity = parent; }; // The parent information is not persistent. Changing it therefore does not set the modified flag for the entity.
80
81 void setObserver(EntityObserver *obs) { m_observer = obs; };
82 EntityObserver *getObserver(void) { return m_observer; };
83
84 ClassFactoryHandler *getClassFactory(void) { return m_classFactory; };
85
86 EntityProperties &getProperties(void) { return m_properties; };
87
88 virtual EntityBase *getEntityFromName(const std::string &n) { if (m_name == n) return this; return nullptr; };
89
90 virtual bool considerForPropertyFilter(void) { return true; };
91 virtual bool considerChildrenForPropertyFilter(void) { return true; };
92
93 virtual void StoreToDataBase(void);
94 virtual void StoreToDataBase(ot::UID givenEntityVersion);
95
96 void setModified(void);
97 void resetModified(void) { m_isModified = false; };
98 bool getModified(void) { return (m_isModified || m_properties.anyPropertyNeedsUpdate()); };
99
100 void restoreFromDataBase(EntityBase *parent, EntityObserver *obs, ModelState *ms, bsoncxx::document::view &doc_view, std::map<ot::UID, EntityBase *> &entityMap);
101
102 virtual void addVisualizationNodes(void) {};
103
104 virtual std::string getClassName(void) { return "EntityBase"; };
105
106 virtual void addPrefetchingRequirementsForTopology(std::list<ot::UID> &prefetchIds);
107
108 enum entityType {TOPOLOGY, DATA};
109 virtual entityType getEntityType(void) = 0;
110
111 void setOwningService(const std::string &owner) { m_owningService = owner; };
112 const std::string &getOwningService(void) { return m_owningService; };
113
114 virtual void detachFromHierarchy(void);
115
116 void setDeletable(bool deletable) { m_isDeletable = deletable; };
117 const bool deletable() const { return m_isDeletable; }
118
119protected:
120 virtual int getSchemaVersion(void) { return 1; };
121 virtual void AddStorageData(bsoncxx::builder::basic::document &storage) {};
122 virtual void readSpecificDataFromDataBase(bsoncxx::document::view &doc_view, std::map<ot::UID, EntityBase *> &entityMap);
123
124 ot::UID createEntityUID(void);
125 EntityBase *readEntityFromEntityID(EntityBase *parent, ot::UID entityID, std::map<ot::UID, EntityBase *> &entityMap);
126 EntityBase *readEntityFromEntityIDAndVersion(EntityBase *parent, ot::UID entityID, ot::UID version, std::map<ot::UID, EntityBase *> &entityMap, ClassFactoryHandler* factory = nullptr);
127 ot::UID getCurrentEntityVersion(ot::UID entityID);
128 void entityIsStored(void);
129
130private:
131 // Persistent attributes
132 std::string m_name;
133 ot::UID m_entityID;
134 ot::UID m_entityStorageVersion;
135 bool m_initiallyHidden;
136 bool m_isEditable;
137 bool m_isDeletable;
138 bool m_selectChildren;
139 bool m_manageParentVisibility;
140 bool m_manageChildVisibility;
141 EntityProperties m_properties;
142 std::string m_owningService;
143
144 // Temporary attributes
145 EntityBase* m_parentEntity;
146 EntityObserver* m_observer;
147 bool m_isModified;
148 ModelState* m_modelState;
149 ClassFactoryHandler* m_classFactory;
150};
151
Definition UniqueUIDGenerator.h:8
JSON document.
Definition JSON.h:276
__declspec(dllexport) void setHoverTreeItem(ot __declspec(dllexport) void addNodeFromFacetData(ot __declspec(dllexport) void addNodeFromFacetDataBase(ot __declspec(dllexport) void addVisualizationContainerNode(ot __declspec(dllexport) void addVisualizationNode(ot __declspec(dllexport) void addVTKNode(ot __declspec(dllexport) void updateVTKNode(ot __declspec(dllexport) void addVisualizationAnnotationNode(ot __declspec(dllexport) void addVisualizationAnnotationNodeDataBase(ot __declspec(dllexport) void addVisualizationMeshNodeFromFacetDataBase(ot __declspec(dllexport) void addVisualizationMeshItemNodeFromFacetDataBase(ot __declspec(dllexport) void addVisualizationCartesianMeshNode(ot __declspec(dllexport) void visualizationCartesianMeshNodeShowLines(ot __declspec(dllexport) void addVisualizationCartesianMeshItemNode(ot __declspec(dllexport) void visualizationTetMeshNodeTetEdges(ot __declspec(dllexport) void notifySceneNodeAboutViewChange(ot __declspec(dllexport) std __declspec(dllexport) void removeSelectedCurveNodes(ot __declspec(dllexport) void addVisualizationPlot1DNode(ot __declspec(dllexport) void visualizationResult1DPropertiesChanged(ot __declspec(dllexport) void visualizationPlot1DPropertiesChanged(ot __declspec(dllexport) void setEntityName(ot __declspec(dllexport) void renameEntityPath(const std __declspec(dllexport) void updateObjectColor(ot __declspec(dllexport) void updateMeshColor(ot __declspec(dllexport) void updateObjectFacetsFromDataBase(ot __declspec(dllexport) void setClearColor(ot __declspec(dllexport) void setDataModel(ot __declspec(dllexport) void getSelectedModelEntityIDs(std __declspec(dllexport) void getSelectedVisibleModelEntityIDs(std __declspec(dllexport) ot __declspec(dllexport) ot __declspec(dllexport) void removeShapes(ot __declspec(dllexport) void setShapeVisibility(ot __declspec(dllexport) void hideEntities(ot __declspec(dllexport) void showBranch(ot __declspec(dllexport) void hideBranch(ot __declspec(dllexport) void enterEntitySelectionMode(ot __declspec(dllexport) void setFontPath(const std __declspec(dllexport) void setDataBaseConnection(const std __declspec(dllexport) void prefetchDocumentsFromStorage(const std __declspec(dllexport) void setTabNames(ot __declspec(dllexport) ot __declspec(dllexport) void viewerTabChanged(const std __declspec(dllexport) void viewDataModifiedChanged(const std __declspec(dllexport) void shortcutActivated(const std __declspec(dllexport) void createRubberband(ot __declspec(dllexport) void settingsItemChanged(ot __declspec(dllexport) bool propertyGridValueChanged(ot bool flag
Definition ViewerAPI.h:147
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27