Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAttributeCarrierDialog.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
26#include <netedit/GNENet.h>
27#include <netedit/GNEUndoList.h>
31
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
43
44// Object implementation
45FXIMPLEMENT(GNEAttributeCarrierDialog::AttributeTextField, FXHorizontalFrame, AttributeTextFieldMap, ARRAYNUMBER(AttributeTextFieldMap))
46
47// ===========================================================================
48// member method definitions
49// ===========================================================================
50
51// ---------------------------------------------------------------------------
52// GNEAttributeCarrierDialog::AttributeTextField - methods
53// ---------------------------------------------------------------------------
54
56 const GNEAttributeProperties* attrProperty) :
57 FXHorizontalFrame(verticalFrame, GUIDesignAuxiliarHorizontalFrame),
58 myACDialogParent(ACDialog),
59 myAttrProperty(attrProperty) {
60 // get static tooltip menu
61 const auto tooltipMenu = ACDialog->getElement()->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
62 // check if create button or label
63 if (attrProperty->isVClass() && (attrProperty->getAttr() != SUMO_ATTR_DISALLOW)) {
64 myAttributeButton = new MFXButtonTooltip(this, tooltipMenu, attrProperty->getAttrStr(), nullptr, this,
65 MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW, GUIDesignButtonAttribute);
66 myAttributeButton->setTipText(TL("Open dialog for editing vClasses"));
67 } else if (attrProperty->isColor()) {
68 myAttributeButton = new MFXButtonTooltip(this, tooltipMenu, attrProperty->getAttrStr(), GUIIconSubSys::getIcon(GUIIcon::COLORWHEEL), this,
69 MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_COLOR, GUIDesignButtonAttribute);
70 myAttributeButton->setTipText(TL("Open dialog for editing color"));
71 } else {
72 // create label
73 new FXLabel(this, attrProperty->getAttrStr().c_str(), nullptr, GUIDesignLabelThickedFixed(100));
74 }
75 // continue depending of attr type
76 if (attrProperty->isBool()) {
77 // create lef boolean checkBox for enable/disable attributes
78 myCheckButton = new FXCheckButton(this, "bool", this, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GUIDesignCheckButton);
79 // continue depending of current value
80 if (ACDialog->getElement()->getAttribute(attrProperty->getAttr()) == GNEAttributeCarrier::TRUE_STR) {
81 myCheckButton->setCheck(TRUE);
82 myCheckButton->setText(TL("true"));
83 } else {
84 myCheckButton->setCheck(FALSE);
85 myCheckButton->setText(TL("false"));
86 }
87 } else {
88 // create text field
90 // set attribute
91 myTextField->setText(ACDialog->getElement()->getAttribute(attrProperty->getAttr()).c_str());
92 }
93}
94
95
96long
98 auto undoList = myACDialogParent->getElement()->getNet()->getViewNet()->getUndoList();
99 if (obj == myTextField) {
100 if (myACDialogParent->getElement()->isValid(myAttrProperty->getAttr(), myTextField->getText().text())) {
101 // set attribute
102 myACDialogParent->getElement()->setAttribute(myAttrProperty->getAttr(), myTextField->getText().text(), undoList);
103 // set valid color and kill focus
106 myTextField->killFocus();
107 } else {
108 // set invalid color
109 myTextField->setTextColor(GUIDesignTextColorRed);
110 // set background color
111 if (myTextField->getText().empty()) {
113 } else {
115 }
116 }
117 } else if (obj == myCheckButton) {
118 if (myCheckButton->getCheck() == TRUE) {
119 myACDialogParent->getElement()->setAttribute(myAttrProperty->getAttr(), GNEAttributeCarrier::TRUE_STR, undoList);
120 myCheckButton->setText(TL("true"));
121 } else {
122 myACDialogParent->getElement()->setAttribute(myAttrProperty->getAttr(), GNEAttributeCarrier::FALSE_STR, undoList);
123 myCheckButton->setText(TL("false"));
124 }
125 }
126 return 1;
127}
128
129
130long
133 // If previous attribute wasn't correct, set black as default color
135 color = GNEAttributeCarrier::parse<RGBColor>(myTextField->getText().text());
136 } else if (myAttrProperty->hasDefaultValue()) {
137 color = myAttrProperty->getDefaultColorValue();
138 }
139 // declare colorDialog
140 const auto colorDialog = new GNEColorDialog(myACDialogParent->getApplicationWindow(), color);
141 // continue depending of result
142 if (colorDialog->getResult() == GNEDialog::Result::ACCEPT) {
143 myTextField->setText(toString(colorDialog->getColor()).c_str(), TRUE);
144 }
145 return 1;
146}
147
148
149long
151 // declare allowVClassesDialog
152 const auto allowVClassesDialog = new GNEVClassesDialog(myACDialogParent->getApplicationWindow(), myAttrProperty->getAttr(),
153 myTextField->getText().text());
154 // continue depending of result
155 if (allowVClassesDialog->getResult() == GNEDialog::Result::ACCEPT) {
156 myTextField->setText(allowVClassesDialog->getModifiedVClasses().c_str(), TRUE);
157 }
158 return 1;
159}
160
161// ---------------------------------------------------------------------------
162// GNEAttributeCarrierDialog - methods
163// ---------------------------------------------------------------------------
164
167 // Create auxiliar frames for rows
168 FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
169 FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));
170 FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));
171 // calculate number of attributes
172 std::vector<const GNEAttributeProperties*> attrProperties;
173 for (const auto& attrProperty : myElement->getTagProperty()->getAttributeProperties()) {
174 // check if this attribute can be edited in edit mode and in basic editor
175 if (attrProperty->isEditMode() && attrProperty->isBasicEditor()) {
176 attrProperties.push_back(attrProperty);
177 }
178 }
179 // spread attributes in two columns
180 for (size_t i = 0; i < attrProperties.size(); i++) {
181 // create attribute text field
182 auto attributeTextField = new AttributeTextField(this, (i % 2 == 0) ? columnLeft : columnRight, attrProperties[i]);
183 // add to myAttributeTextFields vector
184 myAttributeTextFields.push_back(attributeTextField);
185 }
186 // init commandGroup
187 myElement->getNet()->getViewNet()->getUndoList()->begin(myElement, TLF("edit % '%'", AC->getTagStr(), AC->getID()));
188 // open dialog
189 openDialog();
190}
191
192
194
195
196void
198 // nothing to do
199}
200
201
202long
203GNEAttributeCarrierDialog::onCmdAccept(FXObject*, FXSelector, void*) {
204 // close dialog accepting changes
205 return acceptElementDialog();
206}
207
208
209long
210GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {
211 // reset changes
212 resetChanges();
213 return 1;
214}
215
216/****************************************************************************/
FXDEFMAP(GNEAttributeCarrierDialog::AttributeTextField) AttributeTextFieldMap[]
DialogType
@ MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE
set attribute (string, bool, etc.) in attributes editor row
@ MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_COLOR
open color dialog in attributes editor row
@ MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW
open allow dialog in attributes editor row
#define GUIDesignTextColorRed
red color (for invalid text)
Definition GUIDesigns.h:44
#define GUIDesignTextField
Definition GUIDesigns.h:74
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignBackgroundColorRed
red background color (for invalid text)
Definition GUIDesigns.h:50
#define GUIDesignAuxiliarFrameFixedWidth(width)
design for auxiliar (Without borders) frame with fixed width and extended height
Definition GUIDesigns.h:415
#define GUIDesignTextColorBlack
black color (for correct text)
Definition GUIDesigns.h:38
#define GUIDesignBackgroundColorWhite
white background color (for valid text)
Definition GUIDesigns.h:47
@ EMPTY
Definition GUIIcons.h:59
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
@ SUMO_ATTR_DISALLOW
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
long onCmdSetAttribute(FXObject *obj, FXSelector, void *)
event after edit text field
const GNEAttributeProperties * myAttrProperty
attribute property
FXCheckButton * myCheckButton
check button for true/false
MFXTextFieldIcon * myTextField
text field for attribute
long onCmdOpenColorDialog(FXObject *sender, FXSelector, void *arg)
called when user press "edit color" dialog
long onCmdOpenVClassDialog(FXObject *, FXSelector, void *)
called when user press vClass dialog
AttributeTextField(GNEAttributeCarrierDialog *ACDialog, FXVerticalFrame *verticalFrame, const GNEAttributeProperties *attrProperty)
constructor
GNEAttributeCarrierDialog * myACDialogParent
FOX needs this.
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
GNEAttributeCarrierDialog(GNEAttributeCarrier *AC)
constructor
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
std::vector< AttributeTextField * > myAttributeTextFields
list of attribute text fields
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
static const std::string FALSE_STR
true value in string format(used for comparing boolean values in getAttribute(...))
static const std::string TRUE_STR
true value in string format (used for comparing boolean values in getAttribute(......
const std::string getID() const override
get ID (all Attribute Carriers have one)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
const std::string & getTagStr() const
get tag assigned to this object in string format
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
void openDialog(FXWindow *focusableElement=nullptr)
GNETemplateElementDialog(GNEAttributeCarrier *element, DialogType type)
dialog arguments, used for certain modal dialogs that can not be edited using tab
static const RGBColor BLACK
Definition RGBColor.h:196