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