Eclipse SUMO - Simulation of Urban MObility
GNEContainerPlanFrame.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 ContainerPlan elements
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
25 #include <netedit/GNEViewParent.h>
27 
28 #include "GNEContainerPlanFrame.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 // ---------------------------------------------------------------------------
36 // GNEContainerPlanFrame - methods
37 // ---------------------------------------------------------------------------
38 
40  GNEFrame(viewParent, viewNet, "ContainerPlans"),
41  myRouteHandler("", viewNet->getNet(), true, false) {
42 
43  // create container types selector modul
44  myContainerSelector = new DemandElementSelector(this, {GNETagProperties::TagType::CONTAINER});
45 
46  // Create tag selector for container plan
47  myContainerPlanTagSelector = new GNETagSelector(this, GNETagProperties::TagType::CONTAINERPLAN, GNE_TAG_TRANSPORT_EDGE);
48 
49  // Create container parameters
51 
52  // create myPathCreator Module
53  myPathCreator = new GNEPathCreator(this);
54 
55  // Create GNEElementTree modul
57 }
58 
59 
61 
62 
63 void
65  // get containers maps
66  const auto& containers = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_CONTAINER);
67  const auto& containerFlows = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_CONTAINERFLOW);
68  // Only show moduls if there is at least one container
69  if ((containers.size() > 0) || (containerFlows.size() > 0)) {
70  // show container selector
72  // refresh tag selector
74  // set first container as demand element (this will call demandElementSelected() function)
75  if (containers.size() > 0) {
76  myContainerSelector->setDemandElement(*containers.begin());
77  } else {
78  myContainerSelector->setDemandElement(*containerFlows.begin());
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  // enable undo/redo
101  // hide frame
102  GNEFrame::hide();
103 }
104 
105 
106 bool
108  // first check if container selected is valid
109  if (myContainerSelector->getCurrentDemandElement() == nullptr) {
110  myViewNet->setStatusBarText("Current selected container isn't valid.");
111  return false;
112  }
113  // finally check that container plan selected is valid
115  myViewNet->setStatusBarText("Current selected container plan isn't valid.");
116  return false;
117  }
118  // Obtain current container plan tag (only for improve code legibility)
120  // declare flags for requirements
121  const bool requireContainerStop = ((containerPlanTag == GNE_TAG_TRANSPORT_CONTAINERSTOP) || (containerPlanTag == GNE_TAG_TRANSHIP_CONTAINERSTOP) ||
122  (containerPlanTag == GNE_TAG_STOPCONTAINER_CONTAINERSTOP));
123  const bool requireEdge = ((containerPlanTag == GNE_TAG_TRANSPORT_EDGE) || (containerPlanTag == GNE_TAG_TRANSHIP_EDGE) ||
124  (containerPlanTag == GNE_TAG_TRANSHIP_EDGES) || (containerPlanTag == GNE_TAG_STOPCONTAINER_EDGE));
125  // continue depending of tag
126  if (requireContainerStop && objectsUnderCursor.getAdditionalFront() && (objectsUnderCursor.getAdditionalFront()->getTagProperty().getTag() == SUMO_TAG_CONTAINER_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 container is valid
149  // Obtain current container plan tag (only for improve code legibility)
151  // show container attributes
153  // get previous container plan
155  // set path creator mode depending if previousEdge exist
156  if (previousEdge) {
157  // set path creator mode
158  myPathCreator->showPathCreatorModule(containerPlanTag, true, false);
159  // check if add previous edge
161  myPathCreator->addEdge(previousEdge, false, false);
162  }
163  } else {
164  // set path creator mode
165  myPathCreator->showPathCreatorModule(containerPlanTag, false, false);
166  }
167  // show container hierarchy
169  } else {
170  // hide moduls if tag selecte isn't valid
174  }
175 }
176 
177 
178 void
180  // check if a valid container was selected
182  // show container plan tag selector
184  // now check if container plan selected is valid
186  // call tag selected
187  tagSelected();
188  } else {
192  }
193  } else {
194  // hide moduls if container selected isn't valid
199  }
200 }
201 
202 
203 bool
204 GNEContainerPlanFrame::createPath(const bool /*useLastRoute*/) {
205  // first check that all attributes are valid
208  } else {
209  // check if container plan can be created
214  myPathCreator, true)) {
215  // refresh GNEElementTree
217  // abort path creation
219  // refresh using tagSelected
220  tagSelected();
221  // refresh containerPlan attributes
223  // enable show all person plans
225  return true;
226  }
227  }
228  return false;
229 }
230 
231 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_TRANSPORT_CONTAINERSTOP
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_CONTAINERFLOW
@ GNE_TAG_STOPCONTAINER_EDGE
@ GNE_TAG_TRANSHIP_EDGES
@ GNE_TAG_STOPCONTAINER_CONTAINERSTOP
@ SUMO_TAG_CONTAINER
@ GNE_TAG_TRANSHIP_EDGE
@ GNE_TAG_TRANSHIP_CONTAINERSTOP
@ GNE_TAG_TRANSPORT_EDGE
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
GNEEdge * getContainerPlanPreviousEdge() const
get previous edge for the current container plan
void showDemandElementSelector()
show demand element selector
void hideDemandElementSelector()
hide demand element selector
void enableUndoRedo()
disable undo-redo
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
GNEElementTree * myContainerHierarchy
Container Hierarchy.
GNERouteHandler myRouteHandler
route handler
GNEAttributesCreator * myContainerPlanAttributes
internal vehicle attributes
DemandElementSelector * myContainerSelector
Container selectors.
GNEContainerPlanFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
GNEPathCreator * myPathCreator
Path Creator.
GNETagSelector * myContainerPlanTagSelector
containerPlan selector
GNEPathCreator * getPathCreator() const
get path creator modul
bool addContainerPlanElement(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add container plan element
void demandElementSelected()
selected demand element in DemandElementSelector
void tagSelected()
Tag selected in GNETagSelector.
bool createPath(const bool useLastRoute)
create path
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
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
void abortPathCreation()
abort path creation
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
void hidePathCreatorModule()
show GNEPathCreator
void showPathCreatorModule(SumoXMLTag element, const bool firstElement, const bool consecutives)
show GNEPathCreator for the given tag
bool buildContainerPlan(SumoXMLTag tag, GNEDemandElement *containerParent, GNEAttributesCreator *containerPlanAttributes, GNEPathCreator *pathCreator, const bool centerAfterCreation)
build container 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 isStopContainer() const
return true if tag correspond to a container 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
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
GNEEdge * getEdgeFront() const
get front edge or a pointer to nullptr
GNENet * getNet() const
get the net object
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