Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEDrawingShape.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-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/****************************************************************************/
18// Frame for draw shapes
19/****************************************************************************/
20
22#include <netedit/GNEViewNet.h>
26
27#include "GNEDrawingShape.h"
28
29// ===========================================================================
30// FOX callback mapping
31// ===========================================================================
32
38
39// Object implementation
40FXIMPLEMENT(GNEDrawingShape, MFXGroupBoxModule, DrawingShapeMap, ARRAYNUMBER(DrawingShapeMap))
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46
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
70
71
73 // abort current drawing before show
75 // show MFXGroupBoxModule
76 MFXGroupBoxModule::show();
77}
78
79
81 // abort current drawing before hide
83 // show MFXGroupBoxModule
84 MFXGroupBoxModule::hide();
85}
86
87
88void
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
100void
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
117void
119 // clear created points
120 myTemporalShape.clear();
121 // change buttons
122 myStartDrawingButton->enable();
123 myStopDrawingButton->disable();
124 myAbortDrawingButton->disable();
125}
126
127
128void
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
138void
140 if (myTemporalShape.size() > 1) {
141 myTemporalShape.pop_back();
142 }
143}
144
145
146const PositionVector&
150
151
152bool
154 return myStopDrawingButton->isEnabled();
155}
156
157
158void
163
164
165bool
169
170
171long
172GNEDrawingShape::onCmdStartDrawing(FXObject*, FXSelector, void*) {
173 startDrawing();
174 return 0;
175}
176
177
178long
179GNEDrawingShape::onCmdStopDrawing(FXObject*, FXSelector, void*) {
180 stopDrawing();
181 return 0;
182}
183
184
185long
186GNEDrawingShape::onCmdAbortDrawing(FXObject*, FXSelector, void*) {
187 abortDrawing();
188 return 0;
189}
190
191/****************************************************************************/
FXDEFMAP(GNEDrawingShape) DrawingShapeMap[]
@ MID_GNE_STARTDRAWING
start drawing polygon
@ MID_GNE_ABORTDRAWING
abort drawing polygon
@ MID_GNE_STOPDRAWING
stop drawing polygon
#define GUIDesignButton
Definition GUIDesigns.h:82
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:279
#define TL(string)
Definition MsgHandler.h:305
void startDrawing()
start drawing
GNEFrame * myFrameParent
pointer to frame parent
bool isDrawing() const
return true if currently a shape is drawed
FXButton * myStartDrawingButton
button for start drawing
FXButton * myAbortDrawingButton
button for abort drawing
void addNewPoint(const Position &P)
add new point to temporal shape
bool getDeleteLastCreatedPoint()
get flag delete last created point
void abortDrawing()
abort drawing
bool myDeleteLastCreatedPoint
flag to enable/disable delete point mode
void setDeleteLastCreatedPoint(bool value)
enable or disable delete last created point
~GNEDrawingShape()
destructor
long onCmdAbortDrawing(FXObject *, FXSelector, void *)
Called when the user press abort drawing button.
PositionVector myTemporalShape
current drawed shape
void removeLastPoint()
remove last added point
long onCmdStartDrawing(FXObject *, FXSelector, void *)
FXButton * myStopDrawingButton
button for stop drawing
void showDrawingShape()
show Drawing mode
void stopDrawing()
stop drawing and check if shape can be created
void hideDrawingShape()
hide Drawing mode
long onCmdStopDrawing(FXObject *, FXSelector, void *)
Called when the user press stop drawing button.
const PositionVector & getTemporalShape() const
get Temporal shape
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:154
virtual bool shapeDrawed()
build a shaped element using the drawed shape
Definition GNEFrame.cpp:288
void updateViewNet(const bool ignoreViewUpdater=true) const
Mark the entire GNEViewNet to be repainted later.
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
A list item which allows for custom coloring.
MFXGroupBoxModule (based on FXGroupBox)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.