Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAttributesCreatorRow.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// Row used in AttributesCreator
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
24#include <netedit/GNEViewNet.h>
33
36
37// ===========================================================================
38// FOX callback mapping
39// ===========================================================================
40
46
47// Object implementation
48FXIMPLEMENT(GNEAttributesCreatorRow, FXHorizontalFrame, RowCreatorMap, ARRAYNUMBER(RowCreatorMap))
49
50
51// ===========================================================================
52// method definitions
53// ===========================================================================
54
56 FXHorizontalFrame(AttributesCreatorParent->getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame),
57 myAttributesCreatorParent(AttributesCreatorParent),
58 myAttrProperties(attrProperties) {
59 // Create left visual elements
60 myAttributeLabel = new MFXLabelTooltip(this,
61 AttributesCreatorParent->getFrameParent()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
62 TL("name"), nullptr, GUIDesignLabelThickedFixed(100));
63 myAttributeLabel->hide();
64 myEnableAttributeCheckButton = new FXCheckButton(this, TL("name"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButtonAttribute);
65 myEnableAttributeCheckButton->hide();
67 myAttributeColorButton->hide();
69 myAttributeAllowButton->hide();
70 // Create right visual elements
71 myValueTextField = new FXTextField(this, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
72 myValueTextField->hide();
73 myValueCheckButton = new FXCheckButton(this, TL("Disabled"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
74 myValueCheckButton->hide();
77 myValueComboBox->hide();
78 // only create if parent was created
79 if (getParent()->id()) {
80 // create GNEAttributesCreatorRow
81 FXHorizontalFrame::create();
82 // refresh row
83 refreshRow();
84 // show GNEAttributesCreatorRow
85 show();
86 }
87}
88
89
90void
92 // only destroy if parent was created
93 if (getParent()->id()) {
94 FXHorizontalFrame::destroy();
95 }
96}
97
98
103
104
105std::string
107 if (myAttrProperties->isBool()) {
108 return (myValueCheckButton->getCheck() == 1) ? "1" : "0";
109 } else if (myAttrProperties->isDiscrete()) {
110 return myValueComboBox->getText().text();
111 } else {
112 return myValueTextField->getText().text();
113 }
114}
115
116
117bool
119 if (shown()) {
120 return myEnableAttributeCheckButton->getCheck() == TRUE;
121 } else {
122 return false;
123 }
124}
125
126
127void
129 if (shown()) {
130 // set radio button
131 myEnableAttributeCheckButton->setCheck(value);
132 // enable or disable input fields
133 if (value) {
134 if (myAttrProperties->isBool()) {
135 myValueCheckButton->enable();
136 } else if (myAttrProperties->isDiscrete()) {
138 } else {
139 myValueTextField->enable();
140 }
141 } else {
142 if (myAttrProperties->isBool()) {
143 myValueCheckButton->disable();
144 } else if (myAttrProperties->isDiscrete()) {
146 } else {
147 myValueTextField->disable();
148 }
149 }
150 }
151}
152
153
154void
156 if (myAttrProperties->isBool()) {
157 return myValueCheckButton->enable();
158 } else if (myAttrProperties->isDiscrete()) {
160 } else {
161 return myValueTextField->enable();
162 }
163}
164
165
166void
168 if (myAttrProperties->isBool()) {
169 return myValueCheckButton->disable();
170 } else if (myAttrProperties->isDiscrete()) {
172 } else {
173 return myValueTextField->disable();
174 }
175}
176
177
178bool
180 if (!shown()) {
181 return false;
182 } else if (myAttrProperties->isBool()) {
183 return myValueCheckButton->isEnabled();
184 } else if (myAttrProperties->isDiscrete()) {
185 return myValueComboBox->isEnabled();
186 } else {
187 return myValueTextField->isEnabled();
188 }
189}
190
191
192void
194 // reset invalid value
195 myInvalidValue.clear();
196 // special case for attribute ID
198 // show label
199 myAttributeLabel->setText(myAttrProperties->getAttrStr().c_str());
200 myAttributeLabel->setTipText(myAttrProperties->getDefinition().c_str());
201 myAttributeLabel->show();
202 // generate ID
203 myValueTextField->setText(generateID().c_str());
204 // show textField
205 myValueTextField->setTextColor(FXRGB(0, 0, 0));
206 myValueTextField->killFocus();
207 myValueTextField->show();
208 } else {
209 // left
210 if (myAttrProperties->isColor()) {
211 // show color button
212 myAttributeColorButton->setTextColor(FXRGB(0, 0, 0));
213 myAttributeColorButton->killFocus();
216 // show allow button
217 myAttributeAllowButton->setTextColor(FXRGB(0, 0, 0));
218 myAttributeAllowButton->killFocus();
220 } else if (myAttrProperties->isActivatable()) {
221 // show check button
224 // enable or disable depending of template AC
226 myEnableAttributeCheckButton->setCheck(TRUE);
227 } else {
228 myEnableAttributeCheckButton->setCheck(FALSE);
229 }
230 } else {
231 // show label
232 myAttributeLabel->setText(myAttrProperties->getAttrStr().c_str());
233 myAttributeLabel->setTipText(myAttrProperties->getDefinition().c_str());
234 myAttributeLabel->show();
235 }
236 // right
237 if (myAttrProperties->isBool()) {
238 if (GNEAttributeCarrier::parse<bool>(myAttributesCreatorParent->getCurrentTemplateAC()->getAttribute(myAttrProperties->getAttr()))) {
239 myValueCheckButton->setCheck(true);
240 myValueCheckButton->setText("true");
241 } else {
242 myValueCheckButton->setCheck(false);
243 myValueCheckButton->setText("false");
244 }
245 myValueCheckButton->show();
246 // check if enable or disable
248 myValueCheckButton->enable();
249 } else {
250 myValueCheckButton->disable();
251 }
252 } else if (myAttrProperties->isDiscrete()) {
253 // fill textField
255 // check if add POI icons
257 for (const auto& POIIcon : SUMOXMLDefinitions::POIIcons.getValues()) {
259 }
260 } else {
261 for (const auto& item : myAttrProperties->getDiscreteValues()) {
262 myValueComboBox->appendIconItem(item.c_str());
263 }
264 }
266 if (index < 0) {
268 } else {
270 }
272 myValueComboBox->setTextColor(FXRGB(128, 128, 128));
273 } else {
274 myValueComboBox->setTextColor(FXRGB(0, 0, 0));
275 myValueComboBox->killFocus();
276 }
277 myValueComboBox->show();
278 // check if enable or disable
281 } else {
283 }
284 } else {
285 myValueTextField->setTextColor(FXRGB(0, 0, 0));
286 myValueTextField->killFocus();
289 myValueTextField->setTextColor(FXRGB(128, 128, 128));
290 } else {
291 myValueTextField->setTextColor(FXRGB(0, 0, 0));
292 myValueTextField->killFocus();
293 }
294 myValueTextField->show();
295 // check if enable or disable
297 myValueTextField->enable();
298 } else {
299 myValueTextField->disable();
300 }
301 }
302 }
303}
304
305
306void
308 myAttributeLabel->disable();
310 myAttributeColorButton->disable();
311 myAttributeAllowButton->disable();
312 myValueTextField->disable();
314 myValueCheckButton->disable();
315}
316
317
318bool
320 return (myValueTextField->getTextColor() != FXRGB(255, 0, 0) &&
321 myValueComboBox->getTextColor() != FXRGB(255, 0, 0));
322}
323
324
329
330
331long
332GNEAttributesCreatorRow::onCmdSetAttribute(FXObject* obj, FXSelector, void*) {
333 // check what object was called
334 if (obj == myEnableAttributeCheckButton) {
335 if (myEnableAttributeCheckButton->getCheck()) {
336 // enable text field
337 if (myValueTextField->shown()) {
338 myValueTextField->enable();
339 }
340 // enable comboBox
341 if (myValueComboBox->shown()) {
343 }
344 // enable check button
345 if (myValueCheckButton->shown()) {
346 myValueCheckButton->enable();
347 }
349 } else {
350 // disable text field
351 if (myValueTextField->shown()) {
352 myValueTextField->disable();
353 }
354 // disable text field
355 if (myValueComboBox->shown()) {
357 }
358 // disable check button
359 if (myValueCheckButton->shown()) {
360 myValueCheckButton->disable();
361 }
363 }
364 } else if (obj == myValueCheckButton) {
365 if (myValueCheckButton->getCheck()) {
366 myValueCheckButton->setText("true");
368 } else {
369 myValueCheckButton->setText("false");
371 }
372 } else if (obj == myValueComboBox) {
373 // check if use default value
374 const bool useDefaultValue = (myValueComboBox->getText().empty() && myAttrProperties->hasDefaultValue());
375 // change color of text field depending of myCurrentValueValid
377 // check color depending if is a default value
378 if (useDefaultValue || (myAttrProperties->hasDefaultValue() && (myAttrProperties->getDefaultValue() == myValueComboBox->getText().text()))) {
379 myValueComboBox->setTextColor(FXRGB(128, 128, 128));
380 } else {
381 myValueComboBox->setTextColor(FXRGB(0, 0, 0));
382 myValueComboBox->killFocus();
383 }
384 // check if use default value
385 if (useDefaultValue) {
387 // refresh entire GNEAttributesCreator
389 } else {
391 }
392 // special case for trigger stops (in the future will be changed)
394 // refresh entire GNEAttributesCreator
396 }
397 } else {
398 // if value of TextField isn't valid, change their color to Red
399 myValueComboBox->setTextColor(FXRGB(255, 0, 0));
400 myValueComboBox->killFocus();
401 }
402 } else if (obj == myValueTextField) {
403 // check if use default value
404 const bool useDefaultValue = (myValueTextField->getText().empty() && myAttrProperties->hasDefaultValue());
405 // change color of text field depending of myCurrentValueValid
406 if (myAttributesCreatorParent->getCurrentTemplateAC()->isValid(myAttrProperties->getAttr(), myValueTextField->getText().text()) || useDefaultValue) {
407 // check color depending if is a default value
408 if (useDefaultValue || (myAttrProperties->hasDefaultValue() && (myAttrProperties->getDefaultValue() == myValueTextField->getText().text()))) {
409 myValueTextField->setTextColor(FXRGB(128, 128, 128));
410 } else {
411 myValueTextField->setTextColor(FXRGB(0, 0, 0));
412 myValueTextField->killFocus();
413 }
414 // check if use default value
415 if (useDefaultValue) {
417 // refresh entire GNEAttributesCreator
419 } else {
421 }
422 } else {
423 // if value of TextField isn't valid, change their color to Red
424 myValueTextField->setTextColor(FXRGB(255, 0, 0));
425 myValueComboBox->killFocus();
426 }
427 }
428 // Update row
429 update();
430 return 1;
431}
432
433
434long
436 // create FXColorDialog
437 FXColorDialog colordialog(this, TL("Color Dialog"));
438 colordialog.setTarget(this);
439 colordialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::COLORWHEEL));
440 // If previous attribute wasn't correct, set black as default color
441 if (GNEAttributeCarrier::canParse<RGBColor>(myValueTextField->getText().text())) {
442 colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myValueTextField->getText().text())));
443 } else {
444 colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myAttrProperties->getDefaultValue())));
445 }
446 // execute dialog to get a new color
447 if (colordialog.execute()) {
448 myValueTextField->setText(toString(MFXUtils::getRGBColor(colordialog.getRGBA())).c_str(), TRUE);
449 }
450 return 0;
451}
452
453
454long
456 // declare bool for accept changes
457 bool acceptChanges = false;
458 // get allow string
459 std::string allow = myValueTextField->getText().text();
460 // opena allowDisallow dialog
462 // continue depending of acceptChanges
463 if (acceptChanges) {
464 // update text field
465 myValueTextField->setText(allow.c_str(), TRUE);
466 }
467 return 0;
468}
469
470
471std::string
473 // get attribute carriers
474 const auto& GNEAttributeCarriers = myAttributesCreatorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
475 // continue depending of type
477 return GNEAttributeCarriers->generateAdditionalID(myAttrProperties->getTagPropertyParent()->getTag());
479 return GNEAttributeCarriers->generateDemandElementID(myAttrProperties->getTagPropertyParent()->getTag());
480 } else {
481 return "";
482 }
483}
484
485
486bool
498
499/****************************************************************************/
FXDEFMAP(GNEAttributesCreatorRow) RowCreatorMap[]
@ MID_GNE_ATTRIBUTESEDITORROW_OPENALLOWDIALLOG
open allow dialog in attributes editor row
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_GNE_ATTRIBUTESEDITORROW_OPENCOLORDIALOG
open color dialog in attributes editor row
#define GUIDesignButtonAttribute
button extended over over column with thick and raise frame
Definition GUIDesigns.h:88
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition GUIDesigns.h:302
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:311
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:49
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:192
#define GUIDesignCheckButtonAttribute
checkButton without thick extended over the frame used for attributes
Definition GUIDesigns.h:201
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:252
#define TL(string)
Definition MsgHandler.h:301
POIIcon
POI icons.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_ICON
icon
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_TRIGGERED
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Dialog for edit rerouters.
virtual void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
virtual bool isAttributeEnabled(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool isColor() const
return true if attribute is a color
bool isSVCPermission() const
return true if attribute is a VehicleClass
bool isBool() const
return true if attribute is boolean
const std::string & getAttrStr() const
get XML Attribute
bool isDiscrete() const
return true if attribute is discrete
const std::string & getDefaultValue() const
get default value
const std::string & getDefinition() const
get default value
const GNETagProperties * getTagPropertyParent() const
get reference to tagProperty parent
bool hasDefaultValue() const
return true if attribute owns a default value
bool isActivatable() const
return true if attribute is activatable
const std::vector< std::string > & getDiscreteValues() const
get discrete values
SumoXMLAttr getAttr() const
get XML Attribute
bool hasAutomaticID() const
return true if attribute ID can generate an automatic ID
GNEAttributeCarrier * getCurrentTemplateAC() const
get current template AC
GNEFrame * getFrameParent() const
return frame parent
void refreshAttributesCreator()
refresh attribute creator
std::string generateID() const
FOX needs this.
MFXLabelTooltip * myAttributeLabel
Label with the name of the attribute.
FXButton * myAttributeColorButton
Button for open color editor.
FXTextField * myValueTextField
textField to modify the default value of string parameters
FXCheckButton * myValueCheckButton
check button to enable/disable the value of boolean parameters
bool getAttributeCheckButtonCheck() const
return status of label checkbox button
bool isValidID() const
check if current ID placed in myValueTextField is valid
long onCmdOpenAllowDialog(FXObject *, FXSelector, void *)
called when user press the allow dialog button
bool isAttributesCreatorRowEnabled() const
check if row is enabled
long onCmdSetAttribute(FXObject *, FXSelector, void *)
std::string getValue() const
return value
const GNEAttributeProperties * myAttrProperties
attribute properties
void destroy()
destroy GNEAttributesCreatorRow (but don't delete)
FXButton * myAttributeAllowButton
Button for open allow editor.
bool isAttributeValid() const
check if current attribute is valid
void disableAttributesCreatorRow()
disable row
long onCmdOpenColorDialog(FXObject *, FXSelector, void *)
called when user press the color dialog button
MFXComboBoxIcon * myValueComboBox
comboBox for discrete vaues
void setAttributeCheckButtonCheck(bool value)
enable or disable label checkbox button for Terminatel attributes
const GNEAttributeProperties * getAttrProperties() const
return Attr
GNEAttributesCreator * myAttributesCreatorParent
pointer to GNEAttributesCreator
FXCheckButton * myEnableAttributeCheckButton
check button to enable/disable Label attribute
std::string myInvalidValue
string which indicates the reason due current value is invalid
GNEAttributesCreator * getAttributesCreatorParent() const
get GNEAttributesCreator parent
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:153
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
std::string generateAdditionalID(SumoXMLTag type) const
generate additional id
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:133
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool isDemandElement() const
return true if tag correspond to a demand element
bool isAdditionalElement() const
return true if tag correspond to an additional element (note: this include TAZ, shapes and wires)
bool isVehicleStop() const
return true if tag correspond to a vehicle stop element
GNENet * getNet() const
get the net object
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
ComboBox with icon.
long setCurrentItem(const FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
FXint findItem(const FXString &text) const
find item
FXString getText() const
Get the text.
void setTextColor(FXColor clr)
Change text color.
void clearItems()
Remove all items from the list.
void disable()
Disable combo box.
FXColor getTextColor() const
Return text color.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon item in the last position
void enable()
Enable combo box.
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition MFXUtils.cpp:112
static RGBColor getRGBColor(FXColor col)
converts FXColor to RGBColor
Definition MFXUtils.cpp:106
static FXIcon * getPOIIcon(POIIcon iconType)
returns icon associated to the given POI image
Definition POIIcons.cpp:30
static StringBijection< POIIcon > POIIcons
POI icon values.
std::vector< T > getValues() const