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.

131 lines
5.6 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020-2021 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 <settings/common_settings.h>
  24. #include <settings/parameters.h>
  25. #include <settings/settings_manager.h>
  26. #include "symbol_editor_settings.h"
  27. #include <default_values.h>
  28. ///! Update the schema version whenever a migration is required
  29. const int libeditSchemaVersion = 1;
  30. SYMBOL_EDITOR_SETTINGS::SYMBOL_EDITOR_SETTINGS() :
  31. APP_SETTINGS_BASE( "symbol_editor", libeditSchemaVersion ),
  32. m_Defaults(),
  33. m_Repeat(),
  34. m_ShowPinElectricalType( true ),
  35. m_LibWidth(),
  36. m_EditSymbolVisibleColumns()
  37. {
  38. // Make Coverity happy
  39. m_UseEeschemaColorSettings = true;;
  40. // Init settings:
  41. SetLegacyFilename( wxS( "eeschema" ) );
  42. m_params.emplace_back( new PARAM<int>( "defaults.line_width",
  43. &m_Defaults.line_width, 0 ) );
  44. m_params.emplace_back( new PARAM<int>( "defaults.text_size",
  45. &m_Defaults.text_size, DEFAULT_TEXT_SIZE ) );
  46. m_params.emplace_back( new PARAM<int>( "defaults.pin_length",
  47. &m_Defaults.pin_length, DEFAULT_PIN_LENGTH ) );
  48. m_params.emplace_back( new PARAM<int>( "defaults.pin_name_size",
  49. &m_Defaults.pin_name_size, DEFAULT_PINNAME_SIZE ) );
  50. m_params.emplace_back( new PARAM<int>( "defaults.pin_num_size",
  51. &m_Defaults.pin_num_size, DEFAULT_PINNUM_SIZE ) );
  52. m_params.emplace_back( new PARAM<int>( "repeat.label_delta",
  53. &m_Repeat.label_delta, 1 ) );
  54. m_params.emplace_back( new PARAM<int>( "repeat.pin_step",
  55. &m_Repeat.pin_step, 100 ) );
  56. m_params.emplace_back( new PARAM<bool>( "show_pin_electrical_type",
  57. &m_ShowPinElectricalType, true ) );
  58. m_params.emplace_back( new PARAM<int>( "lib_table_width",
  59. &m_LibWidth, 250 ) );
  60. m_params.emplace_back( new PARAM<wxString>( "edit_symbol_visible_columns",
  61. &m_EditSymbolVisibleColumns, "0 1 2 3 4 5 6 7" ) );
  62. m_params.emplace_back( new PARAM<wxString>( "pin_table_visible_columns",
  63. &m_PinTableVisibleColumns, "0 1 2 3 4 5 9 10" ) );
  64. m_params.emplace_back( new PARAM<bool>( "use_eeschema_color_settings",
  65. &m_UseEeschemaColorSettings, true ) );
  66. registerMigration( 0, 1,
  67. [&]() -> bool
  68. {
  69. // This is actually a migration for APP_SETTINGS_BASE::m_LibTree
  70. return migrateLibTreeWidth();
  71. } );
  72. }
  73. bool SYMBOL_EDITOR_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
  74. {
  75. bool ret = APP_SETTINGS_BASE::MigrateFromLegacy( aCfg );
  76. // Now modify the loaded grid selection, because in earlier versions the grids index was shared
  77. // between all applications and started at 1000 mils. There is a 4-position offset between
  78. // this index and the possible eeschema grids list that we have to subtract.
  79. std::string gridSizePtr = "window.grid.last_size";
  80. if( std::optional<int> currentSize = Get<int>( gridSizePtr ) )
  81. {
  82. Set( gridSizePtr, *currentSize - 4 );
  83. }
  84. else
  85. {
  86. // Otherwise, default grid size should be 50 mils; index 1
  87. Set( gridSizePtr, 1 );
  88. }
  89. ret &= fromLegacy<int>( aCfg, "DefaultWireWidth", "defaults.line_width" );
  90. ret &= fromLegacy<int>( aCfg, "DefaultPinLength", "defaults.pin_length" );
  91. ret &= fromLegacy<int>( aCfg, "LibeditPinNameSize", "defaults.pin_name_size" );
  92. ret &= fromLegacy<int>( aCfg, "LibeditPinNumSize", "defaults.pin_num_size" );
  93. ret &= fromLegacy<int>( aCfg, "LibeditRepeatLabelInc", "repeat.label_delta" );
  94. ret &= fromLegacy<int>( aCfg, "LibeditPinRepeatStep", "repeat.pin_step" );
  95. ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepX", "repeat.x_step" );
  96. ret &= fromLegacy<int>( aCfg, "LibeditRepeatStepY", "repeat.y_step" );
  97. ret &= fromLegacy<int>( aCfg, "LibeditLibWidth", "lib_table_width" );
  98. ret &= fromLegacy<bool>( aCfg, "LibeditShowPinElectricalType", "show_pin_electrical_type" );
  99. ret &= fromLegacyString( aCfg, "LibEditFieldsShownColumns", "edit_symbol_visible_columns" );
  100. ret &= fromLegacyString( aCfg, "PinTableShownColumns", "pin_table_visible_columns" );
  101. return ret;
  102. }