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.org/sumo
3 // Copyright (C) 2001-2022 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 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEViewParent.h>
31 
33 #include "GNEAttributesCreator.h"
34 
35 
36 // ===========================================================================
37 // FOX callback mapping
38 // ===========================================================================
39 
40 FXDEFMAP(GNEAttributesCreatorRow) RowCreatorMap[] = {
43 };
44 
45 // Object implementation
46 FXIMPLEMENT(GNEAttributesCreatorRow, FXHorizontalFrame, RowCreatorMap, ARRAYNUMBER(RowCreatorMap))
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 
54  FXHorizontalFrame(AttributesCreatorParent->getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame),
55  myAttributesCreatorParent(AttributesCreatorParent),
56  myAttrProperties(attrProperties) {
57  // Create left visual elements
58  myAttributeLabel = new MFXLabelTooltip(this,
59  AttributesCreatorParent->getFrameParent()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
60  "name", nullptr, GUIDesignLabelAttribute);
61  myAttributeLabel->hide();
62  myEnableAttributeCheckButton = new FXCheckButton(this, TL("name"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButtonAttribute);
63  myEnableAttributeCheckButton->hide();
64  myAttributeButton = new FXButton(this, TL("button"), nullptr, this, MID_GNE_SET_ATTRIBUTE_DIALOG, GUIDesignButtonAttribute);
65  myAttributeButton->hide();
66  // Create right visual elements
67  myValueTextField = new FXTextField(this, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
68  myValueTextField->hide();
69  myValueCheckButton = new FXCheckButton(this, TL("Disabled"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
70  myValueCheckButton->hide();
71  myValueComboBox = new FXComboBox(this, GUIDesignComboBoxNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignComboBoxAttribute);
72  myValueComboBox->hide();
73  // only create if parent was created
74  if (getParent()->id()) {
75  // create GNEAttributesCreatorRow
76  FXHorizontalFrame::create();
77  // refresh row
78  refreshRow();
79  // show GNEAttributesCreatorRow
80  show();
81  }
82 }
83 
84 
85 void
87  // only destroy if parent was created
88  if (getParent()->id()) {
89  FXHorizontalFrame::destroy();
90  }
91 }
92 
93 
96  return myAttrProperties;
97 }
98 
99 
100 std::string
102  if (myAttrProperties.isBool()) {
103  return (myValueCheckButton->getCheck() == 1) ? "1" : "0";
104  } else if (myAttrProperties.isDiscrete()) {
105  return myValueComboBox->getText().text();
106  } else {
107  return myValueTextField->getText().text();
108  }
109 }
110 
111 
112 bool
114  if (shown()) {
115  return myEnableAttributeCheckButton->getCheck() == TRUE;
116  } else {
117  return false;
118  }
119 }
120 
121 
122 void
124  if (shown()) {
125  // set radio button
126  myEnableAttributeCheckButton->setCheck(value);
127  // enable or disable input fields
128  if (value) {
129  if (myAttrProperties.isBool()) {
130  myValueCheckButton->enable();
131  } else if (myAttrProperties.isDiscrete()) {
132  myValueComboBox->enable();
133  } else {
134  myValueTextField->enable();
135  }
136  } else {
137  if (myAttrProperties.isBool()) {
138  myValueCheckButton->disable();
139  } else if (myAttrProperties.isDiscrete()) {
140  myValueComboBox->disable();
141  } else {
142  myValueTextField->disable();
143  }
144  }
145  }
146 }
147 
148 
149 void
151  if (myAttrProperties.isBool()) {
152  return myValueCheckButton->enable();
153  } else if (myAttrProperties.isDiscrete()) {
154  myValueComboBox->enable();
155  } else {
156  return myValueTextField->enable();
157  }
158 }
159 
160 
161 void
163  if (myAttrProperties.isBool()) {
164  return myValueCheckButton->disable();
165  } else if (myAttrProperties.isDiscrete()) {
166  myValueComboBox->disable();
167  } else {
168  return myValueTextField->disable();
169  }
170 }
171 
172 
173 bool
175  if (!shown()) {
176  return false;
177  } else if (myAttrProperties.isBool()) {
178  return myValueCheckButton->isEnabled();
179  } else if (myAttrProperties.isDiscrete()) {
180  return myValueComboBox->isEnabled();
181  } else {
182  return myValueTextField->isEnabled();
183  }
184 }
185 
186 
187 void
189  // reset invalid value
190  myInvalidValue.clear();
191  // special case for attribute ID
193  // show label
194  myAttributeLabel->setText(myAttrProperties.getAttrStr().c_str());
195  myAttributeLabel->setTipText(myAttrProperties.getDefinition().c_str());
196  myAttributeLabel->show();
197  // generate ID
198  myValueTextField->setText(generateID().c_str());
199  // show textField
200  myValueTextField->setTextColor(FXRGB(0, 0, 0));
201  myValueTextField->killFocus();
202  myValueTextField->show();
203  } else {
204  // left
206  // show color button
207  myAttributeButton->setTextColor(FXRGB(0, 0, 0));
208  myAttributeButton->killFocus();
209  myAttributeButton->setText(myAttrProperties.getAttrStr().c_str());
210  myAttributeButton->show();
211  } else if (myAttrProperties.isActivatable()) {
212  // show check button
215  // enable or disable depending of template AC
217  myEnableAttributeCheckButton->setCheck(TRUE);
218  } else {
219  myEnableAttributeCheckButton->setCheck(FALSE);
220  }
221  } else {
222  // show label
223  myAttributeLabel->setText(myAttrProperties.getAttrStr().c_str());
224  myAttributeLabel->setTipText(myAttrProperties.getDefinition().c_str());
225  myAttributeLabel->show();
226  }
227  // right
228  if (myAttrProperties.isBool()) {
229  if (GNEAttributeCarrier::parse<bool>(myAttributesCreatorParent->getCurrentTemplateAC()->getAttribute(myAttrProperties.getAttr()))) {
230  myValueCheckButton->setCheck(true);
231  myValueCheckButton->setText(TL("true"));
232  } else {
233  myValueCheckButton->setCheck(false);
234  myValueCheckButton->setText(TL("false"));
235  }
236  myValueCheckButton->show();
237  // check if enable or disable
239  myValueCheckButton->enable();
240  } else {
241  myValueCheckButton->disable();
242  }
243  } else if (myAttrProperties.isDiscrete()) {
244  // fill textField
245  myValueComboBox->clearItems();
246  for (const auto& item : myAttrProperties.getDiscreteValues()) {
247  myValueComboBox->appendItem(item.c_str());
248  }
249  myValueComboBox->setNumVisible(myValueComboBox->getNumItems());
252  myValueComboBox->setTextColor(FXRGB(128, 128, 128));
253  } else {
254  myValueComboBox->setTextColor(FXRGB(0, 0, 0));
255  myValueComboBox->killFocus();
256  }
257  myValueComboBox->show();
258  // check if enable or disable
260  myValueComboBox->enable();
261  } else {
262  myValueComboBox->disable();
263  }
264  } else {
265  myValueTextField->setTextColor(FXRGB(0, 0, 0));
266  myValueTextField->killFocus();
269  myValueTextField->setTextColor(FXRGB(128, 128, 128));
270  } else {
271  myValueTextField->setTextColor(FXRGB(0, 0, 0));
272  myValueTextField->killFocus();
273  }
274  myValueTextField->show();
275  // check if enable or disable
277  myValueTextField->enable();
278  } else {
279  myValueTextField->disable();
280  }
281  }
282  }
283 }
284 
285 
286 void
288  myAttributeLabel->disable();
289  myEnableAttributeCheckButton->disable();
290  myAttributeButton->disable();
291  myValueTextField->disable();
292  myValueComboBox->disable();
293  myValueCheckButton->disable();
294 }
295 
296 
297 bool
299  return (myValueTextField->getTextColor() != FXRGB(255, 0, 0) &&
300  myValueComboBox->getTextColor() != FXRGB(255, 0, 0));
301 }
302 
303 
307 }
308 
309 
310 long
311 GNEAttributesCreatorRow::onCmdSetAttribute(FXObject* obj, FXSelector, void*) {
312  // check what object was called
313  if (obj == myEnableAttributeCheckButton) {
314  if (myEnableAttributeCheckButton->getCheck()) {
315  // enable text field
316  if (myValueTextField->shown()) {
317  myValueTextField->enable();
318  }
319  // enable comboBox
320  if (myValueComboBox->shown()) {
321  myValueComboBox->enable();
322  }
323  // enable check button
324  if (myValueCheckButton->shown()) {
325  myValueCheckButton->enable();
326  }
328  } else {
329  // disable text field
330  if (myValueTextField->shown()) {
331  myValueTextField->disable();
332  }
333  // disable text field
334  if (myValueComboBox->shown()) {
335  myValueComboBox->disable();
336  }
337  // disable check button
338  if (myValueCheckButton->shown()) {
339  myValueCheckButton->disable();
340  }
342  }
343  } else if (obj == myValueCheckButton) {
344  if (myValueCheckButton->getCheck()) {
345  myValueCheckButton->setText(TL("true"));
347  } else {
348  myValueCheckButton->setText(TL("false"));
350  }
351  } else if (obj == myValueComboBox) {
352  // check if use default value
353  const bool useDefaultValue = (myValueComboBox->getText().empty() && myAttrProperties.hasDefaultValue());
354  // change color of text field depending of myCurrentValueValid
355  if (myAttributesCreatorParent->getCurrentTemplateAC()->isValid(myAttrProperties.getAttr(), myValueComboBox->getText().text()) || useDefaultValue) {
356  // check color depending if is a default value
357  if (useDefaultValue || (myAttrProperties.hasDefaultValue() && (myAttrProperties.getDefaultValue() == myValueComboBox->getText().text()))) {
358  myValueComboBox->setTextColor(FXRGB(128, 128, 128));
359  } else {
360  myValueComboBox->setTextColor(FXRGB(0, 0, 0));
361  myValueComboBox->killFocus();
362  }
363  // check if use default value
364  if (useDefaultValue) {
366  // refresh entire GNEAttributesCreator
368  } else {
370  }
371  // special case for trigger stops (in the future will be changed)
373  // refresh entire GNEAttributesCreator
375  }
376  } else {
377  // if value of TextField isn't valid, change their color to Red
378  myValueComboBox->setTextColor(FXRGB(255, 0, 0));
379  myValueComboBox->killFocus();
380  }
381  } else if (obj == myValueTextField) {
382  // check if use default value
383  const bool useDefaultValue = (myValueTextField->getText().empty() && myAttrProperties.hasDefaultValue());
384  // change color of text field depending of myCurrentValueValid
385  if (myAttributesCreatorParent->getCurrentTemplateAC()->isValid(myAttrProperties.getAttr(), myValueTextField->getText().text()) || useDefaultValue) {
386  // check color depending if is a default value
387  if (useDefaultValue || (myAttrProperties.hasDefaultValue() && (myAttrProperties.getDefaultValue() == myValueTextField->getText().text()))) {
388  myValueTextField->setTextColor(FXRGB(128, 128, 128));
389  } else {
390  myValueTextField->setTextColor(FXRGB(0, 0, 0));
391  myValueTextField->killFocus();
392  }
393  // check if use default value
394  if (useDefaultValue) {
396  // refresh entire GNEAttributesCreator
398  } else {
400  }
401  } else {
402  // if value of TextField isn't valid, change their color to Red
403  myValueTextField->setTextColor(FXRGB(255, 0, 0));
404  myValueComboBox->killFocus();
405  }
406  }
407  // Update row
408  update();
409  return 1;
410 }
411 
412 
413 long
415  // declare bool for accept changes
416  bool acceptChanges = false;
417  // continue depending of attribute
419  // create FXColorDialog
420  FXColorDialog colordialog(this, tr("Color Dialog"));
421  colordialog.setTarget(this);
422  // If previous attribute wasn't correct, set black as default color
423  if (GNEAttributeCarrier::canParse<RGBColor>(myValueTextField->getText().text())) {
424  colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myValueTextField->getText().text())));
425  } else {
426  colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myAttrProperties.getDefaultValue())));
427  }
428  // execute dialog to get a new color
429  if (colordialog.execute()) {
430  myValueTextField->setText(toString(MFXUtils::getRGBColor(colordialog.getRGBA())).c_str(), TRUE);
431  }
432  } else if (myAttrProperties.getAttr() == SUMO_ATTR_ALLOW) {
433  // get allow string
434  std::string allow = myValueTextField->getText().text();
435  // opena allowDisallow dialog
436  GNEAllowVClassesDialog(myAttributesCreatorParent->getFrameParent()->getViewNet(), &allow, &acceptChanges).execute();
437  // continue depending of acceptChanges
438  if (acceptChanges) {
439  // update text field
440  myValueTextField->setText(allow.c_str(), TRUE);
441  }
442  } else if (myAttrProperties.getAttr() == SUMO_ATTR_DISALLOW) {
443  // transform disallow to allow
444  std::string allow = getVehicleClassNames(~parseVehicleClasses(myValueTextField->getText().text()));
445  // opena allowDisallow dialog
446  GNEAllowVClassesDialog(myAttributesCreatorParent->getFrameParent()->getViewNet(), &allow, &acceptChanges).execute();
447  // continue depending of acceptChanges
448  if (acceptChanges) {
449  // update text field
450  myValueTextField->setText(getVehicleClassNames(~parseVehicleClasses(allow)).c_str(), TRUE);
451  }
452  }
453  return 0;
454 }
455 
456 
457 std::string
459  // get attribute carriers
460  const auto& GNEAttributeCarriers = myAttributesCreatorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
461  // continue depending of type
463  return GNEAttributeCarriers->generateAdditionalID(myAttrProperties.getTagPropertyParent().getTag());
465  return GNEAttributeCarriers->generateDemandElementID(myAttrProperties.getTagPropertyParent().getTag());
466  } else {
467  return "";
468  }
469 }
470 
471 
472 bool
476  myAttrProperties.getTagPropertyParent().getTag(), myValueTextField->getText().text(), false) == nullptr);
479  myAttrProperties.getTagPropertyParent().getTag(), myValueTextField->getText().text(), false) == nullptr);
480  } else {
481  throw ProcessError("Unsuported additional ID");
482  }
483 }
484 
485 /****************************************************************************/
FXDEFMAP(GNEAttributesCreatorRow) RowCreatorMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:870
@ MID_GNE_SET_ATTRIBUTE_DIALOG
attribute edited trough dialog
Definition: GUIAppEnum.h:904
#define GUIDesignButtonAttribute
button extended over over column with thick and raise frame
Definition: GUIDesigns.h:80
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition: GUIDesigns.h:315
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:321
#define GUIDesignTextField
Definition: GUIDesigns.h:48
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:397
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame
Definition: GUIDesigns.h:241
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:69
#define GUIDesignCheckButton
checkButton placed in left position
Definition: GUIDesigns.h:169
#define GUIDesignCheckButtonAttribute
checkButton without thick extended over the frame used for attributes
Definition: GUIDesigns.h:175
#define TL(string)
Definition: MsgHandler.h:282
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ 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_EnableAttribute)
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 atribute is a color
bool isBool() const
return true if atribute is boolean
const std::string & getAttrStr() const
get XML Attribute
bool isDiscrete() const
return true if atribute 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 atribute 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
generate ID
MFXLabelTooltip * myAttributeLabel
Label with the name of the attribute.
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
bool isAttributesCreatorRowEnabled() const
check if row is enabled
long onCmdSetAttribute(FXObject *, FXSelector, void *)
FXComboBox * myValueComboBox
comboBox for discrete vaues
std::string getValue() const
return value
void destroy()
destroy GNEAttributesCreatorRow (but don't delete)
bool isAttributeValid() const
check if current attribute is valid
void disableAttributesCreatorRow()
disable row
long onCmdOpenAttributeDialog(FXObject *, FXSelector, void *)
called when user press the open dialog button
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
FXButton * myAttributeButton
Button for open color or allow/disallow editor.
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:132
bool isStop() const
return true if tag correspond to a stop element
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)
GNENet * getNet() const
get the net object
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