KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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#pragma once
26
28#include <eda_shape.h>
29
30
31class LINE_READER;
32class EDA_DRAW_FRAME;
33class FOOTPRINT;
34class MSG_PANEL_ITEM;
35
36
38{
39public:
40 PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T aItemType, SHAPE_T aShapeType );
41
42 PCB_SHAPE( BOARD_ITEM* aParent = nullptr, SHAPE_T aShapeType = SHAPE_T::SEGMENT );
43
44 // Do not create a copy constructor & operator=.
45 // The ones generated by the compiler are adequate.
46
47 ~PCB_SHAPE() override;
48
49 void CopyFrom( const BOARD_ITEM* aOther ) override;
50
51 static bool ClassOf( const EDA_ITEM* aItem )
52 {
53 return aItem && PCB_SHAPE_T == aItem->Type();
54 }
55
56 wxString GetClass() const override
57 {
58 return wxT( "PCB_SHAPE" );
59 }
60
61 void Serialize( google::protobuf::Any &aContainer ) const override;
62 bool Deserialize( const google::protobuf::Any &aContainer ) override;
63
64 bool IsConnected() const override;
65
66 wxString GetFriendlyName() const override { return getFriendlyName(); }
67
68 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override;
69
70 void SetLayer( PCB_LAYER_ID aLayer ) override;
71 PCB_LAYER_ID GetLayer() const override { return m_layer; }
72
73 bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
74
75 virtual LSET GetLayerSet() const override;
76 virtual void SetLayerSet( const LSET& aLayers ) override;
77
78 void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
79 VECTOR2I GetPosition() const override { return getPosition(); }
80
81 VECTOR2I GetCenter() const override { return getCenter(); }
82
87 std::vector<VECTOR2I> GetConnectionPoints() const;
88
89 bool HasLineStroke() const override { return true; }
90
91 STROKE_PARAMS GetStroke() const override { return m_stroke; }
92 void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
93
94 int GetWidth() const override;
95
96 void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) override;
97
102 virtual std::vector<VECTOR2I> GetCorners() const;
103
108 const VECTOR2I GetFocusPosition() const override;
109
113 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
114 FLASHING aFlash = FLASHING::DEFAULT ) const override;
115
116 bool IsProxyItem() const override { return m_proxyItem; }
117 void SetIsProxyItem( bool aIsProxy = true ) override;
118
119 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
120
121 const BOX2I GetBoundingBox() const override { return getBoundingBox(); }
122
123 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
124 {
125 return hitTest( aPosition, aAccuracy );
126 }
127
128 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
129 {
130 return hitTest( aRect, aContained, aAccuracy );
131 }
132
133 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override
134 {
135 return hitTest( aPoly, aContained );
136 }
137
138 void Normalize() override;
139
145 void NormalizeForCompare() override;
146
147 void Move( const VECTOR2I& aMoveVector ) override;
148
149 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
150
151 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
152
153 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
154
155 void Scale( double aScale );
156
157 void UpdateHatching() const override;
158
169 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
170 int aError, ERROR_LOC aErrorLoc,
171 bool ignoreLineWidth = false ) const override;
172
173 void TransformShapeToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
174 int aError, ERROR_LOC aErrorLoc ) const override;
175
176 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
177
178 BITMAPS GetMenuImage() const override;
179
180 EDA_ITEM* Clone() const override;
181
182 const BOX2I ViewBBox() const override;
183
184 std::vector<int> ViewGetLayers() const override;
185
187 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
188
189 double Similarity( const BOARD_ITEM& aBoardItem ) const override;
190
191 bool operator==( const PCB_SHAPE& aShape ) const;
192 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
193
194 void SetHasSolderMask( bool aVal ) { m_hasSolderMask = aVal; }
195 bool HasSolderMask() const { return m_hasSolderMask; }
196
197 void SetLocalSolderMaskMargin( std::optional<int> aMargin ) { m_solderMaskMargin = aMargin; }
198 std::optional<int> GetLocalSolderMaskMargin() const { return m_solderMaskMargin; }
199
200 int GetSolderMaskExpansion() const;
201
202#if defined(DEBUG)
203 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
204#endif
205
206protected:
207 void swapData( BOARD_ITEM* aImage ) override;
208
209 bool isMoving() const override { return IsMoving(); }
210
211 int getMaxError() const override;
212
214 {
215 bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
216 };
217
218protected:
220 std::optional<int> m_solderMaskMargin;
221};
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
BOARD_CONNECTED_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
Container for design settings for a BOARD object.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:81
PCB_LAYER_ID m_layer
Definition board_item.h:453
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:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
bool IsMoving() const
Definition eda_item.h:125
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
bool m_proxyItem
Definition eda_shape.h:520
VECTOR2I getCenter() const
bool hitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill)
Definition eda_shape.cpp:51
void setPosition(const VECTOR2I &aPos)
const BOX2I getBoundingBox() const
VECTOR2I getPosition() const
STROKE_PARAMS m_stroke
Definition eda_shape.h:493
wxString getFriendlyName() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:66
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:93
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
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:121
virtual void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
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.
void swapData(BOARD_ITEM *aImage) override
bool IsConnected() const override
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
bool HitTest(const SHAPE_LINE_CHAIN &aPoly, bool aContained) const override
Test if aPoly intersects this item.
Definition pcb_shape.h:133
std::optional< int > GetLocalSolderMaskMargin() const
Definition pcb_shape.h:198
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:81
bool isMoving() const override
Definition pcb_shape.h:209
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
Definition pcb_shape.cpp:51
bool HasLineStroke() const override
Check if this item has line stoke properties.
Definition pcb_shape.h:89
int GetWidth() const override
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
bool HasSolderMask() const
Definition pcb_shape.h:195
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:123
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.
void SetHasSolderMask(bool aVal)
Definition pcb_shape.h:194
std::optional< int > m_solderMaskMargin
Definition pcb_shape.h:220
int GetSolderMaskExpansion() const
void NormalizeForCompare() override
Normalize coordinates to compare 2 similar PCB_SHAPES similat to Normalize(), but also normalize SEGM...
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_shape.h:78
const VECTOR2I GetFocusPosition() const override
Allows items to return their visual center rather than their anchor.
virtual void SetLayerSet(const LSET &aLayers) override
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
virtual std::vector< VECTOR2I > GetCorners() const
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
bool IsProxyItem() const override
Definition pcb_shape.h:116
bool m_hasSolderMask
Definition pcb_shape.h:219
~PCB_SHAPE() override
Definition pcb_shape.cpp:67
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_shape.h:51
bool operator==(const PCB_SHAPE &aShape) const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
wxString GetFriendlyName() const override
Definition pcb_shape.h:66
void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc) const override
Convert the item shape to a polyset.
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.
STROKE_PARAMS GetStroke() const override
Definition pcb_shape.h:91
void SetIsProxyItem(bool aIsProxy=true) override
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings) override
void SetLocalSolderMaskMargin(std::optional< int > aMargin)
Definition pcb_shape.h:197
void Move(const VECTOR2I &aMoveVector) override
Move this object.
std::vector< VECTOR2I > GetConnectionPoints() const
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
int getMaxError() const override
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
void UpdateHatching() const override
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void Scale(double aScale)
bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects this item.
Definition pcb_shape.h:128
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition pcb_shape.cpp:79
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition pcb_shape.h:92
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
void CopyFrom(const BOARD_ITEM *aOther) override
Definition pcb_shape.cpp:72
std::vector< int > ViewGetLayers() const override
wxString GetClass() const override
Return the class name.
Definition pcb_shape.h:56
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
VECTOR2I GetPosition() const override
Definition pcb_shape.h:79
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:71
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
SHAPE_T
Definition eda_shape.h:43
@ SEGMENT
Definition eda_shape.h:45
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:184
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:185
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
FLIP_DIRECTION
Definition mirror.h:27
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695