Eclipse SUMO - Simulation of Urban MObility
GNEDrawingShape.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 
25 
26 #include "GNEDrawingShape.h"
27 
28 
29 // ===========================================================================
30 // FOX callback mapping
31 // ===========================================================================
32 
33 FXDEFMAP(GNEDrawingShape) DrawingShapeMap[] = {
37 };
38 
39 // Object implementation
40 FXIMPLEMENT(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 = new FXButton(getCollapsableFrame(), TL("Start drawing"), 0, this, MID_GNE_STARTDRAWING, GUIDesignButton);
53  myStopDrawingButton = new FXButton(getCollapsableFrame(), TL("Stop drawing"), 0, this, MID_GNE_STOPDRAWING, GUIDesignButton);
54  myAbortDrawingButton = new FXButton(getCollapsableFrame(), TL("Abort drawing"), 0, this, MID_GNE_ABORTDRAWING, GUIDesignButton);
55  // create information label
56  std::ostringstream information;
57  information
58  << "- 'Start drawing' or ENTER\n"
59  << " to create shape.\n"
60  << "- 'Stop drawing' or ENTER to\n"
61  << " finish shape creation.\n"
62  << "- 'Abort drawing' or ESC to\n"
63  << " abort shape creation.\n"
64  << "- 'Shift + Click' to remove\n"
65  << " last inserted point.";
66  myInformationLabel = new FXLabel(getCollapsableFrame(), information.str().c_str(), 0, GUIDesignLabelFrameInformation);
67  // disable stop and abort functions as init
68  myStopDrawingButton->disable();
69  myAbortDrawingButton->disable();
70 }
71 
72 
74 
75 
77  // abort current drawing before show
78  abortDrawing();
79  // show MFXGroupBoxModule
80  MFXGroupBoxModule::show();
81 }
82 
83 
85  // abort current drawing before hide
86  abortDrawing();
87  // show MFXGroupBoxModule
88  MFXGroupBoxModule::hide();
89 }
90 
91 
92 void
94  // Only start drawing if GNEDrawingShape modul is shown
95  if (shown()) {
96  // change buttons
97  myStartDrawingButton->disable();
98  myStopDrawingButton->enable();
99  myAbortDrawingButton->enable();
100  }
101 }
102 
103 
104 void
106  // try to build shape
107  if (myFrameParent->shapeDrawed()) {
108  // clear created points
109  myTemporalShape.clear();
110  // change buttons
111  myStartDrawingButton->enable();
112  myStopDrawingButton->disable();
113  myAbortDrawingButton->disable();
114  } else {
115  // abort drawing if shape cannot be created
116  abortDrawing();
117  }
118 }
119 
120 
121 void
123  // clear created points
124  myTemporalShape.clear();
125  // change buttons
126  myStartDrawingButton->enable();
127  myStopDrawingButton->disable();
128  myAbortDrawingButton->disable();
129 }
130 
131 
132 void
134  if (myStopDrawingButton->isEnabled()) {
135  myTemporalShape.push_back(P);
136  } else {
137  throw ProcessError("A new point cannot be added if drawing wasn't started");
138  }
139 }
140 
141 
142 void
144  if (myTemporalShape.size() > 1) {
145  myTemporalShape.pop_back();
146  }
147 }
148 
149 
150 const PositionVector&
152  return myTemporalShape;
153 }
154 
155 
156 bool
158  return myStopDrawingButton->isEnabled();
159 }
160 
161 
162 void
164  myDeleteLastCreatedPoint = value;
165 }
166 
167 
168 bool
171 }
172 
173 
174 long
175 GNEDrawingShape::onCmdStartDrawing(FXObject*, FXSelector, void*) {
176  startDrawing();
177  return 0;
178 }
179 
180 
181 long
182 GNEDrawingShape::onCmdStopDrawing(FXObject*, FXSelector, void*) {
183  stopDrawing();
184  return 0;
185 }
186 
187 
188 long
189 GNEDrawingShape::onCmdAbortDrawing(FXObject*, FXSelector, void*) {
190  abortDrawing();
191  return 0;
192 }
193 
194 /****************************************************************************/
FXDEFMAP(GNEDrawingShape) DrawingShapeMap[]
@ MID_GNE_STARTDRAWING
start drawing polygon
Definition: GUIAppEnum.h:936
@ MID_GNE_ABORTDRAWING
abort drawing polygon
Definition: GUIAppEnum.h:940
@ MID_GNE_STOPDRAWING
stop drawing polygon
Definition: GUIAppEnum.h:938
#define GUIDesignButton
Definition: GUIDesigns.h:77
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:271
#define TL(string)
Definition: MsgHandler.h:282
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
virtual bool shapeDrawed()
build a shaped element using the drawed shape
Definition: GNEFrame.cpp:278
MFXGroupBoxModule (based on FXGroupBox)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.