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.dev/sumo
3 // Copyright (C) 2001-2024 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 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
28 
29 #include "GNEPersonFrame.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 // ---------------------------------------------------------------------------
36 // GNEPersonFrame - methods
37 // ---------------------------------------------------------------------------
38 
40  GNEFrame(viewParent, viewNet, TL("Persons")),
41  myRouteHandler("", viewNet->getNet(), true, false),
42  myPersonBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
43 
44  // create tag Selector module for persons
45  myPersonTagSelector = new GNETagSelector(this, GNETagProperties::TagType::PERSON, SUMO_TAG_PERSON);
46 
47  // create person types selector module and set DEFAULT_PEDTYPE_ID as default element
48  myTypeSelector = new GNEDemandElementSelector(this, SUMO_TAG_VTYPE, GNETagProperties::TagType::PERSON);
49 
50  // create person attributes
52 
53  // create plan selector module for person plans
55 
56  // create person plan attributes
58 
59  // Create Netedit parameter
61 
62  // create GNEPlanCreator Module
63  myPlanCreator = new GNEPlanCreator(this);
64 
65  // create plan creator legend
67 }
68 
69 
71  delete myPersonBaseObject;
72 }
73 
74 
75 void
77  // refresh tag selector
81  // show frame
83 }
84 
85 
86 void
88  // reset candidate edges
89  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
90  edge.second->resetCandidateFlags();
91  }
92  // hide frame
94 }
95 
96 
97 bool
99  // first check that we clicked over an AC
100  if (viewObjects.getAttributeCarrierFront() == nullptr) {
101  return false;
102  }
103  // obtain tags (only for improve code legibility)
105  // first check that current selected person is valid
106  if (personTag == SUMO_TAG_NOTHING) {
107  myViewNet->setStatusBarText(TL("Current selected person isn't valid."));
108  return false;
109  }
110  // now check that pType is valid
111  if (myTypeSelector->getCurrentDemandElement() == nullptr) {
112  myViewNet->setStatusBarText(TL("Current selected person type isn't valid."));
113  return false;
114  }
115  // finally check that person plan selected is valid
116  if (myPlanSelector->getCurrentPlanTemplate() == nullptr) {
117  myViewNet->setStatusBarText(TL("Current selected person plan isn't valid."));
118  return false;
119  }
120  for (GNEAdditional* o : viewObjects.getAdditionals()) {
121  if (o->getTagProperty().isStoppingPlace()) {
122  return myPlanCreator->addStoppingPlace(o);
123  }
124  }
125  for (GNEDemandElement* o : viewObjects.getDemandElements()) {
126  if (o->getTagProperty().getTag() == SUMO_TAG_ROUTE) {
127  return myPlanCreator->addRoute(o);
128  }
129  }
130  if (!viewObjects.getJunctions().empty()) {
131  return myPlanCreator->addJunction(viewObjects.getJunctions().front());
132  }
133  if (!viewObjects.getLanes().empty()) {
134  return myPlanCreator->addEdge(viewObjects.getLanes().front());
135  }
136  if (!viewObjects.getTAZs().empty()) {
137  return myPlanCreator->addTAZ(viewObjects.getTAZs().front());
138  }
139  return false;
140 }
141 
142 
145  return myPlanCreator;
146 }
147 
148 
151  return myTypeSelector;
152 }
153 
154 
157  return myPlanSelector;
158 }
159 
160 
163  return myPersonAttributes;
164 }
165 
166 // ===========================================================================
167 // protected
168 // ===========================================================================
169 
170 void
172  // first check if person is valid
174  // show PType selector and person plan selector
176  // check if current person type selected is valid
178  // show person attributes depending of myPlanSelector
181  } else {
183  }
184  // show person plan tag selector
186  // check current plan template
188  // show person plan attributes
190  // show Netedit attributes module
192  // show edge path creator module
194  // show path legend
196  } else {
197  // hide modules
202  }
203  } else {
204  // hide modules
211  }
212  } else {
213  // hide all modules if person isn't valid
221  }
222 }
223 
224 
225 void
228  // show person attributes depending of myPlanSelector
231  } else {
233  }
234  // show person plan tag selector
236  // now check if person plan selected is valid
238  // show person plan attributes
240  // show Netedit attributes module
242  // show edge path creator module
244  // show legend
246  } else {
247  // hide modules
251  }
252  } else {
253  // hide modules
259  }
260 }
261 
262 
263 bool
264 GNEPersonFrame::createPath(const bool /*useLastRoute*/) {
265  // first check that all attributes are valid
267  myViewNet->setStatusBarText(TL("Invalid person parameters."));
268  } else if (!myPersonPlanAttributes->areValuesValid()) {
271  // begin undo-redo operation
275  // create person
276  GNEDemandElement* person = buildPerson();
277  // check if person and person plan can be created
279  person, myPersonPlanAttributes, myPlanCreator, true)) {
280  // end undo-redo operation
281  myViewNet->getUndoList()->end();
282  // abort path creation
284  // refresh person and personPlan attributes
287  // compute person
288  person->computePathElement();
289  // enable show all person plans
291  return true;
292  } else {
293  // abort person creation
295  }
296  }
297  return false;
298 }
299 
300 // ---------------------------------------------------------------------------
301 // GNEPersonFrame - private methods
302 // ---------------------------------------------------------------------------
303 
306  // first person base object
308  // obtain person tag (only for improve code legibility)
310  // set tag
311  myPersonBaseObject->setTag(personTag);
312  // get attribute ad values
314  // Check if ID has to be generated
317  }
318  // add pType parameter
320  // check if we're creating a person or personFlow
321  if (personTag == SUMO_TAG_PERSON) {
322  // Add parameter departure
325  }
326  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
328  // obtain person parameters
329  SUMOVehicleParameter* personParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_PERSON, SUMOSAXAttrs, false, false, false);
330  // check personParameters
331  if (personParameters) {
332  myPersonBaseObject->setVehicleParameter(personParameters);
333  // parse vehicle
335  // delete personParameters
336  delete personParameters;
337  }
338  } else {
339  // set begin and end attributes
342  }
343  // adjust poisson value
346  }
347  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
349  // obtain personFlow parameters
350  SUMOVehicleParameter* personFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_PERSONFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
351  // check personParameters
352  if (personFlowParameters) {
353  myPersonBaseObject->setVehicleParameter(personFlowParameters);
354  // parse vehicle
356  // delete personParameters
357  delete personFlowParameters;
358  }
359  }
360  // refresh person and personPlan attributes
363  // return created person
365 }
366 
367 
368 /****************************************************************************/
#define TL(string)
Definition: MsgHandler.h:315
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define SUMOTime_MAX
Definition: SUMOTime.h:34
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_PERSON
@ SUMO_TAG_PERSONFLOW
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_POISSON
poisson definition (used in flow)
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
SUMOTime getTimeAttribute(const SumoXMLAttr attr) const
get time attribute
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
bool hasTimeAttribute(const SumoXMLAttr attr) const
check if current SumoBaseObject has the given time attribute
void setVehicleParameter(const SUMOVehicleParameter *vehicleParameter)
set vehicle parameters
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
const std::string getID() const
get ID (all Attribute Carriers have one)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
bool areValuesValid() const
check if parameters of attributes are valid
void showAttributesCreatorModule(GNEAttributeCarrier *templateAC, const std::vector< SumoXMLAttr > &hiddenAttributes)
show GNEAttributesCreator modul
void hideAttributesCreatorModule()
hide group box
void refreshAttributesCreator()
refresh attribute creator
virtual void computePathElement()=0
compute pathElement
void showDemandElementSelector()
show demand element selector
void refreshDemandElementSelector()
refresh demand element selector
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void hideDemandElementSelector()
hide demand element selector
GNEViewNet * myViewNet
FOX need this.
Definition: GNEFrame.h:117
virtual void show()
show Frame
Definition: GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:124
const std::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition: GNEFrame.cpp:311
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:123
void showNeteditAttributesModule(GNEAttributeCarrier *templateAC)
show Netedit attributes modul
void hideNeteditAttributesModule()
hide Netedit attributes modul
GNENeteditAttributes * myNeteditAttributes
Netedit parameter.
GNEPlanCreator * myPlanCreator
plan creator
GNEPlanSelector * myPlanSelector
personPlan selector
GNEDemandElementSelector * myTypeSelector
Person Type selectors.
~GNEPersonFrame()
Destructor.
GNEDemandElementSelector * getTypeSelector() const
get Type selectors
GNEPersonFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void show()
show Frame
void demandElementSelected()
selected demand element in DemandElementSelector
GNEPlanCreator * getPlanCreator() const
get plan creator module
void tagSelected()
Tag selected in GNETagSelector.
GNEDemandElement * buildPerson()
build person and return it (note: function includes a call to begin(...), but NOT a call to end(....
GNEPlanSelector * getPlanSelector() const
get personPlan selector
CommonXMLStructure::SumoBaseObject * myPersonBaseObject
person base object
GNERouteHandler myRouteHandler
route handler
void hide()
hide Frame
GNEPlanCreatorLegend * myPlanCreatorLegend
plan creator legend
bool createPath(const bool useLastRoute)
create path
bool addPerson(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
add vehicle element
GNEAttributesCreator * myPersonAttributes
internal vehicle attributes
GNEAttributesCreator * myPersonPlanAttributes
internal person plan attributes
GNEAttributesCreator * getPersonAttributes() const
get attributes creator
GNETagSelector * myPersonTagSelector
person tag selector (used to select diffent kind of persons)
bool addStoppingPlace(GNEAdditional *stoppingPlace)
add from to stoppingPlace
bool addRoute(GNEDemandElement *route)
add route
bool planCanBeCreated(const GNEDemandElement *planTemplate) const
check if plan can be created
void hidePathCreatorModule()
show GNEPlanCreator
bool addTAZ(GNEAdditional *taz)
add TAZ
bool addJunction(GNEJunction *junction)
add junction
bool addEdge(GNELane *lane)
add edge (clicking over lanes)
void abortPathCreation()
abort path creation
void showPlanCreatorModule(const GNEPlanSelector *planSelector, const GNEDemandElement *previousPlan)
show plan creator for the given tag property
void showPlanCreatorLegend()
show plan creator legend
void hidePlanCreatorLegend()
hide Legend modul
GNEDemandElement * getCurrentPlanTemplate() const
get current plan template
void showPlanSelector()
show plan selector
const GNETagProperties & getCurrentPlanTagProperties() const
get current plan tag properties
void hidePlanSelector()
plan item selector
void refreshPlanSelector()
refresh plan selector (used when frameParent is show)
bool buildPersonPlan(const GNEDemandElement *planTemplate, GNEDemandElement *personParent, GNEAttributesCreator *personPlanAttributes, GNEPlanCreator *planCreator, 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...
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool isPlanStopPerson() const
return true if tag correspond to a person stop plan
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
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
const std::vector< GNETAZ * > & getTAZs() const
get vector with TAZs
GNEAttributeCarrier * getAttributeCarrierFront() const
get front attribute carrier or a pointer to nullptr
const std::vector< GNEDemandElement * > & getDemandElements() const
get vector with Demand Elements
const std::vector< GNEJunction * > & getJunctions() const
get vector with junctions
const std::vector< GNELane * > & getLanes() const
get lanes
const std::vector< GNEAdditional * > & getAdditionals() const
get vector with additionals
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:741
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:827
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:88
void setChecked(bool val, const bool inform=false)
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 * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false, const bool allowInternalRoutes=false)
Parses a vehicle's attributes.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault, const bool allowInternalRoutes=false)
Parses a flow's attributes.
MFXCheckableButton * menuCheckShowAllPersonPlans
show all person plans