Eclipse SUMO - Simulation of Urban MObility
GNEStopFrame.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 add Stops elements
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
26 
27 #include "GNEStopFrame.h"
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 
33 // ---------------------------------------------------------------------------
34 // GNEStopFrame::HelpCreation - methods
35 // ---------------------------------------------------------------------------
36 
38  FXGroupBox(StopFrameParent->myContentFrame, "Help", GUIDesignGroupBoxFrame),
39  myStopFrameParent(StopFrameParent) {
40  myInformationLabel = new FXLabel(this, "", 0, GUIDesignLabelFrameInformation);
41 }
42 
43 
45 
46 
47 void
49  // first update help cration
50  updateHelpCreation();
51  // show modul
52  show();
53 }
54 
55 
56 void
58  hide();
59 }
60 
61 
62 void
64  // create information label
65  std::ostringstream information;
66  // set text depending of selected Stop type
67  switch (myStopFrameParent->myStopTagSelector->getCurrentTagProperties().getTag()) {
69  information
70  << "- Click over a bus stop\n"
71  << " to create a stop.";
72  break;
74  information
75  << "- Click over a container stop\n"
76  << " to create a stop.";
77  break;
79  information
80  << "- Click over a charging \n"
81  << " station to create a stop.";
82  break;
84  information
85  << "- Click over a parking area\n"
86  << " to create a stop.";
87  break;
88  case SUMO_TAG_STOP_LANE:
89  information
90  << "- Click over a lane to\n"
91  << " create a stop.";
92  break;
93  default:
94  information
95  << "- No stop parents in\n"
96  << " current network.";
97  break;
98  }
99  // set information label
100  myInformationLabel->setText(information.str().c_str());
101 }
102 
103 // ---------------------------------------------------------------------------
104 // GNEStopFrame - methods
105 // ---------------------------------------------------------------------------
106 
107 GNEStopFrame::GNEStopFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
108  GNEFrame(horizontalFrameParent, viewNet, "Stops") {
109 
110  // Create Stop parent selector
111  myStopParentSelector = new GNEFrameModuls::DemandElementSelector(this, {GNETagProperties::TagType::PERSON, GNETagProperties::TagType::VEHICLE, GNETagProperties::TagType::ROUTE});
112 
113  // Create item Selector modul for Stops
114  myStopTagSelector = new GNEFrameModuls::TagSelector(this, GNETagProperties::TagType::STOP);
115 
116  // Create Stop parameters
118 
119  // Create Netedit parameter
121 
122  // Create Help Creation Modul
123  myHelpCreation = new HelpCreation(this);
124 
125  // refresh myStopParentMatchBox
127 }
128 
129 
131 
132 
133 void
135  // first check if stop frame moduls can be shown
136  bool validStopParent = false;
137  // check if at least there an item that supports an stop
138  for (auto i = myStopParentSelector->getAllowedTags().begin(); (i != myStopParentSelector->getAllowedTags().end()) && (validStopParent == false); i++) {
139  if (myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(*i).size() > 0) {
140  validStopParent = true;
141  }
142  }
143  // show or hidde moduls depending of validStopParent
144  if (validStopParent) {
147  // refresh vType selector
149  // refresh item selector
151  } else {
152  // hide moduls (except help creation)
157  // show help creation modul
159  }
160  // show frame
161  GNEFrame::show();
162 }
163 
164 
165 bool
167  // check if we're selecting a new stop parent
168  if (mouseButtonKeyPressed.shiftKeyPressed()) {
169  if (objectsUnderCursor.getDemandElementFront() &&
170  (objectsUnderCursor.getDemandElementFront()->getTagProperty().isVehicle() || objectsUnderCursor.getDemandElementFront()->getTagProperty().getTag() == SUMO_TAG_ROUTE)) {
172  WRITE_WARNING("Selected " + objectsUnderCursor.getDemandElementFront()->getTagStr() + " '" + objectsUnderCursor.getDemandElementFront()->getID() + "' as stop parent.");
173  return true;
174  } else {
175  WRITE_WARNING("Selected Stop parent isn't valid.");
176  return false;
177  }
178 
179  } else {
180  // now check if stop parent selector is valid
181  if (myStopParentSelector->getCurrentDemandElement() == nullptr) {
182  WRITE_WARNING("Current selected Stop parent isn't valid.");
183  return false;
184  }
185  // declare a Stop
186  SUMOVehicleParameter::Stop stopParameter;
187  // check if stop parameters was sucesfully obtained
190  objectsUnderCursor.getLaneFront(), objectsUnderCursor.getAdditionalFront())) {
191  // create it in RouteFrame
193  // stop sucesfully created, then return true
194  return true;
195  } else {
196  return false;
197  }
198  }
199 }
200 
201 bool
204  const GNEFrameAttributesModuls::NeteditAttributes* myNeteditAttributes,
205  const GNELane* lane, const GNEAdditional* stoppingPlace) {
206  // first check that current selected Stop is valid
207  if (stopTag == SUMO_TAG_NOTHING) {
208  WRITE_WARNING("Current selected Stop type isn't valid.");
209  return false;
210  } else if (stopTag == SUMO_TAG_STOP_LANE) {
211  if (lane) {
212  stop.lane = lane->getID();
213  } else {
214  WRITE_WARNING("Click over a " + toString(SUMO_TAG_LANE) + " to create a stop placed in a " + toString(SUMO_TAG_LANE));
215  return false;
216  }
217  } else if (stopTag == GNE_TAG_PERSONSTOP_EDGE) {
218  if (lane) {
219  stop.edge = lane->getParentEdge()->getID();
220  } else {
221  WRITE_WARNING("Click over a " + toString(SUMO_TAG_EDGE) + " to create a stop placed in a " + toString(SUMO_TAG_EDGE));
222  return false;
223  }
224  } else if (stoppingPlace) {
225  if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_BUS_STOP) {
226  if ((stopTag != SUMO_TAG_STOP_BUSSTOP) && (stopTag != GNE_TAG_PERSONSTOP_BUSSTOP)) {
227  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
228  return false;
229  } else {
230  stop.busstop = stoppingPlace->getID();
231  stop.startPos = 0;
232  stop.endPos = 0;
233  }
234  } else if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_CONTAINER_STOP) {
235  if (stopTag != SUMO_TAG_STOP_CONTAINERSTOP) {
236  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
237  return false;
238  } else {
239  stop.containerstop = stoppingPlace->getID();
240  stop.startPos = 0;
241  stop.endPos = 0;
242  }
243  } else if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_CHARGING_STATION) {
244  if (stopTag != SUMO_TAG_STOP_CHARGINGSTATION) {
245  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
246  return false;
247  } else {
248  stop.chargingStation = stoppingPlace->getID();
249  stop.startPos = 0;
250  stop.endPos = 0;
251  }
252  } else if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA) {
253  if (stopTag != SUMO_TAG_STOP_PARKINGAREA) {
254  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
255  return false;
256  } else {
257  stop.parkingarea = stoppingPlace->getID();
258  stop.startPos = 0;
259  stop.endPos = 0;
260  }
261  }
262  } else {
263  if (stopTag == SUMO_TAG_STOP_BUSSTOP) {
264  WRITE_WARNING("Click over a " + toString(SUMO_TAG_STOP_BUSSTOP) + " to create a stop placed in a " + toString(SUMO_TAG_STOP_BUSSTOP));
265  } else if (stopTag == SUMO_TAG_STOP_CONTAINERSTOP) {
266  WRITE_WARNING("Click over a " + toString(SUMO_TAG_CONTAINER_STOP) + " to create a stop placed in a " + toString(SUMO_TAG_CONTAINER_STOP));
267  } else if (stopTag == SUMO_TAG_CHARGING_STATION) {
268  WRITE_WARNING("Click over a " + toString(SUMO_TAG_CHARGING_STATION) + " to create a stop placed in a " + toString(SUMO_TAG_CHARGING_STATION));
269  } else if (stopTag == SUMO_TAG_STOP_PARKINGAREA) {
270  WRITE_WARNING("Click over a " + toString(SUMO_TAG_PARKING_AREA) + " to create a stop placed in a " + toString(SUMO_TAG_PARKING_AREA));
271  } else if (stopTag == GNE_TAG_PERSONTRIP_EDGE_BUSSTOP) {
272  WRITE_WARNING("Click over a " + toString(SUMO_TAG_STOP_BUSSTOP) + " to create a person stop placed in a " + toString(SUMO_TAG_STOP_BUSSTOP));
273  }
274  return false;
275  }
276  // check if stop attributes are valid
277  if (!stopAttributes->areValuesValid()) {
278  stopAttributes->showWarningMessage();
279  return false;
280  }
281  // declare map to keep attributes from Frames from Frame
282  std::map<SumoXMLAttr, std::string> valuesMap = stopAttributes->getAttributesAndValues(false);
283  // add netedit values
284  if (!stop.lane.empty()) {
286  // check if start position can be parsed
287  if (GNEAttributeCarrier::canParse<double>(valuesMap[SUMO_ATTR_STARTPOS])) {
288  stop.startPos = GNEAttributeCarrier::parse<double>(valuesMap[SUMO_ATTR_STARTPOS]);
290  }
291  // check if end position can be parsed
292  if (GNEAttributeCarrier::canParse<double>(valuesMap[SUMO_ATTR_ENDPOS])) {
293  stop.endPos = GNEAttributeCarrier::parse<double>(valuesMap[SUMO_ATTR_ENDPOS]);
294  stop.parametersSet |= STOP_END_SET;
295  }
296  }
297  // obtain friendly position
298  if (valuesMap.count(SUMO_ATTR_FRIENDLY_POS) > 0) {
299  stop.friendlyPos = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_FRIENDLY_POS));
300  }
301  // obtain actType
302  if (valuesMap.count(SUMO_ATTR_ACTTYPE) > 0) {
303  stop.actType = valuesMap.at(SUMO_ATTR_ACTTYPE);
304  }
305  // fill rest of parameters depending if it was edited
306  if (valuesMap.count(SUMO_ATTR_DURATION) > 0) {
307  stop.duration = string2time(valuesMap.at(SUMO_ATTR_DURATION));
309  } else {
310  stop.duration = -1;
312  }
313  if (valuesMap.count(SUMO_ATTR_UNTIL) > 0) {
314  stop.until = string2time(valuesMap[SUMO_ATTR_UNTIL]);
316  } else {
317  stop.until = -1;
318  stop.parametersSet &= ~STOP_UNTIL_SET;
319  }
320  if (valuesMap.count(SUMO_ATTR_EXTENSION) > 0) {
321  stop.extension = string2time(valuesMap.at(SUMO_ATTR_EXTENSION));
323  }
324  if (valuesMap.count(SUMO_ATTR_TRIGGERED) > 0) {
325  stop.triggered = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_TRIGGERED));
327  }
328  if (valuesMap.count(SUMO_ATTR_CONTAINER_TRIGGERED) > 0) {
329  stop.containerTriggered = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_CONTAINER_TRIGGERED));
331  }
332  if (valuesMap.count(SUMO_ATTR_PARKING) > 0) {
333  stop.parking = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_PARKING));
335  }
336  if (valuesMap.count(SUMO_ATTR_EXPECTED) > 0) {
337  stop.awaitedPersons = GNEAttributeCarrier::parse<std::set<std::string> >(valuesMap.at(SUMO_ATTR_EXPECTED));
339  }
340  if (valuesMap.count(SUMO_ATTR_EXPECTED_CONTAINERS) > 0) {
341  stop.awaitedContainers = GNEAttributeCarrier::parse<std::set<std::string> >(valuesMap.at(SUMO_ATTR_EXPECTED_CONTAINERS));
343  }
344  if (valuesMap.count(SUMO_ATTR_TRIP_ID) > 0) {
345  stop.tripId = valuesMap.at(SUMO_ATTR_TRIP_ID);
347  }
348  if (valuesMap.count(SUMO_ATTR_INDEX) > 0) {
349  if (valuesMap[SUMO_ATTR_INDEX] == "fit") {
350  stop.index = STOP_INDEX_FIT;
351  } else if (valuesMap[SUMO_ATTR_INDEX] == "end") {
352  stop.index = STOP_INDEX_END;
353  } else {
354  stop.index = GNEAttributeCarrier::parse<int>(valuesMap[SUMO_ATTR_INDEX]);
355  }
356  } else {
357  stop.index = STOP_INDEX_END;
358  }
359  // refresh stop attributes
360  stopAttributes->refreshRows();
361  // all ok, then return true
362  return true;
363 }
364 
365 // ===========================================================================
366 // protected
367 // ===========================================================================
368 
369 void
372  // show Stop type selector modul
376  } else {
377  // hide all moduls if stop parent isn't valid
381  }
382 }
383 
384 
385 void
387  // show or hidde moduls depending if current selected stop parent is valid
391  // show moduls
395  } else {
399  }
400  } else {
401  // hide moduls
406  }
407 }
408 
409 
410 /****************************************************************************/
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:278
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:223
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
const int STOP_DURATION_SET
const int STOP_INDEX_END
const int STOP_EXPECTED_SET
const int STOP_UNTIL_SET
const int STOP_PARKING_SET
const int STOP_TRIP_ID_SET
const int STOP_START_SET
const int STOP_CONTAINER_TRIGGER_SET
const int STOP_EXTENSION_SET
const int STOP_INDEX_FIT
const int STOP_TRIGGER_SET
const int STOP_END_SET
const int STOP_EXPECTED_CONTAINERS_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_PERSONSTOP_BUSSTOP
@ SUMO_TAG_STOP_CONTAINERSTOP
stop placed over a containerStop (used in netedit)
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_STOP_CHARGINGSTATION
stop placed over a charging station (used in netedit)
@ SUMO_TAG_STOP_LANE
stop placed over a lane (used in netedit)
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ GNE_TAG_PERSONSTOP_EDGE
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ GNE_TAG_PERSONTRIP_EDGE_BUSSTOP
@ SUMO_TAG_STOP_BUSSTOP
stop placed over a busStop (used in netedit)
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_STOP_PARKINGAREA
stop placed over a parking area (used in netedit)
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_CONTAINER_TRIGGERED
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_PARKING
@ SUMO_ATTR_EXTENSION
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_ACTTYPE
@ SUMO_ATTR_EXPECTED
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_EXPECTED_CONTAINERS
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_TRIGGERED
@ SUMO_ATTR_DURATION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
const std::string & getID() const
get ID
void refreshRows()
refresh rows (called after creating an element)
void showAttributesCreatorModul(const GNETagProperties &tagProperties, const std::vector< SumoXMLAttr > &hiddenAttributes)
show AttributesCreator modul
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
void showNeteditAttributesModul(const GNETagProperties &tagValue)
show Netedit attributes modul
bool getNeteditAttributesAndValues(std::map< SumoXMLAttr, std::string > &valuesMap, const GNELane *lane) const
fill valuesMap with netedit attributes
void hideNeteditAttributesModul()
hide Netedit attributes modul
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
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
const std::vector< SumoXMLTag > & getAllowedTags() const
void showDemandElementSelector()
show demand element selector
void hideDemandElementSelector()
hide demand element selector
void refreshDemandElementSelector()
refresh demand element selector
void hideTagSelector()
hide item selector
void refreshTagProperties()
due myCurrentTagProperties is a Reference, we need to refresh it when frameParent is show
const GNETagProperties & getCurrentTagProperties() const
get current type tag
void showTagSelector()
show item selector
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
GNEEdge * getParentEdge() const
get arent edge
Definition: GNELane.cpp:111
const std::map< SumoXMLTag, std::map< std::string, GNEDemandElement * > > & getDemandElements() const
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
const std::string & getID() const
get ID
static void buildStop(GNENet *net, bool undoDemandElements, const SUMOVehicleParameter::Stop &stopParameters, GNEDemandElement *stopParent)
build stop
void updateHelpCreation()
update HelpCreation
void showHelpCreation()
show HelpCreation
FXLabel * myInformationLabel
Label with creation information.
Definition: GNEStopFrame.h:62
void hideHelpCreation()
hide HelpCreation
HelpCreation(GNEStopFrame *StopFrameParent)
constructor
void show()
show Frame
~GNEStopFrame()
Destructor.
GNEFrameModuls::DemandElementSelector * myStopParentSelector
Stop parent selectors.
Definition: GNEStopFrame.h:99
static bool getStopParameter(SUMOVehicleParameter::Stop &stop, const SumoXMLTag stopTag, GNEViewNet *viewNet, GNEFrameAttributesModuls::AttributesCreator *stopAttributes, const GNEFrameAttributesModuls::NeteditAttributes *myNeteditAttributes, const GNELane *lane, const GNEAdditional *stoppingPlace)
get stop parameters
GNEFrameAttributesModuls::NeteditAttributes * myNeteditAttributes
Netedit parameter.
Definition: GNEStopFrame.h:108
GNEFrameModuls::TagSelector * myStopTagSelector
stop tag selector selector (used to select diffent kind of Stops)
Definition: GNEStopFrame.h:102
void demandElementSelected()
selected demand element in DemandElementSelector
HelpCreation * myHelpCreation
Help creation.
Definition: GNEStopFrame.h:111
void tagSelected()
Tag selected in TagSelector.
GNEFrameAttributesModuls::AttributesCreator * myStopAttributes
internal Stop attributes
Definition: GNEStopFrame.h:105
GNEStopFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
bool addStop(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add Stop element
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
bool isVehicle() const
return true if tag correspond to a vehicle element
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
class used to group all variables related with objects under cursor after a click over view
GNELane * getLaneFront() const
get front lane or a pointer to nullptr
GNEAdditional * getAdditionalFront() const
get front additional element or a pointer to nullptr
GNEDemandElement * getDemandElementFront() const
get front demand element or a pointer to nullptr
GNENet * getNet() const
get the net object
Definition of vehicle stop (position and duration)
std::string edge
The edge to stop at (used only in NETEDIT)
std::string lane
The lane to stop at.
SUMOTime extension
The maximum time extension for boarding / loading.
bool friendlyPos
enable or disable friendly position (used by NETEDIT)
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
std::string chargingStation
(Optional) charging station if one is assigned to the stop
int parametersSet
Information for the output which parameter were set.
int index
at which position in the stops list
SUMOTime until
The time at which the vehicle may continue its journey.
std::string actType
act Type (only used by Persons) (used by NETEDIT)
bool triggered
whether an arriving person lets the vehicle continue
double endPos
The stopping position end.
bool parking
whether the vehicle is removed from the net while stopping
std::set< std::string > awaitedPersons
IDs of persons the vehicle has to wait for until departing.
std::set< std::string > awaitedContainers
IDs of containers the vehicle has to wait for until departing.
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::string tripId
id of the trip within a cyclical public transport route
std::string containerstop
(Optional) container stop if one is assigned to the stop
bool containerTriggered
whether an arriving container lets the vehicle continue
SUMOTime duration
The stopping duration.
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