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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The Widget for add Stops elements
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewNet.h>
30 
31 #include "GNEStopFrame.h"
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
36 
37 // ---------------------------------------------------------------------------
38 // GNEStopFrame::HelpCreation - methods
39 // ---------------------------------------------------------------------------
40 
42  FXGroupBox(StopFrameParent->myContentFrame, "Help", GUIDesignGroupBoxFrame),
43  myStopFrameParent(StopFrameParent) {
44  myInformationLabel = new FXLabel(this, "", 0, GUIDesignLabelFrameInformation);
45 }
46 
47 
49 
50 
51 void
53  // first update help cration
55  // show modul
56  show();
57 }
58 
59 
60 void
62  hide();
63 }
64 
65 
66 void
68  // create information label
69  std::ostringstream information;
70  // set text depending of selected Stop type
73  information
74  << "- Click over a bus stop\n"
75  << " to create a stop.";
76  break;
78  information
79  << "- Click over a container stop\n"
80  << " to create a stop.";
81  break;
83  information
84  << "- Click over a charging \n"
85  << " station to create a stop.";
86  break;
88  information
89  << "- Click over a parking area\n"
90  << " to create a stop.";
91  break;
92  case SUMO_TAG_STOP_LANE:
93  information
94  << "- Click over a lane to\n"
95  << " create a stop.";
96  break;
97  default:
98  information
99  << "- No stop parents in\n"
100  << " current network.";
101  break;
102  }
103  // set information label
104  myInformationLabel->setText(information.str().c_str());
105 }
106 
107 // ---------------------------------------------------------------------------
108 // GNEStopFrame - methods
109 // ---------------------------------------------------------------------------
110 
111 GNEStopFrame::GNEStopFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
112  GNEFrame(horizontalFrameParent, viewNet, "Stops") {
113 
114  // Create Stop parent selector
115  myStopParentSelector = new GNEFrameModuls::DemandElementSelector(this, {GNEAttributeCarrier::TagType::TAGTYPE_PERSON, GNEAttributeCarrier::TagType::TAGTYPE_VEHICLE, GNEAttributeCarrier::TagType::TAGTYPE_ROUTE});
116 
117  // Create item Selector modul for Stops
118  myStopTagSelector = new GNEFrameModuls::TagSelector(this, GNEAttributeCarrier::TagType::TAGTYPE_STOP);
119 
120  // Create Stop parameters
122 
123  // Create Netedit parameter
125 
126  // Create Help Creation Modul
127  myHelpCreation = new HelpCreation(this);
128 
129  // refresh myStopParentMatchBox
131 }
132 
133 
135 
136 
137 void
139  // first check if stop frame moduls can be shown
140  bool validStopParent = false;
141  // check if at least there an item that supports an stop
142  for (auto i = myStopParentSelector->getAllowedTags().begin(); (i != myStopParentSelector->getAllowedTags().end()) && (validStopParent == false); i++) {
143  if (myViewNet->getNet()->getAttributeCarriers().demandElements.at(*i).size() > 0) {
144  validStopParent = true;
145  }
146  }
147  // show or hidde moduls depending of validStopParent
148  if (validStopParent) {
151  // refresh vType selector
153  // refresh item selector
155  } else {
156  // hide moduls (except help creation)
161  // show help creation modul
163  }
164  // show frame
165  GNEFrame::show();
166 }
167 
168 
169 bool
170 GNEStopFrame::addStop(const GNEViewNetHelper::ObjectsUnderCursor& objectsUnderCursor, bool shiftPressed) {
171  // check if we're selecting a new stop parent
172  if (shiftPressed) {
173  if (objectsUnderCursor.getDemandElementFront() &&
174  (objectsUnderCursor.getDemandElementFront()->getTagProperty().isVehicle() || objectsUnderCursor.getDemandElementFront()->getTagProperty().getTag() == SUMO_TAG_ROUTE)) {
176  WRITE_WARNING("Selected " + objectsUnderCursor.getDemandElementFront()->getTagStr() + " '" + objectsUnderCursor.getDemandElementFront()->getID() + "' as stop parent.");
177  return true;
178  } else {
179  WRITE_WARNING("Selected Stop parent isn't valid.");
180  return false;
181  }
182 
183  } else {
184  // now check if stop parent selector is valid
185  if (myStopParentSelector->getCurrentDemandElement() == nullptr) {
186  WRITE_WARNING("Current selected Stop parent isn't valid.");
187  return false;
188  }
189  // declare a Stop
190  SUMOVehicleParameter::Stop stopParameter;
191  bool friendlyPosition = false;
192  // check if stop parameters was sucesfully obtained
193  if (getStopParameter(stopParameter, friendlyPosition, myStopTagSelector->getCurrentTagProperties().getTag(),
195  objectsUnderCursor.getLaneFront(), objectsUnderCursor.getAdditionalFront())) {
196  // create it in RouteFrame
197  GNERouteHandler::buildStop(myViewNet, true, stopParameter, myStopParentSelector->getCurrentDemandElement(), friendlyPosition);
198  // stop sucesfully created, then return true
199  return true;
200  } else {
201  return false;
202  }
203  }
204 }
205 
206 bool
207 GNEStopFrame::getStopParameter(SUMOVehicleParameter::Stop& stop, bool& friendlyPosition, const SumoXMLTag stopTag,
209  const GNELane* lane, const GNEAdditional* stoppingPlace) {
210  // first check that current selected Stop is valid
211  if (stopTag == SUMO_TAG_NOTHING) {
212  WRITE_WARNING("Current selected Stop type isn't valid.");
213  return false;
214  } else if ((stopTag == SUMO_TAG_STOP_LANE) || (stopTag == SUMO_TAG_PERSONSTOP_LANE)) {
215  if (lane) {
216  stop.lane = lane->getID();
217  } else {
218  WRITE_WARNING("Click over a " + toString(SUMO_TAG_LANE) + " to create a stop placed in a " + toString(SUMO_TAG_LANE));
219  return false;
220  }
221  } else if (stoppingPlace) {
222  if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_BUS_STOP) {
223  if ((stopTag != SUMO_TAG_STOP_BUSSTOP) && (stopTag != SUMO_TAG_PERSONSTOP_BUSSTOP)) {
224  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
225  return false;
226  } else {
227  stop.busstop = stoppingPlace->getID();
228  stop.startPos = 0;
229  stop.endPos = 0;
230  }
231  } else if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_CONTAINER_STOP) {
232  if (stopTag != SUMO_TAG_STOP_CONTAINERSTOP) {
233  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
234  return false;
235  } else {
236  stop.containerstop = stoppingPlace->getID();
237  stop.startPos = 0;
238  stop.endPos = 0;
239  }
240  } else if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_CHARGING_STATION) {
241  if (stopTag != SUMO_TAG_STOP_CHARGINGSTATION) {
242  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
243  return false;
244  } else {
245  stop.chargingStation = stoppingPlace->getID();
246  stop.startPos = 0;
247  stop.endPos = 0;
248  }
249  } else if (stoppingPlace->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA) {
250  if (stopTag != SUMO_TAG_STOP_PARKINGAREA) {
251  WRITE_WARNING("Invalid clicked stopping place to create a stop placed in a " + stoppingPlace->getTagProperty().getTagStr());
252  return false;
253  } else {
254  stop.parkingarea = stoppingPlace->getID();
255  stop.startPos = 0;
256  stop.endPos = 0;
257  }
258  }
259  } else {
260  if (stopTag == SUMO_TAG_STOP_BUSSTOP) {
261  WRITE_WARNING("Click over a " + toString(SUMO_TAG_STOP_BUSSTOP) + " to create a stop placed in a " + toString(SUMO_TAG_STOP_BUSSTOP));
262  } else if (stopTag != SUMO_TAG_STOP_CONTAINERSTOP) {
263  WRITE_WARNING("Click over a " + toString(SUMO_TAG_CONTAINER_STOP) + " to create a stop placed in a " + toString(SUMO_TAG_CONTAINER_STOP));
264  } else if (stopTag != SUMO_TAG_CHARGING_STATION) {
265  WRITE_WARNING("Click over a " + toString(SUMO_TAG_CHARGING_STATION) + " to create a stop placed in a " + toString(SUMO_TAG_CHARGING_STATION));
266  } else if (stopTag != SUMO_TAG_STOP_PARKINGAREA) {
267  WRITE_WARNING("Click over a " + toString(SUMO_TAG_PARKING_AREA) + " to create a stop placed in a " + toString(SUMO_TAG_PARKING_AREA));
268  } else if (stopTag == SUMO_TAG_PERSONTRIP_BUSSTOP) {
269  WRITE_WARNING("Click over a " + toString(SUMO_TAG_STOP_BUSSTOP) + " to create a person stop placed in a " + toString(SUMO_TAG_STOP_BUSSTOP));
270  }
271  return false;
272  }
273  // check if stop attributes are valid
274  if (!stopAttributes->areValuesValid()) {
275  stopAttributes->showWarningMessage();
276  return false;
277  }
278  // declare map to keep attributes from Frames from Frame
279  std::map<SumoXMLAttr, std::string> valuesMap = stopAttributes->getAttributesAndValues(false);
280  // generate ID
281  valuesMap[SUMO_ATTR_ID] = viewNet->getNet()->generateDemandElementID("", stopTag);
282  // add netedit values
283  if (!stop.lane.empty()) {
284  myNeteditAttributes->getNeteditAttributesAndValues(valuesMap, lane);
285  // check if start position can be parsed
286  if (GNEAttributeCarrier::canParse<double>(valuesMap[SUMO_ATTR_STARTPOS])) {
287  stop.startPos = GNEAttributeCarrier::parse<double>(valuesMap[SUMO_ATTR_STARTPOS]);
289  }
290  // check if end position can be parsed
291  if (GNEAttributeCarrier::canParse<double>(valuesMap[SUMO_ATTR_ENDPOS])) {
292  stop.endPos = GNEAttributeCarrier::parse<double>(valuesMap[SUMO_ATTR_ENDPOS]);
293  stop.parametersSet |= STOP_END_SET;
294  }
295  }
296  // obtain friendly position
297  if (valuesMap.count(SUMO_ATTR_FRIENDLY_POS) > 0) {
298  friendlyPosition = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_FRIENDLY_POS));
299  }
300  // fill rest of parameters depending if it was edited
301  if (valuesMap.count(SUMO_ATTR_DURATION) > 0) {
302  stop.duration = string2time(valuesMap.at(SUMO_ATTR_DURATION));
303  } else {
304  stop.duration = -1;
305  }
306  if (valuesMap.count(SUMO_ATTR_UNTIL) > 0) {
307  stop.until = string2time(valuesMap[SUMO_ATTR_UNTIL]);
308  } else {
309  stop.until = -1;
310  }
311  if (valuesMap.count(SUMO_ATTR_TRIGGERED) > 0) {
312  stop.triggered = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_TRIGGERED));
314  }
315  if (valuesMap.count(SUMO_ATTR_CONTAINER_TRIGGERED) > 0) {
316  stop.containerTriggered = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_CONTAINER_TRIGGERED));
318  }
319  if (valuesMap.count(SUMO_ATTR_PARKING) > 0) {
320  stop.parking = GNEAttributeCarrier::parse<bool>(valuesMap.at(SUMO_ATTR_PARKING));
322  }
323  if (valuesMap.count(SUMO_ATTR_EXPECTED) > 0) {
324  stop.awaitedPersons = GNEAttributeCarrier::parse<std::set<std::string> >(valuesMap.at(SUMO_ATTR_EXPECTED));
326  }
327  if (valuesMap.count(SUMO_ATTR_EXPECTED_CONTAINERS) > 0) {
328  stop.awaitedContainers = GNEAttributeCarrier::parse<std::set<std::string> >(valuesMap.at(SUMO_ATTR_EXPECTED_CONTAINERS));
330  }
331  if (valuesMap.count(SUMO_ATTR_TRIP_ID) > 0) {
332  stop.tripId = valuesMap.at(SUMO_ATTR_TRIP_ID);
334  }
335  if (valuesMap.count(SUMO_ATTR_INDEX) > 0) {
336  if (valuesMap[SUMO_ATTR_INDEX] == "fit") {
337  stop.index = STOP_INDEX_FIT;
338  } else if (valuesMap[SUMO_ATTR_INDEX] == "end") {
339  stop.index = STOP_INDEX_END;
340  } else {
341  stop.index = GNEAttributeCarrier::parse<int>(valuesMap[SUMO_ATTR_INDEX]);
342  }
343  } else {
344  stop.index = STOP_INDEX_END;
345  }
346  // all ok, then return true
347  return true;
348 }
349 
350 // ===========================================================================
351 // protected
352 // ===========================================================================
353 
354 void
357  // show Stop type selector modul
361  } else {
362  // hide all moduls if stop parent isn't valid
366  }
367 }
368 
369 
370 void
372  // show or hidde moduls depending if current selected stop parent is valid
376  // show moduls
380  } else {
384  }
385  } else {
386  // hide moduls
391  }
392 }
393 
394 /****************************************************************************/
const AttributeCarriers & getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:1014
stop placed over a parking area (used in netedit)
const int STOP_CONTAINER_TRIGGER_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::string lane
The lane to stop at.
void hideHelpCreation()
hide HelpCreation
std::set< std::string > awaitedPersons
IDs of persons the vehicle has to wait for until departing.
bool isVehicle() const
return true if tag correspond to a vehicle element
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
void showTagSelector()
show item selector
begin/end of the description of a single lane
void refreshDemandElementSelector()
refresh demand element selector
void showAttributesCreatorModul(const GNEAttributeCarrier::TagProperties &myTagProperties)
show AttributesCreator modul
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
stop placed over a lane (used in netedit)
std::string busstop
(Optional) bus stop if one is assigned to the stop
int parametersSet
Information for the output which parameter were set.
void showDemandElementSelector()
show demand element selector
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
void hideNeteditAttributesModul()
hide Netedit attributes modul
const int STOP_INDEX_FIT
std::map< SumoXMLAttr, std::string > getAttributesAndValues(bool includeAll) const
get attributes and their values
std::string parkingarea
(Optional) parking area if one is assigned to the stop
void tagSelected()
Tag selected in TagSelector.
GNEFrameAttributesModuls::AttributesCreator * myStopAttributes
internal Stop attributes
Definition: GNEStopFrame.h:108
begin/end of the description of a route
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
bool triggered
whether an arriving person lets the vehicle continue
bool areValuesValid() const
check if parameters of attributes are valid
GNEStopFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
std::string tripId
id of the trip within a cyclical public transport route
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:120
void showNeteditAttributesModul(const GNEAttributeCarrier::TagProperties &tagValue)
show Netedit attributes modul
GNEDemandElement * getDemandElementFront() const
get front net element element (or a pointer to nullptr if there isn&#39;t)
const int STOP_START_SET
void showHelpCreation()
show HelpCreation
void hideTagSelector()
hide item selector
GNEDemandElement * getCurrentDemandElement() const
get current demand element
stop placed over a charging station (used in netedit)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
void updateHelpCreation()
update HelpCreation
void demandElementSelected()
selected demand element in DemandElementSelector
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::vector< SumoXMLTag > & getAllowedTags() const
static bool getStopParameter(SUMOVehicleParameter::Stop &stop, bool &friendlyPosition, const SumoXMLTag stopTag, GNEViewNet *viewNet, const GNEFrameAttributesModuls::AttributesCreator *stopAttributes, const GNEFrameAttributesModuls::NeteditAttributes *myNeteditAttributes, const GNELane *lane, const GNEAdditional *stoppingPlace)
get stop parameters
SUMOTime until
The time at which the vehicle may continue its journey.
void refreshTagProperties()
due myCurrentTagProperties is a Reference, we need to refresh it when frameParent is show ...
const int STOP_INDEX_END
GNEStopFrame * myStopFrameParent
pointer to Stop Frame Parent
Definition: GNEStopFrame.h:62
stop placed over a containerStop (used in netedit)
stop placed over a busStop (used in netedit)
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:42
class used to group all variables related with objects under cursor after a click over view ...
const int STOP_TRIP_ID_SET
GNELane * getLaneFront() const
get front lane (or a pointer to nullptr if there isn&#39;t)
std::map< SumoXMLTag, std::map< std::string, GNEDemandElement * > > demandElements
map with the name and pointer to demand elements of net
Definition: GNENet.h:105
const int STOP_EXPECTED_SET
const std::string getID() const
function to support debugging
GNEFrameModuls::DemandElementSelector * myStopParentSelector
Stop parent selectors.
Definition: GNEStopFrame.h:102
double endPos
The stopping position end.
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:210
std::string generateDemandElementID(const std::string &prefix, SumoXMLTag type) const
generate demand element id
Definition: GNENet.cpp:2411
FXLabel * myInformationLabel
Label with creation information.
Definition: GNEStopFrame.h:65
GNEAdditional * getAdditionalFront() const
get front additional element (or a pointer to nullptr if there isn&#39;t)
void show()
show Frame
Definition of vehicle stop (position and duration)
int index
at which position in the stops list
const int STOP_END_SET
bool getNeteditAttributesAndValues(std::map< SumoXMLAttr, std::string > &valuesMap, const GNELane *lane) const
fill valuesMap with netedit attributes
const int STOP_PARKING_SET
double startPos
The stopping position start.
const int STOP_TRIGGER_SET
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
const int STOP_EXPECTED_CONTAINERS_SET
bool containerTriggered
whether an arriving container lets the vehicle continue
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:255
HelpCreation(GNEStopFrame *StopFrameParent)
constructor
static void buildStop(GNEViewNet *viewNet, bool undoDemandElements, const SUMOVehicleParameter::Stop &stopParameters, GNEDemandElement *stopParent, bool friendlyPosition)
build stop
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNEAttributeCarrier::TagProperties & getCurrentTagProperties() const
get current type tag
HelpCreation * myHelpCreation
Help creation.
Definition: GNEStopFrame.h:114
GNEFrameAttributesModuls::NeteditAttributes * myNeteditAttributes
Netedit parameter.
Definition: GNEStopFrame.h:111
bool addStop(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, bool shiftPressed)
add Stop element
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
std::string chargingStation
(Optional) charging station if one is assigned to the stop
std::string containerstop
(Optional) container stop if one is assigned to the stop
void hideDemandElementSelector()
hide demand element selector
~GNEStopFrame()
Destructor.
GNEFrameModuls::TagSelector * myStopTagSelector
stop tag selector selector (used to select diffent kind of Stops)
Definition: GNEStopFrame.h:105
SUMOTime duration
The stopping duration.
bool parking
whether the vehicle is removed from the net while stopping
std::set< std::string > awaitedContainers
IDs of containers the vehicle has to wait for until departing.