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
21#include <netedit/GNENet.h>
24
26
27// ===========================================================================
28// FOX callback mapping
29// ===========================================================================
30
31FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[] = {
33};
34
35// Object abstract implementation
36FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))
37
38// ===========================================================================
39// member method definitions
40// ===========================================================================
41
43 GNEDialog(applicationWindow, TL("Custom Geometry Point"), GUIIcon::MODEMOVE, Buttons::ACCEPT_CANCEL_RESET,
44 OpenType::MODAL, ResizeMode::STATIC, 320, 80),
45 myEditedPosition(pos),
46 myOriginalPos(pos),
47 myGeo(GeoConvHelper::getFinal().getProjString() != "!") {
48 // create main frame
49 FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
50 // create frame for X,Y
51 FXHorizontalFrame* XYFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
52 new FXLabel(XYFrame, "X,Y,[Z]", nullptr, GUIDesignLabelThickedFixed(75));
53 myTextFieldXY = new FXTextField(XYFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
54 myTextFieldXY->setText(toString(pos).c_str());
55 // create frame for lon,lat
56 FXHorizontalFrame* lonLatFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
57 new FXLabel(lonLatFrame, "lon,lat,[Z]", nullptr, GUIDesignLabelThickedFixed(75));
58 myTextFieldLonLat = new FXTextField(lonLatFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
59 // check if enable geo coordinates
60 if (myGeo) {
61 Position geoPos = pos;
63 myTextFieldLonLat->setText(toString(geoPos, gPrecisionGeo).c_str());
64 } else {
65 myTextFieldLonLat->disable();
66 }
67 // create buttons centered
68 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
69 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
70 myKeepOldButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close accepting changes"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonCustomWidth(43));
71 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close discarding changes"), GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCustomWidth(43));
72 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("reset to previous values"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonCustomWidth(43));
73 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
74 // create
75 create();
76 // show in the given position
77 show(PLACEMENT_SCREEN);
78 // open as modal dialog (will block all windows until stop() or stopModal() is called)
79 getApp()->runModalFor(this);
80}
81
82
86
87
88const Position&
92
93
94void
96 // nothing to do
97}
98
99
100long
101GNEGeometryPointDialog::onCmdChangeGeometryPoint(FXObject* sender, FXSelector, void*) {
102 // check text field
103 if (sender == myTextFieldXY) {
104 // check if position can be parsed
105 if (GNEAttributeCarrier::canParse<Position>(myTextFieldXY->getText().text())) {
106 // set valid color and kill focus
108 myTextFieldXY->killFocus();
109 // obtain position
110 myEditedPosition = GNEAttributeCarrier::parse<Position>(myTextFieldXY->getText().text());
111 // check if there is geo coordinates
112 if (myGeo) {
113 // calculate geo position
114 Position geoPos = myEditedPosition;
116 // set geo position in myTextFieldLonLat
117 myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
119 }
120 } else {
121 // set invalid color
123 }
124 } else {
125 // check if position can be parsed
126 if (GNEAttributeCarrier::canParse<Position>(myTextFieldLonLat->getText().text())) {
127 // set valid color and kill focus
129 myTextFieldLonLat->killFocus();
130 // obtain geo position
131 Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());
132 // calculate cartesian position
133 myEditedPosition = geoPo;
135 // set geo position in myTextFieldXY
136 myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);
138 } else {
139 // set invalid color
141 }
142 }
143 return 1;
144}
145
146
147long
148GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {
149 // stop modal
150 getApp()->stopModal(this);
151 return 1;
152}
153
154
155long
156GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {
157 // set original position
159 // stop modal
160 getApp()->stopModal(this);
161 return 1;
162}
163
164
165long
166GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {
167 // set original position
169 // calculate geo position
170 Position geoPos = myEditedPosition;
172 // set valid colors
174 // check geo
175 if (myGeo) {
177 }
178 // set text field
179 myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);
180 // check geo
181 if (myGeo) {
182 myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
183 }
184 return 1;
185}
186
187
189 myViewNet(nullptr),
190 myOriginalPos(),
191 myGeo(false) {
192}
193
194/****************************************************************************/
FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:991
@ 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:305
int gPrecisionGeo
Definition StdDefs.cpp:28
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The main window of Netedit.
OpenType
Open dialog type.
Definition GNEDialog.h:55
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