Loading [MathJax]/extensions/tex2jax.js
Antares Simulator
Power System Simulator
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages Concepts
item.h
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __ANTARES_TOOLBOX_MAP_ITEM_H__
22#define __ANTARES_TOOLBOX_MAP_ITEM_H__
23
24#include <vector>
25#include <set>
26#include <map>
27#include <wx/gdicmn.h>
28#include <wx/colour.h>
29#include <wx/dc.h>
30
31namespace Antares
32{
33namespace Map
34{
35class DrawingContext;
36class Manager;
37class Connection;
38class BindingConstraint;
39
40class Item
41{
42public:
44 {
45 bool operator()(const Item* s1, const Item* s2) const
46 {
47 return s1 < s2;
48 }
49 };
50
51 using Vector = std::vector<Item*>;
52
53 using Set = std::set<Item*, SetCompare>;
54
55 using Links = std::map<Item*, bool>;
56
57 enum Type
58 {
59 tyUnknown,
60 tyNode,
61 tyConnection,
62 tyBindingConstraint,
63 };
64
65public:
67
68
71 Item(Manager& manager, const int zPos = 0);
75 virtual ~Item();
77
81 virtual Type type() const
82 {
83 return tyUnknown;
84 }
85
87
88
92 {
93 return pManager;
94 };
95 const Manager& manager() const
96 {
97 return pManager;
98 };
100
102
103
106 virtual bool isVisibleOnLayer(const size_t& /* layerID */) const
107 {
108 return false;
109 }
111
113
114 const wxString& caption() const
115 {
116 return pCaption;
117 }
118 void caption(const wxString& v)
119 {
120 pCaption = v;
121 forceReload();
122 captionHasChanged();
123 }
125
127
128 int x() const
129 {
130 return pX;
131 }
132 void x(const int v)
133 {
134 pX = v;
135 forceReload();
136 positionHasChanged();
137 }
139
141
142 int y() const
143 {
144 return pY;
145 }
146 void y(const int v)
147 {
148 pY = v;
149 forceReload();
150 positionHasChanged();
151 }
153
154 virtual wxPoint absolutePosition(DrawingContext& dc) const;
155
157
158 const wxColour& color() const
159 {
160 return pColor;
161 }
162 void color(const wxColour& c);
163 void color(const wxString& s);
164 void color(const int r, const int g, const int b);
165 void color(const int r, const int g, const int b, const int alpha);
167
169
170 virtual bool selected() const
171 {
172 return pSelected;
173 }
174 virtual void selected(bool v);
176
178
179 int zPosition() const
180 {
181 return pZPosition;
182 }
184
186
187
190 virtual void refreshCache(wxDC& dc) = 0;
191
195 void forceReload();
196
200 bool isInvalidated() const
201 {
202 return pInvalidated;
203 }
205
207
208
213 virtual bool contains(const int x, const int y, double& distance) = 0;
214
220 virtual bool isContained(const int x1, const int y1, const int x2, const int y2) const = 0;
221
225 virtual void draw(DrawingContext& dc) = 0;
226
227 virtual void drawExternalDrawer(DrawingContext&)
228 {
229 }
231
232 virtual void move(const int x, const int y);
233
237 virtual void extendBoundingBox(wxPoint& topLeft, wxPoint& bottomRight) = 0;
238
240
241
244 virtual void mouseDblClick()
245 {
246 }
248
249protected:
250 void internalClearAllLinks();
251
252 virtual void captionHasChanged()
253 {
254 }
255 virtual void positionHasChanged()
256 {
257 }
258 virtual void colorHasChanged()
259 {
260 }
261
262protected:
263 Manager& pManager;
265 wxColour pColor;
270
272 int pX;
274 int pY;
276 wxString pCaption;
277
279 Links* pLinks;
280
281 int pZPosition;
282
283 // Friends
284 friend class ::Antares::Map::Manager;
285 friend class ::Antares::Map::Connection;
286 friend class ::Antares::Map::BindingConstraint;
287}; // class Item
288
289} // namespace Map
290} // namespace Antares
291
292#include "../drawingcontext.h"
293#include "../manager.h"
294#include "connection.h"
295
296#endif // __ANTARES_TOOLBOX_MAP_ITEM_H__
Drawing Context.
Definition drawingcontext.h:43
Definition item.h:41
Manager & manager()
Get the manager.
Definition item.h:91
virtual ~Item()
Destructor.
Definition item.cpp:44
virtual void mouseDblClick()
Mouse double click.
Definition item.h:244
virtual bool contains(const int x, const int y, double &distance)=0
Get if the drawing representation of the node contains the point (x,y)
virtual bool isContained(const int x1, const int y1, const int x2, const int y2) const =0
Get if the drawing representation of the node is contained inside a bounding box.
virtual void extendBoundingBox(wxPoint &topLeft, wxPoint &bottomRight)=0
Extends the bounding box.
bool pSelected
Selected.
Definition item.h:267
virtual void refreshCache(wxDC &dc)=0
Refresh the cache (even if not invalidated)
int pY
X-Coordinate.
Definition item.h:274
virtual void draw(DrawingContext &dc)=0
Draw the node.
int pX
Y-Coordinate.
Definition item.h:272
Links * pLinks
Linked with other items.
Definition item.h:279
wxColour pColor
Color.
Definition item.h:265
virtual Type type() const
Type.
Definition item.h:81
virtual bool isVisibleOnLayer(const size_t &) const
Get the visivility for a layerId.
Definition item.h:106
Item(Manager &manager, const int zPos=0)
Constructor.
Definition item.cpp:30
wxString pCaption
Caption.
Definition item.h:276
void forceReload()
Mark the node as invalidated (to force its refresh for the next canvas update)
Definition item.cpp:136
bool pInvalidated
invalidated
Definition item.h:269
bool isInvalidated() const
Get the node is invalidated.
Definition item.h:200
A convenient container for nodes on the graph.
Definition manager.h:46
Definition item.h:44