Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNECalibratorDialog.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// Dialog for edit calibrators
19/****************************************************************************/
20
26#include <netedit/GNENet.h>
27#include <netedit/GNEUndoList.h>
30
31#include "GNECalibratorDialog.h"
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
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
56
57
58void
60 // nothing to do
61}
62
63
64long
65GNECalibratorDialog::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
90long
91GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {
92 // reset changes
94 // update tables
98 return 1;
99}
100
101// ---------------------------------------------------------------------------
102// GNECalibratorDialog::RoutesList - methods
103// ---------------------------------------------------------------------------
104
105GNECalibratorDialog::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
111long
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
129long
131 // open attribute carrier dialog
132 GNEAttributeCarrierDialog(myEditedElements.at(rowIndex));
133 return 1;
134}
135
136// ---------------------------------------------------------------------------
137// GNECalibratorDialog::VTypesList - methods
138// ---------------------------------------------------------------------------
139
140GNECalibratorDialog::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
146long
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
164long
166 // open vType dialog
167 GNEVehicleTypeDialog(myEditedElements.at(rowIndex));
168 return 1;
169}
170
171// ---------------------------------------------------------------------------
172// GNECalibratorDialog::CalibratorFlowsList - methods
173// ---------------------------------------------------------------------------
174
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
188long
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
222long
224 // open attribute carrier dialog
225 GNEAttributeCarrierDialog(myEditedElements.at(rowIndex));
226 return 1;
227}
228
229/****************************************************************************/
#define GUIDesignUniformHorizontalFrame
design for horizontal frame used to pack another frames with a uniform width
Definition GUIDesigns.h:442
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:409
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_ROUTE
description of a route
@ GNE_TAG_CALIBRATOR_FLOW
a flow definition within in Calibrator
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
long openElementDialog(const size_t rowIndex)
open element dialog
CalibratorFlowsList(GNECalibratorDialog *rerouterDialog, FXVerticalFrame *contentFrame, RoutesList *routesList, VTypesList *vTypesList)
constructor
RoutesList(GNECalibratorDialog *rerouterDialog, FXVerticalFrame *contentFrame)
constructor
long openElementDialog(const size_t rowIndex)
open element dialog
long openElementDialog(const size_t rowIndex)
open element dialog
VTypesList(GNECalibratorDialog *rerouterDialog, FXVerticalFrame *contentFrame)
constructor
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
RoutesList * myRoutes
list with routes
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
VTypesList * myVTypes
list with vTypes
CalibratorFlowsList * myCalibratorFlows
list with calibrator flows
GNECalibratorDialog(GNEAdditional *calibrator)
Constructor.
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
FXVerticalFrame * myContentFrame
content frame
Definition GNEDialog.h:135
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
Options
FOX-declaration.
void disableList(const std::string &reason)
disable list
bool isListValid() const
check if the current list is valid
const std::unordered_map< SumoXMLTag, std::unordered_map< const GUIGlObject *, GNEDemandElement * >, std::hash< int > > & getDemandElements() const
get demand elements
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
GNEAdditional * myElement
pointer to edited element
T * getElement() const
get edited element
void resetChanges()
reset changes did in this dialog.
long acceptElementDialog()
close dialog commiting changes
long updateList()
update element list
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
dialog arguments, used for certain modal dialogs that can not be edited using tab