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