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 
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEUndoList.h>
29 
30 #include "GNERouteFrame.h"
31 
32 // ===========================================================================
33 // FOX callback mapping
34 // ===========================================================================
35 
36 FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[] = {
39 };
40 
41 // Object implementation
42 FXIMPLEMENT(GNERouteFrame::RouteModeSelector, FXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 
49 // ---------------------------------------------------------------------------
50 // GNERouteFrame::RouteModeSelector - methods
51 // ---------------------------------------------------------------------------
52 
54  FXGroupBoxModule(routeFrameParent->myContentFrame, "Route mode"),
55  myRouteFrameParent(routeFrameParent) {
56  // create route template
57  myRouteTemplate = new GNERoute(routeFrameParent->getViewNet()->getNet());
58  // first fill myRouteModesStrings
59  myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, "non consecutive edges"));
60  myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, "consecutive edges"));
61  // Create FXComboBox for Route mode
62  myRouteModeMatchBox = new FXComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, this, MID_GNE_ROUTEFRAME_ROUTEMODE, GUIDesignComboBox);
63  // fill myRouteModeMatchBox with route modes
64  for (const auto& routeMode : myRouteModesStrings) {
65  myRouteModeMatchBox->appendItem(routeMode.second.c_str());
66  }
67  // Set visible items
68  myRouteModeMatchBox->setNumVisible((int)myRouteModeMatchBox->getNumItems());
69  // Create FXComboBox for VClass
70  myVClassMatchBox = new FXComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, this, MID_GNE_ROUTEFRAME_VCLASS, GUIDesignComboBox);
71  // fill myVClassMatchBox with all VCLass
72  for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
73  myVClassMatchBox->appendItem(vClass.c_str());
74  }
75  // set Passenger als default VCLass
76  myVClassMatchBox->setCurrentItem(7);
77  // Set visible items
78  myVClassMatchBox->setNumVisible((int)myVClassMatchBox->getNumItems());
79  // RouteModeSelector is always shown
80  show();
81 }
82 
83 
85  delete myRouteTemplate;
86 }
87 
88 
91  return myCurrentRouteMode;
92 }
93 
94 
95 bool
97  return (myCurrentRouteMode != RouteMode::INVALID);
98 }
99 
100 
101 bool
103  return myValidVClass;
104 }
105 
106 
107 void
109  // check if current mode is valid
110  if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
111  // show route attributes modul
112  myRouteFrameParent->myRouteAttributes->showAttributesCreatorModule(myRouteTemplate, {});
113  // show path creator
114  myRouteFrameParent->myPathCreator->showPathCreatorModule(SUMO_TAG_ROUTE, false, (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES));
115  // update edge colors
116  myRouteFrameParent->myPathCreator->updateEdgeColors();
117  // show legend
118  myRouteFrameParent->myPathLegend->showPathLegendModule();
119  } else {
120  // hide all moduls if route mode isnt' valid
121  myRouteFrameParent->myRouteAttributes->hideAttributesCreatorModule();
122  myRouteFrameParent->myPathCreator->hidePathCreatorModule();
123  myRouteFrameParent->myPathLegend->hidePathLegendModule();
124  // reset all flags
125  for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
126  edge.second->resetCandidateFlags();
127  }
128  // update view net
129  myRouteFrameParent->myViewNet->update();
130  }
131 }
132 
133 
134 long
136  // first abort all current operations in moduls
137  myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
138  // set invalid current route mode
139  myCurrentRouteMode = RouteMode::INVALID;
140  // set color of myTypeMatchBox to red (invalid)
141  myRouteModeMatchBox->setTextColor(FXRGB(255, 0, 0));
142  // Check if value of myTypeMatchBox correspond of an allowed additional tags
143  for (const auto& routeMode : myRouteModesStrings) {
144  if (routeMode.second == myRouteModeMatchBox->getText().text()) {
145  // Set new current type
146  myCurrentRouteMode = routeMode.first;
147  // set color of myTypeMatchBox to black (valid)
148  myRouteModeMatchBox->setTextColor(FXRGB(0, 0, 0));
149  // Write Warning in console if we're in testing mode
150  WRITE_DEBUG(("Selected RouteMode '" + myRouteModeMatchBox->getText() + "' in RouteModeSelector").text());
151  }
152  }
153  // check if parameters are valid
154  areParametersValid();
155  return 1;
156 }
157 
158 
159 long
161  // first abort all current operations in moduls
162  myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
163  // set vClass flag invalid
164  myValidVClass = false;
165  // set color of myTypeMatchBox to red (invalid)
166  myVClassMatchBox->setTextColor(FXRGB(255, 0, 0));
167  // Check if value of myTypeMatchBox correspond of an allowed additional tags
168  for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
169  if (vClass == myVClassMatchBox->getText().text()) {
170  // change flag
171  myValidVClass = true;
172  // set color of myTypeMatchBox to black (valid)
173  myVClassMatchBox->setTextColor(FXRGB(0, 0, 0));
174  // set vClass in Path creator
175  myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
176  // Write Warning in console if we're in testing mode
177  WRITE_DEBUG(("Selected VClass '" + myVClassMatchBox->getText() + "' in RouteModeSelector").text());
178  }
179  }
180  // check if parameters are valid
181  areParametersValid();
182  return 1;
183 }
184 
185 // ---------------------------------------------------------------------------
186 // GNERouteFrame - methods
187 // ---------------------------------------------------------------------------
188 
189 GNERouteFrame::GNERouteFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
190  GNEFrame(horizontalFrameParent, viewNet, "Routes"),
191  myRouteHandler("", myViewNet->getNet(), true),
192  myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
193 
194  // create route mode Selector modul
196 
197  // Create route parameters
199 
200  // create consecutive edges modul
202 
203  // create legend label
205 }
206 
207 
209  delete myRouteBaseObject;
210 }
211 
212 
213 void
215  // call are parameters valid
217  // show route frame
218  GNEFrame::show();
219 }
220 
221 
222 void
224  // reset candidate edges
225  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
226  edge.second->resetCandidateFlags();
227  }
228  GNEFrame::hide();
229 }
230 
231 
232 bool
234  // first check if current vClass and mode are valid and edge exist
236  // add edge in path
237  myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
238  // update view
240  return true;
241  } else {
242  return false;
243  }
244 }
245 
246 
249  return myPathCreator;
250 }
251 
252 
253 void
255  // check that route attributes are valid
258  } else if (myPathCreator->getSelectedEdges().size() > 0) {
259  // clear base object
261  // set tag
263  // obtain attributes
267  }
268  // declare edge vector
269  std::vector<std::string> edges;
270  for (const auto& path : myPathCreator->getPath()) {
271  for (const auto& edgeID : path.getSubPath()) {
272  // get edge
273  GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());
274  // avoid double edges
275  if (edges.empty() || (edges.back() != edge->getID())) {
276  edges.push_back(edge->getID());
277  }
278  }
279  }
280  // set edges in route base object
282  // creare route
284  // abort path creation
286  // refresh route attributes
288  // compute path route
290  }
291 }
292 
293 /****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
Definition: GUIAppEnum.h:1032
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
Definition: GUIAppEnum.h:1034
#define GUIDesignComboBox
Definition: GUIDesigns.h:267
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:285
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:290
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
FXGroupBoxModule (based on FXGroupBox)
virtual void computePathElement()=0
compute pathElement
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
bool areValuesValid() const
check if parameters of attributes are valid
void refreshAttributesCreator()
refresh attribute creator
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:114
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
const std::vector< Path > & getPath() const
get path route
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
void abortPathCreation()
abort path creation
const std::vector< GNEEdge * > & getSelectedEdges() const
get current selected edges
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:125
const std::string & getID() const
get ID
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
GNEFrameAttributeModules::AttributesCreator * myRouteAttributes
internal route attributes
GNEFrameModules::PathCreator * getPathCreator() const
get path creator modul
GNERouteHandler myRouteHandler
route handler
~GNERouteFrame()
Destructor.
GNEFrameModules::PathCreator * myPathCreator
path creator modul
RouteMode
route creation modes
Definition: GNERouteFrame.h:44
void hide()
hide delete frame
RouteModeSelector * myRouteModeSelector
route mode selector
bool addEdgeRoute(GNEEdge *clickedEdge, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add route edge
GNERouteFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
GNEFrameModules::PathLegend * myPathLegend
path legend modul
void createPath()
create path
GNENet * getNet() const
get the net object
void updateViewNet() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:372
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
C++ TraCI client API implementation.
Definition: Route.h:31
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