KiCad PCB EDA Suite
class_board_item.cpp
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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <fctsys.h>
27 #include <pcbnew.h>
28 #include <wx/debug.h>
29 
30 #include <class_board.h>
31 #include <string>
32 
33 wxString BOARD_ITEM::ShowShape( STROKE_T aShape )
34 {
35  switch( aShape )
36  {
37  case S_SEGMENT: return _( "Line" );
38  case S_RECT: return _( "Rect" );
39  case S_ARC: return _( "Arc" );
40  case S_CIRCLE: return _( "Circle" );
41  case S_CURVE: return _( "Bezier Curve" );
42  case S_POLYGON: return _( "Polygon" );
43  default: return wxT( "??" );
44  }
45 }
46 
47 
49 {
50  if( Type() == PCB_T )
51  return (BOARD*) this;
52 
53  BOARD_ITEM* parent = GetParent();
54 
55  if( parent )
56  return parent->GetBoard();
57 
58  return NULL;
59 }
60 
61 
63 {
64  if( IsInGroup() && GetBoard() )
65  return dynamic_cast<PCB_GROUP*>( GetBoard()->GetItem( m_groupUuid ) );
66 
67  return nullptr;
68 }
69 
70 
72 {
73  m_groupUuid = aGroup ? aGroup->m_Uuid : niluuid;
74 }
75 
76 
77 wxString BOARD_ITEM::GetLayerName() const
78 {
79  BOARD* board = GetBoard();
80 
81  if( board )
82  return board->GetLayerName( m_Layer );
83 
84  // If no parent, return standard name
86 }
87 
88 
90 {
91  BOARD* board = GetBoard();
92  LSET layers = GetLayerSet();
93 
94  // Try to be smart and useful. Check all copper first.
95  if( layers[F_Cu] && layers[B_Cu] )
96  return _( "all copper layers" );
97 
98  LSET copperLayers = layers & board->GetEnabledLayers().AllCuMask();
99  LSET techLayers = layers & board->GetEnabledLayers().AllTechMask();
100 
101  for( LSET testLayers : { copperLayers, techLayers, layers } )
102  {
103  for( int bit = PCBNEW_LAYER_ID_START; bit < PCB_LAYER_ID_COUNT; ++bit )
104  {
105  if( testLayers[ bit ] )
106  {
107  wxString layerInfo = board->GetLayerName( static_cast<PCB_LAYER_ID>( bit ) );
108 
109  if( testLayers.count() > 1 )
110  layerInfo << _( " and others" );
111 
112  return layerInfo;
113  }
114  }
115  }
116 
117  // No copper, no technicals: no layer
118  return _( "no layers" );
119 }
120 
121 
122 void BOARD_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
123 {
124  // Basic fallback
125  aCount = 1;
126  aLayers[0] = m_Layer;
127 }
128 
129 
131 {
132  auto parent = GetParent();
133 
134  if( parent )
135  parent->Remove( this );
136 
137  delete this;
138 }
139 
140 
142 {
143 }
144 
145 
147  PCB_LAYER_ID aLayer,
148  int aClearanceValue, int aError,
149  bool ignoreLineWidth ) const
150 {
151  wxASSERT_MSG( false, "Called TransformShapeWithClearanceToPolygon() on unsupported BOARD_ITEM." );
152 };
153 
154 
156 {
157  if( a->Type() != b->Type() )
158  return a->Type() < b->Type();
159 
160  if( a->GetLayer() != b->GetLayer() )
161  return a->GetLayer() < b->GetLayer();
162 
163  return a->m_Uuid < b->m_Uuid;
164 }
165 
166 
167 std::shared_ptr<SHAPE> BOARD_ITEM::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
168 {
169  std::shared_ptr<SHAPE> shape;
170 
171  int unimplemented_get_effective_shape = 0;
172  assert( unimplemented_get_effective_shape );
173  (void) unimplemented_get_effective_shape;
174 
175  return shape;
176 }
177 
178 
179 static struct BOARD_ITEM_DESC
180 {
182  {
184 
185  if( layerEnum.Choices().GetCount() == 0 )
186  {
187  layerEnum.Undefined( UNDEFINED_LAYER );
188 
189  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
190  layerEnum.Map( *seq, LSET::Name( *seq ) );
191  }
192 
196 
197  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _( "Position X" ),
199  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _( "Position Y" ),
201  propMgr.AddProperty( new PROPERTY_ENUM<BOARD_ITEM, PCB_LAYER_ID>( _( "Layer" ),
203  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, bool>( _( "Locked" ),
205  }
207 
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:749
static wxString ShowShape(STROKE_T aShape)
Function ShowShape converts the enum STROKE_T integer value to a wxString.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:61
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition: property.h:604
Definition: typeinfo.h:85
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
ENUM_MAP & Undefined(T aValue)
Definition: property.h:531
polygon (not yet used for tracks, but could be in microwave apps)
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
static ENUM_MAP< T > & Instance()
Definition: property.h:517
void DeleteStructure()
Function DeleteStructure deletes this object after removing from its parent if it has one.
virtual wxString LayerMaskDescribe() const
Helper function Return a string (to be shown to the user) describing a layer mask.
usual segment : line with rounded ends
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
wxPGChoices & Choices()
Definition: property.h:557
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:819
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names
Definition: property_mgr.h:244
PCB_LAYER_ID m_Layer
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
segment with non rounded ends
PCB_LAYER_ID
A quick note on layer IDs:
Display value expressed in distance units (mm/inch)
Definition: property.h:47
LSET is a set of PCB_LAYER_IDs.
int GetY() const
#define NULL
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:81
SHAPE_POLY_SET.
Arcs (with rounded ends)
KIID niluuid(0)
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declares an inheritance relationship between types.
void SetY(int aY)
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
static LSET AllLayersMask()
Definition: lset.cpp:786
Bezier Curve.
void SetX(int aX)
PCB_GROUP * GetGroup() const
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
const KIID m_Uuid
Definition: base_struct.h:162
virtual bool IsLocked() const
Function IsLocked.
static struct BOARD_ITEM_DESC _BOARD_ITEM_DESC
int GetX() const
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:176
#define _(s)
Definition: 3d_actions.cpp:33
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
void AddProperty(PROPERTY_BASE *aProperty)
Registers a property.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Function GetEffectiveShape Some pad shapes can be complex (rounded/chamfered rectangle),...
Provides class metadata.
Definition: property_mgr.h:58
void SetGroup(PCB_GROUP *aGroup)
bool IsInGroup() const
Test if this item is inside a group.
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:523
BOARD_ITEM_CONTAINER * GetParent() const
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError=ARC_LOW_DEF, bool ignoreLineWidth=false) const
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
virtual LSET GetLayerSet() const
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition: class_board.h:603