KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef __DRAWING_TOOL_H
24#define __DRAWING_TOOL_H
25
26#include <functional>
27#include <stack>
28#include <optional>
29#include <eda_shape.h>
32#include <tool/tool_menu.h>
33#include <tools/pcb_selection.h>
34#include <tools/pcb_tool_base.h>
35#include <tools/pcb_actions.h>
36
37namespace KIGFX
38{
39 class VIEW;
40 class VIEW_CONTROLS;
41}
42
43class BOARD;
44class BOARD_ITEM;
45class PAD;
46class PCB_TRACK;
47class DRC_ENGINE;
49class PCB_SHAPE;
51class PCB_VIA;
54class STATUS_MIN_MAX_POPUP;
55
56
63 int aWorstClearance, int aEpsilon );
64
65
72PCB_TRACK* FindSnapTrack( PCB_BASE_EDIT_FRAME* aFrame, const PCB_VIA* aVia, const VECTOR2I& aPosition,
73 const LSET& aLayers, int aSnapRange = 0 );
74PAD* FindSnapPad( PCB_BASE_EDIT_FRAME* aFrame, const PCB_VIA* aVia, const VECTOR2I& aPosition, const LSET& aLayers,
75 int aSnapRange = 0 );
76
77
81
83{
84public:
87
89 bool Init() override;
90
92 void Reset( RESET_REASON aReason ) override;
93
120
125 MODE GetDrawingMode() const;
126
129 int PlaceTuningPattern( const TOOL_EVENT& aEvent );
130
133 int PlaceViaStitch( const TOOL_EVENT& aEvent );
134
138 int PlaceMicroviaStack( const TOOL_EVENT& aEvent );
139
144 void SeedViaStackStart( const VECTOR2I& aPos, PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd )
145 {
146 m_viaStackSeeded = true;
147 m_viaStackSeedPos = aPos;
148 m_viaStackSeedStart = aStart;
149 m_viaStackSeedEnd = aEnd;
150 }
151
159 int DrawLine( const TOOL_EVENT& aEvent );
160
167 int DrawRectangle( const TOOL_EVENT& aEvent );
168
175 int DrawCircle( const TOOL_EVENT& aEvent );
176
177 int DrawEllipse( const TOOL_EVENT& aEvent );
178
179 int DrawEllipseArc( const TOOL_EVENT& aEvent );
180
188 int DrawArc( const TOOL_EVENT& aEvent );
189
195 int DrawBezier( const TOOL_EVENT& aEvent );
196
201 int PlaceReferenceImage( const TOOL_EVENT& aEvent );
202
206 int ConvertImageToOutlines( const TOOL_EVENT& aEvent );
207
211 int PlacePoint( const TOOL_EVENT& aEvent );
212
217 int PlaceText( const TOOL_EVENT& aEvent );
218
219 /*
220 * Start interactively drawing a table (rows & columns of TEXTBOXes).
221 */
222 int DrawTable( const TOOL_EVENT& aEvent );
223
229 int DrawBarcode( const TOOL_EVENT& aEvent );
230
238 int DrawDimension( const TOOL_EVENT& aEvent );
239
253 int DrawZone( const TOOL_EVENT& aEvent );
254
255 int DrawVia( const TOOL_EVENT& aEvent );
256
260 int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
261
265 int SetAnchor( const TOOL_EVENT& aEvent );
266
270 int PlaceSubGrid( const TOOL_EVENT& aEvent );
271
273 void setTransitions() override;
274
275 void SetStroke( const STROKE_PARAMS& aStroke, PCB_LAYER_ID aLayer )
276 {
277 m_layer = aLayer;
278 m_stroke = aStroke;
279 }
280
281 void UpdateStatusBar() const;
282
283private:
297 bool drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, std::optional<VECTOR2D> aStartingPoint,
298 std::stack<PCB_SHAPE*>* aCommittedGraphics );
299
300 int runSimpleShapeDraw( const TOOL_EVENT& aEvent, SHAPE_T aShapeType, MODE aMode, const wxString& aCommitLabel,
301 std::function<bool( const TOOL_EVENT&, PCB_SHAPE**, std::optional<VECTOR2D> )> aDrawer );
302
308 VECTOR2I snapEventPosition( const TOOL_EVENT& aEvent );
309
324 SHAPE_DRAW_RESULT drawManagedShape( const TOOL_EVENT& aTool, std::unique_ptr<PCB_SHAPE>& aGraphic,
325 SHAPE_DRAW_BEHAVIOR& aBehavior, const std::vector<VECTOR2D>& aInitialPts,
326 const std::optional<ARC_TANGENT_SEED>& aTangentSeed = std::nullopt,
327 VECTOR2I* aLastClick = nullptr );
328
341 bool getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone );
342
349
357 VECTOR2I getClampedDifferenceEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
358 {
359 typedef std::numeric_limits<int> coord_limits;
360 const int guardValue = 1;
361
362 VECTOR2I::extended_type maxDiff = coord_limits::max() - guardValue;
363
364 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
365 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
366
367 if( xDiff > maxDiff )
368 xDiff = maxDiff;
369 if( yDiff > maxDiff )
370 yDiff = maxDiff;
371
372 if( xDiff < -maxDiff )
373 xDiff = -maxDiff;
374 if( yDiff < -maxDiff )
375 yDiff = -maxDiff;
376
377 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
378 }
379
387 VECTOR2I getClampedRadiusEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
388 {
389 typedef std::numeric_limits<int> coord_limits;
390 const int guardValue = 10;
391
392 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
393 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
394
395 double maxRadius = coord_limits::max() / 2 - guardValue;
396 double radius = std::hypot( xDiff, yDiff );
397
398 if( radius > maxRadius )
399 {
400 double scaleFactor = maxRadius / radius;
401
402 xDiff = KiROUND<double, int>( xDiff * scaleFactor );
403 yDiff = KiROUND<double, int>( yDiff * scaleFactor );
404 }
405
406 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
407 }
408
414 bool m_inDrawingTool; // Re-entrancy guard
415
416 PCB_LAYER_ID m_layer; // The layer we last drew on
417 STROKE_PARAMS m_stroke; // Current stroke for multi-segment drawing
419
423
424 // Router handoff: pre-anchored first hop and span for the next stack placement.
425 bool m_viaStackSeeded = false;
429
430 static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press
431 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
432
433
434 friend class ZONE_CREATE_HELPER; // give internal access to helper classes
435};
436
437#endif /* __DRAWING_TOOL_H */
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
VECTOR2I m_viaStackSeedPos
TEXT_ATTRIBUTES m_textAttrs
MODE GetDrawingMode() const
Return the current drawing mode of the DRAWING_TOOL or NONE if not currently in any drawing mode.
PCB_LAYER_ID m_viaStackSeedStart
PCB_LAYER_ID m_viaStackSeedEnd
void SetStroke(const STROKE_PARAMS &aStroke, PCB_LAYER_ID aLayer)
PCB_SELECTION m_preview
int DrawEllipseArc(const TOOL_EVENT &aEvent)
PCB_LAYER_ID m_layer
int DrawTable(const TOOL_EVENT &aEvent)
int SetAnchor(const TOOL_EVENT &aEvent)
Place the footprint anchor (only in footprint editor).
int DrawDimension(const TOOL_EVENT &aEvent)
Start interactively drawing a dimension.
int PlacePoint(const TOOL_EVENT &aEvent)
Place a reference 0D point.
void SeedViaStackStart(const VECTOR2I &aPos, PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd)
Pre-anchor the next microvia stack placement to a fixed first hop and span, used when the router hand...
int DrawVia(const TOOL_EVENT &aEvent)
bool m_viaStackSeeded
int PlaceSubGrid(const TOOL_EVENT &aEvent)
Place a grid item on the board.
KIGFX::VIEW_CONTROLS * m_controls
friend class ZONE_CREATE_HELPER
KIGFX::VIEW * m_view
STROKE_PARAMS m_stroke
int DrawZone(const TOOL_EVENT &aEvent)
Start interactively drawing a zone.
int DrawBezier(const TOOL_EVENT &aEvent)
Start interactively drawing a bezier curve.
int DrawLine(const TOOL_EVENT &aEvent)
Start interactively drawing a line.
VECTOR2I snapEventPosition(const TOOL_EVENT &aEvent)
Snap a tool event's position the way a click is snapped.
int DrawArc(const TOOL_EVENT &aEvent)
Start interactively drawing an arc.
VECTOR2I getClampedDifferenceEnd(const VECTOR2I &aOrigin, const VECTOR2I &aEnd)
Clamps the end vector to respect numeric limits of difference representation.
BOARD_CONNECTED_ITEM * m_pickerItem
MODE
The possible drawing modes of DRAWING_TOOL.
bool drawShape(const TOOL_EVENT &aTool, PCB_SHAPE **aGraphic, std::optional< VECTOR2D > aStartingPoint, std::stack< PCB_SHAPE * > *aCommittedGraphics)
Start drawing a selected shape (i.e.
void setTransitions() override
Set up handlers for various events.
int PlaceImportedGraphics(const TOOL_EVENT &aEvent)
Place a drawing imported from a DXF or SVG file.
VECTOR2I getClampedRadiusEnd(const VECTOR2I &aOrigin, const VECTOR2I &aEnd)
Clamp the end vector to respect numeric limits of radius representation.
static const unsigned int WIDTH_STEP
int runSimpleShapeDraw(const TOOL_EVENT &aEvent, SHAPE_T aShapeType, MODE aMode, const wxString &aCommitLabel, std::function< bool(const TOOL_EVENT &, PCB_SHAPE **, std::optional< VECTOR2D >)> aDrawer)
static const unsigned int COORDS_PADDING
int DrawBarcode(const TOOL_EVENT &aEvent)
Starts interactively drawing a barcode.
SHAPE_DRAW_RESULT drawManagedShape(const TOOL_EVENT &aTool, std::unique_ptr< PCB_SHAPE > &aGraphic, SHAPE_DRAW_BEHAVIOR &aBehavior, const std::vector< VECTOR2D > &aInitialPts, const std::optional< ARC_TANGENT_SEED > &aTangentSeed=std::nullopt, VECTOR2I *aLastClick=nullptr)
Run the interactive drawing event loop for a shape, driven by a SHAPE_DRAW_BEHAVIOR.
int DrawEllipse(const TOOL_EVENT &aEvent)
int PlaceMicroviaStack(const TOOL_EVENT &aEvent)
Place a stacked or staggered microvia stack.
int DrawCircle(const TOOL_EVENT &aEvent)
Start interactively drawing a circle.
int PlaceTuningPattern(const TOOL_EVENT &aEvent)
BOARD * m_board
int DrawRectangle(const TOOL_EVENT &aEvent)
Start interactively drawing a rectangle.
bool Init() override
Init() is called once upon a registration of the tool.
void constrainDimension(PCB_DIMENSION_BASE *aDim)
Force the dimension lime to be drawn on multiple of 45 degrees.
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...
PCB_BASE_EDIT_FRAME * m_frame
void UpdateStatusBar() const
int ConvertImageToOutlines(const TOOL_EVENT &aEvent)
Trace a placed reference image into filled graphics and replace it with them.
int PlaceReferenceImage(const TOOL_EVENT &aEvent)
Display a dialog that allows one to select a reference image and then decide where to place the image...
PCB_TUNING_PATTERN * m_tuningPattern
bool getSourceZoneForAction(ZONE_MODE aMode, ZONE **aZone)
Get a source zone item for an action that takes an existing zone into account (for example a cutout o...
int PlaceViaStitch(const TOOL_EVENT &aEvent)
Design Rule Checker object that performs all the DRC tests.
Definition drc_engine.h:129
An interface for classes handling user events controlling the view behavior such as zooming,...
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Definition pad.h:61
Common, abstract interface for edit frames.
Abstract dimension API.
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
Abstract interface for interactive shape-drawing behaviours.
Simple container to manage line stroke parameters.
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
VECTOR2_TRAITS< int32_t >::extended_type extended_type
Definition vector2d.h:69
Handle a list of polygons defining a copper zone.
Definition zone.h:70
int ComputeWorstViaClearance(PCB_BASE_EDIT_FRAME *aFrame, DRC_ENGINE *aEngine)
Shared placement DRC checks, used by the plain via tool and the microvia stack tool so both block pla...
PAD * FindSnapPad(PCB_BASE_EDIT_FRAME *aFrame, const PCB_VIA *aVia, const VECTOR2I &aPosition, const LSET &aLayers, int aSnapRange=0)
PCB_TRACK * FindSnapTrack(PCB_BASE_EDIT_FRAME *aFrame, const PCB_VIA *aVia, const VECTOR2I &aPosition, const LSET &aLayers, int aSnapRange=0)
int ViaSnapRange(PCB_BASE_EDIT_FRAME *aFrame)
Shared placement snapping, used by the plain via tool and the microvia stack tool.
bool CheckItemDRCViolation(BOARD_CONNECTED_ITEM *aItem, PCB_BASE_EDIT_FRAME *aFrame, DRC_ENGINE *aEngine, int aWorstClearance, int aEpsilon)
SHAPE_T
Definition eda_shape.h:55
void Reset() override
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
ZONE_MODE
Definition pcb_actions.h:34
SHAPE_DRAW_RESULT
Outcome of an interactive shape drawing loop, telling the caller how to continue.
int radius
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708