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-2020 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 
40  // create person types selector modul
41  myPersonSelector = new GNEFrameModuls::DemandElementSelector(this, {GNETagProperties::TagType::PERSON});
42 
43  // Create tag selector for person plan
44  myPersonPlanTagSelector = new GNEFrameModuls::TagSelector(this, GNETagProperties::TagType::PERSONPLAN);
45 
46  // Create person parameters
48 
49  // create myPathCreator Modul
51 
52  // Create HierarchicalElementTree modul
54 
55  // set PersonPlan tag type in tag selector
56  myPersonPlanTagSelector->setCurrentTagType(GNETagProperties::TagType::PERSONPLAN);
57 }
58 
59 
61 
62 
63 void
65  // get persons maps
66  const std::map<std::string, GNEDemandElement*>& persons = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_PERSON);
67  const std::map<std::string, GNEDemandElement*>& personFlows = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_PERSONFLOW);
68  // Only show moduls if there is at least one person
69  if ((persons.size() > 0) || (personFlows.size() > 0)) {
70  // show person selector
72  // refresh person plan tag selector
74  // set first person as demand element (this will call demandElementSelected() function)
75  if (persons.size() > 0) {
76  myPersonSelector->setDemandElement(persons.begin()->second);
77  } else {
78  myPersonSelector->setDemandElement(personFlows.begin()->second);
79  }
80  } else {
81  // hide all moduls except helpCreation
87  }
88  // show frame
90 }
91 
92 
93 void
95  // reset candidate edges
96  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
97  edge.second->resetCandidateFlags();
98  }
99  // hide frame
100  GNEFrame::hide();
101 }
102 
103 
104 bool
106  // first check if person selected is valid
107  if (myPersonSelector->getCurrentDemandElement() == nullptr) {
108  myViewNet->setStatusBarText("Current selected person isn't valid.");
109  return false;
110  }
111  // finally check that person plan selected is valid
113  myViewNet->setStatusBarText("Current selected person plan isn't valid.");
114  return false;
115  }
116  // Obtain current person plan tag (only for improve code legibility)
118  // declare flags for requierements
119  const bool requireBusStop = ((personPlanTag == GNE_TAG_PERSONTRIP_EDGE_BUSSTOP) || (personPlanTag == GNE_TAG_WALK_EDGE_BUSSTOP) ||
120  (personPlanTag == GNE_TAG_RIDE_EDGE_BUSSTOP) || (personPlanTag == GNE_TAG_PERSONSTOP_BUSSTOP));
121  const bool requireEdge = ((personPlanTag == GNE_TAG_PERSONTRIP_EDGE_EDGE) || (personPlanTag == GNE_TAG_WALK_EDGES) ||
122  (personPlanTag == GNE_TAG_WALK_EDGE_EDGE) || (personPlanTag == GNE_TAG_RIDE_EDGE_EDGE));
123  // continue depending of tag
124  if ((personPlanTag == GNE_TAG_WALK_ROUTE) && objectsUnderCursor.getDemandElementFront() && (objectsUnderCursor.getDemandElementFront()->getTagProperty().getTag() == SUMO_TAG_ROUTE)) {
125  return myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
126  } else if (requireBusStop && objectsUnderCursor.getAdditionalFront() && (objectsUnderCursor.getAdditionalFront()->getTagProperty().getTag() == SUMO_TAG_BUS_STOP)) {
127  return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
128  } else if (requireEdge && objectsUnderCursor.getEdgeFront()) {
129  return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
130  } else {
131  return false;
132  }
133 }
134 
135 
138  return myPathCreator;
139 }
140 
141 // ===========================================================================
142 // protected
143 // ===========================================================================
144 
145 void
147  // first check if person is valid
149  // Obtain current person plan tag (only for improve code legibility)
151  // show person attributes
153  // get previous person plan
155  // set path creator mode depending if previousEdge exist
156  if (previousEdge) {
157  // set path creator mode
158  myPathCreator->showPathCreatorModul(personPlanTag, true, false);
159  // add previous edge
160  myPathCreator->addEdge(previousEdge, false, false);
161  } else {
162  // set path creator mode
163  myPathCreator->showPathCreatorModul(personPlanTag, false, false);
164  }
165  // show person hierarchy
167  } else {
168  // hide moduls if tag selecte isn't valid
172  }
173 }
174 
175 
176 void
178  // check if a valid person was selected
180  // show person plan tag selector
182  // now check if person plan selected is valid
184  // call tag selected
185  tagSelected();
186  } else {
190  }
191  } else {
192  // hide moduls if person selected isn't valid
197  }
198 }
199 
200 
201 void
203  // first check that all attributes are valid
206  } else {
207  // check if person plan can be created
212  myPathCreator)) {
213  // refresh HierarchicalElementTree
215  // abort path creation
217  // refresh using tagSelected
218  tagSelected();
219  // refresh personPlan attributes
221  }
222  }
223 }
224 
225 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_PERSONTRIP_EDGE_EDGE
@ GNE_TAG_PERSONSTOP_BUSSTOP
@ SUMO_TAG_NOTHING
invalid tag
@ GNE_TAG_WALK_EDGES
@ SUMO_TAG_BUS_STOP
A bus stop.
@ GNE_TAG_RIDE_EDGE_EDGE
@ GNE_TAG_WALK_EDGE_EDGE
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ GNE_TAG_PERSONTRIP_EDGE_BUSSTOP
@ GNE_TAG_RIDE_EDGE_BUSSTOP
@ SUMO_TAG_PERSON
@ GNE_TAG_WALK_EDGE_BUSSTOP
@ GNE_TAG_WALK_ROUTE
@ SUMO_TAG_PERSONFLOW
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:49
void refreshRows()
refresh rows (called after creating an element)
void showAttributesCreatorModul(const GNETagProperties &tagProperties, const std::vector< SumoXMLAttr > &hiddenAttributes)
show AttributesCreator modul
bool areValuesValid() const
check if parameters of attributes are valid
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:113
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
GNEEdge * getPersonPlanPreviousEdge() const
get previous edge for the current selected demand elemnt
void showDemandElementSelector()
show demand element selector
void hideDemandElementSelector()
hide demand element selector
void refreshHierarchicalElementTree()
refresh HierarchicalElementTree
void showHierarchicalElementTree(GNEAttributeCarrier *AC)
show HierarchicalElementTree
void hideHierarchicalElementTree()
hide HierarchicalElementTree
bool addRoute(GNEDemandElement *route, const bool shiftKeyPressed, const bool controlKeyPressed)
add route
void abortPathCreation()
abort path creation
void showPathCreatorModul(SumoXMLTag tag, const bool firstElement, const bool consecutives)
show PathCreator for the given tag
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
bool addStoppingPlace(GNEAdditional *stoppingPlace, const bool shiftKeyPressed, const bool controlKeyPressed)
add stoppingPlace
void hidePathCreatorModul()
show PathCreator
void hideTagSelector()
hide item selector
void setCurrentTagType(GNETagProperties::TagType tagType)
set current type manually
void refreshTagProperties()
due myCurrentTagProperties is a Reference, we need to refresh it when frameParent is show
const GNETagProperties & getCurrentTagProperties() const
get current type tag
void showTagSelector()
show item selector
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
const std::map< SumoXMLTag, std::map< std::string, GNEDemandElement * > > & getDemandElements() const
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
bool addPersonPlanElement(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add person plan element
GNEFrameModuls::PathCreator * myPathCreator
Path Creator.
GNEFrameModuls::PathCreator * getPathCreator() const
get path creator modul
~GNEPersonPlanFrame()
Destructor.
GNEFrameAttributesModuls::AttributesCreator * myPersonPlanAttributes
internal vehicle attributes
void show()
show Frame
void createPath()
create path
GNEFrameModuls::DemandElementSelector * myPersonSelector
Person selectors.
GNEFrameModuls::TagSelector * myPersonPlanTagSelector
personPlan selector
void tagSelected()
Tag selected in TagSelector.
GNEFrameModuls::HierarchicalElementTree * myPersonHierarchy
Person Hierarchy.
GNEPersonPlanFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
void demandElementSelected()
selected demand element in DemandElementSelector
void hide()
hide Frame
static bool buildPersonPlan(SumoXMLTag tag, GNEDemandElement *personParent, GNEFrameAttributesModuls::AttributesCreator *personPlanAttributes, GNEFrameModuls::PathCreator *pathCreator)
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
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:575
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