Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/foxtools/MFXGroupBoxModule.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2006-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file MFXGroupBoxModule.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Dec 2021
17
///
18
//
19
/****************************************************************************/
20
21
/* =========================================================================
22
* included modules
23
* ======================================================================= */
24
#include <config.h>
25
26
#include <utils/gui/div/GUIDesigns.h>
27
#include <utils/gui/images/GUIIconSubSys.h>
28
#include <utils/gui/windows/GUIAppEnum.h>
29
#include <netedit/frames/GNEFrame.h>
30
#include <netedit/GNEViewNet.h>
31
#include <netedit/GNEViewParent.h>
32
#include <netedit/GNEApplicationWindow.h>
33
#include <netedit/frames/GNETLSTable.h>
34
35
#include "MFXGroupBoxModule.h"
36
#include "MFXButtonTooltip.h"
37
38
39
// ===========================================================================
40
// FOX callback mapping
41
// ===========================================================================
42
43
FXDEFMAP(MFXGroupBoxModule) MFXGroupBoxModuleMap[] = {
44
FXMAPFUNC(SEL_PAINT, 0, MFXGroupBoxModule::onPaint),
45
FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_COLLAPSE, MFXGroupBoxModule::onCmdCollapseButton),
46
FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_EXTEND, MFXGroupBoxModule::onCmdExtendButton),
47
FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_RESETWIDTH, MFXGroupBoxModule::onCmdResetButton),
48
FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_SAVE, MFXGroupBoxModule::onCmdSaveButton),
49
FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_LOAD, MFXGroupBoxModule::onCmdLoadButton),
50
FXMAPFUNC(SEL_UPDATE, MID_GROUPBOXMODULE_RESETWIDTH, MFXGroupBoxModule::onUpdResetButton),
51
};
52
53
// Object implementation
54
FXIMPLEMENT(MFXGroupBoxModule, FXVerticalFrame, MFXGroupBoxModuleMap, ARRAYNUMBER(MFXGroupBoxModuleMap))
55
56
// ===========================================================================
57
// method definitions
58
// ===========================================================================
59
60
MFXGroupBoxModule::MFXGroupBoxModule(GNEFrame* frame, const std::string& text, const int options) :
61
FXVerticalFrame(frame->getContentFrame(), GUIDesignGroupBoxModule),
62
myOptions(options),
63
myFrameParent(frame),
64
myCollapsed(false) {
65
// build button and labels
66
FXHorizontalFrame* headerFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
67
if (myOptions & Options::COLLAPSIBLE) {
68
myCollapseButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::COLLAPSE), this, MID_GROUPBOXMODULE_COLLAPSE, GUIDesignButtonMFXGroupBoxModule);
69
}
70
if (myOptions & Options::EXTENSIBLE) {
71
myExtendButton = new MFXButtonTooltip(headerFrame,
72
frame->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
73
TL("Expand"), nullptr, this, MID_GROUPBOXMODULE_EXTEND, GUIDesignButtonMFXGroupBoxModuleExtend);
74
myExtendButton->setTipText(TL("Expand frame to show all contents"));
75
myResetWidthButton = new MFXButtonTooltip(headerFrame,
76
frame->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
77
"", GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GROUPBOXMODULE_RESETWIDTH, GUIDesignButtonMFXGroupBoxModule);
78
myResetWidthButton->setTipText(TL("Shrink frame to default width"));
79
}
80
if (myOptions & Options::SAVE) {
81
mySaveButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_GROUPBOXMODULE_SAVE, GUIDesignButtonMFXGroupBoxModule);
82
}
83
if (myOptions & Options::LOAD) {
84
myLoadButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN_NET), this, MID_GROUPBOXMODULE_LOAD, GUIDesignButtonMFXGroupBoxModule);
85
}
86
myLabel = new FXLabel(headerFrame, text.c_str(), nullptr, GUIDesignLabelMFXGroupBoxModule);
87
// build collapsable frame
88
myCollapsableFrame = new FXVerticalFrame(this, GUIDesignCollapsableFrame);
89
}
90
91
92
MFXGroupBoxModule::MFXGroupBoxModule(FXVerticalFrame* contentFrame, const std::string& text, const int options) :
93
FXVerticalFrame(contentFrame, GUIDesignGroupBoxModuleExtendY),
94
myOptions(options),
95
myCollapsed(false) {
96
// build button and labels
97
FXHorizontalFrame* headerFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
98
if (myOptions & Options::COLLAPSIBLE) {
99
myCollapseButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::COLLAPSE), this, MID_GROUPBOXMODULE_COLLAPSE, GUIDesignButtonMFXGroupBoxModule);
100
}
101
if (myOptions & Options::EXTENSIBLE) {
102
throw ProcessError("This MFXGroupBoxModule doesn't support Extensible flag");
103
}
104
if (myOptions & Options::SAVE) {
105
mySaveButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_GROUPBOXMODULE_SAVE, GUIDesignButtonMFXGroupBoxModule);
106
}
107
if (myOptions & Options::LOAD) {
108
myLoadButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN_NET), this, MID_GROUPBOXMODULE_LOAD, GUIDesignButtonMFXGroupBoxModule);
109
}
110
myLabel = new FXLabel(headerFrame, text.c_str(), nullptr, GUIDesignLabelMFXGroupBoxModule);
111
// build collapsable frame
112
myCollapsableFrame = new FXVerticalFrame(this, GUIDesignCollapsableFrame);
113
}
114
115
116
MFXGroupBoxModule::~MFXGroupBoxModule() {}
117
118
119
void
120
MFXGroupBoxModule::setText(const std::string& text) {
121
myLabel->setText(text.c_str());
122
}
123
124
125
FXVerticalFrame*
126
MFXGroupBoxModule::getCollapsableFrame() {
127
return myCollapsableFrame;
128
}
129
130
131
long
132
MFXGroupBoxModule::onPaint(FXObject*, FXSelector, void* ptr) {
133
FXEvent* event = (FXEvent*)ptr;
134
FXDCWindow dc(this, event);
135
// Paint background
136
dc.setForeground(backColor);
137
dc.fillRectangle(event->rect.x, event->rect.y, event->rect.w, event->rect.h);
138
// draw groove rectangle
139
drawGrooveRectangle(dc, 0, 15, width, height - 15);
140
return 1;
141
}
142
143
144
long
145
MFXGroupBoxModule::onCmdCollapseButton(FXObject*, FXSelector, void*) {
146
if (myCollapsed) {
147
myCollapsed = false;
148
myCollapseButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::COLLAPSE));
149
myCollapsableFrame->show();
150
} else {
151
myCollapsed = true;
152
myCollapseButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::UNCOLLAPSE));
153
myCollapsableFrame->hide();
154
}
155
recalc();
156
return 1;
157
}
158
159
160
long
161
MFXGroupBoxModule::onCmdExtendButton(FXObject*, FXSelector, void*) {
162
if (myFrameParent) {
163
int maximumWidth = -1;
164
// iterate over all collapsableFrame childrens
165
for (auto child = myCollapsableFrame->getFirst(); child != nullptr; child = child->getNext()) {
166
// currently only for GNETLSTables
167
const auto TLSTable = dynamic_cast<GNETLSTable*>(child);
168
if (TLSTable) {
169
// get scrollbar width
170
const int scrollBarWidth = TLSTable->getTLSPhasesParent()->getTLSEditorParent()->getScrollBarWidth();
171
if ((TLSTable->getWidth() + scrollBarWidth) > maximumWidth) {
172
maximumWidth = (TLSTable->getWidth() + scrollBarWidth);
173
}
174
}
175
}
176
// set frame ara width
177
if (maximumWidth != -1) {
178
// add extra padding (30, constant, 15 left, 15 right)
179
myFrameParent->getViewNet()->getViewParent()->setFrameAreaWidth(maximumWidth + 30);
180
}
181
}
182
return 1;
183
}
184
185
186
long
187
MFXGroupBoxModule::onCmdResetButton(FXObject*, FXSelector, void*) {
188
if (myFrameParent) {
189
myFrameParent->getViewNet()->getViewParent()->setFrameAreaWidth(220);
190
}
191
return 1;
192
}
193
194
195
long
196
MFXGroupBoxModule::onUpdResetButton(FXObject* sender, FXSelector, void*) {
197
if (myFrameParent) {
198
if (myFrameParent->getViewNet()->getViewParent()->getFrameAreaWidth() == 220) {
199
sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
200
} else {
201
sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
202
}
203
}
204
return 1;
205
}
206
207
208
long
209
MFXGroupBoxModule::onCmdSaveButton(FXObject*, FXSelector, void*) {
210
return saveContents();
211
}
212
213
214
long
215
MFXGroupBoxModule::onCmdLoadButton(FXObject*, FXSelector, void*) {
216
return loadContents();
217
}
218
219
220
MFXGroupBoxModule::MFXGroupBoxModule() :
221
myOptions(Options::NOTHING),
222
myCollapsed(false) {
223
}
224
225
226
bool
227
MFXGroupBoxModule::saveContents() const {
228
// nothing to do
229
return false;
230
}
231
232
233
bool
234
MFXGroupBoxModule::loadContents() const {
235
// nothing to do
236
return false;
237
}
238
239
240
void
241
MFXGroupBoxModule::toggleSaveButton(const bool value) {
242
if (mySaveButton) {
243
if (value) {
244
mySaveButton->enable();
245
} else {
246
mySaveButton->disable();
247
}
248
}
249
}
250
251