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.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 
26 
27 #include "GNEDrawingShape.h"
28 
29 
30 // ===========================================================================
31 // FOX callback mapping
32 // ===========================================================================
33 
34 FXDEFMAP(GNEDrawingShape) DrawingShapeMap[] = {
38 };
39 
40 // Object implementation
41 FXIMPLEMENT(GNEDrawingShape, MFXGroupBoxModule, DrawingShapeMap, ARRAYNUMBER(DrawingShapeMap))
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 
49  MFXGroupBoxModule(frameParent, TL("Drawing")),
50  myFrameParent(frameParent),
51  myDeleteLastCreatedPoint(false) {
52  // create start and stop buttons
53  myStartDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Start drawing"), "", "", 0, this, MID_GNE_STARTDRAWING, GUIDesignButton);
54  myStopDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Stop drawing"), "", "", 0, this, MID_GNE_STOPDRAWING, GUIDesignButton);
55  myAbortDrawingButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Abort drawing"), "", "", 0, this, MID_GNE_ABORTDRAWING, GUIDesignButton);
56  // create information label
57  std::ostringstream information;
58  information
59  << "- " << TL("'Start drawing' or ENTER to create a shape.") << "\n"
60  << "- " << TL("'Stop drawing' or ENTER to finish shape creation.") << "\n"
61  << "- " << TL("'Abort drawing' or ESC to abort shape creation.") << "\n"
62  << "- " << TL("'Shift + Click' to remove the last inserted point.");
63  myInformationLabel = new MFXDynamicLabel(getCollapsableFrame(), information.str().c_str(), 0, GUIDesignLabelFrameInformation);
64  // disable stop and abort functions as init
65  myStopDrawingButton->disable();
66  myAbortDrawingButton->disable();
67 }
68 
69 
71 
72 
74  // abort current drawing before show
75  abortDrawing();
76  // show MFXGroupBoxModule
77  MFXGroupBoxModule::show();
78 }
79 
80 
82  // abort current drawing before hide
83  abortDrawing();
84  // show MFXGroupBoxModule
85  MFXGroupBoxModule::hide();
86 }
87 
88 
89 void
91  // Only start drawing if GNEDrawingShape modul is shown
92  if (shown()) {
93  // change buttons
94  myStartDrawingButton->disable();
95  myStopDrawingButton->enable();
96  myAbortDrawingButton->enable();
97  }
98 }
99 
100 
101 void
103  // try to build shape
104  if (myFrameParent->shapeDrawed()) {
105  // clear created points
106  myTemporalShape.clear();
107  // change buttons
108  myStartDrawingButton->enable();
109  myStopDrawingButton->disable();
110  myAbortDrawingButton->disable();
111  } else {
112  // abort drawing if shape cannot be created
113  abortDrawing();
114  }
115 }
116 
117 
118 void
120  // clear created points
121  myTemporalShape.clear();
122  // change buttons
123  myStartDrawingButton->enable();
124  myStopDrawingButton->disable();
125  myAbortDrawingButton->disable();
126 }
127 
128 
129 void
131  if (myStopDrawingButton->isEnabled()) {
132  myTemporalShape.push_back(P);
133  } else {
134  throw ProcessError(TL("A new point cannot be added if drawing wasn't started"));
135  }
136 }
137 
138 
139 void
141  if (myTemporalShape.size() > 1) {
142  myTemporalShape.pop_back();
143  }
144 }
145 
146 
147 const PositionVector&
149  return myTemporalShape;
150 }
151 
152 
153 bool
155  return myStopDrawingButton->isEnabled();
156 }
157 
158 
159 void
161  myDeleteLastCreatedPoint = value;
162 }
163 
164 
165 bool
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 /****************************************************************************/
FXDEFMAP(GNEDrawingShape) DrawingShapeMap[]
@ MID_GNE_STARTDRAWING
start drawing polygon
Definition: GUIAppEnum.h:1007
@ MID_GNE_ABORTDRAWING
abort drawing polygon
Definition: GUIAppEnum.h:1011
@ MID_GNE_STOPDRAWING
stop drawing polygon
Definition: GUIAppEnum.h:1009
#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
virtual bool shapeDrawed()
build a shaped element using the drawed shape
Definition: GNEFrame.cpp:279
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
Definition: GUIDesigns.cpp:128
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.