OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
GraphicsItemCfg.h
Go to the documentation of this file.
1
5// ###########################################################################################################################################################################################################################################################################################################################
6
7#pragma once
8
9// OpenTwin header
10#include "OTCore/Size2D.h"
11#include "OTCore/Point2D.h"
12#include "OTCore/Flags.h"
13#include "OTCore/Serializable.h"
14#include "OTGui/Font.h"
15#include "OTGui/Margins.h"
16#include "OTGui/GuiTypes.h"
17#include "OTGui/Transform.h"
19#include "OTCore/CoreTypes.h"
20
21// std header
22#include <map>
23#include <string>
24
25#pragma warning(disable:4251)
26
27#define OT_JSON_MEMBER_GraphicsItemCfgType "GIType"
28
29namespace ot {
30
34 public:
35
38 NoFlags = 0x0000,
39 ItemIsMoveable = 0x0001,
40 ItemIsSelectable = 0x0002,
41 ItemIsConnectable = 0x0004,
42
43 ItemSnapsToGridTopLeft = 0x0010,
44 ItemSnapsToGridCenter = 0x0020,
45
48 ItemForwardsTooltip = 0x0100,
49
52 ItemUserTransformEnabled = 0x0200,
53
57 ItemIgnoresParentTransform = 0x0400,
58
63 ItemHandlesState = 0x1000,
64
67 ItemForwardsState = 0x2000
68 };
70
72 virtual ~GraphicsItemCfg();
73
74 // ###########################################################################################################################################################################################################################################################################################################################
75
76 // Pure virtual methods
77
79 virtual std::string getFactoryKey(void) const = 0;
80
82 virtual GraphicsItemCfg* createCopy(void) const = 0;
83
84 // ###########################################################################################################################################################################################################################################################################################################################
85
86 // Base class methods
87
91 virtual void addToJsonObject(JsonValue& _object, JsonAllocator& _allocator) const override;
92
96 virtual void setFromJsonObject(const ConstJsonObject& _object) override;
97
98 // ###########################################################################################################################################################################################################################################################################################################################
99
100 // Setter / Getter
101
103 void setName(const std::string& _name) { m_name = _name; };
104
106 const std::string& getName(void) const { return m_name; };
107
110 void setTitle(const std::string& _title) { m_title = _title; };
111
114 const std::string& getTitle(void) const { return m_title; };
115
118 void setToolTip(const std::string& _toolTip) { m_tooltip = _toolTip; };
119
122 const std::string& getToolTip(void) const { return m_tooltip; };
123
129 void setPosition(double _x, double _y) { this->setPosition(Point2DD(_x, _y)); };
130
135 void setPosition(const Point2DD& _pos) { m_pos = _pos; };
136
140 const Point2DD& getPosition(void) const { return m_pos; };
141
144 void setAdditionalTriggerDistance(double _d) { this->setAdditionalTriggerDistance(MarginsD(_d, _d, _d, _d)); };
145
147 void setAdditionalTriggerDistance(double _left, double _top, double _right, double _bottom) { this->setAdditionalTriggerDistance(MarginsD(_left, _top, _right, _bottom)); };
148
151 void setAdditionalTriggerDistance(const MarginsD& _d) { m_additionalTriggerDistance = _d; };
152
154 const MarginsD& getAdditionalTriggerDistance(void) const { return m_additionalTriggerDistance; };
155
158 void setMinimumSize(double _width, double _height) { this->setMinimumSize(Size2DD(_width, _height)); };
159
162 void setMinimumSize(const Size2DD& _size) { m_minSize = _size; };
163
166 const Size2DD& getMinimumSize(void) const { return m_minSize; };
167
170 void setMaximumSize(double _width, double _height) { this->setMaximumSize(Size2DD(_width, _height)); };
171
174 void setMaximumSize(const Size2DD& _size) { m_maxSize = _size; };
175
178 const Size2DD& getMaximumSize(void) const { return m_maxSize; };
179
183 void setFixedSize(double _width, double _height) { this->setFixedSize(Size2DD(_width, _height)); };
184
188 void setFixedSize(const Size2DD& _size);
189
195 void setMargins(double _left, double _top, double _right, double _bottom) { this->setMargins(ot::MarginsD(_left, _top, _right, _bottom)); };
196
199 void setMargins(const MarginsD& _margins) { m_margins = _margins; };
200
202 const MarginsD& getMargins(void) const { return m_margins; };
203
204 void setGraphicsItemFlag(GraphicsItemFlag _flag, bool _active = true) { m_flags.setFlag(_flag, _active); };
205 void setGraphicsItemFlags(const GraphicsItemFlags& _flags) { m_flags = _flags; };
206 const GraphicsItemFlags& getGraphicsItemFlags(void) const { return m_flags; };
207
210 void setAlignment(Alignment _align) { m_alignment = _align; };
211
214 Alignment getAlignment(void) const { return m_alignment; };
215
218 void setUid(const UID& _uid) { m_uid = _uid; };
219
223 const ot::UID& getUid(void) const { return m_uid; };
224
227 void setSizePolicy(SizePolicy _policy) { m_sizePolicy = _policy; };
228
232 SizePolicy getSizePolicy(void) const { return m_sizePolicy; };
233
236 void setConnectionDirection(ConnectionDirection _direction) { m_connectionDirection = _direction; };
237
241 ConnectionDirection getConnectionDirection(void) const { return m_connectionDirection; };
242
246 void addStringMapEntry(const std::string& _key, const std::string& _value) { m_stringMap.insert_or_assign(_key, _value); };
247
250 void setStringMap(const std::map<std::string, std::string>& _map) { m_stringMap = _map; };
251
255 const std::map<std::string, std::string>& getStringMap(void) const { return m_stringMap; };
256
260 std::string getStringForKey(const std::string& _key) const;
261
263 void setTransform(const Transform& _transform) { m_transform = _transform; };
264
266 const Transform& getTransform(void) const { return m_transform; };
267
268 // ###########################################################################################################################################################################################################################################################################################################################
269
270 // Helper
271
275 virtual void copyConfigDataToItem(GraphicsItemCfg* _target) const;
276
277 private:
278 std::string m_name;
279 std::string m_title;
280 ot::UID m_uid;
281 std::string m_tooltip;
282 Point2DD m_pos;
283 MarginsD m_additionalTriggerDistance;
284
285 Size2DD m_minSize;
286 Size2DD m_maxSize;
287
288 MarginsD m_margins;
289 GraphicsItemFlags m_flags;
290 ot::Alignment m_alignment;
291 ot::SizePolicy m_sizePolicy;
292 ConnectionDirection m_connectionDirection;
293
294 Transform m_transform;
295
296 std::map<std::string, std::string> m_stringMap;
297 };
298
299}
300
#define OT_ADD_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided private 32/64 bit bitfield....
Definition Flags.h:129
#define OT_GUI_API_EXPORT
Definition OTGuiAPIExport.h:9
The Flags class is a wrapper around a enum that allows bitwise operations (flags)....
Definition Flags.h:214
The GraphicsItemCfg is the base class for all graphics item configurations.
Definition GraphicsItemCfg.h:33
const ot::UID & getUid(void) const
Item UID. The item UID is used to uniquely identify an item in a GraphicsScene. The must never exist ...
Definition GraphicsItemCfg.h:223
void setName(const std::string &_name)
Set item name.
Definition GraphicsItemCfg.h:103
void setMaximumSize(double _width, double _height)
Sets the item maximum size.
Definition GraphicsItemCfg.h:170
virtual std::string getFactoryKey(void) const =0
Returns the unique GraphicsItemCfg type name that is used in the GraphicsItemCfgFactory.
void setAdditionalTriggerDistance(const MarginsD &_d)
Sets the additional trigger distance. The additional trigger distance will expand/shrink the imaginar...
Definition GraphicsItemCfg.h:151
virtual GraphicsItemCfg * createCopy(void) const =0
Creates a copy of this item.
void setStringMap(const std::map< std::string, std::string > &_map)
Sets the string map.
Definition GraphicsItemCfg.h:250
void setUid(const UID &_uid)
Set item UID.
Definition GraphicsItemCfg.h:218
const Point2DD & getPosition(void) const
Item position If the item is the root item, the position is the scene position. If the item is a chil...
Definition GraphicsItemCfg.h:140
SizePolicy getSizePolicy(void) const
Current item size policy. The item size policy is used for nested items.
Definition GraphicsItemCfg.h:232
const std::string & getTitle(void) const
Item title The item title will be displayed to the user when needed.
Definition GraphicsItemCfg.h:114
const Transform & getTransform(void) const
Get the item transform.
Definition GraphicsItemCfg.h:266
void setMargins(double _left, double _top, double _right, double _bottom)
Set item margins.
Definition GraphicsItemCfg.h:195
const Size2DD & getMinimumSize(void) const
Item minimum size. If the graphics item is resized (e.g. via layout) then it may not shrink below the...
Definition GraphicsItemCfg.h:166
void setSizePolicy(SizePolicy _policy)
Set item size policy.
Definition GraphicsItemCfg.h:227
ConnectionDirection getConnectionDirection(void) const
Current item connection direction. This has only an effect if GraphicsItemFlag::ItemIsConnectable is ...
Definition GraphicsItemCfg.h:241
const MarginsD & getMargins(void) const
Item margins.
Definition GraphicsItemCfg.h:202
void setFixedSize(double _width, double _height)
Sets the items minimum and maximum size.
Definition GraphicsItemCfg.h:183
void setTransform(const Transform &_transform)
Set the item transform.
Definition GraphicsItemCfg.h:263
const GraphicsItemFlags & getGraphicsItemFlags(void) const
Definition GraphicsItemCfg.h:206
Alignment getAlignment(void) const
Current item alignment. The alignment only has an effect if the item is nested.
Definition GraphicsItemCfg.h:214
const std::string & getToolTip(void) const
ToolTip that will be displayed to the user when he hovers over the item. If the root item in a graphi...
Definition GraphicsItemCfg.h:122
void setGraphicsItemFlag(GraphicsItemFlag _flag, bool _active=true)
Definition GraphicsItemCfg.h:204
void setAlignment(Alignment _align)
Set the item alignment.
Definition GraphicsItemCfg.h:210
Flags< GraphicsItemFlag > GraphicsItemFlags
Definition GraphicsItemCfg.h:69
void setConnectionDirection(ConnectionDirection _direction)
Set the item connection direction.
Definition GraphicsItemCfg.h:236
const std::string & getName(void) const
Item name.
Definition GraphicsItemCfg.h:106
void setTitle(const std::string &_title)
Set item title The item title will be displayed to the user when needed.
Definition GraphicsItemCfg.h:110
void setPosition(const Point2DD &_pos)
Set item position If the item is the root item, the position is the scene position....
Definition GraphicsItemCfg.h:135
void setMargins(const MarginsD &_margins)
Set item margins.
Definition GraphicsItemCfg.h:199
GraphicsItemFlag
GraphicsItemFlag.
Definition GraphicsItemCfg.h:37
const std::map< std::string, std::string > & getStringMap(void) const
The string map may be used to reference a value via a key in a complex graphics item....
Definition GraphicsItemCfg.h:255
void setAdditionalTriggerDistance(double _d)
Definition GraphicsItemCfg.h:144
void setToolTip(const std::string &_toolTip)
Set ToolTip.
Definition GraphicsItemCfg.h:118
void setGraphicsItemFlags(const GraphicsItemFlags &_flags)
Definition GraphicsItemCfg.h:205
void setMaximumSize(const Size2DD &_size)
Sets the item maximum size.
Definition GraphicsItemCfg.h:174
void setMinimumSize(const Size2DD &_size)
Sets the item minimum size.
Definition GraphicsItemCfg.h:162
const MarginsD & getAdditionalTriggerDistance(void) const
Definition GraphicsItemCfg.h:154
void addStringMapEntry(const std::string &_key, const std::string &_value)
Adds the provided entry to the string map. If an entry for the same key already exists it will be rep...
Definition GraphicsItemCfg.h:246
void setMinimumSize(double _width, double _height)
Sets the item minimum size.
Definition GraphicsItemCfg.h:158
const Size2DD & getMaximumSize(void) const
Item maximum size. If the graphics item is resized (e.g. via layout) then it may not brow above the m...
Definition GraphicsItemCfg.h:178
void setPosition(double _x, double _y)
Set item position If the item is the root item, the position is the scene position....
Definition GraphicsItemCfg.h:129
void setAdditionalTriggerDistance(double _left, double _top, double _right, double _bottom)
Definition GraphicsItemCfg.h:147
Definition Margins.h:98
2D Point with double values
Definition Point2D.h:144
The Serializable class is the default interface of serializable objects.
Definition Serializable.h:17
2D Size with double values
Definition Size2D.h:115
General item transformation.
Definition Transform.h:16
Definition Connector.h:8
SizePolicy
Size policy for UI elements.
Definition GuiTypes.h:58
ConnectionDirection
Describes in which direction a connetion from an item is starting.
Definition GuiTypes.h:65
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27
Alignment
Alignment.
Definition GuiTypes.h:21
rapidjson::Value JsonValue
Writable JSON value.
Definition JSON.h:27
rapidjson::GenericObject< true, rapidjson::GenericValue< rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > > > ConstJsonObject
Read only JSON Object.
Definition JSON.h:35
rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > JsonAllocator
Allocator used for writing to JSON values.
Definition JSON.h:30