Eclipse SUMO - Simulation of Urban MObility
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-2024 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 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewNet.h>
25 #include <netedit/GNEViewParent.h>
33 
35 #include "GNEAttributesCreator.h"
36 
37 
38 // ===========================================================================
39 // FOX callback mapping
40 // ===========================================================================
41 
42 FXDEFMAP(GNEAttributesCreatorRow) RowCreatorMap[] = {
46 };
47 
48 // Object implementation
49 FXIMPLEMENT(GNEAttributesCreatorRow, FXHorizontalFrame, RowCreatorMap, ARRAYNUMBER(RowCreatorMap))
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 
57  FXHorizontalFrame(AttributesCreatorParent->getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame),
58  myAttributesCreatorParent(AttributesCreatorParent),
59  myAttrProperties(attrProperties) {
60  // Create left visual elements
61  myAttributeLabel = new MFXLabelTooltip(this,
62  AttributesCreatorParent->getFrameParent()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
63  TL("name"), nullptr, GUIDesignLabelThickedFixed(100));
64  myAttributeLabel->hide();
65  myEnableAttributeCheckButton = new FXCheckButton(this, TL("name"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButtonAttribute);
66  myEnableAttributeCheckButton->hide();
68  myAttributeColorButton->hide();
70  myAttributeAllowButton->hide();
71  // Create right visual elements
72  myValueTextField = new FXTextField(this, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
73  myValueTextField->hide();
74  myValueCheckButton = new FXCheckButton(this, TL("Disabled"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
75  myValueCheckButton->hide();
78  myValueComboBox->hide();
79  // only create if parent was created
80  if (getParent()->id()) {
81  // create GNEAttributesCreatorRow
82  FXHorizontalFrame::create();
83  // refresh row
84  refreshRow();
85  // show GNEAttributesCreatorRow
86  show();
87  }
88 }
89 
90 
91 void
93  // only destroy if parent was created
94  if (getParent()->id()) {
95  FXHorizontalFrame::destroy();
96  }
97 }
98 
99 
102  return myAttrProperties;
103 }
104 
105 
106 std::string
108  if (myAttrProperties.isBool()) {
109  return (myValueCheckButton->getCheck() == 1) ? "1" : "0";
110  } else if (myAttrProperties.isDiscrete()) {
111  return myValueComboBox->getText().text();
112  } else {
113  return myValueTextField->getText().text();
114  }
115 }
116 
117 
118 bool
120  if (shown()) {
121  return myEnableAttributeCheckButton->getCheck() == TRUE;
122  } else {
123  return false;
124  }
125 }
126 
127 
128 void
130  if (shown()) {
131  // set radio button
132  myEnableAttributeCheckButton->setCheck(value);
133  // enable or disable input fields
134  if (value) {
135  if (myAttrProperties.isBool()) {
136  myValueCheckButton->enable();
137  } else if (myAttrProperties.isDiscrete()) {
139  } else {
140  myValueTextField->enable();
141  }
142  } else {
143  if (myAttrProperties.isBool()) {
144  myValueCheckButton->disable();
145  } else if (myAttrProperties.isDiscrete()) {
147  } else {
148  myValueTextField->disable();
149  }
150  }
151  }
152 }
153 
154 
155 void
157  if (myAttrProperties.isBool()) {
158  return myValueCheckButton->enable();
159  } else if (myAttrProperties.isDiscrete()) {
161  } else {
162  return myValueTextField->enable();
163  }
164 }
165 
166 
167 void
169  if (myAttrProperties.isBool()) {
170  return myValueCheckButton->disable();
171  } else if (myAttrProperties.isDiscrete()) {
173  } else {
174  return myValueTextField->disable();
175  }
176 }
177 
178 
179 bool
181  if (!shown()) {
182  return false;
183  } else if (myAttrProperties.isBool()) {
184  return myValueCheckButton->isEnabled();
185  } else if (myAttrProperties.isDiscrete()) {
186  return myValueComboBox->isEnabled();
187  } else {
188  return myValueTextField->isEnabled();
189  }
190 }
191 
192 
193 void
195  // reset invalid value
196  myInvalidValue.clear();
197  // special case for attribute ID
199  // show label
200  myAttributeLabel->setText(myAttrProperties.getAttrStr().c_str());
201  myAttributeLabel->setTipText(myAttrProperties.getDefinition().c_str());
202  myAttributeLabel->show();
203  // generate ID
204  myValueTextField->setText(generateID().c_str());
205  // show textField
206  myValueTextField->setTextColor(FXRGB(0, 0, 0));
207  myValueTextField->killFocus();
208  myValueTextField->show();
209  } else {
210  // left
211  if (myAttrProperties.isColor()) {
212  // show color button
213  myAttributeColorButton->setTextColor(FXRGB(0, 0, 0));
214  myAttributeColorButton->killFocus();
215  myAttributeColorButton->show();
217  // show allow button
218  myAttributeAllowButton->setTextColor(FXRGB(0, 0, 0));
219  myAttributeAllowButton->killFocus();
220  myAttributeAllowButton->show();
221  } else if (myAttrProperties.isActivatable()) {
222  // show check button
225  // enable or disable depending of template AC
227  myEnableAttributeCheckButton->setCheck(TRUE);
228  } else {
229  myEnableAttributeCheckButton->setCheck(FALSE);
230  }
231  } else {
232  // show label
233  myAttributeLabel->setText(myAttrProperties.getAttrStr().c_str());
234  myAttributeLabel->setTipText(myAttrProperties.getDefinition().c_str());
235  myAttributeLabel->show();
236  }
237  // right
238  if (myAttrProperties.isBool()) {
239  if (GNEAttributeCarrier::parse<bool>(myAttributesCreatorParent->getCurrentTemplateAC()->getAttribute(myAttrProperties.getAttr()))) {
240  myValueCheckButton->setCheck(true);
241  myValueCheckButton->setText("true");
242  } else {
243  myValueCheckButton->setCheck(false);
244  myValueCheckButton->setText("false");
245  }
246  myValueCheckButton->show();
247  // check if enable or disable
249  myValueCheckButton->enable();
250  } else {
251  myValueCheckButton->disable();
252  }
253  } else if (myAttrProperties.isDiscrete()) {
254  // fill textField
256  // check if add POI icons
258  for (const auto& POIIcon : SUMOXMLDefinitions::POIIcons.getValues()) {
260  }
261  } else {
262  for (const auto& item : myAttrProperties.getDiscreteValues()) {
263  myValueComboBox->appendIconItem(item.c_str());
264  }
265  }
267  if (index < 0) {
269  } else {
271  }
273  myValueComboBox->setTextColor(FXRGB(128, 128, 128));
274  } else {
275  myValueComboBox->setTextColor(FXRGB(0, 0, 0));
276  myValueComboBox->killFocus();
277  }
278  myValueComboBox->show();
279  // check if enable or disable
282  } else {
284  }
285  } else {
286  myValueTextField->setTextColor(FXRGB(0, 0, 0));
287  myValueTextField->killFocus();
290  myValueTextField->setTextColor(FXRGB(128, 128, 128));
291  } else {
292  myValueTextField->setTextColor(FXRGB(0, 0, 0));
293  myValueTextField->killFocus();
294  }
295  myValueTextField->show();
296  // check if enable or disable
298  myValueTextField->enable();
299  } else {
300  myValueTextField->disable();
301  }
302  }
303  }
304 }
305 
306 
307 void
309  myAttributeLabel->disable();
310  myEnableAttributeCheckButton->disable();
311  myAttributeColorButton->disable();
312  myAttributeAllowButton->disable();
313  myValueTextField->disable();
315  myValueCheckButton->disable();
316 }
317 
318 
319 bool
321  return (myValueTextField->getTextColor() != FXRGB(255, 0, 0) &&
322  myValueComboBox->getTextColor() != FXRGB(255, 0, 0));
323 }
324 
325 
329 }
330 
331 
332 long
333 GNEAttributesCreatorRow::onCmdSetAttribute(FXObject* obj, FXSelector, void*) {
334  // check what object was called
335  if (obj == myEnableAttributeCheckButton) {
336  if (myEnableAttributeCheckButton->getCheck()) {
337  // enable text field
338  if (myValueTextField->shown()) {
339  myValueTextField->enable();
340  }
341  // enable comboBox
342  if (myValueComboBox->shown()) {
344  }
345  // enable check button
346  if (myValueCheckButton->shown()) {
347  myValueCheckButton->enable();
348  }
350  } else {
351  // disable text field
352  if (myValueTextField->shown()) {
353  myValueTextField->disable();
354  }
355  // disable text field
356  if (myValueComboBox->shown()) {
358  }
359  // disable check button
360  if (myValueCheckButton->shown()) {
361  myValueCheckButton->disable();
362  }
364  }
365  } else if (obj == myValueCheckButton) {
366  if (myValueCheckButton->getCheck()) {
367  myValueCheckButton->setText("true");
369  } else {
370  myValueCheckButton->setText("false");
372  }
373  } else if (obj == myValueComboBox) {
374  // check if use default value
375  const bool useDefaultValue = (myValueComboBox->getText().empty() && myAttrProperties.hasDefaultValue());
376  // change color of text field depending of myCurrentValueValid
378  // check color depending if is a default value
379  if (useDefaultValue || (myAttrProperties.hasDefaultValue() && (myAttrProperties.getDefaultValue() == myValueComboBox->getText().text()))) {
380  myValueComboBox->setTextColor(FXRGB(128, 128, 128));
381  } else {
382  myValueComboBox->setTextColor(FXRGB(0, 0, 0));
383  myValueComboBox->killFocus();
384  }
385  // check if use default value
386  if (useDefaultValue) {
388  // refresh entire GNEAttributesCreator
390  } else {
392  }
393  // special case for trigger stops (in the future will be changed)
395  // refresh entire GNEAttributesCreator
397  }
398  } else {
399  // if value of TextField isn't valid, change their color to Red
400  myValueComboBox->setTextColor(FXRGB(255, 0, 0));
401  myValueComboBox->killFocus();
402  }
403  } else if (obj == myValueTextField) {
404  // check if use default value
405  const bool useDefaultValue = (myValueTextField->getText().empty() && myAttrProperties.hasDefaultValue());
406  // change color of text field depending of myCurrentValueValid
407  if (myAttributesCreatorParent->getCurrentTemplateAC()->isValid(myAttrProperties.getAttr(), myValueTextField->getText().text()) || useDefaultValue) {
408  // check color depending if is a default value
409  if (useDefaultValue || (myAttrProperties.hasDefaultValue() && (myAttrProperties.getDefaultValue() == myValueTextField->getText().text()))) {
410  myValueTextField->setTextColor(FXRGB(128, 128, 128));
411  } else {
412  myValueTextField->setTextColor(FXRGB(0, 0, 0));
413  myValueTextField->killFocus();
414  }
415  // check if use default value
416  if (useDefaultValue) {
418  // refresh entire GNEAttributesCreator
420  } else {
422  }
423  } else {
424  // if value of TextField isn't valid, change their color to Red
425  myValueTextField->setTextColor(FXRGB(255, 0, 0));
426  myValueComboBox->killFocus();
427  }
428  }
429  // Update row
430  update();
431  return 1;
432 }
433 
434 
435 long
436 GNEAttributesCreatorRow::onCmdOpenColorDialog(FXObject*, FXSelector, void*) {
437  // create FXColorDialog
438  FXColorDialog colordialog(this, TL("Color Dialog"));
439  colordialog.setTarget(this);
440  colordialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::COLORWHEEL));
441  // If previous attribute wasn't correct, set black as default color
442  if (GNEAttributeCarrier::canParse<RGBColor>(myValueTextField->getText().text())) {
443  colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myValueTextField->getText().text())));
444  } else {
445  colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myAttrProperties.getDefaultValue())));
446  }
447  // execute dialog to get a new color
448  if (colordialog.execute()) {
449  myValueTextField->setText(toString(MFXUtils::getRGBColor(colordialog.getRGBA())).c_str(), TRUE);
450  }
451  return 0;
452 }
453 
454 
455 long
456 GNEAttributesCreatorRow::onCmdOpenAllowDialog(FXObject*, FXSelector, void*) {
457  // declare bool for accept changes
458  bool acceptChanges = false;
459  // get allow string
460  std::string allow = myValueTextField->getText().text();
461  // opena allowDisallow dialog
462  GNEAllowVClassesDialog(myAttributesCreatorParent->getFrameParent()->getViewNet(), &allow, &acceptChanges).execute();
463  // continue depending of acceptChanges
464  if (acceptChanges) {
465  // update text field
466  myValueTextField->setText(allow.c_str(), TRUE);
467  }
468  return 0;
469 }
470 
471 
472 std::string
474  // get attribute carriers
475  const auto& GNEAttributeCarriers = myAttributesCreatorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
476  // continue depending of type
478  return GNEAttributeCarriers->generateAdditionalID(myAttrProperties.getTagPropertyParent().getTag());
480  return GNEAttributeCarriers->generateDemandElementID(myAttrProperties.getTagPropertyParent().getTag());
481  } else {
482  return "";
483  }
484 }
485 
486 
487 bool
491  myAttrProperties.getTagPropertyParent().getTag(), myValueTextField->getText().text(), false) == nullptr);
494  myAttrProperties.getTagPropertyParent().getTag(), myValueTextField->getText().text(), false) == nullptr);
495  } else {
496  throw ProcessError(TL("Unsupported additional ID"));
497  }
498 }
499 
500 /****************************************************************************/
FXDEFMAP(GNEAttributesCreatorRow) RowCreatorMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:930
@ MID_GNE_SET_ATTRIBUTE_COLOR
edit attribute color
Definition: GUIAppEnum.h:972
@ MID_GNE_SET_ATTRIBUTE_ALLOW
edit attribute allow
Definition: GUIAppEnum.h:970
#define GUIDesignButtonAttribute
button extended over over column with thick and raise frame
Definition: GUIDesigns.h:94
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition: GUIDesigns.h:308
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:317
#define GUIDesignTextField
Definition: GUIDesigns.h:65
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:405
#define GUIDesignComboBoxVisibleItemsMedium
combo box medium small
Definition: GUIDesigns.h:53
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:80
#define GUIDesignCheckButton
checkButton placed in left position
Definition: GUIDesigns.h:198
#define GUIDesignCheckButtonAttribute
checkButton without thick extended over the frame used for attributes
Definition: GUIDesigns.h:207
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition: GUIDesigns.h:258
#define TL(string)
Definition: MsgHandler.h:315
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
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
const GNETagProperties & getTagPropertyParent() const
get reference to tagProperty parent
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
void enableAttributesCreatorRow()
enable row
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
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
GNEAttributesCreator * myAttributesCreatorParent
pointer to GNEAttributesCreator
FXCheckButton * myEnableAttributeCheckButton
check button to enable/disable Label attribute
const GNEAttributeProperties & getAttrProperties() const
return Attr
std::string myInvalidValue
string which indicates the reason due current value is invalid
const GNEAttributeProperties myAttrProperties
attribute properties
GNEAttributesCreator * getAttributesCreatorParent() const
get GNEAttributesCreator parent
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
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:121
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
Definition: GUIDesigns.cpp:128
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.