Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2023 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
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
54
55 // create person plan attributes
57
58 // Create Netedit parameter
60
61 // create GNEPathCreator Module
62 myPathCreator = new GNEPathCreator(this);
63
64 // create legend label
66
67 // limit path creator to pedestrians
69}
70
71
75
76
77void
93
94
95void
97 // reset candidate edges
98 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
99 edge.second->resetCandidateFlags();
100 }
101 // hide frame
103}
104
105
106bool
108 // first check that we clicked over an AC
109 if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
110 return false;
111 }
112 // obtain tags (only for improve code legibility)
114 SumoXMLTag clickedACTag = objectsUnderCursor.getAttributeCarrierFront()->getTagProperty().getTag();
115 // first check that current selected person is valid
116 if (personTag == SUMO_TAG_NOTHING) {
117 myViewNet->setStatusBarText(TL("Current selected person isn't valid."));
118 return false;
119 }
120 // now check that pType is valid
121 if (myTypeSelector->getCurrentDemandElement() == nullptr) {
122 myViewNet->setStatusBarText(TL("Current selected person type isn't valid."));
123 return false;
124 }
125 // finally check that person plan selected is valid
127 myViewNet->setStatusBarText(TL("Current selected person plan isn't valid."));
128 return false;
129 }
130 // add elements to path creator
131 if (clickedACTag == SUMO_TAG_LANE) {
132 return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
133 } else if ((clickedACTag == SUMO_TAG_BUS_STOP) || (clickedACTag == SUMO_TAG_TRAIN_STOP)) {
134 return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
135 } else if (clickedACTag == SUMO_TAG_ROUTE) {
136 return myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
137 } else if (clickedACTag == SUMO_TAG_JUNCTION) {
138 return myPathCreator->addJunction(objectsUnderCursor.getJunctionFront());
139 } else {
140 return false;
141 }
142}
143
144
149
150
155
156// ===========================================================================
157// protected
158// ===========================================================================
159
160void
162 // first check if person is valid
164 // show PType selector and person plan selector
166 // check if current person type selected is valid
168 // show person attributes depending of myPersonPlanTagSelector
171 } else {
173 }
174 // show person plan tag selector
176 // now check if person plan selected is valid
178 // show person plan attributes
180 // show Netedit attributes modul
182 // show path creator depending of tag
186 } else {
187 // update VClass of myPathCreator depending if person is a ride
190 } else {
192 }
193 // show edge path creator modul
195 // show path legend
197 }
198 } else {
199 // hide modules
204 }
205 } else {
206 // hide modules
213 }
214 } else {
215 // hide all moduls if person isn't valid
223 }
224}
225
226
227void
230 // show person attributes depending of myPersonPlanTagSelector
233 } else {
235 }
236 // show person plan tag selector
238 // now check if person plan selected is valid
240 // update VClass of myPathCreator depending if person is a ride
243 } else {
245 }
246 // show person plan attributes
248 // show Netedit attributes modul
250 // show edge path creator modul
252 // show legend
254 // show warning if we have selected a vType oriented to containers or vehicles
256 WRITE_WARNING(TL("VType with vClass == 'ignoring' is oriented to containers"));
258 WRITE_WARNING(TL("VType with vClass != 'pedestrian' is not oriented to persons"));
259 }
260 } else {
261 // hide modules
265 }
266 } else {
267 // hide modules
273 }
274}
275
276
277bool
278GNEPersonFrame::createPath(const bool /*useLastRoute*/) {
279 // first check that all attributes are valid
281 myViewNet->setStatusBarText(TL("Invalid person parameters."));
282 } else if (!myPersonPlanAttributes->areValuesValid()) {
284 } else {
285 // begin undo-redo operation
289 // create person
290 GNEDemandElement* person = buildPerson();
291 // check if person and person plan can be created
294 person, myPersonPlanAttributes, myPathCreator, true)) {
295 // end undo-redo operation
297 // abort path creation
299 // refresh person and personPlan attributes
302 // compute person
303 person->computePathElement();
304 // enable show all person plans
306 return true;
307 } else {
308 // abort person creation
310 }
311 }
312 return false;
313}
314
315// ---------------------------------------------------------------------------
316// GNEPersonFrame - private methods
317// ---------------------------------------------------------------------------
318
321 // first person base object
323 // obtain person tag (only for improve code legibility)
325 // set tag
326 myPersonBaseObject->setTag(personTag);
327 // get attribute ad values
329 // Check if ID has to be generated
332 }
333 // add pType parameter
335 // check if we're creating a person or personFlow
336 if (personTag == SUMO_TAG_PERSON) {
337 // Add parameter departure
340 }
341 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
343 // obtain person parameters
344 SUMOVehicleParameter* personParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_PERSON, SUMOSAXAttrs, false, false, false);
345 // check personParameters
346 if (personParameters) {
347 myPersonBaseObject->setVehicleParameter(personParameters);
348 // parse vehicle
350 // delete personParameters
351 delete personParameters;
352 }
353 } else {
354 // set begin and end attributes
357 }
358 // adjust poisson value
361 }
362 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
364 // obtain personFlow parameters
365 SUMOVehicleParameter* personFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_PERSONFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
366 // check personParameters
367 if (personFlowParameters) {
368 myPersonBaseObject->setVehicleParameter(personFlowParameters);
369 // parse vehicle
371 // delete personParameters
372 delete personFlowParameters;
373 }
374 }
375 // refresh person and personPlan attributes
378 // return created person
380}
381
382
383/****************************************************************************/
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
#define TL(string)
Definition MsgHandler.h:287
#define SUMOTime_MAX
Definition SUMOTime.h:34
@ 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_TRAIN_STOP
A train stop (alias for bus stop)
@ 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
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: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:120
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
bool addJunction(GNEJunction *junction)
add junction
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
void hidePathLegendModule()
hide Legend modul
void showPathLegendModule()
show Legend modul
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
GNEPathLegendModule * myPathLegend
path legend modul
DemandElementSelector * getTypeSelector() const
get Type selectors
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
void setStatusBarText(const std::string &text)
set statusBar text
A single child window which contains a view of the simulation area.
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 * 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