Antares Simulator
Power System Simulator
control.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_CONTROL_H__
22 #define __ANTARES_TOOLBOX_MAP_CONTROL_H__
23 
24 #include <wx/scrolwin.h>
25 #include "nodes/node.h"
26 #include "manager.h"
27 #include "tools/tool.h"
28 #include "settings.h"
29 #include "../notebook/notebook.h"
30 
31 #define DEFAULT_MAP_WIDTH 1680
32 #define DEFAULT_MAP_HEIGHT 1050
33 
34 namespace Antares::Map
35 {
36 // Forward declaration
37 class Component;
38 
42 class Control final: public wxScrolledWindow
43 {
44  friend class Component;
45 
46 public:
47  enum
48  {
49  gridSize = 75,
50  };
51 
52 public:
54 
55 
61  Control(wxWindow* parent, Component& component);
62 
64 
65 
72  Control(wxWindow* parent, Component& component, size_t uID);
73 
75  virtual ~Control();
76 
78 
82  const size_t& getUid() const
83  {
84  return this->uid;
85  }
86 
88 
89  double zoom() const
90  {
91  return pZoom;
92  }
93 
94  void zoom(const double v);
95 
97 
98  void forceReload()
99  {
100  pInvalidated = true;
101  }
102 
103  const wxColour& getBackgroundColor()
104  {
105  return pBackgroundColor;
106  }
107 
108  void setBackgroundColor(const wxColour& newColor)
109  {
110  pBackgroundColor = newColor;
111  }
112 
114 
115 
120  void render(wxPaintEvent& evt);
121 
127  wxBitmap getRenderedMapImage(const MapRenderOptions& mapOptions);
129 
131 
132 
137  void paintGraph(wxDC& dc, bool inFile = false);
138 
139  void refresh()
140  {
141  this->Refresh();
142  }
143 
144  void reset();
145 
146  void mouseMoved(wxMouseEvent& evt);
147 
148  void mouseLeftDown(wxMouseEvent& evt);
149 
150  void mouseWheelMoved(wxMouseEvent& evt);
151 
152  void mouseLeftUp(wxMouseEvent& evt);
153 
154  void rightClick(wxMouseEvent& evt);
155 
156  void mouseLeftWindow(wxMouseEvent& evt);
157 
158  void keyPressed(wxKeyEvent& evt);
159 
160  void keyReleased(wxKeyEvent& evt);
161 
162  void keyChar(wxKeyEvent& evt);
163 
164  void mouseDblClick(wxMouseEvent& evt);
165 
169  uint areasCount() const;
170 
171  void setpInfosAreaCount(wxStaticText* infosAreaCount)
172  {
173  pInfosAreaCount = infosAreaCount;
174  }
175 
176  wxStaticText* getpInfosAreaCount()
177  {
178  return pInfosAreaCount;
179  }
180 
184  uint connectionsCount() const;
185 
186  void setpInfosConnxCount(wxStaticText* infosConnxCount)
187  {
188  pInfosConnxCount = infosConnxCount;
189  }
190 
191  wxStaticText* getpInfosConnxCount()
192  {
193  return pInfosConnxCount;
194  }
195 
196  void setPointX(wxTextCtrl* textCtrl)
197  {
198  pointX = textCtrl;
199  }
200 
201  wxTextCtrl* getPointX()
202  {
203  return pointX;
204  }
205 
206  void setPointY(wxTextCtrl* textCtrl)
207  {
208  pointY = textCtrl;
209  }
210 
211  wxTextCtrl* getPointY()
212  {
213  return pointY;
214  }
215 
216  void addNewNode(uint count = 1);
217  void addNewNodeWhereTheMouseIs();
218  void addNewLoadNodeWhereTheMouseIs();
219  void addNewThermalNodeWhereTheMouseIs();
220  void addNewNuclearNodeWhereTheMouseIs();
221  void addNewCCGTNodeWhereTheMouseIs();
222  void addNewCoalNodeWhereTheMouseIs();
223  void addNewOilNodeWhereTheMouseIs();
224  void addNewHydroNodeWhereTheMouseIs();
225  void addNewPSPPNodeWhereTheMouseIs();
226  void addNewRENWNodeWhereTheMouseIs();
227  void addNewWindNodeWhereTheMouseIs();
228  void addNewSolarNodeWhereTheMouseIs();
229  void addNewBioMNodeWhereTheMouseIs();
230  void addNewVoidNodeWhereTheMouseIs();
231  void addNewVirtualNodeWhereTheMouseIs();
232 
233  void recenter();
234  void recenter(int x, int y);
235 
236  void computeBoundingBoxOfSelectedNodes();
237 
238 public:
241 
247  // Antares::Component::Button* pBtnSelectionPlant;
250 
252  Yuni::Event<void(int, int)> onPopupEvent;
253 
255  static size_t newUID;
256 
257 private:
261  void refreshCache();
262 
263  void updateMouseInfosFromEvent(wxMouseEvent& evt);
264 
269  void drawGrid(wxDC& dc);
274  void drawSelectionBox(wxDC& dc);
279  void drawTools(DrawingContext& drawingContext);
281 
282  void preDrawBoundingBoxOfSelectedNodes(wxDC& dc, const BoundingBox& bb);
283 
284  void drawSingleNode(wxDC& dc, Node* node);
285 
286  void removeTools();
287  void removeTools(const Tool::LifeSpan filter);
288  Tool::Tool* findTool(const int x, const int y);
289 
290  void performActionForSelectedTool();
291 
292  void addToolsForCurrentSelection();
293 
294  void onScroll(wxScrollWinEvent& evt);
295 
296  void onSize(wxSizeEvent& evt);
297 
298 private:
299  enum MouseAction
300  {
301  mouseActionNone,
302  mouseActionSelectionBox,
303  mouseActionMoveSelection,
304  mouseActionTool,
305  };
306 
307 private:
308  Component& pComponent;
309  bool pInvalidated = true;
310  bool pInvalidatedInnerCacheSize = true;
311 
312  wxTextCtrl* pointX = nullptr;
313  wxTextCtrl* pointY = nullptr;
314  wxStaticText* pInfosAreaCount = nullptr;
315  wxStaticText* pInfosConnxCount = nullptr;
317  double pZoom = 1.;
318  wxColour pBackgroundColor = Settings::background;
319 
320  wxPoint pCachedRealSize;
321  wxPoint pCachedBoxSize;
322  wxPoint pCachedOrigin;
323  wxPoint pOffsetForSelectedNodes;
324  wxPoint pBottomRight;
325 
326  bool pKeyShift = false;
327  bool pKeyCtrl = false;
328  wxPoint pCurrentScroll;
329  wxPoint pCurrentMousePosition;
330  wxPoint pCurrentMousePositionGraph;
331  wxPoint pCurrentClientSize;
332  wxPoint pLastMousePosition;
333  Tool::Tool* pLastSelectedTool = nullptr;
334  Tool::Tool* pRemoverForSelection = nullptr;
335 
336  MouseAction pMouseAction = mouseActionNone;
337  BoundingBox pSelectionBox;
338 
339  Tool::List pTools;
340 
341  int previousMaxSizeX = -1;
342  int previousMaxSizeY = -1;
343 
344  const size_t uid;
345 
346  Antares::Component::Notebook::Page* pPage = nullptr;
347 
348  bool wasDrawn = false;
349 
350  // Event table
351  DECLARE_EVENT_TABLE()
352 
353 }; // class Control
354 
355 } // namespace Antares::Map
356 
357 #endif // __ANTARES_TOOLBOX_MAP_CONTROL_H__
Definition: button.h:32
Definition: notebook.h:61
Standard study MAP.
Definition: component.h:40
Sub-Component for drawing the map and handle user-events.
Definition: control.h:43
Antares::Component::Button * pBtnSelectionArea
The toggle button for selecting areas with the mouse.
Definition: control.h:243
Yuni::Event< void(int, int)> onPopupEvent
Popup event.
Definition: control.h:252
static size_t newUID
Control id management.
Definition: control.h:255
wxBitmap getRenderedMapImage(const MapRenderOptions &mapOptions)
Renders the map in an image object for further on-disk storage.
Definition: control.cpp:172
Control(wxWindow *parent, Component &component)
Default Constructor.
Definition: control.cpp:67
virtual ~Control()
Destructor.
Definition: control.cpp:122
void render(wxPaintEvent &evt)
Renders the map on screen.
Definition: control.cpp:152
uint areasCount() const
Get how many area we have.
Definition: control.cpp:1440
Manager & nodes
All nodes.
Definition: control.h:240
Antares::Component::Button * pBtnSelectionLink
The toggle button for selecting links with the mouse.
Definition: control.h:245
uint connectionsCount() const
Get how many connections we have.
Definition: control.cpp:1445
const size_t & getUid() const
get Control id
Definition: control.h:82
void recenter()
Definition: control.cpp:1102
Antares::Component::Button * pBtnSelectionConstraint
The toggle button for selecting clusters with the mouse.
Definition: control.h:249
void paintGraph(wxDC &dc, bool inFile=false)
Paints the.
Definition: control.cpp:293
Drawing Context.
Definition: drawingcontext.h:41
A convenient container for nodes on the graph.
Definition: manager.h:44
A node in a map.
Definition: node.h:39
Visual component to make an action on the selected items.
Definition: tool.h:48