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>
27
28#include "GNEPersonFrame.h"
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
34// ---------------------------------------------------------------------------
35// GNEPersonFrame - methods
36// ---------------------------------------------------------------------------
37
39 GNEFrame(viewParent, viewNet, "Persons"),
40 myRouteHandler("", viewNet->getNet(), true, false),
41 myPersonBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
42
43 // create tag Selector modul for persons
44 myPersonTagSelector = new GNETagSelector(this, GNETagProperties::TagType::PERSON, SUMO_TAG_PERSON);
45
46 // create person types selector modul and set DEFAULT_PEDTYPE_ID as default element
48
49 // create person attributes
51
52 // create tag Selector modul for person plans
53 myPersonPlanTagSelector = new GNETagSelector(this, GNETagProperties::TagType::PERSONPLAN, GNE_TAG_PERSONTRIP_EDGE);
54
55 // create person plan attributes
57
58 // Create Netedit parameter
60
61 // create GNEPathCreator Module
62 myPathCreator = new GNEPathCreator(this);
63
64 // limit path creator to pedestrians
66}
67
68
70 delete myPersonBaseObject;
71}
72
73
74void
76 // refresh tag selector
80 // update VClass of myPathCreator
84 } else {
86 }
87 // show frame
89}
90
91
92void
94 // reset candidate edges
95 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
96 edge.second->resetCandidateFlags();
97 }
98 // hide frame
100}
101
102
103bool
105 // first check that we clicked over an AC
106 if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
107 return false;
108 }
109 // obtain tags (only for improve code legibility)
111 SumoXMLTag clickedACTag = objectsUnderCursor.getAttributeCarrierFront()->getTagProperty().getTag();
112 // first check that current selected person is valid
113 if (personTag == SUMO_TAG_NOTHING) {
114 myViewNet->setStatusBarText("Current selected person isn't valid.");
115 return false;
116 }
117 // now check that pType is valid
118 if (myTypeSelector->getCurrentDemandElement() == nullptr) {
119 myViewNet->setStatusBarText("Current selected person type isn't valid.");
120 return false;
121 }
122 // finally check that person plan selected is valid
124 myViewNet->setStatusBarText("Current selected person plan isn't valid.");
125 return false;
126 }
127 // add elements to path creator
128 if (clickedACTag == SUMO_TAG_LANE) {
129 return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
130 } else if (clickedACTag == SUMO_TAG_BUS_STOP) {
131 return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
132 } else if (clickedACTag == SUMO_TAG_ROUTE) {
133 return myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
134 } else if (clickedACTag == SUMO_TAG_JUNCTION) {
135 return myPathCreator->addJunction(objectsUnderCursor.getJunctionFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
136 } else {
137 return false;
138 }
139}
140
141
144 return myPathCreator;
145}
146
147// ===========================================================================
148// protected
149// ===========================================================================
150
151void
153 // first check if person is valid
155 // show PType selector and person plan selector
157 // check if current person type selected is valid
159 // show person attributes depending of myPersonPlanTagSelector
162 } else {
164 }
165 // show person plan tag selector
167 // now check if person plan selected is valid
169 // show person plan attributes
171 // show Netedit attributes modul
173 // show path creator depending of tag
177 } else {
178 // update VClass of myPathCreator depending if person is a ride
181 } else {
183 }
184 // show edge path creator modul
186 }
187 } else {
188 // hide modules
192 }
193 } else {
194 // hide modules
200 }
201 } else {
202 // hide all moduls if person isn't valid
209 }
210}
211
212
213void
216 // show person attributes depending of myPersonPlanTagSelector
219 } else {
221 }
222 // show person plan tag selector
224 // now check if person plan selected is valid
226 // update VClass of myPathCreator depending if person is a ride
229 } else {
231 }
232 // show person plan attributes
234 // show Netedit attributes modul
236 // show edge path creator modul
238 // show warning if we have selected a vType oriented to containers or vehicles
240 WRITE_WARNING(TL("VType with vClass == 'ignoring' is oriented to containers"));
242 WRITE_WARNING(TL("VType with vClass != 'pedestrian' is not oriented to persons"));
243 }
244 } else {
245 // hide modules
249 }
250 } else {
251 // hide modules
257 }
258}
259
260
261bool
262GNEPersonFrame::createPath(const bool /*useLastRoute*/) {
263 // first check that all attributes are valid
265 myViewNet->setStatusBarText("Invalid person parameters.");
266 } else if (!myPersonPlanAttributes->areValuesValid()) {
268 } else {
269 // begin undo-redo operation
273 // create person
274 GNEDemandElement* person = buildPerson();
275 // check if person and person plan can be created
278 person, myPersonPlanAttributes, myPathCreator, true)) {
279 // end undo-redo operation
281 // abort path creation
283 // refresh person and personPlan attributes
286 // compute person
287 person->computePathElement();
288 // enable show all person plans
290 return true;
291 } else {
292 // abort person creation
294 }
295 }
296 return false;
297}
298
299// ---------------------------------------------------------------------------
300// GNEPersonFrame - private methods
301// ---------------------------------------------------------------------------
302
305 // first person base object
307 // obtain person tag (only for improve code legibility)
309 // set tag
310 myPersonBaseObject->setTag(personTag);
311 // get attribute ad values
313 // Check if ID has to be generated
316 }
317 // add pType parameter
319 // check if we're creating a person or personFlow
320 if (personTag == SUMO_TAG_PERSON) {
321 // Add parameter departure
324 }
325 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
327 // obtain person parameters
328 SUMOVehicleParameter* personParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_PERSON, SUMOSAXAttrs, false, false, false);
329 // check personParameters
330 if (personParameters) {
331 myPersonBaseObject->setVehicleParameter(personParameters);
332 // parse vehicle
334 // delete personParameters
335 delete personParameters;
336 }
337 } else {
338 // set begin and end attributes
341 }
342 // adjust poisson value
345 }
346 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
348 // obtain personFlow parameters
349 SUMOVehicleParameter* personFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_PERSONFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
350 // check personParameters
351 if (personFlowParameters) {
352 myPersonBaseObject->setVehicleParameter(personFlowParameters);
353 // parse vehicle
355 // delete personParameters
356 delete personFlowParameters;
357 }
358 }
359 // refresh person and personPlan attributes
362 // return created person
364}
365
366
367/****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
#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
@ 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
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 hasDoubleAttribute(const SumoXMLAttr attr) const
check if current SumoBaseObject has the given double attribute
void setVehicleParameter(const SUMOVehicleParameter *vehicleParameter)
set vehicle parameters
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
double getDoubleAttribute(const SumoXMLAttr attr) const
get double attribute
void clear()
clear SumoBaseObject
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void refreshDemandElementSelector()
refresh demand element selector
void showDemandElementSelector()
show demand element selector
void hideDemandElementSelector()
hide demand element selector
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
An Element which don't belong to GNENet but has influence in the simulation.
virtual SUMOVehicleClass getVClass() const =0
virtual void computePathElement()=0
compute pathElement
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:310
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:132
void showNeteditAttributesModule(GNEAttributeCarrier *templateAC)
show Netedit attributes modul
void hideNeteditAttributesModule()
hide Netedit attributes modul
bool addStoppingPlace(GNEAdditional *stoppingPlace, const bool shiftKeyPressed, const bool controlKeyPressed)
add stoppingPlace
bool addRoute(GNEDemandElement *route, const bool shiftKeyPressed, const bool controlKeyPressed)
add route
void abortPathCreation()
abort path creation
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
void setVClass(SUMOVehicleClass vClass)
set vClass
void hidePathCreatorModule()
show GNEPathCreator
void showPathCreatorModule(SumoXMLTag element, const bool firstElement, const bool consecutives)
show GNEPathCreator for the given tag
bool addJunction(GNEJunction *junction, const bool shiftKeyPressed, const bool controlKeyPressed)
add junction
GNENeteditAttributes * myNeteditAttributes
Netedit parameter.
GNETagSelector * 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
DemandElementSelector * myTypeSelector
Person Type selectors.
GNEPersonFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void show()
show Frame
void demandElementSelected()
selected demand element in DemandElementSelector
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(....
CommonXMLStructure::SumoBaseObject * myPersonBaseObject
person base object
GNERouteHandler myRouteHandler
route handler
GNEPathCreator * myPathCreator
edge path creator (used for Walks, rides and trips)
void hide()
hide Frame
bool createPath(const bool useLastRoute)
create path
GNEAttributesCreator * myPersonAttributes
internal vehicle attributes
GNEAttributesCreator * myPersonPlanAttributes
internal person plan attributes
GNEPathCreator * getPathCreator() const
get GNEPathCreator module
GNETagSelector * myPersonTagSelector
person tag selector (used to select diffent kind of persons)
bool buildPersonPlan(SumoXMLTag tag, GNEDemandElement *personParent, GNEAttributesCreator *personPlanAttributes, GNEPathCreator *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 refreshTagSelector()
refresh tagSelector (used when frameParent is show)
void showTagSelector()
show item selector
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void hideTagSelector()
hide item selector
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:650
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:768
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:84
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