You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

764 lines
24 KiB

  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. #include "board_stackup.h"
  21. #include <convert_to_biu.h>
  22. #include <base_units.h>
  23. #include <kicad_string.h>
  24. #include <layers_id_colors_and_visibility.h>
  25. #include <board_design_settings.h>
  26. #include <board.h>
  27. #include <i18n_utility.h> // For _HKI definition
  28. #include "stackup_predefined_prms.h"
  29. BOARD_STACKUP_ITEM::BOARD_STACKUP_ITEM( BOARD_STACKUP_ITEM_TYPE aType )
  30. {
  31. DIELECTRIC_PRMS item_prms;
  32. m_DielectricPrmsList.emplace_back( item_prms );
  33. m_LayerId = UNDEFINED_LAYER;
  34. m_Type = aType;
  35. SetDielectricLayerId( 1 );
  36. SetEnabled( true );
  37. // Initialize parameters to a usual value for allowed types:
  38. switch( m_Type )
  39. {
  40. case BS_ITEM_TYPE_COPPER:
  41. m_TypeName = KEY_COPPER;
  42. SetThickness( GetCopperDefaultThickness() );
  43. break;
  44. case BS_ITEM_TYPE_DIELECTRIC:
  45. m_TypeName = KEY_CORE; // or prepreg
  46. SetMaterial( "FR4" ); // or other dielectric name
  47. SetLossTangent( 0.02 ); // for FR4
  48. SetEpsilonR( 4.5 ); // for FR4
  49. break;
  50. case BS_ITEM_TYPE_SOLDERPASTE:
  51. m_TypeName = "solderpaste";
  52. break;
  53. case BS_ITEM_TYPE_SOLDERMASK:
  54. m_TypeName = "soldermask";
  55. m_Color = "Green";
  56. SetMaterial( NotSpecifiedPrm() ); // or other solder mask material name
  57. SetThickness( GetMaskDefaultThickness() );
  58. SetEpsilonR( DEFAULT_EPSILON_R_SOLDERMASK );
  59. break;
  60. case BS_ITEM_TYPE_SILKSCREEN:
  61. m_TypeName = "silkscreen";
  62. m_Color = NotSpecifiedPrm();
  63. SetMaterial( NotSpecifiedPrm() ); // or other silkscreen material name
  64. SetEpsilonR( DEFAULT_EPSILON_R_SILKSCREEN );
  65. break;
  66. case BS_ITEM_TYPE_UNDEFINED:
  67. break;
  68. }
  69. }
  70. BOARD_STACKUP_ITEM::BOARD_STACKUP_ITEM( const BOARD_STACKUP_ITEM& aOther )
  71. {
  72. m_LayerId = aOther.m_LayerId;
  73. m_DielectricLayerId = aOther.m_DielectricLayerId;
  74. m_Type = aOther.m_Type;
  75. m_enabled = aOther.m_enabled;
  76. m_DielectricPrmsList = aOther.m_DielectricPrmsList;
  77. m_TypeName = aOther.m_TypeName;
  78. m_LayerName = aOther.m_LayerName;
  79. m_Color = aOther.GetColor();
  80. }
  81. void BOARD_STACKUP_ITEM::AddDielectricPrms( int aDielectricPrmsIdx )
  82. {
  83. // add a DIELECTRIC_PRMS item to m_DielectricPrmsList
  84. DIELECTRIC_PRMS new_prms;
  85. m_DielectricPrmsList.emplace( m_DielectricPrmsList.begin() + aDielectricPrmsIdx,
  86. new_prms );
  87. }
  88. void BOARD_STACKUP_ITEM::RemoveDielectricPrms( int aDielectricPrmsIdx )
  89. {
  90. // Remove a DIELECTRIC_PRMS item from m_DielectricPrmsList if possible
  91. if( GetSublayersCount() < 2 || aDielectricPrmsIdx < 0
  92. || aDielectricPrmsIdx >= GetSublayersCount() )
  93. return;
  94. m_DielectricPrmsList.erase( m_DielectricPrmsList.begin() + aDielectricPrmsIdx );
  95. }
  96. int BOARD_STACKUP_ITEM::GetCopperDefaultThickness()
  97. {
  98. // A reasonable thickness for copper layers:
  99. return Millimeter2iu( 0.035 );
  100. }
  101. int BOARD_STACKUP_ITEM::GetMaskDefaultThickness()
  102. {
  103. // A reasonable thickness for solder mask:
  104. return Millimeter2iu( 0.01 );
  105. }
  106. // Getters:
  107. int BOARD_STACKUP_ITEM::GetThickness( int aDielectricSubLayer ) const
  108. {
  109. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  110. return m_DielectricPrmsList[aDielectricSubLayer].m_Thickness;
  111. }
  112. double BOARD_STACKUP_ITEM::GetLossTangent( int aDielectricSubLayer ) const
  113. {
  114. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  115. return m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent;
  116. }
  117. double BOARD_STACKUP_ITEM::GetEpsilonR( int aDielectricSubLayer ) const
  118. {
  119. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  120. return m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR;
  121. }
  122. bool BOARD_STACKUP_ITEM::IsThicknessLocked( int aDielectricSubLayer ) const
  123. {
  124. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  125. return m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked;
  126. }
  127. wxString BOARD_STACKUP_ITEM::GetMaterial( int aDielectricSubLayer ) const
  128. {
  129. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  130. return m_DielectricPrmsList[aDielectricSubLayer].m_Material;
  131. }
  132. // Setters:
  133. void BOARD_STACKUP_ITEM::SetThickness( int aThickness, int aDielectricSubLayer )
  134. {
  135. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  136. if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
  137. m_DielectricPrmsList[aDielectricSubLayer].m_Thickness = aThickness;
  138. }
  139. void BOARD_STACKUP_ITEM::SetLossTangent( double aTg, int aDielectricSubLayer )
  140. {
  141. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  142. if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
  143. m_DielectricPrmsList[aDielectricSubLayer].m_LossTangent = aTg;
  144. }
  145. void BOARD_STACKUP_ITEM::SetEpsilonR( double aEpsilon, int aDielectricSubLayer )
  146. {
  147. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  148. if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
  149. m_DielectricPrmsList[aDielectricSubLayer].m_EpsilonR = aEpsilon;
  150. }
  151. void BOARD_STACKUP_ITEM::SetThicknessLocked( bool aLocked, int aDielectricSubLayer )
  152. {
  153. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  154. if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
  155. m_DielectricPrmsList[aDielectricSubLayer].m_ThicknessLocked = aLocked;
  156. }
  157. void BOARD_STACKUP_ITEM::SetMaterial( const wxString& aName, int aDielectricSubLayer )
  158. {
  159. wxASSERT( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() );
  160. if( aDielectricSubLayer >= 0 && aDielectricSubLayer < GetSublayersCount() )
  161. m_DielectricPrmsList[aDielectricSubLayer].m_Material = aName;
  162. }
  163. bool BOARD_STACKUP_ITEM::HasEpsilonRValue() const
  164. {
  165. return m_Type == BS_ITEM_TYPE_DIELECTRIC
  166. || m_Type == BS_ITEM_TYPE_SOLDERMASK
  167. //|| m_Type == BS_ITEM_TYPE_SILKSCREEN
  168. ;
  169. };
  170. bool BOARD_STACKUP_ITEM::HasLossTangentValue() const
  171. {
  172. return m_Type == BS_ITEM_TYPE_DIELECTRIC
  173. || m_Type == BS_ITEM_TYPE_SOLDERMASK;
  174. };
  175. bool BOARD_STACKUP_ITEM::HasMaterialValue( int aDielectricSubLayer ) const
  176. {
  177. // return true if the material is specified
  178. return IsMaterialEditable() && IsPrmSpecified( GetMaterial( aDielectricSubLayer ) );
  179. }
  180. bool BOARD_STACKUP_ITEM::IsMaterialEditable() const
  181. {
  182. // The material is editable only for dielectric
  183. return m_Type == BS_ITEM_TYPE_DIELECTRIC ||
  184. m_Type == BS_ITEM_TYPE_SOLDERMASK ||
  185. m_Type == BS_ITEM_TYPE_SILKSCREEN;
  186. }
  187. bool BOARD_STACKUP_ITEM::IsColorEditable() const
  188. {
  189. return m_Type == BS_ITEM_TYPE_SOLDERMASK || m_Type == BS_ITEM_TYPE_SILKSCREEN;
  190. }
  191. bool BOARD_STACKUP_ITEM::IsThicknessEditable() const
  192. {
  193. switch( m_Type )
  194. {
  195. case BS_ITEM_TYPE_COPPER:
  196. return true;
  197. case BS_ITEM_TYPE_DIELECTRIC:
  198. return true;
  199. case BS_ITEM_TYPE_SOLDERMASK:
  200. return true;
  201. case BS_ITEM_TYPE_SOLDERPASTE:
  202. return false;
  203. case BS_ITEM_TYPE_SILKSCREEN:
  204. return false;
  205. default:
  206. break;
  207. }
  208. return false;
  209. }
  210. wxString BOARD_STACKUP_ITEM::FormatEpsilonR( int aDielectricSubLayer ) const
  211. {
  212. // return a wxString to print/display Epsilon R
  213. wxString txt;
  214. txt.Printf( "%.2f", GetEpsilonR( aDielectricSubLayer ) );
  215. return txt;
  216. }
  217. wxString BOARD_STACKUP_ITEM::FormatLossTangent( int aDielectricSubLayer ) const
  218. {
  219. // return a wxString to print/display Loss Tangent
  220. wxString txt;
  221. txt.Printf( "%g", GetLossTangent( aDielectricSubLayer ) );
  222. return txt;
  223. }
  224. wxString BOARD_STACKUP_ITEM::FormatDielectricLayerName() const
  225. {
  226. // return a wxString to print/display a dielectric name
  227. wxString lname;
  228. lname.Printf( _( "Dielectric %d" ), GetDielectricLayerId() );
  229. return lname;
  230. }
  231. BOARD_STACKUP::BOARD_STACKUP()
  232. {
  233. m_HasDielectricConstrains = false; // True if some dielectric layers have constrains
  234. // (Loss tg and Epison R)
  235. m_HasThicknessConstrains = false; // True if some dielectric or copper layers have constrains
  236. m_EdgeConnectorConstraints = BS_EDGE_CONNECTOR_NONE;
  237. m_CastellatedPads = false; // True if some castellated pads exist
  238. m_EdgePlating = false; // True if edge board is plated
  239. m_FinishType = "None"; // undefined finish type
  240. }
  241. BOARD_STACKUP::BOARD_STACKUP( const BOARD_STACKUP& aOther )
  242. {
  243. m_HasDielectricConstrains = aOther.m_HasDielectricConstrains;
  244. m_HasThicknessConstrains = aOther.m_HasThicknessConstrains;
  245. m_EdgeConnectorConstraints = aOther.m_EdgeConnectorConstraints;
  246. m_CastellatedPads = aOther.m_CastellatedPads;
  247. m_EdgePlating = aOther.m_EdgePlating;
  248. m_FinishType = aOther.m_FinishType;
  249. // All items in aOther.m_list have to be duplicated, because aOther.m_list
  250. // manage pointers to these items
  251. for( auto item : aOther.m_list )
  252. {
  253. BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
  254. Add( dup_item );
  255. }
  256. }
  257. BOARD_STACKUP& BOARD_STACKUP::operator=( const BOARD_STACKUP& aOther )
  258. {
  259. m_HasDielectricConstrains = aOther.m_HasDielectricConstrains;
  260. m_HasThicknessConstrains = aOther.m_HasThicknessConstrains;
  261. m_EdgeConnectorConstraints = aOther.m_EdgeConnectorConstraints;
  262. m_CastellatedPads = aOther.m_CastellatedPads;
  263. m_EdgePlating = aOther.m_EdgePlating;
  264. m_FinishType = aOther.m_FinishType;
  265. RemoveAll();
  266. // All items in aOther.m_list have to be duplicated, because aOther.m_list
  267. // manage pointers to these items
  268. for( auto item : aOther.m_list )
  269. {
  270. BOARD_STACKUP_ITEM* dup_item = new BOARD_STACKUP_ITEM( *item );
  271. Add( dup_item );
  272. }
  273. return *this;
  274. }
  275. void BOARD_STACKUP::RemoveAll()
  276. {
  277. for( auto item : m_list )
  278. delete item;
  279. m_list.clear();
  280. }
  281. BOARD_STACKUP_ITEM* BOARD_STACKUP::GetStackupLayer( int aIndex )
  282. {
  283. if( aIndex < 0 || aIndex >= GetCount() )
  284. return nullptr;
  285. return GetList()[aIndex];
  286. }
  287. int BOARD_STACKUP::BuildBoardThicknessFromStackup() const
  288. {
  289. // return the board thickness from the thickness of BOARD_STACKUP_ITEM list
  290. int thickness = 0;
  291. for( auto item : m_list )
  292. {
  293. if( item->IsThicknessEditable() && item->IsEnabled() )
  294. thickness += item->GetThickness();
  295. }
  296. return thickness;
  297. }
  298. bool BOARD_STACKUP::SynchronizeWithBoard( BOARD_DESIGN_SETTINGS* aSettings )
  299. {
  300. bool change = false;
  301. // Build the suitable stackup:
  302. BOARD_STACKUP stackup;
  303. stackup.BuildDefaultStackupList( aSettings );
  304. // First, find removed layers:
  305. for( BOARD_STACKUP_ITEM* curr_item: m_list )
  306. {
  307. bool found = false;
  308. for( BOARD_STACKUP_ITEM* item: stackup.GetList() )
  309. {
  310. if( curr_item->GetBrdLayerId() != UNDEFINED_LAYER )
  311. {
  312. if( item->GetBrdLayerId() == curr_item->GetBrdLayerId() )
  313. {
  314. found = true;
  315. break;
  316. }
  317. }
  318. else // curr_item = dielectric layer
  319. {
  320. if( item->GetBrdLayerId() != UNDEFINED_LAYER )
  321. continue;
  322. if( item->GetDielectricLayerId() == curr_item->GetDielectricLayerId() )
  323. {
  324. found = true;
  325. break;
  326. }
  327. }
  328. }
  329. if( !found ) // a layer was removed: a change is found
  330. {
  331. change = true;
  332. break;
  333. }
  334. }
  335. // Now initialize all stackup items to the initial values, when exist
  336. for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
  337. {
  338. bool found = false;
  339. // Search for initial settings:
  340. for( const BOARD_STACKUP_ITEM* initial_item : m_list )
  341. {
  342. if( item->GetBrdLayerId() != UNDEFINED_LAYER )
  343. {
  344. if( item->GetBrdLayerId() == initial_item->GetBrdLayerId() )
  345. {
  346. *item = *initial_item;
  347. found = true;
  348. break;
  349. }
  350. }
  351. else // dielectric layer: see m_DielectricLayerId for identification
  352. {
  353. // Compare dielectric layer with dielectric layer
  354. if( initial_item->GetBrdLayerId() != UNDEFINED_LAYER )
  355. continue;
  356. if( item->GetDielectricLayerId() == initial_item->GetDielectricLayerId() )
  357. {
  358. *item = *initial_item;
  359. found = true;
  360. break;
  361. }
  362. }
  363. }
  364. if( !found )
  365. {
  366. change = true;
  367. }
  368. }
  369. // Transfer other stackup settings from aSettings
  370. const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
  371. m_HasDielectricConstrains = source_stackup.m_HasDielectricConstrains;
  372. m_EdgeConnectorConstraints = source_stackup.m_EdgeConnectorConstraints;
  373. m_CastellatedPads = source_stackup.m_CastellatedPads;
  374. m_EdgePlating = source_stackup.m_EdgePlating;
  375. m_FinishType = source_stackup.m_FinishType;
  376. *this = stackup;
  377. return change;
  378. }
  379. void BOARD_STACKUP::BuildDefaultStackupList( const BOARD_DESIGN_SETTINGS* aSettings,
  380. int aActiveCopperLayersCount )
  381. {
  382. // Creates a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
  383. // Note: the m_TypeName string is made translatable using _HKI marker, but is not
  384. // translated when building the stackup.
  385. // It will be used as this in files, and can be translated only in dialog
  386. // if aSettings == NULL, build a full stackup (with 32 copper layers)
  387. LSET enabledLayer = aSettings ? aSettings->GetEnabledLayers() : StackupAllowedBrdLayers();
  388. int copperLayerCount = aSettings ? aSettings->GetCopperLayerCount() : B_Cu+1;
  389. // We need to calculate a suitable dielectric layer thickness.
  390. // If no settings, and if aActiveCopperLayersCount is given, use it
  391. // (If no settings, and no aActiveCopperLayersCount, the full 32 layers are used)
  392. int activeCuLayerCount = copperLayerCount;
  393. if( aSettings == nullptr && aActiveCopperLayersCount > 0 )
  394. activeCuLayerCount = aActiveCopperLayersCount;
  395. int brd__thickness = aSettings ? aSettings->GetBoardThickness() : Millimeter2iu( 1.6 );
  396. int diel_thickness = brd__thickness -
  397. ( BOARD_STACKUP_ITEM::GetCopperDefaultThickness() * activeCuLayerCount );
  398. // Take in account the solder mask thickness:
  399. int sm_count = ( enabledLayer & LSET( 2, F_Mask, B_Mask) ).count();
  400. diel_thickness -= BOARD_STACKUP_ITEM::GetMaskDefaultThickness() * sm_count;
  401. int dielectric_idx = 0;
  402. // Add silk screen, solder mask and solder paste layers on top
  403. if( enabledLayer[F_SilkS] )
  404. {
  405. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_SILKSCREEN );
  406. item->SetBrdLayerId( F_SilkS );
  407. item->SetTypeName( _HKI( "Top Silk Screen" ) );
  408. Add( item );
  409. }
  410. if( enabledLayer[F_Paste] )
  411. {
  412. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_SOLDERPASTE );
  413. item->SetBrdLayerId( F_Paste );
  414. item->SetTypeName( _HKI( "Top Solder Paste" ) );
  415. Add( item );
  416. }
  417. if( enabledLayer[F_Mask] )
  418. {
  419. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_SOLDERMASK );
  420. item->SetBrdLayerId( F_Mask );
  421. item->SetTypeName( _HKI( "Top Solder Mask" ) );
  422. Add( item );
  423. }
  424. // Add copper and dielectric layers
  425. for( int ii = 0; ii < copperLayerCount; ii++ )
  426. {
  427. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_COPPER );
  428. item->SetBrdLayerId( ( PCB_LAYER_ID )ii );
  429. item->SetTypeName( KEY_COPPER );
  430. Add( item );
  431. if( ii == copperLayerCount-1 )
  432. {
  433. item->SetBrdLayerId( B_Cu );
  434. break;
  435. }
  436. // Add the dielectric layer:
  437. item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_DIELECTRIC );
  438. item->SetThickness( diel_thickness );
  439. item->SetDielectricLayerId( dielectric_idx + 1 );
  440. // Display a dielectric default layer name:
  441. if( (dielectric_idx & 1) == 0 )
  442. {
  443. item->SetTypeName( KEY_CORE );
  444. item->SetMaterial( "FR4" );
  445. }
  446. else
  447. {
  448. item->SetTypeName( KEY_PREPREG );
  449. item->SetMaterial( "FR4" );
  450. }
  451. Add( item );
  452. dielectric_idx++;
  453. }
  454. // Add silk screen, solder mask and solder paste layers on bottom
  455. if( enabledLayer[B_Mask] )
  456. {
  457. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_SOLDERMASK );
  458. item->SetBrdLayerId( B_Mask );
  459. item->SetTypeName( _HKI( "Bottom Solder Mask" ) );
  460. Add( item );
  461. }
  462. if( enabledLayer[B_Paste] )
  463. {
  464. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_SOLDERPASTE );
  465. item->SetBrdLayerId( B_Paste );
  466. item->SetTypeName( _HKI( "Bottom Solder Paste" ) );
  467. Add( item );
  468. }
  469. if( enabledLayer[B_SilkS] )
  470. {
  471. BOARD_STACKUP_ITEM* item = new BOARD_STACKUP_ITEM( BS_ITEM_TYPE_SILKSCREEN );
  472. item->SetBrdLayerId( B_SilkS );
  473. item->SetTypeName( _HKI( "Bottom Silk Screen" ) );
  474. Add( item );
  475. }
  476. // Transfer other stackup settings from aSettings
  477. if( aSettings )
  478. {
  479. const BOARD_STACKUP& source_stackup = aSettings->GetStackupDescriptor();
  480. m_EdgeConnectorConstraints = source_stackup.m_EdgeConnectorConstraints;
  481. m_CastellatedPads = source_stackup.m_CastellatedPads;
  482. m_EdgePlating = source_stackup.m_EdgePlating;
  483. m_FinishType = source_stackup.m_FinishType;
  484. }
  485. }
  486. void BOARD_STACKUP::FormatBoardStackup( OUTPUTFORMATTER* aFormatter,
  487. const BOARD* aBoard, int aNestLevel ) const
  488. {
  489. // Board stackup is the ordered list from top to bottom of
  490. // physical layers and substrate used to build the board.
  491. if( m_list.empty() )
  492. return;
  493. aFormatter->Print( aNestLevel, "(stackup\n" );
  494. int nest_level = aNestLevel+1;
  495. // Note:
  496. // Unspecified parameters are not stored in file.
  497. for( BOARD_STACKUP_ITEM* item: m_list )
  498. {
  499. wxString layer_name;
  500. if( item->GetBrdLayerId() == UNDEFINED_LAYER )
  501. layer_name.Printf( "dielectric %d", item->GetDielectricLayerId() );
  502. else
  503. layer_name = LSET::Name( item->GetBrdLayerId() );
  504. aFormatter->Print( nest_level, "(layer %s (type %s)",
  505. aFormatter->Quotew( layer_name ).c_str(),
  506. aFormatter->Quotew( item->GetTypeName() ).c_str() );
  507. if( item->IsColorEditable() && IsPrmSpecified( item->GetColor() ) )
  508. aFormatter->Print( 0, " (color %s)",
  509. aFormatter->Quotew( item->GetColor() ).c_str() );
  510. for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
  511. {
  512. if( idx ) // not for the main (first) layer.
  513. {
  514. aFormatter->Print( 0, "\n" );
  515. aFormatter->Print( nest_level+1, "addsublayer" );
  516. }
  517. if( item->IsThicknessEditable() )
  518. {
  519. if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC && item->IsThicknessLocked( idx ) )
  520. aFormatter->Print( 0, " (thickness %s locked)",
  521. FormatInternalUnits( item->GetThickness( idx ) ).c_str() );
  522. else
  523. aFormatter->Print( 0, " (thickness %s)",
  524. FormatInternalUnits( item->GetThickness( idx ) ).c_str() );
  525. }
  526. if( item->HasMaterialValue( idx ) )
  527. aFormatter->Print( 0, " (material %s)",
  528. aFormatter->Quotew( item->GetMaterial( idx ) ).c_str() );
  529. if( item->HasEpsilonRValue() && item->HasMaterialValue( idx ) )
  530. aFormatter->Print( 0, " (epsilon_r %g)", item->GetEpsilonR( idx ) );
  531. if( item->HasLossTangentValue() && item->HasMaterialValue( idx ) )
  532. aFormatter->Print( 0, " (loss_tangent %s)",
  533. Double2Str(item->GetLossTangent( idx ) ).c_str() );
  534. }
  535. aFormatter->Print( 0, ")\n" );
  536. }
  537. // Other infos about board, related to layers and other fabrication specifications
  538. if( IsPrmSpecified( m_FinishType ) )
  539. aFormatter->Print( nest_level, "(copper_finish %s)\n",
  540. aFormatter->Quotew( m_FinishType ).c_str() );
  541. aFormatter->Print( nest_level, "(dielectric_constraints %s)\n",
  542. m_HasDielectricConstrains ? "yes" : "no" );
  543. if( m_EdgeConnectorConstraints > 0 )
  544. aFormatter->Print( nest_level, "(edge_connector %s)\n",
  545. m_EdgeConnectorConstraints > 1 ? "bevelled": "yes" );
  546. if( m_CastellatedPads )
  547. aFormatter->Print( nest_level, "(castellated_pads yes)\n" );
  548. if( m_EdgePlating )
  549. aFormatter->Print( nest_level, "(edge_plating yes)\n" );
  550. aFormatter->Print( aNestLevel, ")\n" );
  551. }
  552. int BOARD_STACKUP::GetLayerDistance( PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer ) const
  553. {
  554. wxASSERT( IsCopperLayer( aFirstLayer ) && IsCopperLayer( aSecondLayer ) );
  555. if( aFirstLayer == aSecondLayer )
  556. return 0;
  557. if( aSecondLayer < aFirstLayer )
  558. std::swap( aFirstLayer, aSecondLayer );
  559. int total = 0;
  560. bool start = false;
  561. bool half = false;
  562. for( BOARD_STACKUP_ITEM* item : m_list )
  563. {
  564. // Will be UNDEFINED_LAYER for dielectrics
  565. PCB_LAYER_ID layer = item->GetBrdLayerId();
  566. if( layer != UNDEFINED_LAYER && !IsCopperLayer( layer ) )
  567. continue; // Silk/mask layer
  568. // Reached the start copper layer? Start counting the next dielectric after it
  569. if( !start && ( layer != UNDEFINED_LAYER && layer >= aFirstLayer ) )
  570. {
  571. start = true;
  572. half = true;
  573. }
  574. else if( !start )
  575. continue;
  576. // Reached the stop copper layer? we're done
  577. if( start && ( layer != UNDEFINED_LAYER && layer >= aSecondLayer ) )
  578. half = true;
  579. for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ )
  580. {
  581. int subThickness = item->GetThickness( sublayer );
  582. total += half ? ( subThickness / 2 ) : subThickness;
  583. }
  584. half = false;
  585. if( layer != UNDEFINED_LAYER && layer >= aSecondLayer )
  586. break;
  587. }
  588. return total;
  589. }
  590. bool IsPrmSpecified( const wxString& aPrmValue )
  591. {
  592. // return true if the param value is specified:
  593. if( !aPrmValue.IsEmpty()
  594. && ( aPrmValue.CmpNoCase( NotSpecifiedPrm() ) != 0 )
  595. && aPrmValue != wxGetTranslation( NotSpecifiedPrm() ) )
  596. return true;
  597. return false;
  598. }