Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNEVariableSpeedSignDialog.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 GNEVariableSpeedSignDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date April 2016
17
///
18
// Dialog for edit variableSpeedSigns
19
/****************************************************************************/
20
21
#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>
22
#include <netedit/elements/additional/GNEVariableSpeedSignStep.h>
23
#include <netedit/GNENet.h>
24
#include <netedit/GNEUndoList.h>
25
#include <netedit/GNEViewParent.h>
26
#include <utils/options/OptionsCont.h>
27
28
#include "GNEVariableSpeedSignDialog.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
GNEVariableSpeedSignDialog::GNEVariableSpeedSignDialog(GNEAdditional* variableSpeedSign) :
35
GNETemplateElementDialog<GNEAdditional>(variableSpeedSign, DialogType::VSS) {
36
// create variableSpeedSign steps element list
37
myVariableSpeedSignSteps = new VariableSpeedSignStepsList(this);
38
// open dialog
39
openDialog();
40
}
41
42
43
GNEVariableSpeedSignDialog::~GNEVariableSpeedSignDialog() {}
44
45
46
void
47
GNEVariableSpeedSignDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
48
// nothing to do
49
}
50
51
52
long
53
GNEVariableSpeedSignDialog::onCmdAccept(FXObject*, FXSelector, void*) {
54
// Check if there is overlapping between Steps
55
if (!myVariableSpeedSignSteps->isSorted()) {
56
// open warning Box
57
GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),
58
TLF("VariableSpeedSign steps of % '%' cannot be saved", toString(SUMO_TAG_VSS), myElement->getID()),
59
TL("Steps has to be sorted."));
60
return 1;
61
} else {
62
// close dialog accepting changes
63
return acceptElementDialog();
64
}
65
}
66
67
68
long
69
GNEVariableSpeedSignDialog::onCmdReset(FXObject*, FXSelector, void*) {
70
// reset changes
71
resetChanges();
72
// update tables
73
myVariableSpeedSignSteps->updateList();
74
return 1;
75
}
76
77
// ---------------------------------------------------------------------------
78
// GNEVariableSpeedSignDialog::VariableSpeedSignStepsList - methods
79
// ---------------------------------------------------------------------------
80
81
GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::VariableSpeedSignStepsList(GNEVariableSpeedSignDialog* variableSpeedSignDialog) :
82
GNETemplateElementList(variableSpeedSignDialog, variableSpeedSignDialog->getContentFrame(), SUMO_TAG_STEP,
83
GNEElementList::Options::SORTELEMENTS | GNEElementList::Options::FIXED_HEIGHT) {
84
}
85
86
87
long
88
GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::addNewElement() {
89
// create step depending of number of steps
90
if (getEditedElements().empty()) {
91
return insertElement(new GNEVariableSpeedSignStep(myElementDialogParent->getElement(), 0,
92
OptionsCont::getOptions().getFloat("default.speed")));
93
} else {
94
SUMOTime biggestTime = 0;
95
// get end with biggest end
96
for (const auto& step : getEditedElements()) {
97
const auto time = string2time(step->getAttribute(SUMO_ATTR_TIME));
98
if (biggestTime < time) {
99
biggestTime = time;
100
}
101
}
102
return insertElement(new GNEVariableSpeedSignStep(myElementDialogParent->getElement(), biggestTime + string2time("10"),
103
OptionsCont::getOptions().getFloat("default.speed")));
104
}
105
}
106
107
108
long
109
GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::openElementDialog(const size_t /*rowIndex*/) {
110
// nothing to edit in steps
111
return 1;
112
}
113
114
115
bool
116
GNEVariableSpeedSignDialog::VariableSpeedSignStepsList::isSorted() const {
117
// declare a vector to store steps
118
std::vector<double> sortedSteps;
119
// save time steps
120
for (const auto& step : getEditedElements()) {
121
sortedSteps.push_back(step->getAttributeDouble(SUMO_ATTR_TIME));
122
}
123
// check if all are sorted
124
if (sortedSteps.size() > 1) {
125
// check if the next step is bigger than the current step
126
for (int i = 0; i < (int)sortedSteps.size() - 1; i++) {
127
if (sortedSteps.at(i) > sortedSteps.at(i + 1)) {
128
return false;
129
}
130
}
131
}
132
return true;
133
}
134
135
/****************************************************************************/
136
137