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.

1139 lines
41 KiB

8 years ago
14 years ago
14 years ago
14 years ago
6 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <fctsys.h>
  24. #include <common.h>
  25. #include <class_board.h>
  26. #include <class_track.h>
  27. #include <layers_id_colors_and_visibility.h>
  28. #include <kiface_i.h>
  29. #include <pcbnew.h>
  30. #include <board_design_settings.h>
  31. #include <drc/drc.h>
  32. #include <widgets/ui_common.h>
  33. #include <drc/drc_rule.h>
  34. #define CopperLayerCountKey wxT( "CopperLayerCount" )
  35. #define BoardThicknessKey wxT( "BoardThickness" )
  36. #define LayerKeyPrefix wxT( "Layer" )
  37. #define LayerNameKey wxT( "Name" )
  38. #define LayerTypeKey wxT( "Type" )
  39. #define LayerEnabledKey wxT( "Enabled" )
  40. #define NetclassNameKey wxT( "Name" )
  41. #define ClearanceKey wxT( "Clearance" )
  42. #define TrackWidthKey wxT( "TrackWidth" )
  43. #define ViaDiameterKey wxT( "ViaDiameter" )
  44. #define ViaDrillKey wxT( "ViaDrill" )
  45. #define uViaDiameterKey wxT( "uViaDiameter" )
  46. #define uViaDrillKey wxT( "uViaDrill" )
  47. #define dPairWidthKey wxT( "dPairWidth" )
  48. #define dPairGapKey wxT( "dPairGap" )
  49. #define dPairViaGapKey wxT( "dPairViaGap" )
  50. class PARAM_CFG_SEVERITIES : public PARAM_CFG
  51. {
  52. protected:
  53. BOARD* m_Pt_param; ///< Pointer to the parameter value
  54. public:
  55. PARAM_CFG_SEVERITIES( BOARD* ptparam, const wxChar* group = nullptr ) :
  56. PARAM_CFG( wxEmptyString, PARAM_SEVERITIES, group )
  57. {
  58. m_Pt_param = ptparam;
  59. }
  60. void ReadParam( wxConfigBase* aConfig ) const override
  61. {
  62. if( !m_Pt_param || !aConfig )
  63. return;
  64. BOARD* board = m_Pt_param;
  65. BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
  66. wxString oldPath = aConfig->GetPath();
  67. // Read legacy settings first so that modern settings will overwrite them
  68. bool flag;
  69. if( aConfig->Read( wxT( "RequireCourtyardDefinitions" ), &flag, false ) )
  70. {
  71. if( flag )
  72. bds.m_DRCSeverities[ DRCE_MISSING_COURTYARD ] = RPT_SEVERITY_ERROR;
  73. else
  74. bds.m_DRCSeverities[ DRCE_MISSING_COURTYARD ] = RPT_SEVERITY_IGNORE;
  75. }
  76. if( aConfig->Read( wxT( "ProhibitOverlappingCourtyards" ), &flag, false ) )
  77. {
  78. if( flag )
  79. bds.m_DRCSeverities[ DRCE_OVERLAPPING_FOOTPRINTS ] = RPT_SEVERITY_ERROR;
  80. else
  81. bds.m_DRCSeverities[ DRCE_OVERLAPPING_FOOTPRINTS ] = RPT_SEVERITY_IGNORE;
  82. }
  83. bds.m_DRCSeverities[ CLEANUP_SHORT ] = RPT_SEVERITY_ACTION;
  84. bds.m_DRCSeverities[ CLEANUP_REDUNDANT_VIA ] = RPT_SEVERITY_ACTION;
  85. bds.m_DRCSeverities[ CLEANUP_DUPLICATE_TRACK ] = RPT_SEVERITY_ACTION;
  86. bds.m_DRCSeverities[ CLEANUP_MERGE_TRACKS ] = RPT_SEVERITY_ACTION;
  87. bds.m_DRCSeverities[ CLEANUP_DANGLING_TRACK ] = RPT_SEVERITY_ACTION;
  88. bds.m_DRCSeverities[ CLEANUP_DANGLING_VIA ] = RPT_SEVERITY_ACTION;
  89. bds.m_DRCSeverities[ CLEANUP_ZERO_LENGTH_TRACK ] = RPT_SEVERITY_ACTION;
  90. bds.m_DRCSeverities[ CLEANUP_TRACK_IN_PAD ] = RPT_SEVERITY_ACTION;
  91. DRC_ITEM drc( 0 );
  92. wxString severity;
  93. auto mapSeverity = []( const wxString& aSeverity )
  94. {
  95. if( aSeverity == wxT( "warning" ) )
  96. return RPT_SEVERITY_WARNING;
  97. else if( aSeverity == wxT( "ignore" ) )
  98. return RPT_SEVERITY_IGNORE;
  99. else
  100. return RPT_SEVERITY_ERROR;
  101. };
  102. for( int i = DRCE_FIRST; i <= DRCE_LAST; ++i )
  103. {
  104. wxString name = drc.GetErrorText( i, false );
  105. name.Replace( wxT( " " ), wxT( "_" ) );
  106. if( aConfig->Read( name, &severity, wxEmptyString ) )
  107. bds.m_DRCSeverities[i] = mapSeverity( severity );
  108. }
  109. aConfig->SetPath( oldPath );
  110. }
  111. void SaveParam( wxConfigBase* aConfig ) const override
  112. {
  113. if( !m_Pt_param || !aConfig )
  114. return;
  115. BOARD* board = m_Pt_param;
  116. BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
  117. wxString oldPath = aConfig->GetPath();
  118. DRC_ITEM drc( 0 );
  119. auto mapSeverity = []( int aSeverity )
  120. {
  121. if( aSeverity == RPT_SEVERITY_IGNORE )
  122. return wxT( "ignore" );
  123. else if( aSeverity == RPT_SEVERITY_WARNING )
  124. return wxT( "warning" );
  125. else
  126. return wxT( "error" );
  127. };
  128. for( int i = DRCE_FIRST; i <= DRCE_LAST; ++i )
  129. {
  130. wxString name = drc.GetErrorText( i, false );
  131. name.Replace( wxT( " " ), wxT( "_" ) );
  132. aConfig->Write( name, mapSeverity( bds.m_DRCSeverities[i] ) );
  133. }
  134. aConfig->SetPath( oldPath );
  135. }
  136. };
  137. //
  138. // NOTE: layer configuration info is stored in both the BOARD and BOARD_DESIGN_SETTINGS so one
  139. // of the two needs to read/write the config so we don't end up with order dependency issues.
  140. //
  141. class PARAM_CFG_LAYERS : public PARAM_CFG
  142. {
  143. protected:
  144. BOARD* m_Pt_param; ///< Pointer to the parameter value
  145. public:
  146. PARAM_CFG_LAYERS( BOARD* ptparam, const wxChar* group = nullptr ) :
  147. PARAM_CFG( wxEmptyString, PARAM_LAYERS, group )
  148. {
  149. m_Pt_param = ptparam;
  150. }
  151. void ReadParam( wxConfigBase* aConfig ) const override
  152. {
  153. if( !m_Pt_param || !aConfig )
  154. return;
  155. BOARD* board = m_Pt_param;
  156. BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
  157. LSET enabledLayers = bds.GetEnabledLayers();
  158. wxString oldPath = aConfig->GetPath();
  159. wxString layerKeyPrefix = LayerKeyPrefix;
  160. bds.SetCopperLayerCount( aConfig->Read( CopperLayerCountKey, 2 ) );
  161. double thickness = aConfig->ReadDouble( BoardThicknessKey, DEFAULT_BOARD_THICKNESS_MM );
  162. bds.SetBoardThickness( Millimeter2iu( thickness ) );
  163. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  164. {
  165. PCB_LAYER_ID layer = *seq;
  166. wxString path = layerKeyPrefix + wxT( "." ) + board->GetStandardLayerName( layer );
  167. wxString layerName;
  168. int layerType;
  169. bool layerEnabled;
  170. aConfig->SetPath( oldPath );
  171. aConfig->SetPath( path );
  172. if( aConfig->Read( LayerNameKey, &layerName ) )
  173. board->SetLayerName( layer, layerName );
  174. if( aConfig->Read( LayerTypeKey, &layerType ) )
  175. board->SetLayerType( layer, (LAYER_T) layerType );
  176. if( aConfig->Read( LayerEnabledKey, &layerEnabled ) )
  177. enabledLayers.set( layer, layerEnabled );
  178. }
  179. board->SetEnabledLayers( enabledLayers );
  180. aConfig->SetPath( oldPath );
  181. }
  182. void SaveParam( wxConfigBase* aConfig ) const override
  183. {
  184. if( !m_Pt_param || !aConfig )
  185. return;
  186. BOARD* board = m_Pt_param;
  187. BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
  188. wxString oldPath = aConfig->GetPath();
  189. wxString layerKeyPrefix = LayerKeyPrefix;
  190. aConfig->Write( CopperLayerCountKey, board->GetCopperLayerCount() );
  191. aConfig->Write( BoardThicknessKey, Iu2Millimeter( bds.GetBoardThickness() ) );
  192. for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
  193. {
  194. PCB_LAYER_ID layer = *seq;
  195. wxString path = layerKeyPrefix + wxT( "." ) + board->GetStandardLayerName( layer );
  196. wxString layerName = board->GetLayerName( layer );
  197. LAYER_T layerType = board->GetLayerType( layer );
  198. aConfig->SetPath( oldPath );
  199. aConfig->SetPath( path );
  200. if( IsCopperLayer( layer ) )
  201. {
  202. aConfig->Write( LayerNameKey, layerName );
  203. aConfig->Write( LayerTypeKey, (int) layerType );
  204. }
  205. aConfig->Write( LayerEnabledKey, board->IsLayerEnabled( layer ) );
  206. }
  207. aConfig->SetPath( oldPath );
  208. }
  209. };
  210. class PARAM_CFG_TRACKWIDTHS : public PARAM_CFG
  211. {
  212. protected:
  213. std::vector<int>* m_Pt_param; ///< Pointer to the parameter value
  214. public:
  215. PARAM_CFG_TRACKWIDTHS( std::vector<int>* ptparam, const wxChar* group = nullptr ) :
  216. PARAM_CFG( wxEmptyString, PARAM_TRACKWIDTHS, group )
  217. {
  218. m_Pt_param = ptparam;
  219. }
  220. void ReadParam( wxConfigBase* aConfig ) const override
  221. {
  222. if( !m_Pt_param || !aConfig )
  223. return;
  224. m_Pt_param->clear();
  225. for( int index = 1; ; ++index )
  226. {
  227. wxString key = TrackWidthKey;
  228. double width;
  229. if( !aConfig->Read( key << index, &width ) )
  230. break;
  231. m_Pt_param->push_back( Millimeter2iu( width ) );
  232. }
  233. }
  234. void SaveParam( wxConfigBase* aConfig ) const override
  235. {
  236. if( !m_Pt_param || !aConfig )
  237. return;
  238. for( size_t index = 1; index <= m_Pt_param->size(); ++index )
  239. {
  240. wxString key = TrackWidthKey;
  241. aConfig->Write( key << index, Iu2Millimeter( m_Pt_param->at( index - 1 ) ) );
  242. }
  243. }
  244. };
  245. class PARAM_CFG_VIADIMENSIONS : public PARAM_CFG
  246. {
  247. protected:
  248. std::vector<VIA_DIMENSION>* m_Pt_param; ///< Pointer to the parameter value
  249. public:
  250. PARAM_CFG_VIADIMENSIONS( std::vector<VIA_DIMENSION>* ptparam, const wxChar* group = nullptr ) :
  251. PARAM_CFG( wxEmptyString, PARAM_VIADIMENSIONS, group )
  252. {
  253. m_Pt_param = ptparam;
  254. }
  255. void ReadParam( wxConfigBase* aConfig ) const override
  256. {
  257. if( !m_Pt_param || !aConfig )
  258. return;
  259. m_Pt_param->clear();
  260. for( int index = 1; ; ++index )
  261. {
  262. double diameter = 0.0, drill = 0.0;
  263. wxString key = ViaDiameterKey;
  264. if( !aConfig->Read( key << index, &diameter ) )
  265. break;
  266. key = ViaDrillKey;
  267. drill = aConfig->ReadDouble( key << index, 0.0 );
  268. m_Pt_param->emplace_back( VIA_DIMENSION( Millimeter2iu( diameter ),
  269. Millimeter2iu( drill ) ) );
  270. }
  271. }
  272. void SaveParam( wxConfigBase* aConfig ) const override
  273. {
  274. if( !m_Pt_param || !aConfig )
  275. return;
  276. for( size_t index = 1; index <= m_Pt_param->size(); ++index )
  277. {
  278. wxString key = ViaDiameterKey;
  279. aConfig->Write( key << index, Iu2Millimeter( m_Pt_param->at( index - 1 ).m_Diameter ) );
  280. key = ViaDrillKey;
  281. aConfig->Write( key << index, Iu2Millimeter( m_Pt_param->at( index - 1 ).m_Drill ) );
  282. }
  283. }
  284. };
  285. class PARAM_CFG_DIFFPAIRDIMENSIONS : public PARAM_CFG
  286. {
  287. protected:
  288. std::vector<DIFF_PAIR_DIMENSION>* m_Pt_param; ///< Pointer to the parameter value
  289. public:
  290. PARAM_CFG_DIFFPAIRDIMENSIONS( std::vector<DIFF_PAIR_DIMENSION>* ptparam,
  291. const wxChar* group = nullptr ) :
  292. PARAM_CFG( wxEmptyString, PARAM_DIFFPAIRDIMENSIONS, group )
  293. {
  294. m_Pt_param = ptparam;
  295. }
  296. void ReadParam( wxConfigBase* aConfig ) const override
  297. {
  298. if( !m_Pt_param || !aConfig )
  299. return;
  300. m_Pt_param->clear();
  301. for( int index = 1; ; ++index )
  302. {
  303. double width, gap, viagap;
  304. wxString key = dPairWidthKey;
  305. if( !aConfig->Read( key << index, &width ) )
  306. break;
  307. key = dPairGapKey;
  308. gap = aConfig->ReadDouble( key << index, 0.0 );
  309. key = dPairViaGapKey;
  310. viagap = aConfig->ReadDouble( key << index, 0.0 );
  311. m_Pt_param->emplace_back( DIFF_PAIR_DIMENSION( Millimeter2iu( width ),
  312. Millimeter2iu( gap ),
  313. Millimeter2iu( viagap ) ) );
  314. }
  315. }
  316. void SaveParam( wxConfigBase* aConfig ) const override
  317. {
  318. if( !m_Pt_param || !aConfig )
  319. return;
  320. for( size_t index = 1; index <= m_Pt_param->size(); ++index )
  321. {
  322. wxString key = dPairWidthKey;
  323. aConfig->Write( key << index, Iu2Millimeter( m_Pt_param->at( index - 1 ).m_Width ) );
  324. key = dPairGapKey;
  325. aConfig->Write( key << index, Iu2Millimeter( m_Pt_param->at( index - 1 ).m_Gap ) );
  326. key = dPairViaGapKey;
  327. aConfig->Write( key << index, Iu2Millimeter( m_Pt_param->at( index - 1 ).m_ViaGap ) );
  328. }
  329. }
  330. };
  331. class PARAM_CFG_NETCLASSES : public PARAM_CFG
  332. {
  333. protected:
  334. NETCLASSES* m_Pt_param; ///< Pointer to the parameter value
  335. public:
  336. PARAM_CFG_NETCLASSES( const wxChar* ident, NETCLASSES* ptparam,
  337. const wxChar* group = nullptr ) :
  338. PARAM_CFG( ident, PARAM_NETCLASSES, group )
  339. {
  340. m_Pt_param = ptparam;
  341. }
  342. void ReadParam( wxConfigBase* aConfig ) const override
  343. {
  344. if( !m_Pt_param || !aConfig )
  345. return;
  346. wxString oldPath = aConfig->GetPath();
  347. m_Pt_param->Clear();
  348. for( int index = 0; ; ++index )
  349. {
  350. wxString path = "";
  351. NETCLASSPTR netclass;
  352. wxString netclassName;
  353. if( index == 0 )
  354. path = "Default";
  355. else
  356. path << index;
  357. aConfig->SetPath( oldPath );
  358. aConfig->SetPath( m_Ident );
  359. aConfig->SetPath( path );
  360. if( !aConfig->Read( NetclassNameKey, &netclassName ) )
  361. break;
  362. if( index == 0 )
  363. netclass = m_Pt_param->GetDefault();
  364. else
  365. netclass = std::make_shared<NETCLASS>( netclassName );
  366. #define READ_MM( aKey, aDefault ) Millimeter2iu( aConfig->ReadDouble( aKey, aDefault ) )
  367. netclass->SetClearance( READ_MM( ClearanceKey, netclass->GetClearance() ) );
  368. netclass->SetTrackWidth( READ_MM( TrackWidthKey, netclass->GetTrackWidth() ) );
  369. netclass->SetViaDiameter( READ_MM( ViaDiameterKey, netclass->GetViaDiameter() ) );
  370. netclass->SetViaDrill( READ_MM( ViaDrillKey, netclass->GetViaDrill() ) );
  371. netclass->SetuViaDiameter( READ_MM( uViaDiameterKey, netclass->GetuViaDiameter() ) );
  372. netclass->SetuViaDrill( READ_MM( uViaDrillKey, netclass->GetuViaDrill() ) );
  373. netclass->SetDiffPairWidth( READ_MM( dPairWidthKey, netclass->GetDiffPairWidth() ) );
  374. netclass->SetDiffPairGap( READ_MM( dPairGapKey, netclass->GetDiffPairGap() ) );
  375. netclass->SetDiffPairViaGap( READ_MM( dPairViaGapKey, netclass->GetDiffPairViaGap() ) );
  376. if( index > 0 )
  377. m_Pt_param->Add( netclass );
  378. }
  379. aConfig->SetPath( oldPath );
  380. }
  381. void SaveParam( wxConfigBase* aConfig ) const override
  382. {
  383. if( !m_Pt_param || !aConfig )
  384. return;
  385. wxString oldPath = aConfig->GetPath();
  386. NETCLASSES::const_iterator nc = m_Pt_param->begin();
  387. for( unsigned index = 0; index <= m_Pt_param->GetCount(); ++index )
  388. {
  389. wxString path = "";
  390. NETCLASSPTR netclass;
  391. if( index == 0 )
  392. path = "Default";
  393. else
  394. path << index;
  395. aConfig->SetPath( oldPath );
  396. aConfig->SetPath( m_Ident );
  397. aConfig->SetPath( path );
  398. if( index == 0 )
  399. {
  400. netclass = m_Pt_param->GetDefault();
  401. }
  402. else
  403. {
  404. netclass = nc->second;
  405. ++nc;
  406. }
  407. aConfig->Write( NetclassNameKey, netclass->GetName() );
  408. #define WRITE_MM( aKey, aValue ) aConfig->Write( aKey, Iu2Millimeter( aValue ) )
  409. WRITE_MM( ClearanceKey, netclass->GetClearance() );
  410. WRITE_MM( TrackWidthKey, netclass->GetTrackWidth() );
  411. WRITE_MM( ViaDiameterKey, netclass->GetViaDiameter() );
  412. WRITE_MM( ViaDrillKey, netclass->GetViaDrill() );
  413. WRITE_MM( uViaDiameterKey, netclass->GetuViaDiameter() );
  414. WRITE_MM( uViaDrillKey, netclass->GetuViaDrill() );
  415. WRITE_MM( dPairWidthKey, netclass->GetDiffPairWidth() );
  416. WRITE_MM( dPairGapKey, netclass->GetDiffPairGap() );
  417. WRITE_MM( dPairViaGapKey, netclass->GetDiffPairViaGap() );
  418. }
  419. aConfig->SetPath( oldPath );
  420. }
  421. };
  422. BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() :
  423. m_Pad_Master( NULL )
  424. {
  425. m_HasStackup = false; // no stackup defined by default
  426. LSET all_set = LSET().set();
  427. m_enabledLayers = all_set; // All layers enabled at first.
  428. // SetCopperLayerCount() will adjust this.
  429. SetVisibleLayers( all_set );
  430. // set all but hidden text as visible.
  431. m_visibleElements = ~( 1 << GAL_LAYER_INDEX( LAYER_MOD_TEXT_INVISIBLE ) );
  432. SetCopperLayerCount( 2 ); // Default design is a double sided board
  433. m_CurrentViaType = VIATYPE::THROUGH;
  434. // if true, when creating a new track starting on an existing track, use this track width
  435. m_UseConnectedTrackWidth = false;
  436. m_BlindBuriedViaAllowed = false;
  437. m_MicroViasAllowed = false;
  438. // First is always the reference designator
  439. m_DefaultFPTextItems.emplace_back( wxT( "REF**" ), true, F_SilkS );
  440. // Second is always the value
  441. m_DefaultFPTextItems.emplace_back( wxT( "" ), true, F_Fab );
  442. // Any following ones are freebies
  443. m_DefaultFPTextItems.emplace_back( wxT( "${REF}" ), true, F_Fab );
  444. m_LineThickness[ LAYER_CLASS_SILK ] = Millimeter2iu( DEFAULT_SILK_LINE_WIDTH );
  445. m_TextSize[ LAYER_CLASS_SILK ] = wxSize( Millimeter2iu( DEFAULT_SILK_TEXT_SIZE ),
  446. Millimeter2iu( DEFAULT_SILK_TEXT_SIZE ) );
  447. m_TextThickness[ LAYER_CLASS_SILK ] = Millimeter2iu( DEFAULT_SILK_TEXT_WIDTH );
  448. m_TextItalic[ LAYER_CLASS_SILK ] = false;
  449. m_TextUpright[ LAYER_CLASS_SILK ] = false;
  450. m_LineThickness[ LAYER_CLASS_COPPER ] = Millimeter2iu( DEFAULT_COPPER_LINE_WIDTH );
  451. m_TextSize[ LAYER_CLASS_COPPER ] = wxSize( Millimeter2iu( DEFAULT_COPPER_TEXT_SIZE ),
  452. Millimeter2iu( DEFAULT_COPPER_TEXT_SIZE ) );
  453. m_TextThickness[ LAYER_CLASS_COPPER ] = Millimeter2iu( DEFAULT_COPPER_TEXT_WIDTH );
  454. m_TextItalic[ LAYER_CLASS_COPPER ] = false;
  455. m_TextUpright[ LAYER_CLASS_COPPER ] = false;
  456. // Edges & Courtyards; text properties aren't used but better to have them holding
  457. // reasonable values than not.
  458. m_LineThickness[ LAYER_CLASS_EDGES ] = Millimeter2iu( DEFAULT_EDGE_WIDTH );
  459. m_TextSize[ LAYER_CLASS_EDGES ] = wxSize( Millimeter2iu( DEFAULT_TEXT_SIZE ),
  460. Millimeter2iu( DEFAULT_TEXT_SIZE ) );
  461. m_TextThickness[ LAYER_CLASS_EDGES ] = Millimeter2iu( DEFAULT_TEXT_WIDTH );
  462. m_TextItalic[ LAYER_CLASS_EDGES ] = false;
  463. m_TextUpright[ LAYER_CLASS_EDGES ] = false;
  464. m_LineThickness[ LAYER_CLASS_COURTYARD ] = Millimeter2iu( DEFAULT_COURTYARD_WIDTH );
  465. m_TextSize[ LAYER_CLASS_COURTYARD ] = wxSize( Millimeter2iu( DEFAULT_TEXT_SIZE ),
  466. Millimeter2iu( DEFAULT_TEXT_SIZE ) );
  467. m_TextThickness[ LAYER_CLASS_COURTYARD ] = Millimeter2iu( DEFAULT_TEXT_WIDTH );
  468. m_TextItalic[ LAYER_CLASS_COURTYARD ] = false;
  469. m_TextUpright[ LAYER_CLASS_COURTYARD ] = false;
  470. m_LineThickness[ LAYER_CLASS_FAB ] = Millimeter2iu( DEFAULT_LINE_WIDTH );
  471. m_TextSize[ LAYER_CLASS_FAB ] = wxSize( Millimeter2iu( DEFAULT_TEXT_SIZE ),
  472. Millimeter2iu( DEFAULT_TEXT_SIZE ) );
  473. m_TextThickness[ LAYER_CLASS_FAB ] = Millimeter2iu( DEFAULT_TEXT_WIDTH );
  474. m_TextItalic[ LAYER_CLASS_FAB ] = false;
  475. m_TextUpright[ LAYER_CLASS_FAB ] = false;
  476. m_LineThickness[ LAYER_CLASS_OTHERS ] = Millimeter2iu( DEFAULT_LINE_WIDTH );
  477. m_TextSize[ LAYER_CLASS_OTHERS ] = wxSize( Millimeter2iu( DEFAULT_TEXT_SIZE ),
  478. Millimeter2iu( DEFAULT_TEXT_SIZE ) );
  479. m_TextThickness[ LAYER_CLASS_OTHERS ] = Millimeter2iu( DEFAULT_TEXT_WIDTH );
  480. m_TextItalic[ LAYER_CLASS_OTHERS ] = false;
  481. m_TextUpright[ LAYER_CLASS_OTHERS ] = false;
  482. m_DimensionUnits = 0; // Inches
  483. m_DimensionPrecision = 1; // 0.001mm / 0.1 mil
  484. m_useCustomTrackVia = false;
  485. m_customTrackWidth = Millimeter2iu( DEFAULT_CUSTOMTRACKWIDTH );
  486. m_customViaSize.m_Diameter = Millimeter2iu( DEFAULT_VIASMINSIZE );
  487. m_customViaSize.m_Drill = Millimeter2iu( DEFAULT_MINTHROUGHDRILL );
  488. m_useCustomDiffPair = false;
  489. m_customDiffPair.m_Width = Millimeter2iu( DEFAULT_CUSTOMDPAIRWIDTH );
  490. m_customDiffPair.m_Gap = Millimeter2iu( DEFAULT_CUSTOMDPAIRGAP );
  491. m_customDiffPair.m_ViaGap = Millimeter2iu( DEFAULT_CUSTOMDPAIRVIAGAP );
  492. m_MinClearance = Millimeter2iu( DEFAULT_MINCLEARANCE );
  493. m_TrackMinWidth = Millimeter2iu( DEFAULT_TRACKMINWIDTH );
  494. m_ViasMinAnnulus = Millimeter2iu( DEFAULT_VIASMINSIZE - DEFAULT_MINTHROUGHDRILL ) / 2;
  495. m_ViasMinSize = Millimeter2iu( DEFAULT_VIASMINSIZE );
  496. m_MinThroughDrill = Millimeter2iu( DEFAULT_MINTHROUGHDRILL );
  497. m_MicroViasMinSize = Millimeter2iu( DEFAULT_MICROVIASMINSIZE );
  498. m_MicroViasMinDrill = Millimeter2iu( DEFAULT_MICROVIASMINDRILL );
  499. m_CopperEdgeClearance = Millimeter2iu( DEFAULT_COPPEREDGECLEARANCE );
  500. m_HoleToHoleMin = Millimeter2iu( DEFAULT_HOLETOHOLEMIN );
  501. for( int errorCode = DRCE_FIRST; errorCode <= DRCE_LAST; ++errorCode )
  502. m_DRCSeverities[ errorCode ] = RPT_SEVERITY_ERROR;
  503. m_DRCSeverities[ DRCE_MISSING_COURTYARD ] = RPT_SEVERITY_IGNORE;
  504. m_DRCSeverities[ DRCE_PTH_IN_COURTYARD ] = RPT_SEVERITY_IGNORE;
  505. m_DRCSeverities[ DRCE_NPTH_IN_COURTYARD ] = RPT_SEVERITY_IGNORE;
  506. m_DRCSeverities[ DRCE_DANGLING_TRACK ] = RPT_SEVERITY_WARNING;
  507. m_DRCSeverities[ DRCE_DANGLING_VIA ] = RPT_SEVERITY_WARNING;
  508. m_DRCSeverities[ DRCE_MISSING_FOOTPRINT ] = RPT_SEVERITY_WARNING;
  509. m_DRCSeverities[ DRCE_DUPLICATE_FOOTPRINT ] = RPT_SEVERITY_WARNING;
  510. m_DRCSeverities[ DRCE_EXTRA_FOOTPRINT ] = RPT_SEVERITY_WARNING;
  511. m_MaxError = ARC_HIGH_DEF;
  512. m_ZoneUseNoOutlineInFill = false; // Use compatibility mode by default
  513. // Global mask margins:
  514. m_SolderMaskMargin = Millimeter2iu( DEFAULT_SOLDERMASK_CLEARANCE );
  515. m_SolderMaskMinWidth = Millimeter2iu( DEFAULT_SOLDERMASK_MIN_WIDTH );
  516. m_SolderPasteMargin = 0; // Solder paste margin absolute value
  517. m_SolderPasteMarginRatio = 0.0; // Solder paste margin as a ratio of pad size
  518. // The final margin is the sum of these 2 values
  519. // Usually < 0 because the mask is smaller than pad
  520. // Layer thickness for 3D viewer
  521. m_boardThickness = Millimeter2iu( DEFAULT_BOARD_THICKNESS_MM );
  522. m_viaSizeIndex = 0;
  523. m_trackWidthIndex = 0;
  524. m_diffPairIndex = 0;
  525. }
  526. // Add parameters to save in project config.
  527. // values are saved in mm
  528. void BOARD_DESIGN_SETTINGS::AppendConfigs( BOARD* aBoard, std::vector<PARAM_CFG*>* aResult )
  529. {
  530. aResult->push_back( new PARAM_CFG_LAYERS( aBoard ) );
  531. aResult->push_back( new PARAM_CFG_BOOL( wxT( "AllowMicroVias" ),
  532. &m_MicroViasAllowed, false ) );
  533. aResult->push_back( new PARAM_CFG_BOOL( wxT( "AllowBlindVias" ),
  534. &m_BlindBuriedViaAllowed, false ) );
  535. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinClearance" ),
  536. &m_MinClearance,
  537. Millimeter2iu( DEFAULT_MINCLEARANCE ), Millimeter2iu( 0.01 ), Millimeter2iu( 25.0 ),
  538. nullptr, MM_PER_IU ) );
  539. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinTrackWidth" ),
  540. &m_TrackMinWidth,
  541. Millimeter2iu( DEFAULT_TRACKMINWIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 25.0 ),
  542. nullptr, MM_PER_IU ) );
  543. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinViaAnnulus" ),
  544. &m_ViasMinAnnulus,
  545. Millimeter2iu( DEFAULT_VIASMINSIZE ), Millimeter2iu( 0.01 ), Millimeter2iu( 25.0 ),
  546. nullptr, MM_PER_IU ) );
  547. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinViaDiameter" ),
  548. &m_ViasMinSize,
  549. Millimeter2iu( DEFAULT_VIASMINSIZE ), Millimeter2iu( 0.01 ), Millimeter2iu( 25.0 ),
  550. nullptr, MM_PER_IU ) );
  551. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinThroughDrill" ),
  552. &m_MinThroughDrill,
  553. Millimeter2iu( DEFAULT_MINTHROUGHDRILL ), Millimeter2iu( 0.01 ), Millimeter2iu( 25.0 ),
  554. nullptr, MM_PER_IU, wxT( "MinViaDrill" ) ) );
  555. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinMicroViaDiameter" ),
  556. &m_MicroViasMinSize,
  557. Millimeter2iu( DEFAULT_MICROVIASMINSIZE ), Millimeter2iu( 0.01 ), Millimeter2iu( 10.0 ),
  558. nullptr, MM_PER_IU ) );
  559. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinMicroViaDrill" ),
  560. &m_MicroViasMinDrill,
  561. Millimeter2iu( DEFAULT_MICROVIASMINDRILL ), Millimeter2iu( 0.01 ), Millimeter2iu( 10.0 ),
  562. nullptr, MM_PER_IU ) );
  563. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "MinHoleToHole" ),
  564. &m_HoleToHoleMin,
  565. Millimeter2iu( DEFAULT_HOLETOHOLEMIN ), Millimeter2iu( 0.0 ), Millimeter2iu( 10.0 ),
  566. nullptr, MM_PER_IU ) );
  567. aResult->push_back( new PARAM_CFG_SEVERITIES( aBoard ) );
  568. // Note: a clearance of -0.01 is a flag indicating we should use the legacy (pre-6.0) method
  569. // based on the edge cut thicknesses.
  570. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "CopperEdgeClearance" ),
  571. &m_CopperEdgeClearance,
  572. Millimeter2iu( LEGACY_COPPEREDGECLEARANCE ), Millimeter2iu( -0.01 ), Millimeter2iu( 25.0 ),
  573. nullptr, MM_PER_IU ) );
  574. aResult->push_back( new PARAM_CFG_TRACKWIDTHS( &m_TrackWidthList ) );
  575. aResult->push_back( new PARAM_CFG_VIADIMENSIONS( &m_ViasDimensionsList ) );
  576. aResult->push_back( new PARAM_CFG_DIFFPAIRDIMENSIONS( &m_DiffPairDimensionsList ) );
  577. aResult->push_back( new PARAM_CFG_NETCLASSES( wxT( "Netclasses" ), &m_NetClasses ) );
  578. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SilkLineWidth" ),
  579. &m_LineThickness[ LAYER_CLASS_SILK ],
  580. Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  581. nullptr, MM_PER_IU, wxT( "ModuleOutlineThickness" ) ) );
  582. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SilkTextSizeV" ),
  583. &m_TextSize[ LAYER_CLASS_SILK ].y,
  584. Millimeter2iu( DEFAULT_SILK_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  585. nullptr, MM_PER_IU, wxT( "ModuleTextSizeV" ) ) );
  586. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SilkTextSizeH" ),
  587. &m_TextSize[ LAYER_CLASS_SILK ].x,
  588. Millimeter2iu( DEFAULT_SILK_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  589. nullptr, MM_PER_IU, wxT( "ModuleTextSizeH" ) ) );
  590. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SilkTextSizeThickness" ),
  591. &m_TextThickness[ LAYER_CLASS_SILK ],
  592. Millimeter2iu( DEFAULT_SILK_TEXT_WIDTH ), 1, TEXTS_MAX_WIDTH,
  593. nullptr, MM_PER_IU, wxT( "ModuleTextSizeThickness" ) ) );
  594. aResult->push_back( new PARAM_CFG_BOOL( wxT( "SilkTextItalic" ),
  595. &m_TextItalic[ LAYER_CLASS_SILK ], false ) );
  596. aResult->push_back( new PARAM_CFG_BOOL( wxT( "SilkTextUpright" ),
  597. &m_TextUpright[ LAYER_CLASS_SILK ], true ) );
  598. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "CopperLineWidth" ),
  599. &m_LineThickness[ LAYER_CLASS_COPPER ],
  600. Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  601. nullptr, MM_PER_IU, wxT( "DrawSegmentWidth" ) ) );
  602. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "CopperTextSizeV" ),
  603. &m_TextSize[ LAYER_CLASS_COPPER ].y,
  604. Millimeter2iu( DEFAULT_COPPER_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  605. nullptr, MM_PER_IU, wxT( "PcbTextSizeV" ) ) );
  606. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "CopperTextSizeH" ),
  607. &m_TextSize[ LAYER_CLASS_COPPER ].x,
  608. Millimeter2iu( DEFAULT_COPPER_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  609. nullptr, MM_PER_IU, wxT( "PcbTextSizeH" ) ) );
  610. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "CopperTextThickness" ),
  611. &m_TextThickness[ LAYER_CLASS_COPPER ],
  612. Millimeter2iu( DEFAULT_COPPER_TEXT_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  613. nullptr, MM_PER_IU, wxT( "PcbTextThickness" ) ) );
  614. aResult->push_back( new PARAM_CFG_BOOL( wxT( "CopperTextItalic" ),
  615. &m_TextItalic[ LAYER_CLASS_COPPER ], false ) );
  616. aResult->push_back( new PARAM_CFG_BOOL( wxT( "CopperTextUpright" ),
  617. &m_TextUpright[ LAYER_CLASS_COPPER ], true ) );
  618. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "EdgeCutLineWidth" ),
  619. &m_LineThickness[ LAYER_CLASS_EDGES ],
  620. Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  621. nullptr, MM_PER_IU, wxT( "BoardOutlineThickness" ) ) );
  622. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "CourtyardLineWidth" ),
  623. &m_LineThickness[ LAYER_CLASS_COURTYARD ],
  624. Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  625. nullptr, MM_PER_IU ) );
  626. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "FabLineWidth" ),
  627. &m_LineThickness[ LAYER_CLASS_FAB ],
  628. Millimeter2iu( DEFAULT_LINE_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  629. nullptr, MM_PER_IU ) );
  630. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "FabTextSizeV" ),
  631. &m_TextSize[ LAYER_CLASS_FAB ].x,
  632. Millimeter2iu( DEFAULT_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  633. nullptr, MM_PER_IU ) );
  634. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "FabTextSizeH" ),
  635. &m_TextSize[ LAYER_CLASS_FAB ].y,
  636. Millimeter2iu( DEFAULT_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  637. nullptr, MM_PER_IU ) );
  638. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "FabTextSizeThickness" ),
  639. &m_TextThickness[ LAYER_CLASS_FAB ],
  640. Millimeter2iu( DEFAULT_TEXT_WIDTH ), 1, TEXTS_MAX_WIDTH,
  641. nullptr, MM_PER_IU ) );
  642. aResult->push_back( new PARAM_CFG_BOOL( wxT( "FabTextItalic" ),
  643. &m_TextItalic[ LAYER_CLASS_FAB ], false ) );
  644. aResult->push_back( new PARAM_CFG_BOOL( wxT( "FabTextUpright" ),
  645. &m_TextUpright[ LAYER_CLASS_FAB ], true ) );
  646. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "OthersLineWidth" ),
  647. &m_LineThickness[ LAYER_CLASS_OTHERS ],
  648. Millimeter2iu( DEFAULT_SILK_LINE_WIDTH ), Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
  649. nullptr, MM_PER_IU, wxT( "ModuleOutlineThickness" ) ) );
  650. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "OthersTextSizeV" ),
  651. &m_TextSize[ LAYER_CLASS_OTHERS ].x,
  652. Millimeter2iu( DEFAULT_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  653. nullptr, MM_PER_IU ) );
  654. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "OthersTextSizeH" ),
  655. &m_TextSize[ LAYER_CLASS_OTHERS ].y,
  656. Millimeter2iu( DEFAULT_TEXT_SIZE ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
  657. nullptr, MM_PER_IU ) );
  658. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "OthersTextSizeThickness" ),
  659. &m_TextThickness[ LAYER_CLASS_OTHERS ],
  660. Millimeter2iu( DEFAULT_TEXT_WIDTH ), 1, TEXTS_MAX_WIDTH,
  661. nullptr, MM_PER_IU ) );
  662. aResult->push_back( new PARAM_CFG_BOOL( wxT( "OthersTextItalic" ),
  663. &m_TextItalic[ LAYER_CLASS_OTHERS ], false ) );
  664. aResult->push_back( new PARAM_CFG_BOOL( wxT( "OthersTextUpright" ),
  665. &m_TextUpright[ LAYER_CLASS_OTHERS ], true ) );
  666. aResult->push_back( new PARAM_CFG_INT( wxT( "DimensionUnits" ),
  667. &m_DimensionUnits, 0, 0, 2 ) );
  668. aResult->push_back( new PARAM_CFG_INT( wxT( "DimensionPrecision" ),
  669. &m_DimensionPrecision, 1, 0, 2 ) );
  670. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SolderMaskClearance" ),
  671. &m_SolderMaskMargin,
  672. Millimeter2iu( DEFAULT_SOLDERMASK_CLEARANCE ), Millimeter2iu( -1.0 ), Millimeter2iu( 1.0 ),
  673. nullptr, MM_PER_IU ) );
  674. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SolderMaskMinWidth" ),
  675. &m_SolderMaskMinWidth,
  676. Millimeter2iu( DEFAULT_SOLDERMASK_MIN_WIDTH ), 0, Millimeter2iu( 1.0 ),
  677. nullptr, MM_PER_IU ) );
  678. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SolderPasteClearance" ),
  679. &m_SolderPasteMargin,
  680. Millimeter2iu( DEFAULT_SOLDERPASTE_CLEARANCE ), Millimeter2iu( -1.0 ), Millimeter2iu( 1.0 ),
  681. nullptr, MM_PER_IU ) );
  682. aResult->push_back( new PARAM_CFG_DOUBLE( wxT( "SolderPasteRatio" ),
  683. &m_SolderPasteMarginRatio,
  684. DEFAULT_SOLDERPASTE_RATIO, -0.5, 1.0 ) );
  685. }
  686. int BOARD_DESIGN_SETTINGS::GetSeverity( int aDRCErrorCode )
  687. {
  688. return m_DRCSeverities[ aDRCErrorCode ];
  689. }
  690. bool BOARD_DESIGN_SETTINGS::Ignore( int aDRCErrorCode )
  691. {
  692. return m_DRCSeverities[ aDRCErrorCode ] == RPT_SEVERITY_IGNORE;
  693. }
  694. bool BOARD_DESIGN_SETTINGS::SetCurrentNetClass( const wxString& aNetClassName )
  695. {
  696. NETCLASSPTR netClass = m_NetClasses.Find( aNetClassName );
  697. bool lists_sizes_modified = false;
  698. // if not found (should not happen) use the default
  699. if( !netClass )
  700. netClass = m_NetClasses.GetDefault();
  701. m_currentNetClassName = netClass->GetName();
  702. // Initialize others values:
  703. if( m_TrackWidthList.size() == 0 )
  704. {
  705. lists_sizes_modified = true;
  706. m_TrackWidthList.push_back( 0 );
  707. }
  708. if( m_ViasDimensionsList.size() == 0 )
  709. {
  710. lists_sizes_modified = true;
  711. m_ViasDimensionsList.emplace_back( VIA_DIMENSION() );
  712. }
  713. if( m_DiffPairDimensionsList.size() == 0 )
  714. {
  715. lists_sizes_modified = true;
  716. m_DiffPairDimensionsList.emplace_back( DIFF_PAIR_DIMENSION() );
  717. }
  718. /* note the m_ViasDimensionsList[0] and m_TrackWidthList[0] values
  719. * are always the Netclass values
  720. */
  721. if( m_TrackWidthList[0] != netClass->GetTrackWidth() )
  722. {
  723. lists_sizes_modified = true;
  724. m_TrackWidthList[0] = netClass->GetTrackWidth();
  725. }
  726. if( m_ViasDimensionsList[0].m_Diameter != netClass->GetViaDiameter() )
  727. {
  728. lists_sizes_modified = true;
  729. m_ViasDimensionsList[0].m_Diameter = netClass->GetViaDiameter();
  730. }
  731. if( m_ViasDimensionsList[0].m_Drill != netClass->GetViaDrill() )
  732. {
  733. lists_sizes_modified = true;
  734. m_ViasDimensionsList[0].m_Drill = netClass->GetViaDrill();
  735. }
  736. if( m_DiffPairDimensionsList[0].m_Width != netClass->GetDiffPairWidth() )
  737. {
  738. lists_sizes_modified = true;
  739. m_DiffPairDimensionsList[0].m_Width = netClass->GetDiffPairWidth();
  740. }
  741. if( m_DiffPairDimensionsList[0].m_Gap != netClass->GetDiffPairGap() )
  742. {
  743. lists_sizes_modified = true;
  744. m_DiffPairDimensionsList[0].m_Gap = netClass->GetDiffPairGap();
  745. }
  746. if( m_DiffPairDimensionsList[0].m_ViaGap != netClass->GetDiffPairViaGap() )
  747. {
  748. lists_sizes_modified = true;
  749. m_DiffPairDimensionsList[0].m_ViaGap = netClass->GetDiffPairViaGap();
  750. }
  751. if( GetViaSizeIndex() >= m_ViasDimensionsList.size() )
  752. SetViaSizeIndex( m_ViasDimensionsList.size() );
  753. if( GetTrackWidthIndex() >= m_TrackWidthList.size() )
  754. SetTrackWidthIndex( m_TrackWidthList.size() );
  755. if( GetDiffPairIndex() >= m_DiffPairDimensionsList.size() )
  756. SetDiffPairIndex( m_DiffPairDimensionsList.size() );
  757. return lists_sizes_modified;
  758. }
  759. int BOARD_DESIGN_SETTINGS::GetBiggestClearanceValue()
  760. {
  761. int clearance = GetDefault()->GetClearance();
  762. for( const std::pair<const wxString, NETCLASSPTR>& netclass : m_NetClasses.NetClasses() )
  763. clearance = std::max( clearance, netclass.second->GetClearance() );
  764. for( const DRC_RULE* rule : m_DRCRules )
  765. clearance = std::max( clearance, rule->m_Clearance.Min );
  766. return clearance;
  767. }
  768. int BOARD_DESIGN_SETTINGS::GetSmallestClearanceValue()
  769. {
  770. int clearance = GetDefault()->GetClearance();
  771. for( const std::pair<const wxString, NETCLASSPTR>& netclass : m_NetClasses.NetClasses() )
  772. clearance = std::min( clearance, netclass.second->GetClearance() );
  773. return clearance;
  774. }
  775. int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaSize()
  776. {
  777. NETCLASSPTR netclass = m_NetClasses.Find( m_currentNetClassName );
  778. return netclass->GetuViaDiameter();
  779. }
  780. int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaDrill()
  781. {
  782. NETCLASSPTR netclass = m_NetClasses.Find( m_currentNetClassName );
  783. return netclass->GetuViaDrill();
  784. }
  785. void BOARD_DESIGN_SETTINGS::SetViaSizeIndex( unsigned aIndex )
  786. {
  787. m_viaSizeIndex = std::min( aIndex, (unsigned) m_ViasDimensionsList.size() );
  788. m_useCustomTrackVia = false;
  789. }
  790. int BOARD_DESIGN_SETTINGS::GetCurrentViaDrill() const
  791. {
  792. int drill;
  793. if( m_useCustomTrackVia )
  794. drill = m_customViaSize.m_Drill;
  795. else
  796. drill = m_ViasDimensionsList[m_viaSizeIndex].m_Drill;
  797. return drill > 0 ? drill : -1;
  798. }
  799. void BOARD_DESIGN_SETTINGS::SetTrackWidthIndex( unsigned aIndex )
  800. {
  801. m_trackWidthIndex = std::min( aIndex, (unsigned) m_TrackWidthList.size() );
  802. m_useCustomTrackVia = false;
  803. }
  804. void BOARD_DESIGN_SETTINGS::SetDiffPairIndex( unsigned aIndex )
  805. {
  806. m_diffPairIndex = std::min( aIndex, (unsigned) 8 );
  807. m_useCustomDiffPair = false;
  808. }
  809. void BOARD_DESIGN_SETTINGS::SetMinHoleSeparation( int aDistance )
  810. {
  811. m_HoleToHoleMin = aDistance;
  812. }
  813. void BOARD_DESIGN_SETTINGS::SetCopperEdgeClearance( int aDistance )
  814. {
  815. m_CopperEdgeClearance = aDistance;
  816. }
  817. void BOARD_DESIGN_SETTINGS::SetVisibleAlls()
  818. {
  819. SetVisibleLayers( LSET().set() );
  820. m_visibleElements = -1;
  821. }
  822. void BOARD_DESIGN_SETTINGS::SetLayerVisibility( PCB_LAYER_ID aLayer, bool aNewState )
  823. {
  824. m_visibleLayers.set( aLayer, aNewState && IsLayerEnabled( aLayer ));
  825. }
  826. void BOARD_DESIGN_SETTINGS::SetElementVisibility( GAL_LAYER_ID aElementCategory, bool aNewState )
  827. {
  828. if( aNewState )
  829. m_visibleElements |= 1 << GAL_LAYER_INDEX( aElementCategory );
  830. else
  831. m_visibleElements &= ~( 1 << GAL_LAYER_INDEX( aElementCategory ) );
  832. }
  833. void BOARD_DESIGN_SETTINGS::SetCopperLayerCount( int aNewLayerCount )
  834. {
  835. m_copperLayerCount = aNewLayerCount;
  836. // Update only enabled copper layers mask
  837. m_enabledLayers &= ~LSET::AllCuMask();
  838. m_enabledLayers |= LSET::AllCuMask( aNewLayerCount );
  839. }
  840. void BOARD_DESIGN_SETTINGS::SetEnabledLayers( LSET aMask )
  841. {
  842. // Back and front layers are always enabled.
  843. aMask.set( B_Cu ).set( F_Cu );
  844. m_enabledLayers = aMask;
  845. // A disabled layer cannot be visible
  846. m_visibleLayers &= aMask;
  847. // update m_CopperLayerCount to ensure its consistency with m_EnabledLayers
  848. m_copperLayerCount = ( aMask & LSET::AllCuMask() ).count();
  849. }
  850. // Return the layer class index { silk, copper, edges & courtyards, fab, others } of the
  851. // given layer.
  852. int BOARD_DESIGN_SETTINGS::GetLayerClass( PCB_LAYER_ID aLayer ) const
  853. {
  854. if( aLayer == F_SilkS || aLayer == B_SilkS )
  855. return LAYER_CLASS_SILK;
  856. else if( IsCopperLayer( aLayer ) )
  857. return LAYER_CLASS_COPPER;
  858. else if( aLayer == Edge_Cuts )
  859. return LAYER_CLASS_EDGES;
  860. else if( aLayer == F_CrtYd || aLayer == B_CrtYd )
  861. return LAYER_CLASS_COURTYARD;
  862. else if( aLayer == F_Fab || aLayer == B_Fab )
  863. return LAYER_CLASS_FAB;
  864. else
  865. return LAYER_CLASS_OTHERS;
  866. }
  867. int BOARD_DESIGN_SETTINGS::GetLineThickness( PCB_LAYER_ID aLayer ) const
  868. {
  869. return m_LineThickness[ GetLayerClass( aLayer ) ];
  870. }
  871. wxSize BOARD_DESIGN_SETTINGS::GetTextSize( PCB_LAYER_ID aLayer ) const
  872. {
  873. return m_TextSize[ GetLayerClass( aLayer ) ];
  874. }
  875. int BOARD_DESIGN_SETTINGS::GetTextThickness( PCB_LAYER_ID aLayer ) const
  876. {
  877. return m_TextThickness[ GetLayerClass( aLayer ) ];
  878. }
  879. bool BOARD_DESIGN_SETTINGS::GetTextItalic( PCB_LAYER_ID aLayer ) const
  880. {
  881. return m_TextItalic[ GetLayerClass( aLayer ) ];
  882. }
  883. bool BOARD_DESIGN_SETTINGS::GetTextUpright( PCB_LAYER_ID aLayer ) const
  884. {
  885. return m_TextUpright[ GetLayerClass( aLayer ) ];
  886. }