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/GNEViewNet.h>
24#include <netedit/GNEUndoList.h>
27
28#include "GNEContainerFrame.h"
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
34// ---------------------------------------------------------------------------
35// GNEContainerFrame - methods
36// ---------------------------------------------------------------------------
37
39 GNEFrame(viewParent, viewNet, "Containers"),
40 myRouteHandler("", viewNet->getNet(), true, false),
41 myContainerBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
42
43 // create tag Selector modul for containers
44 myContainerTagSelector = new GNETagSelector(this, GNETagProperties::TagType::CONTAINER, SUMO_TAG_CONTAINER);
45
46 // create container types selector modul and set DEFAULT_CONTAINERTYPE_ID as default element
48
49 // create container attributes
51
52 // create tag Selector modul for container plans
53 myContainerPlanTagSelector = new GNETagSelector(this, GNETagProperties::TagType::CONTAINERPLAN, GNE_TAG_TRANSPORT_EDGE);
54
55 // create container plan attributes
57
58 // Create Netedit parameter
60
61 // create GNEPathCreator Module
62 myPathCreator = new GNEPathCreator(this);
63
64 // limit path creator to pedestrians
66}
67
68
71}
72
73
74void
76 // refresh tag selector
80 // update VClass of myPathCreator
84 } else {
86 }
87 // show frame
89}
90
91
92void
94 // reset candidate edges
95 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
96 edge.second->resetCandidateFlags();
97 }
98 // hide frame
100}
101
102
103bool
105 // first check that we clicked over an AC
106 if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
107 return false;
108 }
109 // 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 (containerTag == SUMO_TAG_NOTHING) {
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_JUNCTION) {
133 return myPathCreator->addJunction(objectsUnderCursor.getJunctionFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
134 } else {
135 return false;
136 }
137}
138
139
142 return myPathCreator;
143}
144
145// ===========================================================================
146// protected
147// ===========================================================================
148
149void
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
205void
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(TL("VType with vClass == 'pedestrian' is oriented to pedestrians"));
234 WRITE_WARNING(TL("VType with vClass != 'ignoring' is not oriented to containers"));
235 }
236 } else {
237 // hide modules
241 }
242 } else {
243 // hide modules
249 }
250}
251
252
253bool
254GNEContainerFrame::createPath(const bool /* useLastRoute */) {
255 // first check that all attributes are valid
257 myViewNet->setStatusBarText("Invalid container parameters.");
260 } else {
261 // begin undo-redo operation
265 // create person
267 // check if person and person plan can be created
271 // end undo-redo operation
273 // abort path creation
275 // refresh person and personPlan attributes
278 // compute person
279 person->computePathElement();
280 // enable show all person plans
282 return true;
283 } else {
284 // abort person creation
286 }
287 }
288 return false;
289}
290
291// ---------------------------------------------------------------------------
292// GNEContainerFrame - private methods
293// ---------------------------------------------------------------------------
294
297 // first container base object
299 // obtain container tag (only for improve code legibility)
301 // set tag
302 myContainerBaseObject->setTag(containerTag);
303 // Declare map to keep attributes from myContainerAttributes
305 // Check if ID has to be generated
308 }
309 // add pType parameter
311 // check if we're creating a container or containerFlow
312 if (containerTag == SUMO_TAG_CONTAINER) {
313 // Add parameter departure
316 }
317 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
319 // obtain container parameters
320 SUMOVehicleParameter* containerParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_CONTAINER, SUMOSAXAttrs, false, false, false);
321 // check personParameters
322 if (containerParameters) {
323 myContainerBaseObject->setVehicleParameter(containerParameters);
324 // parse vehicle
326 // delete personParameters
327 delete containerParameters;
328 }
329 } else {
330 // set begin and end attributes
333 }
336 }
337 // adjust poisson value
340 }
341 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
343 // obtain containerFlow parameters
344 SUMOVehicleParameter* containerFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_CONTAINERFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
345 // check personParameters
346 if (containerFlowParameters) {
347 myContainerBaseObject->setVehicleParameter(containerFlowParameters);
348 // parse vehicle
350 // delete personParameters
351 delete containerFlowParameters;
352 }
353 }
354 // refresh container and containerPlan attributes
357 // return created container
359}
360
361
362/****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
#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_JUNCTION
begin/end of the description of a junction
@ 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
@ GNE_ATTR_POISSON
poisson definition (used in flow)
@ SUMO_ATTR_PERIOD
@ 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 setTag(const SumoXMLTag tag)
set SumoBaseObject tag
bool hasDoubleAttribute(const SumoXMLAttr attr) const
check if current SumoBaseObject has the given double attribute
void setVehicleParameter(const SUMOVehicleParameter *vehicleParameter)
set vehicle parameters
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
double getDoubleAttribute(const SumoXMLAttr attr) const
get double attribute
void clear()
clear SumoBaseObject
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
GNEDemandElement * getCurrentDemandElement() const
get current demand element
void refreshDemandElementSelector()
refresh demand element selector
void showDemandElementSelector()
show demand element selector
void hideDemandElementSelector()
hide demand element selector
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
GNETagSelector * myContainerPlanTagSelector
container plan selector (used to select diffent kind of container plan)
void tagSelected()
Tag selected in GNETagSelector.
GNEAttributesCreator * myContainerPlanAttributes
internal container plan attributes
GNERouteHandler myRouteHandler
route handler
CommonXMLStructure::SumoBaseObject * myContainerBaseObject
container base object
GNEContainerFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void hide()
hide Frame
GNEPathCreator * getPathCreator() const
get GNEPathCreator modul
GNEAttributesCreator * myContainerAttributes
internal vehicle attributes
void demandElementSelected()
selected demand element in DemandElementSelector
GNENeteditAttributes * myNeteditAttributes
Netedit parameter.
DemandElementSelector * myTypeSelector
Container Type selectors.
void show()
show Frame
~GNEContainerFrame()
Destructor.
bool addContainer(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add vehicle element
GNETagSelector * myContainerTagSelector
container tag selector (used to select diffent kind of containers)
GNEPathCreator * myPathCreator
edge path creator (used for Walks, rides and trips)
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
An Element which don't belong to GNENet but has influence in the simulation.
virtual SUMOVehicleClass getVClass() const =0
virtual void computePathElement()=0
compute pathElement
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:310
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:132
void showNeteditAttributesModule(GNEAttributeCarrier *templateAC)
show Netedit attributes modul
void hideNeteditAttributesModule()
hide Netedit attributes modul
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 setVClass(SUMOVehicleClass vClass)
set vClass
void hidePathCreatorModule()
show GNEPathCreator
void showPathCreatorModule(SumoXMLTag element, const bool firstElement, const bool consecutives)
show GNEPathCreator for the given tag
bool addJunction(GNEJunction *junction, const bool shiftKeyPressed, const bool controlKeyPressed)
add junction
bool buildContainerPlan(SumoXMLTag tag, GNEDemandElement *containerParent, GNEAttributesCreator *containerPlanAttributes, GNEPathCreator *pathCreator, const bool centerAfterCreation)
build container plan
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...
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
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
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
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
GNEAdditional * getAdditionalFront() const
get front additional element or a pointer to nullptr
GNEJunction * getJunctionFront() const
get front junction or a pointer to nullptr
GNEEdge * getEdgeFront() const
get front edge 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: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
void setChecked(bool val)
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 * 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.
MFXCheckableButton * menuCheckShowAllContainerPlans
show all container 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