Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEGeometryPointDialog.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-2025 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// A dialog for set Geometry Points
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
25
27
28// ===========================================================================
29// FOX callback mapping
30// ===========================================================================
31
32FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[] = {
34};
35
36// Object abstract implementation
37FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))
38
39// ===========================================================================
40// member method definitions
41// ===========================================================================
42
44 GNEDialog(applicationWindow, TL("Custom Geometry Point"), GUIIcon::MODEMOVE, DialogType::GEOMETRYPOINT,
45 Buttons::ACCEPT_CANCEL_RESET, OpenType::MODAL, ResizeMode::STATIC, 320, 80),
46 myEditedPosition(pos),
47 myOriginalPos(pos),
48 myGeo(GeoConvHelper::getFinal().getProjString() != "!") {
49 // create main frame
50 FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
51 // create frame for X,Y
52 FXHorizontalFrame* XYFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
53 new FXLabel(XYFrame, "X,Y,[Z]", nullptr, GUIDesignLabelThickedFixed(75));
54 myTextFieldXY = new FXTextField(XYFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
55 myTextFieldXY->setText(toString(pos).c_str());
56 // create frame for lon,lat
57 FXHorizontalFrame* lonLatFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
58 new FXLabel(lonLatFrame, "lon,lat,[Z]", nullptr, GUIDesignLabelThickedFixed(75));
59 myTextFieldLonLat = new FXTextField(lonLatFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
60 // check if enable geo coordinates
61 if (myGeo) {
62 Position geoPos = pos;
64 myTextFieldLonLat->setText(toString(geoPos, gPrecisionGeo).c_str());
65 } else {
66 myTextFieldLonLat->disable();
67 }
68 // create buttons centered
69 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
70 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
71 myKeepOldButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close accepting changes"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonCustomWidth(43));
72 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close discarding changes"), GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCustomWidth(43));
73 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("reset to previous values"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonCustomWidth(43));
74 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
75 // create
76 create();
77 // show in the given position
78 show(PLACEMENT_SCREEN);
79 // open as modal dialog (will block all windows until stop() or stopModal() is called)
80 getApp()->runModalFor(this);
81}
82
83
87
88
89const Position&
93
94
95void
97 // nothing to do
98}
99
100
101long
102GNEGeometryPointDialog::onCmdChangeGeometryPoint(FXObject* sender, FXSelector, void*) {
103 // check text field
104 if (sender == myTextFieldXY) {
105 // check if position can be parsed
106 if (GNEAttributeCarrier::canParse<Position>(myTextFieldXY->getText().text())) {
107 // set valid color and kill focus
109 myTextFieldXY->killFocus();
110 // obtain position
111 myEditedPosition = GNEAttributeCarrier::parse<Position>(myTextFieldXY->getText().text());
112 // check if there is geo coordinates
113 if (myGeo) {
114 // calculate geo position
115 Position geoPos = myEditedPosition;
117 // set geo position in myTextFieldLonLat
118 myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
120 }
121 } else {
122 // set invalid color
124 }
125 } else {
126 // check if position can be parsed
127 if (GNEAttributeCarrier::canParse<Position>(myTextFieldLonLat->getText().text())) {
128 // set valid color and kill focus
130 myTextFieldLonLat->killFocus();
131 // obtain geo position
132 Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());
133 // calculate cartesian position
134 myEditedPosition = geoPo;
136 // set geo position in myTextFieldXY
137 myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);
139 } else {
140 // set invalid color
142 }
143 }
144 return 1;
145}
146
147
148long
149GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {
150 // stop modal
151 getApp()->stopModal(this);
152 return 1;
153}
154
155
156long
157GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {
158 // set original position
160 // stop modal
161 getApp()->stopModal(this);
162 return 1;
163}
164
165
166long
167GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {
168 // set original position
170 // calculate geo position
171 Position geoPos = myEditedPosition;
173 // set valid colors
175 // check geo
176 if (myGeo) {
178 }
179 // set text field
180 myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);
181 // check geo
182 if (myGeo) {
183 myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
184 }
185 return 1;
186}
187
188
190 myViewNet(nullptr),
191 myOriginalPos(),
192 myGeo(false) {
193}
194
195/****************************************************************************/
DialogType
FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
@ MID_GNE_BUTTON_CANCEL
cancel button
@ MID_GNE_BUTTON_RESET
reset button
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignTextColorRed
red color (for invalid text)
Definition GUIDesigns.h:44
#define GUIDesignButtonCustomWidth(width)
Button with custom width (used in GNEGeometryPointDialog)
Definition GUIDesigns.h:186
#define GUIDesignTextField
Definition GUIDesigns.h:74
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:92
#define GUIDesignTextColorBlack
black color (for correct text)
Definition GUIDesigns.h:38
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:409
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:254
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:347
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:304
int gPrecisionGeo
Definition StdDefs.cpp:29
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
OpenType
Open dialog type.
Definition GNEDialog.h:58
long onCmdAccept(FXObject *sender, FXSelector sel, void *ptr)
event after press accept button
const bool myGeo
flag for geo
FXTextField * myTextFieldXY
text field for X, Y
long onCmdCancel(FXObject *sender, FXSelector sel, void *ptr)
event after press cancel button
long onCmdChangeGeometryPoint(FXObject *sender, FXSelector sel, void *ptr)
event after change position in TextFields
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
Position myEditedPosition
edited position
const Position & getEditedPosition() const
get edited position
FXTextField * myTextFieldLonLat
text field for lon, Lat
long onCmdReset(FXObject *, FXSelector, void *)
event after press cancel button
const Position myOriginalPos
original position (used for reset)
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static methods for processing the coordinates conversion for the current net
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
dialog arguments, used for certain modal dialogs that can not be edited using tab
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37