Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2024 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#include <config.h>
21
23#include <netedit/GNEViewNet.h>
27
28#include "GNEDrawingShape.h"
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
40
41// Object implementation
42FXIMPLEMENT(GNEDrawingShape, MFXGroupBoxModule, DrawingShapeMap, ARRAYNUMBER(DrawingShapeMap))
43
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48
50 MFXGroupBoxModule(frameParent, TL("Drawing")),
51 myFrameParent(frameParent),
52 myDeleteLastCreatedPoint(false) {
53 // create start and stop buttons
54 myStartDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Start drawing"), "", "", 0, this, MID_GNE_STARTDRAWING, GUIDesignButton);
55 myStopDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Stop drawing"), "", "", 0, this, MID_GNE_STOPDRAWING, GUIDesignButton);
56 myAbortDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Abort drawing"), "", "", 0, this, MID_GNE_ABORTDRAWING, GUIDesignButton);
57 // create information label
58 std::ostringstream information;
59 information
60 << "- " << TL("'Start drawing' or ENTER to create a shape.") << "\n"
61 << "- " << TL("'Stop drawing' or ENTER to finish shape creation.") << "\n"
62 << "- " << TL("'Abort drawing' or ESC to abort shape creation.") << "\n"
63 << "- " << TL("'Shift + Click' to remove the last inserted point.");
64 myInformationLabel = new MFXDynamicLabel(getCollapsableFrame(), information.str().c_str(), 0, GUIDesignLabelFrameInformation);
65 // disable stop and abort functions as init
66 myStopDrawingButton->disable();
67 myAbortDrawingButton->disable();
68}
69
70
72
73
75 // abort current drawing before show
77 // show MFXGroupBoxModule
78 MFXGroupBoxModule::show();
79}
80
81
83 // abort current drawing before hide
85 // show MFXGroupBoxModule
86 MFXGroupBoxModule::hide();
87}
88
89
90void
92 // Only start drawing if GNEDrawingShape modul is shown
93 if (shown()) {
94 // change buttons
95 myStartDrawingButton->disable();
96 myStopDrawingButton->enable();
97 myAbortDrawingButton->enable();
98 }
99}
100
101
102void
104 // try to build shape
105 if (myFrameParent->shapeDrawed()) {
106 // clear created points
107 myTemporalShape.clear();
108 // change buttons
109 myStartDrawingButton->enable();
110 myStopDrawingButton->disable();
111 myAbortDrawingButton->disable();
112 } else {
113 // abort drawing if shape cannot be created
114 abortDrawing();
115 }
116}
117
118
119void
121 // clear created points
122 myTemporalShape.clear();
123 // change buttons
124 myStartDrawingButton->enable();
125 myStopDrawingButton->disable();
126 myAbortDrawingButton->disable();
127}
128
129
130void
132 if (myStopDrawingButton->isEnabled()) {
133 myTemporalShape.push_back(P);
134 } else {
135 throw ProcessError(TL("A new point cannot be added if drawing wasn't started"));
136 }
137}
138
139
140void
142 if (myTemporalShape.size() > 1) {
143 myTemporalShape.pop_back();
144 }
145}
146
147
148const PositionVector&
152
153
154bool
156 return myStopDrawingButton->isEnabled();
157}
158
159
160void
165
166
167bool
171
172
173long
174GNEDrawingShape::onCmdStartDrawing(FXObject*, FXSelector, void*) {
175 startDrawing();
176 return 0;
177}
178
179
180long
181GNEDrawingShape::onCmdStopDrawing(FXObject*, FXSelector, void*) {
182 stopDrawing();
183 return 0;
184}
185
186
187long
188GNEDrawingShape::onCmdAbortDrawing(FXObject*, FXSelector, void*) {
189 abortDrawing();
190 return 0;
191}
192
193/****************************************************************************/
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:88
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:285
#define TL(string)
Definition MsgHandler.h:315
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:150
virtual bool shapeDrawed()
build a shaped element using the drawed shape
Definition GNEFrame.cpp:279
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.