KiCad PCB EDA Suite
class_board_item.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
10  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
11  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, you may find one here:
25  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
26  * or you may search the http://www.gnu.org website for the version 2 license,
27  * or you may write to the Free Software Foundation, Inc.,
28  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29  */
30 
31 #include <fctsys.h>
32 #include <common.h>
33 #include <pcbnew.h>
34 #include <wx/debug.h>
35 
36 #include <class_board.h>
37 #include <string>
38 
39 wxString BOARD_ITEM::ShowShape( STROKE_T aShape )
40 {
41  switch( aShape )
42  {
43  case S_SEGMENT: return _( "Line" );
44  case S_RECT: return _( "Rect" );
45  case S_ARC: return _( "Arc" );
46  case S_CIRCLE: return _( "Circle" );
47  case S_CURVE: return _( "Bezier Curve" );
48  case S_POLYGON: return _( "Polygon" );
49  default: return wxT( "??" );
50  }
51 }
52 
53 
55 {
56  if( Type() == PCB_T )
57  return (BOARD*) this;
58 
59  BOARD_ITEM* parent = GetParent();
60 
61  if( parent )
62  return parent->GetBoard();
63 
64  return NULL;
65 }
66 
67 
68 wxString BOARD_ITEM::GetLayerName() const
69 {
70  BOARD* board = GetBoard();
71 
72  if( board )
73  return board->GetLayerName( m_Layer );
74 
75  // If no parent, return standard name
77 }
78 
79 
80 wxString BOARD_ITEM::LayerMaskDescribe( const BOARD* aBoard, LSET aMask )
81 {
82  // Try to be smart and useful. Check all copper first.
83  if( aMask[F_Cu] && aMask[B_Cu] )
84  return _( "All copper layers" );
85 
86  // Check for copper.
87  auto layer = aBoard->GetEnabledLayers().AllCuMask() & aMask;
88 
89  for( int i = 0; i < 3; i++ )
90  {
91  for( int bit = PCBNEW_LAYER_ID_START; bit < PCB_LAYER_ID_COUNT; ++bit )
92  {
93  if( layer[ bit ] )
94  {
95  wxString layerInfo = aBoard->GetLayerName( static_cast<PCB_LAYER_ID>( bit ) );
96 
97  if( aMask.count() > 1 )
98  layerInfo << _( " and others" );
99 
100  return layerInfo;
101  }
102  }
103 
104  // No copper; first, check for technicals and then for all layers.
105  if( i < 1 ) // first, check for technicals
106  layer = aBoard->GetEnabledLayers().AllTechMask() & aMask;
107  else // then check for all other layers
108  layer = aMask;
109  }
110 
111  // No copper, no technicals: no layer
112  return _( "no layers" );
113 }
114 
115 
116 void BOARD_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
117 {
118  // Basic fallback
119  aCount = 1;
120  aLayers[0] = m_Layer;
121 }
122 
123 
125 {
126  auto parent = GetParent();
127 
128  if( parent )
129  parent->Remove( this );
130 
131  delete this;
132 }
133 
134 
136 {
137 }
138 
139 
141  SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError, bool ignoreLineWidth ) const
142 {
143  wxASSERT_MSG( false, "Called TransformShapeWithClearanceToPolygon() on unsupported BOARD_ITEM." );
144 };
145 
146 
147 static struct BOARD_ITEM_DESC
148 {
150  {
151  auto& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
152 
153  if( layerEnum.Choices().GetCount() == 0 )
154  {
155  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
156  {
157  layerEnum.Map( *seq, LSET::Name( *seq ) );
158  }
159  }
160 
164 
165  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _( "Position X" ),
167  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, int>( _( "Position Y" ),
169  propMgr.AddProperty( new PROPERTY_ENUM<BOARD_ITEM, PCB_LAYER_ID>( _( "Layer" ),
171  propMgr.AddProperty( new PROPERTY<BOARD_ITEM, bool>( _( "Locked" ),
173  }
175 
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:712
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
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError=ARC_LOW_DEF, bool ignoreLineWidth=false) const
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition: property.h:585
Definition: typeinfo.h:85
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
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,...
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:515
void DeleteStructure()
Function DeleteStructure deletes this object after removing from its parent if it has one.
usual segment : line with rounded ends
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
static wxString LayerMaskDescribe(const BOARD *aBoard, LSET aMask)
Helper function Return a string (to be shown to the user) describing a layer mask.
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
static LSET AllTechMask()
Function AllTechMask returns a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:782
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:377
#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)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:78
SHAPE_POLY_SET.
Arcs (with rounded ends)
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:749
Bezier Curve.
void SetX(int aX)
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
virtual bool IsLocked() const
Function IsLocked.
static struct BOARD_ITEM_DESC _BOARD_ITEM_DESC
int GetX() const
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
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
The common library.
Provides class metadata.
Definition: property_mgr.h:58
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Function GetStandardLayerName returns an "English Standard" name of a PCB layer when given aLayerNumb...
Definition: class_board.h:648