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 SetSpecFreq( 1e9 ); // for FR4
75 break;
76
78 m_TypeName = wxT( "solderpaste" );
79 break;
80
82 m_TypeName = wxT( "soldermask" );
84 SetMaterial( NotSpecifiedPrm() ); // or other solder mask material name
87 break;
88
90 m_TypeName = wxT( "silkscreen" );
92 SetMaterial( NotSpecifiedPrm() ); // or other silkscreen material name
94 break;
95
97 break;
98 }
99}
100
101
112
113
115{
116 if( m_Type != aOther.m_Type ) return false;
117 if( m_LayerName != aOther.m_LayerName ) return false;
118 if( m_TypeName != aOther.m_TypeName ) return false;
119 if( m_LayerId != aOther.m_LayerId ) return false;
120 if( m_DielectricLayerId != aOther.m_DielectricLayerId ) return false;
121 if( m_enabled != aOther.m_enabled ) return false;
122
123 if( !std::equal( std::begin( m_DielectricPrmsList ), std::end( m_DielectricPrmsList ),
124 std::begin( aOther.m_DielectricPrmsList ),
125 []( const DIELECTRIC_PRMS& aA, const DIELECTRIC_PRMS& aB )
126 {
127 return aA == aB;
128 } ) )
129 {
130 return false;
131 }
132
133 return true;
134}
135
136
137void BOARD_STACKUP_ITEM::AddDielectricPrms( int aDielectricPrmsIdx )
138{
139 // add a DIELECTRIC_PRMS item to m_DielectricPrmsList
140 DIELECTRIC_PRMS new_prms;
141
142 m_DielectricPrmsList.emplace( m_DielectricPrmsList.begin() + aDielectricPrmsIdx, new_prms );
143}
144
145
146void BOARD_STACKUP_ITEM::RemoveDielectricPrms( int aDielectricPrmsIdx )
147{
148 // Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList if possible
149
150 if( GetSublayersCount() < 2
151 || aDielectricPrmsIdx < 0
152 || aDielectricPrmsIdx >= GetSublayersCount() )
153 {
154 return;
155 }
156
157 m_DielectricPrmsList.erase( m_DielectricPrmsList.begin() + aDielectricPrmsIdx );
158}
159
160
161
163{
164 // A reasonable thickness for copper layers:
165 return pcbIUScale.mmToIU( 0.035 );
166}
167
168
170{
171 // A reasonable thickness for solder mask:
172 return pcbIUScale.mmToIU( 0.01 );
173}
174
175
176// Getters:
177wxString BOARD_STACKUP_ITEM::GetColor( int aDielectricSubLayer ) const
178{
179 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
180
181 return m_DielectricPrmsList[aDielectricSubLayer].m_Color;
182}
183
184int BOARD_STACKUP_ITEM::GetThickness( int aDielectricSubLayer ) const
185{
186 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
187
188 return m_DielectricPrmsList[aDielectricSubLayer].m_Thickness;
189}
190
191
192double BOARD_STACKUP_ITEM::GetLossTangent( int aDielectricSubLayer ) const
193{
194 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
195
196 return m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent;
197}
198
199
200double BOARD_STACKUP_ITEM::GetSpecFreq( int aDielectricSubLayer ) const
201{
202 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
203
204 return m_DielectricPrmsList[aDielectricSubLayer].m_SpecFreq;
205}
206
207
209{
210 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
211
212 return m_DielectricPrmsList[aDielectricSubLayer].m_DielectricModel;
213}
214
215
216double BOARD_STACKUP_ITEM::GetEpsilonR( int aDielectricSubLayer ) const
217{
218 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
219
220 return m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR;
221}
222
223
224bool BOARD_STACKUP_ITEM::IsThicknessLocked( int aDielectricSubLayer ) const
225{
226 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
227
228 return m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked;
229}
230
231
232wxString BOARD_STACKUP_ITEM::GetMaterial( int aDielectricSubLayer ) const
233{
234 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
235
236 return m_DielectricPrmsList[aDielectricSubLayer].m_Material;
237}
238
239
240// Setters:
241void BOARD_STACKUP_ITEM::SetColor( const wxString& aColorName , int aDielectricSubLayer )
242{
243 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
244
245 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
246 m_DielectricPrmsList[aDielectricSubLayer].m_Color = aColorName;
247}
248
249
250void BOARD_STACKUP_ITEM::SetThickness( int aThickness, int aDielectricSubLayer )
251{
252 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
253
254 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
255 m_DielectricPrmsList[aDielectricSubLayer].m_Thickness = aThickness;
256}
257
258
259void BOARD_STACKUP_ITEM::SetLossTangent( double aTg, int aDielectricSubLayer )
260{
261 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
262
263 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
264 m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent = aTg;
265}
266
267
268void BOARD_STACKUP_ITEM::SetSpecFreq( const double aSpecFreq, const int aDielectricSubLayer )
269{
270 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
271
272 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
273 m_DielectricPrmsList[aDielectricSubLayer].m_SpecFreq = aSpecFreq;
274}
275
276
277void BOARD_STACKUP_ITEM::SetDielectricModel( DIELECTRIC_MODEL aModel, int aDielectricSubLayer )
278{
279 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
280
281 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
282 m_DielectricPrmsList[aDielectricSubLayer].m_DielectricModel = aModel;
283}
284
285
286void BOARD_STACKUP_ITEM::SetEpsilonR( double aEpsilon, int aDielectricSubLayer )
287{
288 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
289
290 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
291 m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR = aEpsilon;
292}
293
294
295void BOARD_STACKUP_ITEM::SetThicknessLocked( bool aLocked, int aDielectricSubLayer )
296{
297 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
298
299 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
300 m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked = aLocked;
301}
302
303
304void BOARD_STACKUP_ITEM::SetMaterial( const wxString& aName, int aDielectricSubLayer )
305{
306 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
307
308 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
309 m_DielectricPrmsList[aDielectricSubLayer].m_Material = aName;
310}
311
312
318
319
325
326
331
332
333bool BOARD_STACKUP_ITEM::HasMaterialValue( int aDielectricSubLayer ) const
334{
335 // return true if the material is specified
336 return IsMaterialEditable() && IsPrmSpecified( GetMaterial( aDielectricSubLayer ) );
337}
338
339
346
347
354
355
362
363
364wxString BOARD_STACKUP_ITEM::FormatEpsilonR( int aDielectricSubLayer ) const
365{
366 // return a wxString to print/display Epsilon R
367 // note: we do not want scientific notation
368 wxString txt = UIDouble2Str( GetEpsilonR( aDielectricSubLayer ) );
369 return txt;
370}
371
372
373wxString BOARD_STACKUP_ITEM::FormatLossTangent( int aDielectricSubLayer ) const
374{
375 // return a wxString to print/display Loss Tangent
376 // note: we do not want scientific notation
377 wxString txt = UIDouble2Str( GetLossTangent( aDielectricSubLayer ) );
378 return txt;
379}
380
381
383{
384 // return a wxString to print/display a dielectric name
385 wxString lname;
386 lname.Printf( _( "Dielectric %d" ), GetDielectricLayerId() );
387
388 return lname;
389}
390
391
393{
394 m_HasDielectricConstrains = false; // True if some dielectric layers have constrains
395 // (Loss tg and Epison R)
396 m_HasThicknessConstrains = false; // True if some dielectric or copper layers have constrains
398 m_EdgePlating = false; // True if edge board is plated
399 m_FinishType = wxT( "None" ); // undefined finish type
400}
401
402
404{
409 m_FinishType = aOther.m_FinishType;
410
411 // All items in aOther.m_list have to be duplicated, because aOther.m_list
412 // manage pointers to these items
413 for( BOARD_STACKUP_ITEM* item : aOther.m_list )
414 {
415 BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
416 Add( dup_item );
417 }
418}
419
420
422{
427 m_FinishType = aOther.m_FinishType;
428
429 RemoveAll();
430
431 // All items in aOther.m_list have to be duplicated, because aOther.m_list
432 // manage pointers to these items
433 for( BOARD_STACKUP_ITEM* item : aOther.m_list )
434 {
435 BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
436 Add( dup_item );
437 }
438
439 return *this;
440}
441
442
443bool BOARD_STACKUP::operator==( const BOARD_STACKUP& aOther ) const
444{
445 if( m_HasDielectricConstrains != aOther.m_HasDielectricConstrains ) return false;
446 if( m_HasThicknessConstrains != aOther.m_HasThicknessConstrains ) return false;
447 if( m_EdgeConnectorConstraints != aOther.m_EdgeConnectorConstraints ) return false;
448 if( m_EdgePlating != aOther.m_EdgePlating ) return false;
449 if( m_FinishType != aOther.m_FinishType ) return false;
450
451 if( !std::equal( std::begin( m_list ), std::end( m_list ), std::begin( aOther.m_list ),
452 []( const BOARD_STACKUP_ITEM* aA, const BOARD_STACKUP_ITEM* aB )
453 {
454 return *aA == *aB;
455 } ) )
456 {
457 return false;
458 }
459
460 return true;
461}
462
463
464void BOARD_STACKUP::Serialize( google::protobuf::Any& aContainer ) const
465{
466 using namespace kiapi::board;
467 BoardStackup stackup;
468
469 for( const BOARD_STACKUP_ITEM* item : m_list )
470 {
471 BoardStackupLayer* layer = stackup.mutable_layers()->Add();
472
473 layer->mutable_thickness()->set_value_nm( item->GetThickness() );
474 layer->set_layer( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( item->GetBrdLayerId() ) );
475 layer->set_type(
477
478 switch( item->GetType() )
479 {
481 {
482 layer->set_material_name( "copper" );
483 // (no copper params yet...)
484 break;
485 }
486
488 {
489 BoardStackupDielectricLayer* dielectric = layer->mutable_dielectric()->New();
490
491 for( int i = 0; i < item->GetSublayersCount(); ++i )
492 {
493 BoardStackupDielectricProperties* props = dielectric->mutable_layer()->Add();
494 props->set_epsilon_r( item->GetEpsilonR( i ) );
495 props->set_loss_tangent( item->GetLossTangent( i ) );
496 props->set_material_name( item->GetMaterial( i ).ToUTF8() );
497 props->mutable_thickness()->set_value_nm( item->GetThickness( i ) );
498 }
499
500 break;
501 }
502
503 default:
504 break;
505 }
506 }
507
508 aContainer.PackFrom( stackup );
509}
510
511
512bool BOARD_STACKUP::Deserialize( const google::protobuf::Any& aContainer )
513{
514 // Read-only for now
515 return false;
516}
517
518
520{
521 for( BOARD_STACKUP_ITEM* item : m_list )
522 delete item;
523
524 m_list.clear();
525}
526
527
529{
530 if( aIndex < 0 || aIndex >= GetCount() )
531 return nullptr;
532
533 return GetList()[aIndex];
534}
535
536
538{
539 // return the board thickness from the thickness of BOARD_STACKUP_ITEM list
540 int thickness = 0;
541
542 for( BOARD_STACKUP_ITEM* item : m_list )
543 {
544 if( item->IsThicknessEditable() && item->IsEnabled() )
545 {
546 thickness += item->GetThickness();
547
548 // dielectric layers can have more than one main layer
549 // add thickness of all sublayers
550 for( int idx = 1; idx < item->GetSublayersCount(); idx++ )
551 {
552 thickness += item->GetThickness( idx );
553 }
554 }
555 }
556
557 return thickness;
558}
559
560
562{
563 bool change = false;
564 // Build the suitable stackup:
565 BOARD_STACKUP stackup;
566 stackup.BuildDefaultStackupList( aSettings );
567
568 // First, find removed layers:
569 for( BOARD_STACKUP_ITEM* curr_item: m_list )
570 {
571 bool found = false;
572
573 for( BOARD_STACKUP_ITEM* item: stackup.GetList() )
574 {
575 if( curr_item->GetBrdLayerId() != UNDEFINED_LAYER )
576 {
577 if( item->GetBrdLayerId() == curr_item->GetBrdLayerId() )
578 {
579 found = true;
580 break;
581 }
582 }
583 else // curr_item = dielectric layer
584 {
585 if( item->GetBrdLayerId() != UNDEFINED_LAYER )
586 continue;
587
588 if( item->GetDielectricLayerId() == curr_item->GetDielectricLayerId() )
589 {
590 found = true;
591 break;
592 }
593 }
594 }
595
596 if( !found ) // a layer was removed: a change is found
597 {
598 change = true;
599 break;
600 }
601 }
602
603 // Now initialize all stackup items to the initial values, when exist
604 for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
605 {
606 bool found = false;
607 // Search for initial settings:
608 for( const BOARD_STACKUP_ITEM* initial_item : m_list )
609 {
610 if( item->GetBrdLayerId() != UNDEFINED_LAYER )
611 {
612 if( item->GetBrdLayerId() == initial_item->GetBrdLayerId() )
613 {
614 *item = *initial_item;
615 found = true;
616 break;
617 }
618 }
619 else // dielectric layer: see m_DielectricLayerId for identification
620 {
621 // Compare dielectric layer with dielectric layer
622 if( initial_item->GetBrdLayerId() != UNDEFINED_LAYER )
623 continue;
624
625 if( item->GetDielectricLayerId() == initial_item->GetDielectricLayerId() )
626 {
627 *item = *initial_item;
628 found = true;
629 break;
630 }
631 }
632 }
633
634 if( !found )
635 {
636 change = true;
637 }
638 }
639
640 // Transfer layer settings:
641 *this = stackup;
642
643 // Transfer other stackup settings from aSettings
644 const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
647 m_EdgePlating = source_stackup.m_EdgePlating;
648 m_FinishType = source_stackup.m_FinishType;
649
650 return change;
651}
652
653
655 int aActiveCopperLayersCount )
656{
657 // Creates a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
658 // Note: the m_TypeName string is made translatable using _HKI marker, but is not
659 // translated when building the stackup.
660 // It will be used as this in files, and can be translated only in dialog
661 // if aSettings == NULL, build a full stackup (with 32 copper layers)
662 LSET enabledLayer = aSettings ? aSettings->GetEnabledLayers() : StackupAllowedBrdLayers();
663 int copperLayerCount = aSettings ? aSettings->GetCopperLayerCount() : 32;
664
665 // We need to calculate a suitable dielectric layer thickness.
666 // If no settings, and if aActiveCopperLayersCount is given, use it
667 // (If no settings, and no aActiveCopperLayersCount, the full 32 layers are used)
668 int activeCuLayerCount = copperLayerCount;
669
670 if( aSettings == nullptr && aActiveCopperLayersCount > 0 )
671 activeCuLayerCount = aActiveCopperLayersCount;
672
673 int brd__thickness = aSettings ? aSettings->GetBoardThickness() : pcbIUScale.mmToIU( 1.6 );
674 int diel_thickness = brd__thickness -
675 ( BOARD_STACKUP_ITEM::GetCopperDefaultThickness() * activeCuLayerCount );
676
677 // Take in account the solder mask thickness:
678 int sm_count = ( enabledLayer & LSET( { F_Mask, B_Mask } ) ).count();
679 diel_thickness -= BOARD_STACKUP_ITEM::GetMaskDefaultThickness() * sm_count;
680 diel_thickness /= std::max( 1, activeCuLayerCount - 1 );
681
682 int dielectric_idx = 0;
683
684 // Add silk screen, solder mask and solder paste layers on top
685 if( enabledLayer[F_SilkS] )
686 {
688 item->SetBrdLayerId( F_SilkS );
689 item->SetTypeName( _HKI( "Top Silk Screen" ) );
690 Add( item );
691 }
692
693 if( enabledLayer[F_Paste] )
694 {
696 item->SetBrdLayerId( F_Paste );
697 item->SetTypeName( _HKI( "Top Solder Paste" ) );
698 Add( item );
699 }
700
701 if( enabledLayer[F_Mask] )
702 {
704 item->SetBrdLayerId( F_Mask );
705 item->SetTypeName( _HKI( "Top Solder Mask" ) );
706 Add( item );
707 }
708
709 // Add copper and dielectric layers
710 for( PCB_LAYER_ID layer : enabledLayer.CuStack() )
711 {
713 item->SetBrdLayerId( layer );
714 item->SetTypeName( KEY_COPPER );
715 Add( item );
716
717 if( layer == B_Cu )
718 break;
719
720 // Add the dielectric layer:
722 item->SetThickness( diel_thickness );
723 item->SetDielectricLayerId( dielectric_idx + 1 );
724
725 // Display a dielectric default layer name:
726 if( (dielectric_idx & 1) == 0 )
727 {
728 item->SetTypeName( KEY_CORE );
729 item->SetMaterial( wxT( "FR4" ) );
730 }
731 else
732 {
733 item->SetTypeName( KEY_PREPREG );
734 item->SetMaterial( wxT( "FR4" ) );
735 }
736
737 Add( item );
738 dielectric_idx++;
739 }
740
741 // Add silk screen, solder mask and solder paste layers on bottom
742 if( enabledLayer[B_Mask] )
743 {
745 item->SetBrdLayerId( B_Mask );
746 item->SetTypeName( _HKI( "Bottom Solder Mask" ) );
747 Add( item );
748 }
749
750 if( enabledLayer[B_Paste] )
751 {
753 item->SetBrdLayerId( B_Paste );
754 item->SetTypeName( _HKI( "Bottom Solder Paste" ) );
755 Add( item );
756 }
757
758 if( enabledLayer[B_SilkS] )
759 {
761 item->SetBrdLayerId( B_SilkS );
762 item->SetTypeName( _HKI( "Bottom Silk Screen" ) );
763 Add( item );
764 }
765
766 // Transfer other stackup settings from aSettings
767 if( aSettings )
768 {
769 const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
772 m_EdgePlating = source_stackup.m_EdgePlating;
773 m_FinishType = source_stackup.m_FinishType;
774 }
775}
776
777
778void BOARD_STACKUP::FormatBoardStackup( OUTPUTFORMATTER* aFormatter, const BOARD* aBoard ) const
779{
780 // Board stackup is the ordered list from top to bottom of
781 // physical layers and substrate used to build the board.
782 if( m_list.empty() )
783 return;
784
785 aFormatter->Print( "(stackup" );
786
787 // Note:
788 // Unspecified parameters are not stored in file.
789 for( BOARD_STACKUP_ITEM* item: m_list )
790 {
791 wxString layer_name;
792
793 if( item->GetBrdLayerId() == UNDEFINED_LAYER )
794 layer_name.Printf( wxT( "dielectric %d" ), item->GetDielectricLayerId() );
795 else
796 layer_name = LSET::Name( item->GetBrdLayerId() );
797
798 aFormatter->Print( "(layer %s (type %s)",
799 aFormatter->Quotew( layer_name ).c_str(),
800 aFormatter->Quotew( item->GetTypeName() ).c_str() );
801
802 // Output other parameters (in sub layer list there is at least one item)
803 for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
804 {
805 if( idx ) // not for the main (first) layer.
806 aFormatter->Print( " addsublayer" );
807
808 if( item->IsColorEditable() && IsPrmSpecified( item->GetColor( idx ) ) )
809 {
810 aFormatter->Print( "(color %s)",
811 aFormatter->Quotew( item->GetColor( idx ) ).c_str() );
812 }
813
814 if( item->IsThicknessEditable() )
815 {
816 aFormatter->Print( "(thickness %s",
817 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, item->GetThickness( idx ) ).c_str() );
818
819 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC && item->IsThicknessLocked( idx ) )
820 aFormatter->Print( " locked" );
821
822 aFormatter->Print( ")" );
823 }
824
825 if( item->HasMaterialValue( idx ) )
826 {
827 aFormatter->Print( "(material %s)",
828 aFormatter->Quotew( item->GetMaterial( idx ) ).c_str() );
829 }
830
831 if( item->HasEpsilonRValue() && item->HasMaterialValue( idx ) )
832 aFormatter->Print( "(epsilon_r %s)", FormatDouble2Str( item->GetEpsilonR( idx ) ).c_str() );
833
834 if( item->HasLossTangentValue() && item->HasMaterialValue( idx ) )
835 {
836 aFormatter->Print( "(loss_tangent %s)",
837 FormatDouble2Str( item->GetLossTangent( idx ) ).c_str() );
838 }
839
840 if( item->HasSpecFreqValue() && item->HasMaterialValue( idx ) )
841 {
842 aFormatter->Print( "(spec_frequency %s)", FormatDouble2Str( item->GetSpecFreq( idx ) ).c_str() );
843
844 wxString modelToken = wxT( "constant" );
845
846 if( item->GetDielectricModel( idx ) == DIELECTRIC_MODEL::DJORDJEVIC_SARKAR )
847 modelToken = wxT( "djordjevic_sarkar" );
848
849 aFormatter->Print( "(dielectric_model %s)", modelToken.ToStdString().c_str() );
850 }
851 }
852
853 aFormatter->Print( ")" );
854 }
855
856 // Other infos about board, related to layers and other fabrication specifications
858 aFormatter->Print( "(copper_finish %s)", aFormatter->Quotew( m_FinishType ).c_str() );
859
860 KICAD_FORMAT::FormatBool( aFormatter, "dielectric_constraints", m_HasDielectricConstrains );
861
863 {
864 aFormatter->Print( "(edge_connector %s)",
865 m_EdgeConnectorConstraints > 1 ? "bevelled": "yes" );
866 }
867
868 if( m_EdgePlating )
869 KICAD_FORMAT::FormatBool( aFormatter, "edge_plating", true );
870
871 aFormatter->Print( ")" );
872}
873
874
875int BOARD_STACKUP::GetLayerDistance( PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer ) const
876{
877 wxASSERT( IsCopperLayer( aFirstLayer ) && IsCopperLayer( aSecondLayer ) );
878
879 if( aFirstLayer == aSecondLayer )
880 return 0;
881
882 // B_Cu is always the last copper layer but doesn't have the last numerical value
883 if( aSecondLayer != B_Cu && ( aSecondLayer < aFirstLayer || aFirstLayer == B_Cu ) )
884 std::swap( aFirstLayer, aSecondLayer );
885
886 int total = 0;
887 bool start = false;
888 bool half = false;
889
890 for( const BOARD_STACKUP_ITEM* item : m_list )
891 {
892 // Will be UNDEFINED_LAYER for dielectrics
893 const PCB_LAYER_ID layer = item->GetBrdLayerId();
894
895 if( layer != UNDEFINED_LAYER && !IsCopperLayer( layer ) )
896 continue; // Silk/mask layer
897
898 // Reached the start copper layer? Start counting the next dielectric after it
899 if( !start && ( layer != UNDEFINED_LAYER && layer == aFirstLayer ) )
900 {
901 start = true;
902
903 // Only count half of each internal copper layer
904 if( aFirstLayer != F_Cu && aFirstLayer != B_Cu )
905 half = true;
906 }
907 else if( !start )
908 continue;
909
910 // Reached the stop copper layer? we're done
911 if( start && ( layer != UNDEFINED_LAYER && layer == aSecondLayer ) )
912 {
913 // Only count half of each internal copper layer
914 if( aSecondLayer != F_Cu && aSecondLayer != B_Cu )
915 half = true;
916 }
917
918 for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
919 {
920 const int subThickness = item->GetThickness( sublayer );
921 total += half ? ( subThickness / 2 ) : subThickness;
922 }
923
924 half = false;
925
926 if( layer != UNDEFINED_LAYER && layer == aSecondLayer )
927 break;
928 }
929
930 return total;
931}
932
933
934bool IsPrmSpecified( const wxString& aPrmValue )
935{
936 // return true if the param value is specified:
937
938 if( !aPrmValue.IsEmpty()
939 && ( aPrmValue.CmpNoCase( NotSpecifiedPrm() ) != 0 )
940 && aPrmValue != wxGetTranslation( NotSpecifiedPrm() ) )
941 return true;
942
943 return false;
944}
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:125
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_EDGE_CONNECTOR_NONE
BOARD_STACKUP_ITEM_TYPE
@ BS_ITEM_TYPE_UNDEFINED
@ BS_ITEM_TYPE_COPPER
@ BS_ITEM_TYPE_SILKSCREEN
@ BS_ITEM_TYPE_DIELECTRIC
@ BS_ITEM_TYPE_SOLDERPASTE
@ BS_ITEM_TYPE_SOLDERMASK
Container for design settings for a BOARD object.
const 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.
void AddDielectricPrms(int aDielectricPrmsIdx)
Add (insert) a DIELECTRIC_PRMS item to m_DielectricPrmsList all values are set to default.
DIELECTRIC_MODEL GetDielectricModel(int aDielectricSubLayer=0) const
PCB_LAYER_ID m_LayerId
type name of layer (copper, silk screen, core, prepreg ...)
int GetSublayersCount() const
void SetDielectricLayerId(int aLayerId)
bool HasSpecFreqValue() const
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
void SetDielectricModel(DIELECTRIC_MODEL aModel, int aDielectricSubLayer=0)
bool HasMaterialValue(int aDielectricSubLayer=0) const
void SetThicknessLocked(bool aLocked, int aDielectricSubLayer=0)
wxString FormatDielectricLayerName() const
void SetSpecFreq(double aSpecFreq, int aDielectricSubLayer=0)
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)
double GetSpecFreq(int aDielectricSubLayer=0) const
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()
void RemoveAll()
Delete all items in list and clear the list.
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:323
A helper class to manage a dielectric layer set of parameters.
double m_EpsilonR
true for dielectric layers with a fixed thickness (for impedance controlled purposes),...
int m_Thickness
type of material (for dielectric and solder mask)
wxString m_Material
bool operator==(const DIELECTRIC_PRMS &aOther) const
wxString m_Color
For dielectric the dielectric frequency correction model.
bool m_ThicknessLocked
the physical layer thickness in internal units
double m_LossTangent
For dielectric (and solder mask) the dielectric constant.
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:263
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:295
std::string Quotew(const wxString &aWrapee) const
Definition richio.cpp:511
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition richio.cpp:426
#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:679
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
@ F_Cu
Definition layer_ids.h:64
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
#define _HKI(x)
Definition page_info.cpp:44
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...
DIELECTRIC_MODEL
Frequency-domain model used for the substrate dielectric properties.