Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/elements/GNEAttributeCarrierDialog.cpp
193871 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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()->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,
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()->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(), 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
149
long
150
GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenVClassDialog(FXObject*, FXSelector, void*) {
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
165
GNEAttributeCarrierDialog::GNEAttributeCarrierDialog(GNEAttributeCarrier* AC) :
166
GNETemplateElementDialog<GNEAttributeCarrier>(AC, DialogType::ATTRIBUTECARRIER) {
167
// build dialog
168
builder(AC);
169
}
170
171
172
GNEAttributeCarrierDialog::GNEAttributeCarrierDialog(GNEAttributeCarrier* AC, GNEDialog* parentDialog) :
173
GNETemplateElementDialog<GNEAttributeCarrier>(AC, parentDialog, DialogType::ATTRIBUTECARRIER) {
174
// build dialog
175
builder(AC);
176
}
177
178
179
GNEAttributeCarrierDialog::~GNEAttributeCarrierDialog() {}
180
181
182
void
183
GNEAttributeCarrierDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
184
// nothing to do
185
}
186
187
188
long
189
GNEAttributeCarrierDialog::onCmdAccept(FXObject*, FXSelector, void*) {
190
// close dialog accepting changes
191
return acceptElementDialog();
192
}
193
194
195
long
196
GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {
197
// reset changes
198
resetChanges();
199
return 1;
200
}
201
202
203
void
204
GNEAttributeCarrierDialog::builder(GNEAttributeCarrier* /* AC */) {
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
/****************************************************************************/
230
231