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-2020 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, FXGroupBox, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 
49 // ---------------------------------------------------------------------------
50 // GNERouteFrame::RouteModeSelector - methods
51 // ---------------------------------------------------------------------------
52 
54  FXGroupBox(routeFrameParent->myContentFrame, "Route mode", GUIDesignGroupBoxFrame),
55  myRouteFrameParent(routeFrameParent),
56  myCurrentRouteMode(RouteMode::NONCONSECUTIVE_EDGES),
57  myValidVClass(true) {
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(this, 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(this, 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 
86 
89  return myCurrentRouteMode;
90 }
91 
92 
93 bool
95  return (myCurrentRouteMode != RouteMode::INVALID);
96 }
97 
98 
99 bool
101  return myValidVClass;
102 }
103 
104 
105 void
107  // check if current mode is valid
108  if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
109  // show route attributes modul
110  myRouteFrameParent->myRouteAttributes->showAttributesCreatorModul(GNEAttributeCarrier::getTagProperties(SUMO_TAG_ROUTE), {});
111  // show path creator
112  myRouteFrameParent->myPathCreator->showPathCreatorModul(SUMO_TAG_ROUTE, false, (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES));
113  // update edge colors
114  myRouteFrameParent->myPathCreator->updateEdgeColors();
115  // show legend
116  myRouteFrameParent->myPathLegend->showPathLegendModul();
117  } else {
118  // hide all moduls if route mode isnt' valid
119  myRouteFrameParent->myRouteAttributes->hideAttributesCreatorModul();
120  myRouteFrameParent->myPathCreator->hidePathCreatorModul();
121  myRouteFrameParent->myPathLegend->hidePathLegendModul();
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 
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 
187 GNERouteFrame::GNERouteFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
188  GNEFrame(horizontalFrameParent, viewNet, "Routes") {
189 
190  // create route mode Selector modul
192 
193  // Create route parameters
195 
196  // create consecutive edges modul
198 
199  // create legend label
201 }
202 
203 
205 
206 
207 void
209  // call are parameters valid
211  // show route frame
212  GNEFrame::show();
213 }
214 
215 
216 void
218  // reset candidate edges
219  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
220  edge.second->resetCandidateFlags();
221  }
222  GNEFrame::hide();
223 }
224 
225 
226 bool
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 
243  return myPathCreator;
244 }
245 
246 
247 void
249  // check that route attributes are valid
252  } else if (myPathCreator->getSelectedEdges().size() > 0) {
253  // obtain attributes
254  std::map<SumoXMLAttr, std::string> valuesMap = myRouteAttributes->getAttributesAndValues(true);
255  // declare a route parameter
256  GNERouteHandler::RouteParameter routeParameters;
257  for (const auto& path : myPathCreator->getPath()) {
258  for (const auto& edgeID : path.getSubPath()) {
259  // get edge
260  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(edgeID->getID());
261  // avoid double edges
262  if (routeParameters.edges.empty() || (routeParameters.edges.back() != edge)) {
263  routeParameters.edges.push_back(edge);
264  }
265  }
266  }
267  // Check if ID has to be generated
268  if (valuesMap.count(SUMO_ATTR_ID) == 0) {
270  } else {
271  routeParameters.routeID = valuesMap[SUMO_ATTR_ID];
272  }
273  // fill rest of elements
274  routeParameters.color = GNEAttributeCarrier::parse<RGBColor>(valuesMap.at(SUMO_ATTR_COLOR));
275  routeParameters.vClass = myPathCreator->getVClass();
276  // create route
277  GNERoute* route = new GNERoute(myViewNet->getNet(), routeParameters);
278  // add it into GNENet using GNEChange_DemandElement (to allow undo-redo)
279  myViewNet->getUndoList()->p_begin("add " + route->getTagStr());
280  myViewNet->getUndoList()->add(new GNEChange_DemandElement(route, true), true);
282  // abort path creation
284  // refresh route attributes
286  }
287 }
288 
289 /****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
Definition: GUIAppEnum.h:943
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
Definition: GUIAppEnum.h:945
#define GUIDesignComboBox
Definition: GUIDesigns.h:237
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:255
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:278
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
static const GNETagProperties & getTagProperties(SumoXMLTag tag)
get Tag Properties
const std::string & getTagStr() const
get tag assigned to this object in string format
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:49
void refreshRows()
refresh rows (called after creating an element)
std::map< SumoXMLAttr, std::string > getAttributesAndValues(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
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:113
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
std::vector< GNEEdge * > getSelectedEdges() const
get current selected additionals
const std::vector< Path > & getPath() const
get path route
SUMOVehicleClass getVClass() const
get vClass
void abortPathCreation()
abort path creation
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
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 failHard=true) const
get edge by id
Definition: GNENet.cpp:1141
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
std::string generateDemandElementID(SumoXMLTag tag) const
generate demand element id
Definition: GNENet.cpp:2539
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
GNEFrameModuls::PathCreator * myPathCreator
path creator modul
void show()
show delete frame
~GNERouteFrame()
Destructor.
GNEFrameAttributesModuls::AttributesCreator * myRouteAttributes
internal route attributes
RouteMode
route creation modes
Definition: GNERouteFrame.h:36
void hide()
hide delete frame
GNEFrameModuls::PathCreator * getPathCreator() const
get path creator modul
RouteModeSelector * myRouteModeSelector
route mode selector
bool addEdgeRoute(GNEEdge *clickedEdge, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add route edge
GNEFrameModuls::PathLegend * myPathLegend
path legend modul
GNERouteFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
void createPath()
create path
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
GNENet * getNet() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
void updateViewNet() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:318
C++ TraCI client API implementation.
struct for saving route parameters
std::string routeID
string for saving parsed Route ID
std::vector< GNEEdge * > edges
edges
RGBColor color
string for saving parsed route colors
SUMOVehicleClass vClass
vClass used by this route
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