Path: blob/main/src/netedit/dialogs/GNEGeometryPointDialog.cpp
193863 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 GNEGeometryPointDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 202116///17// A dialog for set Geometry Points18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNENet.h>22#include <utils/gui/div/GUIDesigns.h>23#include <utils/gui/windows/GUIAppEnum.h>2425#include "GNEGeometryPointDialog.h"2627// ===========================================================================28// FOX callback mapping29// ===========================================================================3031FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[] = {32FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE, GNEGeometryPointDialog::onCmdChangeGeometryPoint),33};3435// Object abstract implementation36FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))3738// ===========================================================================39// member method definitions40// ===========================================================================4142GNEGeometryPointDialog::GNEGeometryPointDialog(GNEApplicationWindow* applicationWindow, const Position& pos) :43GNEDialog(applicationWindow, TL("Custom Geometry Point"), GUIIcon::MODEMOVE, DialogType::GEOMETRYPOINT,44Buttons::ACCEPT_CANCEL_RESET, OpenType::MODAL, ResizeMode::STATIC, 320, 80),45myEditedPosition(pos),46myOriginalPos(pos),47myGeo(GeoConvHelper::getFinal().getProjString() != "!") {48// create main frame49FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);50// create frame for X,Y51FXHorizontalFrame* XYFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);52new FXLabel(XYFrame, "X,Y,[Z]", nullptr, GUIDesignLabelThickedFixed(75));53myTextFieldXY = new FXTextField(XYFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);54myTextFieldXY->setText(toString(pos).c_str());55// create frame for lon,lat56FXHorizontalFrame* lonLatFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);57new FXLabel(lonLatFrame, "lon,lat,[Z]", nullptr, GUIDesignLabelThickedFixed(75));58myTextFieldLonLat = new FXTextField(lonLatFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);59// check if enable geo coordinates60if (myGeo) {61Position geoPos = pos;62GeoConvHelper::getFinal().cartesian2geo(geoPos);63myTextFieldLonLat->setText(toString(geoPos, gPrecisionGeo).c_str());64} else {65myTextFieldLonLat->disable();66}67// create buttons centered68FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);69new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);70myKeepOldButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close accepting changes"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonCustomWidth(43));71myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close discarding changes"), GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCustomWidth(43));72myResetButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("reset to previous values"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonCustomWidth(43));73new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);74// create75create();76// show in the given position77show(PLACEMENT_SCREEN);78// open as modal dialog (will block all windows until stop() or stopModal() is called)79getApp()->runModalFor(this);80}818283GNEGeometryPointDialog::~GNEGeometryPointDialog() {8485}868788const Position&89GNEGeometryPointDialog::getEditedPosition() const {90return myEditedPosition;91}929394void95GNEGeometryPointDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {96// nothing to do97}9899100long101GNEGeometryPointDialog::onCmdChangeGeometryPoint(FXObject* sender, FXSelector, void*) {102// check text field103if (sender == myTextFieldXY) {104// check if position can be parsed105if (GNEAttributeCarrier::canParse<Position>(myTextFieldXY->getText().text())) {106// set valid color and kill focus107myTextFieldXY->setTextColor(GUIDesignTextColorBlack);108myTextFieldXY->killFocus();109// obtain position110myEditedPosition = GNEAttributeCarrier::parse<Position>(myTextFieldXY->getText().text());111// check if there is geo coordinates112if (myGeo) {113// calculate geo position114Position geoPos = myEditedPosition;115GeoConvHelper::getFinal().cartesian2geo(geoPos);116// set geo position in myTextFieldLonLat117myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);118myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);119}120} else {121// set invalid color122myTextFieldXY->setTextColor(GUIDesignTextColorRed);123}124} else {125// check if position can be parsed126if (GNEAttributeCarrier::canParse<Position>(myTextFieldLonLat->getText().text())) {127// set valid color and kill focus128myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);129myTextFieldLonLat->killFocus();130// obtain geo position131Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());132// calculate cartesian position133myEditedPosition = geoPo;134GeoConvHelper::getFinal().x2cartesian_const(myEditedPosition);135// set geo position in myTextFieldXY136myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);137myTextFieldXY->setTextColor(GUIDesignTextColorBlack);138} else {139// set invalid color140myTextFieldLonLat->setTextColor(GUIDesignTextColorRed);141}142}143return 1;144}145146147long148GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {149// stop modal150getApp()->stopModal(this);151return 1;152}153154155long156GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {157// set original position158myEditedPosition = myOriginalPos;159// stop modal160getApp()->stopModal(this);161return 1;162}163164165long166GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {167// set original position168myEditedPosition = myOriginalPos;169// calculate geo position170Position geoPos = myEditedPosition;171GeoConvHelper::getFinal().cartesian2geo(geoPos);172// set valid colors173myTextFieldXY->setTextColor(GUIDesignTextColorBlack);174// check geo175if (myGeo) {176myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);177}178// set text field179myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);180// check geo181if (myGeo) {182myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);183}184return 1;185}186187188GNEGeometryPointDialog::GNEGeometryPointDialog() :189myViewNet(nullptr),190myOriginalPos(),191myGeo(false) {192}193194/****************************************************************************/195196197