Eclipse SUMO - Simulation of Urban MObility
GNERouteFrame.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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#include <config.h>
21
25#include <netedit/GNEViewNet.h>
26#include <netedit/GNENet.h>
27
28#include "GNERouteFrame.h"
29
30// ===========================================================================
31// FOX callback mapping
32// ===========================================================================
33
34FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[] = {
37};
38
39// Object implementation
40FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46
47// ---------------------------------------------------------------------------
48// GNERouteFrame::RouteModeSelector - methods
49// ---------------------------------------------------------------------------
50
52 MFXGroupBoxModule(routeFrameParent, TL("Route mode")),
53 myRouteFrameParent(routeFrameParent) {
54 // create route template
55 myRouteTemplate = new GNERoute(routeFrameParent->getViewNet()->getNet());
56 // first fill myRouteModesStrings
57 myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, "non consecutive edges"));
58 myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, "consecutive edges"));
59 // Create FXComboBox for Route mode
60 myRouteModeMatchBox = new FXComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, this, MID_GNE_ROUTEFRAME_ROUTEMODE, GUIDesignComboBox);
61 // fill myRouteModeMatchBox with route modes
62 for (const auto& routeMode : myRouteModesStrings) {
63 myRouteModeMatchBox->appendItem(routeMode.second.c_str());
64 }
65 // Set visible items
66 myRouteModeMatchBox->setNumVisible((int)myRouteModeMatchBox->getNumItems());
67 // Create FXComboBox for VClass
68 myVClassMatchBox = new FXComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, this, MID_GNE_ROUTEFRAME_VCLASS, GUIDesignComboBox);
69 // fill myVClassMatchBox with all VCLass
70 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
71 myVClassMatchBox->appendItem(vClass.c_str());
72 }
73 // set Passenger als default VCLass
74 myVClassMatchBox->setCurrentItem(7);
75 // Set visible items
76 myVClassMatchBox->setNumVisible((int)myVClassMatchBox->getNumItems());
77 // RouteModeSelector is always shown
78 show();
79}
80
81
83 delete myRouteTemplate;
84}
85
86
89 return myCurrentRouteMode;
90}
91
92
93bool
95 return (myCurrentRouteMode != RouteMode::INVALID);
96}
97
98
99bool
101 return myValidVClass;
102}
103
104
105void
107 // check if current mode is valid
108 if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
109 // show route attributes modul
110 myRouteFrameParent->myRouteAttributes->showAttributesCreatorModule(myRouteTemplate, {});
111 // show path creator
112 myRouteFrameParent->myPathCreator->showPathCreatorModule(SUMO_TAG_ROUTE, false, (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES));
113 // update edge colors
114 myRouteFrameParent->myPathCreator->updateEdgeColors();
115 // show legend
116 myRouteFrameParent->myPathLegend->showPathLegendModule();
117 } else {
118 // hide all moduls if route mode isnt' valid
119 myRouteFrameParent->myRouteAttributes->hideAttributesCreatorModule();
120 myRouteFrameParent->myPathCreator->hidePathCreatorModule();
121 myRouteFrameParent->myPathLegend->hidePathLegendModule();
122 // reset all flags
123 for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
124 edge.second->resetCandidateFlags();
125 }
126 // update view net
127 myRouteFrameParent->myViewNet->update();
128 }
129}
130
131
132long
134 // first abort all current operations in moduls
135 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
136 // set invalid current route mode
137 myCurrentRouteMode = RouteMode::INVALID;
138 // set color of myTypeMatchBox to red (invalid)
139 myRouteModeMatchBox->setTextColor(FXRGB(255, 0, 0));
140 // Check if value of myTypeMatchBox correspond of an allowed additional tags
141 for (const auto& routeMode : myRouteModesStrings) {
142 if (routeMode.second == myRouteModeMatchBox->getText().text()) {
143 // Set new current type
144 myCurrentRouteMode = routeMode.first;
145 // set color of myTypeMatchBox to black (valid)
146 myRouteModeMatchBox->setTextColor(FXRGB(0, 0, 0));
147 // Write Warning in console if we're in testing mode
148 WRITE_DEBUG(("Selected RouteMode '" + myRouteModeMatchBox->getText() + "' in RouteModeSelector").text());
149 }
150 }
151 // check if parameters are valid
152 areParametersValid();
153 return 1;
154}
155
156
157long
159 // first abort all current operations in moduls
160 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
161 // set vClass flag invalid
162 myValidVClass = false;
163 // set color of myTypeMatchBox to red (invalid)
164 myVClassMatchBox->setTextColor(FXRGB(255, 0, 0));
165 // Check if value of myTypeMatchBox correspond of an allowed additional tags
166 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
167 if (vClass == myVClassMatchBox->getText().text()) {
168 // change flag
169 myValidVClass = true;
170 // set color of myTypeMatchBox to black (valid)
171 myVClassMatchBox->setTextColor(FXRGB(0, 0, 0));
172 // set vClass in Path creator
173 myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
174 // Write Warning in console if we're in testing mode
175 WRITE_DEBUG(("Selected VClass '" + myVClassMatchBox->getText() + "' in RouteModeSelector").text());
176 }
177 }
178 // check if parameters are valid
179 areParametersValid();
180 return 1;
181}
182
183// ---------------------------------------------------------------------------
184// GNERouteFrame - methods
185// ---------------------------------------------------------------------------
186
188 GNEFrame(viewParent, viewNet, "Routes"),
189 myRouteHandler("", myViewNet->getNet(), true, false),
190 myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
191
192 // create route mode Selector modul
194
195 // Create route parameters
197
198 // create consecutive edges modul
199 myPathCreator = new GNEPathCreator(this);
200
201 // create legend label
202 myPathLegend = new GNEM_PathLegend(this);
203}
204
205
207 delete myRouteBaseObject;
208}
209
210
211void
213 // call are parameters valid
215 // show route frame
217}
218
219
220void
222 // reset candidate edges
223 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
224 edge.second->resetCandidateFlags();
225 }
227}
228
229
230bool
232 // first check if current vClass and mode are valid and edge exist
234 // add edge in path
235 myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
236 // update view
238 return true;
239 } else {
240 return false;
241 }
242}
243
244
247 return myPathCreator;
248}
249
250
251bool
252GNERouteFrame::createPath(const bool /*useLastRoute*/) {
253 // check that route attributes are valid
256 } else if (myPathCreator->getSelectedEdges().size() > 0) {
257 // clear base object
259 // set tag
261 // obtain attributes
265 }
266 // declare edge vector
267 std::vector<std::string> edges;
268 for (const auto& path : myPathCreator->getPath()) {
269 for (const auto& edgeID : path.getSubPath()) {
270 // get edge
271 GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());
272 // avoid double edges
273 if (edges.empty() || (edges.back() != edge->getID())) {
274 edges.push_back(edge->getID());
275 }
276 }
277 }
278 // set edges in route base object
280 // creare route
282 // abort path creation
284 // refresh route attributes
286 // get new route
288 // compute path route
289 newRoute->computePathElement();
290 // set as last created route
292 return true;
293 }
294 return false;
295}
296
297/****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
Definition: GUIAppEnum.h:1127
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
Definition: GUIAppEnum.h:1129
#define GUIDesignComboBox
Definition: GUIDesigns.h:306
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:321
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:282
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_ATTR_EDGES
the edges of a route
@ 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 addStringAttribute(const SumoXMLAttr attr, const std::string &value)
void clear()
clear SumoBaseObject
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const std::string getID() const
get ID (all Attribute Carriers have one)
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
bool areValuesValid() const
check if parameters of attributes are valid
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
void refreshAttributesCreator()
refresh attribute creator
virtual void computePathElement()=0
compute pathElement
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
GNEViewNet * myViewNet
FOX need this.
Definition: GNEFrame.h:117
virtual void show()
show Frame
Definition: GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:124
std::string generateDemandElementID(SumoXMLTag tag) const
generate demand element id
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.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
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
GNERoute * myRouteTemplate
route template
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
GNEAttributesCreator * myRouteAttributes
internal route attributes
GNERouteHandler myRouteHandler
route handler
~GNERouteFrame()
Destructor.
GNERouteFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
bool createPath(const bool useLastRoute)
create path
RouteMode
route creation modes
Definition: GNERouteFrame.h:46
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
GNEM_PathLegend * myPathLegend
path legend modul
GNENet * getNet() const
get the net object
void setLastCreatedRoute(GNEDemandElement *lastCreatedRoute)
set last created route
void updateViewNet() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:414
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:84
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