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.dev/sumo
3 // Copyright (C) 2001-2024 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 
34 FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[] = {
37 };
38 
39 // Object implementation
40 FXIMPLEMENT(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 MFXComboBoxIcon for Route mode
60  myRouteModeMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItemsMedium,
62  // fill myRouteModeMatchBox with route modes
63  for (const auto& routeMode : myRouteModesStrings) {
64  myRouteModeMatchBox->appendIconItem(routeMode.second.c_str());
65  }
66  // Create MFXComboBoxIcon for VClass
67  myVClassMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItemsMedium,
69  // fill myVClassMatchBox with all VCLass
70  for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
71  myVClassMatchBox->appendIconItem(vClass.c_str());
72  }
73  // set Passenger als default VCLass
74  myVClassMatchBox->setCurrentItem(7);
75  // RouteModeSelector is always shown
76  show();
77 }
78 
79 
81  delete myRouteTemplate;
82 }
83 
84 
87  return myCurrentRouteMode;
88 }
89 
90 
91 bool
93  return (myCurrentRouteMode != RouteMode::INVALID);
94 }
95 
96 
97 bool
99  return myValidVClass;
100 }
101 
102 
103 void
105  // check if current mode is valid
106  if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
107  // check if create routes consecutively
108  const bool consecutiveEdges = (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES);
109  // show route attributes modul
110  myRouteFrameParent->myRouteAttributes->showAttributesCreatorModule(myRouteTemplate, {});
111  // show path creator
112  myRouteFrameParent->myPathCreator->showPathCreatorModule(myRouteTemplate->getTagProperty(), consecutiveEdges);
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.second->resetCandidateFlags();
125  }
126  // update view net
127  myRouteFrameParent->myViewNet->update();
128  }
129 }
130 
131 
132 long
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 
157 long
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, TL("Routes")),
189  myRouteHandler("", myViewNet->getNet(), true, false),
190  myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
191 
192  // create route mode Selector module
194 
195  // Create route parameters
197 
198  // create consecutive edges module
199  myPathCreator = new GNEPathCreator(this);
200 
201  // create legend label
202  myPathLegend = new GNEPathLegendModule(this);
203 }
204 
205 
207  delete myRouteBaseObject;
208 }
209 
210 
211 void
213  // call are parameters valid
215  // show route frame
216  GNEFrame::show();
217 }
218 
219 
220 void
222  // reset candidate edges
223  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
224  edge.second.second->resetCandidateFlags();
225  }
226  GNEFrame::hide();
227 }
228 
229 
230 bool
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 
251 bool
252 GNERouteFrame::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  // add probability (needed for distributions)
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  // create route
284  // abort path creation
286  // refresh route attributes
288  // get new route
290  // compute path route
291  newRoute->computePathElement();
292  // set as last created route
293  myViewNet->setLastCreatedRoute(newRoute);
294  return true;
295  }
296  return false;
297 }
298 
299 /****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
Definition: GUIAppEnum.h:1203
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
Definition: GUIAppEnum.h:1205
#define GUIDesignComboBox
Definition: GUIDesigns.h:299
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:317
#define GUIDesignComboBoxVisibleItemsMedium
combo box medium small
Definition: GUIDesigns.h:53
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:306
#define TL(string)
Definition: MsgHandler.h:315
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_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
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
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, std::pair< const GUIGlObject *, 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:121
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
GNEPathLegendModule * myPathLegend
path legend modul
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
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:410
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:88
ComboBox with icon.
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