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, 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 <functional>
31#include <stack>
32#include <optional>
33#include <tool/tool_menu.h>
34#include <tools/pcb_selection.h>
35#include <tools/pcb_tool_base.h>
36#include <tools/pcb_actions.h>
37
38namespace KIGFX
39{
40 class VIEW;
41 class VIEW_CONTROLS;
42}
43
44class BOARD;
46class PCB_SHAPE;
49class STATUS_MIN_MAX_POPUP;
50
51
55
57{
58public:
61
63 bool Init() override;
64
66 void Reset( RESET_REASON aReason ) override;
67
93
98 MODE GetDrawingMode() const;
99
102 std::vector<BOARD_ITEM*> DrawSpecificationStackup( const VECTOR2I& origin, PCB_LAYER_ID aLayer,
103 bool aDrawNow, VECTOR2I* tablesize );
104
107 int PlaceStackup( const TOOL_EVENT& aEvent );
108
111 int PlaceTuningPattern( const TOOL_EVENT& aEvent );
112
120 int DrawLine( const TOOL_EVENT& aEvent );
121
128 int DrawRectangle( const TOOL_EVENT& aEvent );
129
136 int DrawCircle( const TOOL_EVENT& aEvent );
137
138 int DrawEllipse( const TOOL_EVENT& aEvent );
139
140 int DrawEllipseArc( const TOOL_EVENT& aEvent );
141
149 int DrawArc( const TOOL_EVENT& aEvent );
150
156 int DrawBezier( const TOOL_EVENT& aEvent );
157
162 int PlaceReferenceImage( const TOOL_EVENT& aEvent );
163
167 int PlacePoint( const TOOL_EVENT& aEvent );
168
173 int PlaceText( const TOOL_EVENT& aEvent );
174
175 /*
176 * Start interactively drawing a table (rows & columns of TEXTBOXes).
177 */
178 int DrawTable( const TOOL_EVENT& aEvent );
179
185 int DrawBarcode( const TOOL_EVENT& aEvent );
186
194 int DrawDimension( const TOOL_EVENT& aEvent );
195
209 int DrawZone( const TOOL_EVENT& aEvent );
210
211 int DrawVia( const TOOL_EVENT& aEvent );
212
216 int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
217
231 std::vector<BOARD_ITEM*>& aItems,
232 std::vector<BOARD_ITEM*>& aPreview, LSET* aLayers );
233
234
238 int SetAnchor( const TOOL_EVENT& aEvent );
239
240
242 void setTransitions() override;
243
244 void SetStroke( const STROKE_PARAMS& aStroke, PCB_LAYER_ID aLayer )
245 {
246 m_layer = aLayer;
247 m_stroke = aStroke;
248 }
249
250 void UpdateStatusBar() const;
251
252private:
254 {
255 // The drawing was accepted "normally"
256 // E.g. for a poly-line, you might then begin a chained next segment
258 // The drawing was cancelled with no shape accepted.
260 // The drawing was reset - no shape was accepted this time,
261 // but the tool remains active.
263 // A shape was accepted, but the tool should reset for the
264 // next one (e.g. no chaining)
266 };
267
279 bool drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
280 std::optional<VECTOR2D> aStartingPoint,
281 std::stack<PCB_SHAPE*>* aCommittedGraphics );
282
283 int runSimpleShapeDraw( const TOOL_EVENT& aEvent, SHAPE_T aShapeType, MODE aMode, const wxString& aCommitLabel,
284 std::function<bool( const TOOL_EVENT&, PCB_SHAPE**, std::optional<VECTOR2D> )> aDrawer );
285
294 bool drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
295 std::optional<VECTOR2D> aStartingPoint );
296
297
311 std::unique_ptr<PCB_SHAPE> drawOneBezier( const TOOL_EVENT& aTool,
312 const OPT_VECTOR2I& aStartingPoint,
313 const OPT_VECTOR2I& aStartingControl1Point,
314 DRAW_ONE_RESULT& aResult );
315
316
326
339 bool getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone );
340
347
355 VECTOR2I getClampedDifferenceEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
356 {
357 typedef std::numeric_limits<int> coord_limits;
358 const int guardValue = 1;
359
360 VECTOR2I::extended_type maxDiff = coord_limits::max() - guardValue;
361
362 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
363 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
364
365 if( xDiff > maxDiff )
366 xDiff = maxDiff;
367 if( yDiff > maxDiff )
368 yDiff = maxDiff;
369
370 if( xDiff < -maxDiff )
371 xDiff = -maxDiff;
372 if( yDiff < -maxDiff )
373 yDiff = -maxDiff;
374
375 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
376 }
377
385 VECTOR2I getClampedRadiusEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
386 {
387 typedef std::numeric_limits<int> coord_limits;
388 const int guardValue = 10;
389
390 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
391 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
392
393 double maxRadius = coord_limits::max() / 2 - guardValue;
394 double radius = std::hypot( xDiff, yDiff );
395
396 if( radius > maxRadius )
397 {
398 double scaleFactor = maxRadius / radius;
399
400 xDiff = KiROUND<double, int>( xDiff * scaleFactor );
401 yDiff = KiROUND<double, int>( yDiff * scaleFactor );
402 }
403
404 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
405 }
406
412 bool m_inDrawingTool; // Re-entrancy guard
413
414 PCB_LAYER_ID m_layer; // The layer we last drew on
415 STROKE_PARAMS m_stroke; // Current stroke for multi-segment drawing
417
421
422 static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press
423 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
424
425
426 friend class ZONE_CREATE_HELPER; // give internal access to helper classes
427};
428
429#endif /* __DRAWING_TOOL_H */
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
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...
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.
int DrawVia(const TOOL_EVENT &aEvent)
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.
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
bool drawArc(const TOOL_EVENT &aTool, PCB_SHAPE **aGraphic, std::optional< VECTOR2D > aStartingPoint)
Start drawing an arc.
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 DrawBarcode(const TOOL_EVENT &aEvent)
Starts interactively drawing a barcode.
int DrawEllipse(const TOOL_EVENT &aEvent)
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)
Draw a polygon, that is added as a zone or a keepout area.
std::unique_ptr< PCB_SHAPE > drawOneBezier(const TOOL_EVENT &aTool, const OPT_VECTOR2I &aStartingPoint, const OPT_VECTOR2I &aStartingControl1Point, DRAW_ONE_RESULT &aResult)
Draw a bezier curve.
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:67
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
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...
Simple container to manage line stroke parameters.
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:78
Generic, UI-independent tool event.
Definition tool_event.h:171
VECTOR2_TRAITS< int32_t >::extended_type extended_type
Definition vector2d.h:73
Handle a list of polygons defining a copper zone.
Definition zone.h:74
SHAPE_T
Definition eda_shape.h:48
void Reset() override
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
ZONE_MODE
Definition pcb_actions.h:35
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:39
int radius
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687