Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/GNEFrame.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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 GNEFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2016
17
///
18
// The Widget for add additional elements
19
/****************************************************************************/
20
21
#include <netedit/dialogs/GNEHelpAttributesDialog.h>
22
#include <netedit/GNEApplicationWindow.h>
23
#include <netedit/GNETagProperties.h>
24
#include <netedit/GNEViewNet.h>
25
#include <netedit/GNEViewParent.h>
26
#include <netedit/elements/GNEAttributeCarrier.h>
27
#include <utils/gui/div/GUIDesigns.h>
28
#include <utils/gui/windows/GUIAppEnum.h>
29
30
#include "GNEFrame.h"
31
32
// ===========================================================================
33
// defines
34
// ===========================================================================
35
36
#define PADDINGFRAME 10 // (5+5)
37
#define VERTICALSCROLLBARWIDTH 15
38
39
// ===========================================================================
40
// static members
41
// ===========================================================================
42
43
FXFont* GNEFrame::myFrameHeaderFont = nullptr;
44
45
// ===========================================================================
46
// method definitions
47
// ===========================================================================
48
49
GNEFrame::GNEFrame(GNEViewParent* viewParent, GNEViewNet* viewNet, const std::string& frameLabel) :
50
FXVerticalFrame(viewParent->getFramesArea(), GUIDesignAuxiliarFrame),
51
myViewNet(viewNet) {
52
53
// fill myPredefinedTagsMML (to avoid repeating this fill during every element creation)
54
int i = 0;
55
while (SUMOXMLDefinitions::attrs[i].key != SUMO_ATTR_NOTHING) {
56
int key = SUMOXMLDefinitions::attrs[i].key;
57
assert(key >= 0);
58
while (key >= (int)myPredefinedTagsMML.size()) {
59
myPredefinedTagsMML.push_back("");
60
}
61
myPredefinedTagsMML[key] = SUMOXMLDefinitions::attrs[i].str;
62
i++;
63
}
64
65
// Create font only one time
66
if (myFrameHeaderFont == nullptr) {
67
myFrameHeaderFont = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
68
}
69
70
// Create frame for header
71
myHeaderFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
72
73
// Create frame for left elements of header (By default unused)
74
myHeaderLeftFrame = new FXHorizontalFrame(myHeaderFrame, GUIDesignAuxiliarHorizontalFrameCenteredVertically);
75
myHeaderLeftFrame->hide();
76
77
// Create title frame
78
myFrameHeaderLabel = new FXLabel(myHeaderFrame, frameLabel.c_str(), nullptr, GUIDesignLabelFrameInformation);
79
80
// Create frame for right elements of header (By default unused)
81
myHeaderRightFrame = new FXHorizontalFrame(myHeaderFrame, GUIDesignAuxiliarHorizontalFrameCenteredVertically);
82
myHeaderRightFrame->hide();
83
84
// Add separator
85
new FXHorizontalSeparator(this, GUIDesignHorizontalSeparator);
86
87
// Create scroll windows with fixed width for contents
88
myScrollWindowsContents = new FXScrollWindow(this, GUIDesignScrollWindowFixedWidth(10));
89
90
// Create frame for contents (in which GroupBox will be placed)
91
myContentFrame = new FXVerticalFrame(myScrollWindowsContents, GUIDesignAuxiliarFrameFixedWidth(0));
92
93
// Set font of header
94
myFrameHeaderLabel->setFont(myFrameHeaderFont);
95
96
// Hide Frame
97
FXVerticalFrame::hide();
98
}
99
100
101
GNEFrame::~GNEFrame() {
102
// delete frame header only one time
103
if (myFrameHeaderFont) {
104
delete myFrameHeaderFont;
105
myFrameHeaderFont = nullptr;
106
}
107
}
108
109
110
void
111
GNEFrame::focusUpperElement() {
112
myFrameHeaderLabel->setFocus();
113
}
114
115
116
void
117
GNEFrame::show() {
118
// show scroll window
119
FXVerticalFrame::show();
120
// Show and update Frame Area in which this GNEFrame is placed
121
myViewNet->getViewParent()->showFramesArea();
122
}
123
124
125
void
126
GNEFrame::hide() {
127
// hide scroll window
128
FXVerticalFrame::hide();
129
// Hide Frame Area in which this GNEFrame is placed
130
myViewNet->getViewParent()->hideFramesArea();
131
}
132
133
134
void
135
GNEFrame::setFrameWidth(const int newWidth) {
136
// set scroll windows size (minus MARGIN)
137
myScrollWindowsContents->setWidth(newWidth - GUIDesignFrameAreaMargin - DEFAULT_SPACING - 1);
138
// calculate new contentWidth
139
int contentWidth = (newWidth - GUIDesignFrameAreaMargin - DEFAULT_SPACING - 1 - 15);
140
// adjust contents frame
141
myContentFrame->setWidth(contentWidth);
142
// set size of all contents frame children
143
for (auto child = myContentFrame->getFirst(); child != nullptr; child = child->getNext()) {
144
child->setWidth(contentWidth);
145
}
146
// call frame width updated
147
frameWidthUpdated();
148
}
149
150
151
GNEViewNet*
152
GNEFrame::getViewNet() const {
153
return myViewNet;
154
}
155
156
157
FXVerticalFrame*
158
GNEFrame::getContentFrame() const {
159
return myContentFrame;
160
}
161
162
163
FXLabel*
164
GNEFrame::getFrameHeaderLabel() const {
165
return myFrameHeaderLabel;
166
}
167
168
169
FXFont*
170
GNEFrame::getFrameHeaderFont() const {
171
return myFrameHeaderFont;
172
}
173
174
175
int
176
GNEFrame::getScrollBarWidth() const {
177
if (myScrollWindowsContents->verticalScrollBar()->shown()) {
178
return myScrollWindowsContents->verticalScrollBar()->getWidth();
179
} else {
180
return 0;
181
}
182
}
183
184
185
void
186
GNEFrame::openHelpAttributesDialog(const GNEAttributeCarrier* AC) const {
187
// open help dialog with attributes of the given attribute carrier
188
GNEHelpAttributesDialog(myViewNet->getViewParent()->getGNEAppWindows(), AC);
189
}
190
191
192
void
193
GNEFrame::updateFrameAfterUndoRedo() {
194
// this function has to be reimplemented in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
195
}
196
197
198
void
199
GNEFrame::frameWidthUpdated() {
200
// this function can be reimplemented in all child frames
201
}
202
203
// ---------------------------------------------------------------------------
204
// GNEFrame - protected methods
205
// ---------------------------------------------------------------------------
206
207
void
208
GNEFrame::tagSelected() {
209
// this function has to be reimplemented in all child frames that uses a GNETagSelector module
210
}
211
212
213
void
214
GNEFrame::demandElementSelected() {
215
// this function has to be reimplemented in all child frames that uses a DemandElementSelector
216
}
217
218
219
bool
220
GNEFrame::shapeDrawed() {
221
// this function has to be reimplemented in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
222
return false;
223
}
224
225
226
void
227
GNEFrame::attributeUpdated(SumoXMLAttr /*attribute*/) {
228
// this function has to be reimplemented in all child frames that uses a AttributeEditor module
229
}
230
231
232
void
233
GNEFrame::selectedOverlappedElement(GNEAttributeCarrier* /* AC */) {
234
// this function has to be reimplemented in all child frames that uses a GNEOverlappedInspection
235
}
236
237
238
bool
239
GNEFrame::createPath(const bool /*useLastRoute*/) {
240
// this function has to be reimplemented in all child frames that uses a path or consecutiveLanePath
241
return false;
242
}
243
244
245
const std::vector<std::string>&
246
GNEFrame::getPredefinedTagsMML() const {
247
return myPredefinedTagsMML;
248
}
249
250
251
FXLabel*
252
GNEFrame::buildRainbow(FXComposite* parent) {
253
// create label for color information
254
FXLabel* label = new FXLabel(parent, TL("Scale: Min -> Max"), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
255
// create frame for color scale
256
FXHorizontalFrame* horizontalFrameColors = new FXHorizontalFrame(parent, GUIDesignAuxiliarHorizontalFrame);
257
for (const auto& color : GNEViewNetHelper::getRainbowScaledColors()) {
258
FXLabel* colorLabel = new FXLabel(horizontalFrameColors, "", nullptr, GUIDesignLabel(JUSTIFY_LEFT));
259
colorLabel->setBackColor(MFXUtils::getFXColor(color));
260
}
261
return label;
262
// for whatever reason, sonar complains in the next line that horizontalFrameColors may leak, but fox does the cleanup
263
} // NOSONAR
264
265
/****************************************************************************/
266
267