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-2024 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
23#include <netedit/GNENet.h>
24#include <netedit/GNEViewNet.h>
25
27
28// ===========================================================================
29// FOX callback mapping
30// ===========================================================================
31
39
40// Object abstract implementation
41FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))
42
43// ===========================================================================
44// member method definitions
45// ===========================================================================
46
48 FXTopWindow(viewNet, "Custom Geometry Point", GUIIconSubSys::getIcon(GUIIcon::MODEMOVE), GUIIconSubSys::getIcon(GUIIcon::MODEMOVE), GUIDesignDialogBoxExplicit(320, 80)),
49 myViewNet(viewNet),
50 myPos(pos),
51 myOriginalPos(*pos),
52 myGeo(GeoConvHelper::getFinal().getProjString() != "!") {
53 // create main frame
54 FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
55 // create frame for X,Y
56 FXHorizontalFrame* XYFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
57 new FXLabel(XYFrame, "X,Y,[Z]", nullptr, GUIDesignLabelThickedFixed(75));
58 myTextFieldXY = new FXTextField(XYFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
59 myTextFieldXY->setText(toString(*pos).c_str());
60 // create frame for lon,lat
61 FXHorizontalFrame* lonLatFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
62 new FXLabel(lonLatFrame, "lon,lat,[Z]", nullptr, GUIDesignLabelThickedFixed(75));
63 myTextFieldLonLat = new FXTextField(lonLatFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
64 // check if enable geo coordinates
65 if (myGeo) {
66 Position geoPos = *pos;
68 myTextFieldLonLat->setText(toString(geoPos, gPrecisionGeo).c_str());
69 } else {
70 myTextFieldLonLat->disable();
71 }
72 // create buttons centered
73 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
74 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
75 myKeepOldButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close accepting changes"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonCustomWidth(43));
76 myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("close discarding changes"), GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCustomWidth(43));
77 myResetButton = GUIDesigns::buildFXButton(buttonsFrame, "", "", TL("reset to previous values"), GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonCustomWidth(43));
78 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
79 // create
80 create();
81 // show in the given position
82 show(PLACEMENT_SCREEN);
83 // open as modal dialog (will block all windows until stop() or stopModal() is called)
84 getApp()->runModalFor(this);
85}
86
87
89 // return focus to GNEViewNet to avoid minimization
90 getParent()->setFocus();
91}
92
93
94long
95GNEGeometryPointDialog::onCmdChangeGeometryPoint(FXObject* sender, FXSelector, void*) {
96 // check text field
97 if (sender == myTextFieldXY) {
98 // check if position can be parsed
99 if (GNEAttributeCarrier::canParse<Position>(myTextFieldXY->getText().text())) {
100 // set valid color and kill focus
101 myTextFieldXY->setTextColor(FXRGB(0, 0, 0));
102 myTextFieldXY->killFocus();
103 // obtain position
104 *myPos = GNEAttributeCarrier::parse<Position>(myTextFieldXY->getText().text());
105 // check if there is geo coordinates
106 if (myGeo) {
107 // calculate geo position
108 Position geoPos = *myPos;
110 // set geo position in myTextFieldLonLat
111 myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
112 myTextFieldLonLat->setTextColor(FXRGB(0, 0, 0));
113 }
114 } else {
115 // set invalid color
116 myTextFieldXY->setTextColor(FXRGB(255, 0, 0));
117 }
118 } else {
119 // check if position can be parsed
120 if (GNEAttributeCarrier::canParse<Position>(myTextFieldLonLat->getText().text())) {
121 // set valid color and kill focus
122 myTextFieldLonLat->setTextColor(FXRGB(0, 0, 0));
123 myTextFieldLonLat->killFocus();
124 // obtain geo position
125 Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());
126 // calculate cartesian position
127 *myPos = geoPo;
129 // set geo position in myTextFieldXY
130 myTextFieldXY->setText(toString(*myPos).c_str(), FALSE);
131 myTextFieldXY->setTextColor(FXRGB(0, 0, 0));
132 } else {
133 // set invalid color
134 myTextFieldLonLat->setTextColor(FXRGB(255, 0, 0));
135 }
136 }
137 return 1;
138}
139
140
141long
142GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {
143 // stop modal
144 getApp()->stopModal(this);
145 return 1;
146}
147
148
149long
150GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {
151 // set original position
153 // stop modal
154 getApp()->stopModal(this);
155 return 1;
156}
157
158
159long
160GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {
161 // set original position
163 // calculate geo position
164 Position geoPos = *myPos;
166 // set valid colors
167 myTextFieldXY->setTextColor(FXRGB(0, 0, 0));
168 // check geo
169 if (myGeo) {
170 myTextFieldLonLat->setTextColor(FXRGB(0, 0, 0));
171 }
172 // set text field
173 myTextFieldXY->setText(toString(*myPos).c_str(), FALSE);
174 // check geo
175 if (myGeo) {
176 myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
177 }
178 return 1;
179}
180
181
183 myViewNet(nullptr),
184 myOriginalPos(),
185 myGeo(false) {
186}
187
188/****************************************************************************/
FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_GNE_BUTTON_CANCEL
cancel button
@ MID_GNE_BUTTON_RESET
reset button
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specific width and height (for example, additional dialogs)
Definition GUIDesigns.h:614
#define GUIDesignButtonCustomWidth(width)
Button with custom width (used in GNEGeometryPointDialog)
Definition GUIDesigns.h:177
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
Definition GUIDesigns.h:252
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:328
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:315
int gPrecisionGeo
Definition StdDefs.cpp:27
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Dialog to edit geometry points.
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)
FXTextField * myTextFieldLonLat
text field for lon, Lat
long onCmdReset(FXObject *, FXSelector, void *)
event after press cancel button
Position * myPos
position to be edited
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.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37