NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
windowmanager.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20#ifndef WINDOWMANAGER_HPP
21#define WINDOWMANAGER_HPP
22
23#include <map>
24#include <string>
25#include <vector>
26
28
29// Global forward declarations
30class CustomWindow;
31class GraphHelper;
32
33namespace tinyxml2
34{
35 class XMLDocument;
36}
37
38namespace NumeRe
39{
44 {
51 };
52
53
59 {
60 CTRL_NONE = 0x0,
61 // Button selections
65 // Icon selection
70 // Dialog types
76 CTRL_TEXTENTRY = 0x8000
77 };
78
79
85 {
88 STATUS_OK = 0x2
89 };
90
91
97 {
99 bool isModal;
100 std::string sMessage;
101 std::string sExpression;
102 std::string sTitle;
103
104 WindowSettings(int ctrls = CTRL_NONE, bool modal = false, const std::string& message = "", const std::string& title = "NumeRe: Window", const std::string& expression = "") : nControls(ctrls), isModal(modal), sMessage(message), sExpression(expression), sTitle(title) {}
105 };
106
107
114 {
115 std::string type;
116 std::string stringValue;
118 };
119
120 // Forward declaration of the window manager class
121 class WindowManager;
122
123
128 class Window
129 {
130 private:
131 friend class WindowManager;
138 size_t nWindowID;
139
140 void registerWindow();
141 void unregisterWindow();
142 void assignWindow(const Window& window);
143 void detach();
144
145 public:
146 Window();
147 Window(const Window& window);
148 Window(WindowType type, WindowManager* manager, const WindowSettings& settings);
149 Window(WindowType type, WindowManager* manager, GraphHelper* graph);
150 Window(WindowType type, WindowManager* manager, tinyxml2::XMLDocument* layoutString);
151 ~Window();
152
153 Window& operator=(const Window& window);
154
156 {
157 return nType;
158 }
159
161 {
162 return m_graph;
163 }
164
166 {
167 return m_settings;
168 }
169
170 size_t getId() const
171 {
172 return nWindowID;
173 }
174
176 {
177 return m_layout;
178 }
179
180 void connect(CustomWindow* _window)
181 {
182 m_customWindow = _window;
183 }
184
186 {
187 return m_customWindow != nullptr;
188 }
189
190 void updateWindowInformation(int status, const std::string& _return);
191 std::vector<int> getWindowItems(const std::string& _selection) const;
192 bool closeWindow();
193 WinItemValue getItemValue(int windowItemID) const;
194 std::string getItemLabel(int windowItemID) const;
195 std::string getItemState(int windowItemID) const;
196 std::string getItemColor(int windowItemID) const;
197 std::string getPropValue(const std::string& varName) const;
198 std::string getProperties() const;
199
200 bool setItemValue(const WinItemValue& _value, int windowItemID);
201 bool setItemLabel(const std::string& _label, int windowItemID);
202 bool setItemState(const std::string& _state, int windowItemID);
203 bool setItemColor(const std::string& _color, int windowItemID);
204 bool setItemGraph(GraphHelper* _helper, int windowItemID);
205 bool setPropValue(const std::string& _value, const std::string& varName);
206 };
207
208
215 {
216 size_t nWindowID;
219 std::string sReturn;
220
221 WindowInformation(size_t id = std::string::npos, Window* win = nullptr, int status = STATUS_RUNNING, const std::string& _return = "")
222 : nWindowID(id), window(win), nStatus(status), sReturn(_return) {}
223 };
224
225
232 {
233 private:
234 friend class Window;
235
236 std::map<size_t, WindowInformation> m_windowMap;
237
238 void updateWindowInformation(const WindowInformation& information);
239
240 size_t registerWindow(Window* window, size_t id);
241 void unregisterWindow(Window* window, size_t id);
242
243 public:
246
247 size_t createWindow(GraphHelper* graph);
248 size_t createWindow(WindowType type, const WindowSettings& settings);
249 size_t createWindow(tinyxml2::XMLDocument* layoutString);
250
253 };
254
255}
256
257#endif // WINDOWMANAGER_HPP
258
This class represents a window, which can be created by the user during run-time by using a layout sc...
This class encapsulates the mglGraph object during transmission from the kernel to the GUI.
This data container is a copy- efficient table to interchange data between Kernel and GUI.
Definition: table.hpp:87
This class represents an abstract window handled by the window manager.
std::string getItemColor(int windowItemID) const
Returns the color of the selected window item as a string.
bool setItemState(const std::string &_state, int windowItemID)
Enables changing the state of the selected window item to the passed state.
void updateWindowInformation(int status, const std::string &_return)
This public member function can be used to update the stored window information in the window manager...
WindowManager * m_manager
Window & operator=(const Window &window)
This member function is the public overload of the assignment operator.
Window()
Default constructor. Initializes an invalid window.
tinyxml2::XMLDocument * m_layout
WinItemValue getItemValue(int windowItemID) const
Returns the value of the selected window item as a string.
std::vector< int > getWindowItems(const std::string &_selection) const
Returns a vector of item ids corresponding to the available window items of this window.
void assignWindow(const Window &window)
This private member function is the generalisation of the assignment operator and the copy constructo...
GraphHelper * getGraph()
std::string getItemLabel(int windowItemID) const
Returns the label of the selected window item as a string.
void registerWindow()
This private member function registers the current window in the window manager. This will automatica...
const tinyxml2::XMLDocument * getLayout() const
bool setItemColor(const std::string &_color, int windowItemID)
Enables changing the color of the selected window item to the passed color.
WindowType getType() const
std::string getItemState(int windowItemID) const
Returns the state of the selected window item as a string.
CustomWindow * m_customWindow
WindowType nType
std::string getProperties() const
Returns a list of all available window properties (comp. prop) in this window.
~Window()
Destructor. Unregisters the current window in the window manager and deletes the layout pointer,...
bool setItemGraph(GraphHelper *_helper, int windowItemID)
Updates the graph in the custom window.
void connect(CustomWindow *_window)
GraphHelper * m_graph
bool setItemValue(const WinItemValue &_value, int windowItemID)
Enables changing the value of the selected window item to the passed value.
bool setPropValue(const std::string &_value, const std::string &varName)
This function sets the value of the selected window property.
void detach()
This private member function is used by the window manager to detach itself from this window to avoid...
const WindowSettings & getWindowSettings() const
bool closeWindow()
Closes the current window.
void unregisterWindow()
This private member function will unregister the current window in the window manager.
std::string getPropValue(const std::string &varName) const
Returns the value of the selected property as a string.
size_t getId() const
bool setItemLabel(const std::string &_label, int windowItemID)
Enables changing the label of the selected window item to the passed label.
WindowSettings m_settings
This is the window manager of the kernel. All windows opened by the kernel will be registered here.
void unregisterWindow(Window *window, size_t id)
This member function will unregister a window. This is done only if the ID and the window pointer are...
size_t registerWindow(Window *window, size_t id)
This member function registers a new window or changes the registration to a new window.
WindowInformation getWindowInformationModal(size_t windowId)
This public member function will return the window information stored in the internal map....
WindowManager()
Empty window manager constructor.
WindowInformation getWindowInformation(size_t windowId)
This public member function will return the window information stored in the internal map....
std::map< size_t, WindowInformation > m_windowMap
~WindowManager()
Destructor. It will detach all registered windows from the manager. This is done to avoid segmentatio...
void updateWindowInformation(const WindowInformation &information)
This function is used by the registered windows to inform the window manager about new window statuse...
size_t createWindow(GraphHelper *graph)
This public member function will create a window object containing the passed graph.
WindowType
Enumeration for the window type.
@ WINDOW_NON_MODAL
WindowStatus
Enumeration for the status of a displayed dialog.
@ STATUS_RUNNING
WindowControls
Enumeration for the contained window controls.
@ CTRL_MESSAGEBOX
@ CTRL_SELECTIONDIALOG
@ CTRL_ICONERROR
@ CTRL_YESNOBUTTON
@ CTRL_FOLDERDIALOG
@ CTRL_TEXTENTRY
@ CTRL_FILEDIALOG
@ CTRL_LISTDIALOG
@ CTRL_ICONQUESTION
@ CTRL_ICONWARNING
@ CTRL_ICONINFORMATION
@ CTRL_CANCELBUTTON
Kernel representation of the WindowItemValue structure of the CustomWindow class.
This class is used by the window manager to handle the information of an opened window and to store i...
WindowInformation(size_t id=std::string::npos, Window *win=nullptr, int status=STATUS_RUNNING, const std::string &_return="")
This class contains the window information to create the dialog in the GUI.
WindowSettings(int ctrls=CTRL_NONE, bool modal=false, const std::string &message="", const std::string &title="NumeRe: Window", const std::string &expression="")