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>
30
31#include "GNERouteFrame.h"
32
33// ===========================================================================
34// FOX callback mapping
35// ===========================================================================
36
41
42// Object implementation
43FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
44
45
46// ===========================================================================
47// method definitions
48// ===========================================================================
49
50// ---------------------------------------------------------------------------
51// GNERouteFrame::RouteModeSelector - methods
52// ---------------------------------------------------------------------------
53
55 MFXGroupBoxModule(routeFrameParent, TL("Route mode")),
56 myRouteFrameParent(routeFrameParent) {
57 // first fill myRouteModesStrings
58 myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, "non consecutive edges"));
59 myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, "consecutive edges"));
60 // Create MFXComboBoxIcon for Route mode
61 myRouteModeMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItems,
63 // fill myRouteModeMatchBox with route modes
64 for (const auto& routeMode : myRouteModesStrings) {
65 myRouteModeMatchBox->appendIconItem(routeMode.second.c_str());
66 }
67 // Create MFXComboBoxIcon for VClass
68 myVClassMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItems,
70 // fill myVClassMatchBox with all VCLass
71 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
72 myVClassMatchBox->appendIconItem(vClass.c_str());
73 }
74 // set Passenger als default VCLass
75 myVClassMatchBox->setCurrentItem(7);
76 // RouteModeSelector is always shown
77 show();
78}
79
80
83
84
87 return myCurrentRouteMode;
88}
89
90
91bool
93 return (myCurrentRouteMode != RouteMode::INVALID);
94}
95
96
97bool
99 return myValidVClass;
100}
101
102
103void
105 const auto routeTemplate = myRouteFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(SUMO_TAG_ROUTE);
106 // check if current mode is valid
107 if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
108 // check if create routes consecutively
109 const bool consecutiveEdges = (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES);
110 // show route attributes modul
111 myRouteFrameParent->myRouteAttributesEditor->showAttributesEditor(routeTemplate, true);
112 // show path creator
113 myRouteFrameParent->myPathCreator->showPathCreatorModule(routeTemplate->getTagProperty(), consecutiveEdges);
114 // update edge colors
115 myRouteFrameParent->myPathCreator->updateEdgeColors();
116 // show legend
117 myRouteFrameParent->myPathLegend->showPathLegendModule();
118 } else {
119 // hide all moduls if route mode isnt' valid
120 myRouteFrameParent->myRouteAttributesEditor->hideAttributesEditor();
121 myRouteFrameParent->myPathCreator->hidePathCreatorModule();
122 myRouteFrameParent->myPathLegend->hidePathLegendModule();
123 // reset all flags
124 for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
125 edge.second->resetCandidateFlags();
126 }
127 // update view net
128 myRouteFrameParent->myViewNet->update();
129 }
130}
131
132
133long
135 // first abort all current operations in moduls
136 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
137 // set invalid current route mode
138 myCurrentRouteMode = RouteMode::INVALID;
139 // set color of myTypeMatchBox to red (invalid)
140 myRouteModeMatchBox->setTextColor(FXRGB(255, 0, 0));
141 // Check if value of myTypeMatchBox correspond of an allowed additional tags
142 for (const auto& routeMode : myRouteModesStrings) {
143 if (routeMode.second == myRouteModeMatchBox->getText().text()) {
144 // Set new current type
145 myCurrentRouteMode = routeMode.first;
146 // set color of myTypeMatchBox to black (valid)
147 myRouteModeMatchBox->setTextColor(FXRGB(0, 0, 0));
148 }
149 }
150 // check if parameters are valid
151 areParametersValid();
152 return 1;
153}
154
155
156long
158 // first abort all current operations in moduls
159 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
160 // set vClass flag invalid
161 myValidVClass = false;
162 // set color of myTypeMatchBox to red (invalid)
163 myVClassMatchBox->setTextColor(FXRGB(255, 0, 0));
164 // Check if value of myTypeMatchBox correspond of an allowed additional tags
165 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
166 if (vClass == myVClassMatchBox->getText().text()) {
167 // change flag
168 myValidVClass = true;
169 // set color of myTypeMatchBox to black (valid)
170 myVClassMatchBox->setTextColor(FXRGB(0, 0, 0));
171 // set vClass in Path creator
172 myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
173 }
174 }
175 // check if parameters are valid
176 areParametersValid();
177 return 1;
178}
179
180// ---------------------------------------------------------------------------
181// GNERouteFrame - methods
182// ---------------------------------------------------------------------------
183
185 GNEFrame(viewParent, viewNet, TL("Routes")),
186 myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
187
188 // create route mode Selector module
190
191 // Create route parameters
193
194 // create consecutive edges module
195 myPathCreator = new GNEPathCreator(this, viewNet->getNet()->getDemandPathManager());
196
197 // create legend label
199}
200
201
205
206
207void
209 // call are parameters valid
211 // show route frame
213}
214
215
216void
218 // reset candidate edges
219 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
220 edge.second->resetCandidateFlags();
221 }
223}
224
225
226bool
228 // first check if current vClass and mode are valid and edge exist
230 // add edge in path
231 myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
232 // update view
234 return true;
235 } else {
236 return false;
237 }
238}
239
240
245
246
247bool
248GNERouteFrame::createPath(const bool /*useLastRoute*/) {
249 // check that route attributes are valid
251 return false;
252 } else if (myPathCreator->getSelectedEdges().size() > 0) {
253 // clear base object
255 // set tag
257 // obtain attributes
259 // add probability (needed for distributions)
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
275 // declare route handler
279 // create route
281 // abort path creation
283 // refresh route attributes
285 // get new route
287 // compute path route
288 newRoute->computePathElement();
289 // set as last created route
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 GUIDesignComboBox
Definition GUIDesigns.h:293
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:311
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:49
#define TL(string)
Definition MsgHandler.h:305
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_PROB
@ SUMO_ATTR_ID
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
void setTag(const SumoXMLTag tag)
set SumoBaseObject tag
void addStringListAttribute(const SumoXMLAttr attr, const std::vector< std::string > &value)
add string list attribute into current SumoBaseObject node
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const std::string getID() const
get ID (all Attribute Carriers have one)
SumoXMLAttr fillSumoBaseObject(CommonXMLStructure::SumoBaseObject *baseObject) const
fill sumo Base object
void refreshAttributesEditor()
refresh attribute editor
bool checkAttributes(const bool showWarning)
check if current edited attributes are valid
virtual void computePathElement()=0
implement in children+
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:121
virtual void show()
show Frame
Definition GNEFrame.cpp:120
virtual void hide()
hide Frame
Definition GNEFrame.cpp:129
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNEPathManager * getDemandPathManager()
get demand path manager
Definition GNENet.cpp:177
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:147
void abortPathCreation()
abort path creation
const std::vector< GNEEdge * > & getSelectedEdges() const
get current selected edges
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
const std::vector< Path > & getPath() const
get path route
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
bool isValidMode() const
check if current mode is Valid
bool isValidVehicleClass() const
check if current VClass is Valid
void areParametersValid()
called after setting a new route or vclass, for showing moduls
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
GNEViewParent * getViewParent() const
get the net object
void setLastCreatedRoute(GNEDemandElement *lastCreatedRoute)
set last created route
void updateViewNet(const bool ignoreViewUpdater=true) const
Mark the entire GNEViewNet to be repainted later.
A single child window which contains a view of the simulation area.
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
MFXGroupBoxModule (based on FXGroupBox)
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
C++ TraCI client API implementation.
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