Antares Simulator
Power System Simulator
item.h
1 /*
2  * Copyright 2007-2025, 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 
31 namespace Antares::Map
32 {
33 class DrawingContext;
34 class Manager;
35 class Connection;
36 class BindingConstraint;
37 
38 class Item
39 {
40 public:
41  struct SetCompare
42  {
43  bool operator()(const Item* s1, const Item* s2) const
44  {
45  return s1 < s2;
46  }
47  };
48 
49  using Vector = std::vector<Item*>;
50 
51  using Set = std::set<Item*, SetCompare>;
52 
53  using Links = std::map<Item*, bool>;
54 
55  enum Type
56  {
57  tyUnknown,
58  tyNode,
59  tyConnection,
60  tyBindingConstraint,
61  };
62 
63 public:
65 
66 
69  Item(Manager& manager, const int zPos = 0);
73  virtual ~Item();
74 
76 
80  virtual Type type() const
81  {
82  return tyUnknown;
83  }
84 
86 
87 
91  {
92  return pManager;
93  }
94 
95  const Manager& manager() const
96  {
97  return pManager;
98  }
99 
101 
103 
104 
107  virtual bool isVisibleOnLayer(const size_t& /* layerID */) const
108  {
109  return false;
110  }
111 
113 
115 
116  const wxString& caption() const
117  {
118  return pCaption;
119  }
120 
121  void caption(const wxString& v)
122  {
123  pCaption = v;
124  forceReload();
125  captionHasChanged();
126  }
127 
129 
131 
132  int x() const
133  {
134  return pX;
135  }
136 
137  void x(const int v)
138  {
139  pX = v;
140  forceReload();
141  positionHasChanged();
142  }
143 
145 
147 
148  int y() const
149  {
150  return pY;
151  }
152 
153  void y(const int v)
154  {
155  pY = v;
156  forceReload();
157  positionHasChanged();
158  }
159 
161 
162  virtual wxPoint absolutePosition(DrawingContext& dc) const;
163 
165 
166  const wxColour& color() const
167  {
168  return pColor;
169  }
170 
171  void color(const wxColour& c);
172  void color(const wxString& s);
173  void color(const int r, const int g, const int b);
174  void color(const int r, const int g, const int b, const int alpha);
175 
177 
179 
180  virtual bool selected() const
181  {
182  return pSelected;
183  }
184 
185  virtual void selected(bool v);
186 
188 
190 
191  int zPosition() const
192  {
193  return pZPosition;
194  }
195 
197 
199 
200 
203  virtual void refreshCache(wxDC& dc) = 0;
204 
208  void forceReload();
209 
213  bool isInvalidated() const
214  {
215  return pInvalidated;
216  }
217 
219 
221 
222 
227  virtual bool contains(const int x, const int y, double& distance) = 0;
228 
234  virtual bool isContained(const int x1, const int y1, const int x2, const int y2) const = 0;
235 
239  virtual void draw(DrawingContext& dc) = 0;
240 
241  virtual void drawExternalDrawer(DrawingContext&)
242  {
243  }
244 
246 
247  virtual void move(const int x, const int y);
248 
252  virtual void extendBoundingBox(wxPoint& topLeft, wxPoint& bottomRight) = 0;
253 
255 
256 
259  virtual void mouseDblClick()
260  {
261  }
262 
264 
265 protected:
266  void internalClearAllLinks();
267 
268  virtual void captionHasChanged()
269  {
270  }
271 
272  virtual void positionHasChanged()
273  {
274  }
275 
276  virtual void colorHasChanged()
277  {
278  }
279 
280 protected:
281  Manager& pManager;
283  wxColour pColor;
285  bool pSelected;
288 
290  int pX;
292  int pY;
294  wxString pCaption;
295 
297  Links* pLinks;
298 
299  int pZPosition;
300 
301  // Friends
302  friend class ::Antares::Map::Manager;
303  friend class ::Antares::Map::Connection;
304  friend class ::Antares::Map::BindingConstraint;
305 }; // class Item
306 
307 } // namespace Antares::Map
308 
309 #include "../drawingcontext.h"
310 #include "../manager.h"
311 #include "connection.h"
312 
313 #endif // __ANTARES_TOOLBOX_MAP_ITEM_H__
Drawing Context.
Definition: drawingcontext.h:41
Definition: item.h:39
Manager & manager()
Get the manager.
Definition: item.h:90
virtual ~Item()
Destructor.
Definition: item.cpp:42
virtual void mouseDblClick()
Mouse double click.
Definition: item.h:259
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:285
virtual void refreshCache(wxDC &dc)=0
Refresh the cache (even if not invalidated)
int pY
X-Coordinate.
Definition: item.h:292
virtual void draw(DrawingContext &dc)=0
Draw the node.
int pX
Y-Coordinate.
Definition: item.h:290
Links * pLinks
Linked with other items.
Definition: item.h:297
wxColour pColor
Color.
Definition: item.h:283
virtual Type type() const
Type.
Definition: item.h:80
virtual bool isVisibleOnLayer(const size_t &) const
Get the visivility for a layerId.
Definition: item.h:107
Item(Manager &manager, const int zPos=0)
Constructor.
Definition: item.cpp:28
wxString pCaption
Caption.
Definition: item.h:294
void forceReload()
Mark the node as invalidated (to force its refresh for the next canvas update)
Definition: item.cpp:142
bool pInvalidated
invalidated
Definition: item.h:287
bool isInvalidated() const
Get the node is invalidated.
Definition: item.h:213
A convenient container for nodes on the graph.
Definition: manager.h:44
Definition: item.h:42