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,
80  GRAPHIC_POLYGON,
81  VIA
82  };
83 
90  MODE GetDrawingMode() const;
91 
98  int DrawLine( const TOOL_EVENT& aEvent );
99 
106  int DrawCircle( const TOOL_EVENT& aEvent );
107 
114  int DrawArc( const TOOL_EVENT& aEvent );
115 
121  int PlaceText( const TOOL_EVENT& aEvent );
122 
129  int DrawDimension( const TOOL_EVENT& aEvent );
130 
138  int DrawZone( const TOOL_EVENT& aEvent );
139  int DrawGraphicPolygon( const TOOL_EVENT& aEvent );
140 
141  int DrawVia( const TOOL_EVENT& aEvent );
142 
150  int DrawZoneKeepout( const TOOL_EVENT& aEvent );
151 
159  int DrawZoneCutout( const TOOL_EVENT& aEvent );
160 
168  int DrawSimilarZone( const TOOL_EVENT& aEvent );
169 
174  int PlaceDXF( const TOOL_EVENT& aEvent );
175 
180  int SetAnchor( const TOOL_EVENT& aEvent );
181 
183  void setTransitions() override;
184 
185 private:
186 
187  enum class ZONE_MODE
188  {
189  ADD,
190  CUTOUT,
191  SIMILAR,
192  GRAPHIC_POLYGON
193  };
194 
204  bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic,
205  OPT<VECTOR2D> aStartingPoint = NULLOPT );
206 
212  bool drawArc( DRAWSEGMENT*& aGraphic );
213 
224  int drawZone( bool aKeepout, ZONE_MODE aMode );
225 
239  bool getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZone );
240 
246  void runPolygonEventLoop( POLYGON_GEOM_MANAGER& aPolyGeomMgr );
247 
256  void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper, VECTOR2I& aPos ) const;
257 
263  void constrainDimension( DIMENSION* dimension );
264 
266  int getSegmentWidth( PCB_LAYER_ID aLayer ) const;
267 
269  PCB_LAYER_ID getDrawingLayer() const;
270 
276 
278  unsigned int m_lineWidth;
279 
280  // How does line width change after one -/+ key press.
281  static const unsigned int WIDTH_STEP;
282 
283 
284  // give internal access to drawing helper classes
285  friend class ZONE_CREATE_HELPER;
286 };
287 
288 #endif /* __DRAWING_TOOL_H */
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
BOARD * m_board
Definition: drawing_tool.h:273
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:281
Class TOOL_MENU.
Definition: tool_menu.h:47
TOOL_MENU & GetToolMenu()
Get the DRAWING_TOOL top-level context menu
Definition: drawing_tool.h:62
KIGFX::VIEW * m_view
Definition: drawing_tool.h:271
PCB_LAYER_ID
A quick note on layer IDs:
const auto NULLOPT
Definition: optional.h:9
Class DRAWING_TOOL.
Definition: drawing_tool.h:49
Class TOOL_EVENT.
Definition: tool_event.h:168
unsigned int m_lineWidth
Stores the current line width for multisegment drawing.
Definition: drawing_tool.h:278
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:272
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:274
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:68
Common, abstract interface for edit frames.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
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
Class VIEW.
Definition: view.h:61
Definition: am_param.h:150
Class DIMENSION.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...