Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/GNEDrawingShape.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 GNEDrawingShape.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2022
17
///
18
// Frame for draw shapes
19
/****************************************************************************/
20
21
#include <netedit/frames/common/GNEInspectorFrame.h>
22
#include <netedit/GNEViewNet.h>
23
#include <utils/foxtools/MFXDynamicLabel.h>
24
#include <utils/gui/div/GUIDesigns.h>
25
#include <utils/gui/windows/GUIAppEnum.h>
26
27
#include "GNEDrawingShape.h"
28
29
// ===========================================================================
30
// FOX callback mapping
31
// ===========================================================================
32
33
FXDEFMAP(GNEDrawingShape) DrawingShapeMap[] = {
34
FXMAPFUNC(SEL_COMMAND, MID_GNE_STARTDRAWING, GNEDrawingShape::onCmdStartDrawing),
35
FXMAPFUNC(SEL_COMMAND, MID_GNE_STOPDRAWING, GNEDrawingShape::onCmdStopDrawing),
36
FXMAPFUNC(SEL_COMMAND, MID_GNE_ABORTDRAWING, GNEDrawingShape::onCmdAbortDrawing)
37
};
38
39
// Object implementation
40
FXIMPLEMENT(GNEDrawingShape, MFXGroupBoxModule, DrawingShapeMap, ARRAYNUMBER(DrawingShapeMap))
41
42
43
// ===========================================================================
44
// method definitions
45
// ===========================================================================
46
47
GNEDrawingShape::GNEDrawingShape(GNEFrame* frameParent) :
48
MFXGroupBoxModule(frameParent, TL("Drawing")),
49
myFrameParent(frameParent),
50
myDeleteLastCreatedPoint(false) {
51
// create start and stop buttons
52
myStartDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Start drawing"), "", "", 0, this, MID_GNE_STARTDRAWING, GUIDesignButton);
53
myStopDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Stop drawing"), "", "", 0, this, MID_GNE_STOPDRAWING, GUIDesignButton);
54
myAbortDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Abort drawing"), "", "", 0, this, MID_GNE_ABORTDRAWING, GUIDesignButton);
55
// create information label
56
std::ostringstream information;
57
information
58
<< "- " << TL("'Start drawing' or ENTER to create a shape.") << "\n"
59
<< "- " << TL("'Stop drawing' or ENTER to finish shape creation.") << "\n"
60
<< "- " << TL("'Abort drawing' or ESC to abort shape creation.") << "\n"
61
<< "- " << TL("'Shift + Click' to remove the last inserted point.");
62
myInformationLabel = new MFXDynamicLabel(getCollapsableFrame(), information.str().c_str(), 0, GUIDesignLabelFrameInformation);
63
// disable stop and abort functions as init
64
myStopDrawingButton->disable();
65
myAbortDrawingButton->disable();
66
}
67
68
69
GNEDrawingShape::~GNEDrawingShape() {}
70
71
72
void GNEDrawingShape::showDrawingShape() {
73
// abort current drawing before show
74
abortDrawing();
75
// show MFXGroupBoxModule
76
MFXGroupBoxModule::show();
77
}
78
79
80
void GNEDrawingShape::hideDrawingShape() {
81
// abort current drawing before hide
82
abortDrawing();
83
// show MFXGroupBoxModule
84
MFXGroupBoxModule::hide();
85
}
86
87
88
void
89
GNEDrawingShape::startDrawing() {
90
// Only start drawing if GNEDrawingShape modul is shown
91
if (shown()) {
92
// change buttons
93
myStartDrawingButton->disable();
94
myStopDrawingButton->enable();
95
myAbortDrawingButton->enable();
96
}
97
}
98
99
100
void
101
GNEDrawingShape::stopDrawing() {
102
// try to build shape
103
if (myFrameParent->shapeDrawed()) {
104
// clear created points
105
myTemporalShape.clear();
106
// change buttons
107
myStartDrawingButton->enable();
108
myStopDrawingButton->disable();
109
myAbortDrawingButton->disable();
110
} else {
111
// abort drawing if shape cannot be created
112
abortDrawing();
113
}
114
}
115
116
117
void
118
GNEDrawingShape::abortDrawing() {
119
// clear created points
120
myTemporalShape.clear();
121
// change buttons
122
myStartDrawingButton->enable();
123
myStopDrawingButton->disable();
124
myAbortDrawingButton->disable();
125
}
126
127
128
void
129
GNEDrawingShape::addNewPoint(const Position& P) {
130
if (myStopDrawingButton->isEnabled()) {
131
myTemporalShape.push_back(P);
132
} else {
133
throw ProcessError(TL("A new point cannot be added if drawing wasn't started"));
134
}
135
}
136
137
138
void
139
GNEDrawingShape::removeLastPoint() {
140
if (myTemporalShape.size() > 1) {
141
myTemporalShape.pop_back();
142
}
143
}
144
145
146
const PositionVector&
147
GNEDrawingShape::getTemporalShape() const {
148
return myTemporalShape;
149
}
150
151
152
bool
153
GNEDrawingShape::isDrawing() const {
154
return myStopDrawingButton->isEnabled();
155
}
156
157
158
void
159
GNEDrawingShape::setDeleteLastCreatedPoint(bool value) {
160
myDeleteLastCreatedPoint = value;
161
myFrameParent->getViewNet()->updateViewNet();
162
}
163
164
165
bool
166
GNEDrawingShape::getDeleteLastCreatedPoint() {
167
return myDeleteLastCreatedPoint;
168
}
169
170
171
long
172
GNEDrawingShape::onCmdStartDrawing(FXObject*, FXSelector, void*) {
173
startDrawing();
174
return 0;
175
}
176
177
178
long
179
GNEDrawingShape::onCmdStopDrawing(FXObject*, FXSelector, void*) {
180
stopDrawing();
181
return 0;
182
}
183
184
185
long
186
GNEDrawingShape::onCmdAbortDrawing(FXObject*, FXSelector, void*) {
187
abortDrawing();
188
return 0;
189
}
190
191
/****************************************************************************/
192
193