Skip to content

Commit 0d644a3

Browse files
committed
Updated GNEAttributeCarrierDialog. Refs #16898
1 parent 693c5a4 commit 0d644a3

File tree

4 files changed

+89
-38
lines changed

4 files changed

+89
-38
lines changed

src/netedit/dialogs/elements/GNEAttributeCarrierDialog.cpp

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <netedit/changes/GNEChange_Attribute.h>
2222
#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>
23+
#include <netedit/dialogs/GNEColorDialog.h>
24+
#include <netedit/dialogs/GNEVClassesDialog.h>
2325
#include <netedit/GNEApplicationWindow.h>
2426
#include <netedit/GNENet.h>
2527
#include <netedit/GNEUndoList.h>
@@ -34,8 +36,9 @@
3436
// ===========================================================================
3537

3638
FXDEFMAP(GNEAttributeCarrierDialog::AttributeTextField) AttributeTextFieldMap[] = {
37-
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE, GNEAttributeCarrierDialog::AttributeTextField::onCmdSetAttribute),
38-
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE_BOOL, GNEAttributeCarrierDialog::AttributeTextField::onCmdSetBoolAttribute),
39+
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GNEAttributeCarrierDialog::AttributeTextField::onCmdSetAttribute),
40+
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_COLOR, GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenColorDialog),
41+
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW, GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenVClassDialog),
3942
};
4043

4144
// Object implementation
@@ -52,14 +55,27 @@ FXIMPLEMENT(GNEAttributeCarrierDialog::AttributeTextField, FXHorizontalFrame, At
5255
GNEAttributeCarrierDialog::AttributeTextField::AttributeTextField(GNEAttributeCarrierDialog* ACDialog, FXVerticalFrame* verticalFrame,
5356
const GNEAttributeProperties* attrProperty) :
5457
FXHorizontalFrame(verticalFrame, GUIDesignAuxiliarHorizontalFrame),
55-
myACDialog(ACDialog),
58+
myACDialogParent(ACDialog),
5659
myAttrProperty(attrProperty) {
57-
// create label
58-
new FXLabel(this, attrProperty->getAttrStr().c_str(), nullptr, GUIDesignLabelThickedFixed(100));
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+
}
5975
// continue depending of attr type
6076
if (attrProperty->isBool()) {
6177
// create lef boolean checkBox for enable/disable attributes
62-
myCheckButton = new FXCheckButton(this, "bool", this, MID_GNE_SET_ATTRIBUTE_BOOL, GUIDesignCheckButtonAttribute);
78+
myCheckButton = new FXCheckButton(this, "bool", this, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GUIDesignCheckButton);
6379
// continue depending of current value
6480
if (ACDialog->getElement()->getAttribute(attrProperty->getAttr()) == GNEAttributeCarrier::TRUE_STR) {
6581
myCheckButton->setCheck(TRUE);
@@ -70,45 +86,74 @@ GNEAttributeCarrierDialog::AttributeTextField::AttributeTextField(GNEAttributeCa
7086
}
7187
} else {
7288
// create text field
73-
myTextField = new MFXTextFieldTooltip(this, ACDialog->getElement()->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
74-
GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
89+
myTextField = new MFXTextFieldTooltip(this, tooltipMenu, GUIDesignTextFieldNCol, this, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GUIDesignTextField);
7590
// set attribute
7691
myTextField->setText(ACDialog->getElement()->getAttribute(attrProperty->getAttr()).c_str());
7792
}
7893
}
7994

8095

8196
long
82-
GNEAttributeCarrierDialog::AttributeTextField::onCmdSetAttribute(FXObject*, FXSelector, void*) {
83-
if (myACDialog->getElement()->isValid(myAttrProperty->getAttr(), myTextField->getText().text())) {
84-
// set attribute
85-
myACDialog->getElement()->setAttribute(myAttrProperty->getAttr(), myTextField->getText().text(), myACDialog->getElement()->getNet()->getViewNet()->getUndoList());
86-
// set valid color and kill focus
87-
myTextField->setTextColor(GUIDesignTextColorBlack);
88-
myTextField->setBackColor(GUIDesignBackgroundColorWhite);
89-
myTextField->killFocus();
90-
} else {
91-
// set invalid color
92-
myTextField->setTextColor(GUIDesignTextColorRed);
93-
// set background color
94-
if (myTextField->getText().empty()) {
95-
myTextField->setTextColor(GUIDesignBackgroundColorRed);
96-
} else {
97+
GNEAttributeCarrierDialog::AttributeTextField::onCmdSetAttribute(FXObject* obj, FXSelector, void*) {
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
104+
myTextField->setTextColor(GUIDesignTextColorBlack);
97105
myTextField->setBackColor(GUIDesignBackgroundColorWhite);
106+
myTextField->killFocus();
107+
} else {
108+
// set invalid color
109+
myTextField->setTextColor(GUIDesignTextColorRed);
110+
// set background color
111+
if (myTextField->getText().empty()) {
112+
myTextField->setTextColor(GUIDesignBackgroundColorRed);
113+
} else {
114+
myTextField->setBackColor(GUIDesignBackgroundColorWhite);
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"));
98124
}
99125
}
100126
return 1;
101127
}
102128

103129

104130
long
105-
GNEAttributeCarrierDialog::AttributeTextField::onCmdSetBoolAttribute(FXObject*, FXSelector, void*) {
106-
if (myCheckButton->getCheck() == TRUE) {
107-
myACDialog->getElement()->setAttribute(myAttrProperty->getAttr(), GNEAttributeCarrier::TRUE_STR, myACDialog->getElement()->getNet()->getViewNet()->getUndoList());
108-
myCheckButton->setText(TL("true"));
109-
} else {
110-
myACDialog->getElement()->setAttribute(myAttrProperty->getAttr(), GNEAttributeCarrier::FALSE_STR, myACDialog->getElement()->getNet()->getViewNet()->getUndoList());
111-
myCheckButton->setText(TL("false"));
131+
GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenColorDialog(FXObject*, FXSelector, void*) {
132+
RGBColor color = RGBColor::BLACK;
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+
149+
long
150+
GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenVClassDialog(FXObject*, FXSelector, void*) {
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);
112157
}
113158
return 1;
114159
}

src/netedit/dialogs/elements/GNEAttributeCarrierDialog.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,28 @@ class GNEAttributeCarrierDialog : public GNETemplateElementDialog<GNEAttributeCa
5050
/// @{
5151

5252
/// @brief event after edit text field
53-
long onCmdSetAttribute(FXObject*, FXSelector, void*);
53+
long onCmdSetAttribute(FXObject* obj, FXSelector, void*);
5454

55-
/// @brief event after edit checkBox
56-
long onCmdSetBoolAttribute(FXObject*, FXSelector, void*);
55+
/// @brief called when user press "edit color" dialog
56+
long onCmdOpenColorDialog(FXObject* sender, FXSelector, void* arg);
57+
58+
/// @brief called when user press vClass dialog
59+
long onCmdOpenVClassDialog(FXObject*, FXSelector, void*);
5760

5861
/// @}
5962

6063
protected:
6164
/// @brief FOX needs this
6265
FOX_CONSTRUCTOR(AttributeTextField)
6366

67+
/// @brief pointer to ACDialog parent
68+
GNEAttributeCarrierDialog* myACDialogParent = nullptr;
69+
6470
/// @brief attribute property
6571
const GNEAttributeProperties* myAttrProperty = nullptr;
6672

67-
/// @brief pointer to ACDialog parent
68-
GNEAttributeCarrierDialog* myACDialog = nullptr;
73+
/// @brief attribute button (color or allow)
74+
MFXButtonTooltip* myAttributeButton = nullptr;
6975

7076
/// @brief text field for attribute
7177
MFXTextFieldTooltip* myTextField = nullptr;

src/netedit/frames/GNEAttributesEditorRow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FXDEFMAP(GNEAttributesEditorRow) GNEAttributeRowMap[] = {
4444
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GNEAttributesEditorRow::onCmdSetAttribute),
4545
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_TOGGLEENABLEATTRIBUTE, GNEAttributesEditorRow::onCmdToggleEnableAttribute),
4646
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_COLOR, GNEAttributesEditorRow::onCmdOpenColorDialog),
47-
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW, GNEAttributesEditorRow::onCmdOpenAllowDialog),
47+
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW, GNEAttributesEditorRow::onCmdOpenVClassDialog),
4848
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_FILE, GNEAttributesEditorRow::onCmdOpenFileDialog),
4949
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_REPARENT, GNEAttributesEditorRow::onCmdReparent),
5050
FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_INSPECTPARENT, GNEAttributesEditorRow::onCmdInspectParent),
@@ -420,7 +420,7 @@ GNEAttributesEditorRow::onCmdOpenColorDialog(FXObject*, FXSelector, void*) {
420420

421421

422422
long
423-
GNEAttributesEditorRow::onCmdOpenAllowDialog(FXObject*, FXSelector, void*) {
423+
GNEAttributesEditorRow::onCmdOpenVClassDialog(FXObject*, FXSelector, void*) {
424424
// declare allowVClassesDialog
425425
const auto allowVClassesDialog = new GNEVClassesDialog(myAttributeTable->getFrameParent()->getViewNet()->getViewParent()->getGNEAppWindows(),
426426
myAttrProperty->getAttr(), myValueTextField->getText().text());

src/netedit/frames/GNEAttributesEditorRow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class GNEAttributesEditorRow : protected FXHorizontalFrame {
7979
long onCmdOpenColorDialog(FXObject* sender, FXSelector, void* arg);
8080

8181
/// @brief called when user press "open allow" dialog
82-
long onCmdOpenAllowDialog(FXObject*, FXSelector, void*);
82+
long onCmdOpenVClassDialog(FXObject*, FXSelector, void*);
8383

8484
/// @brief called when user press "open file" dialog
8585
long onCmdOpenFileDialog(FXObject*, FXSelector, void*);

0 commit comments

Comments
 (0)