Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
ControlEditorManager.cpp
1/*
2 * Copyright (C) 2026 Thales Lima Oliveira <thales.oliveira@uftm.edu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
19
20#include <algorithm>
21
22#include "ControlEditor.h"
23#include "Workspace.h"
24#include "../elements/controlElement/ControlElementContainer.h"
25
26ControlEditorManager::ControlEditorManager(Workspace* workspace)
27 : m_workspace(workspace)
28{
29}
30
31ControlEditorManager::~ControlEditorManager()
32{
33 CloseAll();
34}
35
36ControlEditor* ControlEditorManager::Open(ControlElementContainer* container, int plotLib, int ioFlags)
37{
38 ControlEditor* editor = GetEditor(container);
39
40 if (editor)
41 {
42 //editor->Raise();
43 //editor->SetFocus();
44 //return editor;
45 editor->Close();
46 editor = nullptr;
47 }
48
49 editor = new ControlEditor(m_workspace, m_workspace->GetProperties(), ioFlags);
50
51 editor->SetManager(this);
52 editor->SetElementsList(container->GetControlElementsList());
53 editor->SetConnectionsList(container->GetConnectionLineList());
54 editor->SetControlContainer(container);
55 editor->SetPlotLib(plotLib);
56
57 m_editors.push_back(editor);
58
59 editor->Show();
60 editor->SetJustOpened(true);
61
62 return editor;
63}
64
65void ControlEditorManager::Remove(ControlEditor* editor)
66{
67 auto it = std::find(m_editors.begin(), m_editors.end(), editor);
68
69 if (it != m_editors.end())
70 m_editors.erase(it);
71}
72
73void ControlEditorManager::CloseAll()
74{
75 auto editors = m_editors;
76
77 for (auto* editor : editors)
78 {
79 if (editor)
80 editor->Destroy();
81 }
82
83 m_editors.clear();
84}
85
86bool ControlEditorManager::IsOpen(ControlElementContainer* container) const
87{
88 return GetEditor(container) != nullptr;
89}
90
91ControlEditor* ControlEditorManager::GetEditor(const ControlElementContainer* container) const
92{
93 for (auto* editor : m_editors)
94 {
95 if (!editor)
96 continue;
97
98 if (editor->GetControlContainer() == container)
99 return editor;
100 }
101
102 return nullptr;
103}
Class that can contain all control elements. Can identify (using RTTI) the elements from a generic li...
This class manages the graphical and power elements. It is responsible for handling the user's intera...
Definition Workspace.h:105