Path: blob/main/src/netedit/dialogs/elements/GNEAttributeCarrierDialog.cpp
193871 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEAttributeCarrierDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Aug 202516///17// Dialog for edit attribute carriers18/****************************************************************************/1920#include <netedit/changes/GNEChange_Attribute.h>21#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>22#include <netedit/dialogs/GNEColorDialog.h>23#include <netedit/dialogs/GNEVClassesDialog.h>24#include <netedit/GNEApplicationWindow.h>25#include <netedit/GNENet.h>26#include <netedit/GNEUndoList.h>27#include <netedit/GNEViewParent.h>28#include <utils/foxtools/MFXTextFieldIcon.h>29#include <utils/gui/div/GUIDesigns.h>3031#include "GNEAttributeCarrierDialog.h"3233// ===========================================================================34// FOX callback mapping35// ===========================================================================3637FXDEFMAP(GNEAttributeCarrierDialog::AttributeTextField) AttributeTextFieldMap[] = {38FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GNEAttributeCarrierDialog::AttributeTextField::onCmdSetAttribute),39FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_COLOR, GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenColorDialog),40FXMAPFUNC(SEL_COMMAND, MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW, GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenVClassDialog),41};4243// Object implementation44FXIMPLEMENT(GNEAttributeCarrierDialog::AttributeTextField, FXHorizontalFrame, AttributeTextFieldMap, ARRAYNUMBER(AttributeTextFieldMap))4546// ===========================================================================47// member method definitions48// ===========================================================================4950// ---------------------------------------------------------------------------51// GNEAttributeCarrierDialog::AttributeTextField - methods52// ---------------------------------------------------------------------------5354GNEAttributeCarrierDialog::AttributeTextField::AttributeTextField(GNEAttributeCarrierDialog* ACDialog, FXVerticalFrame* verticalFrame,55const GNEAttributeProperties* attrProperty) :56FXHorizontalFrame(verticalFrame, GUIDesignAuxiliarHorizontalFrame),57myACDialogParent(ACDialog),58myAttrProperty(attrProperty) {59// get static tooltip menu60const auto tooltipMenu = ACDialog->getElement()->getNet()->getGNEApplicationWindow()->getStaticTooltipMenu();61// check if create button or label62if (attrProperty->isVClass() && (attrProperty->getAttr() != SUMO_ATTR_DISALLOW)) {63myAttributeButton = new MFXButtonTooltip(this, tooltipMenu, attrProperty->getAttrStr(), nullptr, this,64MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_ALLOW, GUIDesignButtonAttribute);65myAttributeButton->setTipText(TL("Open dialog for editing vClasses"));66} else if (attrProperty->isColor()) {67myAttributeButton = new MFXButtonTooltip(this, tooltipMenu, attrProperty->getAttrStr(), GUIIconSubSys::getIcon(GUIIcon::COLORWHEEL), this,68MID_GNE_ATTRIBUTESEDITORROW_OPENDIALOG_COLOR, GUIDesignButtonAttribute);69myAttributeButton->setTipText(TL("Open dialog for editing color"));70} else {71// create label72new FXLabel(this, attrProperty->getAttrStr().c_str(), nullptr, GUIDesignLabelThickedFixed(100));73}74// continue depending of attr type75if (attrProperty->isBool()) {76// create lef boolean checkBox for enable/disable attributes77myCheckButton = new FXCheckButton(this, "bool", this, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GUIDesignCheckButton);78// continue depending of current value79if (ACDialog->getElement()->getAttribute(attrProperty->getAttr()) == GNEAttributeCarrier::TRUE_STR) {80myCheckButton->setCheck(TRUE);81myCheckButton->setText(TL("true"));82} else {83myCheckButton->setCheck(FALSE);84myCheckButton->setText(TL("false"));85}86} else {87// create text field88myTextField = new MFXTextFieldIcon(this, tooltipMenu, GUIIcon::EMPTY, this, MID_GNE_ATTRIBUTESEDITORROW_SETATTRIBUTE, GUIDesignTextField);89// set attribute90myTextField->setText(ACDialog->getElement()->getAttribute(attrProperty->getAttr()).c_str());91}92}939495long96GNEAttributeCarrierDialog::AttributeTextField::onCmdSetAttribute(FXObject* obj, FXSelector, void*) {97auto undoList = myACDialogParent->getElement()->getNet()->getUndoList();98if (obj == myTextField) {99if (myACDialogParent->getElement()->isValid(myAttrProperty->getAttr(), myTextField->getText().text())) {100// set attribute101myACDialogParent->getElement()->setAttribute(myAttrProperty->getAttr(), myTextField->getText().text(), undoList);102// set valid color and kill focus103myTextField->setTextColor(GUIDesignTextColorBlack);104myTextField->setBackColor(GUIDesignBackgroundColorWhite);105myTextField->killFocus();106} else {107// set invalid color108myTextField->setTextColor(GUIDesignTextColorRed);109// set background color110if (myTextField->getText().empty()) {111myTextField->setTextColor(GUIDesignBackgroundColorRed);112} else {113myTextField->setBackColor(GUIDesignBackgroundColorWhite);114}115}116} else if (obj == myCheckButton) {117if (myCheckButton->getCheck() == TRUE) {118myACDialogParent->getElement()->setAttribute(myAttrProperty->getAttr(), GNEAttributeCarrier::TRUE_STR, undoList);119myCheckButton->setText(TL("true"));120} else {121myACDialogParent->getElement()->setAttribute(myAttrProperty->getAttr(), GNEAttributeCarrier::FALSE_STR, undoList);122myCheckButton->setText(TL("false"));123}124}125return 1;126}127128129long130GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenColorDialog(FXObject*, FXSelector, void*) {131RGBColor color = RGBColor::BLACK;132// If previous attribute wasn't correct, set black as default color133if (GNEAttributeCarrier::canParse<RGBColor>(myTextField->getText().text())) {134color = GNEAttributeCarrier::parse<RGBColor>(myTextField->getText().text());135} else if (myAttrProperty->hasDefaultValue()) {136color = myAttrProperty->getDefaultColorValue();137}138// declare colorDialog139const auto colorDialog = new GNEColorDialog(myACDialogParent->getApplicationWindow(), myACDialogParent, color);140// continue depending of result141if (colorDialog->getResult() == GNEDialog::Result::ACCEPT) {142myTextField->setText(toString(colorDialog->getColor()).c_str(), TRUE);143}144return 1;145}146147148long149GNEAttributeCarrierDialog::AttributeTextField::onCmdOpenVClassDialog(FXObject*, FXSelector, void*) {150// declare allowVClassesDialog151const auto allowVClassesDialog = new GNEVClassesDialog(myACDialogParent->getApplicationWindow(), myACDialogParent,152myAttrProperty->getAttr(), myTextField->getText().text());153// continue depending of result154if (allowVClassesDialog->getResult() == GNEDialog::Result::ACCEPT) {155myTextField->setText(allowVClassesDialog->getModifiedVClasses().c_str(), TRUE);156}157return 1;158}159160// ---------------------------------------------------------------------------161// GNEAttributeCarrierDialog - methods162// ---------------------------------------------------------------------------163164GNEAttributeCarrierDialog::GNEAttributeCarrierDialog(GNEAttributeCarrier* AC) :165GNETemplateElementDialog<GNEAttributeCarrier>(AC, DialogType::ATTRIBUTECARRIER) {166// build dialog167builder(AC);168}169170171GNEAttributeCarrierDialog::GNEAttributeCarrierDialog(GNEAttributeCarrier* AC, GNEDialog* parentDialog) :172GNETemplateElementDialog<GNEAttributeCarrier>(AC, parentDialog, DialogType::ATTRIBUTECARRIER) {173// build dialog174builder(AC);175}176177178GNEAttributeCarrierDialog::~GNEAttributeCarrierDialog() {}179180181void182GNEAttributeCarrierDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {183// nothing to do184}185186187long188GNEAttributeCarrierDialog::onCmdAccept(FXObject*, FXSelector, void*) {189// close dialog accepting changes190return acceptElementDialog();191}192193194long195GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {196// reset changes197resetChanges();198return 1;199}200201202void203GNEAttributeCarrierDialog::builder(GNEAttributeCarrier* /* AC */) {204// Create auxiliar frames for rows205FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);206FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));207FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));208// calculate number of attributes209std::vector<const GNEAttributeProperties*> attrProperties;210for (const auto& attrProperty : myElement->getTagProperty()->getAttributeProperties()) {211// check if this attribute can be edited in edit mode and in basic editor212if (attrProperty->isEditMode() && attrProperty->isBasicEditor()) {213attrProperties.push_back(attrProperty);214}215}216// spread attributes in two columns217for (size_t i = 0; i < attrProperties.size(); i++) {218// create attribute text field219auto attributeTextField = new AttributeTextField(this, (i % 2 == 0) ? columnLeft : columnRight, attrProperties[i]);220// add to myAttributeTextFields vector221myAttributeTextFields.push_back(attributeTextField);222}223// open dialog224openDialog();225}226227228/****************************************************************************/229230231