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 
26 #include "GNEContainerPlanFrame.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 
33 // ---------------------------------------------------------------------------
34 // GNEContainerPlanFrame - methods
35 // ---------------------------------------------------------------------------
36 
37 GNEContainerPlanFrame::GNEContainerPlanFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
38  GNEFrame(horizontalFrameParent, viewNet, "ContainerPlans"),
39  myRouteHandler("", viewNet->getNet(), true) {
40 
41  // create container types selector modul
42  myContainerSelector = new GNEFrameModules::DemandElementSelector(this, {GNETagProperties::TagType::CONTAINER});
43 
44  // Create tag selector for container plan
45  myContainerPlanTagSelector = new GNEFrameModules::TagSelector(this, GNETagProperties::TagType::CONTAINERPLAN, GNE_TAG_TRANSPORT_EDGE);
46 
47  // Create container parameters
49 
50  // create myPathCreator Module
52 
53  // Create HierarchicalElementTree modul
55 }
56 
57 
59 
60 
61 void
63  // get containers maps
64  const auto& containers = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_CONTAINER);
65  const auto& containerFlows = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_CONTAINERFLOW);
66  // Only show moduls if there is at least one container
67  if ((containers.size() > 0) || (containerFlows.size() > 0)) {
68  // show container selector
70  // refresh tag selector
72  // set first container as demand element (this will call demandElementSelected() function)
73  if (containers.size() > 0) {
74  myContainerSelector->setDemandElement(*containers.begin());
75  } else {
76  myContainerSelector->setDemandElement(*containerFlows.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 container selected is valid
105  if (myContainerSelector->getCurrentDemandElement() == nullptr) {
106  myViewNet->setStatusBarText("Current selected container isn't valid.");
107  return false;
108  }
109  // finally check that container plan selected is valid
111  myViewNet->setStatusBarText("Current selected container plan isn't valid.");
112  return false;
113  }
114  // Obtain current container plan tag (only for improve code legibility)
116  // declare flags for requirements
117  const bool requireContainerStop = ((containerPlanTag == GNE_TAG_TRANSPORT_CONTAINERSTOP) || (containerPlanTag == GNE_TAG_TRANSHIP_CONTAINERSTOP) ||
118  (containerPlanTag == GNE_TAG_STOPCONTAINER_CONTAINERSTOP));
119  const bool requireEdge = ((containerPlanTag == GNE_TAG_TRANSPORT_EDGE) || (containerPlanTag == GNE_TAG_TRANSHIP_EDGE) ||
120  (containerPlanTag == GNE_TAG_TRANSHIP_EDGES) || (containerPlanTag == GNE_TAG_STOPCONTAINER_EDGE));
121  // continue depending of tag
122  if (requireContainerStop && objectsUnderCursor.getAdditionalFront() && (objectsUnderCursor.getAdditionalFront()->getTagProperty().getTag() == SUMO_TAG_CONTAINER_STOP)) {
123  return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
124  } else if (requireEdge && objectsUnderCursor.getEdgeFront()) {
125  return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
126  } else {
127  return false;
128  }
129 }
130 
131 
134  return myPathCreator;
135 }
136 
137 // ===========================================================================
138 // protected
139 // ===========================================================================
140 
141 void
143  // first check if container is valid
145  // Obtain current container plan tag (only for improve code legibility)
147  // show container attributes
149  // get previous container plan
151  // set path creator mode depending if previousEdge exist
152  if (previousEdge) {
153  // set path creator mode
154  myPathCreator->showPathCreatorModule(containerPlanTag, true, false);
155  // add previous edge
156  myPathCreator->addEdge(previousEdge, false, false);
157  } else {
158  // set path creator mode
159  myPathCreator->showPathCreatorModule(containerPlanTag, false, false);
160  }
161  // show container hierarchy
163  } else {
164  // hide moduls if tag selecte isn't valid
168  }
169 }
170 
171 
172 void
174  // check if a valid container was selected
176  // show container plan tag selector
178  // now check if container plan selected is valid
180  // call tag selected
181  tagSelected();
182  } else {
186  }
187  } else {
188  // hide moduls if container selected isn't valid
193  }
194 }
195 
196 
197 void
199  // first check that all attributes are valid
202  } else {
203  // check if container plan can be created
208  myPathCreator)) {
209  // refresh HierarchicalElementTree
211  // abort path creation
213  // refresh using tagSelected
214  tagSelected();
215  // refresh containerPlan attributes
217  }
218  }
219 }
220 
221 /****************************************************************************/
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
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNERouteHandler myRouteHandler
route handler
GNEContainerPlanFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
GNEFrameModules::PathCreator * getPathCreator() const
get path creator modul
GNEFrameAttributeModules::AttributesCreator * myContainerPlanAttributes
internal vehicle attributes
GNEFrameModules::HierarchicalElementTree * myContainerHierarchy
Container Hierarchy.
GNEFrameModules::DemandElementSelector * myContainerSelector
Container selectors.
bool addContainerPlanElement(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add container plan element
GNEFrameModules::TagSelector * myContainerPlanTagSelector
containerPlan selector
void demandElementSelected()
selected demand element in DemandElementSelector
GNEFrameModules::PathCreator * myPathCreator
Path Creator.
void tagSelected()
Tag selected in TagSelector.
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 * getContainerPlanPreviousEdge() const
get previous edge for the current container plan
void hideDemandElementSelector()
hide demand element selector
void hideHierarchicalElementTree()
hide HierarchicalElementTree
void refreshHierarchicalElementTree()
refresh HierarchicalElementTree
void showHierarchicalElementTree(GNEAttributeCarrier *AC)
show HierarchicalElementTree
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
void abortPathCreation()
abort path creation
void hidePathCreatorModule()
show PathCreator
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
bool buildContainerPlan(SumoXMLTag tag, GNEDemandElement *containerParent, GNEFrameAttributeModules::AttributesCreator *containerPlanAttributes, GNEFrameModules::PathCreator *pathCreator)
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
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
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