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-2022 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  myRouteHandler("", viewNet->getNet(), true),
42  myPersonBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
43 
44  // create tag Selector modul for persons
45  myPersonTagSelector = new GNEFrameModules::TagSelector(this, GNETagProperties::TagType::PERSON, SUMO_TAG_PERSON);
46 
47  // create person types selector modul and set DEFAULT_PEDTYPE_ID as default element
49 
50  // create person attributes
52 
53  // create tag Selector modul for person plans
54  myPersonPlanTagSelector = new GNEFrameModules::TagSelector(this, GNETagProperties::TagType::PERSONPLAN, GNE_TAG_PERSONTRIP_EDGE);
55 
56  // create person plan attributes
58 
59  // Create Netedit parameter
61 
62  // create PathCreator Module
64 
65  // limit path creator to pedestrians
67 }
68 
69 
71  delete myPersonBaseObject;
72 }
73 
74 
75 void
77  // refresh tag selector
81  // update VClass of myPathCreator
85  } else {
87  }
88  // show frame
90 }
91 
92 
93 void
95  // reset candidate edges
96  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
97  edge.second->resetCandidateFlags();
98  }
99  // hide frame
100  GNEFrame::hide();
101 }
102 
103 
104 bool
106  // first check that we clicked over an AC
107  if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
108  return false;
109  }
110  // obtain tags (only for improve code legibility)
112  SumoXMLTag clickedACTag = objectsUnderCursor.getAttributeCarrierFront()->getTagProperty().getTag();
113  // first check that current selected person is valid
114  if (personTag == SUMO_TAG_NOTHING) {
115  myViewNet->setStatusBarText("Current selected person isn't valid.");
116  return false;
117  }
118  // now check that pType is valid
119  if (myTypeSelector->getCurrentDemandElement() == nullptr) {
120  myViewNet->setStatusBarText("Current selected person type isn't valid.");
121  return false;
122  }
123  // finally check that person plan selected is valid
125  myViewNet->setStatusBarText("Current selected person plan isn't valid.");
126  return false;
127  }
128  // add elements to path creator
129  if (clickedACTag == SUMO_TAG_LANE) {
130  const bool result = myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
131  // if we're creating a stop, create it immediately
133  createPath();
134  }
135  return result;
136  } else if (clickedACTag == SUMO_TAG_BUS_STOP) {
137  const bool result = myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
138  // if we're creating a stop, create it immediately
140  createPath();
141  }
142  return result;
143  } else if (clickedACTag == SUMO_TAG_ROUTE) {
144  const bool result = myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
145  // if we're creating a walk route, create it immediately
147  createPath();
149  }
150  return result;
151  } else if (clickedACTag == SUMO_TAG_JUNCTION) {
152  return myPathCreator->addJunction(objectsUnderCursor.getJunctionFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
153  } else {
154  return false;
155  }
156 }
157 
158 
161  return myPathCreator;
162 }
163 
164 // ===========================================================================
165 // protected
166 // ===========================================================================
167 
168 void
170  // first check if person is valid
172  // show PType selector and person plan selector
174  // check if current person type selected is valid
176  // show person attributes depending of myPersonPlanTagSelector
179  } else {
181  }
182  // show person plan tag selector
184  // now check if person plan selected is valid
186  // show person plan attributes
188  // show Netedit attributes modul
190  // show path creator depending of tag
194  } else {
195  // update VClass of myPathCreator depending if person is a ride
198  } else {
200  }
201  // show edge path creator modul
203  }
204  } else {
205  // hide modules
209  }
210  } else {
211  // hide modules
217  }
218  } else {
219  // hide all moduls if person isn't valid
226  }
227 }
228 
229 
230 void
233  // show person attributes depending of myPersonPlanTagSelector
236  } else {
238  }
239  // show person plan tag selector
241  // now check if person plan selected is valid
243  // update VClass of myPathCreator depending if person is a ride
246  } else {
248  }
249  // show person plan attributes
251  // show Netedit attributes modul
253  // show edge path creator modul
255  // show warning if we have selected a vType oriented to containers or vehicles
257  WRITE_WARNING("Current selected vType is oriented to containers");
259  WRITE_WARNING("Current selected vType is oriented to vehicles");
260  }
261  } else {
262  // hide modules
266  }
267  } else {
268  // hide modules
274  }
275 }
276 
277 
278 void
280  // first check that all attributes are valid
282  myViewNet->setStatusBarText("Invalid person parameters.");
283  } else if (!myPersonPlanAttributes->areValuesValid()) {
285  } else {
286  // begin undo-redo operation
290  // create person
291  GNEDemandElement* person = buildPerson();
292  // check if person and person plan can be created
295  person, myPersonPlanAttributes, myPathCreator, true)) {
296  // end undo-redo operation
297  myViewNet->getUndoList()->end();
298  // abort path creation
300  // refresh person and personPlan attributes
303  // compute person
304  person->computePathElement();
305  // enable show all person plans
307  } else {
308  // abort person creation
310  }
311  }
312 }
313 
314 // ---------------------------------------------------------------------------
315 // GNEPersonFrame - private methods
316 // ---------------------------------------------------------------------------
317 
320  // first person base object
322  // obtain person tag (only for improve code legibility)
324  // set tag
325  myPersonBaseObject->setTag(personTag);
326  // get attribute ad values
328  // Check if ID has to be generated
331  }
332  // add pType parameter
334  // check if we're creating a person or personFlow
335  if (personTag == SUMO_TAG_PERSON) {
336  // Add parameter departure
339  }
340  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
342  // obtain person parameters
343  SUMOVehicleParameter* personParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_PERSON, SUMOSAXAttrs, false, false, false);
344  // check personParameters
345  if (personParameters) {
346  myPersonBaseObject->setVehicleParameter(personParameters);
347  // parse vehicle
349  // delete personParameters
350  delete personParameters;
351  }
352  } else {
353  // set begin and end attributes
356  }
359  }
360  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
362  // obtain personFlow parameters
363  SUMOVehicleParameter* personFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_PERSONFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
364  // check personParameters
365  if (personFlowParameters) {
366  myPersonBaseObject->setVehicleParameter(personFlowParameters);
367  // parse vehicle
369  // delete personParameters
370  delete personFlowParameters;
371  }
372  }
373  // refresh person and personPlan attributes
376  // return created person
378 }
379 
380 
381 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
#define SUMOTime_MAX
Definition: SUMOTime.h:33
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
const std::string DEFAULT_PEDTYPE_ID
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_JUNCTION
begin/end of the description of a junction
@ 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
@ GNE_TAG_PERSONTRIP_EDGE
@ GNE_TAG_WALK_ROUTE
@ 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:46
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
std::map< std::string, std::string > getAllAttributes() const
get all attributes in string format
void setTag(const SumoXMLTag tag)
set SumoBaseObject tag
void setVehicleParameter(const SUMOVehicleParameter *vehicleParameter)
set vehicle parameters
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
void clear()
clear SumoBaseObject
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
An Element which don't belongs to GNENet but has influency in the simulation.
virtual SUMOVehicleClass getVClass() const =0
virtual void computePathElement()=0
compute pathElement
const std::string & getID() const
get ID
bool areValuesValid() const
check if parameters of attributes are valid
void refreshAttributesCreator()
refresh attribute creator
void showAttributesCreatorModule(GNEAttributeCarrier *templateAC, const std::vector< SumoXMLAttr > &hiddenAttributes)
show AttributesCreator modul
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
void hideNeteditAttributesModule()
hide Netedit attributes modul
void showNeteditAttributesModule(const GNETagProperties &tagValue)
show Netedit attributes modul
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:114
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
void showDemandElementSelector()
show demand element selector
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void refreshDemandElementSelector()
refresh demand element selector
void hideDemandElementSelector()
hide demand element selector
void setVClass(SUMOVehicleClass vClass)
set vClass
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
void abortPathCreation()
abort path creation
void hidePathCreatorModule()
show PathCreator
bool addRoute(GNEDemandElement *route, const bool shiftKeyPressed, const bool controlKeyPressed)
add route
bool addJunction(GNEJunction *junction, const bool shiftKeyPressed, const bool controlKeyPressed)
add junction
bool addStoppingPlace(GNEAdditional *stoppingPlace, const bool shiftKeyPressed, const bool controlKeyPressed)
add stoppingPlace
void showPathCreatorModule(SumoXMLTag element, const bool firstElement, const bool consecutives)
show PathCreator for the given tag
void hideTagSelector()
hide item selector
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void showTagSelector()
show item selector
std::string generateDemandElementID(SumoXMLTag tag) const
generate demand element id
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
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:125
GNEFrameModules::PathCreator * myPathCreator
edge path creator (used for Walks, rides and trips)
GNEPersonFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
GNEFrameModules::TagSelector * myPersonPlanTagSelector
person plan selector (used to select diffent kind of person plan)
~GNEPersonFrame()
Destructor.
bool addPerson(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add vehicle element
void show()
show Frame
GNEFrameAttributeModules::AttributesCreator * myPersonPlanAttributes
internal person plan attributes
GNEFrameAttributeModules::AttributesCreator * myPersonAttributes
internal vehicle attributes
void demandElementSelected()
selected demand element in DemandElementSelector
void tagSelected()
Tag selected in TagSelector.
GNEDemandElement * buildPerson()
build person and return it (note: function includes a call to begin(...), but NOT a call to end(....
CommonXMLStructure::SumoBaseObject * myPersonBaseObject
person base object
GNERouteHandler myRouteHandler
route handler
void hide()
hide Frame
GNEFrameModules::PathCreator * getPathCreator() const
get PathCreator modul
void createPath()
create path
GNEFrameModules::TagSelector * myPersonTagSelector
person tag selector (used to select diffent kind of persons)
GNEFrameModules::DemandElementSelector * myTypeSelector
Person Type selectors.
GNEFrameAttributeModules::NeteditAttributes * myNeteditAttributes
Netedit parameter.
bool buildPersonPlan(SumoXMLTag tag, GNEDemandElement *personParent, GNEFrameAttributeModules::AttributesCreator *personPlanAttributes, GNEFrameModules::PathCreator *pathCreator, const bool centerAfterCreation)
build person plan
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool isRide() const
return true if tag correspond to a ride element
bool isStopPerson() const
return true if tag correspond to a person stop element
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void abortAllChangeGroups()
reverts and discards ALL active chained change 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
GNEJunction * getJunctionFront() const
get front junction 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
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:531
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:629
void setChecked(bool val)
check or uncheck this MFXCheckableButton
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
Encapsulated Xerces-SAX-attributes.
Structure representing possible vehicle parameter.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault)
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.
MFXCheckableButton * menuCheckShowAllPersonPlans
show all person plans
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