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 <core/optional.h>
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,
81  };
82 
89  MODE GetDrawingMode() const;
90 
97  int DrawLine( const TOOL_EVENT& aEvent );
98 
105  int DrawCircle( const TOOL_EVENT& aEvent );
106 
113  int DrawArc( const TOOL_EVENT& aEvent );
114 
120  int PlaceText( const TOOL_EVENT& aEvent );
121 
128  int DrawDimension( const TOOL_EVENT& aEvent );
129 
137  int DrawZone( const TOOL_EVENT& aEvent );
138  int DrawGraphicPolygon( const TOOL_EVENT& aEvent );
139 
140  int DrawVia( const TOOL_EVENT& aEvent );
141 
149  int DrawZoneKeepout( const TOOL_EVENT& aEvent );
150 
158  int DrawZoneCutout( const TOOL_EVENT& aEvent );
159 
167  int DrawSimilarZone( const TOOL_EVENT& aEvent );
168 
173  int PlaceDXF( const TOOL_EVENT& aEvent );
174 
179  int SetAnchor( const TOOL_EVENT& aEvent );
180 
182  void setTransitions() override;
183 
184 private:
185 
186  enum class ZONE_MODE
187  {
188  ADD,
189  CUTOUT,
190  SIMILAR,
192  };
193 
197  void showContextMenu();
198 
208  bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
209  OPT<VECTOR2D> aStartingPoint = NULLOPT );
210 
216  bool drawArc( DRAWSEGMENT*& aGraphic );
217 
228  int drawZone( bool aKeepout, ZONE_MODE aMode );
229 
243  bool getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZone );
244 
250  void runPolygonEventLoop( POLYGON_GEOM_MANAGER& aPolyGeomMgr );
251 
259  void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const;
260 
262  int getSegmentWidth( unsigned int aLayer ) const;
263 
266 
272 
274  unsigned int m_lineWidth;
275 
278 
279  // How does line width change after one -/+ key press.
280  static const unsigned int WIDTH_STEP;
281 
282 
283  // give internal access to drawing helper classes
284  friend class ZONE_CREATE_HELPER;
285 };
286 
287 #endif /* __DRAWING_TOOL_H */
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
int DrawCircle(const TOOL_EVENT &aEvent)
Function DrawCircle() Starts interactively drawing a circle.
int DrawVia(const TOOL_EVENT &aEvent)
int DrawZone(const TOOL_EVENT &aEvent)
Function DrawZone() Starts interactively drawing a zone.
BOARD * m_board
Definition: drawing_tool.h:269
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
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:280
Class TOOL_MENU.
Definition: tool_menu.h:47
bool drawSegment(int aShape, DRAWSEGMENT *&aGraphic, OPT< VECTOR2D > aStartingPoint=NULLOPT)
Starts drawing a selected shape (i.e.
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE_CONTAINER *&aZone)
Function getSourceZoneForAction()
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:267
int getSegmentWidth(unsigned int aLayer) const
Returns the appropriate width for a segment depending on the settings.
PCB_LAYER_ID
A quick note on layer IDs:
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows to input text and its settings and then lets the u...
const auto NULLOPT
Definition: optional.h:9
Class DRAWING_TOOL.
Definition: drawing_tool.h:49
int DrawZoneKeepout(const TOOL_EVENT &aEvent)
Function DrawZoneKeepout() Starts interactively drawing a keepout area.
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:274
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 (...
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:268
int DrawZoneCutout(const TOOL_EVENT &aEvent)
Function DrawZoneCutout() Starts interactively drawing a zone cutout area of an existing zone...
void setTransitions() override
Sets up handlers for various events.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
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.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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
boost::optional< T > OPT
Definition: optional.h:7
int DrawGraphicPolygon(const TOOL_EVENT &aEvent)
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:277
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.