Path: blob/main/src/netedit/dialogs/GNEGeometryPointDialog.cpp
169678 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 GNEGeometryPointDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 202116///17// A dialog for set Geometry Points18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <utils/gui/div/GUIDesigns.h>22#include <utils/gui/windows/GUIAppEnum.h>2324#include "GNEGeometryPointDialog.h"2526// ===========================================================================27// FOX callback mapping28// ===========================================================================2930FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[] = {31FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE, GNEGeometryPointDialog::onCmdChangeGeometryPoint),32};3334// Object abstract implementation35FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))3637// ===========================================================================38// member method definitions39// ===========================================================================4041GNEGeometryPointDialog::GNEGeometryPointDialog(GNEApplicationWindow* applicationWindow, const Position& pos) :42GNEDialog(applicationWindow, TL("Custom Geometry Point"), GUIIcon::MODEMOVE, DialogType::GEOMETRYPOINT,43Buttons::ACCEPT_CANCEL_RESET, OpenType::MODAL, ResizeMode::STATIC, 320, 80),44myEditedPosition(pos),45myOriginalPos(pos),46myGeo(GeoConvHelper::getFinal().getProjString() != "!") {47// create main frame48FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);49// create frame for X,Y50FXHorizontalFrame* XYFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);51new FXLabel(XYFrame, "X,Y,[Z]", nullptr, GUIDesignLabelThickedFixed(75));52myTextFieldXY = new FXTextField(XYFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);53myTextFieldXY->setText(toString(pos).c_str());54// create frame for lon,lat55FXHorizontalFrame* lonLatFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);56new FXLabel(lonLatFrame, "lon,lat,[Z]", nullptr, GUIDesignLabelThickedFixed(75));57myTextFieldLonLat = new FXTextField(lonLatFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);58// check if enable geo coordinates59if (myGeo) {60Position geoPos = pos;61GeoConvHelper::getFinal().cartesian2geo(geoPos);62myTextFieldLonLat->setText(toString(geoPos, gPrecisionGeo).c_str());63} else {64myTextFieldLonLat->disable();65}66// create buttons centered67FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);68new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);69myKeepOldButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close accepting changes"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonCustomWidth(43));70myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close discarding changes"), GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCustomWidth(43));71myResetButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("reset to previous values"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonCustomWidth(43));72new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);73// create74create();75// show in the given position76show(PLACEMENT_SCREEN);77// open as modal dialog (will block all windows until stop() or stopModal() is called)78getApp()->runModalFor(this);79}808182GNEGeometryPointDialog::~GNEGeometryPointDialog() {8384}858687const Position&88GNEGeometryPointDialog::getEditedPosition() const {89return myEditedPosition;90}919293void94GNEGeometryPointDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {95// nothing to do96}979899long100GNEGeometryPointDialog::onCmdChangeGeometryPoint(FXObject* sender, FXSelector, void*) {101// check text field102if (sender == myTextFieldXY) {103// check if position can be parsed104if (GNEAttributeCarrier::canParse<Position>(myTextFieldXY->getText().text())) {105// set valid color and kill focus106myTextFieldXY->setTextColor(GUIDesignTextColorBlack);107myTextFieldXY->killFocus();108// obtain position109myEditedPosition = GNEAttributeCarrier::parse<Position>(myTextFieldXY->getText().text());110// check if there is geo coordinates111if (myGeo) {112// calculate geo position113Position geoPos = myEditedPosition;114GeoConvHelper::getFinal().cartesian2geo(geoPos);115// set geo position in myTextFieldLonLat116myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);117myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);118}119} else {120// set invalid color121myTextFieldXY->setTextColor(GUIDesignTextColorRed);122}123} else {124// check if position can be parsed125if (GNEAttributeCarrier::canParse<Position>(myTextFieldLonLat->getText().text())) {126// set valid color and kill focus127myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);128myTextFieldLonLat->killFocus();129// obtain geo position130Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());131// calculate cartesian position132myEditedPosition = geoPo;133GeoConvHelper::getFinal().x2cartesian_const(myEditedPosition);134// set geo position in myTextFieldXY135myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);136myTextFieldXY->setTextColor(GUIDesignTextColorBlack);137} else {138// set invalid color139myTextFieldLonLat->setTextColor(GUIDesignTextColorRed);140}141}142return 1;143}144145146long147GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {148// stop modal149getApp()->stopModal(this);150return 1;151}152153154long155GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {156// set original position157myEditedPosition = myOriginalPos;158// stop modal159getApp()->stopModal(this);160return 1;161}162163164long165GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {166// set original position167myEditedPosition = myOriginalPos;168// calculate geo position169Position geoPos = myEditedPosition;170GeoConvHelper::getFinal().cartesian2geo(geoPos);171// set valid colors172myTextFieldXY->setTextColor(GUIDesignTextColorBlack);173// check geo174if (myGeo) {175myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);176}177// set text field178myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);179// check geo180if (myGeo) {181myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);182}183return 1;184}185186187GNEGeometryPointDialog::GNEGeometryPointDialog() :188myViewNet(nullptr),189myOriginalPos(),190myGeo(false) {191}192193/****************************************************************************/194195196