Eclipse SUMO - Simulation of Urban MObility
GNEPersonFrame.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 Person elements
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
28 
29 #include "GNEPersonFrame.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 // ---------------------------------------------------------------------------
36 // GNEPersonFrame - methods
37 // ---------------------------------------------------------------------------
38 
39 GNEPersonFrame::GNEPersonFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
40  GNEFrame(horizontalFrameParent, viewNet, "Persons") {
41 
42  // create tag Selector modul for persons
43  myPersonTagSelector = new GNEFrameModuls::TagSelector(this, GNETagProperties::TagType::PERSON);
44 
45  // create person types selector modul
47 
48  // create person attributes
50 
51  // create tag Selector modul for person plans
52  myPersonPlanTagSelector = new GNEFrameModuls::TagSelector(this, GNETagProperties::TagType::PERSONPLAN);
53 
54  // create person plan attributes
56 
57  // Create Netedit parameter
59 
60  // create PathCreator Modul
62 
63  // limit path creator to pedestrians
65 
66  // set Person as default vehicle
68 }
69 
70 
72 
73 
74 void
76  // refresh item selector
80  // update VClass of myPathCreator
83  } else {
85  }
86  // show frame
88 }
89 
90 
91 void
93  // reset candidate edges
94  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
95  edge.second->resetCandidateFlags();
96  }
97  // hide frame
99 }
100 
101 
102 bool
104  // first check that we clicked over an AC
105  if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
106  return false;
107  }
108  // obtain tags (only for improve code legibility)
110  SumoXMLTag clickedACTag = objectsUnderCursor.getAttributeCarrierFront()->getTagProperty().getTag();
111  // first check that current selected person is valid
112  if (personTag == SUMO_TAG_NOTHING) {
113  myViewNet->setStatusBarText("Current selected person isn't valid.");
114  return false;
115  }
116  // now check that pType is valid
117  if (myPTypeSelector->getCurrentDemandElement() == nullptr) {
118  myViewNet->setStatusBarText("Current selected person type isn't valid.");
119  return false;
120  }
121  // finally check that person plan selected is valid
123  myViewNet->setStatusBarText("Current selected person plan isn't valid.");
124  return false;
125  }
126  // add elements to path creator
127  if (clickedACTag == SUMO_TAG_LANE) {
128  return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
129  } else if (clickedACTag == SUMO_TAG_BUS_STOP) {
130  return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
131  } else if (clickedACTag == SUMO_TAG_ROUTE) {
132  return myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
133  } else {
134  return false;
135  }
136 }
137 
138 
141  return myPathCreator;
142 }
143 
144 // ===========================================================================
145 // protected
146 // ===========================================================================
147 
148 void
150  // first check if person is valid
152  // show PType selector and person plan selector
154  // check if current person type selected is valid
156  // show person attributes depending of myPersonPlanTagSelector
159  } else {
161  }
162  // show person plan tag selector
164  // now check if person plan selected is valid
166  // update VClass of myPathCreator depending if person is a ride
169  } else {
171  }
172  // show person plan attributes
174  // show Netedit attributes modul
176  // show edge path creator modul
178  } else {
179  // hide modules
183  }
184  } else {
185  // hide modules
191  }
192  } else {
193  // hide all moduls if person isn't valid
200  }
201 }
202 
203 
204 void
207  // show person attributes depending of myPersonPlanTagSelector
210  } else {
212  }
213  // show person plan tag selector
215  // now check if person plan selected is valid
217  // update VClass of myPathCreator depending if person is a ride
220  } else {
222  }
223  // show person plan attributes
225  // show Netedit attributes modul
227  // show edge path creator modul
229  } else {
230  // hide modules
234  }
235  } else {
236  // hide modules
242  }
243 }
244 
245 
246 void
248  // first check that all attributes are valid
250  myViewNet->setStatusBarText("Invalid person parameters.");
251  } else if (!myPersonPlanAttributes->areValuesValid()) {
253  } else {
254  // begin undo-redo operation
256  // check if person and person plan can be created
260  // end undo-redo operation
262  // abort path creation
264  // refresh person and personPlan attributes
267  } else {
268  // abort person creation
270  }
271  }
272 }
273 
274 // ---------------------------------------------------------------------------
275 // GNEPersonFrame - private methods
276 // ---------------------------------------------------------------------------
277 
280  // obtain person tag (only for improve code legibility)
282  // Declare map to keep attributes from myPersonAttributes
283  std::map<SumoXMLAttr, std::string> valuesMap = myPersonAttributes->getAttributesAndValues(false);
284  // Check if ID has to be generated
285  if (valuesMap.count(SUMO_ATTR_ID) == 0) {
286  valuesMap[SUMO_ATTR_ID] = myViewNet->getNet()->generateDemandElementID(personTag);
287  }
288  // add pType parameter
290  // check if we're creating a person or personFlow
291  if (personTag == SUMO_TAG_PERSON) {
292  // Add parameter departure
293  if (valuesMap[SUMO_ATTR_DEPART].empty()) {
294  valuesMap[SUMO_ATTR_DEPART] = "0";
295  }
296  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
297  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, getPredefinedTagsMML(), toString(personTag));
298  // obtain person parameters
299  SUMOVehicleParameter* personParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_PERSON, SUMOSAXAttrs, false, false, false);
300  // build person in GNERouteHandler
301  GNERouteHandler::buildPerson(myViewNet->getNet(), true, *personParameters);
302  // delete personParameters
303  delete personParameters;
304  } else {
305  // set begin and end attributes
306  if (valuesMap[SUMO_ATTR_BEGIN].empty()) {
307  valuesMap[SUMO_ATTR_BEGIN] = "0";
308  }
309  if (valuesMap[SUMO_ATTR_END].empty()) {
310  valuesMap[SUMO_ATTR_END] = "3600";
311  }
312  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
313  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, getPredefinedTagsMML(), toString(personTag));
314  // obtain personFlow parameters
315  SUMOVehicleParameter* personFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_PERSONFLOW, SUMOSAXAttrs, false, 0, SUMOTime_MAX, true);
316  // build personFlow in GNERouteHandler
317  GNERouteHandler::buildPersonFlow(myViewNet->getNet(), true, *personFlowParameters);
318  // delete personFlowParameters
319  delete personFlowParameters;
320  }
321  // refresh person and personPlan attributes
324  // return created person
325  return myViewNet->getNet()->retrieveDemandElement(personTag, valuesMap[SUMO_ATTR_ID]);
326 }
327 
328 
329 /****************************************************************************/
#define SUMOTime_MAX
Definition: SUMOTime.h:32
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_PERSON
@ SUMO_TAG_PTYPE
description of a person type (used in NETEDIT)
@ SUMO_TAG_PERSONFLOW
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
An Element which don't belongs to GNENet but has influency in the simulation.
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 showNeteditAttributesModul(const GNETagProperties &tagValue)
show Netedit attributes modul
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
const std::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition: GNEFrame.cpp:269
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void showDemandElementSelector()
show demand element selector
void hideDemandElementSelector()
hide demand element selector
void refreshDemandElementSelector()
refresh demand element selector
bool addRoute(GNEDemandElement *route, const bool shiftKeyPressed, const bool controlKeyPressed)
add route
void abortPathCreation()
abort path creation
void showPathCreatorModul(SumoXMLTag tag, const bool firstElement, const bool consecutives)
show PathCreator for the given tag
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
void setVClass(SUMOVehicleClass vClass)
set vClass
bool addStoppingPlace(GNEAdditional *stoppingPlace, const bool shiftKeyPressed, const bool controlKeyPressed)
add stoppingPlace
void hidePathCreatorModul()
show PathCreator
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
void setCurrentTag(SumoXMLTag newTag)
set current type manually
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
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
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
Definition: GNENet.cpp:2435
GNEPersonFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
GNEFrameModuls::PathCreator * myPathCreator
edge path creator (used for Walks, rides and trips)
GNEFrameAttributesModuls::AttributesCreator * myPersonPlanAttributes
internal person plan attributes
~GNEPersonFrame()
Destructor.
bool addPerson(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add vehicle element
GNEFrameModuls::DemandElementSelector * myPTypeSelector
Person Type selectors.
void show()
show Frame
void demandElementSelected()
selected demand element in DemandElementSelector
GNEFrameModuls::TagSelector * myPersonTagSelector
person tag selector (used to select diffent kind of persons)
void tagSelected()
Tag selected in TagSelector.
GNEDemandElement * buildPerson()
build person and return it (note: function includes a call to p_begin(...), but NOT a call to p_end(....
GNEFrameModuls::TagSelector * myPersonPlanTagSelector
person plan selector (used to select diffent kind of person plan)
void hide()
hide Frame
GNEFrameAttributesModuls::NeteditAttributes * myNeteditAttributes
Netedit parameter.
void createPath()
create path
GNEFrameModuls::PathCreator * getPathCreator() const
get PathCreator modul
GNEFrameAttributesModuls::AttributesCreator * myPersonAttributes
internal vehicle attributes
static void buildPerson(GNENet *net, bool undoDemandElements, const SUMOVehicleParameter &personParameters)
static void buildPersonFlow(GNENet *net, bool undoDemandElements, const SUMOVehicleParameter &personFlowParameters)
build person flow
static bool buildPersonPlan(SumoXMLTag tag, GNEDemandElement *personParent, GNEFrameAttributesModuls::AttributesCreator *personPlanAttributes, GNEFrameModuls::PathCreator *pathCreator)
bool isPersonStop() const
return true if tag correspond to a person stop element
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool isRide() const
return true if tag correspond to a ride element
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
void p_abort()
reverts and discards ALL active command groups
class used to group all variables related with objects under cursor after a click over view
GNEAttributeCarrier * getAttributeCarrierFront() const
get front attribute carrier 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
GNEEdge * getEdgeFront() const
get front edge or a pointer to nullptr
GNENet * getNet() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:575
Encapsulated Xerces-SAX-attributes.
Structure representing possible vehicle parameter.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const SUMOTime beginDefault, const SUMOTime endDefault, bool isPerson=false)
Parses a flow's attributes.
static SUMOVehicleParameter * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false)
Parses a vehicle's attributes.
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