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>
31#include <tool/tool_menu.h>
32#include <tools/pcb_selection.h>
33#include <tools/pcb_tool_base.h>
34#include <tools/pcb_actions.h>
35
36namespace KIGFX
37{
38 class VIEW;
39 class VIEW_CONTROLS;
40}
41
42class BOARD;
43class BOARD_ITEM;
44class PAD;
45class PCB_TRACK;
46class DRC_ENGINE;
48class PCB_SHAPE;
50class PCB_VIA;
53class STATUS_MIN_MAX_POPUP;
54
55
62 int aWorstClearance, int aEpsilon );
63
64
71PCB_TRACK* FindSnapTrack( PCB_BASE_EDIT_FRAME* aFrame, const PCB_VIA* aVia, const VECTOR2I& aPosition,
72 const LSET& aLayers, int aSnapRange = 0 );
73PAD* FindSnapPad( PCB_BASE_EDIT_FRAME* aFrame, const PCB_VIA* aVia, const VECTOR2I& aPosition, const LSET& aLayers,
74 int aSnapRange = 0 );
75
76
80
82{
83public:
86
88 bool Init() override;
89
91 void Reset( RESET_REASON aReason ) override;
92
119
124 MODE GetDrawingMode() const;
125
128 std::vector<BOARD_ITEM*> DrawSpecificationStackup( const VECTOR2I& origin, PCB_LAYER_ID aLayer,
129 bool aDrawNow, VECTOR2I* tablesize );
130
133 int PlaceStackup( const TOOL_EVENT& aEvent );
134
137 int PlaceTuningPattern( const TOOL_EVENT& aEvent );
138
141 int PlaceViaStitch( const TOOL_EVENT& aEvent );
142
146 int PlaceMicroviaStack( const TOOL_EVENT& aEvent );
147
152 void SeedViaStackStart( const VECTOR2I& aPos, PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd )
153 {
154 m_viaStackSeeded = true;
155 m_viaStackSeedPos = aPos;
156 m_viaStackSeedStart = aStart;
157 m_viaStackSeedEnd = aEnd;
158 }
159
167 int DrawLine( const TOOL_EVENT& aEvent );
168
175 int DrawRectangle( const TOOL_EVENT& aEvent );
176
183 int DrawCircle( const TOOL_EVENT& aEvent );
184
185 int DrawEllipse( const TOOL_EVENT& aEvent );
186
187 int DrawEllipseArc( const TOOL_EVENT& aEvent );
188
196 int DrawArc( const TOOL_EVENT& aEvent );
197
203 int DrawBezier( const TOOL_EVENT& aEvent );
204
209 int PlaceReferenceImage( const TOOL_EVENT& aEvent );
210
214 int PlacePoint( const TOOL_EVENT& aEvent );
215
220 int PlaceText( const TOOL_EVENT& aEvent );
221
222 /*
223 * Start interactively drawing a table (rows & columns of TEXTBOXes).
224 */
225 int DrawTable( const TOOL_EVENT& aEvent );
226
232 int DrawBarcode( const TOOL_EVENT& aEvent );
233
241 int DrawDimension( const TOOL_EVENT& aEvent );
242
256 int DrawZone( const TOOL_EVENT& aEvent );
257
258 int DrawVia( const TOOL_EVENT& aEvent );
259
263 int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
264
268 int SetAnchor( const TOOL_EVENT& aEvent );
269
273 int PlaceGridItem( const TOOL_EVENT& aEvent );
274
276 void setTransitions() override;
277
278 void SetStroke( const STROKE_PARAMS& aStroke, PCB_LAYER_ID aLayer )
279 {
280 m_layer = aLayer;
281 m_stroke = aStroke;
282 }
283
284 void UpdateStatusBar() const;
285
286private:
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
312 SHAPE_DRAW_RESULT drawManagedShape( const TOOL_EVENT& aTool, std::unique_ptr<PCB_SHAPE>& aGraphic,
313 SHAPE_DRAW_BEHAVIOR& aBehavior, const std::vector<VECTOR2D>& aInitialPts );
314
327 bool getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone );
328
335
343 VECTOR2I getClampedDifferenceEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
344 {
345 typedef std::numeric_limits<int> coord_limits;
346 const int guardValue = 1;
347
348 VECTOR2I::extended_type maxDiff = coord_limits::max() - guardValue;
349
350 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
351 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
352
353 if( xDiff > maxDiff )
354 xDiff = maxDiff;
355 if( yDiff > maxDiff )
356 yDiff = maxDiff;
357
358 if( xDiff < -maxDiff )
359 xDiff = -maxDiff;
360 if( yDiff < -maxDiff )
361 yDiff = -maxDiff;
362
363 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
364 }
365
373 VECTOR2I getClampedRadiusEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
374 {
375 typedef std::numeric_limits<int> coord_limits;
376 const int guardValue = 10;
377
378 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
379 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
380
381 double maxRadius = coord_limits::max() / 2 - guardValue;
382 double radius = std::hypot( xDiff, yDiff );
383
384 if( radius > maxRadius )
385 {
386 double scaleFactor = maxRadius / radius;
387
388 xDiff = KiROUND<double, int>( xDiff * scaleFactor );
389 yDiff = KiROUND<double, int>( yDiff * scaleFactor );
390 }
391
392 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
393 }
394
400 bool m_inDrawingTool; // Re-entrancy guard
401
402 PCB_LAYER_ID m_layer; // The layer we last drew on
403 STROKE_PARAMS m_stroke; // Current stroke for multi-segment drawing
405
409
410 // Router handoff: pre-anchored first hop and span for the next stack placement.
411 bool m_viaStackSeeded = false;
415
416 static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press
417 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
418
419
420 friend class ZONE_CREATE_HELPER; // give internal access to helper classes
421};
422
423#endif /* __DRAWING_TOOL_H */
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
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:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
VECTOR2I m_viaStackSeedPos
TEXT_ATTRIBUTES m_textAttrs
MODE GetDrawingMode() const
Return the current drawing mode of the DRAWING_TOOL or MODE::NONE if not currently in any drawing mod...
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
KIGFX::VIEW_CONTROLS * m_controls
friend class ZONE_CREATE_HELPER
KIGFX::VIEW * m_view
STROKE_PARAMS m_stroke
SHAPE_DRAW_RESULT drawManagedShape(const TOOL_EVENT &aTool, std::unique_ptr< PCB_SHAPE > &aGraphic, SHAPE_DRAW_BEHAVIOR &aBehavior, const std::vector< VECTOR2D > &aInitialPts)
Run the interactive drawing event loop for a shape, driven by a SHAPE_DRAW_BEHAVIOR.
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.
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
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
This method is meant to be overridden in order to specify handlers for events.
int PlaceImportedGraphics(const TOOL_EVENT &aEvent)
Place a drawing imported from a DXF or SVG file.
int PlaceStackup(const TOOL_EVENT &aEvent)
VECTOR2I getClampedRadiusEnd(const VECTOR2I &aOrigin, const VECTOR2I &aEnd)
Clamps 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.
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)
std::vector< BOARD_ITEM * > DrawSpecificationStackup(const VECTOR2I &origin, PCB_LAYER_ID aLayer, bool aDrawNow, VECTOR2I *tablesize)
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 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 PlaceGridItem(const TOOL_EVENT &aEvent)
Place a grid item on the board.
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:63
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:54
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:33
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:683