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>
25 
26 #include "GNEPersonPlanFrame.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 
33 // ---------------------------------------------------------------------------
34 // GNEPersonPlanFrame - methods
35 // ---------------------------------------------------------------------------
36 
37 GNEPersonPlanFrame::GNEPersonPlanFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
38  GNEFrame(horizontalFrameParent, viewNet, "PersonPlans"),
39  myRouteHandler("", viewNet->getNet(), true) {
40 
41  // create person types selector modul
42  myPersonSelector = new GNEFrameModules::DemandElementSelector(this, {GNETagProperties::TagType::PERSON});
43 
44  // Create tag selector for person plan
45  myPersonPlanTagSelector = new GNEFrameModules::TagSelector(this, GNETagProperties::TagType::PERSONPLAN, GNE_TAG_PERSONTRIP_EDGE);
46 
47  // Create person parameters
49 
50  // create myPathCreator Module
52 
53  // Create HierarchicalElementTree modul
55 }
56 
57 
59 
60 
61 void
63  // get persons maps
64  const auto& persons = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_PERSON);
65  const auto& personFlows = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_PERSONFLOW);
66  // Only show moduls if there is at least one person
67  if ((persons.size() > 0) || (personFlows.size() > 0)) {
68  // show person selector
70  // refresh tag selector
72  // set first person as demand element (this will call demandElementSelected() function)
73  if (persons.size() > 0) {
74  myPersonSelector->setDemandElement(*persons.begin());
75  } else {
76  myPersonSelector->setDemandElement(*personFlows.begin());
77  }
78  } else {
79  // hide all moduls except helpCreation
85  }
86  // show frame
88 }
89 
90 
91 void
93  // reset candidate edges
94  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
95  edge.second->resetCandidateFlags();
96  }
97  // hide frame
99 }
100 
101 
102 bool
104  // first check if person selected is valid
105  if (myPersonSelector->getCurrentDemandElement() == nullptr) {
106  myViewNet->setStatusBarText("Current selected person isn't valid.");
107  return false;
108  }
109  // finally check that person plan selected is valid
110  if (myPersonPlanTagSelector->getCurrentTemplateAC() == nullptr) {
111  myViewNet->setStatusBarText("Current selected person plan isn't valid.");
112  return false;
113  }
114  // Obtain current person plan tag (only for improve code legibility)
116  // declare flags for requirements
117  const bool requireBusStop = ((personPlanTag == GNE_TAG_PERSONTRIP_BUSSTOP) || (personPlanTag == GNE_TAG_WALK_BUSSTOP) ||
118  (personPlanTag == GNE_TAG_RIDE_BUSSTOP) || (personPlanTag == GNE_TAG_STOPPERSON_BUSSTOP));
119  const bool requireEdge = ((personPlanTag == GNE_TAG_PERSONTRIP_EDGE) || (personPlanTag == GNE_TAG_WALK_EDGE) ||
120  (personPlanTag == GNE_TAG_RIDE_EDGE) || (personPlanTag == GNE_TAG_WALK_EDGES));
121  // continue depending of tag
122  if ((personPlanTag == GNE_TAG_WALK_ROUTE) && objectsUnderCursor.getDemandElementFront() && (objectsUnderCursor.getDemandElementFront()->getTagProperty().getTag() == SUMO_TAG_ROUTE)) {
123  if (myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed())) {
124  createPath();
126  return true;
127  } else {
128  return false;
129  }
130  } else if (requireBusStop && objectsUnderCursor.getAdditionalFront() && (objectsUnderCursor.getAdditionalFront()->getTagProperty().getTag() == SUMO_TAG_BUS_STOP)) {
131  return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
132  } else if (requireEdge && objectsUnderCursor.getEdgeFront()) {
133  return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
134  } else {
135  return false;
136  }
137 }
138 
139 
142  return myPathCreator;
143 }
144 
145 // ===========================================================================
146 // protected
147 // ===========================================================================
148 
149 void
151  // first check if person is valid
153  // Obtain current person plan tag (only for improve code legibility)
155  // show person attributes
157  // get previous person plan
159  // show path creator depending of tag
162  } else {
163  // update VClass of myPathCreator depending if person is a ride
166  } else {
168  }
169  // set path creator mode depending if previousEdge exist
170  if (previousEdge) {
171  // set path creator mode
172  myPathCreator->showPathCreatorModule(personPlanTag, true, false);
173  // add previous edge
174  myPathCreator->addEdge(previousEdge, false, false);
175  } else {
176  // set path creator mode
177  myPathCreator->showPathCreatorModule(personPlanTag, false, false);
178  }
179  }
180  // show person hierarchy
182  } else {
183  // hide moduls if tag selecte isn't valid
187  }
188 }
189 
190 
191 void
193  // check if a valid person was selected
195  // show person plan tag selector
197  // now check if person plan selected is valid
199  // call tag selected
200  tagSelected();
201  } else {
205  }
206  } else {
207  // hide moduls if person selected isn't valid
212  }
213 }
214 
215 
216 void
218  // first check that all attributes are valid
221  } else {
222  // check if person plan can be created
227  // refresh HierarchicalElementTree
229  // abort path creation
231  // refresh using tagSelected
232  tagSelected();
233  // refresh personPlan attributes
235  }
236  }
237 }
238 
239 /****************************************************************************/
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ 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
@ SUMO_TAG_PERSON
@ GNE_TAG_WALK_EDGE
@ GNE_TAG_PERSONTRIP_EDGE
@ GNE_TAG_RIDE_BUSSTOP
@ GNE_TAG_WALK_ROUTE
@ SUMO_TAG_PERSONFLOW
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
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
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
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
void showDemandElementSelector()
show demand element selector
GNEDemandElement * getCurrentDemandElement() const
get current demand element
GNEEdge * getPersonPlanPreviousEdge() const
get previous edge for the current person plan
void hideDemandElementSelector()
hide demand element selector
void hideHierarchicalElementTree()
hide HierarchicalElementTree
void refreshHierarchicalElementTree()
refresh HierarchicalElementTree
void showHierarchicalElementTree(GNEAttributeCarrier *AC)
show HierarchicalElementTree
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 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
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:125
GNEFrameModules::TagSelector * myPersonPlanTagSelector
personPlan selector
bool addPersonPlanElement(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add person plan element
GNEFrameModules::HierarchicalElementTree * myPersonHierarchy
Person Hierarchy.
GNEFrameModules::DemandElementSelector * myPersonSelector
Person selectors.
~GNEPersonPlanFrame()
Destructor.
GNERouteHandler myRouteHandler
route handler
void show()
show Frame
void createPath()
create path
GNEFrameAttributeModules::AttributesCreator * myPersonPlanAttributes
internal vehicle attributes
GNEFrameModules::PathCreator * myPathCreator
Path Creator.
void tagSelected()
Tag selected in TagSelector.
GNEPersonPlanFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
void demandElementSelected()
selected demand element in DemandElementSelector
GNEFrameModules::PathCreator * getPathCreator() const
get path creator modul
void hide()
hide Frame
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...
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool isRide() const
return true if tag correspond to a ride element
class used to group all variables related with objects under cursor after a click over view
GNEAdditional * getAdditionalFront() const
get front additional element 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
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:629
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