/
AasVisualisationPanel.cpp
175 lines (136 loc) · 4.41 KB
/
AasVisualisationPanel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "AasVisualisationPanel.h"
#include "i18n.h"
#include "iaasfile.h"
#include "imap.h"
#include <wx/button.h>
#include <wx/tglbtn.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/scrolwin.h>
#include "registry/Widgets.h"
namespace ui
{
AasVisualisationPanel::AasVisualisationPanel(wxWindow* parent) :
DockablePanel(parent),
_dialogPanel(nullptr),
_controlContainer(nullptr)
{
populateWindow();
SetMinClientSize(wxSize(135, 100));
}
AasVisualisationPanel::~AasVisualisationPanel()
{
if (panelIsActive())
{
disconnectListeners();
}
}
void AasVisualisationPanel::onPanelActivated()
{
connectListeners();
refresh();
}
void AasVisualisationPanel::onPanelDeactivated()
{
disconnectListeners();
}
void AasVisualisationPanel::connectListeners()
{
_mapEventSlot = GlobalMapModule().signal_mapEvent().connect(
sigc::mem_fun(*this, &AasVisualisationPanel::onMapEvent));
}
void AasVisualisationPanel::disconnectListeners()
{
_mapEventSlot.disconnect();
}
void AasVisualisationPanel::onMapEvent(IMap::MapEvent ev)
{
switch (ev)
{
case IMap::MapEvent::MapLoaded:
refresh();
break;
case IMap::MapEvent::MapUnloading:
clearControls();
break;
default:
break;
};
}
void AasVisualisationPanel::populateWindow()
{
auto scrollView = new wxScrolledWindow(this, wxID_ANY);
scrollView->SetScrollRate(0, 15);
_dialogPanel = scrollView;
_dialogPanel->SetSizer(new wxBoxSizer(wxVERTICAL));
_controlContainer = new wxFlexGridSizer(1, 2, 3, 3);
_controlContainer->AddGrowableCol(0);
_dialogPanel->GetSizer()->Add(_controlContainer, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 12);
createButtons();
_dialogPanel->FitInside(); // ask the sizer about the needed size
SetSizer(new wxBoxSizer(wxVERTICAL));
GetSizer()->Add(scrollView, 1, wxEXPAND);
}
void AasVisualisationPanel::createButtons()
{
// Rescan button
_rescanButton = new wxButton(_dialogPanel, wxID_ANY, _("Search for AAS Files"));
_rescanButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) { refresh(); });
// Bind the toggle button to the registry key
wxToggleButton* showNumbersButton = new wxToggleButton(_dialogPanel, wxID_ANY, _("Show Area Numbers"));
registry::bindWidget(showNumbersButton, map::RKEY_SHOW_AAS_AREA_NUMBERS);
wxToggleButton* hideDistantAreasButton = new wxToggleButton(_dialogPanel, wxID_ANY, _("Hide distant Areas"));
registry::bindWidget(hideDistantAreasButton, map::RKEY_HIDE_DISTANT_AAS_AREAS);
_dialogPanel->GetSizer()->Add(showNumbersButton, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 12);
_dialogPanel->GetSizer()->Add(hideDistantAreasButton, 0, wxEXPAND | wxLEFT | wxRIGHT, 12);
_dialogPanel->GetSizer()->Add(_rescanButton, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 12);
}
void AasVisualisationPanel::clearControls()
{
// Remove all previously allocated controls
_aasControls.clear();
// Delete all wxWidgets objects
_controlContainer->Clear(true);
}
void AasVisualisationPanel::refresh()
{
clearControls();
std::map<std::string, AasFileControlPtr> sortedControls;
// Find all available AAS files for the current map
std::list<map::AasFileInfo> aasFiles = GlobalAasFileManager().getAasFilesForMap(GlobalMapModule().getMapName());
for (map::AasFileInfo& info : aasFiles)
{
// Create a new control for each AAS type
// Store the object in a sorted container
sortedControls[info.type.fileExtension] = std::make_shared<AasFileControl>(_dialogPanel, info);
}
// Assign all controls to the target vector, alphabetically sorted
for (const auto& pair : sortedControls)
{
_aasControls.push_back(pair.second);
}
_controlContainer->SetRows(static_cast<int>(_aasControls.size()));
for (auto i = _aasControls.begin(); i != _aasControls.end(); ++i)
{
_controlContainer->Add((*i)->getToggle(), 1, wxEXPAND);
_controlContainer->Add((*i)->getButtons(), 0, wxEXPAND);
if (i == _aasControls.begin())
{
// Prevent setting the focus on the buttons at the bottom which lets the scrollbar
// of the window jump around, set the focus on the first button.
(*i)->getToggle()->SetFocus();
}
}
_controlContainer->Layout();
_dialogPanel->FitInside(); // ask the sizer about the needed size
update();
}
void AasVisualisationPanel::update()
{
// Broadcast the update() call
for (const auto& control : _aasControls)
{
control->update();
}
}
}