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,
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()->getViewNet()->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(), 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 if (false) {
205 // open warning Box
207 TLF("Error editing % '%'", myElement->getTagStr(), myElement->getID()),
208 TLF("The % '%' cannot be updated because there are invalid attributes.",
210 return 1;
211 } else {
212 // close dialog accepting changes
213 return acceptElementDialog();
214 }
215}
216
217
218long
219GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {
220 // reset changes
221 resetChanges();
222 return 1;
223}
224
225/****************************************************************************/
FXDEFMAP(GNEAttributeCarrierDialog::AttributeTextField) AttributeTextFieldMap[]
@ 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:305
#define TLF(string,...)
Definition MsgHandler.h:307
@ 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 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
const std::string getID() const
get ID (all Attribute Carriers have one)
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 & getTagStr() const
get tag assigned to this object in string format
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:135
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
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