Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNECalibratorDialog.cpp
193674 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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
// parking area reroute
41
myCalibratorFlows = new CalibratorFlowsList(this, myContentFrame);
42
// open dialog
43
openDialog();
44
}
45
46
47
GNECalibratorDialog::~GNECalibratorDialog() {}
48
49
50
void
51
GNECalibratorDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
52
// nothing to do
53
}
54
55
56
long
57
GNECalibratorDialog::onCmdAccept(FXObject*, FXSelector, void*) {
58
// declare strings
59
const auto warningTitle = TLF("Error updating % '%'", myElement->getTagStr(), myElement->getID());
60
const auto infoA = TLF("% '%' cannot be updated because", myElement->getTagStr(), myElement->getID());
61
const auto infoB = TLF("there are invalid %s.", toString(GNE_TAG_CALIBRATOR_FLOW));
62
// continue depending of info
63
if (!myCalibratorFlows->isListValid()) {
64
// open question dialog box with two lines
65
GNEWarningBasicDialog(myElement->getNet()->getGNEApplicationWindow(), this, warningTitle, infoA, infoB);
66
return 1;
67
} else {
68
// close dialog accepting changes
69
return acceptElementDialog();
70
}
71
}
72
73
74
long
75
GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {
76
// reset changes
77
resetChanges();
78
myCalibratorFlows->updateList();
79
return 1;
80
}
81
82
// ---------------------------------------------------------------------------
83
// GNECalibratorDialog::CalibratorFlowsList - methods
84
// ---------------------------------------------------------------------------
85
86
GNECalibratorDialog::CalibratorFlowsList::CalibratorFlowsList(GNECalibratorDialog* calibratorDialog, FXVerticalFrame* contentFrame) :
87
GNETemplateElementList(calibratorDialog, contentFrame, GNE_TAG_CALIBRATOR_FLOW,
88
GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::DIALOG_ELEMENT | GNEElementList::Options::FIXED_HEIGHT) {
89
// disable if there are no routes in net
90
if (calibratorDialog->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).size() == 0) {
91
disableList(TL("No routes in net"));
92
}
93
}
94
95
96
long
97
GNECalibratorDialog::CalibratorFlowsList::addNewElement() {
98
// get vType
99
GNEDemandElement* vType = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID);
100
// get route
101
GNEDemandElement* route = myElementDialogParent->getElement()->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).begin()->second;
102
// calculate begin based in last calibrator flow
103
SUMOTime begin = 0;
104
for (const auto& child : myElementDialogParent->getElement()->getChildAdditionals()) {
105
if (child->getTagProperty()->getTag() == GNE_TAG_CALIBRATOR_FLOW) {
106
begin = GNEAttributeCarrier::parse<SUMOTime>(child->getAttribute(SUMO_ATTR_END));
107
}
108
}
109
const SUMOTime duration = GNEAttributeCarrier::parse<SUMOTime>("3600");
110
// create vType
111
GNECalibratorFlow* calibratorFlow = new GNECalibratorFlow(myElementDialogParent->getElement(), begin, begin + duration, vType, route);
112
// add using undo-redo
113
insertElement(calibratorFlow);
114
// open route dialog
115
const GNEAttributeCarrierDialog calibratorFlowDialog(calibratorFlow, myElementDialogParent);
116
// continue depending of result of routeDialog
117
if (calibratorFlowDialog.getResult() != GNEDialog::Result::ACCEPT) {
118
// add calibratorFlow
119
return removeElement(calibratorFlow);
120
} else if (calibratorFlow->getFileBucket()->getFilename().empty()) {
121
// in this case, the bucket has to be updated manually
122
if (vType->getAttribute(GNE_ATTR_DEFAULT_VTYPE_MODIFIED) == GNEAttributeCarrier::TRUE_STR) {
123
vType->changeFileBucket(calibratorFlow->getFileBucket());
124
}
125
route->changeFileBucket(calibratorFlow->getFileBucket());
126
} else {
127
if (vType->getAttribute(GNE_ATTR_DEFAULT_VTYPE_MODIFIED) == GNEAttributeCarrier::TRUE_STR) {
128
vType->setAttribute(GNE_ATTR_SAVEFILE, calibratorFlow->getFileBucket()->getFilename(), calibratorFlow->getNet()->getUndoList());
129
}
130
route->setAttribute(GNE_ATTR_SAVEFILE, calibratorFlow->getFileBucket()->getFilename(), calibratorFlow->getNet()->getUndoList());
131
}
132
updateList();
133
return 1;
134
}
135
136
137
long
138
GNECalibratorDialog::CalibratorFlowsList::openElementDialog(const size_t rowIndex) {
139
// open attribute carrier dialog
140
GNEAttributeCarrierDialog(myEditedElements.at(rowIndex), myElementDialogParent);
141
return 1;
142
}
143
144
/****************************************************************************/
145
146