Eclipse SUMO - Simulation of Urban MObility
GNEPersonPlanFrame.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 PersonPlan elements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
26
27#include "GNEPersonPlanFrame.h"
28
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
34// ---------------------------------------------------------------------------
35// GNEPersonPlanFrame - methods
36// ---------------------------------------------------------------------------
37
39 GNEFrame(viewParent, viewNet, "PersonPlans"),
40 myRouteHandler("", viewNet->getNet(), true, false) {
41
42 // create person types selector modul
43 myPersonSelector = new DemandElementSelector(this, {GNETagProperties::TagType::PERSON});
44
45 // Create tag selector for person plan
46 myPersonPlanTagSelector = new GNETagSelector(this, GNETagProperties::TagType::PERSONPLAN, GNE_TAG_PERSONTRIP_EDGE);
47
48 // Create person parameters
50
51 // create myPathCreator Module
52 myPathCreator = new GNEPathCreator(this);
53
54 // Create GNEElementTree modul
56}
57
58
60
61
62void
64 // get persons maps
66 const auto& personFlows = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_PERSONFLOW);
67 // Only show moduls if there is at least one person
68 if ((persons.size() > 0) || (personFlows.size() > 0)) {
69 // show person selector
71 // refresh tag selector
73 // set first person as demand element (this will call demandElementSelected() function)
75 GNEDemandElement* personFound = nullptr;
76 // search person
77 for (const auto& person : persons) {
78 if (myViewNet->getFrontAttributeCarrier()->getID() == person->getID()) {
79 personFound = person;
80 }
81 }
82 // search personFlow
83 for (const auto& personFlow : personFlows) {
84 if (myViewNet->getFrontAttributeCarrier()->getID() == personFlow->getID()) {
85 personFound = personFlow;
86 }
87 }
88 // check personFound
89 if (personFound) {
91 }
92 } else {
94 }
95 } else {
96 // hide all moduls except helpCreation
102 }
103 // show frame
105}
106
107
108void
110 // reset candidate edges
111 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
112 edge.second->resetCandidateFlags();
113 }
114 // enable undo/redo
116 // hide frame
118}
119
120
121bool
123 // check if we have to select a new person
124 if (myPersonSelector->getCurrentDemandElement() == nullptr) {
125 if (objectsUnderCursor.getDemandElementFront() && objectsUnderCursor.getDemandElementFront()->getTagProperty().isPerson()) {
126 // continue depending of number of demand elements under cursor
127 if (objectsUnderCursor.getClickedDemandElements().size() > 1) {
128 // Filter persons
130 } else {
131 // select new person
133 }
134 return true;
135 } else {
136 myViewNet->setStatusBarText("Current selected person isn't valid.");
137 return false;
138 }
139 }
140 // finally check that person plan selected is valid
142 myViewNet->setStatusBarText("Current selected person plan isn't valid.");
143 return false;
144 }
145 // Obtain current person plan tag (only for improve code legibility)
147 // declare flags for requirements
148 const bool requireBusStop = ((personPlanTag == GNE_TAG_PERSONTRIP_BUSSTOP) || (personPlanTag == GNE_TAG_WALK_BUSSTOP) ||
149 (personPlanTag == GNE_TAG_RIDE_BUSSTOP) || (personPlanTag == GNE_TAG_STOPPERSON_BUSSTOP));
150 const bool requireEdge = ((personPlanTag == GNE_TAG_PERSONTRIP_EDGE) || (personPlanTag == GNE_TAG_WALK_EDGE) ||
151 (personPlanTag == GNE_TAG_RIDE_EDGE) || (personPlanTag == GNE_TAG_WALK_EDGES) ||
152 (personPlanTag == GNE_TAG_STOPPERSON_EDGE));
153 const bool requireJunction = ((personPlanTag == GNE_TAG_PERSONTRIP_JUNCTIONS) || (personPlanTag == GNE_TAG_WALK_JUNCTIONS));
154 // continue depending of tag
155 if ((personPlanTag == GNE_TAG_WALK_ROUTE) && objectsUnderCursor.getDemandElementFront() && (objectsUnderCursor.getDemandElementFront()->getTagProperty().getTag() == SUMO_TAG_ROUTE)) {
156 return myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
157 } else if (requireBusStop && objectsUnderCursor.getAdditionalFront() && (objectsUnderCursor.getAdditionalFront()->getTagProperty().getTag() == SUMO_TAG_BUS_STOP)) {
158 return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
159 } else if (requireEdge && objectsUnderCursor.getEdgeFront()) {
160 return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
161 } else if (requireJunction && objectsUnderCursor.getJunctionFront()) {
162 return myPathCreator->addJunction(objectsUnderCursor.getJunctionFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
163 } else {
164 return false;
165 }
166}
167
168
169void
172}
173
174
177 return myPathCreator;
178}
179
180
183 return myPersonHierarchy;
184}
185
186// ===========================================================================
187// protected
188// ===========================================================================
189
190void
192 // first check if person is valid
194 // Obtain current person plan tag (only for improve code legibility)
196 // show person attributes
198 // get previous person plan
200 // update VClass of myPathCreator depending if person is a ride
203 } else {
205 }
206 // set path creator mode depending if previousEdge exist
207 if (previousEdge) {
208 // set path creator mode
209 myPathCreator->showPathCreatorModule(personPlanTag, true, false);
210 // add previous edge or junction
212 myPathCreator->addJunction(previousEdge->getToJunction(), false, false);
214 myPathCreator->addEdge(previousEdge, false, false);
215 }
216 } else {
217 // set path creator mode
218 myPathCreator->showPathCreatorModule(personPlanTag, false, false);
219 }
220 // show person hierarchy
222 } else {
223 // hide moduls if tag selecte isn't valid
227 }
228}
229
230
231void
233 // check if a valid person was selected
235 // show person plan tag selector
237 // now check if person plan selected is valid
239 // call tag selected
240 tagSelected();
241 } else {
245 }
246 } else {
247 // hide moduls if person selected isn't valid
252 }
253}
254
255
256bool
257GNEPersonPlanFrame::createPath(const bool /*useLastRoute*/) {
258 // first check that all attributes are valid
261 return false;
262 } else {
263 // check if person plan can be created
268 // refresh GNEElementTree
270 // abort path creation
272 // refresh using tagSelected
273 tagSelected();
274 // refresh personPlan attributes
276 // enable show all person plans
278 return true;
279 } else {
280 return false;
281 }
282 }
283}
284
285/****************************************************************************/
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_PERSONTRIP_JUNCTIONS
@ GNE_TAG_PERSONTRIP_BUSSTOP
@ GNE_TAG_WALK_EDGES
@ SUMO_TAG_BUS_STOP
A bus stop.
@ GNE_TAG_STOPPERSON_BUSSTOP
@ GNE_TAG_WALK_BUSSTOP
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ GNE_TAG_RIDE_EDGE
@ GNE_TAG_WALK_JUNCTIONS
@ SUMO_TAG_PERSON
@ GNE_TAG_WALK_EDGE
@ GNE_TAG_PERSONTRIP_EDGE
@ GNE_TAG_RIDE_BUSSTOP
@ GNE_TAG_STOPPERSON_EDGE
@ GNE_TAG_WALK_ROUTE
@ SUMO_TAG_PERSONFLOW
@ SUMO_ATTR_FROMJUNCTION
GNEDemandElement * getCurrentDemandElement() const
get current demand element
GNEEdge * getPersonPlanPreviousEdge() const
get previous edge for the current person plan
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
void showDemandElementSelector()
show demand element selector
void setDemandElements(const std::vector< GNEDemandElement * > &demandElements)
set multiple demand elements to filter
void hideDemandElementSelector()
hide demand element selector
void enableUndoRedo()
disable undo-redo
const std::string getID() const
get ID (all Attribute Carriers have one)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
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.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
Definition: GNEEdge.h:82
void hideHierarchicalElementTree()
hide GNEElementTree
void refreshHierarchicalElementTree()
refresh GNEElementTree
void showHierarchicalElementTree(GNEAttributeCarrier *AC)
show GNEElementTree
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::map< SumoXMLTag, std::set< GNEDemandElement * > > & getDemandElements() const
get demand elements
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
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
GNEElementTree * getPersonHierarchy() const
get Person Hierarchy
GNETagSelector * myPersonPlanTagSelector
personPlan selector
bool addPersonPlanElement(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add person plan element
bool createPath(const bool useLastRoute)
create path
GNEElementTree * myPersonHierarchy
Person Hierarchy.
~GNEPersonPlanFrame()
Destructor.
GNERouteHandler myRouteHandler
route handler
GNEPersonPlanFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void show()
show Frame
void tagSelected()
Tag selected in GNETagSelector.
GNEPathCreator * myPathCreator
Path Creator.
GNEPathCreator * getPathCreator() const
get path creator module
void demandElementSelected()
selected demand element in DemandElementSelector
GNEAttributesCreator * myPersonPlanAttributes
internal vehicle attributes
void resetSelectedPerson()
reset selected person
DemandElementSelector * myPersonSelector
Person selectors.
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...
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
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
bool isPerson() const
return true if tag correspond to a person 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
class used to group all variables related with objects under cursor after a click over view
const std::vector< GNEDemandElement * > & getClickedDemandElements() const
get vector with clicked Demand Elements
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
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
GNEViewParent * getViewParent() const
get the net 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
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
void setChecked(bool val)
check or uncheck this MFXCheckableButton
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