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  * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __DRAWING_TOOL_H
27 #define __DRAWING_TOOL_H
28 
29 #include <core/optional.h>
30 #include <tool/tool_menu.h>
31 #include <tools/pcb_tool_base.h>
32 #include <tools/pcb_actions.h>
33 
34 namespace KIGFX
35 {
36  class VIEW;
37  class VIEW_CONTROLS;
38 }
39 class BOARD;
41 class DRAWSEGMENT;
43 
51 {
52 public:
53  DRAWING_TOOL();
54  ~DRAWING_TOOL();
55 
57  bool Init() override;
58 
60  void Reset( RESET_REASON aReason ) override;
61 
63  enum class MODE
64  {
65  NONE,
66  LINE,
67  RECTANGLE,
68  CIRCLE,
69  ARC,
70  TEXT,
71  ANCHOR,
72  DXF,
73  DIMENSION,
74  KEEPOUT,
75  ZONE,
77  VIA
78  };
79 
86  MODE GetDrawingMode() const;
87 
94  int DrawLine( const TOOL_EVENT& aEvent );
95 
102  int DrawRectangle( const TOOL_EVENT& aEvent );
103 
110  int DrawCircle( const TOOL_EVENT& aEvent );
111 
118  int DrawArc( const TOOL_EVENT& aEvent );
119 
125  int PlaceText( const TOOL_EVENT& aEvent );
126 
133  int DrawDimension( const TOOL_EVENT& aEvent );
134 
147  int DrawZone( const TOOL_EVENT& aEvent );
148 
149  int DrawVia( const TOOL_EVENT& aEvent );
150 
155  int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
156 
161  int SetAnchor( const TOOL_EVENT& aEvent );
162 
164  void setTransitions() override;
165 
166 private:
167 
179  bool drawSegment( const std::string& aTool, int aShape, DRAWSEGMENT** aGraphic,
180  OPT<VECTOR2D> aStartingPoint );
181 
189  bool drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bool aImmediateMode );
190 
215  bool getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER** aZone );
216 
222  void constrainDimension( DIMENSION* aDim );
223 
225  int getSegmentWidth( PCB_LAYER_ID aLayer ) const;
226 
232 
233  unsigned int m_lineWidth; // Current line width for multi-segment drawing
234  static const unsigned int WIDTH_STEP; // Amount of width change with one -/+ key press
235 
236  // give internal access to drawing helper classes
237  friend class ZONE_CREATE_HELPER;
238 };
239 
240 #endif /* __DRAWING_TOOL_H */
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
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:229
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
int DrawLine(const TOOL_EVENT &aEvent)
Function DrawLine() Starts interactively drawing a line.
int DrawRectangle(const TOOL_EVENT &aEvent)
Function DrawRectangle() Starts interactively drawing a rectangle.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:234
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE_CONTAINER **aZone)
Draws a polygon, that is added as a zone or a keepout area.
KIGFX::VIEW * m_view
Definition: drawing_tool.h:227
void constrainDimension(DIMENSION *aDim)
Function constrainDimension() Forces the dimension lime to be drawn on multiple of 45 degrees.
int PlaceImportedGraphics(const TOOL_EVENT &aEvent)
Function PlaceImportedGraphics() Places a drawing imported from a DXF or SVG file in module editor.
PCB_LAYER_ID
A quick note on layer IDs:
int PlaceText(const TOOL_EVENT &aEvent)
Function PlaceText() Displays a dialog that allows one to input text and its settings and then lets t...
DRAWING_TOOL.
Definition: drawing_tool.h:50
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.
TOOL_EVENT.
Definition: tool_event.h:171
unsigned int m_lineWidth
Definition: drawing_tool.h:233
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:228
int getSegmentWidth(PCB_LAYER_ID aLayer) const
Returns the appropriate width for a segment depending on the settings.
ZONE_MODE
Definition: pcb_actions.h:36
void setTransitions() override
Sets up handlers for various events.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:230
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:63
bool drawArc(const std::string &aTool, DRAWSEGMENT **aGraphic, bool aImmediateMode)
Starts drawing an arc.
int SetAnchor(const TOOL_EVENT &aEvent)
Function SetAnchor() Places the footprint anchor (only in module editor).
Common, abstract interface for edit frames.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
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:79
boost::optional< T > OPT
Definition: optional.h:7
bool drawSegment(const std::string &aTool, int aShape, DRAWSEGMENT **aGraphic, OPT< VECTOR2D > aStartingPoint)
Starts drawing a selected shape (i.e.
VIEW.
Definition: view.h:61
MODE GetDrawingMode() const
Function GetDrawingMode.
int DrawArc(const TOOL_EVENT &aEvent)
Function DrawArc() Starts interactively drawing an arc.
DIMENSION.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
int DrawDimension(const TOOL_EVENT &aEvent)
Function DrawDimension() Starts interactively drawing a dimension.