Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNEAttributeCarrierDialog.cpp
169684 views
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
/****************************************************************************/
14
/// @file GNEAttributeCarrierDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2025
17
///
18
// Dialog for edit attribute carriers
19
/****************************************************************************/
20
21
#include <netedit/changes/GNEChange_Attribute.h>
22
#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>
23
#include <netedit/dialogs/GNEColorDialog.h>
24
#include <netedit/dialogs/GNEVClassesDialog.h>
25
#include <netedit/GNEApplicationWindow.h>
26
#include <netedit/GNENet.h>
27
#include <netedit/GNEUndoList.h>
28
#include <netedit/GNEViewParent.h>
29
#include <utils/foxtools/MFXTextFieldIcon.h>
30
#include <utils/gui/div/GUIDesigns.h>
31
32
#include "GNEAttributeCarrierDialog.h"
33
34
// ===========================================================================
35
// FOX callback mapping
36
// ===========================================================================
37
38
FXDEFMAP(GNEAttributeCarrierDialog::AttributeTextField) AttributeTextFieldMap[] = {
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),
42
};
43
44
// Object implementation
45
FXIMPLEMENT(GNEAttributeCarrierDialog::AttributeTextField, FXHorizontalFrame, AttributeTextFieldMap, ARRAYNUMBER(AttributeTextFieldMap))
46
47
// ===========================================================================
48
// member method definitions
49
// ===========================================================================
50
51
// ---------------------------------------------------------------------------
52
// GNEAttributeCarrierDialog::AttributeTextField - methods
53
// ---------------------------------------------------------------------------
54
55
GNEAttributeCarrierDialog::AttributeTextField::AttributeTextField(GNEAttributeCarrierDialog* ACDialog, FXVerticalFrame* verticalFrame,
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
89
myTextField = new MFXTextFieldIcon(this, tooltipMenu, GUIIcon::EMPTY, this, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GUIDesignTextField);
90
// set attribute
91
myTextField->setText(ACDialog->getElement()->getAttribute(attrProperty->getAttr()).c_str());
92
}
93
}
94
95
96
long
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);
105
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"));
124
}
125
}
126
return 1;
127
}
128
129
130
long
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);
157
}
158
return 1;
159
}
160
161
// ---------------------------------------------------------------------------
162
// GNEAttributeCarrierDialog - methods
163
// ---------------------------------------------------------------------------
164
165
GNEAttributeCarrierDialog::GNEAttributeCarrierDialog(GNEAttributeCarrier* AC) :
166
GNETemplateElementDialog<GNEAttributeCarrier>(AC, DialogType::ATTRIBUTECARRIER) {
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
193
GNEAttributeCarrierDialog::~GNEAttributeCarrierDialog() {}
194
195
196
void
197
GNEAttributeCarrierDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
198
// nothing to do
199
}
200
201
202
long
203
GNEAttributeCarrierDialog::onCmdAccept(FXObject*, FXSelector, void*) {
204
if (false) {
205
// open warning Box
206
GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),
207
TLF("Error editing % '%'", myElement->getTagStr(), myElement->getID()),
208
TLF("The % '%' cannot be updated because there are invalid attributes.",
209
myElement->getTagStr(), myElement->getID()));
210
return 1;
211
} else {
212
// close dialog accepting changes
213
return acceptElementDialog();
214
}
215
}
216
217
218
long
219
GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {
220
// reset changes
221
resetChanges();
222
return 1;
223
}
224
225
/****************************************************************************/
226
227