Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDistributionRefDialog.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 attribute carriers
19/****************************************************************************/
20
25#include <netedit/GNENet.h>
27#include <netedit/GNEUndoList.h>
31
33
34// ===========================================================================
35// Defines
36// ===========================================================================
37
38#define BLACK_COLOR MFXUtils::getFXColor(RGBColor::BLACK)
39#define BLUE_COLOR MFXUtils::getFXColor(RGBColor::BLUE)
40#define RED_COLOR MFXUtils::getFXColor(RGBColor::RED)
41
42// ===========================================================================
43// FOX callback mapping
44// ===========================================================================
45
50
51// Object implementation
52FXIMPLEMENT(GNEDistributionRefDialog, GNEDialog, GNEDistributionRefDialogMap, ARRAYNUMBER(GNEDistributionRefDialogMap))
53
54// ===========================================================================
55// member method definitions
56// ===========================================================================
57
59 GNEDialog(distributionParent->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),
60 TLF("Add % reference", distributionParent->getTagStr()), distributionParent->getTagProperty()->getGUIIcon(),
62 myDistributionParent(distributionParent) {
63 auto tooltipMenu = distributionParent->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
64 // create reference elements
65 FXHorizontalFrame* referenceFrames = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
66 auto referenceLabel = new FXLabel(referenceFrames, "reference", nullptr, GUIDesignLabelThickedFixed(100));
67 myReferencesComboBox = new MFXComboBoxIcon(referenceFrames, tooltipMenu, true, GUIDesignComboBoxVisibleItems,
69 // create probability elements
70 FXHorizontalFrame* probabilityFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
71 new FXLabel(probabilityFrame, toString(SUMO_ATTR_PROB).c_str(), nullptr, GUIDesignLabelThickedFixed(100));
72 myProbabilityTextField = new MFXTextFieldIcon(probabilityFrame, tooltipMenu, GUIIcon::EMPTY, this,
74 // extract all references
75 std::set<std::string> referenceIDs;
76 for (const auto& reference : distributionParent->getHierarchicalElement()->getChildDemandElements()) {
77 if (reference->getTagProperty()->isDistributionReference()) {
78 referenceIDs.insert(reference->getParentDemandElements().at(1)->getID());
79 }
80 }
81 // continue depending on distributionParent
82 if (distributionParent->getTagProperty()->getTag() == SUMO_TAG_VTYPE_DISTRIBUTION) {
83 referenceLabel->setText(toString(SUMO_TAG_VTYPE).c_str());
84 const auto& vTypes = distributionParent->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE);
85 // obtain candidate IDs
86 for (const auto& vType : vTypes) {
87 if (referenceIDs.count(vType.second->getID()) == 0) {
88 myCandidates[vType.second->getID()] = vType.second;
89 }
90 }
91 // insert it in comboBox
92 for (const auto& vTypeID : myCandidates) {
93 myReferencesComboBox->appendIconItem(vTypeID.first.c_str());
94 }
95 } else if (distributionParent->getTagProperty()->getTag() == SUMO_TAG_ROUTE_DISTRIBUTION) {
96 referenceLabel->setText(toString(SUMO_TAG_ROUTE).c_str());
97 const auto& routes = distributionParent->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE);
98 // obtain candidate IDs
99 for (const auto& route : routes) {
100 if (referenceIDs.count(route.second->getID()) == 0) {
101 myCandidates[route.second->getID()] = route.second;
102 }
103 }
104 // insert it in comboBox
105 for (const auto& routeID : myCandidates) {
106 myReferencesComboBox->appendIconItem(routeID.first.c_str());
107 }
108 }
109 // set current item (for update probability)
110 myReferencesComboBox->setCurrentItem(0, TRUE);
111 // open dialog
112 openDialog();
113}
114
115
117
118
119void
121 // nothing to do
122}
123
124
125long
126GNEDistributionRefDialog::onCmdAccept(FXObject*, FXSelector, void*) {
129 // declare referenced element
130 GNEDemandElement* reference = nullptr;
131 const double probability = GNEAttributeCarrier::parse<double>(myProbabilityTextField->getText().text());
133 auto undoList = myDistributionParent->getNet()->getViewNet()->getUndoList();
134 // create a routeRef o a vTypeRef
135 if (distribution->getTagProperty()->getTag() == SUMO_TAG_VTYPE_DISTRIBUTION) {
137 reference = new GNEVTypeRef(distribution, myReferencedElement);
138 } else {
139 reference = new GNEVTypeRef(distribution, myReferencedElement, probability);
140 }
141 } else if (distribution->getTagProperty()->getTag() == SUMO_TAG_ROUTE_DISTRIBUTION) {
143 reference = new GNERouteRef(distribution, myReferencedElement);
144 } else {
145 reference = new GNERouteRef(distribution, myReferencedElement, probability);
146 }
147 }
148 // continue depending if allow/disallow is enabled
150 undoList->begin(myReferencedElement, TLF("add % in '%'", myReferencedElement->getTagStr(), distribution->getID()));
151 undoList->add(new GNEChange_DemandElement(reference, true), true);
152 undoList->end();
153 } else {
155 distribution->addChildElement(reference);
157 reference->incRef("GNEDistributionRefDialog");
158 }
159 return closeDialogAccepting();
160 } else {
161 return closeDialogCanceling();
162 }
163}
164
165
166long
167GNEDistributionRefDialog::onCmdSetReference(FXObject*, FXSelector, void*) {
168 // check if candidateID exist in list of candidates
169 GNEDemandElement* reference = nullptr;
170 for (const auto& candidate : myCandidates) {
171 if (myReferencesComboBox->getText().text() == candidate.first) {
172 reference = candidate.second;
173 break;
174 }
175 }
176 // continue depending if selected candidate exist
177 if (reference == nullptr) {
179 } else {
181 myReferencedElement = reference;
182 // set default probability
184 // check if enable or disable accept button
187 myAcceptButton->enable();
188 } else {
189 myAcceptButton->disable();
190 }
191 }
192 return 1;
193}
194
195
196long
198 // first check if set default probability
199 if (myProbabilityTextField->getText().empty()) {
201 }
202 // check if value can be parsed to double
203 if (GNEAttributeCarrier::canParse<double>(myProbabilityTextField->getText().text())) {
206 } else {
208 }
209 } else {
211 }
212 // check if enable or disable accept button
215 myAcceptButton->enable();
216 } else {
217 myAcceptButton->disable();
218 }
219 return 1;
220}
221
222/****************************************************************************/
DialogType
#define BLUE_COLOR
#define RED_COLOR
#define BLACK_COLOR
FXDEFMAP(GNEDistributionRefDialog) GNEDistributionRefDialogMap[]
@ MID_GNE_DISTRIBUTIONDIALOG_REFERENCE
change reference
@ MID_GNE_DISTRIBUTIONDIALOG_PROBABILITY
change probability
#define GUIDesignComboBox
Definition GUIDesigns.h:295
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:64
#define GUIDesignTextFieldRestricted(type)
text field extended over Frame with thick frame (int)
Definition GUIDesigns.h:77
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:254
#define TLF(string,...)
Definition MsgHandler.h:306
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
description of a route
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ SUMO_ATTR_PROB
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const override
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * getNet() const
get pointer to net
virtual std::string getAttribute(SumoXMLAttr key) const =0
virtual GUIGlObject * getGUIGlObject()=0
get GUIGlObject associated with this AttributeCarrier
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:155
long closeDialogAccepting()
close dialog accepting the changes
OpenType
Open dialog type.
Definition GNEDialog.h:58
long closeDialogCanceling()
close dialog declining the changes
long onCmdSetReference(FXObject *, FXSelector, void *)
event after choose a reference in the comboBox
long onCmdSetProbability(FXObject *, FXSelector, void *)
event after choose a reference in the probability
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
MFXTextFieldIcon * myProbabilityTextField
textField probability
std::map< std::string, GNEDemandElement * > myCandidates
map with candidate IDs;
MFXComboBoxIcon * myReferencesComboBox
comboBox for references
GNEAttributeCarrier * myDistributionParent
FOX needs this.
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
GNEDemandElement * myReferencedElement
current referenced element
void addChildElement(ChildType *element)
add child without updating parent (ONLY used if we're creating elements without undo-redo)
void insertDemandElement(GNEDemandElement *demandElement)
Insert a demand element in container.
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
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
void incRef(const std::string &debugMsg="")
Increase reference.
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
dialog arguments, used for certain modal dialogs that can not be edited using tab
FXString getText() const
Get the text.
void setTextColor(FXColor clr)
Change text color.
FXColor getTextColor() const
Return text color.
FXColor getTextColor() const
Return text color.
FXString getText() const
Get the text for this label.
void setTextColor(FXColor clr)
Change text color.
void setText(const FXString &text, FXbool notify=FALSE)
Change the text and move cursor to end.