Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
manager.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_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
29namespace Antares
30{
31namespace Map
32{
34using BoundingBox = std::pair<wxPoint, wxPoint>;
35
36// Forward declarations
37class Connection;
38class Component;
39class Node;
40class BindingConstraint;
41
45class Manager final
46{
47public:
51 static Manager* Instance();
52
53public:
55
56
59 Manager(Component& component);
61 ~Manager();
63
65
66
69 void attachStudy(Data::Study::Ptr study);
70
74 Data::Study::Ptr study() const
75 {
76 return pStudy;
77 }
79
81
82
85 BoundingBox boundingBox(const size_t& layerID) const;
86
90 BoundingBox boundingBoxOfSelectedNodes(const size_t& layerID) const;
91
98 // void recentreAllNodes(const int offsetX = 0, const int offsetY = 0);
100
102
103
110
115
119 template<class T>
120 T* add();
121
125 Node* addNode(const wxString& id);
126
130 Node* addNode(const wxString& id, const wxString& caption, const int x, const int y);
131
136
140 void addConnectionFromEachSelectedItem(Item* to, Item::Vector* results = NULL);
141
145 bool remove(const wxString& text);
146
151 uint removeAllSelected();
152
156 void hideAllSelected(size_t id);
157
161 void showAllSelected(size_t id);
162
166 void clear();
167
171 Item* find(const int x, const int y) const;
172
184 Item::Vector* find(const int x1, const int y1, const int x2, const int y2) const;
185
189 Item* find(const wxString& text) const;
190
191 Node* find(const Data::Area* area);
192
196 void moveAllSelected(const int x, const int y);
197
201 void invalidateAllNodes();
202
206 void refreshCacheForAllNodes(wxDC& dc);
208
210
211
214 void selectOnly(Item* item);
215
216 void changeItemSelectionState(Item* item);
217
218 void selectOnly(const Item::Vector& item);
219
220 void selectOnly(const Data::Area::Vector& areas);
221
222 void selectOnly(const Data::Area::Vector& areas, const Data::AreaLink::Vector& links);
223
227 void selectAllNodes(size_t layerID);
228
232 void selectAllItems(size_t layerID);
233
237 void selectAllAreas(size_t layerID);
238
242 void selectAllLinks(size_t layerID);
243
247 void unselectAll();
248
252 void reverseSelection();
253
257 void selectFromBoundingBox(const wxPoint& a, const wxPoint& b, const size_t layerID = 0);
258
263 {
264 return (uint)pSelectedItems.size();
265 }
266
267 uint selectedItemsAsConnectionCount() const
268 {
269 return (uint)pSelectedItemsAsConnection;
270 };
271
272 void getAllSelectedItems(std::vector<Item*>& list);
273
274 Data::AreaName findNewCaption(Data::AreaName = "") const;
276
277 void beginUpdate();
278 void endUpdate();
279
283 void draw(DrawingContext& dc);
284
285 void drawExternalDrawer(DrawingContext& dc);
286
287 bool hasChanges() const
288 {
289 return pHasChanges;
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
316public:
317 bool mouseSelectionArea;
318 bool mouseSelectionLinks;
319 bool mouseSelectionPlants;
320 bool mouseSelectionConstraints;
321
322private:
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
333private:
335 using NodeMap = std::map<Item*, bool>;
336 using NodeByZPosition = std::map<int, NodeMap>;
337
338private:
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 Map
368} // namespace Antares
369
370#include "nodes/connection.h"
371#include "manager.hxx"
372
373#endif // __ANTARES_TOOLBOX_MAP_CONTAINER_H__
Definition for a single area.
Definition area.h:52
Definition study.h:61
Standard study MAP.
Definition component.h:42
Definition connection.h:40
Definition item.h:41
A convenient container for nodes on the graph.
Definition manager.h:46
Manager(Component &component)
Default Constructor.
Definition manager.cpp:50
uint removeAllSelected()
Remove all selected items.
Definition manager.cpp:1005
void selectOnly(Item *item)
Select a single item (a node or an interconnection)
Definition manager.cpp:447
bool remove(const wxString &text)
Remove a node from its id or its caption.
Definition manager.cpp:189
void selectAllItems(size_t layerID)
Select all items, without any distinction.
Definition manager.cpp:650
uint areasCount(const size_t &layerID) const
Get how many area we have.
Definition manager.cpp:1086
BoundingBox boundingBox(const size_t &layerID) const
Get the 2D-Bounding box wich contains all nodes.
Definition manager.cpp:140
void showAllSelected(size_t id)
Show all selected items from a layer.
Definition manager.cpp:1035
T * add()
Add a new node in the map.
Definition manager.hxx:49
Data::Study::Ptr study() const
Get the attached study to this map.
Definition manager.h:74
void selectAllLinks(size_t layerID)
Select all links.
Definition manager.cpp:657
void attachStudy(Data::Study::Ptr study)
Attach this map to an existing study.
Definition manager.cpp:80
void unselectAll()
Unselect all nodes.
Definition manager.cpp:579
Item * find(const int x, const int y) const
Find a node from its position.
Definition manager.cpp:205
uint connectionsCount(const size_t &layerID) const
Get how many connections we have.
Definition manager.cpp:1142
void invalidateAllNodes()
Invalidate all nodes.
Definition manager.cpp:272
void clear()
Clear (and destroy) all nodes.
Definition manager.cpp:842
void reverseSelection()
Reverse the selection.
Definition manager.cpp:685
bool loadFromStudy(Data::Study &study)
Load the layout from an existing study.
Definition manager.cpp:85
uint selectedItemsCount() const
Get the count of nodes that are selected.
Definition manager.h:262
void removeLayerVisibility(const size_t &layerID)
remove layer visibility for all nodes
Definition manager.cpp:1107
void selectAllAreas(size_t layerID)
Select all areas only.
Definition manager.cpp:623
void refreshCacheForAllNodes(wxDC &dc)
Update the cache for all nodes.
Definition manager.cpp:312
~Manager()
Destructor.
Definition manager.cpp:68
void moveAllSelected(const int x, const int y)
Moved all selected nodes.
Definition manager.cpp:713
BoundingBox boundingBoxOfSelectedNodes(const size_t &layerID) const
Get the 2D-Bounding box wich contains all nodes.
Definition manager.cpp:156
void draw(DrawingContext &dc)
Draw all items.
Definition manager.cpp:907
void addConnectionFromEachSelectedItem(Item *to, Item::Vector *results=NULL)
Add a connection for each selected item to a item.
Definition manager.cpp:934
Node * addNode(const wxString &id)
Add a new node with a given id.
Definition manager.cpp:173
void hideAllSelected(size_t id)
Hide all selected items from a layer.
Definition manager.cpp:1019
static Manager * Instance()
Get the instance of the main window.
Definition manager.cpp:43
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:723
bool loadFromAttachedStudy()
Load the layout from the attached study.
Definition manager.hxx:43
void selectAllNodes(size_t layerID)
Select all nodes.
Definition manager.cpp:596
Connection * addConnection(Item *a, Item *b)
Add a connection between two items.
Definition manager.cpp:924
A node in a map.
Definition node.h:41