Eclipse SUMO - Simulation of Urban MObility
GNEContainerFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 Container elements
19 /****************************************************************************/
20 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
28 
29 #include "GNEContainerFrame.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 // ---------------------------------------------------------------------------
36 // GNEContainerFrame - methods
37 // ---------------------------------------------------------------------------
38 
40  GNEFrame(viewParent, viewNet, TL("Containers")),
41  myRouteHandler("", viewNet->getNet(), true, false),
42  myContainerBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
43 
44  // create tag Selector module for containers
45  myContainerTagSelector = new GNETagSelector(this, GNETagProperties::TagType::CONTAINER, SUMO_TAG_CONTAINER);
46 
47  // create container types selector module and set DEFAULT_PEDTYPE_ID as default element
48  myTypeSelector = new GNEDemandElementSelector(this, SUMO_TAG_VTYPE, GNETagProperties::TagType::CONTAINER);
49 
50  // create container attributes
52 
53  // create plan selector module for container plans
55 
56  // create container plan attributes
58 
59  // Create Netedit parameter
61 
62  // create GNEPlanCreator Module
63  myPlanCreator = new GNEPlanCreator(this);
64 
65  // create plan creator legend
67 }
68 
69 
71  delete myContainerBaseObject;
72 }
73 
74 
75 void
77  // refresh tag selector
81  // show frame
83 }
84 
85 
86 void
88  // reset candidate edges
89  for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
90  edge.second.second->resetCandidateFlags();
91  }
92  // hide frame
94 }
95 
96 
97 bool
99  // first check that we clicked over an AC
100  if (viewObjects.getAttributeCarrierFront() == nullptr) {
101  return false;
102  }
103  // obtain tags (only for improve code legibility)
105  SumoXMLTag clickedACTag = viewObjects.getAttributeCarrierFront()->getTagProperty().getTag();
106  // first check that current selected container is valid
107  if (containerTag == SUMO_TAG_NOTHING) {
108  myViewNet->setStatusBarText(TL("Current selected container isn't valid."));
109  return false;
110  }
111  // now check that pType is valid
112  if (myTypeSelector->getCurrentDemandElement() == nullptr) {
113  myViewNet->setStatusBarText(TL("Current selected container type isn't valid."));
114  return false;
115  }
116  // finally check that container plan selected is valid
117  if (myPlanSelector->getCurrentPlanTemplate() == nullptr) {
118  myViewNet->setStatusBarText(TL("Current selected container plan isn't valid."));
119  return false;
120  }
121  // add elements to path creator
122  if (clickedACTag == SUMO_TAG_LANE) {
123  return myPlanCreator->addEdge(viewObjects.getLaneFront());
124  } else if (viewObjects.getAttributeCarrierFront()->getTagProperty().isStoppingPlace()) {
125  return myPlanCreator->addStoppingPlace(viewObjects.getAdditionalFront());
126  } else if (clickedACTag == SUMO_TAG_ROUTE) {
127  return myPlanCreator->addRoute(viewObjects.getDemandElementFront());
128  } else if (clickedACTag == SUMO_TAG_JUNCTION) {
129  return myPlanCreator->addJunction(viewObjects.getJunctionFront());
130  } else if (clickedACTag == SUMO_TAG_TAZ) {
131  return myPlanCreator->addTAZ(viewObjects.getTAZFront());
132  } else {
133  return false;
134  }
135 }
136 
137 
140  return myPlanCreator;
141 }
142 
143 
146  return myTypeSelector;
147 }
148 
149 
152  return myPlanSelector;
153 }
154 
155 
158  return myContainerAttributes;
159 }
160 
161 // ===========================================================================
162 // protected
163 // ===========================================================================
164 
165 void
167  // first check if container is valid
169  // show PType selector and container plan selector
171  // check if current container type selected is valid
173  // show container attributes depending of myPlanSelector
176  } else {
178  }
179  // show container plan tag selector
181  // check current plan template
183  // show container plan attributes
185  // show Netedit attributes module
187  // show edge path creator module
189  // show path legend
191  } else {
192  // hide modules
197  }
198  } else {
199  // hide modules
206  }
207  } else {
208  // hide all modules if container isn't valid
216  }
217 }
218 
219 
220 void
223  // show container attributes depending of myPlanSelector
226  } else {
228  }
229  // show container plan tag selector
231  // now check if container plan selected is valid
233  // show container plan attributes
235  // show Netedit attributes module
237  // show edge path creator module
239  // show legend
241  } else {
242  // hide modules
246  }
247  } else {
248  // hide modules
254  }
255 }
256 
257 
258 bool
259 GNEContainerFrame::createPath(const bool /*useLastRoute*/) {
260  // first check that all attributes are valid
262  myViewNet->setStatusBarText(TL("Invalid container parameters."));
263  } else if (!myContainerPlanAttributes->areValuesValid()) {
266  // begin undo-redo operation
270  // create container
271  GNEDemandElement* container = buildContainer();
272  // check if container and container plan can be created
274  container, myContainerPlanAttributes, myPlanCreator, true)) {
275  // end undo-redo operation
276  myViewNet->getUndoList()->end();
277  // abort path creation
279  // refresh container and containerPlan attributes
282  // compute container
283  container->computePathElement();
284  // enable show all container plans
286  return true;
287  } else {
288  // abort container creation
290  }
291  }
292  return false;
293 }
294 
295 // ---------------------------------------------------------------------------
296 // GNEContainerFrame - private methods
297 // ---------------------------------------------------------------------------
298 
301  // first container base object
303  // obtain container tag (only for improve code legibility)
305  // set tag
306  myContainerBaseObject->setTag(containerTag);
307  // get attribute ad values
309  // Check if ID has to be generated
312  }
313  // add pType parameter
315  // check if we're creating a container or containerFlow
316  if (containerTag == SUMO_TAG_CONTAINER) {
317  // Add parameter departure
320  }
321  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
323  // obtain container parameters
324  SUMOVehicleParameter* containerParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_CONTAINER, SUMOSAXAttrs, false, false, false);
325  // check containerParameters
326  if (containerParameters) {
327  myContainerBaseObject->setVehicleParameter(containerParameters);
328  // parse vehicle
330  // delete containerParameters
331  delete containerParameters;
332  }
333  } else {
334  // set begin and end attributes
337  }
338  // adjust poisson value
341  }
342  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
344  // obtain containerFlow parameters
345  SUMOVehicleParameter* containerFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_CONTAINERFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
346  // check containerParameters
347  if (containerFlowParameters) {
348  myContainerBaseObject->setVehicleParameter(containerFlowParameters);
349  // parse vehicle
351  // delete containerParameters
352  delete containerFlowParameters;
353  }
354  }
355  // refresh container and containerPlan attributes
358  // return created container
360 }
361 
362 
363 /****************************************************************************/
#define TL(string)
Definition: MsgHandler.h:315
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define SUMOTime_MAX
Definition: SUMOTime.h:34
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_JUNCTION
begin/end of the description of a junction
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_POISSON
poisson definition (used in flow)
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
SUMOTime getTimeAttribute(const SumoXMLAttr attr) const
get time attribute
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
std::map< std::string, std::string > getAllAttributes() const
get all attributes in string format
void setTag(const SumoXMLTag tag)
set SumoBaseObject tag
bool hasTimeAttribute(const SumoXMLAttr attr) const
check if current SumoBaseObject has the given time attribute
void setVehicleParameter(const SUMOVehicleParameter *vehicleParameter)
set vehicle parameters
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
void clear()
clear SumoBaseObject
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const std::string getID() const
get ID (all Attribute Carriers have one)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
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
void tagSelected()
Tag selected in GNETagSelector.
GNEPlanCreator * getPlanCreator() const
get plan creator module
GNEPlanSelector * myPlanSelector
containerPlan selector
GNEAttributesCreator * myContainerPlanAttributes
internal container plan attributes
bool addContainer(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
add vehicle element
GNERouteHandler myRouteHandler
route handler
GNEDemandElementSelector * myTypeSelector
Container Type selectors.
GNEPlanSelector * getPlanSelector() const
get containerPlan selector
GNEPlanCreator * myPlanCreator
plan creator
CommonXMLStructure::SumoBaseObject * myContainerBaseObject
container base object
GNEDemandElementSelector * getTypeSelector() const
get Type selectors
GNEContainerFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void hide()
hide Frame
GNEAttributesCreator * myContainerAttributes
internal vehicle attributes
void demandElementSelected()
selected demand element in DemandElementSelector
GNENeteditAttributes * myNeteditAttributes
Netedit parameter.
GNEPlanCreatorLegend * myPlanCreatorLegend
plan creator legend
GNEAttributesCreator * getContainerAttributes() const
get attributes creator
void show()
show Frame
~GNEContainerFrame()
Destructor.
GNETagSelector * myContainerTagSelector
container tag selector (used to select diffent kind of containers)
GNEDemandElement * buildContainer()
build container and return it (note: function includes a call to begin(...), but NOT a call to end(....
bool createPath(const bool useLastRoute)
create path
virtual void computePathElement()=0
compute pathElement
void showDemandElementSelector()
show demand element selector
void refreshDemandElementSelector()
refresh demand element selector
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void hideDemandElementSelector()
hide demand element selector
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::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition: GNEFrame.cpp:311
std::string generateDemandElementID(SumoXMLTag tag) const
generate demand element id
const std::map< std::string, std::pair< const GUIGlObject *, GNEEdge * > > & getEdges() const
map with the ID and pointer to edges of net
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:123
void showNeteditAttributesModule(GNEAttributeCarrier *templateAC)
show Netedit attributes modul
void hideNeteditAttributesModule()
hide Netedit attributes modul
bool addStoppingPlace(GNEAdditional *stoppingPlace)
add from to stoppingPlace
bool addRoute(GNEDemandElement *route)
add route
bool planCanBeCreated(const GNEDemandElement *planTemplate) const
check if plan can be created
void hidePathCreatorModule()
show GNEPlanCreator
bool addTAZ(GNEAdditional *taz)
add TAZ
bool addJunction(GNEJunction *junction)
add junction
bool addEdge(GNELane *lane)
add edge (clicking over lanes)
void abortPathCreation()
abort path creation
void showPlanCreatorModule(const GNEPlanSelector *planSelector, const GNEDemandElement *previousPlan)
show plan creator for the given tag property
void showPlanCreatorLegend()
show plan creator legend
void hidePlanCreatorLegend()
hide Legend modul
GNEDemandElement * getCurrentPlanTemplate() const
get current plan template
void showPlanSelector()
show plan selector
const GNETagProperties & getCurrentPlanTagProperties() const
get current plan tag properties
void hidePlanSelector()
plan item selector
void refreshPlanSelector()
refresh plan selector (used when frameParent is show)
bool buildContainerPlan(const GNEDemandElement *planTemplate, GNEDemandElement *containerParent, GNEAttributesCreator *containerPlanAttributes, GNEPlanCreator *planCreator, 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...
bool isPlanStopContainer() const
return true if tag correspond to a container stop plan
bool isStoppingPlace() const
additional elements
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void abortAllChangeGroups()
reverts and discards ALL active chained change groups
class used to group all variables related with objects under cursor after a click over view
GNEAttributeCarrier * getAttributeCarrierFront() const
get front attribute carrier or a pointer to nullptr
GNETAZ * getTAZFront() const
get front TAZ or a pointer to nullptr
GNELane * getLaneFront() const
get front lane or a pointer to nullptr
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
GNENet * getNet() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:721
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:807
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:88
void setChecked(bool val, const bool inform=false)
check or uncheck this MFXCheckableButton
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
Encapsulated Xerces-SAX-attributes.
Structure representing possible vehicle parameter.
static SUMOVehicleParameter * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false, const bool allowInternalRoutes=false)
Parses a vehicle's attributes.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault, const bool allowInternalRoutes=false)
Parses a flow's attributes.
MFXCheckableButton * menuCheckShowAllContainerPlans
show all container plans