Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2023 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
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
54
55 // create container plan attributes
57
58 // Create Netedit parameter
60
61 // create GNEPathCreator Module
62 myPathCreator = new GNEPathCreator(this);
63
64 // create legend label
66
67 // limit path creator to pedestrians
69}
70
71
75
76
77void
93
94
95void
97 // reset candidate edges
98 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
99 edge.second->resetCandidateFlags();
100 }
101 // hide frame
103}
104
105
106bool
108 // first check that we clicked over an AC
109 if (objectsUnderCursor.getAttributeCarrierFront() == nullptr) {
110 return false;
111 }
112 // obtain tags (only for improve code legibility)
114 SumoXMLTag clickedACTag = objectsUnderCursor.getAttributeCarrierFront()->getTagProperty().getTag();
115 // first check that current selected container is valid
116 if (containerTag == SUMO_TAG_NOTHING) {
117 myViewNet->setStatusBarText(TL("Current selected container isn't valid."));
118 return false;
119 }
120 // now check that pType is valid
121 if (myTypeSelector->getCurrentDemandElement() == nullptr) {
122 myViewNet->setStatusBarText(TL("Current selected container type isn't valid."));
123 return false;
124 }
125 // finally check that container plan selected is valid
127 myViewNet->setStatusBarText(TL("Current selected container plan isn't valid."));
128 return false;
129 }
130 // add elements to path creator
131 if (clickedACTag == SUMO_TAG_LANE) {
132 return myPathCreator->addEdge(objectsUnderCursor.getEdgeFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
133 } else if (clickedACTag == SUMO_TAG_CONTAINER_STOP) {
134 return myPathCreator->addStoppingPlace(objectsUnderCursor.getAdditionalFront(), mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
135 } else if (clickedACTag == SUMO_TAG_JUNCTION) {
136 return myPathCreator->addJunction(objectsUnderCursor.getJunctionFront());
137 } else {
138 return false;
139 }
140}
141
142
147
148
153
154// ===========================================================================
155// protected
156// ===========================================================================
157
158void
160 // first check if container is valid
162 // show PType selector and container plan selector
164 // check if current container type selected is valid
166 // show container attributes depending of myContainerPlanTagSelector
169 } else {
171 }
172 // show container plan tag selector
174 // now check if container plan selected is valid
176 // update VClass of myPathCreator depending if container is a ride
179 } else {
181 }
182 // show container plan attributes
184 // show Netedit attributes modul
186 // show edge path creator modul
188 // show path legend
190 } else {
191 // hide modules
196 }
197 } else {
198 // hide modules
205 }
206 } else {
207 // hide all moduls if container isn't valid
215 }
216}
217
218
219void
222 // show container attributes depending of myContainerPlanTagSelector
225 } else {
227 }
228 // show container plan tag selector
230 // now check if container plan selected is valid
232 // update VClass of myPathCreator depending if container is a ride
235 } else {
237 }
238 // show container plan attributes
240 // show Netedit attributes modul
242 // show edge path creator modul
244 // show path legend
246 // show warning if we have selected a vType oriented to persons or vehicles
248 WRITE_WARNING(TL("VType with vClass == 'pedestrian' is oriented to pedestrians"));
250 WRITE_WARNING(TL("VType with vClass != 'ignoring' is not oriented to containers"));
251 }
252 } else {
253 // hide modules
257 }
258 } else {
259 // hide modules
265 }
266}
267
268
269bool
270GNEContainerFrame::createPath(const bool /* useLastRoute */) {
271 // first check that all attributes are valid
273 myViewNet->setStatusBarText(TL("Invalid container parameters."));
276 } else {
277 // begin undo-redo operation
281 // create person
283 // check if person and person plan can be created
287 // end undo-redo operation
289 // abort path creation
291 // refresh person and personPlan attributes
294 // compute person
295 person->computePathElement();
296 // enable show all person plans
298 return true;
299 } else {
300 // abort person creation
302 }
303 }
304 return false;
305}
306
307// ---------------------------------------------------------------------------
308// GNEContainerFrame - private methods
309// ---------------------------------------------------------------------------
310
313 // first container base object
315 // obtain container tag (only for improve code legibility)
317 // set tag
318 myContainerBaseObject->setTag(containerTag);
319 // Declare map to keep attributes from myContainerAttributes
321 // Check if ID has to be generated
324 }
325 // add pType parameter
327 // check if we're creating a container or containerFlow
328 if (containerTag == SUMO_TAG_CONTAINER) {
329 // Add parameter departure
332 }
333 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
335 // obtain container parameters
336 SUMOVehicleParameter* containerParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_CONTAINER, SUMOSAXAttrs, false, false, false);
337 // check personParameters
338 if (containerParameters) {
339 myContainerBaseObject->setVehicleParameter(containerParameters);
340 // parse vehicle
342 // delete personParameters
343 delete containerParameters;
344 }
345 } else {
346 // set begin and end attributes
349 }
352 }
353 // adjust poisson value
356 }
357 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
359 // obtain containerFlow parameters
360 SUMOVehicleParameter* containerFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_CONTAINERFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
361 // check personParameters
362 if (containerFlowParameters) {
363 myContainerBaseObject->setVehicleParameter(containerFlowParameters);
364 // parse vehicle
366 // delete personParameters
367 delete containerFlowParameters;
368 }
369 }
370 // refresh container and containerPlan attributes
373 // return created container
375}
376
377
378/****************************************************************************/
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
#define TL(string)
Definition MsgHandler.h:287
#define SUMOTime_MAX
Definition SUMOTime.h:34
@ 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
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
GNEPathLegendModule * myPathLegend
path legend modul
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.
DemandElementSelector * getTypeSelector() const
get Type selectors
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:311
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:120
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
bool addJunction(GNEJunction *junction)
add junction
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
void hidePathLegendModule()
hide Legend modul
void showPathLegendModule()
show Legend modul
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
void setStatusBarText(const std::string &text)
set statusBar text
A single child window which contains a view of the simulation area.
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 * 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