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-2025 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
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
33
34#include "GNEContainerFrame.h"
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39
41 GNEFrame(viewParent, viewNet, TL("Containers")),
42 myContainerBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
43
44 // create tag Selector module for containers
46
47 // create container types selector module and set DEFAULT_PEDTYPE_ID as default element
49
50 // Create attributes editor
52
53 // create plan selector module for container plans
55
56 // Create attributes editor
58
59 // create GNEPlanCreator Module
61
62 // create plan creator legend
64}
65
66
70
71
72void
74 // refresh tag selector
75 myContainerTagSelector->refreshTagSelector();
76 myTypeSelector->refreshDemandElementSelector();
77 myPlanSelector->refreshPlanSelector();
78 // show frame
80}
81
82
83void
85 // reset candidate edges
86 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
87 edge.second->resetCandidateFlags();
88 }
89 // hide frame
91}
92
93
94bool
96 // first check that we clicked over an AC
97 if (viewObjects.getAttributeCarrierFront() == nullptr) {
98 return false;
99 }
100 // obtain tags (only for improve code legibility)
101 SumoXMLTag containerTag = myContainerTagSelector->getCurrentTemplateAC()->getTagProperty()->getTag();
102 // first check that current selected container is valid
103 if (containerTag == SUMO_TAG_NOTHING) {
104 myViewNet->setStatusBarText(TL("Current selected container isn't valid."));
105 return false;
106 }
107 // now check that pType is valid
108 if (myTypeSelector->getCurrentDemandElement() == nullptr) {
109 myViewNet->setStatusBarText(TL("Current selected container type isn't valid."));
110 return false;
111 }
112 // finally check that container plan selected is valid
113 if (myPlanSelector->getCurrentPlanTemplate() == nullptr) {
114 myViewNet->setStatusBarText(TL("Current selected container plan isn't valid."));
115 return false;
116 }
117 for (GNEAdditional* o : viewObjects.getAdditionals()) {
118 if (o->getTagProperty()->isStoppingPlace()) {
119 return myPlanCreator->addStoppingPlace(o);
120 }
121 }
122 for (GNEDemandElement* o : viewObjects.getDemandElements()) {
123 if (o->getTagProperty()->getTag() == SUMO_TAG_ROUTE) {
124 return myPlanCreator->addRoute(o);
125 }
126 }
127 if (viewObjects.getAttributeCarrierFront() == viewObjects.getJunctionFront()) {
128 return myPlanCreator->addJunction(viewObjects.getJunctions().front());
129 }
130 if (viewObjects.getAttributeCarrierFront() == viewObjects.getLaneFront()) {
131 return myPlanCreator->addEdge(viewObjects.getLanes().front());
132 }
133 if (viewObjects.getAttributeCarrierFront() == viewObjects.getTAZFront()) {
134 return myPlanCreator->addTAZ(viewObjects.getTAZs().front());
135 }
136 return false;
137}
138
139
144
145
150
151
156
157
162
163// ===========================================================================
164// protected
165// ===========================================================================
166
167void
169 // first check if container is valid
170 if (myContainerTagSelector->getCurrentTemplateAC()) {
171 // show PType selector and container plan selector
172 myTypeSelector->showDemandElementSelector();
173 // check if current container type selected is valid
174 if (myTypeSelector->getCurrentDemandElement()) {
175 // show container attributes
176 myContainerAttributesEditor->showAttributesEditor(myContainerTagSelector->getCurrentTemplateAC(), true);
177 // show container plan tag selector
178 myPlanSelector->showPlanSelector();
179 // check current plan template
180 if (myPlanSelector->getCurrentPlanTemplate()) {
181 // show container plan attributes
182 myContainerPlanAttributesEditor->showAttributesEditor(myPlanSelector->getCurrentPlanTemplate(), false);
183 // show edge path creator module
184 myPlanCreator->showPlanCreatorModule(myPlanSelector, nullptr);
185 // show path legend
186 myPlanCreatorLegend->showPlanCreatorLegend();
187 } else {
188 // hide modules
189 myContainerAttributesEditor->hideAttributesEditor();
190 myContainerPlanAttributesEditor->hideAttributesEditor();
191 myPlanCreator->hidePathCreatorModule();
192 myPlanCreatorLegend->hidePlanCreatorLegend();
193 }
194 } else {
195 // hide modules
196 myPlanSelector->hidePlanSelector();
197 myContainerAttributesEditor->hideAttributesEditor();
198 myContainerPlanAttributesEditor->hideAttributesEditor();
199 myPlanCreator->hidePathCreatorModule();
200 myPlanCreatorLegend->hidePlanCreatorLegend();
201 }
202 } else {
203 // hide all modules if container isn't valid
204 myTypeSelector->hideDemandElementSelector();
205 myPlanSelector->hidePlanSelector();
206 myContainerAttributesEditor->hideAttributesEditor();
207 myContainerPlanAttributesEditor->hideAttributesEditor();
208 myPlanCreator->hidePathCreatorModule();
209 myPlanCreatorLegend->hidePlanCreatorLegend();
210 }
211}
212
213
214void
216 if (myTypeSelector->getCurrentDemandElement() && myPlanSelector->getCurrentPlanTemplate()) {
217 // show container attributes
218 myContainerAttributesEditor->showAttributesEditor(myContainerTagSelector->getCurrentTemplateAC(), true);
219 // show container plan tag selector
220 myPlanSelector->showPlanSelector();
221 // now check if container plan selected is valid
222 if (myPlanSelector->getCurrentPlanTagProperties()->getTag() != SUMO_TAG_NOTHING) {
223 // show container plan attributes
224 myContainerPlanAttributesEditor->showAttributesEditor(myPlanSelector->getCurrentPlanTemplate(), false);
225 // show edge path creator module
226 myPlanCreator->showPlanCreatorModule(myPlanSelector, nullptr);
227 // show legend
228 myPlanCreatorLegend->showPlanCreatorLegend();
229 } else {
230 // hide modules
231 myContainerAttributesEditor->hideAttributesEditor();
232 myContainerPlanAttributesEditor->hideAttributesEditor();
233 myPlanCreator->hidePathCreatorModule();
234 }
235 } else {
236 // hide modules
237 myPlanSelector->hidePlanSelector();
238 myContainerAttributesEditor->hideAttributesEditor();
239 myContainerPlanAttributesEditor->hideAttributesEditor();
240 myPlanCreator->hidePathCreatorModule();
241 }
242}
243
244
245bool
246GNEContainerFrame::createPath(const bool /*useLastRoute*/) {
247 // first check that all attributes are valid
248 if (!myContainerAttributesEditor->checkAttributes(true) || !myContainerPlanAttributesEditor->checkAttributes(true)) {
249 return false;
250 } else if (myPlanCreator->planCanBeCreated(myPlanSelector->getCurrentPlanTemplate())) {
251 // begin undo-redo operation
252 myViewNet->getUndoList()->begin(myContainerTagSelector->getCurrentTemplateAC(), "create " +
253 myContainerTagSelector->getCurrentTemplateAC()->getTagProperty()->getTagStr() + " and " +
254 myPlanSelector->getCurrentPlanTagProperties()->getTagStr());
255 // create container
256 GNEDemandElement* container = buildContainer();
257 // declare route handler
258 GNERouteHandler routeHandler(myViewNet->getNet(), container->getAttribute(GNE_ATTR_DEMAND_FILE),
259 myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
260 // check if container and container plan can be created
261 if (routeHandler.buildContainerPlan(myPlanSelector->getCurrentPlanTemplate(),
263 // end undo-redo operation
264 myViewNet->getUndoList()->end();
265 // abort path creation
266 myPlanCreator->abortPathCreation();
267 // refresh container and containerPlan attributes
268 myContainerAttributesEditor->refreshAttributesEditor();
269 myContainerPlanAttributesEditor->refreshAttributesEditor();
270 // compute container
271 container->computePathElement();
272 // enable show all container plans
273 myViewNet->getDemandViewOptions().menuCheckShowAllContainerPlans->setChecked(TRUE);
274 return true;
275 } else {
276 // abort container creation
277 myViewNet->getUndoList()->abortAllChangeGroups();
278 return false;
279 }
280 } else {
281 return false;
282 }
283}
284
285// ---------------------------------------------------------------------------
286// GNEContainerFrame - private methods
287// ---------------------------------------------------------------------------
288
291 // first container base object
292 myContainerBaseObject->clear();
293 // obtain container tag (only for improve code legibility)
294 SumoXMLTag containerTag = myContainerTagSelector->getCurrentTemplateAC()->getTagProperty()->getTag();
295 // set tag
296 myContainerBaseObject->setTag(containerTag);
297 // get attributes
299 // add pType parameter
300 myContainerBaseObject->addStringAttribute(SUMO_ATTR_TYPE, myTypeSelector->getCurrentDemandElement()->getID());
301 // declare route handler
302 GNERouteHandler routeHandler(myViewNet->getNet(), myContainerBaseObject->hasStringAttribute(GNE_ATTR_DEMAND_FILE) ? myContainerBaseObject->getStringAttribute(GNE_ATTR_DEMAND_FILE) : "",
303 myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
304 // check if we're creating a container or containerFlow
305 if (containerTag == SUMO_TAG_CONTAINER) {
306 // Add parameter departure
307 if (!myContainerBaseObject->hasStringAttribute(SUMO_ATTR_DEPART) || myContainerBaseObject->getStringAttribute(SUMO_ATTR_DEPART).empty()) {
308 myContainerBaseObject->addStringAttribute(SUMO_ATTR_DEPART, "0");
309 }
310 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
311 SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(myContainerBaseObject->getAllAttributes(), getPredefinedTagsMML(), toString(containerTag));
312 // obtain container parameters
313 SUMOVehicleParameter* containerParameters = SUMOVehicleParserHelper::parseVehicleAttributes(SUMO_TAG_CONTAINER, SUMOSAXAttrs, false, false, false);
314 // check containerParameters
315 if (containerParameters) {
316 myContainerBaseObject->setVehicleParameter(containerParameters);
317 // parse vehicle
319 // delete containerParameters
320 delete containerParameters;
321 }
322 } else {
323 // set begin and end attributes
324 if (!myContainerBaseObject->hasStringAttribute(SUMO_ATTR_BEGIN) || myContainerBaseObject->getStringAttribute(SUMO_ATTR_BEGIN).empty()) {
325 myContainerBaseObject->addStringAttribute(SUMO_ATTR_BEGIN, "0");
326 }
327 // adjust poisson value
328 if (myContainerBaseObject->hasDoubleAttribute(GNE_ATTR_POISSON)) {
329 myContainerBaseObject->addStringAttribute(SUMO_ATTR_PERIOD, "exp(" + toString(myContainerBaseObject->getDoubleAttribute(GNE_ATTR_POISSON)) + ")");
330 }
331 // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
332 SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(myContainerBaseObject->getAllAttributes(), getPredefinedTagsMML(), toString(containerTag));
333 // obtain containerFlow parameters
334 SUMOVehicleParameter* containerFlowParameters = SUMOVehicleParserHelper::parseFlowAttributes(SUMO_TAG_CONTAINERFLOW, SUMOSAXAttrs, false, true, 0, SUMOTime_MAX);
335 // check containerParameters
336 if (containerFlowParameters) {
337 myContainerBaseObject->setVehicleParameter(containerFlowParameters);
338 // parse vehicle
340 // delete containerParameters
341 delete containerFlowParameters;
342 }
343 }
344 // refresh container and containerPlan attributes
345 myContainerAttributesEditor->refreshAttributesEditor();
346 myContainerPlanAttributesEditor->refreshAttributesEditor();
347 // return created container
348 return myViewNet->getNet()->getAttributeCarriers()->retrieveDemandElement(containerTag, myContainerBaseObject->getStringAttribute(SUMO_ATTR_ID));
349}
350
351
352/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
#define SUMOTime_MAX
Definition SUMOTime.h:34
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ 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_ROUTE
description of a route
@ GNE_ATTR_DEMAND_FILE
demand demand file
@ 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
virtual std::string getAttribute(SumoXMLAttr key) const =0
void tagSelected()
Tag selected in GNETagSelector.
GNEPlanCreator * getPlanCreator() const
get plan creator module
GNEPlanSelector * myPlanSelector
containerPlan selector
GNEAttributesEditor * myContainerPlanAttributesEditor
plan attributes editor
bool addContainer(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
add vehicle element
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
void demandElementSelected()
selected demand element in DemandElementSelector
GNEAttributesEditor * getContainerAttributesEditor() const
get attributes editor
GNEPlanCreatorLegend * myPlanCreatorLegend
plan creator legend
void show()
show Frame
~GNEContainerFrame()
Destructor.
GNEAttributesEditor * myContainerAttributesEditor
attributes editor
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
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:122
virtual void show()
show Frame
Definition GNEFrame.cpp:110
virtual void hide()
hide Frame
Definition GNEFrame.cpp:119
GNEFrame(GNEViewParent *viewParent, GNEViewNet *viewNet, const std::string &frameLabel)
Constructor.
Definition GNEFrame.cpp:42
const std::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition GNEFrame.cpp:239
GNEPathManager * getDemandPathManager()
get demand path manager
Definition GNENet.cpp:174
virtual void computePathElement()=0
implement in children+
bool buildContainerPlan(const GNEDemandElement *planTemplate, GNEDemandElement *containerParent, GNEAttributesEditor *containerPlanAttributesEditor, GNEPlanCreator *planCreator, const bool centerAfterCreation)
build container plan
class used to group all variables related with objects under cursor after a click over view
const std::vector< GNETAZ * > & getTAZs() const
get vector with TAZs
GNEAttributeCarrier * getAttributeCarrierFront() const
get front attribute carrier or a pointer to nullptr
const std::vector< GNEDemandElement * > & getDemandElements() const
get vector with Demand Elements
GNETAZ * getTAZFront() const
get front TAZ or a pointer to nullptr
GNELane * getLaneFront() const
get front lane or a pointer to nullptr
GNEJunction * getJunctionFront() const
get front junction or a pointer to nullptr
const std::vector< GNEJunction * > & getJunctions() const
get vector with junctions
const std::vector< GNELane * > & getLanes() const
get lanes
const std::vector< GNEAdditional * > & getAdditionals() const
get vector with additionals
GNENet * getNet() const
get the net object
A single child window which contains a view of the simulation area.
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.