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.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 Container elements
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
28 
29 #include "GNEContainerFrame.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
35 // ---------------------------------------------------------------------------
36 // GNEContainerFrame - methods
37 // ---------------------------------------------------------------------------
38 
39 GNEContainerFrame::GNEContainerFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
40  GNEFrame(horizontalFrameParent, viewNet, "Containers"),
41  myRouteHandler("", viewNet->getNet(), true),
42  myContainerBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
43 
44  // create tag Selector modul for containers
45  myContainerTagSelector = new GNEFrameModules::TagSelector(this, GNETagProperties::TagType::CONTAINER, SUMO_TAG_CONTAINER);
46 
47  // create container types selector modul and set DEFAULT_CONTAINERTYPE_ID as default element
49 
50  // create container attributes
52 
53  // create tag Selector modul for container plans
54  myContainerPlanTagSelector = new GNEFrameModules::TagSelector(this, GNETagProperties::TagType::CONTAINERPLAN, GNE_TAG_TRANSPORT_EDGE);
55 
56  // create container plan attributes
58 
59  // Create Netedit parameter
61 
62  // create PathCreator Module
64 
65  // limit path creator to pedestrians
67 }
68 
69 
71  delete myContainerBaseObject;
72 }
73 
74 
75 void
77  // refresh tag selector
81  // update VClass of myPathCreator
85  } else {
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 that we clicked over an AC
107  if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
108  return false;
109  }
110  // obtain tags (only for improve code legibility)
111  SumoXMLTag clickedACTag = objectsUnderCursor.getAttributeCarrierFront()->getTagProperty().getTag();
112  // first check that current selected container is valid
113  if (myContainerTagSelector->getCurrentTemplateAC() == nullptr) {
114  myViewNet->setStatusBarText("Current selected container isn't valid.");
115  return false;
116  }
117  // now check that pType is valid
118  if (myTypeSelector->getCurrentDemandElement() == nullptr) {
119  myViewNet->setStatusBarText("Current selected container type isn't valid.");
120  return false;
121  }
122  // finally check that container plan selected is valid
124  myViewNet->setStatusBarText("Current selected container plan isn't valid.");
125  return false;
126  }
127  // add elements to path creator
128  if (clickedACTag == SUMO_TAG_LANE) {
129  return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
130  } else if (clickedACTag == SUMO_TAG_CONTAINER_STOP) {
131  return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
132  } else if (clickedACTag == SUMO_TAG_ROUTE) {
133  return myPathCreator->addRoute(objectsUnderCursor.getDemandElementFront(), 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 container is valid
153  // show PType selector and container plan selector
155  // check if current container type selected is valid
157  // show container attributes depending of myContainerPlanTagSelector
160  } else {
162  }
163  // show container plan tag selector
165  // now check if container plan selected is valid
167  // update VClass of myPathCreator depending if container is a ride
170  } else {
172  }
173  // show container plan attributes
175  // show Netedit attributes modul
177  // show edge path creator modul
179  } else {
180  // hide modules
184  }
185  } else {
186  // hide modules
192  }
193  } else {
194  // hide all moduls if container isn't valid
201  }
202 }
203 
204 
205 void
208  // show container attributes depending of myContainerPlanTagSelector
211  } else {
213  }
214  // show container plan tag selector
216  // now check if container plan selected is valid
218  // update VClass of myPathCreator depending if container is a ride
221  } else {
223  }
224  // show container plan attributes
226  // show Netedit attributes modul
228  // show edge path creator modul
230  // show warning if we have selected a vType oriented to persons or vehicles
232  WRITE_WARNING("Current selected vType is oriented to persons");
234  WRITE_WARNING("Current selected vType is oriented to vehicles");
235  }
236  } else {
237  // hide modules
241  }
242  } else {
243  // hide modules
249  }
250 }
251 
252 
253 void
255  // first check that all attributes are valid
257  myViewNet->setStatusBarText("Invalid container parameters.");
258  } else if (!myContainerPlanAttributes->areValuesValid()) {
260  } else {
261  /*
262  // begin undo-redo operation
263  myViewNet->getUndoList()->begin("create " + myContainerTagSelector->getCurrentTagProperties().getTagStr() + " and " + myContainerPlanTagSelector->getCurrentTagProperties().getTagStr());
264  // create container
265  GNEDemandElement* container = buildContainer();
266  // check if container and container plan can be created
267  if (GNERouteHandler::buildContainerPlan(
268  myContainerPlanTagSelector->getCurrentTagProperties().getTag(),
269  container, myContainerPlanAttributes, myPathCreator)) {
270  // end undo-redo operation
271  myViewNet->getUndoList()->end();
272  // abort path creation
273  myPathCreator->abortPathCreation();
274  // refresh container and containerPlan attributes
275  myContainerAttributes->refreshRows();
276  myContainerPlanAttributes->refreshRows();
277  // compute container
278  container->computePathElement();
279  } else {
280  // abort container creation
281  myViewNet->getUndoList()->p_abort();
282  }
283  */
284  }
285 }
286 
287 // ---------------------------------------------------------------------------
288 // GNEContainerFrame - private methods
289 // ---------------------------------------------------------------------------
290 
293  // obtain container tag (only for improve code legibility)
295  // Declare map to keep attributes from myContainerAttributes
297  // Check if ID has to be generated
300  }
301  // add pType parameter
303  // check if we're creating a container or containerFlow
304  if (containerTag == SUMO_TAG_CONTAINER) {
305  // Add parameter departure
308  }
309  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
311  // obtain container parameters
312  SUMOVehicleParameter* containerParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_CONTAINER, SUMOSAXAttrs, false, false, false);
313  // check personParameters
314  if (containerParameters) {
315  myContainerBaseObject->setVehicleParameter(containerParameters);
316  // parse vehicle
318  // delete personParameters
319  delete containerParameters;
320  }
321  } else {
322  // set begin and end attributes
325  }
328  }
329  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
331  // obtain containerFlow parameters
332  SUMOVehicleParameter* containerFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_CONTAINERFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
333  // check personParameters
334  if (containerFlowParameters) {
335  myContainerBaseObject->setVehicleParameter(containerFlowParameters);
336  // parse vehicle
338  // delete personParameters
339  delete containerFlowParameters;
340  }
341  }
342  // refresh container and containerPlan attributes
345  // return created container
347 }
348 
349 
350 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
#define SUMOTime_MAX
Definition: SUMOTime.h:33
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
const std::string DEFAULT_CONTAINERTYPE_ID
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ GNE_TAG_TRANSPORT_EDGE
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
std::map< std::string, std::string > getAllAttributes() const
get all attributes in string format
void setVehicleParameter(const SUMOVehicleParameter *vehicleParameter)
set vehicle parameters
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNEFrameModules::PathCreator * myPathCreator
edge path creator (used for Walks, rides and trips)
void tagSelected()
Tag selected in TagSelector.
void createPath()
create path
GNERouteHandler myRouteHandler
route handler
GNEFrameModules::TagSelector * myContainerTagSelector
container tag selector (used to select diffent kind of containers)
CommonXMLStructure::SumoBaseObject * myContainerBaseObject
container base object
GNEFrameAttributeModules::AttributesCreator * myContainerPlanAttributes
internal container plan attributes
void hide()
hide Frame
void demandElementSelected()
selected demand element in DemandElementSelector
GNEFrameAttributeModules::AttributesCreator * myContainerAttributes
internal vehicle attributes
GNEFrameModules::TagSelector * myContainerPlanTagSelector
container plan selector (used to select diffent kind of container plan)
GNEFrameModules::DemandElementSelector * myTypeSelector
Container Type selectors.
void show()
show Frame
~GNEContainerFrame()
Destructor.
GNEFrameAttributeModules::NeteditAttributes * myNeteditAttributes
Netedit parameter.
bool addContainer(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add vehicle element
GNEFrameModules::PathCreator * getPathCreator() const
get PathCreator modul
GNEContainerFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
GNEDemandElement * buildContainer()
build container and return it (note: function includes a call to begin(...), but NOT a call to end(....
An Element which don't belongs to GNENet but has influency in the simulation.
virtual SUMOVehicleClass getVClass() const =0
const std::string & getID() const
get ID
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
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
void hideNeteditAttributesModule()
hide Netedit attributes modul
void showNeteditAttributesModule(const GNETagProperties &tagValue)
show Netedit attributes 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
const std::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition: GNEFrame.cpp:269
void showDemandElementSelector()
show demand element selector
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void refreshDemandElementSelector()
refresh demand element selector
void hideDemandElementSelector()
hide demand element selector
void setVClass(SUMOVehicleClass vClass)
set vClass
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
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
std::string generateDemandElementID(SumoXMLTag tag) const
generate demand element id
const std::map< std::string, 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:125
bool isTransportPlan() const
return true if tag correspond to a transport
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
bool isStopContainer() const
return true if tag correspond to a container stop element
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
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
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
Encapsulated Xerces-SAX-attributes.
Structure representing possible vehicle parameter.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault)
Parses a flow's attributes.
static SUMOVehicleParameter * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false)
Parses a vehicle's attributes.
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