Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERouteFrame.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// The Widget for remove network-elements
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
31
32#include "GNERouteFrame.h"
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
42
43// Object implementation
44FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
45
46
47// ===========================================================================
48// method definitions
49// ===========================================================================
50
51// ---------------------------------------------------------------------------
52// GNERouteFrame::RouteModeSelector - methods
53// ---------------------------------------------------------------------------
54
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
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
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
85
86
91
92
93bool
97
98
99bool
103
104
105void
107 const auto routeTemplate = myRouteFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(SUMO_TAG_ROUTE);
108 // check if current mode is valid
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
135long
137 // first abort all current operations in moduls
138 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
139 // set invalid current route mode
141 // set color of myTypeMatchBox to red (invalid)
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)
150 }
151 }
152 // check if parameters are valid
154 return 1;
155}
156
157
158long
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)
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)
173 // set vClass in Path creator
174 myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
175 }
176 }
177 // check if parameters are valid
179 return 1;
180}
181
182// ---------------------------------------------------------------------------
183// GNERouteFrame - methods
184// ---------------------------------------------------------------------------
185
187 GNEFrame(viewParent, viewNet, TL("Routes")),
188 myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
189
190 // create route mode Selector module
192
193 // Create route parameters
195
196 // create consecutive edges module
197 myPathCreator = new GNEPathCreator(this, viewNet->getNet()->getDemandPathManager());
198
199 // create legend label
201}
202
203
207
208
209void
211 // call are parameters valid
212 myRouteModeSelector->areParametersValid();
213 // show route frame
215}
216
217
218void
220 // reset candidate edges
221 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
222 edge.second->resetCandidateFlags();
223 }
225}
226
227
228bool
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
247
248
249bool
250GNERouteFrame::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
259 // obtain attributes
260 myRouteAttributesEditor->fillSumoBaseObject(myRouteBaseObject);
261 // declare edge vector
262 std::vector<std::string> edges;
263 for (const auto& path : myPathCreator->getPath()) {
264 for (const auto& edgeID : path.getSubPath()) {
265 // get edge
266 GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());
267 // avoid double edges
268 if (edges.empty() || (edges.back() != edge->getID())) {
269 edges.push_back(edge->getID());
270 }
271 }
272 }
273 // set edges in route base object
274 myRouteBaseObject->addStringListAttribute(SUMO_ATTR_EDGES, edges);
275 // declare route handler
276 GNERouteHandler routeHandler(myViewNet->getNet(), myRouteBaseObject->hasStringAttribute(GNE_ATTR_DEMAND_FILE) ?
277 myRouteBaseObject->getStringAttribute(GNE_ATTR_DEMAND_FILE) : "",
278 myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
279 // create route
281 // abort path creation
282 myPathCreator->abortPathCreation();
283 // refresh route attributes
284 myRouteAttributesEditor->refreshAttributesEditor();
285 // get new route
286 auto newRoute = myViewNet->getNet()->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_ROUTE, myRouteBaseObject->getStringAttribute(SUMO_ATTR_ID));
287 // compute path route
288 newRoute->computePathElement();
289 // set as last created route
290 myViewNet->setLastCreatedRoute(newRoute);
291 return true;
292 }
293 return false;
294}
295
296/****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
#define GUIDesignTextColorRed
red color (for invalid text)
Definition GUIDesigns.h:44
#define GUIDesignComboBox
Definition GUIDesigns.h:295
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:64
#define GUIDesignTextColorBlack
black color (for correct text)
Definition GUIDesigns.h:38
#define TL(string)
Definition MsgHandler.h:304
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
@ SUMO_TAG_ROUTE
description of a route
@ GNE_ATTR_DEMAND_FILE
demand demand file
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_ID
const std::string getID() const override
get ID (all Attribute Carriers have one)
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:122
virtual void show()
show Frame
Definition GNEFrame.cpp:110
virtual void hide()
hide Frame
Definition GNEFrame.cpp:119
GNEFrame(GNEViewParent *viewParent, GNEViewNet *viewNet, const std::string &frameLabel)
Constructor.
Definition GNEFrame.cpp:42
GNEPathManager * getDemandPathManager()
get demand path manager
Definition GNENet.cpp:174
long onCmdSelectVClass(FXObject *, FXSelector, void *)
Called when the user select another VClass.
long onCmdSelectRouteMode(FXObject *, FXSelector, void *)
const RouteMode & getCurrentRouteMode() const
get current route mode
RouteModeSelector(GNERouteFrame *routeFrameParent)
FOX-declaration.
MFXComboBoxIcon * myVClassMatchBox
comboBox with the list of VClass
bool isValidMode() const
check if current mode is Valid
GNERouteFrame * myRouteFrameParent
pointer to Frame Parent
bool isValidVehicleClass() const
check if current VClass is Valid
MFXComboBoxIcon * myRouteModeMatchBox
comboBox with the list of route modes
bool myValidVClass
flag to check if VClass is Valid
std::vector< std::pair< RouteMode, std::string > > myRouteModesStrings
list of Route modes that will be shown in Match Box
void areParametersValid()
called after setting a new route or vclass, for showing moduls
RouteMode myCurrentRouteMode
current selected route mode
void show()
show delete frame
CommonXMLStructure::SumoBaseObject * myRouteBaseObject
route base object
GNEPathCreator * myPathCreator
path creator modul
GNEPathLegendModule * myPathLegend
path legend modul
~GNERouteFrame()
Destructor.
GNEAttributesEditor * myRouteAttributesEditor
internal route attributes editor
GNERouteFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
bool createPath(const bool useLastRoute)
create path
RouteMode
route creation modes
void hide()
hide delete frame
GNEPathCreator * getPathCreator() const
get path creator module
RouteModeSelector * myRouteModeSelector
route mode selector
bool addEdgeRoute(GNEEdge *clickedEdge, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add route edge
GNENet * getNet() const
get the net object
A single child window which contains a view of the simulation area.
MFXGroupBoxModule (based on FXGroupBox).
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
MFXGroupBoxModule(GNEFrame *frame, const std::string &text, const int options=Options::COLLAPSIBLE)
constructor for frames
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
class used to group all variables related with mouse buttons and key pressed after certain events
bool shiftKeyPressed() const
check if SHIFT is pressed during current event
bool controlKeyPressed() const
check if CONTROL is pressed during current event