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 <stack>
31#include <optional>
32#include <tool/tool_menu.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;
44class PCB_SHAPE;
47class STATUS_MIN_MAX_POPUP;
48
49
53
55{
56public:
59
61 bool Init() override;
62
64 void Reset( RESET_REASON aReason ) override;
65
67 enum class MODE
68 {
78 MD_POINT, // Do not use POINT: it collide with a Windows header define
86 };
87
92 MODE GetDrawingMode() const;
93
96 std::vector<BOARD_ITEM*> DrawSpecificationStackup( const VECTOR2I& origin, PCB_LAYER_ID aLayer,
97 bool aDrawNow, VECTOR2I* tablesize );
98
101 int PlaceStackup( const TOOL_EVENT& aEvent );
102
105 int PlaceTuningPattern( const TOOL_EVENT& aEvent );
106
114 int DrawLine( const TOOL_EVENT& aEvent );
115
122 int DrawRectangle( const TOOL_EVENT& aEvent );
123
130 int DrawCircle( const TOOL_EVENT& aEvent );
131
139 int DrawArc( const TOOL_EVENT& aEvent );
140
146 int DrawBezier( const TOOL_EVENT& aEvent );
147
152 int PlaceReferenceImage( const TOOL_EVENT& aEvent );
153
157 int PlacePoint( const TOOL_EVENT& aEvent );
158
163 int PlaceText( const TOOL_EVENT& aEvent );
164
165 /*
166 * Start interactively drawing a table (rows & columns of TEXTBOXes).
167 */
168 int DrawTable( const TOOL_EVENT& aEvent );
169
177 int DrawDimension( const TOOL_EVENT& aEvent );
178
192 int DrawZone( const TOOL_EVENT& aEvent );
193
194 int DrawVia( const TOOL_EVENT& aEvent );
195
199 int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
200
214 std::vector<BOARD_ITEM*>& aItems,
215 std::vector<BOARD_ITEM*>& aPreview, LSET* aLayers );
216
217
221 int SetAnchor( const TOOL_EVENT& aEvent );
222
226 int ToggleHV45Mode( const TOOL_EVENT& toolEvent );
227
229 void setTransitions() override;
230
231 void SetStroke( const STROKE_PARAMS& aStroke, PCB_LAYER_ID aLayer )
232 {
233 m_layer = aLayer;
234 m_stroke = aStroke;
235 }
236
237 void UpdateStatusBar() const;
238
239private:
241 {
242 // The drawing was accepted "normally"
243 // E.g. for a poly-line, you might then begin a chained next segment
245 // The drawing was cancelled with no shape accepted.
247 // The drawing was reset - no shape was accepted this time,
248 // but the tool remains active.
250 // A shape was accepted, but the tool should reset for the
251 // next one (e.g. no chaining)
253 };
254
266 bool drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
267 std::optional<VECTOR2D> aStartingPoint,
268 std::stack<PCB_SHAPE*>* aCommittedGraphics );
269
278 bool drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
279 std::optional<VECTOR2D> aStartingPoint );
280
294 std::unique_ptr<PCB_SHAPE> drawOneBezier( const TOOL_EVENT& aTool,
295 const OPT_VECTOR2I& aStartingPoint,
296 const OPT_VECTOR2I& aStartingControl1Point,
297 DRAW_ONE_RESULT& aResult );
298
299
309
322 bool getSourceZoneForAction( ZONE_MODE aMode, ZONE** aZone );
323
330
338 VECTOR2I getClampedDifferenceEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
339 {
340 typedef std::numeric_limits<int> coord_limits;
341 const int guardValue = 1;
342
343 VECTOR2I::extended_type maxDiff = coord_limits::max() - guardValue;
344
345 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
346 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
347
348 if( xDiff > maxDiff )
349 xDiff = maxDiff;
350 if( yDiff > maxDiff )
351 yDiff = maxDiff;
352
353 if( xDiff < -maxDiff )
354 xDiff = -maxDiff;
355 if( yDiff < -maxDiff )
356 yDiff = -maxDiff;
357
358 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
359 }
360
368 VECTOR2I getClampedRadiusEnd( const VECTOR2I& aOrigin, const VECTOR2I& aEnd )
369 {
370 typedef std::numeric_limits<int> coord_limits;
371 const int guardValue = 10;
372
373 VECTOR2I::extended_type xDiff = VECTOR2I::extended_type( aEnd.x ) - aOrigin.x;
374 VECTOR2I::extended_type yDiff = VECTOR2I::extended_type( aEnd.y ) - aOrigin.y;
375
376 double maxRadius = coord_limits::max() / 2 - guardValue;
377 double radius = std::hypot( xDiff, yDiff );
378
379 if( radius > maxRadius )
380 {
381 double scaleFactor = maxRadius / radius;
382
383 xDiff = KiROUND<double, int>( xDiff * scaleFactor );
384 yDiff = KiROUND<double, int>( yDiff * scaleFactor );
385 }
386
387 return aOrigin + VECTOR2I( int( xDiff ), int( yDiff ) );
388 }
389
395 bool m_inDrawingTool; // Re-entrancy guard
396
397 PCB_LAYER_ID m_layer; // The layer we last drew on
398 STROKE_PARAMS m_stroke; // Current stroke for multi-segment drawing
400
404
405 static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press
406 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
407
408
409 friend class ZONE_CREATE_HELPER; // give internal access to helper classes
410};
411
412#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:317
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
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
int ToggleHV45Mode(const TOOL_EVENT &toolEvent)
Toggle the horizontal/vertical/45-degree constraint for drawing tools.
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
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 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:66
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
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:695