KiCad PCB EDA Suite
board_design_settings.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) 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 
24 #include <dimension.h>
25 #include <track.h>
27 #include <kiface_i.h>
28 #include <board_design_settings.h>
29 #include <drc/drc_item.h>
30 #include <drc/drc_engine.h>
31 #include <settings/parameters.h>
32 #include <project/project_file.h>
33 #include <advanced_config.h>
34 
35 const int bdsSchemaVersion = 2;
36 
37 
38 BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
39  NESTED_SETTINGS( "board_design_settings", bdsSchemaVersion, aParent, aPath ),
40  m_Pad_Master( NULL )
41 {
42  // We want to leave alone parameters that aren't found in the project JSON as they may be
43  // initialized by the board file parser before NESTED_SETTINGS::LoadFromFile is called.
44  m_resetParamsIfMissing = false;
45 
46  // Create a default NETCLASS list so that things don't break horribly if there's no project
47  // loaded. This also is used during file load for legacy boards that have netclasses stored
48  // in the file. After load, this information will be moved to the project and the pointer
49  // updated.
51 
52  m_HasStackup = false; // no stackup defined by default
53 
54  LSET all_set = LSET().set();
55  m_enabledLayers = all_set; // All layers enabled at first.
56  // SetCopperLayerCount() will adjust this.
57 
58  SetCopperLayerCount( 2 ); // Default design is a double sided board
60 
61  // if true, when creating a new track starting on an existing track, use this track width
63 
65  m_MicroViasAllowed = false;
66 
67  // First is always the reference designator
68  m_DefaultFPTextItems.emplace_back( wxT( "REF**" ), true, F_SilkS );
69  // Second is always the value
70  m_DefaultFPTextItems.emplace_back( wxT( "" ), true, F_Fab );
71  // Any following ones are freebies
72  m_DefaultFPTextItems.emplace_back( wxT( "${REF}" ), true, F_Fab );
73 
78  m_TextItalic[ LAYER_CLASS_SILK ] = false;
80 
87 
88  // Edges & Courtyards; text properties aren't used but better to have them holding
89  // reasonable values than not.
96 
103 
108  m_TextItalic[ LAYER_CLASS_FAB ] = false;
109  m_TextUpright[ LAYER_CLASS_FAB ] = false;
110 
115  m_TextItalic[ LAYER_CLASS_OTHERS ] = false;
117 
126 
127  m_useCustomTrackVia = false;
131 
132  m_useCustomDiffPair = false;
136 
148 
149  for( int errorCode = DRCE_FIRST; errorCode <= DRCE_LAST; ++errorCode )
150  m_DRCSeverities[ errorCode ] = RPT_SEVERITY_ERROR;
151 
155 
158 
163 
164  m_MaxError = ARC_HIGH_DEF;
165  m_ZoneFillVersion = 6; // Use new algo by default to fill zones
166  m_ZoneKeepExternalFillets = false; // Use new algo by default. Legacy boards might
167  // want to set it to true for old algo....
168 
169  // Global mask margins:
172 
173  // Solder paste margin absolute value
175  // Solder paste margin as a ratio of pad size
176  // The final margin is the sum of these 2 values
177  // Usually < 0 because the mask is smaller than pad
179 
180  // Layer thickness for 3D viewer
182 
183  m_viaSizeIndex = 0;
184  m_trackWidthIndex = 0;
185  m_diffPairIndex = 0;
186 
187  // Parameters stored in JSON in the project file
188 
189  // NOTE: Previously, BOARD_DESIGN_SETTINGS stored the basic board layer information (layer
190  // names and enable/disable state) in the project file even though this information is also
191  // stored in the board file. This was implemented for importing these settings from another
192  // project. Going forward, the import feature will just import from other board files (since
193  // we could have multi-board projects in the future anyway) so this functionality is dropped.
194 
195  m_params.emplace_back( new PARAM<bool>( "rules.allow_microvias", &m_MicroViasAllowed, false ) );
196 
197  m_params.emplace_back( new PARAM<bool>( "rules.allow_blind_buried_vias",
198  &m_BlindBuriedViaAllowed, false ) );
199 
200  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_clearance", &m_MinClearance,
202  MM_PER_IU ) );
203 
204  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_track_width", &m_TrackMinWidth,
206  MM_PER_IU ) );
207 
208  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_via_annular_width", &m_ViasMinAnnulus,
210  MM_PER_IU ) );
211 
212  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_via_diameter", &m_ViasMinSize,
214  MM_PER_IU ) );
215 
216  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_through_hole_diameter",
218  Millimeter2iu( 25.0 ), MM_PER_IU ) );
219 
220  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_microvia_diameter",
222  Millimeter2iu( 10.0 ), MM_PER_IU ) );
223 
224  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_microvia_drill", &m_MicroViasMinDrill,
226  Millimeter2iu( 10.0 ), MM_PER_IU ) );
227 
228  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_hole_to_hole", &m_HoleToHoleMin,
230  MM_PER_IU ) );
231 
232  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_hole_clearance", &m_HoleClearance,
234  MM_PER_IU ) );
235 
236  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_silk_clearance", &m_SilkClearance,
238  MM_PER_IU ) );
239 
240  // Note: a clearance of -0.01 is a flag indicating we should use the legacy (pre-6.0) method
241  // based on the edge cut thicknesses.
242  m_params.emplace_back( new PARAM_SCALED<int>( "rules.min_copper_edge_clearance",
244  Millimeter2iu( -0.01 ), Millimeter2iu( 25.0 ), MM_PER_IU ) );
245 
246  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "rule_severities",
247  [&]() -> nlohmann::json
248  {
249  nlohmann::json ret = {};
250 
251  for( const RC_ITEM& item : DRC_ITEM::GetItemsWithSeverities() )
252  {
253  wxString name = item.GetSettingsKey();
254  int code = item.GetErrorCode();
255 
256  if( name.IsEmpty() || m_DRCSeverities.count( code ) == 0 )
257  continue;
258 
259  ret[std::string( name.ToUTF8() )] = SeverityToString( m_DRCSeverities[code] );
260  }
261 
262  return ret;
263  },
264  [&]( const nlohmann::json& aJson )
265  {
266  if( !aJson.is_object() )
267  return;
268 
269  for( const RC_ITEM& item : DRC_ITEM::GetItemsWithSeverities() )
270  {
271  wxString name = item.GetSettingsKey();
272  std::string key( name.ToUTF8() );
273 
274  if( aJson.contains( key ) )
275  m_DRCSeverities[item.GetErrorCode()] = SeverityFromString( aJson[key] );
276  }
277  }, {} ) );
278 
279  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drc_exclusions",
280  [&]() -> nlohmann::json
281  {
282  nlohmann::json js = nlohmann::json::array();
283 
284  for( const auto& entry : m_DrcExclusions )
285  js.push_back( entry );
286 
287  return js;
288  },
289  [&]( const nlohmann::json& aObj )
290  {
291  m_DrcExclusions.clear();
292 
293  if( !aObj.is_array() )
294  return;
295 
296  for( const nlohmann::json& entry : aObj )
297  {
298  if( entry.empty() )
299  continue;
300 
301  m_DrcExclusions.insert( entry.get<wxString>() );
302  }
303  },
304  {} ) );
305 
306  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "track_widths",
307  [&]() -> nlohmann::json
308  {
309  nlohmann::json js = nlohmann::json::array();
310 
311  for( const int& width : m_TrackWidthList )
312  js.push_back( Iu2Millimeter( width ) );
313 
314  return js;
315  },
316  [&]( const nlohmann::json& aJson )
317  {
318  if( !aJson.is_array() )
319  return;
320 
321  m_TrackWidthList.clear();
322 
323  for( const nlohmann::json& entry : aJson )
324  {
325  if( entry.empty() )
326  continue;
327 
328  m_TrackWidthList.emplace_back( Millimeter2iu( entry.get<double>() ) );
329  }
330  },
331  {} ) );
332 
333  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "via_dimensions",
334  [&]() -> nlohmann::json
335  {
336  nlohmann::json js = nlohmann::json::array();
337 
338  for( const auto& via : m_ViasDimensionsList )
339  {
340  nlohmann::json entry = {};
341 
342  entry["diameter"] = Iu2Millimeter( via.m_Diameter );
343  entry["drill"] = Iu2Millimeter( via.m_Drill );
344 
345  js.push_back( entry );
346  }
347 
348  return js;
349  },
350  [&]( const nlohmann::json& aObj )
351  {
352  if( !aObj.is_array() )
353  return;
354 
355  m_ViasDimensionsList.clear();
356 
357  for( const nlohmann::json& entry : aObj )
358  {
359  if( entry.empty() || !entry.is_object() )
360  continue;
361 
362  if( !entry.contains( "diameter" ) || !entry.contains( "drill" ) )
363  continue;
364 
365  int diameter = Millimeter2iu( entry["diameter"].get<double>() );
366  int drill = Millimeter2iu( entry["drill"].get<double>() );
367 
368  m_ViasDimensionsList.emplace_back( VIA_DIMENSION( diameter, drill ) );
369  }
370  },
371  {} ) );
372 
373  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "diff_pair_dimensions",
374  [&]() -> nlohmann::json
375  {
376  nlohmann::json js = nlohmann::json::array();
377 
378  for( const auto& pair : m_DiffPairDimensionsList )
379  {
380  nlohmann::json entry = {};
381 
382  entry["width"] = Iu2Millimeter( pair.m_Width );
383  entry["gap"] = Iu2Millimeter( pair.m_Gap );
384  entry["via_gap"] = Iu2Millimeter( pair.m_ViaGap );
385 
386  js.push_back( entry );
387  }
388 
389  return js;
390  },
391  [&]( const nlohmann::json& aObj )
392  {
393  if( !aObj.is_array() )
394  return;
395 
396  m_DiffPairDimensionsList.clear();
397 
398  for( const nlohmann::json& entry : aObj )
399  {
400  if( entry.empty() || !entry.is_object() )
401  continue;
402 
403  if( !entry.contains( "width" ) || !entry.contains( "gap" )
404  || !entry.contains( "via_gap" ) )
405  continue;
406 
407  int width = Millimeter2iu( entry["width"].get<double>() );
408  int gap = Millimeter2iu( entry["gap"].get<double>() );
409  int via_gap = Millimeter2iu( entry["via_gap"].get<double>() );
410 
411  m_DiffPairDimensionsList.emplace_back(
412  DIFF_PAIR_DIMENSION( width, gap, via_gap ) );
413  }
414  },
415  {} ) );
416 
417  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.silk_line_width",
419  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
420 
421  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.silk_text_size_v",
423  TEXTS_MIN_SIZE, TEXTS_MAX_SIZE, MM_PER_IU ) );
424 
425  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.silk_text_size_h",
427  TEXTS_MIN_SIZE, TEXTS_MAX_SIZE, MM_PER_IU ) );
428 
429  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.silk_text_thickness",
431  TEXTS_MAX_WIDTH, MM_PER_IU ) );
432 
433  m_params.emplace_back( new PARAM<bool>( "defaults.silk_text_italic",
434  &m_TextItalic[LAYER_CLASS_SILK], false ) );
435 
436  m_params.emplace_back( new PARAM<bool>( "defaults.silk_text_upright",
437  &m_TextUpright[ LAYER_CLASS_SILK ], true ) );
438 
439  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.copper_line_width",
441  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
442 
443  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.copper_text_size_v",
445  TEXTS_MIN_SIZE, TEXTS_MAX_SIZE, MM_PER_IU ) );
446 
447  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.copper_text_size_h",
449  TEXTS_MIN_SIZE, TEXTS_MAX_SIZE, MM_PER_IU ) );
450 
451  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.copper_text_thickness",
453  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
454 
455  m_params.emplace_back( new PARAM<bool>( "defaults.copper_text_italic",
456  &m_TextItalic[LAYER_CLASS_COPPER], false ) );
457 
458  m_params.emplace_back( new PARAM<bool>( "defaults.copper_text_upright",
459  &m_TextUpright[LAYER_CLASS_COPPER], true ) );
460 
461  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.board_outline_line_width",
463  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
464 
465  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.courtyard_line_width",
467  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
468 
469  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.fab_line_width",
471  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
472 
473  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.fab_text_size_v",
475  TEXTS_MIN_SIZE, TEXTS_MAX_SIZE, MM_PER_IU ) );
476 
477  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.fab_text_size_h",
479  TEXTS_MIN_SIZE, TEXTS_MAX_SIZE, MM_PER_IU ) );
480 
481  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.fab_text_thickness",
483  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
484 
485  m_params.emplace_back( new PARAM<bool>( "defaults.fab_text_italic",
486  &m_TextItalic[LAYER_CLASS_FAB], false ) );
487 
488  m_params.emplace_back( new PARAM<bool>( "defaults.fab_text_upright",
489  &m_TextUpright[LAYER_CLASS_FAB], true ) );
490 
491  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.other_line_width",
493  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
494 
495  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.other_text_size_v",
497  TEXTS_MAX_SIZE, MM_PER_IU ) );
498 
499  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.other_text_size_h",
501  TEXTS_MAX_SIZE, MM_PER_IU ) );
502 
503  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.other_text_thickness",
505  Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ), MM_PER_IU ) );
506 
507  m_params.emplace_back( new PARAM<bool>( "defaults.other_text_italic",
508  &m_TextItalic[LAYER_CLASS_OTHERS], false ) );
509 
510  m_params.emplace_back( new PARAM<bool>( "defaults.other_text_upright",
511  &m_TextUpright[LAYER_CLASS_OTHERS], true ) );
512 
513  m_params.emplace_back( new PARAM_ENUM<DIM_UNITS_MODE>( "defaults.dimension_units",
516 
517  m_params.emplace_back( new PARAM<int>( "defaults.dimension_precision",
518  &m_DimensionPrecision, 4, 0, 5 ) );
519 
520  m_params.emplace_back( new PARAM_ENUM<DIM_UNITS_FORMAT>( "defaults.dimensions.units_format",
523 
524  m_params.emplace_back( new PARAM<bool>( "defaults.dimensions.suppress_zeroes",
525  &m_DimensionSuppressZeroes, false ) );
526 
527  // NOTE: excluding DIM_TEXT_POSITION::MANUAL from the valid range here
528  m_params.emplace_back( new PARAM_ENUM<DIM_TEXT_POSITION>( "defaults.dimensions.text_position",
531 
532  m_params.emplace_back( new PARAM<bool>( "defaults.dimensions.keep_text_aligned",
533  &m_DimensionKeepTextAligned, true ) );
534 
535  m_params.emplace_back( new PARAM<int>( "defaults.dimensions.arrow_length",
537  Mils2iu( DEFAULT_DIMENSION_ARROW_LENGTH ) ) );
538 
539  m_params.emplace_back( new PARAM<int>( "defaults.dimensions.extension_offset",
542 
543  m_params.emplace_back( new PARAM<bool>( "defaults.zones.45_degree_only",
545 
546  m_params.emplace_back( new PARAM_SCALED<int>( "defaults.zones.min_clearance",
548  Millimeter2iu( 0.0 ), Millimeter2iu( 25.0 ), MM_PER_IU ) );
549 
550  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "defaults.pads",
551  [&]() -> nlohmann::json
552  {
553  nlohmann::json ret =
554  {
555  { "width", Iu2Millimeter( m_Pad_Master.GetSize().x ) },
556  { "height", Iu2Millimeter( m_Pad_Master.GetSize().y ) },
557  { "drill", Iu2Millimeter( m_Pad_Master.GetDrillSize().x ) }
558  };
559 
560  return ret;
561  },
562  [&]( const nlohmann::json& aJson )
563  {
564  if( aJson.contains( "width" ) && aJson.contains( "height" )
565  && aJson.contains( "drill" ) )
566  {
567  wxSize sz;
568  sz.SetWidth( Millimeter2iu( aJson["width"].get<double>() ) );
569  sz.SetHeight( Millimeter2iu( aJson["height"].get<double>() ) );
570 
571  m_Pad_Master.SetSize( sz );
572 
573  int drill = Millimeter2iu( aJson["drill"].get<double>() );
574 
575  m_Pad_Master.SetDrillSize( wxSize( drill, drill ) );
576  }
577  }, {} ) );
578 
579  m_params.emplace_back( new PARAM_SCALED<int>( "rules.max_error", &m_MaxError, ARC_HIGH_DEF,
580  Millimeter2iu( 0.0001 ), Millimeter2iu( 1.0 ), MM_PER_IU ) );
581 
582  // TODO: replace with zones_fill_version parameter and migrate zones_use_no_outline?
583  m_params.emplace_back( new PARAM_LAMBDA<bool>( "zones_use_no_outline",
584  [this]() -> bool
585  {
586  return m_ZoneFillVersion >= 6;
587  },
588  [this]( bool aVal )
589  {
590  m_ZoneFillVersion = aVal ? 6 : 5;
591  },
592  6 ) );
593 
594  m_params.emplace_back( new PARAM<bool>( "zones_allow_external_fillets",
595  &m_ZoneKeepExternalFillets, false ) );
596 
597  registerMigration( 0, 1, std::bind( &BOARD_DESIGN_SETTINGS::migrateSchema0to1, this ) );
598 
599  registerMigration( 1, 2,
600  [&]() -> bool
601  {
602  // Schema 1 to 2: move mask and paste margin settings back to board.
603  // The parameters are removed, so we just have to manually load them here and
604  // they will get saved with the board
605  if( OPT<double> optval = Get<double>( "rules.solder_mask_clearance" ) )
606  m_SolderMaskMargin = static_cast<int>( *optval * IU_PER_MM );
607 
608  if( OPT<double> optval = Get<double>( "rules.solder_mask_min_width" ) )
609  m_SolderMaskMinWidth = static_cast<int>( *optval * IU_PER_MM );
610 
611  if( OPT<double> optval = Get<double>( "rules.solder_paste_clearance" ) )
612  m_SolderPasteMargin = static_cast<int>( *optval * IU_PER_MM );
613 
614  if( OPT<double> optval = Get<double>( "rules.solder_paste_margin_ratio" ) )
615  m_SolderPasteMarginRatio = *optval;
616 
617  try
618  {
619  at( "rules" ).erase( "solder_mask_clearance" );
620  at( "rules" ).erase( "solder_mask_min_width" );
621  at( "rules" ).erase( "solder_paste_clearance" );
622  at( "rules" ).erase( "solder_paste_margin_ratio" );
623  }
624  catch( ... )
625  {}
626 
627  return true;
628  } );
629 }
630 
631 
633 {
634  if( m_parent )
635  {
637  m_parent = nullptr;
638  }
639 }
640 
641 
643  NESTED_SETTINGS( "board_design_settings", bdsSchemaVersion, aOther.m_parent,
644  aOther.m_path ),
645  m_Pad_Master( nullptr )
646 {
647  initFromOther( aOther );
648 }
649 
650 
652 {
653  initFromOther( aOther );
654  return *this;
655 }
656 
657 
659 {
660  // Copy of NESTED_SETTINGS around is not allowed, so let's just update the params.
671  m_ViasMinSize = aOther.m_ViasMinSize;
683  m_MaxError = aOther.m_MaxError;
689 
690  std::copy( std::begin( aOther.m_LineThickness ), std::end( aOther.m_LineThickness ),
691  std::begin( m_LineThickness ) );
692 
693  std::copy( std::begin( aOther.m_TextSize ), std::end( aOther.m_TextSize ),
694  std::begin( m_TextSize ) );
695 
696  std::copy( std::begin( aOther.m_TextThickness ), std::end( aOther.m_TextThickness ),
697  std::begin( m_TextThickness ) );
698 
699  std::copy( std::begin( aOther.m_TextItalic ), std::end( aOther.m_TextItalic ),
700  std::begin( m_TextItalic ) );
701 
702  std::copy( std::begin( aOther.m_TextUpright ), std::end( aOther.m_TextUpright ),
703  std::begin( m_TextUpright ) );
704 
713 
714  m_AuxOrigin = aOther.m_AuxOrigin;
715  m_GridOrigin = aOther.m_GridOrigin;
716  m_HasStackup = aOther.m_HasStackup;
717 
730  m_stackup = aOther.m_stackup;
731 
732  // Only take the pointer from the other if it isn't the default
733  if( aOther.m_netClasses == &aOther.m_internalNetClasses )
735  else
736  m_netClasses = aOther.m_netClasses;
737 
739 }
740 
741 
743 {
761  nlohmann::json::json_pointer units_ptr( "/defaults/dimension_units" );
762  nlohmann::json::json_pointer precision_ptr( "/defaults/dimension_precision" );
763 
764  if( !( contains( units_ptr ) && contains( precision_ptr ) &&
765  at( units_ptr ).is_number_integer() &&
766  at( precision_ptr ).is_number_integer() ) )
767  {
768  // if either is missing or invalid, migration doesn't make sense
769  return true;
770  }
771 
772  int units = at( units_ptr ).get<int>();
773  int precision = at( precision_ptr ).get<int>();
774 
775  // The enum maps directly to precision if the units is mils
776  int extraDigits = 0;
777 
778  switch( units )
779  {
780  case 0: extraDigits = 3; break;
781  case 2: extraDigits = 2; break;
782  default: break;
783  }
784 
785  precision += extraDigits;
786 
787  ( *this )[precision_ptr] = precision;
788 
789  return true;
790 }
791 
792 
793 bool BOARD_DESIGN_SETTINGS::LoadFromFile( const wxString& aDirectory )
794 {
795  bool ret = NESTED_SETTINGS::LoadFromFile( aDirectory );
796 
797  // A number of things won't have been translated by the PROJECT_FILE migration because of
798  // descoped objects required to decode this data. So, it will be in the legacy.pcbnew
799  // section and needs to be pulled out here
800 
801  PROJECT_FILE* project = dynamic_cast<PROJECT_FILE*>( GetParent() );
802 
803  if( !project )
804  return ret;
805 
806  bool migrated = false;
807 
808  auto drcName =
809  []( int aCode ) -> std::string
810  {
811  std::shared_ptr<DRC_ITEM> item = DRC_ITEM::Create( aCode );
812  wxString name = item->GetSettingsKey();
813  return std::string( name.ToUTF8() );
814  };
815 
816  std::string bp = "board.design_settings.rule_severities.";
817  std::string rs = "rule_severities.";
818 
819  if( OPT<bool> v =
820  project->Get<bool>( PointerFromString( bp + "legacy_no_courtyard_defined" ) ) )
821  {
822  if( *v )
823  ( *this )[PointerFromString( rs + drcName( DRCE_MISSING_COURTYARD ) )] = "error";
824  else
825  ( *this )[PointerFromString( rs + drcName( DRCE_MISSING_COURTYARD ) )] = "ignore";
826 
827  project->erase( PointerFromString( bp + "legacy_no_courtyard_defined" ) );
828  migrated = true;
829  }
830 
831  if( OPT<bool> v = project->Get<bool>( PointerFromString( bp + "legacy_courtyards_overlap" ) ) )
832  {
833  if( *v )
834  ( *this )[PointerFromString( rs + drcName( DRCE_OVERLAPPING_FOOTPRINTS ) )] = "error";
835  else
836  ( *this )[PointerFromString( rs + drcName( DRCE_OVERLAPPING_FOOTPRINTS ) )] = "ignore";
837 
838  project->erase( PointerFromString( bp + "legacy_courtyards_overlap" ) );
839  migrated = true;
840  }
841 
842  if( project->contains( "legacy" ) )
843  {
844  // This defaults to false for new boards, but version 5.1.x and prior kept the fillets
845  // so we do the same for legacy boards.
847 
848  project->at( "legacy" ).erase( "pcbnew" );
849  }
850 
851  // Now that we have everything, we need to load again
852  if( migrated )
853  Load();
854 
855  return ret;
856 }
857 
858 
860 {
861  return m_DRCSeverities[ aDRCErrorCode ];
862 }
863 
864 
865 bool BOARD_DESIGN_SETTINGS::Ignore( int aDRCErrorCode )
866 {
867  return m_DRCSeverities[ aDRCErrorCode ] == RPT_SEVERITY_IGNORE;
868 }
869 
870 
872 {
873  int biggest = 0;
874  DRC_CONSTRAINT constraint;
875 
876  if( m_DRCEngine )
877  {
878  m_DRCEngine->QueryWorstConstraint( CLEARANCE_CONSTRAINT, constraint );
879  biggest = std::max( biggest, constraint.Value().Min() );
880 
881  m_DRCEngine->QueryWorstConstraint( HOLE_CLEARANCE_CONSTRAINT, constraint );
882  biggest = std::max( biggest, constraint.Value().Min() );
883 
884  m_DRCEngine->QueryWorstConstraint( EDGE_CLEARANCE_CONSTRAINT, constraint );
885  biggest = std::max( biggest, constraint.Value().Min() );
886  }
887 
888  return biggest;
889 }
890 
891 
893 {
894  int clearance = GetDefault()->GetClearance();
895 
896  for( const std::pair<const wxString, NETCLASSPTR>& netclass : GetNetClasses().NetClasses() )
897  clearance = std::min( clearance, netclass.second->GetClearance() );
898 
899  return clearance;
900 }
901 
902 
904 {
905  NETCLASSPTR netclass = GetNetClasses().Find( m_currentNetClassName );
906 
907  return netclass->GetuViaDiameter();
908 }
909 
910 
912 {
913  NETCLASSPTR netclass = GetNetClasses().Find( m_currentNetClassName );
914 
915  return netclass->GetuViaDrill();
916 }
917 
918 
920 {
921  m_viaSizeIndex = std::min( aIndex, (unsigned) m_ViasDimensionsList.size() );
922  m_useCustomTrackVia = false;
923 }
924 
925 
927 {
928  if( m_useCustomTrackVia )
930  else if( m_viaSizeIndex == 0 )
932  else
933  return m_ViasDimensionsList[ m_viaSizeIndex ].m_Diameter;
934 }
935 
936 
938 {
939  int drill;
940 
941  if( m_useCustomTrackVia )
942  drill = m_customViaSize.m_Drill;
943  else if( m_viaSizeIndex == 0 )
944  drill = GetNetClasses().GetDefaultPtr()->GetViaDrill();
945  else
946  drill = m_ViasDimensionsList[ m_viaSizeIndex ].m_Drill;
947 
948  return drill > 0 ? drill : -1;
949 }
950 
951 
953 {
954  m_trackWidthIndex = std::min( aIndex, (unsigned) m_TrackWidthList.size() );
955  m_useCustomTrackVia = false;
956 }
957 
958 
960 {
961  if( m_useCustomTrackVia )
962  return m_customTrackWidth;
963  else if( m_trackWidthIndex == 0 )
965  else
967 }
968 
969 
971 {
972  m_diffPairIndex = std::min( aIndex, (unsigned) 8 );
973  m_useCustomDiffPair = false;
974 }
975 
976 
978 {
979  m_HoleToHoleMin = aDistance;
980 }
981 
982 
984 {
985  m_CopperEdgeClearance = aDistance;
986 }
987 
988 
990 {
991  m_SilkClearance = aDistance;
992 }
993 
994 
996 {
997  m_copperLayerCount = aNewLayerCount;
998 
999  // Update only enabled copper layers mask
1000  m_enabledLayers &= ~LSET::AllCuMask();
1001 
1002  if( aNewLayerCount > 0 )
1003  m_enabledLayers |= LSET::AllCuMask( aNewLayerCount );
1004 }
1005 
1006 
1008 {
1009  // Back and front layers are always enabled.
1010  aMask.set( B_Cu ).set( F_Cu );
1011 
1012  m_enabledLayers = aMask;
1013 
1014  // update m_CopperLayerCount to ensure its consistency with m_EnabledLayers
1015  m_copperLayerCount = ( aMask & LSET::AllCuMask() ).count();
1016 }
1017 
1018 
1019 // Return the layer class index { silk, copper, edges & courtyards, fab, others } of the
1020 // given layer.
1022 {
1023  if( aLayer == F_SilkS || aLayer == B_SilkS )
1024  return LAYER_CLASS_SILK;
1025  else if( IsCopperLayer( aLayer ) )
1026  return LAYER_CLASS_COPPER;
1027  else if( aLayer == Edge_Cuts )
1028  return LAYER_CLASS_EDGES;
1029  else if( aLayer == F_CrtYd || aLayer == B_CrtYd )
1030  return LAYER_CLASS_COURTYARD;
1031  else if( aLayer == F_Fab || aLayer == B_Fab )
1032  return LAYER_CLASS_FAB;
1033  else
1034  return LAYER_CLASS_OTHERS;
1035 }
1036 
1037 
1039 {
1040  return Millimeter2iu( ADVANCED_CFG::GetCfg().m_DRCEpsilon );
1041 }
1042 
1043 
1045 {
1046  return Millimeter2iu( ADVANCED_CFG::GetCfg().m_HoleWallThickness );
1047 }
1048 
1049 
1051 {
1052  return m_LineThickness[ GetLayerClass( aLayer ) ];
1053 }
1054 
1055 
1057 {
1058  return m_TextSize[ GetLayerClass( aLayer ) ];
1059 }
1060 
1061 
1063 {
1064  return m_TextThickness[ GetLayerClass( aLayer ) ];
1065 }
1066 
1067 
1069 {
1070  return m_TextItalic[ GetLayerClass( aLayer ) ];
1071 }
1072 
1073 
1075 {
1076  return m_TextUpright[ GetLayerClass( aLayer ) ];
1077 }
1078 
1079 
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
#define DEFAULT_EDGE_WIDTH
#define DEFAULT_SILK_TEXT_WIDTH
void SetCopperLayerCount(int aNewLayerCount)
Set the copper layer count to aNewLayerCount.
#define DEFAULT_TRACKMINWIDTH
Container to handle a stock of specific vias each with unique diameter and drill sizes in the BOARD c...
int m_ZoneFillVersion
Option to select different fill algorithms.
void SetEnabledLayers(LSET aMask)
Change the bit-mask of enabled layers to aMask.
void SetCopperEdgeClearance(int aDistance)
#define DEFAULT_COURTYARD_WIDTH
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
wxString m_currentNetClassName
Current net class name used to display netclass info.
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:245
#define DEFAULT_SOLDERPASTE_RATIO
wxPoint m_GridOrigin
origin for grid offsets
NETCLASSPTR Find(const wxString &aName) const
Search this container for a NETCLASS given by aName.
Definition: netclass.cpp:132
JSON_SETTINGS * GetParent()
#define DEFAULT_VIASMINSIZE
#define TEXTS_MAX_WIDTH
Maximum text width in internal units (10 inches)
Definition: pcbnew.h:33
BOARD_DESIGN_SETTINGS(JSON_SETTINGS *aParent, const std::string &aPath)
MINOPTMAX< int > & Value()
Definition: drc_rule.h:122
std::vector< int > m_TrackWidthList
BOARD_STACKUP m_stackup
the description of layers stackup, for board fabrication only physical layers are in layers stackup.
SEVERITY
Definition: ui_common.h:83
static constexpr double IU_PER_MM
Mock up a conversion function.
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
int GetHolePlatingThickness() const
Pad & via drills are finish size.
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Definition: rc_item.h:72
NETCLASSES m_internalNetClasses
Net classes that are loaded from the board file before these were stored in the project.
bool Ignore(int aDRCErrorCode)
Return true if the DRC error code's severity is SEVERITY_IGNORE.
#define LEGACY_COPPEREDGECLEARANCE
#define DEFAULT_BOARD_THICKNESS_MM
int m_DimensionPrecision
Number of digits after the decimal.
ZONE_SETTINGS m_defaultZoneSettings
The default settings that will be used for new zones.
#define DEFAULT_LINE_WIDTH
#define DEFAULT_DIMENSION_ARROW_LENGTH
#define DEFAULT_COPPER_LINE_WIDTH
#define DEFAULT_HOLETOHOLEMIN
Stores an enum as an integer.
Definition: parameters.h:226
void SetSize(const wxSize &aSize)
Definition: pad.h:231
T Min() const
Definition: minoptmax.h:33
DIFF_PAIR_DIMENSION m_customDiffPair
#define DEFAULT_CUSTOMDPAIRGAP
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
VIATYPE m_CurrentViaType
(VIA_BLIND_BURIED, VIA_THROUGH, VIA_MICROVIA)
bool LoadFromFile(const wxString &aDirectory="") override
Loads the JSON document from the parent and then calls Load()
nlohmann::json json
Definition: gerbview.cpp:40
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:62
Container to handle a stock of specific differential pairs each with unique track width,...
#define DEFAULT_MINCLEARANCE
#define DEFAULT_MINTHROUGHDRILL
DIM_TEXT_POSITION m_DimensionTextPosition
DIM_UNITS_MODE m_DimensionUnitsMode
#define DEFAULT_CUSTOMDPAIRVIAGAP
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
int GetLayerClass(PCB_LAYER_ID aLayer) const
#define DEFAULT_DIMENSION_EXTENSION_OFFSET
bool GetTextUpright(PCB_LAYER_ID aLayer) const
#define DEFAULT_SOLDERPASTE_CLEARANCE
bool GetTextItalic(PCB_LAYER_ID aLayer) const
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
#define DEFAULT_TEXT_WIDTH
wxSize m_TextSize[LAYER_CLASS_COUNT]
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
#define DEFAULT_CUSTOMDPAIRWIDTH
const wxSize & GetDrillSize() const
Definition: pad.h:242
PCB_LAYER_ID
A quick note on layer IDs:
int GetTrackWidth() const
Definition: netclass.h:128
#define DEFAULT_SILK_TEXT_SIZE
int m_TextThickness[LAYER_CLASS_COUNT]
LSET is a set of PCB_LAYER_IDs.
#define DEFAULT_SILK_LINE_WIDTH
#define NULL
void SetMinHoleSeparation(int aDistance)
bool LoadFromFile(const wxString &aDirectory="") override
Loads the backing file from disk and then calls Load()
void SetDrillSize(const wxSize &aSize)
Definition: pad.h:241
const wxSize & GetSize() const
Definition: pad.h:232
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
int GetViaDrill() const
Definition: netclass.h:136
bool m_TextItalic[LAYER_CLASS_COUNT]
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition: parameters.h:388
#define ZONE_CLEARANCE_MIL
Definition: zones.h:33
BOARD_DESIGN_SETTINGS & operator=(const BOARD_DESIGN_SETTINGS &aOther)
NETCLASSES & GetNetClasses() const
Text appears outside the dimension line (default)
bool m_BlindBuriedViaAllowed
true to allow blind/buried vias
SEVERITY GetSeverity(int aDRCErrorCode)
const int bdsSchemaVersion
#define TEXTS_MAX_SIZE
Maximum text size in internal units (10 inches)
Definition: pcbnew.h:32
void SetDiffPairIndex(unsigned aIndex)
#define DEFAULT_MICROVIASMINSIZE
NETCLASS * GetDefaultPtr() const
Definition: netclass.h:258
#define DEFAULT_MICROVIASMINDRILL
#define DEFAULT_SOLDERMASK_MIN_WIDTH
int m_LineThickness[LAYER_CLASS_COUNT]
Text appears in line with the dimension line.
#define DEFAULT_HOLECLEARANCE
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:81
#define TEXTS_MIN_SIZE
Minimum text size in internal units (1 mil)
Definition: pcbnew.h:31
#define DEFAULT_COPPEREDGECLEARANCE
bool m_resetParamsIfMissing
Whether or not to set parameters to their default value if missing from JSON on Load()
wxString SeverityToString(const SEVERITY &aSeverity)
Definition: ui_common.cpp:47
Board layer functions and definitions.
const char * name
Definition: DXF_plotter.cpp:59
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
#define DEFAULT_SILKCLEARANCE
int GetClearance() const
Definition: netclass.h:124
std::map< int, SEVERITY > m_DRCSeverities
SEVERITY SeverityFromString(const wxString &aSeverity)
Definition: ui_common.cpp:36
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: drc_item.h:100
NETCLASS * GetDefault() const
int GetViaDiameter() const
Definition: netclass.h:132
void SetSilkClearance(int aDistance)
Set the minimum distance between silk items to aValue.
void initFromOther(const BOARD_DESIGN_SETTINGS &aOther)
#define DEFAULT_COPPER_TEXT_WIDTH
std::vector< VIA_DIMENSION > m_ViasDimensionsList
boost::optional< T > OPT
Definition: optional.h:7
#define DEFAULT_CUSTOMTRACKWIDTH
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
DIM_UNITS_FORMAT m_DimensionUnitsFormat
#define DEFAULT_TEXT_SIZE
Ratio of the font height to the baseline of the text above the wire.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
NETCLASSES * m_netClasses
This will point to m_internalNetClasses until it is repointed to the project after load.
#define DEFAULT_SOLDERMASK_CLEARANCE
int m_copperLayerCount
Number of copper layers for this design.
#define DEFAULT_COPPER_TEXT_SIZE
bool m_MicroViasAllowed
true to allow micro vias
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
std::set< wxString > m_DrcExclusions
static constexpr int Millimeter2iu(double mm)
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
LSET m_enabledLayers
Bit-mask for layer enabling.
wxPoint m_AuxOrigin
origin for plot exports
wxSize GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
int m_boardThickness
Board thickness for 3D viewer.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
bool m_TextUpright[LAYER_CLASS_COUNT]
Container for design settings for a BOARD object.