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-2023 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>
32
35
36
37// ===========================================================================
38// FOX callback mapping
39// ===========================================================================
40
45
46// Object implementation
47FXIMPLEMENT(GNEAttributesCreatorRow, FXHorizontalFrame, RowCreatorMap, ARRAYNUMBER(RowCreatorMap))
48
49
50// ===========================================================================
51// method definitions
52// ===========================================================================
53
55 FXHorizontalFrame(AttributesCreatorParent->getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame),
56 myAttributesCreatorParent(AttributesCreatorParent),
57 myAttrProperties(attrProperties) {
58 // Create left visual elements
59 myAttributeLabel = new MFXLabelTooltip(this,
60 AttributesCreatorParent->getFrameParent()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
61 TL("name"), nullptr, GUIDesignLabelThickedFixed(100));
62 myAttributeLabel->hide();
63 myEnableAttributeCheckButton = new FXCheckButton(this, TL("name"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButtonAttribute);
64 myEnableAttributeCheckButton->hide();
65 myAttributeButton = new FXButton(this, TL("button"), nullptr, this, MID_GNE_SET_ATTRIBUTE_DIALOG, GUIDesignButtonAttribute);
66 myAttributeButton->hide();
67 // Create right visual elements
68 myValueTextField = new FXTextField(this, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
69 myValueTextField->hide();
70 myValueCheckButton = new FXCheckButton(this, TL("Disabled"), this, MID_GNE_SET_ATTRIBUTE, GUIDesignCheckButton);
71 myValueCheckButton->hide();
72 myValueComboBox = new FXComboBox(this, GUIDesignComboBoxNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignComboBoxAttribute);
73 myValueComboBox->hide();
74 // only create if parent was created
75 if (getParent()->id()) {
76 // create GNEAttributesCreatorRow
77 FXHorizontalFrame::create();
78 // refresh row
79 refreshRow();
80 // show GNEAttributesCreatorRow
81 show();
82 }
83}
84
85
86void
88 // only destroy if parent was created
89 if (getParent()->id()) {
90 FXHorizontalFrame::destroy();
91 }
92}
93
94
99
100
101std::string
103 if (myAttrProperties.isBool()) {
104 return (myValueCheckButton->getCheck() == 1) ? "1" : "0";
105 } else if (myAttrProperties.isDiscrete()) {
106 return myValueComboBox->getText().text();
107 } else {
108 return myValueTextField->getText().text();
109 }
110}
111
112
113bool
115 if (shown()) {
116 return myEnableAttributeCheckButton->getCheck() == TRUE;
117 } else {
118 return false;
119 }
120}
121
122
123void
125 if (shown()) {
126 // set radio button
127 myEnableAttributeCheckButton->setCheck(value);
128 // enable or disable input fields
129 if (value) {
130 if (myAttrProperties.isBool()) {
131 myValueCheckButton->enable();
132 } else if (myAttrProperties.isDiscrete()) {
133 myValueComboBox->enable();
134 } else {
135 myValueTextField->enable();
136 }
137 } else {
138 if (myAttrProperties.isBool()) {
139 myValueCheckButton->disable();
140 } else if (myAttrProperties.isDiscrete()) {
141 myValueComboBox->disable();
142 } else {
143 myValueTextField->disable();
144 }
145 }
146 }
147}
148
149
150void
152 if (myAttrProperties.isBool()) {
153 return myValueCheckButton->enable();
154 } else if (myAttrProperties.isDiscrete()) {
155 myValueComboBox->enable();
156 } else {
157 return myValueTextField->enable();
158 }
159}
160
161
162void
164 if (myAttrProperties.isBool()) {
165 return myValueCheckButton->disable();
166 } else if (myAttrProperties.isDiscrete()) {
167 myValueComboBox->disable();
168 } else {
169 return myValueTextField->disable();
170 }
171}
172
173
174bool
176 if (!shown()) {
177 return false;
178 } else if (myAttrProperties.isBool()) {
179 return myValueCheckButton->isEnabled();
180 } else if (myAttrProperties.isDiscrete()) {
181 return myValueComboBox->isEnabled();
182 } else {
183 return myValueTextField->isEnabled();
184 }
185}
186
187
188void
190 // reset invalid value
191 myInvalidValue.clear();
192 // special case for attribute ID
194 // show label
195 myAttributeLabel->setText(myAttrProperties.getAttrStr().c_str());
196 myAttributeLabel->setTipText(myAttrProperties.getDefinition().c_str());
197 myAttributeLabel->show();
198 // generate ID
199 myValueTextField->setText(generateID().c_str());
200 // show textField
201 myValueTextField->setTextColor(FXRGB(0, 0, 0));
202 myValueTextField->killFocus();
203 myValueTextField->show();
204 } else {
205 // left
207 // show color button
208 myAttributeButton->setTextColor(FXRGB(0, 0, 0));
209 myAttributeButton->killFocus();
211 myAttributeButton->show();
212 } else if (myAttrProperties.isActivatable()) {
213 // show check button
216 // enable or disable depending of template AC
218 myEnableAttributeCheckButton->setCheck(TRUE);
219 } else {
220 myEnableAttributeCheckButton->setCheck(FALSE);
221 }
222 } else {
223 // show label
224 myAttributeLabel->setText(myAttrProperties.getAttrStr().c_str());
225 myAttributeLabel->setTipText(myAttrProperties.getDefinition().c_str());
226 myAttributeLabel->show();
227 }
228 // right
229 if (myAttrProperties.isBool()) {
230 if (GNEAttributeCarrier::parse<bool>(myAttributesCreatorParent->getCurrentTemplateAC()->getAttribute(myAttrProperties.getAttr()))) {
231 myValueCheckButton->setCheck(true);
232 myValueCheckButton->setText("true");
233 } else {
234 myValueCheckButton->setCheck(false);
235 myValueCheckButton->setText("false");
236 }
237 myValueCheckButton->show();
238 // check if enable or disable
240 myValueCheckButton->enable();
241 } else {
242 myValueCheckButton->disable();
243 }
244 } else if (myAttrProperties.isDiscrete()) {
245 // fill textField
246 myValueComboBox->clearItems();
247 for (const auto& item : myAttrProperties.getDiscreteValues()) {
248 myValueComboBox->appendItem(item.c_str());
249 }
250 // set number of visible items
252 myValueComboBox->setNumVisible(myValueComboBox->getNumItems());
253 } else {
254 myValueComboBox->setNumVisible(10);
255 }
258 myValueComboBox->setTextColor(FXRGB(128, 128, 128));
259 } else {
260 myValueComboBox->setTextColor(FXRGB(0, 0, 0));
261 myValueComboBox->killFocus();
262 }
263 myValueComboBox->show();
264 // check if enable or disable
266 myValueComboBox->enable();
267 } else {
268 myValueComboBox->disable();
269 }
270 } else {
271 myValueTextField->setTextColor(FXRGB(0, 0, 0));
272 myValueTextField->killFocus();
275 myValueTextField->setTextColor(FXRGB(128, 128, 128));
276 } else {
277 myValueTextField->setTextColor(FXRGB(0, 0, 0));
278 myValueTextField->killFocus();
279 }
280 myValueTextField->show();
281 // check if enable or disable
283 myValueTextField->enable();
284 } else {
285 myValueTextField->disable();
286 }
287 }
288 }
289}
290
291
292void
294 myAttributeLabel->disable();
296 myAttributeButton->disable();
297 myValueTextField->disable();
298 myValueComboBox->disable();
299 myValueCheckButton->disable();
300}
301
302
303bool
305 return (myValueTextField->getTextColor() != FXRGB(255, 0, 0) &&
306 myValueComboBox->getTextColor() != FXRGB(255, 0, 0));
307}
308
309
314
315
316long
317GNEAttributesCreatorRow::onCmdSetAttribute(FXObject* obj, FXSelector, void*) {
318 // check what object was called
319 if (obj == myEnableAttributeCheckButton) {
320 if (myEnableAttributeCheckButton->getCheck()) {
321 // enable text field
322 if (myValueTextField->shown()) {
323 myValueTextField->enable();
324 }
325 // enable comboBox
326 if (myValueComboBox->shown()) {
327 myValueComboBox->enable();
328 }
329 // enable check button
330 if (myValueCheckButton->shown()) {
331 myValueCheckButton->enable();
332 }
334 } else {
335 // disable text field
336 if (myValueTextField->shown()) {
337 myValueTextField->disable();
338 }
339 // disable text field
340 if (myValueComboBox->shown()) {
341 myValueComboBox->disable();
342 }
343 // disable check button
344 if (myValueCheckButton->shown()) {
345 myValueCheckButton->disable();
346 }
348 }
349 } else if (obj == myValueCheckButton) {
350 if (myValueCheckButton->getCheck()) {
351 myValueCheckButton->setText("true");
353 } else {
354 myValueCheckButton->setText("false");
356 }
357 } else if (obj == myValueComboBox) {
358 // check if use default value
359 const bool useDefaultValue = (myValueComboBox->getText().empty() && myAttrProperties.hasDefaultValue());
360 // change color of text field depending of myCurrentValueValid
361 if (myAttributesCreatorParent->getCurrentTemplateAC()->isValid(myAttrProperties.getAttr(), myValueComboBox->getText().text()) || useDefaultValue) {
362 // check color depending if is a default value
363 if (useDefaultValue || (myAttrProperties.hasDefaultValue() && (myAttrProperties.getDefaultValue() == myValueComboBox->getText().text()))) {
364 myValueComboBox->setTextColor(FXRGB(128, 128, 128));
365 } else {
366 myValueComboBox->setTextColor(FXRGB(0, 0, 0));
367 myValueComboBox->killFocus();
368 }
369 // check if use default value
370 if (useDefaultValue) {
372 // refresh entire GNEAttributesCreator
374 } else {
376 }
377 // special case for trigger stops (in the future will be changed)
379 // refresh entire GNEAttributesCreator
381 }
382 } else {
383 // if value of TextField isn't valid, change their color to Red
384 myValueComboBox->setTextColor(FXRGB(255, 0, 0));
385 myValueComboBox->killFocus();
386 }
387 } else if (obj == myValueTextField) {
388 // check if use default value
389 const bool useDefaultValue = (myValueTextField->getText().empty() && myAttrProperties.hasDefaultValue());
390 // change color of text field depending of myCurrentValueValid
391 if (myAttributesCreatorParent->getCurrentTemplateAC()->isValid(myAttrProperties.getAttr(), myValueTextField->getText().text()) || useDefaultValue) {
392 // check color depending if is a default value
393 if (useDefaultValue || (myAttrProperties.hasDefaultValue() && (myAttrProperties.getDefaultValue() == myValueTextField->getText().text()))) {
394 myValueTextField->setTextColor(FXRGB(128, 128, 128));
395 } else {
396 myValueTextField->setTextColor(FXRGB(0, 0, 0));
397 myValueTextField->killFocus();
398 }
399 // check if use default value
400 if (useDefaultValue) {
402 // refresh entire GNEAttributesCreator
404 } else {
406 }
407 } else {
408 // if value of TextField isn't valid, change their color to Red
409 myValueTextField->setTextColor(FXRGB(255, 0, 0));
410 myValueComboBox->killFocus();
411 }
412 }
413 // Update row
414 update();
415 return 1;
416}
417
418
419long
421 // declare bool for accept changes
422 bool acceptChanges = false;
423 // continue depending of attribute
425 // create FXColorDialog
426 FXColorDialog colordialog(this, TL("Color Dialog"));
427 colordialog.setTarget(this);
428 // If previous attribute wasn't correct, set black as default color
429 if (GNEAttributeCarrier::canParse<RGBColor>(myValueTextField->getText().text())) {
430 colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myValueTextField->getText().text())));
431 } else {
432 colordialog.setRGBA(MFXUtils::getFXColor(GNEAttributeCarrier::parse<RGBColor>(myAttrProperties.getDefaultValue())));
433 }
434 // execute dialog to get a new color
435 if (colordialog.execute()) {
436 myValueTextField->setText(toString(MFXUtils::getRGBColor(colordialog.getRGBA())).c_str(), TRUE);
437 }
438 } else if (myAttrProperties.getAttr() == SUMO_ATTR_ALLOW) {
439 // get allow string
440 std::string allow = myValueTextField->getText().text();
441 // opena allowDisallow dialog
442 GNEAllowVClassesDialog(myAttributesCreatorParent->getFrameParent()->getViewNet(), &allow, &acceptChanges).execute();
443 // continue depending of acceptChanges
444 if (acceptChanges) {
445 // update text field
446 myValueTextField->setText(allow.c_str(), TRUE);
447 }
448 }
449 return 0;
450}
451
452
453std::string
455 // get attribute carriers
456 const auto& GNEAttributeCarriers = myAttributesCreatorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
457 // continue depending of type
459 return GNEAttributeCarriers->generateAdditionalID(myAttrProperties.getTagPropertyParent().getTag());
461 return GNEAttributeCarriers->generateDemandElementID(myAttrProperties.getTagPropertyParent().getTag());
462 } else {
463 return "";
464 }
465}
466
467
468bool
480
481/****************************************************************************/
FXDEFMAP(GNEAttributesCreatorRow) RowCreatorMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:907
@ MID_GNE_SET_ATTRIBUTE_DIALOG
attribute edited trough dialog
Definition GUIAppEnum.h:943
#define GUIDesignButtonAttribute
button extended over over column with thick and raise frame
Definition GUIDesigns.h:77
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition GUIDesigns.h:297
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:306
#define GUIDesignTextField
Definition GUIDesigns.h:51
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:394
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:66
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:187
#define GUIDesignCheckButtonAttribute
checkButton without thick extended over the frame used for attributes
Definition GUIDesigns.h:196
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:247
#define TL(string)
Definition MsgHandler.h:287
@ 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 attribute is a color
bool showAllDiscreteValues() const
show all discrete values in the comboBox
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
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
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:120
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