Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/dialogs/GNEGeometryPointDialog.cpp
193716 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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
/****************************************************************************/
14
/// @file GNEGeometryPointDialog.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2021
17
///
18
// A dialog for set Geometry Points
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <utils/gui/div/GUIDesigns.h>
24
#include <utils/gui/windows/GUIAppEnum.h>
25
26
#include "GNEGeometryPointDialog.h"
27
28
// ===========================================================================
29
// FOX callback mapping
30
// ===========================================================================
31
32
FXDEFMAP(GNEGeometryPointDialog) GNEGeometryPointDialogMap[] = {
33
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE, GNEGeometryPointDialog::onCmdChangeGeometryPoint),
34
};
35
36
// Object abstract implementation
37
FXIMPLEMENT_ABSTRACT(GNEGeometryPointDialog, FXTopWindow, GNEGeometryPointDialogMap, ARRAYNUMBER(GNEGeometryPointDialogMap))
38
39
// ===========================================================================
40
// member method definitions
41
// ===========================================================================
42
43
GNEGeometryPointDialog::GNEGeometryPointDialog(GNEApplicationWindow* applicationWindow, const Position& pos) :
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;
63
GeoConvHelper::getFinal().cartesian2geo(geoPos);
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
84
GNEGeometryPointDialog::~GNEGeometryPointDialog() {
85
86
}
87
88
89
const Position&
90
GNEGeometryPointDialog::getEditedPosition() const {
91
return myEditedPosition;
92
}
93
94
95
void
96
GNEGeometryPointDialog::runInternalTest(const InternalTestStep::DialogArgument* /*dialogArgument*/) {
97
// nothing to do
98
}
99
100
101
long
102
GNEGeometryPointDialog::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
108
myTextFieldXY->setTextColor(GUIDesignTextColorBlack);
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;
116
GeoConvHelper::getFinal().cartesian2geo(geoPos);
117
// set geo position in myTextFieldLonLat
118
myTextFieldLonLat->setText(toString(geoPos).c_str(), FALSE);
119
myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);
120
}
121
} else {
122
// set invalid color
123
myTextFieldXY->setTextColor(GUIDesignTextColorRed);
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
129
myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);
130
myTextFieldLonLat->killFocus();
131
// obtain geo position
132
Position geoPo = GNEAttributeCarrier::parse<Position>(myTextFieldLonLat->getText().text());
133
// calculate cartesian position
134
myEditedPosition = geoPo;
135
GeoConvHelper::getFinal().x2cartesian_const(myEditedPosition);
136
// set geo position in myTextFieldXY
137
myTextFieldXY->setText(toString(myEditedPosition).c_str(), FALSE);
138
myTextFieldXY->setTextColor(GUIDesignTextColorBlack);
139
} else {
140
// set invalid color
141
myTextFieldLonLat->setTextColor(GUIDesignTextColorRed);
142
}
143
}
144
return 1;
145
}
146
147
148
long
149
GNEGeometryPointDialog::onCmdAccept(FXObject*, FXSelector, void*) {
150
// stop modal
151
getApp()->stopModal(this);
152
return 1;
153
}
154
155
156
long
157
GNEGeometryPointDialog::onCmdCancel(FXObject*, FXSelector, void*) {
158
// set original position
159
myEditedPosition = myOriginalPos;
160
// stop modal
161
getApp()->stopModal(this);
162
return 1;
163
}
164
165
166
long
167
GNEGeometryPointDialog::onCmdReset(FXObject*, FXSelector, void*) {
168
// set original position
169
myEditedPosition = myOriginalPos;
170
// calculate geo position
171
Position geoPos = myEditedPosition;
172
GeoConvHelper::getFinal().cartesian2geo(geoPos);
173
// set valid colors
174
myTextFieldXY->setTextColor(GUIDesignTextColorBlack);
175
// check geo
176
if (myGeo) {
177
myTextFieldLonLat->setTextColor(GUIDesignTextColorBlack);
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
189
GNEGeometryPointDialog::GNEGeometryPointDialog() :
190
myViewNet(nullptr),
191
myOriginalPos(),
192
myGeo(false) {
193
}
194
195
/****************************************************************************/
196
197