KiCad PCB EDA Suite
Loading...
Searching...
No Matches
stackup_table_model.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
21
22#include <string>
23
24#include <base_units.h>
25#include <board.h>
29#include <eda_units.h>
30#include <i18n_utility.h>
31#include <string_utils.h>
32
33#include <wx/translation.h>
34
35
37{
38 // Headings match the one-shot stackup table this generator replaces
39 static const GENERATED_TABLE_SCHEMA schema(
40 { { (int) STACKUP_TABLE_COLUMN_ID::LAYER_NAME, "layer", _HKI( "Layer Name" ), GENERATED_TABLE_ALIGN::LEFT,
41 true, _HKI( "Layer" ) },
42 { (int) STACKUP_TABLE_COLUMN_ID::TYPE, "type", _HKI( "Type" ), GENERATED_TABLE_ALIGN::LEFT, true,
43 _HKI( "Type" ) },
44 { (int) STACKUP_TABLE_COLUMN_ID::MATERIAL, "material", _HKI( "Material" ), GENERATED_TABLE_ALIGN::LEFT,
45 true, _HKI( "Material" ) },
46 { (int) STACKUP_TABLE_COLUMN_ID::THICKNESS, "thickness", _HKI( "Thickness" ),
47 GENERATED_TABLE_ALIGN::RIGHT, true, _HKI( "Thickness" ) },
48 { (int) STACKUP_TABLE_COLUMN_ID::COLOR, "color", _HKI( "Color" ), GENERATED_TABLE_ALIGN::LEFT, true,
49 _HKI( "Color" ) },
50 { (int) STACKUP_TABLE_COLUMN_ID::EPSILON_R, "epsilon_r", _HKI( "Epsilon R" ),
51 GENERATED_TABLE_ALIGN::RIGHT, true, _HKI( "Epsilon R" ) },
52 { (int) STACKUP_TABLE_COLUMN_ID::LOSS_TANGENT, "loss_tangent", _HKI( "Loss Tangent" ),
53 GENERATED_TABLE_ALIGN::RIGHT, true, _HKI( "Loss Tan" ) } },
55
56 return schema;
57}
58
59
60namespace
61{
62
63wxString layerName( const BOARD& aBoard, const BOARD_STACKUP_ITEM& aItem, int aSublayer )
64{
65 // Dielectric names are built like the gerber job file's, since the stackup's own are not very good
66 if( aItem.GetType() == BS_ITEM_TYPE_DIELECTRIC )
67 {
68 wxString name = _( "Dielectric" );
69
70 if( aItem.GetSublayersCount() < 2 )
71 name << wxT( " " ) << aItem.GetDielectricLayerId();
72 else
73 name << wxString::Format( _( " %d (%d/%d)" ), aItem.GetDielectricLayerId(), aSublayer + 1,
74 aItem.GetSublayersCount() );
75
76 return name;
77 }
78
79 // The stackup keeps the name from when Board Setup last closed, so a later rename would be missed
80 if( IsValidLayer( aItem.GetBrdLayerId() ) )
81 return aBoard.GetLayerName( aItem.GetBrdLayerId() );
82
83 return aItem.GetLayerName();
84}
85
86
87wxString cellText( const BOARD_STACKUP_ITEM& aItem, int aSublayer, const wxString& aName, int aColumnId,
88 GENERATED_TABLE_UNITS aUnits, int aPrecision )
89{
90 switch( static_cast<STACKUP_TABLE_COLUMN_ID>( aColumnId ) )
91 {
93 return aName;
94
96 return InitialCaps( aItem.GetTypeName() );
97
99 return aItem.GetMaterial( aSublayer );
100
102 // Layers like silkscreen, paste, etc. have no defined thickness, but that
103 // does not mean that they are specified as exactly 0mm
104 if( !aItem.IsThicknessEditable() )
105 return NotSpecifiedPrm();
106
107 // The table's own units, so the drawing does not change with the editor's display units
108 return FormatGeneratedTableLength( aItem.GetThickness( aSublayer ), aUnits, aPrecision );
109
111 return aItem.GetColor( aSublayer );
112
115
118 aItem.GetLossTangent( aSublayer ) );
119
120 default:
121 return wxEmptyString;
122 }
123}
124
125
126std::string canonicalName( PCB_LAYER_ID aLayer )
127{
128 return std::string( BOARD::GetStandardLayerName( aLayer ).ToUTF8() );
129}
130
131} // namespace
132
133
134std::vector<GENERATED_TABLE_ROW> BuildStackupTableRows( const BOARD& aBoard,
135 const std::vector<GENERATED_TABLE_COLUMN>& aColumns,
136 GENERATED_TABLE_UNITS aUnits, int aPrecision )
137{
138 // A copy, so generating the table never rewrites a stale stored stackup behind the user's back
139 BOARD_STACKUP stackup = aBoard.GetStackupOrDefault();
140 stackup.SynchronizeWithBoard( &aBoard.GetDesignSettings() );
141
142 std::vector<GENERATED_TABLE_ROW> rows;
143 PCB_LAYER_ID copperAbove = UNDEFINED_LAYER;
144
145 for( const BOARD_STACKUP_ITEM* item : stackup.GetList() )
146 {
147 if( item->GetType() == BS_ITEM_TYPE_COPPER )
148 copperAbove = item->GetBrdLayerId();
149
150 for( int sublayer = 0; sublayer < item->GetSublayersCount(); ++sublayer )
151 {
152 GENERATED_TABLE_ROW& row = rows.emplace_back();
153
154 // Canonical names, so a rename does not move a row's formatting onto a different layer
155 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
156 row.m_Key = "D:" + canonicalName( copperAbove ) + ":" + std::to_string( sublayer );
157 else
158 {
159 row.m_Key = "L:" + canonicalName( item->GetBrdLayerId() );
160 }
161
162 const wxString name = layerName( aBoard, *item, sublayer );
163
164 row.m_Cells.reserve( aColumns.size() );
165
166 for( const GENERATED_TABLE_COLUMN& column : aColumns )
167 row.m_Cells.push_back( cellText( *item, sublayer, name, column.m_Id, aUnits, aPrecision ) );
168 }
169 }
170
171 return rows;
172}
const char * name
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:131
@ BS_ITEM_TYPE_COPPER
@ BS_ITEM_TYPE_DIELECTRIC
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
bool SynchronizeWithBoard(const BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
BOARD_STACKUP GetStackupOrDefault() const
Definition board.cpp:3506
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition board.h:1131
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:960
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
The columns one generator (the drill chart, a stackup table, ...) can produce, and the units and prec...
#define _(s)
wxString FormatGeneratedTableLength(int aValue, GENERATED_TABLE_UNITS aUnits, int aPrecision)
Render a length the way a generated table's cell shows it.
GENERATED_TABLE_UNITS
Some functions to handle hotkeys in KiCad.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
Definition layer_ids.h:722
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.
#define _HKI(x)
Definition page_info.cpp:40
wxString NotSpecifiedPrm()
std::vector< GENERATED_TABLE_ROW > BuildStackupTableRows(const BOARD &aBoard, const std::vector< GENERATED_TABLE_COLUMN > &aColumns, GENERATED_TABLE_UNITS aUnits, int aPrecision)
One row per stackup layer, and per sublayer of a split dielectric, top to bottom.
const GENERATED_TABLE_SCHEMA & StackupTableSchema()
Every column a stackup table can show, all of them by default.
STACKUP_TABLE_COLUMN_ID
wxString InitialCaps(const wxString &aString)
Capitalize only the first word.
A column as a generated table actually carries it: what a row's cell in that column holds and how it ...
One data row of a generated table, and the identity its formatting follows across rebuilds.
std::vector< wxString > m_Cells
std::vector< DATABASE_CONNECTION::ROW > rows