Eclipse SUMO - Simulation of Urban MObility
GNEGeometryPointDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 #include <config.h>
21 
24 #include <netedit/GNENet.h>
25 #include <netedit/GNEViewNet.h>
26 
27 #include "GNEGeometryPointDialog.h"
28 
29 // ===========================================================================
30 // FOX callback mapping
31 // ===========================================================================
32 
33 FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[] = {
38  FXMAPFUNC(SEL_CLOSE, 0, GNEGeometryPointDialog::onCmdCancel),
39 };
40 
41 // Object abstract implementation
42 FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
47 
49  FXTopWindow(viewNet, "Custom Geometry Point", GUIIconSubSys::getIcon(GUIIcon::MODEMOVE), GUIIconSubSys::getIcon(GUIIcon::MODEMOVE), GUIDesignDialogBoxExplicit(320, 80)),
50  myViewNet(viewNet),
51  myPos(pos),
52  myOriginalPos(*pos),
53  myGeo(GeoConvHelper::getFinal().getProjString() != "!") {
54  // create main frame
55  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
56  // create frame for X,Y
57  FXHorizontalFrame* XYFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
58  new FXLabel(XYFrame, "X,Y,[Z]", nullptr, GUIDesignLabelThick75);
59  myTextFieldXY = new FXTextField(XYFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
60  myTextFieldXY->setText(toString(*pos).c_str());
61  // create frame for lon,lat
62  FXHorizontalFrame* lonLatFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
63  new FXLabel(lonLatFrame, "lon,lat,[Z]", nullptr, GUIDesignLabelThick75);
64  myTextFieldLonLat = new FXTextField(lonLatFrame, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
65  // check if enable geo coordinates
66  if (myGeo) {
67  Position geoPos = *pos;
69  myTextFieldLonLat->setText(toString(geoPos, gPrecisionGeo).c_str());
70  } else {
71  myTextFieldLonLat->disable();
72  }
73  // create buttons centered
74  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
75  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
76  myAcceptButton = new FXButton(buttonsFrame, "\t\tclose accepting changes", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonCustomWidth(43));
77  myCancelButton = new FXButton(buttonsFrame, "\t\tclose discarding changes", GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCustomWidth(43));
78  myResetButton = new FXButton(buttonsFrame, "\t\treset to previous values", GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GNE_BUTTON_RESET, GUIDesignButtonCustomWidth(43));
79  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
80  // create
81  create();
82  // show in the given position
83  show(PLACEMENT_SCREEN);
84  // open as modal dialog (will block all windows until stop() or stopModal() is called)
85  getApp()->runModalFor(this);
86 }
87 
88 
90  // return focus to GNEViewNet to avoid minimization
91  getParent()->setFocus();
92 }
93 
94 
95 long
96 GNEGeometryPointDialog::onCmdChangeGeometryPoint(FXObject* sender, FXSelector, void*) {
97  // check text field
98  if (sender == myTextFieldXY) {
99  // check if position can be parsed
100  if (GNEAttributeCarrier::canParse<Position>(myTextFieldXY->getText().text())) {
101  // set valid color and kill focus
102  myTextFieldXY->setTextColor(FXRGB(0, 0, 0));
103  myTextFieldXY->killFocus();
104  // obtain position
105  *myPos = GNEAttributeCarrier::parse<Position>(myTextFieldXY->getText().text());
106  // check if there is geo coordiantes
107  if (myGeo) {
108  // calculate geo position
109  Position geoPos = *myPos;
111  // set geo position in myTextFieldLonLat
112  myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
113  myTextFieldLonLat->setTextColor(FXRGB(0, 0, 0));
114  }
115  } else {
116  // set invalid color
117  myTextFieldXY->setTextColor(FXRGB(255, 0, 0));
118  }
119  } else {
120  // check if position can be parsed
121  if (GNEAttributeCarrier::canParse<Position>(myTextFieldLonLat->getText().text())) {
122  // set valid color and kill focus
123  myTextFieldLonLat->setTextColor(FXRGB(0, 0, 0));
124  myTextFieldLonLat->killFocus();
125  // obtain geo position
126  Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());
127  // calculate cartesian position
128  *myPos = geoPo;
130  // set geo position in myTextFieldXY
131  myTextFieldXY->setText(toString(*myPos).c_str(), FALSE);
132  myTextFieldXY->setTextColor(FXRGB(0, 0, 0));
133  } else {
134  // set invalid color
135  myTextFieldLonLat->setTextColor(FXRGB(255, 0, 0));
136  }
137  }
138  return 1;
139 }
140 
141 
142 long
143 GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {
144  // stop modal
145  getApp()->stopModal(this);
146  return 1;
147 }
148 
149 
150 long
151 GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {
152  // set original position
153  *myPos = myOriginalPos;
154  // stop modal
155  getApp()->stopModal(this);
156  return 1;
157 }
158 
159 
160 long
161 GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {
162  // set original position
163  *myPos = myOriginalPos;
164  // calculate geo position
165  Position geoPos = *myPos;
167  // set valid colors
168  myTextFieldXY->setTextColor(FXRGB(0, 0, 0));
169  // check geo
170  if (myGeo) {
171  myTextFieldLonLat->setTextColor(FXRGB(0, 0, 0));
172  }
173  // set text field
174  myTextFieldXY->setText(toString(*myPos).c_str(), FALSE);
175  // check geo
176  if (myGeo) {
177  myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
178  }
179  return 1;
180 }
181 
182 
184  myViewNet(nullptr),
185  myOriginalPos(),
186  myGeo(false) {
187 }
188 
189 /****************************************************************************/
FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:797
@ MID_GNE_BUTTON_CANCEL
cancel button
Definition: GUIAppEnum.h:1193
@ MID_GNE_BUTTON_RESET
reset button
Definition: GUIAppEnum.h:1195
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1191
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specift width and height (for example, additional dialogs)
Definition: GUIDesigns.h:539
#define GUIDesignButtonCustomWidth(width)
Button with custom width (used in GNEGeometryPointDialog)
Definition: GUIDesigns.h:136
#define GUIDesignTextField
Definition: GUIDesigns.h:42
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:343
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:60
#define GUIDesignLabelThick75
label with thick, text justify to left and width of 75
Definition: GUIDesigns.h:253
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:340
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:293
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
int gPrecisionGeo
Definition: StdDefs.cpp:26
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Dialog to edit sequences, parameters, etc.. of Additionals.
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 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
Definition: GeoConvHelper.h:53
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
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