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-2021 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 
32 class LINE_READER;
33 class EDA_DRAW_FRAME;
34 class FOOTPRINT;
35 class MSG_PANEL_ITEM;
36 
37 
38 class PCB_SHAPE : public BOARD_ITEM, public EDA_SHAPE
39 {
40 public:
41  PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T idtype, SHAPE_T shapetype );
42 
43  PCB_SHAPE( BOARD_ITEM* aParent = NULL, SHAPE_T shapetype = 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  bool IsType( const KICAD_T aScanTypes[] ) const override
61  {
62  if( BOARD_ITEM::IsType( aScanTypes ) )
63  return true;
64 
65  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
66  {
67  if( *p == PCB_LOCATE_GRAPHIC_T )
68  return true;
69  else if( *p == PCB_LOCATE_BOARD_EDGE_T )
70  return m_layer == Edge_Cuts;
71  }
72 
73  return false;
74  }
75 
76  void SetPosition( const wxPoint& aPos ) override { setPosition( aPos ); }
77  wxPoint GetPosition() const override { return getPosition(); }
78 
79  wxPoint GetCenter() const override { return getCenter(); }
80 
85  const wxPoint GetFocusPosition() const override;
86 
93 
97  std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override;
98 
99  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
100 
101  const EDA_RECT GetBoundingBox() const override { return getBoundingBox(); }
102 
103  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override
104  {
105  return hitTest( aPosition, aAccuracy );
106  }
107 
108  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
109  {
110  return hitTest( aRect, aContained, aAccuracy );
111  }
112 
113  virtual void Move( const wxPoint& aMoveVector ) override;
114 
115  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
116 
117  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
118 
119  void Scale( double aScale );
120 
134  PCB_LAYER_ID aLayer, int aClearanceValue,
135  int aError, ERROR_LOC aErrorLoc,
136  bool ignoreLineWidth = false ) const override;
137 
138  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
139 
140  virtual BITMAPS GetMenuImage() const override;
141 
142  virtual EDA_ITEM* Clone() const override;
143 
144  virtual const BOX2I ViewBBox() const override;
145 
146  virtual void SwapData( BOARD_ITEM* aImage ) override;
147 
149  {
150  bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
151  };
152 
153 #if defined(DEBUG)
154  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
155 #endif
156 
157 protected:
158  double getParentOrientation() const override;
159  wxPoint getParentPosition() const override;
160 };
161 
162 #endif // PCB_SHAPE_H
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
Definition: pcb_shape.cpp:206
wxPoint getCenter() const
Definition: eda_shape.cpp:389
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void Scale(double aScale)
Definition: pcb_shape.cpp:103
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_shape.cpp:175
bool hitTest(const wxPoint &aPosition, int aAccuracy=0) const
Definition: eda_shape.cpp:652
virtual BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_shape.cpp:169
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
Definition: pcb_shape.cpp:221
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_shape.cpp:181
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Make a set of SHAPE objects representing the PCB_SHAPE.
Definition: pcb_shape.cpp:200
The base class for create windows for drawing purpose.
virtual void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
Definition: pcb_shape.cpp:109
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T idtype, SHAPE_T shapetype)
Definition: pcb_shape.cpp:36
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
wxPoint getParentPosition() const override
Definition: pcb_shape.cpp:141
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: pcb_shape.h:103
virtual void Move(const wxPoint &aMoveVector) override
Move this object.
Definition: pcb_shape.cpp:97
Represent a set of closed polygons.
SHAPE_T
Definition: eda_shape.h:40
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:79
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:183
void SetPosition(const wxPoint &aPos) override
Definition: pcb_shape.h:76
bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects or is contained within the bounding box of an item.
Definition: pcb_shape.h:108
void setPosition(const wxPoint &aPos)
Definition: eda_shape.cpp:85
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: pcb_shape.cpp:163
EDA_UNITS
Definition: eda_units.h:38
wxPoint GetPosition() const override
Definition: pcb_shape.h:77
const EDA_RECT getBoundingBox() const
Definition: eda_shape.cpp:591
bool IsType(const KICAD_T aScanTypes[]) const override
Check whether the item is one of the listed types.
Definition: pcb_shape.h:60
wxString GetClass() const override
Return the class name.
Definition: pcb_shape.h:55
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
FOOTPRINT * GetParentFootprint() const
Return the parent footprint or NULL if PCB_SHAPE does not belong to a footprint.
Definition: pcb_shape.cpp:123
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_shape.h:101
Handle the component boundary box.
Definition: eda_rect.h:42
const wxPoint GetFocusPosition() const override
Allows items to return their visual center rather than their anchor.
Definition: pcb_shape.cpp:55
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
PCB_LAYER_ID m_layer
Definition: board_item.h:316
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_shape.h:50
wxPoint getPosition() const
Definition: eda_shape.cpp:91
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_shape.cpp:115
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
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:150
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
double getParentOrientation() const override
Definition: pcb_shape.cpp:132