NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
windowmanager.cpp
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#include "../gui/compositions/customwindow.hpp"
20#include "kernel.hpp"
21#include "core/utils/tinyxml2.h"
23#include "windowmanager.hpp"
24
25namespace NumeRe
26{
27
28 //
29 //
30 // CLASS WINDOW
31 //
32 //
33
39 {
41 m_graph = nullptr;
42 m_manager = nullptr;
43 m_customWindow = nullptr;
44 nWindowID = std::string::npos;
45 m_layout = nullptr;
46 }
47
48
55 Window::Window(const Window& window) : Window()
56 {
57 assignWindow(window);
58 }
59
60
69 Window::Window(WindowType type, WindowManager* manager, const WindowSettings& settings) : Window()
70 {
71 nType = type;
72 m_manager = manager;
73 m_settings = settings;
74
76 }
77
78
88 {
89 nType = type;
90 m_manager = manager;
91 m_graph = graph;
92
94 }
95
96
106 {
107 nType = type;
108 m_manager = manager;
109 m_layout = layoutString;
110
112 }
113
114
121 {
123
124 if (m_layout)
125 delete m_layout;
126 }
127
128
139 {
140 if (m_manager)
142 }
143
144
154 {
155 if (m_manager)
157 }
158
159
169 void Window::assignWindow(const Window& window)
170 {
171 // Ensure that the current window is
172 // not already registered to avoid
173 // orphan windows in the window manager
175
176 // Copy the passed windows contents
177 nType = window.nType;
178 m_graph = window.m_graph;
179 m_manager = window.m_manager;
180 m_settings = window.m_settings;
181 m_layout = window.m_layout;
182 nWindowID = window.nWindowID;
183 window.m_layout = nullptr;
184
185 // Register this new window (this will automatically
186 // remove the copied window from the register)
188 }
189
190
200 {
201 assignWindow(window);
202
203 return *this;
204 }
205
206
217 void Window::updateWindowInformation(int status, const std::string& _return)
218 {
219 if (m_manager)
220 m_manager->updateWindowInformation(WindowInformation(nWindowID, status == STATUS_RUNNING ? this : nullptr, status, _return));
221 }
222
223
233 std::vector<int> Window::getWindowItems(const std::string& _selection) const
234 {
235 if (m_customWindow)
236 {
237 if (_selection == "checkbox")
239 else if (_selection == "button")
241 else if (_selection == "textfield")
243 else if (_selection == "dropdown")
245 else if (_selection == "combobox")
247 else if (_selection == "radio")
249 else if (_selection == "bitmap")
251 else if (_selection == "tablegrid")
253 else if (_selection == "gauge")
255 else if (_selection == "spinbut")
257 else if (_selection == "statictext" || _selection == "text")
259 else if (_selection == "grapher")
261 else if (_selection == "treelist")
263 else if (_selection == "slider")
265 else if (_selection == "menuitem")
267 }
268
269 return std::vector<int>();
270 }
271
272
282 {
284
285 if (m_customWindow)
286 {
287 WindowItemValue value = m_customWindow->getItemValue(windowItemID);
288
289 val.stringValue = value.stringValue.ToStdString();
290 val.tableValue = value.tableValue;
291 val.type = value.type.ToStdString();
292 }
293
294 return val;
295 }
296
297
306 std::string Window::getItemLabel(int windowItemID) const
307 {
308 if (m_customWindow)
309 return m_customWindow->getItemLabel(windowItemID).ToStdString();
310
311 return "";
312 }
313
314
323 std::string Window::getItemState(int windowItemID) const
324 {
325 if (m_customWindow)
326 return m_customWindow->getItemState(windowItemID).ToStdString();
327
328 return "";
329 }
330
331
340 std::string Window::getItemColor(int windowItemID) const
341 {
342 if (m_customWindow)
343 return m_customWindow->getItemColor(windowItemID).ToStdString();
344
345 return "";
346 }
347
348
357 std::string Window::getPropValue(const std::string& varName) const
358 {
359 if (m_customWindow)
360 return m_customWindow->getPropValue(varName).ToStdString();
361
362 return "nan";
363 }
364
365
373 std::string Window::getProperties() const
374 {
375 if (m_customWindow)
376 return m_customWindow->getProperties().ToStdString();
377
378 return "\"\"";
379 }
380
381
391 bool Window::setItemValue(const NumeRe::WinItemValue& _value, int windowItemID)
392 {
393 if (m_customWindow)
394 {
395 WindowItemValue val;
396 val.stringValue = _value.stringValue;
397 val.tableValue = _value.tableValue;
398 val.type = _value.type;
399 return m_customWindow->setItemValue(val, windowItemID);
400 }
401
402 return false;
403 }
404
405
415 bool Window::setItemLabel(const std::string& _label, int windowItemID)
416 {
417 if (m_customWindow)
418 return m_customWindow->setItemLabel(_label, windowItemID);
419
420 return false;
421 }
422
423
433 bool Window::setItemState(const std::string& _state, int windowItemID)
434 {
435 if (m_customWindow)
436 return m_customWindow->setItemState(_state, windowItemID);
437
438 return false;
439 }
440
441
451 bool Window::setItemColor(const std::string& _color, int windowItemID)
452 {
453 if (m_customWindow)
454 return m_customWindow->setItemColor(_color, windowItemID);
455
456 return false;
457 }
458
459
469 bool Window::setItemGraph(GraphHelper* _helper, int windowItemID)
470 {
471 if (m_customWindow)
472 return m_customWindow->setItemGraph(_helper, windowItemID);
473
474 return false;
475 }
476
477
487 bool Window::setPropValue(const std::string& _value, const std::string& varName)
488 {
489 if (m_customWindow)
490 return m_customWindow->setPropValue(_value, varName);
491
492 return false;
493 }
494
495
503 {
504 if (m_customWindow)
505 return m_customWindow->closeWindow();
506
507 return false;
508 }
509
510
525 {
526 m_manager = nullptr;
527 }
528
529 //
530 //
531 // CLASS WINDOWMANAGER
532 //
533 //
534
546 {
547 if (m_windowMap.find(information.nWindowID) != m_windowMap.end())
548 m_windowMap[information.nWindowID] = information;
549 }
550
551
562 size_t WindowManager::registerWindow(Window* window, size_t id)
563 {
564 if (id == std::string::npos)
565 {
566 id = m_windowMap.size();
567
568 // Ensure the new ID is unique
569 while (m_windowMap.find(id) != m_windowMap.end())
570 id++;
571 }
572
573
574 m_windowMap[id] = WindowInformation(id, window, 0, "");
575
576 return id;
577 }
578
579
592 {
593 // Search for the passed window ID
594 auto iter = m_windowMap.find(id);
595
596 // If the ID exists and the pointer is equal
597 if (iter != m_windowMap.end() && iter->second.window == window)
598 {
599 // If the window type is a graph window
600 // delete it directly - it's not necessary
601 // to keep it in memory
602 if (window->getType() == WINDOW_GRAPH)
603 m_windowMap.erase(iter);
604 else if (iter->second.nStatus == STATUS_RUNNING)
605 {
606 iter->second.nStatus = STATUS_CANCEL;
607 iter->second.window = nullptr;
608 }
609 }
610 }
611
612
617 {
618 //
619 }
620
621
629 {
630 for (auto iter = m_windowMap.begin(); iter != m_windowMap.end(); ++iter)
631 {
632 if (iter->second.window)
633 {
634 iter->second.window->detach();
635 iter->second.nStatus = STATUS_CANCEL;
636 }
637 }
638 }
639
640
651 {
652 Window window(WINDOW_GRAPH, this, graph);
653
655
656 return window.getId();
657 }
658
659
671 {
672 Window window(type, this, settings);
673
675
676 return window.getId();
677 }
678
679
690 {
691 Window window(WINDOW_CUSTOM, this, layoutString);
692
694
695 return window.getId();
696 }
697
698
712 {
713 // Search for the passed window ID
714 auto iter = m_windowMap.find(windowId);
715
716 if (iter != m_windowMap.end())
717 {
718 // Get the window information
719 WindowInformation winInfo = iter->second;
720
721 // Erase the window from the map
722 // if it has been closed
723 if (winInfo.nStatus)
724 {
725 m_windowMap.erase(iter);
726 }
727
728 return winInfo;
729 }
730
731 return WindowInformation();
732 }
733
734
748 {
749 WindowInformation winInfo;
750
751 // Repeatedly check for the closing of
752 // the window
753 do
754 {
755 Sleep(100);
756
757 // Search for the passed window ID
758 auto iter = m_windowMap.find(windowId);
759
760 if (iter != m_windowMap.end())
761 {
762 // Get the window information
763 winInfo = iter->second;
764
765 // Erase the window from the map
766 // if it has been closed
767 if (winInfo.nStatus != STATUS_RUNNING)
768 {
769 m_windowMap.erase(iter);
770 return winInfo;
771 }
772 }
773 else
774 break;
775
776 }
777 while (winInfo.nStatus == STATUS_RUNNING);
778
779 // Return an empty window information
780 return winInfo;
781 }
782
783
784
785}
786
787
bool setItemState(const wxString &_state, int windowItemID)
Change the state of the selected item.
bool setItemValue(WindowItemValue &_value, int windowItemID)
Change the value of the selected item.
wxString getItemLabel(int windowItemID) const
Get the label of the selected item.
bool setItemGraph(GraphHelper *_helper, int windowItemID)
Updates the selected grapher item.
std::vector< int > getWindowItems(WindowItemType _type) const
Returns a list of all window item IDs, which correspond to the selected WindowItemType.
bool setPropValue(const wxString &_value, const wxString &varName)
Sets the value of the selected window property.
bool setItemLabel(const wxString &_label, int windowItemID)
Change the label of the selected item.
wxString getProperties() const
Returns a list of all available window properties.
wxString getPropValue(const wxString &varName) const
Returns the value of the selected window property.
wxString getItemColor(int windowItemID) const
Get the color of the selected item.
wxString getItemState(int windowItemID) const
Get the state of the selected item.
bool setItemColor(const wxString &_color, int windowItemID)
Change the color of the selected item.
WindowItemValue getItemValue(int windowItemID) const
Get the value of the selected item.
bool closeWindow()
Close this window.
This class encapsulates the mglGraph object during transmission from the kernel to the GUI.
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...
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...
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.
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...
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.
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
void showWindow(const NumeRe::Window &window)
This member function passes a window object to the user interface, which will then converted into a r...
Definition: kernel.cpp:3267
WindowType
Enumeration for the window type.
@ STATUS_RUNNING
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...
This class contains the window information to create the dialog in the GUI.
A structure to simplify reading and updating window item values.
wxString stringValue
NumeRe::Table tableValue