KiCad PCB EDA Suite
drawing_tool.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __DRAWING_TOOL_H
26 #define __DRAWING_TOOL_H
27 
28 #include <tools/pcb_tool.h>
29 #include <boost/optional.hpp>
30 
31 #include <tool/tool_menu.h>
32 
33 namespace KIGFX
34 {
35  class VIEW;
36  class VIEW_CONTROLS;
37 }
38 class BOARD;
40 class DRAWSEGMENT;
42 
49 class DRAWING_TOOL : public PCB_TOOL
50 {
51 public:
52  DRAWING_TOOL();
53  ~DRAWING_TOOL();
54 
56  bool Init() override;
57 
59  void Reset( RESET_REASON aReason ) override;
60 
63  {
64  return m_menu;
65  }
66 
68  enum class MODE
69  {
70  NONE,
71  LINE,
72  CIRCLE,
73  ARC,
74  TEXT,
75  ANCHOR,
76  DXF,
77  DIMENSION,
78  KEEPOUT,
79  ZONE,
80  };
81 
88  MODE GetDrawingMode() const;
89 
96  int DrawLine( const TOOL_EVENT& aEvent );
97 
104  int DrawCircle( const TOOL_EVENT& aEvent );
105 
112  int DrawArc( const TOOL_EVENT& aEvent );
113 
119  int PlaceText( const TOOL_EVENT& aEvent );
120 
127  int DrawDimension( const TOOL_EVENT& aEvent );
128 
136  int DrawZone( const TOOL_EVENT& aEvent );
137 
145  int DrawKeepout( const TOOL_EVENT& aEvent );
146 
154  int DrawZoneCutout( const TOOL_EVENT& aEvent );
155 
163  int DrawSimilarZone( const TOOL_EVENT& aEvent );
164 
169  int PlaceDXF( const TOOL_EVENT& aEvent );
170 
175  int SetAnchor( const TOOL_EVENT& aEvent );
176 
178  void SetTransitions() override;
179 
180 private:
181 
182  enum class ZONE_MODE
183  {
184  ADD,
185  CUTOUT,
186  SIMILAR
187  };
188 
192  void showContextMenu();
193 
200  bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
201  boost::optional<VECTOR2D> aStartingPoint = boost::none );
202 
208  bool drawArc( DRAWSEGMENT*& aGraphic );
209 
217  int drawZone( bool aKeepout, ZONE_MODE aMode );
218 
232  bool getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZone );
233 
239  void runPolygonEventLoop( POLYGON_GEOM_MANAGER& aPolyGeomMgr );
240 
248  void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const;
249 
251  int getSegmentWidth( unsigned int aLayer ) const;
252 
254  LAYER_ID getDrawingLayer() const;
255 
261 
263  unsigned int m_lineWidth;
264 
267 
268  // How does line width change after one -/+ key press.
269  static const unsigned int WIDTH_STEP;
270 
271 
272  // give internal access to drawing helper classes
273  friend class ZONE_CREATE_HELPER;
274 };
275 
276 #endif /* __DRAWING_TOOL_H */
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
int DrawKeepout(const TOOL_EVENT &aEvent)
Function DrawKeepout() Starts interactively drawing a keepout area.
int DrawCircle(const TOOL_EVENT &aEvent)
Function DrawCircle() Starts interactively drawing a circle.
int DrawZone(const TOOL_EVENT &aEvent)
Function DrawZone() Starts interactively drawing a zone.
BOARD * m_board
Definition: drawing_tool.h:258
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
MODE GetDrawingMode() const
Function GetDrawingMode.
int drawZone(bool aKeepout, ZONE_MODE aMode)
Draws a polygon, that is added as a zone or a keepout area.
int DrawLine(const TOOL_EVENT &aEvent)
Function DrawLine() Starts interactively drawing a line.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:269
Class TOOL_MENU.
Definition: tool_menu.h:47
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE_CONTAINER *&aZone)
Function getSourceZoneForAction()
bool drawSegment(int aShape, DRAWSEGMENT *&aGraphic, boost::optional< VECTOR2D > aStartingPoint=boost::none)
Starts drawing a selected shape (i.e.
Add a new zone with the same settings as an existing one.
TOOL_MENU & GetToolMenu()
Get the DRAWING_TOOL top-level context menu
Definition: drawing_tool.h:62
int PlaceDXF(const TOOL_EVENT &aEvent)
Function PlaceDXF() Places a drawing imported from a DXF file in module editor.
KIGFX::VIEW * m_view
Definition: drawing_tool.h:256
int getSegmentWidth(unsigned int aLayer) const
Returns the appropriate width for a segment depending on the settings.
void SetTransitions() override
Sets up handlers for various events.
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows to input text and its settings and then lets the u...
Class DRAWING_TOOL.
Definition: drawing_tool.h:49
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Class TOOL_EVENT.
Definition: tool_event.h:162
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:263
void showContextMenu()
Shows the context menu for the drawing tool This menu consists of normal UI functions (zoom...
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
Definition: view_controls.h:94
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:257
Class PCB_TOOL.
Definition: pcb_tool.h:45
int DrawZoneCutout(const TOOL_EVENT &aEvent)
Function DrawZoneCutout() Starts interactively drawing a zone cutout area of an existing zone...
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:259
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:68
int SetAnchor(const TOOL_EVENT &aEvent)
Function SetAnchor() Places the footprint anchor (only in module editor).
Common, abstract interface for edit frames.
LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry ...
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
bool drawArc(DRAWSEGMENT *&aGraphic)
Starts drawing an arc.
Class VIEW.
Definition: view.h:58
Add a new zone/keepout with fresh settings.
int DrawSimilarZone(const TOOL_EVENT &aEvent)
Function DrawSimilarZone() Starts interactively drawing a zone with same settings as an existing zone...
void runPolygonEventLoop(POLYGON_GEOM_MANAGER &aPolyGeomMgr)
Run the event loop for polygon creation, sending user input on to the given POLYGON_GEOM_MANAGER for ...
int DrawArc(const TOOL_EVENT &aEvent)
Function DrawArc() Starts interactively drawing an arc.
Make a cutout to an existing zone.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: drawing_tool.h:266
void make45DegLine(DRAWSEGMENT *aSegment, DRAWSEGMENT *aHelper) const
Function make45DegLine() Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees.
int DrawDimension(const TOOL_EVENT &aEvent)
Function DrawDimension() Starts interactively drawing a dimension.