Antares Simulator
Power System Simulator
manager.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_CONTAINER_H__
22 #define __ANTARES_TOOLBOX_MAP_CONTAINER_H__
23 
24 #include <antares/study/study.h>
25 #include <vector>
26 #include <queue>
27 #include "nodes/node.h"
28 
29 namespace Antares::Map
30 {
32 using BoundingBox = std::pair<wxPoint, wxPoint>;
33 
34 // Forward declarations
35 class Connection;
36 class Component;
37 class Node;
38 class BindingConstraint;
39 
43 class Manager final
44 {
45 public:
49  static Manager* Instance();
50 
51 public:
53 
54 
57  Manager(Component& component);
59  ~Manager();
61 
63 
64 
67  void attachStudy(Data::Study::Ptr study);
68 
72  Data::Study::Ptr study() const
73  {
74  return pStudy;
75  }
76 
78 
80 
81 
84  BoundingBox boundingBox(const size_t& layerID) const;
85 
89  BoundingBox boundingBoxOfSelectedNodes(const size_t& layerID) const;
90 
97  // void recentreAllNodes(const int offsetX = 0, const int offsetY = 0);
99 
101 
102 
109 
113  bool loadFromAttachedStudy();
114 
118  template<class T>
119  T* add();
120 
124  Node* addNode(const wxString& id);
125 
129  Node* addNode(const wxString& id, const wxString& caption, const int x, const int y);
130 
135 
139  void addConnectionFromEachSelectedItem(Item* to, Item::Vector* results = NULL);
140 
144  bool remove(const wxString& text);
145 
150  uint removeAllSelected();
151 
155  void hideAllSelected(size_t id);
156 
160  void showAllSelected(size_t id);
161 
165  void clear();
166 
170  Item* find(const int x, const int y) const;
171 
183  Item::Vector* find(const int x1, const int y1, const int x2, const int y2) const;
184 
188  Item* find(const wxString& text) const;
189 
190  Node* find(const Data::Area* area);
191 
195  void moveAllSelected(const int x, const int y);
196 
200  void invalidateAllNodes();
201 
205  void refreshCacheForAllNodes(wxDC& dc);
207 
209 
210 
213  void selectOnly(Item* item);
214 
215  void changeItemSelectionState(Item* item);
216 
217  void selectOnly(const Item::Vector& item);
218 
219  void selectOnly(const Data::Area::Vector& areas);
220 
221  void selectOnly(const Data::Area::Vector& areas, const Data::AreaLink::Vector& links);
222 
226  void selectAllNodes(size_t layerID);
227 
231  void selectAllItems(size_t layerID);
232 
236  void selectAllAreas(size_t layerID);
237 
241  void selectAllLinks(size_t layerID);
242 
246  void unselectAll();
247 
251  void reverseSelection();
252 
256  void selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const size_t layerID = 0);
257 
261  uint selectedItemsCount() const
262  {
263  return (uint)pSelectedItems.size();
264  }
265 
266  uint selectedItemsAsConnectionCount() const
267  {
268  return (uint)pSelectedItemsAsConnection;
269  }
270 
271  void getAllSelectedItems(std::vector<Item*>& list);
272 
273  Data::AreaName findNewCaption(Data::AreaName = "") const;
275 
276  void beginUpdate();
277  void endUpdate();
278 
282  void draw(DrawingContext& dc);
283 
284  void drawExternalDrawer(DrawingContext& dc);
285 
286  bool hasChanges() const
287  {
288  return pHasChanges;
289  }
290 
291  void setChangesFlag(bool v)
292  {
293  pHasChanges = v;
294  }
295 
299  uint areasCount(const size_t& layerID) const;
300 
304  void removeLayerVisibility(const size_t& layerID);
305 
306  size_t getActiveLayerId();
307 
311  uint connectionsCount(const size_t& layerID) const;
312 
313  void pendingDeleteArea(Data::Area* area);
314  void pendingDeleteLink(Data::AreaLink* lnk);
315 
316 public:
317  bool mouseSelectionArea;
318  bool mouseSelectionLinks;
319  bool mouseSelectionPlants;
320  bool mouseSelectionConstraints;
321 
322 private:
323  void internalAddItem(Item* item, bool takeOwnership = false);
324  void internalRemoveItem(Item* item);
325  bool removeTheFirstSelectedItem();
326 
327  void deallocationStackAdd(Item* i);
328  void deallocationStackRemove(Item* it);
329  bool deallocationStackExists(Item* it);
330 
331  void deleteAllPendingData();
332 
333 private:
335  using NodeMap = std::map<Item*, bool>;
336  using NodeByZPosition = std::map<int, NodeMap>;
337 
338 private:
339  Component& pComponent;
340  Data::Study::Ptr pStudy;
341 
342  NodeByZPosition pAllNodes;
343 
344  Item::Set pStackDeallocation;
345 
346  NodeMap pSelectedItems;
347  int pSelectedItemsAsConnection;
348 
349  std::queue<Item*> pExternalQueue;
350 
351  bool pHasChanges;
352 
354  uint pUpdaterLock;
355 
356  Data::AreaLink::Vector pLinksToDelete;
357  Data::Area::Vector pAreasToDelete;
358 
359  // Some friends
360  friend class ::Antares::Map::Item;
361  friend class ::Antares::Map::Node;
362  friend class ::Antares::Map::Connection;
363  friend class ::Antares::Map::BindingConstraint;
364 
365 }; // class Manager
366 
367 } // namespace Antares::Map
368 
369 #include "manager.hxx"
370 #include "nodes/connection.h"
371 
372 #endif // __ANTARES_TOOLBOX_MAP_CONTAINER_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Standard study MAP.
Definition: component.h:40
Definition: connection.h:38
Definition: item.h:39
A convenient container for nodes on the graph.
Definition: manager.h:44
Manager(Component &component)
Default Constructor.
Definition: manager.cpp:48
uint removeAllSelected()
Remove all selected items.
Definition: manager.cpp:1101
void selectOnly(Item *item)
Select a single item (a node or an interconnection)
Definition: manager.cpp:477
bool remove(const wxString &text)
Remove a node from its id or its caption.
Definition: manager.cpp:203
void selectAllItems(size_t layerID)
Select all items, without any distinction.
Definition: manager.cpp:696
uint areasCount(const size_t &layerID) const
Get how many area we have.
Definition: manager.cpp:1192
BoundingBox boundingBox(const size_t &layerID) const
Get the 2D-Bounding box wich contains all nodes.
Definition: manager.cpp:148
void showAllSelected(size_t id)
Show all selected items from a layer.
Definition: manager.cpp:1137
T * add()
Add a new node in the map.
Definition: manager.hxx:47
Data::Study::Ptr study() const
Get the attached study to this map.
Definition: manager.h:72
void selectAllLinks(size_t layerID)
Select all links.
Definition: manager.cpp:703
void attachStudy(Data::Study::Ptr study)
Attach this map to an existing study.
Definition: manager.cpp:78
void unselectAll()
Unselect all nodes.
Definition: manager.cpp:619
Item * find(const int x, const int y) const
Find a node from its position.
Definition: manager.cpp:219
uint connectionsCount(const size_t &layerID) const
Get how many connections we have.
Definition: manager.cpp:1256
void invalidateAllNodes()
Invalidate all nodes.
Definition: manager.cpp:290
void clear()
Clear (and destroy) all nodes.
Definition: manager.cpp:912
void reverseSelection()
Reverse the selection.
Definition: manager.cpp:731
bool loadFromStudy(Data::Study &study)
Load the layout from an existing study.
Definition: manager.cpp:83
uint selectedItemsCount() const
Get the count of nodes that are selected.
Definition: manager.h:261
void removeLayerVisibility(const size_t &layerID)
remove layer visibility for all nodes
Definition: manager.cpp:1217
void selectAllAreas(size_t layerID)
Select all areas only.
Definition: manager.cpp:667
void refreshCacheForAllNodes(wxDC &dc)
Update the cache for all nodes.
Definition: manager.cpp:332
~Manager()
Destructor.
Definition: manager.cpp:66
void moveAllSelected(const int x, const int y)
Moved all selected nodes.
Definition: manager.cpp:763
BoundingBox boundingBoxOfSelectedNodes(const size_t &layerID) const
Get the 2D-Bounding box wich contains all nodes.
Definition: manager.cpp:168
void draw(DrawingContext &dc)
Draw all items.
Definition: manager.cpp:983
void addConnectionFromEachSelectedItem(Item *to, Item::Vector *results=NULL)
Add a connection for each selected item to a item.
Definition: manager.cpp:1016
Node * addNode(const wxString &id)
Add a new node with a given id.
Definition: manager.cpp:187
void hideAllSelected(size_t id)
Hide all selected items from a layer.
Definition: manager.cpp:1117
static Manager * Instance()
Get the instance of the main window.
Definition: manager.cpp:41
void selectFromBoundingBox(const wxPoint &a, const wxPoint &b, const size_t layerID=0)
Select all nodes which are contained in a bounding box.
Definition: manager.cpp:775
bool loadFromAttachedStudy()
Load the layout from the attached study.
Definition: manager.hxx:41
void selectAllNodes(size_t layerID)
Select all nodes.
Definition: manager.cpp:638
Connection * addConnection(Item *a, Item *b)
Add a connection between two items.
Definition: manager.cpp:1004
A node in a map.
Definition: node.h:39