KiCad PCB EDA Suite
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-2020 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 <wx/debug.h>
27 #include <i18n_utility.h>
28 #include <board.h>
29 #include <string>
30 
32 {
33  switch( aShape )
34  {
35  case PCB_SHAPE_TYPE::SEGMENT: return _( "Line" );
36  case PCB_SHAPE_TYPE::RECT: return _( "Rect" );
37  case PCB_SHAPE_TYPE::ARC: return _( "Arc" );
38  case PCB_SHAPE_TYPE::CIRCLE: return _( "Circle" );
39  case PCB_SHAPE_TYPE::CURVE: return _( "Bezier Curve" );
40  case PCB_SHAPE_TYPE::POLYGON: return _( "Polygon" );
41  default: return wxT( "??" );
42  }
43 }
44 
45 
47 {
48  if( Type() == PCB_T )
49  return (BOARD*) this;
50 
51  BOARD_ITEM* parent = GetParent();
52 
53  if( parent )
54  return parent->GetBoard();
55 
56  return NULL;
57 }
58 
59 
60 wxString BOARD_ITEM::GetLayerName() const
61 {
62  BOARD* board = GetBoard();
63 
64  if( board )
65  return board->GetLayerName( m_layer );
66 
67  // If no parent, return standard name
69 }
70 
71 
73 {
74  BOARD* board = GetBoard();
75  LSET layers = GetLayerSet();
76 
77  // Try to be smart and useful. Check all copper first.
78  if( layers[F_Cu] && layers[B_Cu] )
79  return _( "all copper layers" );
80 
81  LSET copperLayers = layers & board->GetEnabledLayers().AllCuMask();
82  LSET techLayers = layers & board->GetEnabledLayers().AllTechMask();
83 
84  for( LSET testLayers : { copperLayers, techLayers, layers } )
85  {
86  for( int bit = PCBNEW_LAYER_ID_START; bit < PCB_LAYER_ID_COUNT; ++bit )
87  {
88  if( testLayers[ bit ] )
89  {
90  wxString layerInfo = board->GetLayerName( static_cast<PCB_LAYER_ID>( bit ) );
91 
92  if( testLayers.count() > 1 )
93  layerInfo << wxS( " " ) + _( "and others" );
94 
95  return layerInfo;
96  }
97  }
98  }
99 
100  // No copper, no technicals: no layer
101  return _( "no layers" );
102 }
103 
104 
105 void BOARD_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
106 {
107  // Basic fallback
108  aCount = 1;
109  aLayers[0] = m_layer;
110 }
111 
112 
114 {
115  BOARD_ITEM_CONTAINER* parent = GetParent();
116 
117  if( parent )
118  parent->Remove( this );
119 
120  delete this;
121 }
122 
123 
125 {
126 }
127 
128 
130  PCB_LAYER_ID aLayer, int aClearanceValue,
131  int aError, ERROR_LOC aErrorLoc,
132  bool ignoreLineWidth ) const
133 {
134  wxASSERT_MSG( false, "Called TransformShapeWithClearanceToPolygon() on unsupported BOARD_ITEM." );
135 };
136 
137 
139 {
140  if( a->Type() != b->Type() )
141  return a->Type() < b->Type();
142 
143  if( a->GetLayer() != b->GetLayer() )
144  return a->GetLayer() < b->GetLayer();
145 
146  if( a->m_Uuid != b->m_Uuid ) // shopuld be always the case foer valid boards
147  return a->m_Uuid < b->m_Uuid;
148 
149  return a < b;
150 }
151 
152 
153 std::shared_ptr<SHAPE> BOARD_ITEM::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
154 {
155  std::shared_ptr<SHAPE> shape;
156 
157  wxFAIL_MSG( "GetEffectiveShape() not implemented for " + GetClass() );
158 
159  return shape;
160 }
161 
162 
163 static struct BOARD_ITEM_DESC
164 {
166  {
168 
169  if( layerEnum.Choices().GetCount() == 0 )
170  {
171  layerEnum.Undefined( UNDEFINED_LAYER );
172 
173  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
174  layerEnum.Map( *seq, LSET::Name( *seq ) );
175  }
176 
180 
181  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _HKI( "Position X" ),
183  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _HKI( "Position Y" ),
187  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, bool>( _HKI( "Locked" ),
189  }
191 
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define TYPE_HASH(x)
Definition: property.h:59
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition: property.h:610
Definition: typeinfo.h:84
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:342
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
ENUM_MAP & Undefined(T aValue)
Definition: property.h:523
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: board_item.cpp:105
static ENUM_MAP< T > & Instance()
Definition: property.h:510
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:113
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
Definition: board.cpp:447
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:257
PCB_SHAPE_TYPE
The set of shapes for PCB graphics and tracks and footprint graphics in the .m_Shape member.
Definition: board_item.h:48
wxPGChoices & Choices()
Definition: property.h:559
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:820
static struct BOARD_ITEM_DESC _BOARD_ITEM_DESC
#define REGISTER_TYPE(x)
Definition: property_mgr.h:248
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
polygon (not yet used for tracks, but could be in microwave apps)
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:124
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:72
PCB_LAYER_ID
A quick note on layer IDs:
Display value expressed in distance units (mm/inch)
Definition: property.h:53
LSET is a set of PCB_LAYER_IDs.
int GetY() const
Definition: board_item.h:103
#define NULL
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
Represent a set of closed polygons.
segment with non rounded ends
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void SetY(int aY)
Definition: board_item.h:125
static LSET AllLayersMask()
Definition: lset.cpp:787
void SetX(int aX)
Definition: board_item.h:119
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
const KIID m_Uuid
Definition: eda_item.h:525
Some functions to handle hotkeys in KiCad.
virtual bool IsLocked() const
Definition: board_item.h:249
virtual wxString GetClass() const =0
Return the class name.
int GetX() const
Definition: board_item.h:97
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:138
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
usual segment : line with rounded ends
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
PCB_LAYER_ID m_layer
Definition: board_item.h:363
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:153
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:62
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
Definition: board_item.cpp:129
virtual void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL)=0
Removes an item from the container.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:516
static wxString ShowShape(PCB_SHAPE_TYPE aShape)
Convert the enum #PCB_SHAPE_TYPE_T integer value to a wxString.
Definition: board_item.cpp:31
Arcs (with rounded ends)
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:60
#define _HKI(x)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:178
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition: board.h:676