Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNECalibratorDialog.cpp
169684 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 GNECalibratorDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date March 2017
17
///
18
// Dialog for edit calibrators
19
/****************************************************************************/
20
21
#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>
22
#include <netedit/dialogs/elements/GNEVehicleTypeDialog.h>
23
#include <netedit/elements/additional/GNECalibratorFlow.h>
24
#include <netedit/elements/demand/GNERoute.h>
25
#include <netedit/elements/demand/GNEVType.h>
26
#include <netedit/GNENet.h>
27
#include <netedit/GNEUndoList.h>
28
#include <netedit/GNEViewParent.h>
29
#include <utils/gui/div/GUIDesigns.h>
30
31
#include "GNECalibratorDialog.h"
32
#include "GNEAttributeCarrierDialog.h"
33
34
// ===========================================================================
35
// member method definitions
36
// ===========================================================================
37
38
GNECalibratorDialog::GNECalibratorDialog(GNEAdditional* calibrator) :
39
GNETemplateElementDialog<GNEAdditional>(calibrator, DialogType::CALIBRATOR) {
40
// Create two columns, one for Routes and VehicleTypes, and other for Flows
41
FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
42
FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
43
FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
44
// create route element list
45
myRoutes = new RoutesList(this, columnLeft);
46
// create closing lane reroute element list
47
myVTypes = new VTypesList(this, columnLeft);
48
// parking area reroute
49
myCalibratorFlows = new CalibratorFlowsList(this, columnRight, myRoutes, myVTypes);
50
// open dialog
51
openDialog();
52
}
53
54
55
GNECalibratorDialog::~GNECalibratorDialog() {}
56
57
58
void
59
GNECalibratorDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
60
// nothing to do
61
}
62
63
64
long
65
GNECalibratorDialog::onCmdAccept(FXObject*, FXSelector, void*) {
66
// declare strings
67
const auto warningTitle = TLF("Error updating % '%'", myElement->getTagStr(), myElement->getID());
68
const auto infoA = TLF("% '%' cannot be updated because", myElement->getTagStr(), myElement->getID());
69
std::string infoB;
70
// set infoB
71
if (!myRoutes->isListValid()) {
72
infoB = TLF("there are invalid %s.", toString(SUMO_TAG_ROUTE));
73
} else if (!myVTypes->isListValid()) {
74
infoB = TLF("there are invalid %s.", toString(SUMO_TAG_VTYPE));
75
} else if (!myCalibratorFlows->isListValid()) {
76
infoB = TLF("there are invalid %s.", toString(GNE_TAG_CALIBRATOR_FLOW));
77
}
78
// continue depending of info
79
if (infoB.size() > 0) {
80
// open question dialog box with two lines
81
GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(), warningTitle, infoA, infoB);
82
return 1;
83
} else {
84
// close dialog accepting changes
85
return acceptElementDialog();
86
}
87
}
88
89
90
long
91
GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {
92
// reset changes
93
resetChanges();
94
// update tables
95
myRoutes->updateList();
96
myVTypes->updateList();
97
myCalibratorFlows->updateList();
98
return 1;
99
}
100
101
// ---------------------------------------------------------------------------
102
// GNECalibratorDialog::RoutesList - methods
103
// ---------------------------------------------------------------------------
104
105
GNECalibratorDialog::RoutesList::RoutesList(GNECalibratorDialog* rerouterDialog, FXVerticalFrame* contentFrame) :
106
GNETemplateElementList(rerouterDialog, contentFrame, SUMO_TAG_ROUTE,
107
GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {
108
}
109
110
111
long
112
GNECalibratorDialog::RoutesList::addNewElement() {
113
// create route using calibrator as parent
114
GNERoute* route = new GNERoute(myElementDialogParent->getElement());
115
// insert route
116
insertElement(route);
117
// open route dialog
118
const auto routeDialog = GNEAttributeCarrierDialog(route);
119
// continue depending of result of routeDialog
120
if (routeDialog.getResult() != GNEDialog::Result::ACCEPT) {
121
// remove route
122
return removeElement(route);
123
} else {
124
return 1;
125
}
126
}
127
128
129
long
130
GNECalibratorDialog::RoutesList::openElementDialog(const size_t rowIndex) {
131
// open attribute carrier dialog
132
GNEAttributeCarrierDialog(myEditedElements.at(rowIndex));
133
return 1;
134
}
135
136
// ---------------------------------------------------------------------------
137
// GNECalibratorDialog::VTypesList - methods
138
// ---------------------------------------------------------------------------
139
140
GNECalibratorDialog::VTypesList::VTypesList(GNECalibratorDialog* rerouterDialog, FXVerticalFrame* contentFrame) :
141
GNETemplateElementList(rerouterDialog, contentFrame, SUMO_TAG_VTYPE,
142
GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {
143
}
144
145
146
long
147
GNECalibratorDialog::VTypesList::addNewElement() {
148
// create vType
149
GNEVType* vType = new GNEVType(myElementDialogParent->getElement());
150
// insert vType
151
insertElement(vType);
152
// open route dialog
153
const auto vTypeDialog = GNEVehicleTypeDialog(vType);
154
// continue depending of result of routeDialog
155
if (vTypeDialog.getResult() != GNEDialog::Result::ACCEPT) {
156
// remove vType
157
return removeElement(vType);
158
} else {
159
return 1;
160
}
161
}
162
163
164
long
165
GNECalibratorDialog::VTypesList::openElementDialog(const size_t rowIndex) {
166
// open vType dialog
167
GNEVehicleTypeDialog(myEditedElements.at(rowIndex));
168
return 1;
169
}
170
171
// ---------------------------------------------------------------------------
172
// GNECalibratorDialog::CalibratorFlowsList - methods
173
// ---------------------------------------------------------------------------
174
175
GNECalibratorDialog::CalibratorFlowsList::CalibratorFlowsList(GNECalibratorDialog* rerouterDialog, FXVerticalFrame* contentFrame,
176
RoutesList* routesList, VTypesList* vTypesList) :
177
GNETemplateElementList(rerouterDialog, contentFrame, GNE_TAG_CALIBRATOR_FLOW,
178
GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT),
179
myRoutesList(routesList),
180
myVTypesList(vTypesList) {
181
// disable if there are no routes in net
182
if (rerouterDialog->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).size() == 0) {
183
disableList(TL("No routes in net"));
184
}
185
}
186
187
188
long
189
GNECalibratorDialog::CalibratorFlowsList::addNewElement() {
190
// get vType
191
GNEDemandElement* vType = nullptr;
192
if (myVTypesList->getEditedElements().size() > 0) {
193
vType = myVTypesList->getEditedElements().back();
194
} else {
195
vType = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE).begin()->second;
196
}
197
// get route
198
GNEDemandElement* route = nullptr;
199
if (myVTypesList->getEditedElements().size() > 0) {
200
route = myVTypesList->getEditedElements().back();
201
} else {
202
route = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).begin()->second;
203
}
204
// check if route and vType are valid
205
if (route && vType) {
206
// create vType
207
GNECalibratorFlow* calibratorFlow = new GNECalibratorFlow(myElementDialogParent->getElement(), vType, route);
208
// add using undo-redo
209
insertElement(calibratorFlow);
210
// open route dialog
211
const auto calibratorFlowDialog = GNEAttributeCarrierDialog(calibratorFlow);
212
// continue depending of result of routeDialog
213
if (calibratorFlowDialog.getResult() != GNEDialog::Result::CANCEL) {
214
// add calibratorFlow
215
return removeElement(calibratorFlow);
216
}
217
}
218
return 1;
219
}
220
221
222
long
223
GNECalibratorDialog::CalibratorFlowsList::openElementDialog(const size_t rowIndex) {
224
// open attribute carrier dialog
225
GNEAttributeCarrierDialog(myEditedElements.at(rowIndex));
226
return 1;
227
}
228
229
/****************************************************************************/
230
231