KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_stackup.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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22#include "board_stackup.h"
23#include <base_units.h>
24#include <string_utils.h>
25#include <layer_ids.h>
27#include <board.h>
28#include <i18n_utility.h> // For _HKI definition
31#include <richio.h>
32#include <google/protobuf/any.pb.h>
33#include <api/board/board.pb.h>
34#include <api/api_enums.h>
35
36
38{
39 if( m_Material != aOther.m_Material ) return false;
40 if( m_Thickness != aOther.m_Thickness ) return false;
41 if( m_ThicknessLocked != aOther.m_ThicknessLocked ) return false;
42 if( m_EpsilonR != aOther.m_EpsilonR ) return false;
43 if( m_LossTangent != aOther.m_LossTangent ) return false;
44 if( m_Color != aOther.m_Color ) return false;
45
46 return true;
47}
48
49
51{
52 DIELECTRIC_PRMS item_prms;
53 m_DielectricPrmsList.emplace_back( item_prms );
55 m_Type = aType;
57 SetEnabled( true );
58
59 // Initialize parameters to a usual value for allowed types:
60 switch( m_Type )
61 {
65 break;
66
68 m_TypeName = KEY_CORE; // or prepreg
70 SetMaterial( wxT( "FR4" ) ); // or other dielectric name
71 SetLossTangent( 0.02 ); // for FR4
72 SetEpsilonR( 4.5 ); // for FR4
73 break;
74
76 m_TypeName = wxT( "solderpaste" );
77 break;
78
80 m_TypeName = wxT( "soldermask" );
82 SetMaterial( NotSpecifiedPrm() ); // or other solder mask material name
85 break;
86
88 m_TypeName = wxT( "silkscreen" );
90 SetMaterial( NotSpecifiedPrm() ); // or other silkscreen material name
92 break;
93
95 break;
96 }
97}
98
99
101{
102 m_LayerId = aOther.m_LayerId;
104 m_Type = aOther.m_Type;
105 m_enabled = aOther.m_enabled;
107 m_TypeName = aOther.m_TypeName;
108 m_LayerName = aOther.m_LayerName;
109}
110
111
113{
114 if( m_Type != aOther.m_Type ) return false;
115 if( m_LayerName != aOther.m_LayerName ) return false;
116 if( m_TypeName != aOther.m_TypeName ) return false;
117 if( m_LayerId != aOther.m_LayerId ) return false;
118 if( m_DielectricLayerId != aOther.m_DielectricLayerId ) return false;
119 if( m_enabled != aOther.m_enabled ) return false;
120
121 if( !std::equal( std::begin( m_DielectricPrmsList ), std::end( m_DielectricPrmsList ),
122 std::begin( aOther.m_DielectricPrmsList ),
123 []( const DIELECTRIC_PRMS& aA, const DIELECTRIC_PRMS& aB )
124 {
125 return aA == aB;
126 } ) )
127 {
128 return false;
129 }
130
131 return true;
132}
133
134
135void BOARD_STACKUP_ITEM::AddDielectricPrms( int aDielectricPrmsIdx )
136{
137 // add a DIELECTRIC_PRMS item to m_DielectricPrmsList
138 DIELECTRIC_PRMS new_prms;
139
140 m_DielectricPrmsList.emplace( m_DielectricPrmsList.begin() + aDielectricPrmsIdx, new_prms );
141}
142
143
144void BOARD_STACKUP_ITEM::RemoveDielectricPrms( int aDielectricPrmsIdx )
145{
146 // Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList if possible
147
148 if( GetSublayersCount() < 2
149 || aDielectricPrmsIdx < 0
150 || aDielectricPrmsIdx >= GetSublayersCount() )
151 {
152 return;
153 }
154
155 m_DielectricPrmsList.erase( m_DielectricPrmsList.begin() + aDielectricPrmsIdx );
156}
157
158
159
161{
162 // A reasonable thickness for copper layers:
163 return pcbIUScale.mmToIU( 0.035 );
164}
165
166
168{
169 // A reasonable thickness for solder mask:
170 return pcbIUScale.mmToIU( 0.01 );
171}
172
173
174// Getters:
175wxString BOARD_STACKUP_ITEM::GetColor( int aDielectricSubLayer ) const
176{
177 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
178
179 return m_DielectricPrmsList[aDielectricSubLayer].m_Color;
180}
181
182int BOARD_STACKUP_ITEM::GetThickness( int aDielectricSubLayer ) const
183{
184 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
185
186 return m_DielectricPrmsList[aDielectricSubLayer].m_Thickness;
187}
188
189
190double BOARD_STACKUP_ITEM::GetLossTangent( int aDielectricSubLayer ) const
191{
192 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
193
194 return m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent;
195}
196
197
198double BOARD_STACKUP_ITEM::GetEpsilonR( int aDielectricSubLayer ) const
199{
200 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
201
202 return m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR;
203}
204
205
206bool BOARD_STACKUP_ITEM::IsThicknessLocked( int aDielectricSubLayer ) const
207{
208 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
209
210 return m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked;
211}
212
213
214wxString BOARD_STACKUP_ITEM::GetMaterial( int aDielectricSubLayer ) const
215{
216 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
217
218 return m_DielectricPrmsList[aDielectricSubLayer].m_Material;
219}
220
221
222// Setters:
223void BOARD_STACKUP_ITEM::SetColor( const wxString& aColorName , int aDielectricSubLayer )
224{
225 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
226
227 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
228 m_DielectricPrmsList[aDielectricSubLayer].m_Color = aColorName;
229}
230
231
232void BOARD_STACKUP_ITEM::SetThickness( int aThickness, int aDielectricSubLayer )
233{
234 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
235
236 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
237 m_DielectricPrmsList[aDielectricSubLayer].m_Thickness = aThickness;
238}
239
240
241void BOARD_STACKUP_ITEM::SetLossTangent( double aTg, int aDielectricSubLayer )
242{
243 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
244
245 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
246 m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent = aTg;
247}
248
249
250void BOARD_STACKUP_ITEM::SetEpsilonR( double aEpsilon, int aDielectricSubLayer )
251{
252 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
253
254 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
255 m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR = aEpsilon;
256}
257
258
259void BOARD_STACKUP_ITEM::SetThicknessLocked( bool aLocked, int aDielectricSubLayer )
260{
261 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
262
263 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
264 m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked = aLocked;
265}
266
267
268void BOARD_STACKUP_ITEM::SetMaterial( const wxString& aName, int aDielectricSubLayer )
269{
270 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
271
272 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
273 m_DielectricPrmsList[aDielectricSubLayer].m_Material = aName;
274}
275
276
278{
281};
282
283
285{
288};
289
290
291bool BOARD_STACKUP_ITEM::HasMaterialValue( int aDielectricSubLayer ) const
292{
293 // return true if the material is specified
294 return IsMaterialEditable() && IsPrmSpecified( GetMaterial( aDielectricSubLayer ) );
295}
296
297
299{
303}
304
305
307{
311}
312
313
315{
319}
320
321
322wxString BOARD_STACKUP_ITEM::FormatEpsilonR( int aDielectricSubLayer ) const
323{
324 // return a wxString to print/display Epsilon R
325 // note: we do not want scientific notation
326 wxString txt = UIDouble2Str( GetEpsilonR( aDielectricSubLayer ) );
327 return txt;
328}
329
330
331wxString BOARD_STACKUP_ITEM::FormatLossTangent( int aDielectricSubLayer ) const
332{
333 // return a wxString to print/display Loss Tangent
334 // note: we do not want scientific notation
335 wxString txt = UIDouble2Str( GetLossTangent( aDielectricSubLayer ) );
336 return txt;
337}
338
339
341{
342 // return a wxString to print/display a dielectric name
343 wxString lname;
344 lname.Printf( _( "Dielectric %d" ), GetDielectricLayerId() );
345
346 return lname;
347}
348
349
351{
352 m_HasDielectricConstrains = false; // True if some dielectric layers have constrains
353 // (Loss tg and Epison R)
354 m_HasThicknessConstrains = false; // True if some dielectric or copper layers have constrains
356 m_CastellatedPads = false; // True if some castellated pads exist
357 m_EdgePlating = false; // True if edge board is plated
358 m_FinishType = wxT( "None" ); // undefined finish type
359}
360
361
363{
369 m_FinishType = aOther.m_FinishType;
370
371 // All items in aOther.m_list have to be duplicated, because aOther.m_list
372 // manage pointers to these items
373 for( BOARD_STACKUP_ITEM* item : aOther.m_list )
374 {
375 BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
376 Add( dup_item );
377 }
378}
379
380
382{
388 m_FinishType = aOther.m_FinishType;
389
390 RemoveAll();
391
392 // All items in aOther.m_list have to be duplicated, because aOther.m_list
393 // manage pointers to these items
394 for( BOARD_STACKUP_ITEM* item : aOther.m_list )
395 {
396 BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
397 Add( dup_item );
398 }
399
400 return *this;
401}
402
403
404bool BOARD_STACKUP::operator==( const BOARD_STACKUP& aOther ) const
405{
406 if( m_HasDielectricConstrains != aOther.m_HasDielectricConstrains ) return false;
407 if( m_HasThicknessConstrains != aOther.m_HasThicknessConstrains ) return false;
408 if( m_EdgeConnectorConstraints != aOther.m_EdgeConnectorConstraints ) return false;
409 if( m_CastellatedPads != aOther.m_CastellatedPads ) return false;
410 if( m_EdgePlating != aOther.m_EdgePlating ) return false;
411 if( m_FinishType != aOther.m_FinishType ) return false;
412
413 if( !std::equal( std::begin( m_list ), std::end( m_list ), std::begin( aOther.m_list ),
414 []( const BOARD_STACKUP_ITEM* aA, const BOARD_STACKUP_ITEM* aB )
415 {
416 return *aA == *aB;
417 } ) )
418 {
419 return false;
420 }
421
422 return true;
423}
424
425
426void BOARD_STACKUP::Serialize( google::protobuf::Any& aContainer ) const
427{
428 using namespace kiapi::board;
429 BoardStackup stackup;
430
431 for( const BOARD_STACKUP_ITEM* item : m_list )
432 {
433 BoardStackupLayer* layer = stackup.mutable_layers()->Add();
434
435 layer->mutable_thickness()->set_value_nm( item->GetThickness() );
436 layer->set_layer( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( item->GetBrdLayerId() ) );
437 layer->set_type(
438 ToProtoEnum<BOARD_STACKUP_ITEM_TYPE, BoardStackupLayerType>( item->GetType() ) );
439
440 switch( item->GetType() )
441 {
443 {
444 layer->set_material_name( "copper" );
445 // (no copper params yet...)
446 break;
447 }
448
450 {
451 BoardStackupDielectricLayer* dielectric = layer->mutable_dielectric()->New();
452
453 for( int i = 0; i < item->GetSublayersCount(); ++i )
454 {
455 BoardStackupDielectricProperties* props = dielectric->mutable_layer()->Add();
456 props->set_epsilon_r( item->GetEpsilonR( i ) );
457 props->set_loss_tangent( item->GetLossTangent( i ) );
458 props->set_material_name( item->GetMaterial( i ).ToUTF8() );
459 props->mutable_thickness()->set_value_nm( item->GetThickness( i ) );
460 }
461
462 break;
463 }
464
465 default:
466 break;
467 }
468 }
469
470 aContainer.PackFrom( stackup );
471}
472
473
474bool BOARD_STACKUP::Deserialize( const google::protobuf::Any& aContainer )
475{
476 // Read-only for now
477 return false;
478}
479
480
482{
483 for( BOARD_STACKUP_ITEM* item : m_list )
484 delete item;
485
486 m_list.clear();
487}
488
489
491{
492 if( aIndex < 0 || aIndex >= GetCount() )
493 return nullptr;
494
495 return GetList()[aIndex];
496}
497
498
500{
501 // return the board thickness from the thickness of BOARD_STACKUP_ITEM list
502 int thickness = 0;
503
504 for( BOARD_STACKUP_ITEM* item : m_list )
505 {
506 if( item->IsThicknessEditable() && item->IsEnabled() )
507 {
508 thickness += item->GetThickness();
509
510 // dielectric layers can have more than one main layer
511 // add thickness of all sublayers
512 for( int idx = 1; idx < item->GetSublayersCount(); idx++ )
513 {
514 thickness += item->GetThickness( idx );
515 }
516 }
517 }
518
519 return thickness;
520}
521
522
524{
525 bool change = false;
526 // Build the suitable stackup:
527 BOARD_STACKUP stackup;
528 stackup.BuildDefaultStackupList( aSettings );
529
530 // First, find removed layers:
531 for( BOARD_STACKUP_ITEM* curr_item: m_list )
532 {
533 bool found = false;
534
535 for( BOARD_STACKUP_ITEM* item: stackup.GetList() )
536 {
537 if( curr_item->GetBrdLayerId() != UNDEFINED_LAYER )
538 {
539 if( item->GetBrdLayerId() == curr_item->GetBrdLayerId() )
540 {
541 found = true;
542 break;
543 }
544 }
545 else // curr_item = dielectric layer
546 {
547 if( item->GetBrdLayerId() != UNDEFINED_LAYER )
548 continue;
549
550 if( item->GetDielectricLayerId() == curr_item->GetDielectricLayerId() )
551 {
552 found = true;
553 break;
554 }
555 }
556 }
557
558 if( !found ) // a layer was removed: a change is found
559 {
560 change = true;
561 break;
562 }
563 }
564
565 // Now initialize all stackup items to the initial values, when exist
566 for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
567 {
568 bool found = false;
569 // Search for initial settings:
570 for( const BOARD_STACKUP_ITEM* initial_item : m_list )
571 {
572 if( item->GetBrdLayerId() != UNDEFINED_LAYER )
573 {
574 if( item->GetBrdLayerId() == initial_item->GetBrdLayerId() )
575 {
576 *item = *initial_item;
577 found = true;
578 break;
579 }
580 }
581 else // dielectric layer: see m_DielectricLayerId for identification
582 {
583 // Compare dielectric layer with dielectric layer
584 if( initial_item->GetBrdLayerId() != UNDEFINED_LAYER )
585 continue;
586
587 if( item->GetDielectricLayerId() == initial_item->GetDielectricLayerId() )
588 {
589 *item = *initial_item;
590 found = true;
591 break;
592 }
593 }
594 }
595
596 if( !found )
597 {
598 change = true;
599 }
600 }
601
602 // Transfer layer settings:
603 *this = stackup;
604
605 // Transfer other stackup settings from aSettings
606 const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
609 m_CastellatedPads = source_stackup.m_CastellatedPads;
610 m_EdgePlating = source_stackup.m_EdgePlating;
611 m_FinishType = source_stackup.m_FinishType;
612
613 return change;
614}
615
616
618 int aActiveCopperLayersCount )
619{
620 // Creates a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
621 // Note: the m_TypeName string is made translatable using _HKI marker, but is not
622 // translated when building the stackup.
623 // It will be used as this in files, and can be translated only in dialog
624 // if aSettings == NULL, build a full stackup (with 32 copper layers)
625 LSET enabledLayer = aSettings ? aSettings->GetEnabledLayers() : StackupAllowedBrdLayers();
626 int copperLayerCount = aSettings ? aSettings->GetCopperLayerCount() : 32;
627
628 // We need to calculate a suitable dielectric layer thickness.
629 // If no settings, and if aActiveCopperLayersCount is given, use it
630 // (If no settings, and no aActiveCopperLayersCount, the full 32 layers are used)
631 int activeCuLayerCount = copperLayerCount;
632
633 if( aSettings == nullptr && aActiveCopperLayersCount > 0 )
634 activeCuLayerCount = aActiveCopperLayersCount;
635
636 int brd__thickness = aSettings ? aSettings->GetBoardThickness() : pcbIUScale.mmToIU( 1.6 );
637 int diel_thickness = brd__thickness -
638 ( BOARD_STACKUP_ITEM::GetCopperDefaultThickness() * activeCuLayerCount );
639
640 // Take in account the solder mask thickness:
641 int sm_count = ( enabledLayer & LSET( { F_Mask, B_Mask } ) ).count();
642 diel_thickness -= BOARD_STACKUP_ITEM::GetMaskDefaultThickness() * sm_count;
643 diel_thickness /= std::max( 1, activeCuLayerCount - 1 );
644
645 int dielectric_idx = 0;
646
647 // Add silk screen, solder mask and solder paste layers on top
648 if( enabledLayer[F_SilkS] )
649 {
651 item->SetBrdLayerId( F_SilkS );
652 item->SetTypeName( _HKI( "Top Silk Screen" ) );
653 Add( item );
654 }
655
656 if( enabledLayer[F_Paste] )
657 {
659 item->SetBrdLayerId( F_Paste );
660 item->SetTypeName( _HKI( "Top Solder Paste" ) );
661 Add( item );
662 }
663
664 if( enabledLayer[F_Mask] )
665 {
667 item->SetBrdLayerId( F_Mask );
668 item->SetTypeName( _HKI( "Top Solder Mask" ) );
669 Add( item );
670 }
671
672 // Add copper and dielectric layers
673 for( PCB_LAYER_ID layer : enabledLayer.CuStack() )
674 {
676 item->SetBrdLayerId( layer );
677 item->SetTypeName( KEY_COPPER );
678 Add( item );
679
680 if( layer == B_Cu )
681 break;
682
683 // Add the dielectric layer:
685 item->SetThickness( diel_thickness );
686 item->SetDielectricLayerId( dielectric_idx + 1 );
687
688 // Display a dielectric default layer name:
689 if( (dielectric_idx & 1) == 0 )
690 {
691 item->SetTypeName( KEY_CORE );
692 item->SetMaterial( wxT( "FR4" ) );
693 }
694 else
695 {
696 item->SetTypeName( KEY_PREPREG );
697 item->SetMaterial( wxT( "FR4" ) );
698 }
699
700 Add( item );
701 dielectric_idx++;
702 }
703
704 // Add silk screen, solder mask and solder paste layers on bottom
705 if( enabledLayer[B_Mask] )
706 {
708 item->SetBrdLayerId( B_Mask );
709 item->SetTypeName( _HKI( "Bottom Solder Mask" ) );
710 Add( item );
711 }
712
713 if( enabledLayer[B_Paste] )
714 {
716 item->SetBrdLayerId( B_Paste );
717 item->SetTypeName( _HKI( "Bottom Solder Paste" ) );
718 Add( item );
719 }
720
721 if( enabledLayer[B_SilkS] )
722 {
724 item->SetBrdLayerId( B_SilkS );
725 item->SetTypeName( _HKI( "Bottom Silk Screen" ) );
726 Add( item );
727 }
728
729 // Transfer other stackup settings from aSettings
730 if( aSettings )
731 {
732 const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
735 m_CastellatedPads = source_stackup.m_CastellatedPads;
736 m_EdgePlating = source_stackup.m_EdgePlating;
737 m_FinishType = source_stackup.m_FinishType;
738 }
739}
740
741
742void BOARD_STACKUP::FormatBoardStackup( OUTPUTFORMATTER* aFormatter, const BOARD* aBoard ) const
743{
744 // Board stackup is the ordered list from top to bottom of
745 // physical layers and substrate used to build the board.
746 if( m_list.empty() )
747 return;
748
749 aFormatter->Print( "(stackup" );
750
751 // Note:
752 // Unspecified parameters are not stored in file.
753 for( BOARD_STACKUP_ITEM* item: m_list )
754 {
755 wxString layer_name;
756
757 if( item->GetBrdLayerId() == UNDEFINED_LAYER )
758 layer_name.Printf( wxT( "dielectric %d" ), item->GetDielectricLayerId() );
759 else
760 layer_name = LSET::Name( item->GetBrdLayerId() );
761
762 aFormatter->Print( "(layer %s (type %s)",
763 aFormatter->Quotew( layer_name ).c_str(),
764 aFormatter->Quotew( item->GetTypeName() ).c_str() );
765
766 // Output other parameters (in sub layer list there is at least one item)
767 for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
768 {
769 if( idx ) // not for the main (first) layer.
770 aFormatter->Print( " addsublayer" );
771
772 if( item->IsColorEditable() && IsPrmSpecified( item->GetColor( idx ) ) )
773 {
774 aFormatter->Print( "(color %s)",
775 aFormatter->Quotew( item->GetColor( idx ) ).c_str() );
776 }
777
778 if( item->IsThicknessEditable() )
779 {
780 aFormatter->Print( "(thickness %s",
781 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, item->GetThickness( idx ) ).c_str() );
782
783 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC && item->IsThicknessLocked( idx ) )
784 aFormatter->Print( " locked" );
785
786 aFormatter->Print( ")" );
787 }
788
789 if( item->HasMaterialValue( idx ) )
790 {
791 aFormatter->Print( "(material %s)",
792 aFormatter->Quotew( item->GetMaterial( idx ) ).c_str() );
793 }
794
795 if( item->HasEpsilonRValue() && item->HasMaterialValue( idx ) )
796 aFormatter->Print( "(epsilon_r %g)", item->GetEpsilonR( idx ) );
797
798 if( item->HasLossTangentValue() && item->HasMaterialValue( idx ) )
799 {
800 aFormatter->Print( "(loss_tangent %s)",
801 FormatDouble2Str( item->GetLossTangent( idx ) ).c_str() );
802 }
803 }
804
805 aFormatter->Print( ")" );
806 }
807
808 // Other infos about board, related to layers and other fabrication specifications
810 aFormatter->Print( "(copper_finish %s)", aFormatter->Quotew( m_FinishType ).c_str() );
811
812 KICAD_FORMAT::FormatBool( aFormatter, "dielectric_constraints", m_HasDielectricConstrains );
813
815 {
816 aFormatter->Print( "(edge_connector %s)",
817 m_EdgeConnectorConstraints > 1 ? "bevelled": "yes" );
818 }
819
821 KICAD_FORMAT::FormatBool( aFormatter, "castellated_pads", true );
822
823 if( m_EdgePlating )
824 KICAD_FORMAT::FormatBool( aFormatter, "edge_plating", true );
825
826 aFormatter->Print( ")" );
827}
828
829
830int BOARD_STACKUP::GetLayerDistance( PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer ) const
831{
832 wxASSERT( IsCopperLayer( aFirstLayer ) && IsCopperLayer( aSecondLayer ) );
833
834 if( aFirstLayer == aSecondLayer )
835 return 0;
836
837 // B_Cu is always the last copper layer but doesn't have the last numerical value
838 if( aSecondLayer != B_Cu && ( aSecondLayer < aFirstLayer || aFirstLayer == B_Cu ) )
839 std::swap( aFirstLayer, aSecondLayer );
840
841 int total = 0;
842 bool start = false;
843 bool half = false;
844
845 for( BOARD_STACKUP_ITEM* item : m_list )
846 {
847 // Will be UNDEFINED_LAYER for dielectrics
848 PCB_LAYER_ID layer = item->GetBrdLayerId();
849
850 if( layer != UNDEFINED_LAYER && !IsCopperLayer( layer ) )
851 continue; // Silk/mask layer
852
853 // Reached the start copper layer? Start counting the next dielectric after it
854 if( !start && ( layer != UNDEFINED_LAYER && layer == aFirstLayer ) )
855 {
856 start = true;
857 half = true;
858 }
859 else if( !start )
860 continue;
861
862 // Reached the stop copper layer? we're done
863 if( start && ( layer != UNDEFINED_LAYER && layer == aSecondLayer ) )
864 half = true;
865
866 for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
867 {
868 int subThickness = item->GetThickness( sublayer );
869 total += half ? ( subThickness / 2 ) : subThickness;
870 }
871
872 half = false;
873
874 if( layer != UNDEFINED_LAYER && layer == aSecondLayer )
875 break;
876 }
877
878 return total;
879}
880
881
882bool IsPrmSpecified( const wxString& aPrmValue )
883{
884 // return true if the param value is specified:
885
886 if( !aPrmValue.IsEmpty()
887 && ( aPrmValue.CmpNoCase( NotSpecifiedPrm() ) != 0 )
888 && aPrmValue != wxGetTranslation( NotSpecifiedPrm() ) )
889 return true;
890
891 return false;
892}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_EDGE_CONNECTOR_NONE
Definition: board_stackup.h:57
BOARD_STACKUP_ITEM_TYPE
Definition: board_stackup.h:43
@ BS_ITEM_TYPE_UNDEFINED
Definition: board_stackup.h:44
@ BS_ITEM_TYPE_COPPER
Definition: board_stackup.h:45
@ BS_ITEM_TYPE_SILKSCREEN
Definition: board_stackup.h:51
@ BS_ITEM_TYPE_DIELECTRIC
Definition: board_stackup.h:46
@ BS_ITEM_TYPE_SOLDERPASTE
Definition: board_stackup.h:48
@ BS_ITEM_TYPE_SOLDERMASK
Definition: board_stackup.h:49
Container for design settings for a BOARD object.
LSET GetEnabledLayers() const
Return a bit-mask of all the layers that are enabled.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
BOARD_STACKUP & GetStackupDescriptor()
Manage one layer needed to make a physical board.
Definition: board_stackup.h:96
void AddDielectricPrms(int aDielectricPrmsIdx)
Add (insert) a DIELECTRIC_PRMS item to m_DielectricPrmsList all values are set to default.
PCB_LAYER_ID m_LayerId
type name of layer (copper, silk screen, core, prepreg ...)
int GetSublayersCount() const
void SetDielectricLayerId(int aLayerId)
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetColor(int aDielectricSubLayer=0) const
bool HasEpsilonRValue() const
void SetThickness(int aThickness, int aDielectricSubLayer=0)
bool IsMaterialEditable() const
BOARD_STACKUP_ITEM_TYPE m_Type
bool HasMaterialValue(int aDielectricSubLayer=0) const
void SetThicknessLocked(bool aLocked, int aDielectricSubLayer=0)
wxString FormatDielectricLayerName() const
void SetMaterial(const wxString &aName, int aDielectricSubLayer=0)
BOARD_STACKUP_ITEM(BOARD_STACKUP_ITEM_TYPE aType)
bool HasLossTangentValue() const
bool IsThicknessEditable() const
void SetLossTangent(double aTg, int aDielectricSubLayer=0)
int GetThickness(int aDielectricSubLayer=0) const
void SetEnabled(bool aEnable)
std::vector< DIELECTRIC_PRMS > m_DielectricPrmsList
the "layer" id for dielectric layers, from 1 (top) to 31 (bottom) (only 31 dielectric layers for 32 c...
static int GetMaskDefaultThickness()
wxString GetMaterial(int aDielectricSubLayer=0) const
wxString m_TypeName
name of layer as shown in layer manager. Useful to create reports
void SetBrdLayerId(PCB_LAYER_ID aBrdLayerId)
void SetTypeName(const wxString &aName)
bool IsThicknessLocked(int aDielectricSubLayer=0) const
wxString FormatEpsilonR(int aDielectricSubLayer=0) const
int m_DielectricLayerId
the layer id (F.Cu to B.Cu, F.Silk, B.silk, F.Mask, B.Mask) and UNDEFINED_LAYER (-1) for dielectric l...
void SetColor(const wxString &aColorName, int aDielectricSubLayer=0)
void SetEpsilonR(double aEpsilon, int aDielectricSubLayer=0)
void RemoveDielectricPrms(int aDielectricPrmsIdx)
Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList.
int GetDielectricLayerId() const
bool operator==(const BOARD_STACKUP_ITEM &aOther) const
bool IsColorEditable() const
wxString FormatLossTangent(int aDielectricSubLayer=0) const
double GetLossTangent(int aDielectricSubLayer=0) const
static int GetCopperDefaultThickness()
Manage layers needed to make a physical board.
void RemoveAll()
Delete all items in list and clear the list.
bool m_CastellatedPads
True if castellated pads exist.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
static LSET StackupAllowedBrdLayers()
int GetCount() const
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
bool operator==(const BOARD_STACKUP &aOther) const
int BuildBoardThicknessFromStackup() const
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
void Add(BOARD_STACKUP_ITEM *aItem)
Add a new item in stackup layer.
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
BOARD_STACKUP & operator=(const BOARD_STACKUP &aOther)
BOARD_STACKUP_ITEM * GetStackupLayer(int aIndex)
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.
std::vector< BOARD_STACKUP_ITEM * > m_list
bool m_EdgePlating
True if the edge board is plated.
BS_EDGE_CONNECTOR_CONSTRAINTS m_EdgeConnectorConstraints
If the board has edge connector cards, some constrains can be specified in job file: BS_EDGE_CONNECTO...
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard) const
Write the stackup info on board file.
bool m_HasThicknessConstrains
True if some layers (copper and/or dielectric) have specific thickness.
wxString m_FinishType
The name of external copper finish.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:295
A helper class to manage a dielectric layer set of parameters.
Definition: board_stackup.h:67
double m_EpsilonR
true for dielectric layers with a fixed thickness (for impedance controlled purposes),...
Definition: board_stackup.h:84
int m_Thickness
type of material (for dielectric and solder mask)
Definition: board_stackup.h:81
wxString m_Material
Definition: board_stackup.h:80
bool operator==(const DIELECTRIC_PRMS &aOther) const
wxString m_Color
For dielectric (and solder mask) the dielectric loss.
Definition: board_stackup.h:86
bool m_ThicknessLocked
the physical layer thickness in internal units
Definition: board_stackup.h:82
double m_LossTangent
For dielectric (and solder mask) the dielectric constant.
Definition: board_stackup.h:85
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:245
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:188
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:545
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:460
#define _HKI(x)
#define _(s)
Some functions to handle hotkeys in KiCad.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition: layer_ids.h:581
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_Paste
Definition: layer_ids.h:104
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ F_Mask
Definition: layer_ids.h:97
@ B_Paste
Definition: layer_ids.h:105
@ F_SilkS
Definition: layer_ids.h:100
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ B_SilkS
Definition: layer_ids.h:101
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:170
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
wxString NotSpecifiedPrm()
#define KEY_PREPREG
#define KEY_COPPER
#define KEY_CORE
#define DEFAULT_EPSILON_R_SILKSCREEN
#define DEFAULT_EPSILON_R_SOLDERMASK
std::string UIDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 We want to avoid scientific ...
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
constexpr int mmToIU(double mm) const
Definition: base_units.h:88