KiCad PCB EDA Suite
pcb_shape.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) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef PCB_SHAPE_H
26#define PCB_SHAPE_H
27
28#include <board_item.h>
29#include <eda_shape.h>
30
31
32class LINE_READER;
33class EDA_DRAW_FRAME;
34class FOOTPRINT;
35class MSG_PANEL_ITEM;
36
37
38class PCB_SHAPE : public BOARD_ITEM, public EDA_SHAPE
39{
40public:
41 PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T aItemType, SHAPE_T aShapeType );
42
43 PCB_SHAPE( BOARD_ITEM* aParent = NULL, SHAPE_T aShapeType = SHAPE_T::SEGMENT );
44
45 // Do not create a copy constructor & operator=.
46 // The ones generated by the compiler are adequate.
47
48 ~PCB_SHAPE();
49
50 static inline bool ClassOf( const EDA_ITEM* aItem )
51 {
52 return aItem && PCB_SHAPE_T == aItem->Type();
53 }
54
55 wxString GetClass() const override
56 {
57 return wxT( "PCB_SHAPE" );
58 }
59
60 wxString GetFriendlyName() const override { return EDA_SHAPE::GetFriendlyName(); }
61
62 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override;
63
64 void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
65 VECTOR2I GetPosition() const override { return getPosition(); }
66
67 VECTOR2I GetCenter() const override { return getCenter(); }
68
69 bool HasLineStroke() const override { return true; }
70
71 STROKE_PARAMS GetStroke() const override { return m_stroke; }
72 void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
73
78 virtual std::vector<VECTOR2I> GetCorners() const;
79
84 const VECTOR2I GetFocusPosition() const override;
85
92
96 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
97 FLASHING aFlash = FLASHING::DEFAULT ) const override;
98
99 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
100
101 const BOX2I GetBoundingBox() const override { return getBoundingBox(); }
102
103 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
104 {
105 return hitTest( aPosition, aAccuracy );
106 }
107
108 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
109 {
110 return hitTest( aRect, aContained, aAccuracy );
111 }
112
113 void NormalizeRect();
114
115 virtual void Move( const VECTOR2I& aMoveVector ) override;
116
117 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
118
119 virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
120
121 virtual void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
122
123 void Scale( double aScale );
124
135 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
136 int aError, ERROR_LOC aErrorLoc,
137 bool ignoreLineWidth = false ) const override;
138
139 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
140
141 virtual BITMAPS GetMenuImage() const override;
142
143 virtual EDA_ITEM* Clone() const override;
144
145 virtual const BOX2I ViewBBox() const override;
146
148 double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
149
150#if defined(DEBUG)
151 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
152#endif
153
154protected:
155 virtual void swapData( BOARD_ITEM* aImage ) override;
156
158 {
159 bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
160 };
161
162 EDA_ANGLE getParentOrientation() const override;
163 VECTOR2I getParentPosition() const override;
164};
165
166#endif // PCB_SHAPE_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:70
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
wxString GetFriendlyName() const
Definition: eda_shape.cpp:611
VECTOR2I getCenter() const
Definition: eda_shape.cpp:444
bool hitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Definition: eda_shape.cpp:745
void setPosition(const VECTOR2I &aPos)
Definition: eda_shape.cpp:93
const BOX2I getBoundingBox() const
Definition: eda_shape.cpp:684
VECTOR2I getPosition() const
Definition: eda_shape.cpp:99
STROKE_PARAMS m_stroke
Definition: eda_shape.h:365
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_shape.h:101
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: pcb_shape.cpp:302
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_shape.cpp:350
EDA_ANGLE getParentOrientation() const override
Definition: pcb_shape.cpp:258
virtual void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_shape.cpp:197
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:67
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_shape.cpp:191
virtual BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_shape.cpp:321
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
Definition: pcb_shape.cpp:38
FOOTPRINT * GetParentFootprint() const
Return the parent footprint or NULL if PCB_SHAPE does not belong to a footprint.
Definition: pcb_shape.cpp:252
void NormalizeRect()
Definition: pcb_shape.cpp:175
bool HasLineStroke() const override
Check if this item has line stoke properties.
Definition: pcb_shape.h:69
virtual const BOX2I ViewBBox() const override
Definition: pcb_shape.cpp:333
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: pcb_shape.h:103
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Make a set of SHAPE objects representing the PCB_SHAPE.
Definition: pcb_shape.cpp:344
void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_shape.h:64
const VECTOR2I GetFocusPosition() const override
Allows items to return their visual center rather than their anchor.
Definition: pcb_shape.cpp:91
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: pcb_shape.cpp:315
virtual std::vector< VECTOR2I > GetCorners() const
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
Definition: pcb_shape.cpp:133
VECTOR2I getParentPosition() const override
Definition: pcb_shape.cpp:267
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_shape.h:50
wxString GetFriendlyName() const override
Definition: pcb_shape.h:60
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
Definition: pcb_shape.cpp:390
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:71
virtual void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_shape.cpp:163
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_shape.cpp:327
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_shape.cpp:276
virtual void Mirror(const VECTOR2I &aCentre, bool aMirrorAroundXAxis)
Definition: pcb_shape.cpp:205
void Scale(double aScale)
Definition: pcb_shape.cpp:169
bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects this item.
Definition: pcb_shape.h:108
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: pcb_shape.h:72
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: pcb_shape.cpp:57
wxString GetClass() const override
Return the class name.
Definition: pcb_shape.h:55
VECTOR2I GetPosition() const override
Definition: pcb_shape.h:65
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
SHAPE_T
Definition: eda_shape.h:41
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
Definition: pcb_shape.cpp:368
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88