Antares Simulator
Power System Simulator
tool.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_TOOLS_TOOL_H__
22 #define __ANTARES_TOOLBOX_MAP_TOOLS_TOOL_H__
23 
24 #include <vector>
25 #include "../drawingcontext.h"
26 
27 namespace Antares::Map::Tool
28 {
32 enum LifeSpan
33 {
35  lifeSpanMouseSelection,
40  lifeSpanImmortality,
41 
42 }; // enum LifeSpan
43 
47 class Tool
48 {
49 public:
51 
52 
58  Tool(Manager& manager, const char* icon);
60  virtual ~Tool();
61 
63 
65 
66  Manager& manager()
67  {
68  return pManager;
69  }
70 
71  const Manager& manager() const
72  {
73  return pManager;
74  }
75 
77 
79 
80  int x() const
82  {
83  return pX;
84  }
85 
87  void x(const int v)
88  {
89  pX = v;
90  }
91 
93 
95  int y() const
97  {
98  return pY;
99  }
100 
102  void y(const int v)
103  {
104  pY = v;
105  }
106 
108 
110 
111  uint width() const
113  {
114  return pWidth;
115  }
116 
118  uint height() const
119  {
120  return pHeight;
121  }
122 
124 
126 
127  const wxBitmap* icon() const
129  {
130  return pIcon;
131  }
132 
140  void icon(const char* filename);
141 
142  //}
143 
145 
146  LifeSpan lifeSpan() const
148  {
149  return lifeSpanMouseSelection;
150  }
151 
153 
155 
156 
164  bool contains(const int x, const int y) const
165  {
166  return x >= pX && x <= pX + pWidth && y >= pY && y <= pY + pHeight;
167  }
168 
177  virtual void draw(DrawingContext& dc,
178  const bool mouseDown,
179  const wxPoint& position,
180  const wxPoint& absolute) const;
181 
183 
193  virtual bool actionIsImmediate() const
194  {
195  return true;
196  }
197 
203  virtual bool onMouseUp(const int mx, const int my) = 0;
204 
205 protected:
209  int pX;
211  int pY;
213  int pWidth;
215  int pHeight;
217  wxBitmap* pIcon;
218 
219 }; // class Tool
220 
222 using List = std::vector<Tool*>;
223 
224 } // namespace Antares::Map::Tool
225 
226 #endif // __ANTARES_TOOLBOX_MAP_TOOLS_TOOL_H__
Drawing Context.
Definition: drawingcontext.h:41
A convenient container for nodes on the graph.
Definition: manager.h:44
Visual component to make an action on the selected items.
Definition: tool.h:48
virtual bool actionIsImmediate() const
Get if the action triggered by the tool is immediate.
Definition: tool.h:193
bool contains(const int x, const int y) const
Get if a point is insided the bounding box of the tool.
Definition: tool.h:164
Manager & pManager
The parent manager.
Definition: tool.h:207
Tool(Manager &manager, const char *icon)
Constructor.
Definition: tool.cpp:28
int pWidth
Width.
Definition: tool.h:213
LifeSpan lifeSpan() const
Get the lifespan of the tool.
Definition: tool.h:147
int pHeight
Height.
Definition: tool.h:215
int pX
The X-Coordinate.
Definition: tool.h:209
wxBitmap * pIcon
Icon.
Definition: tool.h:217
const wxBitmap * icon() const
Get the icon of the tool, NULL if not available.
Definition: tool.h:128
uint width() const
Get the width of the tool.
Definition: tool.h:112
virtual ~Tool()
Destructor.
Definition: tool.cpp:38
virtual bool onMouseUp(const int mx, const int my)=0
Event: The user has clicked on the tool.
int pY
The Y-Coordinate.
Definition: tool.h:211
virtual void draw(DrawingContext &dc, const bool mouseDown, const wxPoint &position, const wxPoint &absolute) const
Draw the tool.
Definition: tool.cpp:49
int y() const
Get the Y-Coordinate of the tool.
Definition: tool.h:96
uint height() const
Get the height of the tool.
Definition: tool.h:118
void y(const int v)
Set the Y-Coordinate of the tool.
Definition: tool.h:102
void x(const int v)
Set the X-Coordinate of the tool.
Definition: tool.h:87
int x() const
Get the X-Coordinate of the tool.
Definition: tool.h:81