Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/demand/GNEContainerFrame.cpp
169685 views
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
/****************************************************************************/
14
/// @file GNEContainerFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date May 2019
17
///
18
// The Widget for add Container elements
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/GNEUndoList.h>
24
#include <netedit/GNEViewParent.h>
25
#include <netedit/elements/additional/GNETAZ.h>
26
#include <netedit/elements/demand/GNERouteHandler.h>
27
#include <netedit/frames/GNEAttributesEditor.h>
28
#include <netedit/frames/GNEDemandSelector.h>
29
#include <netedit/frames/GNEPlanCreator.h>
30
#include <netedit/frames/GNEPlanCreatorLegend.h>
31
#include <utils/vehicle/SUMOVehicleParserHelper.h>
32
#include <utils/xml/SUMOSAXAttributesImpl_Cached.h>
33
34
#include "GNEContainerFrame.h"
35
36
// ===========================================================================
37
// method definitions
38
// ===========================================================================
39
40
GNEContainerFrame::GNEContainerFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :
41
GNEFrame(viewParent, viewNet, TL("Containers")),
42
myContainerBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
43
44
// create tag Selector module for containers
45
myContainerTagSelector = new GNETagSelector(this, GNETagProperties::Type::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::Type::CONTAINER);
49
50
// Create attributes editor
51
myContainerAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);
52
53
// create plan selector module for container plans
54
myPlanSelector = new GNEPlanSelector(this, SUMO_TAG_CONTAINER);
55
56
// Create attributes editor
57
myContainerPlanAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);
58
59
// create GNEPlanCreator Module
60
myPlanCreator = new GNEPlanCreator(this, viewNet->getNet()->getDemandPathManager());
61
62
// create plan creator legend
63
myPlanCreatorLegend = new GNEPlanCreatorLegend(this);
64
}
65
66
67
GNEContainerFrame::~GNEContainerFrame() {
68
delete myContainerBaseObject;
69
}
70
71
72
void
73
GNEContainerFrame::show() {
74
// refresh tag selector
75
myContainerTagSelector->refreshTagSelector();
76
myTypeSelector->refreshDemandElementSelector();
77
myPlanSelector->refreshPlanSelector();
78
// show frame
79
GNEFrame::show();
80
}
81
82
83
void
84
GNEContainerFrame::hide() {
85
// reset candidate edges
86
for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
87
edge.second->resetCandidateFlags();
88
}
89
// hide frame
90
GNEFrame::hide();
91
}
92
93
94
bool
95
GNEContainerFrame::addContainer(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {
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
140
GNEPlanCreator*
141
GNEContainerFrame::getPlanCreator() const {
142
return myPlanCreator;
143
}
144
145
146
GNEDemandElementSelector*
147
GNEContainerFrame::getTypeSelector() const {
148
return myTypeSelector;
149
}
150
151
152
GNEPlanSelector*
153
GNEContainerFrame::getPlanSelector() const {
154
return myPlanSelector;
155
}
156
157
158
GNEAttributesEditor*
159
GNEContainerFrame::getContainerAttributesEditor() const {
160
return myContainerAttributesEditor;
161
}
162
163
// ===========================================================================
164
// protected
165
// ===========================================================================
166
167
void
168
GNEContainerFrame::tagSelected() {
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
214
void
215
GNEContainerFrame::demandElementSelected() {
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
245
bool
246
GNEContainerFrame::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(),
262
container, myContainerPlanAttributesEditor, myPlanCreator, true)) {
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
289
GNEDemandElement*
290
GNEContainerFrame::buildContainer() {
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
298
myContainerAttributesEditor->fillSumoBaseObject(myContainerBaseObject);
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
318
routeHandler.parseSumoBaseObject(myContainerBaseObject);
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
339
routeHandler.parseSumoBaseObject(myContainerBaseObject);
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
/****************************************************************************/
353
354