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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef __DRAWING_TOOL_H
28 #define __DRAWING_TOOL_H
29 
30 #include <core/optional.h>
31 #include <tool/tool_menu.h>
32 #include <tools/pcb_tool_base.h>
33 #include <tools/pcb_actions.h>
34 
35 namespace KIGFX
36 {
37  class VIEW;
38  class VIEW_CONTROLS;
39 }
40 
41 class BOARD;
43 class PCB_SHAPE;
45 
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 
84  MODE GetDrawingMode() const;
85 
89  std::vector<BOARD_ITEM*> DrawBoardCharacteristics( wxPoint origin, PCB_LAYER_ID aLayer,
90  bool aDrawNow, wxPoint* tablesize );
91 
95  std::vector<BOARD_ITEM*> DrawSpecificationStackup( wxPoint origin, PCB_LAYER_ID aLayer,
96  bool aDrawNow, wxPoint* tablesize );
97 
101  int PlaceCharacteristics( const TOOL_EVENT& aEvent );
102 
106  int PlaceStackup( const TOOL_EVENT& aEvent );
107 
115  int DrawLine( const TOOL_EVENT& aEvent );
116 
123  int DrawRectangle( const TOOL_EVENT& aEvent );
124 
131  int DrawCircle( const TOOL_EVENT& aEvent );
132 
140  int DrawArc( const TOOL_EVENT& aEvent );
141 
146  int PlaceText( const TOOL_EVENT& aEvent );
147 
155  int DrawDimension( const TOOL_EVENT& aEvent );
156 
170  int DrawZone( const TOOL_EVENT& aEvent );
171 
172  int DrawVia( const TOOL_EVENT& aEvent );
173 
177  int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
178 
190  int InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
191  std::vector<BOARD_ITEM*>& aItems,
192  std::vector<BOARD_ITEM*>& aPreview, LSET* aLayers );
193 
194 
198  int SetAnchor( const TOOL_EVENT& aEvent );
199 
203  int ToggleLine45degMode( const TOOL_EVENT& aEvent );
204 
206  void setTransitions() override;
207 
208 private:
220  bool drawSegment( const std::string& aTool, PCB_SHAPE** aGraphic,
221  OPT<VECTOR2D> aStartingPoint );
222 
231  bool drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool aImmediateMode );
232 
255  bool getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone );
256 
263 
265  int getSegmentWidth( PCB_LAYER_ID aLayer ) const;
266 
272  bool m_inDrawingTool; // Re-entrancy guard
273 
274  unsigned int m_lineWidth; // Current line width for multi-segment drawing
275  static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press
276 
277 
278  friend class ZONE_CREATE_HELPER; // give internal access to helper classes
279 };
280 
281 #endif /* __DRAWING_TOOL_H */
int DrawCircle(const TOOL_EVENT &aEvent)
Start interactively drawing a circle.
int InteractivePlaceWithPreview(const TOOL_EVENT &aEvent, std::vector< BOARD_ITEM * > &aItems, std::vector< BOARD_ITEM * > &aPreview, LSET *aLayers)
Interactively place a set of BOARD_ITEM.
int DrawVia(const TOOL_EVENT &aEvent)
int DrawZone(const TOOL_EVENT &aEvent)
Start interactively drawing a zone.
BOARD * m_board
Definition: drawing_tool.h:269
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:194
int DrawLine(const TOOL_EVENT &aEvent)
Start interactively drawing a line.
int DrawRectangle(const TOOL_EVENT &aEvent)
Start interactively drawing a rectangle.
static const unsigned int WIDTH_STEP
Definition: drawing_tool.h:275
Abstract dimension API.
Definition: pcb_dimension.h:95
bool m_inDrawingTool
Definition: drawing_tool.h:272
KIGFX::VIEW * m_view
Definition: drawing_tool.h:267
std::vector< BOARD_ITEM * > DrawSpecificationStackup(wxPoint origin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint *tablesize)
Function DrawSpecificationStackup()
int PlaceImportedGraphics(const TOOL_EVENT &aEvent)
Place a drawing imported from a DXF or SVG file in footprint editor.
bool drawSegment(const std::string &aTool, PCB_SHAPE **aGraphic, OPT< VECTOR2D > aStartingPoint)
Start drawing a selected shape (i.e.
PCB_LAYER_ID
A quick note on layer IDs:
int PlaceText(const TOOL_EVENT &aEvent)
Display a dialog that allows one to input text and its settings and then lets the user decide where t...
LSET is a set of PCB_LAYER_IDs.
std::vector< BOARD_ITEM * > DrawBoardCharacteristics(wxPoint origin, PCB_LAYER_ID aLayer, bool aDrawNow, wxPoint *tablesize)
Function DrawBoardCharacteristics()
Tool responsible for drawing graphical elements like lines, arcs, circles, etc.
Definition: drawing_tool.h:50
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
bool Init() override
Init() is called once upon a registration of the tool.
Generic, UI-independent tool event.
Definition: tool_event.h:152
unsigned int m_lineWidth
Definition: drawing_tool.h:274
An interface for classes handling user events controlling the view behavior such as zooming,...
int PlaceCharacteristics(const TOOL_EVENT &aEvent)
Function PlaceCharacteristics()
bool drawArc(const std::string &aTool, PCB_SHAPE **aGraphic, bool aImmediateMode)
Start drawing an arc.
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:268
int getSegmentWidth(PCB_LAYER_ID aLayer) const
ZONE_MODE
Definition: pcb_actions.h:33
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:270
void constrainDimension(PCB_DIMENSION_BASE *aDim)
Force the dimension lime to be drawn on multiple of 45 degrees.
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE **aZone)
Draw a polygon, that is added as a zone or a keepout area.
int SetAnchor(const TOOL_EVENT &aEvent)
Place the footprint anchor (only in footprint editor).
Common, abstract interface for edit frames.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
int PlaceStackup(const TOOL_EVENT &aEvent)
Function PlaceStackup()
An adjunct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from ...
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
int ToggleLine45degMode(const TOOL_EVENT &aEvent)
Toggle the 45 degree angle constraint for graphic lines.
boost::optional< T > OPT
Definition: optional.h:7
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
MODE GetDrawingMode() const
Return the current drawing mode of the DRAWING_TOOL or #MODE::NONE if not currently in any drawing mo...
int DrawArc(const TOOL_EVENT &aEvent)
Start interactively drawing an arc.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
int DrawDimension(const TOOL_EVENT &aEvent)
Start interactively drawing a dimension.