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 (C) 2009-2021 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
30#include <google/protobuf/any.pb.h>
31#include <api/board/board.pb.h>
32#include <api/api_enums.h>
33
34
36{
37 if( m_Material != aOther.m_Material ) return false;
38 if( m_Thickness != aOther.m_Thickness ) return false;
39 if( m_ThicknessLocked != aOther.m_ThicknessLocked ) return false;
40 if( m_EpsilonR != aOther.m_EpsilonR ) return false;
41 if( m_LossTangent != aOther.m_LossTangent ) return false;
42 if( m_Color != aOther.m_Color ) return false;
43
44 return true;
45}
46
47
49{
50 DIELECTRIC_PRMS item_prms;
51 m_DielectricPrmsList.emplace_back( item_prms );
53 m_Type = aType;
55 SetEnabled( true );
56
57 // Initialize parameters to a usual value for allowed types:
58 switch( m_Type )
59 {
63 break;
64
66 m_TypeName = KEY_CORE; // or prepreg
68 SetMaterial( wxT( "FR4" ) ); // or other dielectric name
69 SetLossTangent( 0.02 ); // for FR4
70 SetEpsilonR( 4.5 ); // for FR4
71 break;
72
74 m_TypeName = wxT( "solderpaste" );
75 break;
76
78 m_TypeName = wxT( "soldermask" );
80 SetMaterial( NotSpecifiedPrm() ); // or other solder mask material name
83 break;
84
86 m_TypeName = wxT( "silkscreen" );
88 SetMaterial( NotSpecifiedPrm() ); // or other silkscreen material name
90 break;
91
93 break;
94 }
95}
96
97
99{
100 m_LayerId = aOther.m_LayerId;
102 m_Type = aOther.m_Type;
103 m_enabled = aOther.m_enabled;
105 m_TypeName = aOther.m_TypeName;
106 m_LayerName = aOther.m_LayerName;
107}
108
109
111{
112 if( m_Type != aOther.m_Type ) return false;
113 if( m_LayerName != aOther.m_LayerName ) return false;
114 if( m_TypeName != aOther.m_TypeName ) return false;
115 if( m_LayerId != aOther.m_LayerId ) return false;
116 if( m_DielectricLayerId != aOther.m_DielectricLayerId ) return false;
117 if( m_enabled != aOther.m_enabled ) return false;
118
119 if( !std::equal( std::begin( m_DielectricPrmsList ), std::end( m_DielectricPrmsList ),
120 std::begin( aOther.m_DielectricPrmsList ),
121 []( const DIELECTRIC_PRMS& aA, const DIELECTRIC_PRMS& aB )
122 {
123 return aA == aB;
124 } ) )
125 {
126 return false;
127 }
128
129 return true;
130}
131
132
133void BOARD_STACKUP_ITEM::AddDielectricPrms( int aDielectricPrmsIdx )
134{
135 // add a DIELECTRIC_PRMS item to m_DielectricPrmsList
136 DIELECTRIC_PRMS new_prms;
137
138 m_DielectricPrmsList.emplace( m_DielectricPrmsList.begin() + aDielectricPrmsIdx, new_prms );
139}
140
141
142void BOARD_STACKUP_ITEM::RemoveDielectricPrms( int aDielectricPrmsIdx )
143{
144 // Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList if possible
145
146 if( GetSublayersCount() < 2
147 || aDielectricPrmsIdx < 0
148 || aDielectricPrmsIdx >= GetSublayersCount() )
149 {
150 return;
151 }
152
153 m_DielectricPrmsList.erase( m_DielectricPrmsList.begin() + aDielectricPrmsIdx );
154}
155
156
157
159{
160 // A reasonable thickness for copper layers:
161 return pcbIUScale.mmToIU( 0.035 );
162}
163
164
166{
167 // A reasonable thickness for solder mask:
168 return pcbIUScale.mmToIU( 0.01 );
169}
170
171
172// Getters:
173wxString BOARD_STACKUP_ITEM::GetColor( int aDielectricSubLayer ) const
174{
175 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
176
177 return m_DielectricPrmsList[aDielectricSubLayer].m_Color;
178}
179
180int BOARD_STACKUP_ITEM::GetThickness( int aDielectricSubLayer ) const
181{
182 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
183
184 return m_DielectricPrmsList[aDielectricSubLayer].m_Thickness;
185}
186
187
188double BOARD_STACKUP_ITEM::GetLossTangent( int aDielectricSubLayer ) const
189{
190 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
191
192 return m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent;
193}
194
195
196double BOARD_STACKUP_ITEM::GetEpsilonR( int aDielectricSubLayer ) const
197{
198 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
199
200 return m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR;
201}
202
203
204bool BOARD_STACKUP_ITEM::IsThicknessLocked( int aDielectricSubLayer ) const
205{
206 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
207
208 return m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked;
209}
210
211
212wxString BOARD_STACKUP_ITEM::GetMaterial( int aDielectricSubLayer ) const
213{
214 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
215
216 return m_DielectricPrmsList[aDielectricSubLayer].m_Material;
217}
218
219
220// Setters:
221void BOARD_STACKUP_ITEM::SetColor( const wxString& aColorName , int aDielectricSubLayer )
222{
223 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
224
225 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
226 m_DielectricPrmsList[aDielectricSubLayer].m_Color = aColorName;
227}
228
229
230void BOARD_STACKUP_ITEM::SetThickness( int aThickness, int aDielectricSubLayer )
231{
232 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
233
234 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
235 m_DielectricPrmsList[aDielectricSubLayer].m_Thickness = aThickness;
236}
237
238
239void BOARD_STACKUP_ITEM::SetLossTangent( double aTg, int aDielectricSubLayer )
240{
241 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
242
243 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
244 m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent = aTg;
245}
246
247
248void BOARD_STACKUP_ITEM::SetEpsilonR( double aEpsilon, int aDielectricSubLayer )
249{
250 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
251
252 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
253 m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR = aEpsilon;
254}
255
256
257void BOARD_STACKUP_ITEM::SetThicknessLocked( bool aLocked, int aDielectricSubLayer )
258{
259 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
260
261 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
262 m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked = aLocked;
263}
264
265
266void BOARD_STACKUP_ITEM::SetMaterial( const wxString& aName, int aDielectricSubLayer )
267{
268 wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
269
270 if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
271 m_DielectricPrmsList[aDielectricSubLayer].m_Material = aName;
272}
273
274
276{
279};
280
281
283{
286};
287
288
289bool BOARD_STACKUP_ITEM::HasMaterialValue( int aDielectricSubLayer ) const
290{
291 // return true if the material is specified
292 return IsMaterialEditable() && IsPrmSpecified( GetMaterial( aDielectricSubLayer ) );
293}
294
295
297{
301}
302
303
305{
309}
310
311
313{
317}
318
319
320wxString BOARD_STACKUP_ITEM::FormatEpsilonR( int aDielectricSubLayer ) const
321{
322 // return a wxString to print/display Epsilon R
323 // note: we do not want scientific notation
324 wxString txt = UIDouble2Str( GetEpsilonR( aDielectricSubLayer ) );
325 return txt;
326}
327
328
329wxString BOARD_STACKUP_ITEM::FormatLossTangent( int aDielectricSubLayer ) const
330{
331 // return a wxString to print/display Loss Tangent
332 // note: we do not want scientific notation
333 wxString txt = UIDouble2Str( GetLossTangent( aDielectricSubLayer ) );
334 return txt;
335}
336
337
339{
340 // return a wxString to print/display a dielectric name
341 wxString lname;
342 lname.Printf( _( "Dielectric %d" ), GetDielectricLayerId() );
343
344 return lname;
345}
346
347
349{
350 m_HasDielectricConstrains = false; // True if some dielectric layers have constrains
351 // (Loss tg and Epison R)
352 m_HasThicknessConstrains = false; // True if some dielectric or copper layers have constrains
354 m_CastellatedPads = false; // True if some castellated pads exist
355 m_EdgePlating = false; // True if edge board is plated
356 m_FinishType = wxT( "None" ); // undefined finish type
357}
358
359
361{
367 m_FinishType = aOther.m_FinishType;
368
369 // All items in aOther.m_list have to be duplicated, because aOther.m_list
370 // manage pointers to these items
371 for( BOARD_STACKUP_ITEM* item : aOther.m_list )
372 {
373 BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
374 Add( dup_item );
375 }
376}
377
378
380{
386 m_FinishType = aOther.m_FinishType;
387
388 RemoveAll();
389
390 // All items in aOther.m_list have to be duplicated, because aOther.m_list
391 // manage pointers to these items
392 for( BOARD_STACKUP_ITEM* item : aOther.m_list )
393 {
394 BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
395 Add( dup_item );
396 }
397
398 return *this;
399}
400
401
402bool BOARD_STACKUP::operator==( const BOARD_STACKUP& aOther ) const
403{
404 if( m_HasDielectricConstrains != aOther.m_HasDielectricConstrains ) return false;
405 if( m_HasThicknessConstrains != aOther.m_HasThicknessConstrains ) return false;
406 if( m_EdgeConnectorConstraints != aOther.m_EdgeConnectorConstraints ) return false;
407 if( m_CastellatedPads != aOther.m_CastellatedPads ) return false;
408 if( m_EdgePlating != aOther.m_EdgePlating ) return false;
409 if( m_FinishType != aOther.m_FinishType ) return false;
410
411 if( !std::equal( std::begin( m_list ), std::end( m_list ), std::begin( aOther.m_list ),
412 []( const BOARD_STACKUP_ITEM* aA, const BOARD_STACKUP_ITEM* aB )
413 {
414 return *aA == *aB;
415 } ) )
416 {
417 return false;
418 }
419
420 return true;
421}
422
423
424void BOARD_STACKUP::Serialize( google::protobuf::Any& aContainer ) const
425{
426 kiapi::board::BoardStackup stackup;
427
428 for( const BOARD_STACKUP_ITEM* item : m_list )
429 {
430 kiapi::board::BoardStackupLayer* layer = stackup.mutable_layers()->Add();
431
432 // TODO dielectric sub-layers
433 layer->mutable_thickness()->set_value_nm( item->GetThickness() );
434 layer->set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>(
435 item->GetBrdLayerId() ) );
436
437 switch( item->GetType() )
438 {
439 case BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_COPPER:
440 {
441 layer->mutable_copper()->New();
442 // (no copper params yet...)
443 break;
444 }
445
446 default:
447 // TODO
448 break;
449 }
450 }
451
452 aContainer.PackFrom( stackup );
453}
454
455
456bool BOARD_STACKUP::Deserialize( const google::protobuf::Any& aContainer )
457{
458 return true;
459}
460
461
463{
464 for( BOARD_STACKUP_ITEM* item : m_list )
465 delete item;
466
467 m_list.clear();
468}
469
470
472{
473 if( aIndex < 0 || aIndex >= GetCount() )
474 return nullptr;
475
476 return GetList()[aIndex];
477}
478
479
481{
482 // return the board thickness from the thickness of BOARD_STACKUP_ITEM list
483 int thickness = 0;
484
485 for( BOARD_STACKUP_ITEM* item : m_list )
486 {
487 if( item->IsThicknessEditable() && item->IsEnabled() )
488 {
489 thickness += item->GetThickness();
490
491 // dielectric layers can have more than one main layer
492 // add thickness of all sublayers
493 for( int idx = 1; idx < item->GetSublayersCount(); idx++ )
494 {
495 thickness += item->GetThickness( idx );
496 }
497 }
498 }
499
500 return thickness;
501}
502
503
505{
506 bool change = false;
507 // Build the suitable stackup:
508 BOARD_STACKUP stackup;
509 stackup.BuildDefaultStackupList( aSettings );
510
511 // First, find removed layers:
512 for( BOARD_STACKUP_ITEM* curr_item: m_list )
513 {
514 bool found = false;
515
516 for( BOARD_STACKUP_ITEM* item: stackup.GetList() )
517 {
518 if( curr_item->GetBrdLayerId() != UNDEFINED_LAYER )
519 {
520 if( item->GetBrdLayerId() == curr_item->GetBrdLayerId() )
521 {
522 found = true;
523 break;
524 }
525 }
526 else // curr_item = dielectric layer
527 {
528 if( item->GetBrdLayerId() != UNDEFINED_LAYER )
529 continue;
530
531 if( item->GetDielectricLayerId() == curr_item->GetDielectricLayerId() )
532 {
533 found = true;
534 break;
535 }
536 }
537 }
538
539 if( !found ) // a layer was removed: a change is found
540 {
541 change = true;
542 break;
543 }
544 }
545
546 // Now initialize all stackup items to the initial values, when exist
547 for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
548 {
549 bool found = false;
550 // Search for initial settings:
551 for( const BOARD_STACKUP_ITEM* initial_item : m_list )
552 {
553 if( item->GetBrdLayerId() != UNDEFINED_LAYER )
554 {
555 if( item->GetBrdLayerId() == initial_item->GetBrdLayerId() )
556 {
557 *item = *initial_item;
558 found = true;
559 break;
560 }
561 }
562 else // dielectric layer: see m_DielectricLayerId for identification
563 {
564 // Compare dielectric layer with dielectric layer
565 if( initial_item->GetBrdLayerId() != UNDEFINED_LAYER )
566 continue;
567
568 if( item->GetDielectricLayerId() == initial_item->GetDielectricLayerId() )
569 {
570 *item = *initial_item;
571 found = true;
572 break;
573 }
574 }
575 }
576
577 if( !found )
578 {
579 change = true;
580 }
581 }
582
583 // Transfer layer settings:
584 *this = stackup;
585
586 // Transfer other stackup settings from aSettings
587 const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
590 m_CastellatedPads = source_stackup.m_CastellatedPads;
591 m_EdgePlating = source_stackup.m_EdgePlating;
592 m_FinishType = source_stackup.m_FinishType;
593
594 return change;
595}
596
597
599 int aActiveCopperLayersCount )
600{
601 // Creates a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
602 // Note: the m_TypeName string is made translatable using _HKI marker, but is not
603 // translated when building the stackup.
604 // It will be used as this in files, and can be translated only in dialog
605 // if aSettings == NULL, build a full stackup (with 32 copper layers)
606 LSET enabledLayer = aSettings ? aSettings->GetEnabledLayers() : StackupAllowedBrdLayers();
607 int copperLayerCount = aSettings ? aSettings->GetCopperLayerCount() : B_Cu+1;
608
609 // We need to calculate a suitable dielectric layer thickness.
610 // If no settings, and if aActiveCopperLayersCount is given, use it
611 // (If no settings, and no aActiveCopperLayersCount, the full 32 layers are used)
612 int activeCuLayerCount = copperLayerCount;
613
614 if( aSettings == nullptr && aActiveCopperLayersCount > 0 )
615 activeCuLayerCount = aActiveCopperLayersCount;
616
617 int brd__thickness = aSettings ? aSettings->GetBoardThickness() : pcbIUScale.mmToIU( 1.6 );
618 int diel_thickness = brd__thickness -
619 ( BOARD_STACKUP_ITEM::GetCopperDefaultThickness() * activeCuLayerCount );
620
621 // Take in account the solder mask thickness:
622 int sm_count = ( enabledLayer & LSET( 2, F_Mask, B_Mask) ).count();
623 diel_thickness -= BOARD_STACKUP_ITEM::GetMaskDefaultThickness() * sm_count;
624 diel_thickness /= std::max( 1, activeCuLayerCount - 1 );
625
626 int dielectric_idx = 0;
627
628 // Add silk screen, solder mask and solder paste layers on top
629 if( enabledLayer[F_SilkS] )
630 {
632 item->SetBrdLayerId( F_SilkS );
633 item->SetTypeName( _HKI( "Top Silk Screen" ) );
634 Add( item );
635 }
636
637 if( enabledLayer[F_Paste] )
638 {
640 item->SetBrdLayerId( F_Paste );
641 item->SetTypeName( _HKI( "Top Solder Paste" ) );
642 Add( item );
643 }
644
645 if( enabledLayer[F_Mask] )
646 {
648 item->SetBrdLayerId( F_Mask );
649 item->SetTypeName( _HKI( "Top Solder Mask" ) );
650 Add( item );
651 }
652
653 // Add copper and dielectric layers
654 for( int ii = 0; ii < copperLayerCount; ii++ )
655 {
657 item->SetBrdLayerId( ( PCB_LAYER_ID )ii );
658 item->SetTypeName( KEY_COPPER );
659 Add( item );
660
661 if( ii == copperLayerCount-1 )
662 {
663 item->SetBrdLayerId( B_Cu );
664 break;
665 }
666
667 // Add the dielectric layer:
669 item->SetThickness( diel_thickness );
670 item->SetDielectricLayerId( dielectric_idx + 1 );
671
672 // Display a dielectric default layer name:
673 if( (dielectric_idx & 1) == 0 )
674 {
675 item->SetTypeName( KEY_CORE );
676 item->SetMaterial( wxT( "FR4" ) );
677 }
678 else
679 {
680 item->SetTypeName( KEY_PREPREG );
681 item->SetMaterial( wxT( "FR4" ) );
682 }
683
684 Add( item );
685 dielectric_idx++;
686 }
687
688 // Add silk screen, solder mask and solder paste layers on bottom
689 if( enabledLayer[B_Mask] )
690 {
692 item->SetBrdLayerId( B_Mask );
693 item->SetTypeName( _HKI( "Bottom Solder Mask" ) );
694 Add( item );
695 }
696
697 if( enabledLayer[B_Paste] )
698 {
700 item->SetBrdLayerId( B_Paste );
701 item->SetTypeName( _HKI( "Bottom Solder Paste" ) );
702 Add( item );
703 }
704
705 if( enabledLayer[B_SilkS] )
706 {
708 item->SetBrdLayerId( B_SilkS );
709 item->SetTypeName( _HKI( "Bottom Silk Screen" ) );
710 Add( item );
711 }
712
713 // Transfer other stackup settings from aSettings
714 if( aSettings )
715 {
716 const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
719 m_CastellatedPads = source_stackup.m_CastellatedPads;
720 m_EdgePlating = source_stackup.m_EdgePlating;
721 m_FinishType = source_stackup.m_FinishType;
722 }
723}
724
725
727 const BOARD* aBoard, int aNestLevel ) const
728{
729 // Board stackup is the ordered list from top to bottom of
730 // physical layers and substrate used to build the board.
731 if( m_list.empty() )
732 return;
733
734 aFormatter->Print( aNestLevel, "(stackup\n" );
735 int nest_level = aNestLevel+1;
736
737 // Note:
738 // Unspecified parameters are not stored in file.
739 for( BOARD_STACKUP_ITEM* item: m_list )
740 {
741 wxString layer_name;
742
743 if( item->GetBrdLayerId() == UNDEFINED_LAYER )
744 layer_name.Printf( wxT( "dielectric %d" ), item->GetDielectricLayerId() );
745 else
746 layer_name = LSET::Name( item->GetBrdLayerId() );
747
748 aFormatter->Print( nest_level, "(layer %s (type %s)",
749 aFormatter->Quotew( layer_name ).c_str(),
750 aFormatter->Quotew( item->GetTypeName() ).c_str() );
751
752 // Output other parameters ( in sub layer list there is at least one item)
753 for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
754 {
755 if( idx ) // not for the main (first) layer.
756 {
757 aFormatter->Print( 0, "\n" );
758 aFormatter->Print( nest_level+1, "addsublayer" );
759 }
760
761 if( item->IsColorEditable() && IsPrmSpecified( item->GetColor( idx ) ) )
762 {
763 aFormatter->Print( 0, " (color %s)",
764 aFormatter->Quotew( item->GetColor( idx ) ).c_str() );
765 }
766
767 if( item->IsThicknessEditable() )
768 {
769 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC && item->IsThicknessLocked( idx ) )
770 aFormatter->Print( 0, " (thickness %s locked)",
771 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, item->GetThickness( idx ) ).c_str() );
772 else
773 aFormatter->Print( 0, " (thickness %s)",
774 EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, item->GetThickness( idx ) ).c_str() );
775 }
776
777 if( item->HasMaterialValue( idx ) )
778 aFormatter->Print( 0, " (material %s)",
779 aFormatter->Quotew( item->GetMaterial( idx ) ).c_str() );
780
781 if( item->HasEpsilonRValue() && item->HasMaterialValue( idx ) )
782 aFormatter->Print( 0, " (epsilon_r %g)", item->GetEpsilonR( idx ) );
783
784 if( item->HasLossTangentValue() && item->HasMaterialValue( idx ) )
785 aFormatter->Print( 0, " (loss_tangent %s)",
786 FormatDouble2Str( item->GetLossTangent( idx ) ).c_str() );
787 }
788
789 aFormatter->Print( 0, ")\n" );
790 }
791
792 // Other infos about board, related to layers and other fabrication specifications
794 {
795 aFormatter->Print( nest_level, "(copper_finish %s)\n",
796 aFormatter->Quotew( m_FinishType ).c_str() );
797 }
798
799 aFormatter->Print( nest_level, "(dielectric_constraints %s)\n",
800 m_HasDielectricConstrains ? "yes" : "no" );
801
803 {
804 aFormatter->Print( nest_level, "(edge_connector %s)\n",
805 m_EdgeConnectorConstraints > 1 ? "bevelled": "yes" );
806 }
807
809 aFormatter->Print( nest_level, "(castellated_pads yes)\n" );
810
811 if( m_EdgePlating )
812 aFormatter->Print( nest_level, "(edge_plating yes)\n" );
813
814 aFormatter->Print( aNestLevel, ")\n" );
815}
816
817
818int BOARD_STACKUP::GetLayerDistance( PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer ) const
819{
820 wxASSERT( IsCopperLayer( aFirstLayer ) && IsCopperLayer( aSecondLayer ) );
821
822 if( aFirstLayer == aSecondLayer )
823 return 0;
824
825 if( aSecondLayer < aFirstLayer )
826 std::swap( aFirstLayer, aSecondLayer );
827
828 int total = 0;
829 bool start = false;
830 bool half = false;
831
832 for( BOARD_STACKUP_ITEM* item : m_list )
833 {
834 // Will be UNDEFINED_LAYER for dielectrics
835 PCB_LAYER_ID layer = item->GetBrdLayerId();
836
837 if( layer != UNDEFINED_LAYER && !IsCopperLayer( layer ) )
838 continue; // Silk/mask layer
839
840 // Reached the start copper layer? Start counting the next dielectric after it
841 if( !start && ( layer != UNDEFINED_LAYER && layer >= aFirstLayer ) )
842 {
843 start = true;
844 half = true;
845 }
846 else if( !start )
847 continue;
848
849 // Reached the stop copper layer? we're done
850 if( start && ( layer != UNDEFINED_LAYER && layer >= aSecondLayer ) )
851 half = true;
852
853 for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
854 {
855 int subThickness = item->GetThickness( sublayer );
856 total += half ? ( subThickness / 2 ) : subThickness;
857 }
858
859 half = false;
860
861 if( layer != UNDEFINED_LAYER && layer >= aSecondLayer )
862 break;
863 }
864
865 return total;
866}
867
868
869bool IsPrmSpecified( const wxString& aPrmValue )
870{
871 // return true if the param value is specified:
872
873 if( !aPrmValue.IsEmpty()
874 && ( aPrmValue.CmpNoCase( NotSpecifiedPrm() ) != 0 )
875 && aPrmValue != wxGetTranslation( NotSpecifiedPrm() ) )
876 return true;
877
878 return false;
879}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
bool IsPrmSpecified(const wxString &aPrmValue)
@ BS_EDGE_CONNECTOR_NONE
Definition: board_stackup.h:56
BOARD_STACKUP_ITEM_TYPE
Definition: board_stackup.h:42
@ BS_ITEM_TYPE_UNDEFINED
Definition: board_stackup.h:43
@ BS_ITEM_TYPE_COPPER
Definition: board_stackup.h:44
@ BS_ITEM_TYPE_SILKSCREEN
Definition: board_stackup.h:50
@ BS_ITEM_TYPE_DIELECTRIC
Definition: board_stackup.h:45
@ BS_ITEM_TYPE_SOLDERPASTE
Definition: board_stackup.h:47
@ BS_ITEM_TYPE_SOLDERMASK
Definition: board_stackup.h:48
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:95
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.
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard, int aNestLevel) const
Write the stackup info on board file.
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...
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:281
A helper class to manage a dielectric layer set of parameters.
Definition: board_stackup.h:66
double m_EpsilonR
true for dielectric layers with a fixed thickness (for impedance controlled purposes),...
Definition: board_stackup.h:83
int m_Thickness
type of material (for dielectric and solder mask)
Definition: board_stackup.h:80
wxString m_Material
Definition: board_stackup.h:79
bool operator==(const DIELECTRIC_PRMS &aOther) const
wxString m_Color
For dielectric (and solder mask) the dielectric loss.
Definition: board_stackup.h:85
bool m_ThicknessLocked
the physical layer thickness in internal units
Definition: board_stackup.h:81
double m_LossTangent
For dielectric (and solder mask) the dielectric constant.
Definition: board_stackup.h:84
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:574
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:89
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:526
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
#define _HKI(x)
#define _(s)
Some functions to handle hotkeys in KiCad.
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:880
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_Paste
Definition: layer_ids.h:101
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ F_SilkS
Definition: layer_ids.h:104
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ B_SilkS
Definition: layer_ids.h:103
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:169
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