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.

172 lines
6.3 KiB

6 years ago
6 years ago
6 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2021-2022 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 <gerbview_settings.h>
  24. #include <layer_ids.h>
  25. #include <pgm_base.h>
  26. #include <settings/common_settings.h>
  27. #include <settings/json_settings_internals.h>
  28. #include <settings/parameters.h>
  29. #include <settings/settings_manager.h>
  30. #include <wx/config.h>
  31. ///! Update the schema version whenever a migration is required
  32. const int gerbviewSchemaVersion = 0;
  33. GERBVIEW_SETTINGS::GERBVIEW_SETTINGS() :
  34. APP_SETTINGS_BASE( "gerbview", gerbviewSchemaVersion ),
  35. m_Appearance(),
  36. m_BoardLayersCount( 2 )
  37. {
  38. // Init settings:
  39. m_params.emplace_back( new PARAM<bool>( "appearance.show_border_and_titleblock",
  40. &m_Appearance.show_border_and_titleblock, false ) );
  41. m_params.emplace_back( new PARAM<bool>( "appearance.show_dcodes",
  42. &m_Appearance.show_dcodes, false ) );
  43. m_params.emplace_back( new PARAM<bool>( "appearance.show_negative_objects",
  44. &m_Appearance.show_negative_objects, false ) );
  45. m_params.emplace_back( new PARAM<wxString>( "appearance.page_type",
  46. &m_Appearance.page_type, "GERBER" ) );
  47. m_params.emplace_back( new PARAM_LIST<wxString>( "system.drill_file_history",
  48. &m_DrillFileHistory, {} ) );
  49. m_params.emplace_back( new PARAM_LIST<wxString>( "system.zip_file_history",
  50. &m_ZipFileHistory, {} ) );
  51. m_params.emplace_back( new PARAM_LIST<wxString>( "system.job_file_history",
  52. &m_JobFileHistory, {} ) );
  53. m_params.emplace_back( new PARAM_LIST<int>( "gerber_to_pcb_layers",
  54. &m_GerberToPcbLayerMapping, {} ) );
  55. m_params.emplace_back( new PARAM<int>( "gerber_to_pcb_copperlayers_count",
  56. &m_BoardLayersCount, 2 ) );
  57. m_params.emplace_back( new PARAM<bool>( "excellon_defaults.unit_mm",
  58. &m_ExcellonDefaults.m_UnitsMM, false ) );
  59. m_params.emplace_back( new PARAM<bool>( "excellon_defaults.lz_format",
  60. &m_ExcellonDefaults.m_LeadingZero, true ) );
  61. m_params.emplace_back( new PARAM<int>( "excellon_defaults.mm_integer_len",
  62. &m_ExcellonDefaults.m_MmIntegerLen, FMT_INTEGER_MM, 2 , 6 ) );
  63. m_params.emplace_back( new PARAM<int>( "excellon_defaults.mm_mantissa_len",
  64. &m_ExcellonDefaults.m_MmMantissaLen, FMT_MANTISSA_MM, 2 , 6 ) );
  65. m_params.emplace_back( new PARAM<int>( "excellon_defaults.inch_integer_len",
  66. &m_ExcellonDefaults.m_InchIntegerLen, FMT_INTEGER_INCH, 2 , 6 ) );
  67. m_params.emplace_back( new PARAM<int>( "excellon_defaults.inch_mantissa_len",
  68. &m_ExcellonDefaults.m_InchMantissaLen, FMT_MANTISSA_INCH, 2 , 6 ) );
  69. }
  70. bool GERBVIEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
  71. {
  72. bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
  73. ret &= fromLegacy<bool>( aCfg,
  74. "ShowBorderAndTitleBlock", "appearance.show_border_and_titleblock" );
  75. ret &= fromLegacy<bool>( aCfg, "ShowDCodesOpt", "appearance.show_dcodes" );
  76. ret &= fromLegacy<bool>( aCfg, "ShowNegativeObjectsOpt", "appearance.show_negative_objects" );
  77. ret &= fromLegacyString( aCfg, "PageSizeOpt", "appearance.page_type" );
  78. auto migrate_files = [&] ( const std::string& aPath, const std::string& aDest )
  79. {
  80. int max_history_size = Pgm().GetCommonSettings()->m_System.file_history_size;
  81. wxString file, key;
  82. nlohmann::json js = nlohmann::json::array();
  83. aCfg->SetPath( aPath );
  84. for( int i = 0; i < max_history_size; i++ )
  85. {
  86. key.Printf( wxT( "file%d" ), i );
  87. file = aCfg->Read( key, wxEmptyString );
  88. if( !file.IsEmpty() )
  89. js.emplace_back( file.ToStdString() );
  90. }
  91. aCfg->SetPath( wxT( ".." ) );
  92. Set( aDest, js );
  93. };
  94. migrate_files( "drl_files", "system.drill_file_history" );
  95. migrate_files( "zip_files", "system.zip_file_history" );
  96. migrate_files( "job_files", "system.job_file_history" );
  97. {
  98. wxString key;
  99. int value = 0;
  100. Set( "gerber_to_pcb_layers", nlohmann::json::array() );
  101. for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
  102. {
  103. key.Printf( wxT( "GbrLyr%dToPcb" ), i );
  104. aCfg->Read( key, &value, UNSELECTED_LAYER );
  105. At( "gerber_to_pcb_layers" ).emplace_back( value );
  106. }
  107. }
  108. COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetMigratedColorSettings();
  109. auto migrateLegacyColor = [&] ( const std::string& aKey, int aLayerId ) {
  110. wxString str;
  111. if( aCfg->Read( aKey, &str ) )
  112. cs->SetColor( aLayerId, COLOR4D( str ) );
  113. };
  114. migrateLegacyColor( "BackgroundColorEx", LAYER_GERBVIEW_BACKGROUND );
  115. migrateLegacyColor( "DCodeColorEx", LAYER_DCODES );
  116. migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_GRID );
  117. migrateLegacyColor( "NegativeObjectsColorEx", LAYER_NEGATIVE_OBJECTS );
  118. migrateLegacyColor( "WorksheetColorEx", LAYER_GERBVIEW_DRAWINGSHEET );
  119. migrateLegacyColor( "GridColorEx", LAYER_GERBVIEW_PAGE_LIMITS );
  120. wxString key;
  121. for( int i = 0, id = GERBVIEW_LAYER_ID_START;
  122. id < GERBER_DRAWLAYERS_COUNT + GERBVIEW_LAYER_ID_START; ++i, ++id )
  123. {
  124. key.Printf( wxT( "ColorLayer%dEx" ), i );
  125. migrateLegacyColor( key.ToStdString(), id );
  126. }
  127. Pgm().GetSettingsManager().SaveColorSettings( cs, "gerbview" );
  128. Set( "appearance.color_theme", cs->GetFilename() );
  129. return ret;
  130. }