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-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/****************************************************************************/
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 // parking area reroute
42 // open dialog
43 openDialog();
44}
45
46
48
49
50void
52 // nothing to do
53}
54
55
56long
57GNECalibratorDialog::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
74long
75GNECalibratorDialog::onCmdReset(FXObject*, FXSelector, void*) {
76 // reset changes
78 myCalibratorFlows->updateList();
79 return 1;
80}
81
82// ---------------------------------------------------------------------------
83// GNECalibratorDialog::CalibratorFlowsList - methods
84// ---------------------------------------------------------------------------
85
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
96long
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
123 vType->changeFileBucket(calibratorFlow->getFileBucket());
124 }
125 route->changeFileBucket(calibratorFlow->getFileBucket());
126 } else {
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
137long
139 // open attribute carrier dialog
141 return 1;
142}
143
144/****************************************************************************/
DialogType
Definition DialogType.h:30
long long int SUMOTime
Definition GUI.h:36
@ CALIBRATOR
Definition GUIIcons.h:442
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string DEFAULT_VTYPE_ID
@ 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
@ GNE_ATTR_SAVEFILE
save file
@ SUMO_ATTR_END
weights: time range end
@ GNE_ATTR_DEFAULT_VTYPE_MODIFIED
Flag to check if a default VType was modified.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
const std::string & getFilename() const
get filename
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
static const std::string TRUE_STR
true value in string format (used for comparing boolean values in getAttribute(......
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
GNENet * getNet() const
get pointer to net
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
long openElementDialog(const size_t rowIndex)
open element dialog
CalibratorFlowsList(GNECalibratorDialog *calibratorDialog, FXVerticalFrame *contentFrame)
constructor
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
CalibratorFlowsList * myCalibratorFlows
list with calibrator flows
GNECalibratorDialog(GNEAdditional *calibrator)
Constructor.
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
void changeFileBucket(FileBucket *fileBucket)
change filebucket manually (used only during calibratorFlows creation)
Result getResult() const
get result to indicate if this dialog was closed accepting or rejecting changes
void openDialog(FXWindow *focusableElement=nullptr)
GNEElementList(GNEDialog *parentDialog, FXVerticalFrame *contentFrame, SumoXMLTag tag, GNEElementList::Options options)
constructor
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:174
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
T * getElement() const
get edited element
GNETemplateElementDialog(GNEAdditional *element, DialogType type)
GNETemplateElementList(GNETemplateElementDialog< GNEAdditional > *elementDialogParent, FXVerticalFrame *contentFrame, SumoXMLTag tag, GNEElementList::Options options)
dialog arguments, used for certain modal dialogs that can not be edited using tab