Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/demand/GNEContainerPlanFrame.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 GNEContainerPlanFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2019
17
///
18
// The Widget for add ContainerPlan elements
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/elements/additional/GNETAZ.h>
25
#include <netedit/elements/demand/GNERouteHandler.h>
26
#include <netedit/frames/GNEAttributesEditor.h>
27
#include <netedit/frames/GNEDemandSelector.h>
28
#include <netedit/frames/GNEElementTree.h>
29
#include <netedit/frames/GNEPlanCreator.h>
30
#include <netedit/frames/GNEPlanCreatorLegend.h>
31
32
#include "GNEContainerPlanFrame.h"
33
34
// ===========================================================================
35
// method definitions
36
// ===========================================================================
37
38
GNEContainerPlanFrame::GNEContainerPlanFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :
39
GNEFrame(viewParent, viewNet, TL("ContainerPlans")) {
40
41
// create container types selector module
42
myContainerSelector = new GNEDemandElementSelector(this, {GNETagProperties::Type::CONTAINER});
43
44
// Create plan selector
45
myPlanSelector = new GNEPlanSelector(this, SUMO_TAG_CONTAINER);
46
47
// Create attributes editor
48
myContainerPlanAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);
49
50
// create plan creator Module
51
myPlanCreator = new GNEPlanCreator(this, viewNet->getNet()->getDemandPathManager());
52
53
// Create GNEElementTree module
54
myContainerHierarchy = new GNEElementTree(this);
55
56
// create plan creator legend
57
myPlanCreatorLegend = new GNEPlanCreatorLegend(this);
58
}
59
60
61
GNEContainerPlanFrame::~GNEContainerPlanFrame() {}
62
63
64
void
65
GNEContainerPlanFrame::show() {
66
// get containers maps
67
const auto& containers = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_CONTAINER);
68
const auto& containerFlows = myViewNet->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_CONTAINERFLOW);
69
// Only show modules if there is at least one container
70
if ((containers.size() > 0) || (containerFlows.size() > 0)) {
71
// show container selector
72
myContainerSelector->showDemandElementSelector();
73
// refresh tag selector
74
myPlanSelector->refreshPlanSelector();
75
} else {
76
// hide all modules
77
myContainerSelector->hideDemandElementSelector();
78
myPlanSelector->hidePlanSelector();
79
myContainerPlanAttributesEditor->hideAttributesEditor();
80
myPlanCreator->hidePathCreatorModule();
81
myContainerHierarchy->hideHierarchicalElementTree();
82
myPlanCreatorLegend->hidePlanCreatorLegend();
83
}
84
// show frame
85
GNEFrame::show();
86
}
87
88
89
void
90
GNEContainerPlanFrame::hide() {
91
// reset candidate edges
92
for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
93
edge.second->resetCandidateFlags();
94
}
95
// enable undo/redo
96
myViewNet->getViewParent()->getGNEAppWindows()->enableUndoRedoTemporally();
97
// hide frame
98
GNEFrame::hide();
99
}
100
101
102
bool
103
GNEContainerPlanFrame::addContainerPlanElement(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {
104
// first check that we clicked over an AC
105
if (viewObjects.getAttributeCarrierFront() == nullptr) {
106
return false;
107
}
108
// check if we have to select a new container
109
if (myContainerSelector->getCurrentDemandElement() == nullptr) {
110
if (viewObjects.getDemandElementFront() && viewObjects.getDemandElementFront()->getTagProperty()->isContainer()) {
111
// continue depending of number of demand elements under cursor
112
if (viewObjects.getDemandElements().size() > 1) {
113
// Filter containers
114
myContainerSelector->setDemandElements(viewObjects.getDemandElements());
115
} else {
116
// select new container
117
myContainerSelector->setDemandElement(viewObjects.getDemandElementFront());
118
}
119
return true;
120
} else {
121
myViewNet->setStatusBarText(TL("Current selected container isn't valid."));
122
return false;
123
}
124
}
125
// finally check that container plan selected is valid
126
if (!myPlanSelector->getCurrentPlanTemplate()) {
127
myViewNet->setStatusBarText(TL("Current selected container plan isn't valid."));
128
return false;
129
}
130
// continue depending of marked elements
131
if (myPlanSelector->markRoutes() && viewObjects.getDemandElementFront() &&
132
(viewObjects.getDemandElementFront()->getTagProperty()->getTag() == SUMO_TAG_ROUTE)) {
133
return myPlanCreator->addRoute(viewObjects.getDemandElementFront());
134
} else if (myPlanSelector->markStoppingPlaces() && viewObjects.getAdditionalFront() &&
135
(viewObjects.getAdditionalFront()->getTagProperty()->isStoppingPlace())) {
136
return myPlanCreator->addStoppingPlace(viewObjects.getAdditionalFront());
137
} else if (myPlanSelector->markJunctions() && viewObjects.getJunctionFront()) {
138
return myPlanCreator->addJunction(viewObjects.getJunctionFront());
139
} else if (myPlanSelector->markEdges() && viewObjects.getLaneFront()) {
140
return myPlanCreator->addEdge(viewObjects.getLaneFront());
141
} else if (myPlanSelector->markTAZs() && viewObjects.getTAZFront()) {
142
return myPlanCreator->addTAZ(viewObjects.getTAZFront());
143
} else {
144
return false;
145
}
146
}
147
148
149
void
150
GNEContainerPlanFrame::resetSelectedContainer() {
151
myContainerSelector->setDemandElement(nullptr);
152
}
153
154
155
GNEPlanCreator*
156
GNEContainerPlanFrame::getPlanCreator() const {
157
return myPlanCreator;
158
}
159
160
161
GNEElementTree*
162
GNEContainerPlanFrame::getContainerHierarchy() const {
163
return myContainerHierarchy;
164
}
165
166
167
GNEDemandElementSelector*
168
GNEContainerPlanFrame::getContainerSelector() const {
169
return myContainerSelector;
170
}
171
172
173
GNEPlanSelector*
174
GNEContainerPlanFrame::getPlanSelector() const {
175
return myPlanSelector;
176
}
177
178
// ===========================================================================
179
// protected
180
// ===========================================================================
181
182
void
183
GNEContainerPlanFrame::tagSelected() {
184
// first check if container is valid
185
if (myPlanSelector->getCurrentPlanTemplate()) {
186
// show container attributes
187
myContainerPlanAttributesEditor->showAttributesEditor(myPlanSelector->getCurrentPlanTemplate(), true);
188
// set path creator mode depending if previousEdge exist
189
if (myContainerSelector) {
190
// show path creator mode
191
myPlanCreator->showPlanCreatorModule(myPlanSelector, myContainerSelector->getPreviousPlanElement());
192
// show legend
193
myPlanCreatorLegend->showPlanCreatorLegend();
194
// show container hierarchy
195
myContainerHierarchy->showHierarchicalElementTree(myContainerSelector->getCurrentDemandElement());
196
} else {
197
// hide modules
198
myPlanCreator->hidePathCreatorModule();
199
myContainerHierarchy->hideHierarchicalElementTree();
200
myPlanCreatorLegend->hidePlanCreatorLegend();
201
}
202
} else {
203
// hide modules if tag selected isn't valid
204
myContainerPlanAttributesEditor->hideAttributesEditor();
205
myPlanCreator->hidePathCreatorModule();
206
myContainerHierarchy->hideHierarchicalElementTree();
207
myPlanCreatorLegend->hidePlanCreatorLegend();
208
}
209
}
210
211
212
void
213
GNEContainerPlanFrame::demandElementSelected() {
214
// check if a valid container was selected
215
if (myContainerSelector->getCurrentDemandElement()) {
216
// show container plan tag selector
217
myPlanSelector->showPlanSelector();
218
// now check if container plan selected is valid
219
if (myPlanSelector->getCurrentPlanTemplate()) {
220
// call tag selected
221
tagSelected();
222
} else {
223
myContainerPlanAttributesEditor->hideAttributesEditor();
224
myPlanCreator->hidePathCreatorModule();
225
myContainerHierarchy->hideHierarchicalElementTree();
226
myPlanCreatorLegend->hidePlanCreatorLegend();
227
}
228
} else {
229
// hide modules if container selected isn't valid
230
myPlanSelector->hidePlanSelector();
231
myContainerPlanAttributesEditor->hideAttributesEditor();
232
myPlanCreator->hidePathCreatorModule();
233
myContainerHierarchy->hideHierarchicalElementTree();
234
myPlanCreatorLegend->hidePlanCreatorLegend();
235
}
236
}
237
238
239
bool
240
GNEContainerPlanFrame::createPath(const bool /*useLastRoute*/) {
241
// first check that all attributes are valid
242
if (!myContainerPlanAttributesEditor->checkAttributes(true)) {
243
return false;
244
} else {
245
// declare route handler
246
GNERouteHandler routeHandler(myViewNet->getNet(), myContainerSelector->getCurrentDemandElement()->getAttribute(GNE_ATTR_DEMAND_FILE),
247
myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
248
// check if container plan can be created
249
if (routeHandler.buildContainerPlan(myPlanSelector->getCurrentPlanTemplate(), myContainerSelector->getCurrentDemandElement(),
250
myContainerPlanAttributesEditor, myPlanCreator, false)) {
251
// refresh GNEElementTree
252
myContainerHierarchy->refreshHierarchicalElementTree();
253
// abort path creation
254
myPlanCreator->abortPathCreation();
255
// refresh using tagSelected
256
tagSelected();
257
// refresh containerPlan attributes
258
myContainerPlanAttributesEditor->refreshAttributesEditor();
259
// enable show all container plans
260
myViewNet->getDemandViewOptions().menuCheckShowAllContainerPlans->setChecked(TRUE);
261
return true;
262
} else {
263
return false;
264
}
265
}
266
}
267
268
/****************************************************************************/
269
270