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, see <https://www.gnu.org/licenses/>.
18 */
19
20
21#include <board.h>
23#include <board_item.h>
24#include <pcb_table.h>
25#include <pcb_tablecell.h>
26#include <pcb_edit_frame.h>
27#include <units_provider.h>
29#include <string_utils.h>
30
32{
33 BOARD_DESIGN_SETTINGS& settings = aBoard->GetDesignSettings();
34 BOARD_STACKUP& stackup = settings.GetStackupDescriptor();
35 UNITS_PROVIDER units_provider( pcbIUScale, aDisplayUnits );
36
37 stackup.SynchronizeWithBoard( &settings );
38
39 std::vector<BOARD_STACKUP_ITEM*> layers = stackup.GetList();
40
41 PCB_TABLE* table = new PCB_TABLE( aBoard, pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ) );
42 table->SetColCount( 7 );
43
44 const auto addHeaderCell =
45 [&]( const wxString& text )
46 {
48 c->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
49 c->SetTextThickness( pcbIUScale.mmToIU( 0.3 ) );
50 c->SetText( text );
51 table->AddCell( c );
52 };
53
54 const auto addDataCell =
55 [&]( const wxString& text, const char align = 'L' )
56 {
58 c->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
59 c->SetTextThickness( pcbIUScale.mmToIU( 0.2 ) );
60
61 if( align == 'R' )
63
64 c->SetText( text );
65 table->AddCell( c );
66 };
67
68 const auto layerThicknessString =
69 [&]( const BOARD_STACKUP_ITEM& aStackupItem, int aSublayerId )
70 {
71 const int layerThickness = aStackupItem.GetThickness( aSublayerId );
72
73 // Layers like silkscreen, paste, etc. have no defined thickness, but that
74 // does not mean that they are specified as exactly 0mm
75 if( !aStackupItem.IsThicknessEditable() )
76 return NotSpecifiedPrm();
77
78 return units_provider.StringFromValue( layerThickness, true );
79 };
80
81 addHeaderCell( _( "Layer Name" ) );
82 addHeaderCell( _( "Type" ) );
83 addHeaderCell( _( "Material" ) );
84 addHeaderCell( _( "Thickness" ) );
85 addHeaderCell( _( "Color" ) );
86 addHeaderCell( _( "Epsilon R" ) );
87 addHeaderCell( _( "Loss Tangent" ) );
88
89 for( int i = 0; i < stackup.GetCount(); i++ )
90 {
91 BOARD_STACKUP_ITEM* stackup_item = layers.at( i );
92
93 for( int sublayer_id = 0; sublayer_id < stackup_item->GetSublayersCount(); sublayer_id++ )
94 {
95 // Layer names are empty until we close at least once the board setup dialog.
96 // If the user did not open the dialog, then get the names from the board.
97 // But dielectric layer names will be missing. And in stackup, the name is not very good
98 // So, for dielectric, a name will be used, similar to the name build in gerber job file
99 wxString layerName = stackup_item->GetLayerName();
100
101 if( layerName.IsEmpty() )
102 {
103 if( IsValidLayer( stackup_item->GetBrdLayerId() ) )
104 layerName = aBoard->GetLayerName( stackup_item->GetBrdLayerId() );
105 }
106
107 if( stackup_item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
108 {
109 layerName = _( "Dielectric" );
110
111 if( stackup_item->GetSublayersCount() < 2 )
112 layerName << wxT( " " ) << stackup_item->GetDielectricLayerId();
113 else
114 layerName << wxString::Format( _( " %d (%d/%d)" ), stackup_item->GetDielectricLayerId(),
115 sublayer_id + 1, stackup_item->GetSublayersCount() );
116 }
117
118 addDataCell( layerName );
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 table->SetPosition( VECTOR2I( 0, 0 ) );
133
134 return table;
135}
136
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:124
#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
int GetDielectricLayerId() 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:372
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:793
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1149
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:265
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:404
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
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:44
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
Definition layer_ids.h:653
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.
std::vector< std::vector< std::string > > table
@ GR_TEXT_H_ALIGN_RIGHT
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683