Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
control.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_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
34namespace Antares
35{
36namespace Map
37{
38// Forward declaration
39class Component;
40
44class Control final : public wxScrolledWindow
45{
46 friend class Component;
47
48public:
49 enum
50 {
51 gridSize = 75,
52 };
53
54public:
56
57
63 Control(wxWindow* parent, Component& component);
64
66
67
74 Control(wxWindow* parent, Component& component, size_t uID);
75
77 virtual ~Control();
79
83 const size_t& getUid() const
84 {
85 return this->uid;
86 }
87
89
90 double zoom() const
91 {
92 return pZoom;
93 }
94 void zoom(const double v);
96
97 void forceReload()
98 {
99 pInvalidated = true;
100 }
101 const wxColour& getBackgroundColor()
102 {
103 return pBackgroundColor;
104 }
105 void setBackgroundColor(const wxColour& newColor)
106 {
107 pBackgroundColor = newColor;
108 }
109
111
112
117 void render(wxPaintEvent& evt);
118
124 wxBitmap getRenderedMapImage(const MapRenderOptions& mapOptions);
126
128
129
134 void paintGraph(wxDC& dc, bool inFile = false);
135
136 void refresh()
137 {
138 this->Refresh();
139 }
140
141 void reset();
142
143 void mouseMoved(wxMouseEvent& evt);
144
145 void mouseLeftDown(wxMouseEvent& evt);
146
147 void mouseWheelMoved(wxMouseEvent& evt);
148
149 void mouseLeftUp(wxMouseEvent& evt);
150
151 void rightClick(wxMouseEvent& evt);
152
153 void mouseLeftWindow(wxMouseEvent& evt);
154
155 void keyPressed(wxKeyEvent& evt);
156
157 void keyReleased(wxKeyEvent& evt);
158
159 void keyChar(wxKeyEvent& evt);
160
161 void mouseDblClick(wxMouseEvent& evt);
162
166 uint areasCount() const;
167
168 void setpInfosAreaCount(wxStaticText* infosAreaCount)
169 {
170 pInfosAreaCount = infosAreaCount;
171 }
172 wxStaticText* getpInfosAreaCount()
173 {
174 return pInfosAreaCount;
175 }
176
180 uint connectionsCount() const;
181 void setpInfosConnxCount(wxStaticText* infosConnxCount)
182 {
183 pInfosConnxCount = infosConnxCount;
184 }
185 wxStaticText* getpInfosConnxCount()
186 {
187 return pInfosConnxCount;
188 }
189
190 void setPointX(wxTextCtrl* textCtrl)
191 {
192 pointX = textCtrl;
193 }
194 wxTextCtrl* getPointX()
195 {
196 return pointX;
197 }
198 void setPointY(wxTextCtrl* textCtrl)
199 {
200 pointY = textCtrl;
201 }
202 wxTextCtrl* getPointY()
203 {
204 return pointY;
205 }
206
207 void addNewNode(uint count = 1);
208 void addNewNodeWhereTheMouseIs();
209 void addNewLoadNodeWhereTheMouseIs();
210 void addNewThermalNodeWhereTheMouseIs();
211 void addNewNuclearNodeWhereTheMouseIs();
212 void addNewCCGTNodeWhereTheMouseIs();
213 void addNewCoalNodeWhereTheMouseIs();
214 void addNewOilNodeWhereTheMouseIs();
215 void addNewHydroNodeWhereTheMouseIs();
216 void addNewPSPPNodeWhereTheMouseIs();
217 void addNewRENWNodeWhereTheMouseIs();
218 void addNewWindNodeWhereTheMouseIs();
219 void addNewSolarNodeWhereTheMouseIs();
220 void addNewBioMNodeWhereTheMouseIs();
221 void addNewVoidNodeWhereTheMouseIs();
222 void addNewVirtualNodeWhereTheMouseIs();
223
224 void recenter();
225 void recenter(int x, int y);
226
227 void computeBoundingBoxOfSelectedNodes();
228
229public:
232
238 // Antares::Component::Button* pBtnSelectionPlant;
241
243 Yuni::Event<void(int, int)> onPopupEvent;
244
246 static size_t newUID;
247
248private:
252 void refreshCache();
253
254 void updateMouseInfosFromEvent(wxMouseEvent& evt);
255
260 void drawGrid(wxDC& dc);
265 void drawSelectionBox(wxDC& dc);
270 void drawTools(DrawingContext& drawingContext);
272
273 void preDrawBoundingBoxOfSelectedNodes(wxDC& dc, const BoundingBox& bb);
274
275 void drawSingleNode(wxDC& dc, Node* node);
276
277 void removeTools();
278 void removeTools(const Tool::LifeSpan filter);
279 Tool::Tool* findTool(const int x, const int y);
280
281 void performActionForSelectedTool();
282
283 void addToolsForCurrentSelection();
284
285 void onScroll(wxScrollWinEvent& evt);
286
287 void onSize(wxSizeEvent& evt);
288
289private:
290 enum MouseAction
291 {
292 mouseActionNone,
293 mouseActionSelectionBox,
294 mouseActionMoveSelection,
295 mouseActionTool,
296 };
297
298private:
299 Component& pComponent;
300 bool pInvalidated = true;
301 bool pInvalidatedInnerCacheSize = true;
302
303 wxTextCtrl* pointX = nullptr;
304 wxTextCtrl* pointY = nullptr;
305 wxStaticText* pInfosAreaCount = nullptr;
306 wxStaticText* pInfosConnxCount = nullptr;
308 double pZoom = 1.;
309 wxColour pBackgroundColor = Settings::background;
310
311 wxPoint pCachedRealSize;
312 wxPoint pCachedBoxSize;
313 wxPoint pCachedOrigin;
314 wxPoint pOffsetForSelectedNodes;
315 wxPoint pBottomRight;
316
317 bool pKeyShift = false;
318 bool pKeyCtrl = false;
319 wxPoint pCurrentScroll;
320 wxPoint pCurrentMousePosition;
321 wxPoint pCurrentMousePositionGraph;
322 wxPoint pCurrentClientSize;
323 wxPoint pLastMousePosition;
324 Tool::Tool* pLastSelectedTool = nullptr;
325 Tool::Tool* pRemoverForSelection = nullptr;
326
327 MouseAction pMouseAction = mouseActionNone;
328 BoundingBox pSelectionBox;
329
330 Tool::List pTools;
331
332 int previousMaxSizeX = -1;
333 int previousMaxSizeY = -1;
334
335 const size_t uid;
336
337 Antares::Component::Notebook::Page* pPage = nullptr;
338
339 bool wasDrawn = false;
340
341 // Event table
342 DECLARE_EVENT_TABLE()
343
344}; // class Control
345
346} // namespace Map
347} // namespace Antares
348
349#endif // __ANTARES_TOOLBOX_MAP_CONTROL_H__
Definition button.h:34
Definition notebook.h:62
Standard study MAP.
Definition component.h:42
Sub-Component for drawing the map and handle user-events.
Definition control.h:45
Antares::Component::Button * pBtnSelectionArea
The toggle button for selecting areas with the mouse.
Definition control.h:234
Yuni::Event< void(int, int)> onPopupEvent
Popup event.
Definition control.h:243
static size_t newUID
Control id management.
Definition control.h:246
wxBitmap getRenderedMapImage(const MapRenderOptions &mapOptions)
Renders the map in an image object for further on-disk storage.
Definition control.cpp:172
const size_t & getUid() const
get Control id
Definition control.h:83
Control(wxWindow *parent, Component &component)
Default Constructor.
Definition control.cpp:69
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:1384
Manager & nodes
All nodes.
Definition control.h:231
Antares::Component::Button * pBtnSelectionLink
The toggle button for selecting links with the mouse.
Definition control.h:236
uint connectionsCount() const
Get how many connections we have.
Definition control.cpp:1389
void recenter()
Definition control.cpp:1056
Antares::Component::Button * pBtnSelectionConstraint
The toggle button for selecting clusters with the mouse.
Definition control.h:240
void paintGraph(wxDC &dc, bool inFile=false)
Paints the.
Definition control.cpp:277
Drawing Context.
Definition drawingcontext.h:43
A convenient container for nodes on the graph.
Definition manager.h:46
A node in a map.
Definition node.h:41
Visual component to make an action on the selected items.
Definition tool.h:52