KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_stackup_table.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25#include <board.h>
27#include <board_item.h>
28#include <pcb_table.h>
29#include <pcb_tablecell.h>
30#include <pcb_edit_frame.h>
31#include <units_provider.h>
33#include <string_utils.h>
34
36{
37 BOARD_DESIGN_SETTINGS& settings = aBoard->GetDesignSettings();
38 BOARD_STACKUP& stackup = settings.GetStackupDescriptor();
39 UNITS_PROVIDER units_provider( pcbIUScale, aDisplayUnits );
40
41 stackup.SynchronizeWithBoard( &settings );
42
43 std::vector<BOARD_STACKUP_ITEM*> layers = stackup.GetList();
44
45 PCB_TABLE* table = new PCB_TABLE( aBoard, pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ) );
46 table->SetColCount( 7 );
47
48 const auto addHeaderCell =
49 [&]( const wxString& text )
50 {
52 c->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
53 c->SetTextThickness( pcbIUScale.mmToIU( 0.3 ) );
54 c->SetText( text );
55 table->AddCell( c );
56 };
57
58 const auto addDataCell =
59 [&]( const wxString& text, const char align = 'L' )
60 {
62 c->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
63 c->SetTextThickness( pcbIUScale.mmToIU( 0.2 ) );
64
65 if( align == 'R' )
67
68 c->SetText( text );
69 table->AddCell( c );
70 };
71
72 const auto layerThicknessString =
73 [&]( const BOARD_STACKUP_ITEM& aStackupItem, int aSublayerId )
74 {
75 const int layerThickness = aStackupItem.GetThickness( aSublayerId );
76
77 // Layers like silkscreen, paste, etc. have no defined thickness, but that
78 // does not mean that they are specified as exactly 0mm
79 if( !aStackupItem.IsThicknessEditable() )
80 return NotSpecifiedPrm();
81
82 return units_provider.StringFromValue( layerThickness, true );
83 };
84
85 addHeaderCell( _( "Layer Name" ) );
86 addHeaderCell( _( "Type" ) );
87 addHeaderCell( _( "Material" ) );
88 addHeaderCell( _( "Thickness" ) );
89 addHeaderCell( _( "Color" ) );
90 addHeaderCell( _( "Epsilon R" ) );
91 addHeaderCell( _( "Loss Tangent" ) );
92
93 for( int i = 0; i < stackup.GetCount(); i++ )
94 {
95 BOARD_STACKUP_ITEM* stackup_item = layers.at( i );
96
97 for( int sublayer_id = 0; sublayer_id < stackup_item->GetSublayersCount(); sublayer_id++ )
98 {
99 // Layer names are empty until we close at least once the board setup dialog.
100 // If the user did not open the dialog, then get the names from the board.
101 // But dielectric layer names will be missing.
102 // In this case, for dielectric, a dummy name will be used
103 if( stackup_item->GetLayerName().IsEmpty() )
104 {
105 wxString layerName;
106
107 if( IsValidLayer( stackup_item->GetBrdLayerId() ) )
108 layerName = aBoard->GetLayerName( stackup_item->GetBrdLayerId() );
109
110 if( layerName.IsEmpty() && stackup_item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
111 layerName = _( "Dielectric" );
112
113 addDataCell( layerName );
114 }
115 else
116 {
117 addDataCell( stackup_item->GetLayerName() );
118 }
119
120 addDataCell( InitialCaps( stackup_item->GetTypeName() ) );
121 addDataCell( stackup_item->GetMaterial( sublayer_id ) );
122 addDataCell( layerThicknessString( *stackup_item, sublayer_id ), 'R' );
123 addDataCell( stackup_item->GetColor( sublayer_id ) );
125 stackup_item->GetEpsilonR( sublayer_id ) ), 'R' );
127 stackup_item->GetLossTangent( sublayer_id ) ), 'R' );
128 }
129 }
130
131 table->Autosize();
132
133 return table;
134}
135
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:115
#define DEFAULT_LINE_WIDTH
@ BS_ITEM_TYPE_DIELECTRIC
PCB_TABLE * Build_Board_Stackup_Table(BOARD *aBoard, EDA_UNITS aDisplayUnits)
Container for design settings for a BOARD object.
BOARD_STACKUP & GetStackupDescriptor()
Manage one layer needed to make a physical board.
wxString GetTypeName() const
int GetSublayersCount() const
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetColor(int aDielectricSubLayer=0) const
wxString GetLayerName() const
PCB_LAYER_ID GetBrdLayerId() const
bool IsThicknessEditable() const
int GetThickness(int aDielectricSubLayer=0) const
BOARD_STACKUP_ITEM_TYPE GetType() const
wxString GetMaterial(int aDielectricSubLayer=0) const
double GetLossTangent(int aDielectricSubLayer=0) const
Manage layers needed to make a physical board.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
int GetCount() const
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:692
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1041
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:544
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition eda_text.cpp:295
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:281
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:420
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
#define _(s)
EDA_UNITS
Definition eda_units.h:48
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
Definition layer_ids.h:654
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Return the string from aValue according to aUnits (inch, mm ...) for display.
wxString NotSpecifiedPrm()
wxString InitialCaps(const wxString &aString)
Capitalize only the first word.
@ GR_TEXT_H_ALIGN_RIGHT
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695