Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/demand/GNERouteFrame.cpp
169684 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 GNERouteFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Dec 2018
17
///
18
// The Widget for remove network-elements
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/elements/demand/GNERouteHandler.h>
25
#include <netedit/frames/GNEAttributesEditor.h>
26
#include <netedit/frames/GNEFrame.h>
27
#include <netedit/frames/GNEPathCreator.h>
28
#include <netedit/frames/GNEPathLegendModule.h>
29
#include <utils/gui/div/GUIDesigns.h>
30
#include <utils/common/MsgHandler.h>
31
32
#include "GNERouteFrame.h"
33
34
// ===========================================================================
35
// FOX callback mapping
36
// ===========================================================================
37
38
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[] = {
39
FXMAPFUNC(SEL_COMMAND, MID_GNE_ROUTEFRAME_ROUTEMODE, GNERouteFrame::RouteModeSelector::onCmdSelectRouteMode),
40
FXMAPFUNC(SEL_COMMAND, MID_GNE_ROUTEFRAME_VCLASS, GNERouteFrame::RouteModeSelector::onCmdSelectVClass),
41
};
42
43
// Object implementation
44
FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
45
46
47
// ===========================================================================
48
// method definitions
49
// ===========================================================================
50
51
// ---------------------------------------------------------------------------
52
// GNERouteFrame::RouteModeSelector - methods
53
// ---------------------------------------------------------------------------
54
55
GNERouteFrame::RouteModeSelector::RouteModeSelector(GNERouteFrame* routeFrameParent) :
56
MFXGroupBoxModule(routeFrameParent, TL("Route mode")),
57
myRouteFrameParent(routeFrameParent) {
58
const auto statictooltipMenu = routeFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
59
// first fill myRouteModesStrings
60
myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, TL("non consecutive edges")));
61
myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, TL("consecutive edges")));
62
// Create MFXComboBoxIcon for Route mode
63
myRouteModeMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), statictooltipMenu, false, GUIDesignComboBoxVisibleItems,
64
this, MID_GNE_ROUTEFRAME_ROUTEMODE, GUIDesignComboBox);
65
// fill myRouteModeMatchBox with route modes
66
for (const auto& routeMode : myRouteModesStrings) {
67
myRouteModeMatchBox->appendIconItem(routeMode.second.c_str());
68
}
69
// Create MFXComboBoxIcon for VClass
70
myVClassMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), statictooltipMenu, false, GUIDesignComboBoxVisibleItems,
71
this, MID_GNE_ROUTEFRAME_VCLASS, GUIDesignComboBox);
72
// fill myVClassMatchBox with all VCLass
73
for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
74
myVClassMatchBox->appendIconItem(vClass.c_str());
75
}
76
// set Passenger als default VCLass
77
myVClassMatchBox->setCurrentItem(7);
78
// RouteModeSelector is always shown
79
show();
80
}
81
82
83
GNERouteFrame::RouteModeSelector::~RouteModeSelector() {
84
}
85
86
87
const GNERouteFrame::RouteMode&
88
GNERouteFrame::RouteModeSelector::getCurrentRouteMode() const {
89
return myCurrentRouteMode;
90
}
91
92
93
bool
94
GNERouteFrame::RouteModeSelector::isValidMode() const {
95
return (myCurrentRouteMode != RouteMode::INVALID);
96
}
97
98
99
bool
100
GNERouteFrame::RouteModeSelector::isValidVehicleClass() const {
101
return myValidVClass;
102
}
103
104
105
void
106
GNERouteFrame::RouteModeSelector::areParametersValid() {
107
const auto routeTemplate = myRouteFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(SUMO_TAG_ROUTE);
108
// check if current mode is valid
109
if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
110
// check if create routes consecutively
111
const bool consecutiveEdges = (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES);
112
// show route attributes modul
113
myRouteFrameParent->myRouteAttributesEditor->showAttributesEditor(routeTemplate, true);
114
// show path creator
115
myRouteFrameParent->myPathCreator->showPathCreatorModule(routeTemplate->getTagProperty(), consecutiveEdges);
116
// update edge colors
117
myRouteFrameParent->myPathCreator->updateEdgeColors();
118
// show legend
119
myRouteFrameParent->myPathLegend->showPathLegendModule();
120
} else {
121
// hide all moduls if route mode isnt' valid
122
myRouteFrameParent->myRouteAttributesEditor->hideAttributesEditor();
123
myRouteFrameParent->myPathCreator->hidePathCreatorModule();
124
myRouteFrameParent->myPathLegend->hidePathLegendModule();
125
// reset all flags
126
for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
127
edge.second->resetCandidateFlags();
128
}
129
// update view net
130
myRouteFrameParent->myViewNet->update();
131
}
132
}
133
134
135
long
136
GNERouteFrame::RouteModeSelector::onCmdSelectRouteMode(FXObject*, FXSelector, void*) {
137
// first abort all current operations in moduls
138
myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
139
// set invalid current route mode
140
myCurrentRouteMode = RouteMode::INVALID;
141
// set color of myTypeMatchBox to red (invalid)
142
myRouteModeMatchBox->setTextColor(GUIDesignTextColorRed);
143
// Check if value of myTypeMatchBox correspond of an allowed additional tags
144
for (const auto& routeMode : myRouteModesStrings) {
145
if (routeMode.second == myRouteModeMatchBox->getText().text()) {
146
// Set new current type
147
myCurrentRouteMode = routeMode.first;
148
// set color of myTypeMatchBox to black (valid)
149
myRouteModeMatchBox->setTextColor(GUIDesignTextColorBlack);
150
}
151
}
152
// check if parameters are valid
153
areParametersValid();
154
return 1;
155
}
156
157
158
long
159
GNERouteFrame::RouteModeSelector::onCmdSelectVClass(FXObject*, FXSelector, void*) {
160
// first abort all current operations in moduls
161
myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
162
// set vClass flag invalid
163
myValidVClass = false;
164
// set color of myTypeMatchBox to red (invalid)
165
myVClassMatchBox->setTextColor(GUIDesignTextColorRed);
166
// Check if value of myTypeMatchBox correspond of an allowed additional tags
167
for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
168
if (vClass == myVClassMatchBox->getText().text()) {
169
// change flag
170
myValidVClass = true;
171
// set color of myTypeMatchBox to black (valid)
172
myVClassMatchBox->setTextColor(GUIDesignTextColorBlack);
173
// set vClass in Path creator
174
myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
175
}
176
}
177
// check if parameters are valid
178
areParametersValid();
179
return 1;
180
}
181
182
// ---------------------------------------------------------------------------
183
// GNERouteFrame - methods
184
// ---------------------------------------------------------------------------
185
186
GNERouteFrame::GNERouteFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :
187
GNEFrame(viewParent, viewNet, TL("Routes")),
188
myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
189
190
// create route mode Selector module
191
myRouteModeSelector = new RouteModeSelector(this);
192
193
// Create route parameters
194
myRouteAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);
195
196
// create consecutive edges module
197
myPathCreator = new GNEPathCreator(this, viewNet->getNet()->getDemandPathManager());
198
199
// create legend label
200
myPathLegend = new GNEPathLegendModule(this);
201
}
202
203
204
GNERouteFrame::~GNERouteFrame() {
205
delete myRouteBaseObject;
206
}
207
208
209
void
210
GNERouteFrame::show() {
211
// call are parameters valid
212
myRouteModeSelector->areParametersValid();
213
// show route frame
214
GNEFrame::show();
215
}
216
217
218
void
219
GNERouteFrame::hide() {
220
// reset candidate edges
221
for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
222
edge.second->resetCandidateFlags();
223
}
224
GNEFrame::hide();
225
}
226
227
228
bool
229
GNERouteFrame::addEdgeRoute(GNEEdge* clickedEdge, const GNEViewNetHelper::MouseButtonKeyPressed& mouseButtonKeyPressed) {
230
// first check if current vClass and mode are valid and edge exist
231
if (clickedEdge && myRouteModeSelector->isValidVehicleClass() && myRouteModeSelector->isValidMode()) {
232
// add edge in path
233
myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
234
// update view
235
myViewNet->updateViewNet();
236
return true;
237
} else {
238
return false;
239
}
240
}
241
242
243
GNEPathCreator*
244
GNERouteFrame::getPathCreator() const {
245
return myPathCreator;
246
}
247
248
249
bool
250
GNERouteFrame::createPath(const bool /*useLastRoute*/) {
251
// check that route attributes are valid
252
if (!myRouteAttributesEditor->checkAttributes(true)) {
253
return false;
254
} else if (myPathCreator->getSelectedEdges().size() > 0) {
255
// clear base object
256
myRouteBaseObject->clear();
257
// set tag
258
myRouteBaseObject->setTag(SUMO_TAG_ROUTE);
259
// obtain attributes
260
myRouteAttributesEditor->fillSumoBaseObject(myRouteBaseObject);
261
// add probability (needed for distributions)
262
myRouteBaseObject->addDoubleAttribute(SUMO_ATTR_PROB, 1.0);
263
// declare edge vector
264
std::vector<std::string> edges;
265
for (const auto& path : myPathCreator->getPath()) {
266
for (const auto& edgeID : path.getSubPath()) {
267
// get edge
268
GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());
269
// avoid double edges
270
if (edges.empty() || (edges.back() != edge->getID())) {
271
edges.push_back(edge->getID());
272
}
273
}
274
}
275
// set edges in route base object
276
myRouteBaseObject->addStringListAttribute(SUMO_ATTR_EDGES, edges);
277
// declare route handler
278
GNERouteHandler routeHandler(myViewNet->getNet(), myRouteBaseObject->hasStringAttribute(GNE_ATTR_DEMAND_FILE) ?
279
myRouteBaseObject->getStringAttribute(GNE_ATTR_DEMAND_FILE) : "",
280
myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
281
// create route
282
routeHandler.parseSumoBaseObject(myRouteBaseObject);
283
// abort path creation
284
myPathCreator->abortPathCreation();
285
// refresh route attributes
286
myRouteAttributesEditor->refreshAttributesEditor();
287
// get new route
288
auto newRoute = myViewNet->getNet()->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_ROUTE, myRouteBaseObject->getStringAttribute(SUMO_ATTR_ID));
289
// compute path route
290
newRoute->computePathElement();
291
// set as last created route
292
myViewNet->setLastCreatedRoute(newRoute);
293
return true;
294
}
295
return false;
296
}
297
298
/****************************************************************************/
299
300