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()->getGNEApplicationWindow()->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,
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,
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()->getUndoList();
99 if (obj == myTextField) {
101 // set attribute
103 // set valid color and kill focus
107 } else {
108 // set invalid color
110 // set background color
111 if (myTextField->getText().empty()) {
113 } else {
115 }
116 }
117 } else if (obj == myCheckButton) {
118 if (myCheckButton->getCheck() == TRUE) {
120 myCheckButton->setText(TL("true"));
121 } else {
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
134 if (GNEAttributeCarrier::canParse<RGBColor>(myTextField->getText().text())) {
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(), myACDialogParent, 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(), myACDialogParent,
153 myAttrProperty->getAttr(), 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
170
171
177
178
180
181
182void
184 // nothing to do
185}
186
187
188long
189GNEAttributeCarrierDialog::onCmdAccept(FXObject*, FXSelector, void*) {
190 // close dialog accepting changes
191 return acceptElementDialog();
192}
193
194
195long
196GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {
197 // reset changes
198 resetChanges();
199 return 1;
200}
201
202
203void
205 // Create auxiliar frames for rows
206 FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
207 FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));
208 FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));
209 // calculate number of attributes
210 std::vector<const GNEAttributeProperties*> attrProperties;
211 for (const auto& attrProperty : myElement->getTagProperty()->getAttributeProperties()) {
212 // check if this attribute can be edited in edit mode and in basic editor
213 if (attrProperty->isEditMode() && attrProperty->isBasicEditor()) {
214 attrProperties.push_back(attrProperty);
215 }
216 }
217 // spread attributes in two columns
218 for (size_t i = 0; i < attrProperties.size(); i++) {
219 // create attribute text field
220 auto attributeTextField = new AttributeTextField(this, (i % 2 == 0) ? columnLeft : columnRight, attrProperties[i]);
221 // add to myAttributeTextFields vector
222 myAttributeTextFields.push_back(attributeTextField);
223 }
224 // open dialog
225 openDialog();
226}
227
228
229/****************************************************************************/
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 GUIDesignButtonAttribute
button extended over over column with thick and raise frame
Definition GUIDesigns.h:106
#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
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:194
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:254
#define TL(string)
Definition MsgHandler.h:304
@ 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
GNEAttributeCarrierDialog * myACDialogParent
FOX needs this.
void builder(GNEAttributeCarrier *AC)
builder
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 GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
GNENet * getNet() const
get pointer to net
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
SumoXMLAttr getAttr() const
get XML Attribute
FXVerticalFrame * myContentFrame
content frame
Definition GNEDialog.h:159
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
GNEAttributeCarrier * 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
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
dialog arguments, used for certain modal dialogs that can not be edited using tab
virtual void killFocus()
Remove the focus from this window.
FXString getText() const
Get the text for this label.
void setTextColor(FXColor clr)
Change text color.
static const RGBColor BLACK
Definition RGBColor.h:196