Antares Simulator
Power System Simulator
component.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_COMPONENT_H__
22 #define __ANTARES_TOOLBOX_MAP_COMPONENT_H__
23 
24 #include <antares/study/study.h>
25 #include "control.h"
26 #include <wx/stattext.h>
27 #include <ui/common/component/panel.h>
28 #include "../button.h"
29 #include "../notebook/mapnotebook.h"
30 #include "settings.h"
31 
32 #include <wx/textctrl.h>
33 
34 namespace Antares::Map
35 {
39 class Component final: public Antares::Component::Panel, public Yuni::IEventObserver<Component>
40 {
41 public:
43 
44 
47  Component(wxWindow* parent);
51  virtual ~Component();
53 
55 
56 
64  void attachStudy(Data::Study::Ptr study);
65 
69  void detachStudy(bool canRefresh = true);
70 
75  Data::Study::Ptr attachedStudy();
77 
79 
80 
86  bool loadFromStudy(Data::Study& study);
87 
92  bool loadFromAttachedStudy();
93 
101  bool saveToStudy(Data::Study& study, bool incremental = true);
102 
109  bool saveToAttachedStudy(bool incremental = true);
111 
118  bool saveToImageFile(const AnyString& filePath, const MapRenderOptions& options);
120 
121  void clear();
122 
124 
125 
128  void recenterView();
129 
130  void onCenterXY(void*);
131 
135  void setFocus();
136 
140  uint selectedAreaCount() const;
142 
143  void drawerVisible();
144 
145  void showLayerAll();
146 
147  void forceReload();
148  void refresh();
149 
154 
155  void renameNodeFromArea(const Data::Area* area);
156 
158 
159 
162  void unselectAll(bool canRefresh = true);
163 
167  void selectAll();
168 
172  void reverseSelection();
173 
177  void selectOnly(const Data::Area::Vector& areas);
178 
182  void selectOnly(const Data::Area::Vector& areas, const Data::AreaLink::Vector& links);
184 
186 
187 
190  void reimportNodeColors(const Data::Area* area);
191 
195  void moveNodeFromAreaX(const Data::Area* area, int x);
196 
200  void moveNodeFromAreaY(const Data::Area* area, int y);
201 
203 
204  size_t getActiveLayerID()
205  {
206  return pMapActiveLayer ? pMapActiveLayer->getUid() : 0;
207  }
208 
209 public:
211  Yuni::Event<void(int, int)> onPopupEvent;
213  Yuni::Event<void(const wxString&)> onStatusBarText;
215  Yuni::Event<void(Component&)> onDblClick;
217  // Yuni::Event<void (void*)> onTextEnter;
218 
219 private:
220  class Drawer final: public Antares::Component::Panel
221  {
222  public:
223  Drawer(wxWindow* parent, Component& com):
225  pComponent(com)
226  {
227  }
228 
229  void onDraw(wxPaintEvent& evt);
230  void onSize(wxSizeEvent& evt);
231 
232  private:
233  void drawFromDevice(wxDC& dc);
234 
235  private:
236  Component& pComponent;
237  DECLARE_EVENT_TABLE()
238  };
239 
240  void onApplicationQuit();
241 
242  void onPageChanged(Antares::Component::MapNotebook::Page& page);
243 
244  Antares::Component::MapNotebook::Page* addNewLayer(wxString pageName = wxString(""),
245  size_t uID = 0);
246 
247  void addNewEmptyLayer()
248  {
249  addNewLayer();
250  }
251 
252  void removeLayer(Antares::Component::MapNotebook::Page& page);
253 
254  void evtOnPopupEvent(int x, int y);
255 
256  void evtOnSelectionHide(wxCommandEvent&);
257 
258  void evtOnSelectionShow(wxCommandEvent&);
259 
260  void onCopy(void*);
261  void onCopyDropdown(Antares::Component::Button&, wxMenu& menu, void*);
262  void evtPopupCopy(wxCommandEvent&);
263  void evtPopupCopyAll(wxCommandEvent&);
264  void evtPopupCopyAllAreas(wxCommandEvent&);
265  void evtPopupCopyAllLinks(wxCommandEvent&);
266  void onPaste(void*);
267  void onPasteDropdown(Antares::Component::Button&, wxMenu& menu, void*);
268  void evtPopupPaste(wxCommandEvent&);
269  void evtPopupPasteSpecial(wxCommandEvent&);
270  void onSelectAll(void*);
271 
272  void onNew(void*);
273  void onNewDropdown(Antares::Component::Button&, wxMenu& menu, void*);
274 
275  template<unsigned int N>
276  inline void evtNewArea(wxCommandEvent&)
277  {
278  if (pMapActiveLayer)
279  {
280  pMapActiveLayer->addNewNode(N);
281  }
282  setFocus();
283  }
284 
285  void onToggleMouseSelectionArea(void*);
286  void onToggleMouseSelectionLink(void*);
287  void onToggleMouseSelectionPlant(void*);
288  void onToggleMouseSelectionConstraint(void*);
289 
290  void onCenter(void*);
291 
292  void onEvtCenterXY(wxCommandEvent& WXUNUSED(event));
293 
294 private:
295  Control* pMapActiveLayer;
297  std::vector<Control*> mapLayersPtrList;
298 
299  wxStaticText* pInfosAreaCount;
300  wxStaticText* pInfosConnxCount;
301  // Toggle buttons
302  // The class wxWindow is used here to not include button.h everywhere
303  // It is already such a pain to compile on Windows...
305  wxWindow* pBtnSelectionArea;
307  wxWindow* pBtnSelectionLink;
309  wxWindow* pBtnSelectionPlant;
311  wxWindow* pBtnSelectionConstraint;
312 
313  // PopUp Menu
314  wxMenu* pSelectionPopUpMenu;
315 
316 }; // class Component
317 
318 } // namespace Antares::Map
319 
320 #endif // __ANTARES_TOOLBOX_MAP_COMPONENT_H__
Definition: button.h:32
MapNotebook.
Definition: mapnotebook.h:33
Definition: notebook.h:61
Panel implementation.
Definition: panel.h:34
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Standard study MAP.
Definition: component.h:40
Component(wxWindow *parent)
Default Constructor.
Definition: component.cpp:57
bool loadFromStudy(Data::Study &study)
Load the map's settings from an existing Antares study.
Definition: component.cpp:578
void unselectAll(bool canRefresh=true)
Select all nodes of type "area".
Definition: component.cpp:866
void refreshHeaderInformations()
Refresh the header informations (how many areas/connexions)
Definition: component.cpp:772
bool saveToAttachedStudy(bool incremental=true)
Save the map's settings to the attached study (if any)
Definition: component.cpp:642
void selectOnly(const Data::Area::Vector &areas)
Select only items from a list of areas.
Definition: component.cpp:889
void reimportNodeColors(const Data::Area *area)
Refresh the internal cache about the color of a single area.
Definition: component.cpp:825
void recenterView()
Recenter scrollbars to the center of the map.
Definition: component.cpp:1207
void reverseSelection()
Reverse the selection.
Definition: component.cpp:923
Data::Study::Ptr attachedStudy()
Get the study attached to the map.
Definition: component.cpp:573
virtual ~Component()
Destructor.
Definition: component.cpp:117
void moveNodeFromAreaX(const Data::Area *area, int x)
Refresh the internal cache about the X-coordinate of a single area.
Definition: component.cpp:837
void attachStudy(Data::Study::Ptr study)
Attach a study to the map to reflect changes.
Definition: component.cpp:509
void selectAll()
Select all nodes of type "area".
Definition: component.cpp:879
Yuni::Event< void(int, int)> onPopupEvent
Popup event.
Definition: component.h:211
void moveNodeFromAreaY(const Data::Area *area, int y)
Refresh the internal cache about the X-coordinate of a single area.
Definition: component.cpp:849
uint selectedAreaCount() const
Get how many areas have been selected.
Definition: component.cpp:861
void setFocus()
Set the focus to the map.
Definition: component.cpp:705
bool saveToStudy(Data::Study &study, bool incremental=true)
Save the map's settings to a study.
Definition: component.cpp:623
bool loadFromAttachedStudy()
Load the map's settings from the attached study.
Definition: component.cpp:606
Yuni::Event< void(Component &)> onDblClick
Event: Double-Click on a item.
Definition: component.h:215
bool saveToImageFile(const AnyString &filePath, const MapRenderOptions &options)
Save the map into an image file.
Definition: component.cpp:648
Yuni::Event< void(const wxString &)> onStatusBarText
Status bar event.
Definition: component.h:213
void detachStudy(bool canRefresh=true)
Detach the study (if any) currently attached to the map.
Definition: component.cpp:563
const size_t & getUid() const
get Control id
Definition: control.h:82
Definition: settings.h:46