Path: blob/main/src/netedit/dialogs/elements/GNEAttributeCarrierDialog.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 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()->getViewNet()->getViewParent()->getGNEAppWindows()->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()->getViewNet()->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(), 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(), myAttrProperty->getAttr(),152myTextField->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// Create auxiliar frames for rows167FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);168FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));169FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrameFixedWidth(250));170// calculate number of attributes171std::vector<const GNEAttributeProperties*> attrProperties;172for (const auto& attrProperty : myElement->getTagProperty()->getAttributeProperties()) {173// check if this attribute can be edited in edit mode and in basic editor174if (attrProperty->isEditMode() && attrProperty->isBasicEditor()) {175attrProperties.push_back(attrProperty);176}177}178// spread attributes in two columns179for (size_t i = 0; i < attrProperties.size(); i++) {180// create attribute text field181auto attributeTextField = new AttributeTextField(this, (i % 2 == 0) ? columnLeft : columnRight, attrProperties[i]);182// add to myAttributeTextFields vector183myAttributeTextFields.push_back(attributeTextField);184}185// init commandGroup186myElement->getNet()->getViewNet()->getUndoList()->begin(myElement, TLF("edit % '%'", AC->getTagStr(), AC->getID()));187// open dialog188openDialog();189}190191192GNEAttributeCarrierDialog::~GNEAttributeCarrierDialog() {}193194195void196GNEAttributeCarrierDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {197// nothing to do198}199200201long202GNEAttributeCarrierDialog::onCmdAccept(FXObject*, FXSelector, void*) {203if (false) {204// open warning Box205GNEWarningBasicDialog(myElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows(),206TLF("Error editing % '%'", myElement->getTagStr(), myElement->getID()),207TLF("The % '%' cannot be updated because there are invalid attributes.",208myElement->getTagStr(), myElement->getID()));209return 1;210} else {211// close dialog accepting changes212return acceptElementDialog();213}214}215216217long218GNEAttributeCarrierDialog::onCmdReset(FXObject*, FXSelector, void*) {219// reset changes220resetChanges();221return 1;222}223224/****************************************************************************/225226227