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.

152 lines
6.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 CERN
  5. * @author Jon Evans <jon@craftyjon.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * 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 <base_screen.h>
  21. #include <class_libentry.h>
  22. #include <convert_to_biu.h>
  23. #include <default_values.h>
  24. #include <eda_text.h>
  25. #include <eeschema_settings.h>
  26. #include <kiface_i.h>
  27. #include <schematic_settings.h>
  28. #include <settings/parameters.h>
  29. const int schSettingsSchemaVersion = 0;
  30. SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
  31. NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
  32. m_DefaultLineWidth( DEFAULT_LINE_THICKNESS * IU_PER_MILS ),
  33. m_DefaultWireThickness( DEFAULT_WIRE_THICKNESS * IU_PER_MILS ),
  34. m_DefaultBusThickness( DEFAULT_BUS_THICKNESS * IU_PER_MILS ),
  35. m_DefaultTextSize( DEFAULT_TEXT_SIZE * IU_PER_MILS ),
  36. m_TextOffsetRatio( 0.08 ),
  37. m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
  38. m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ),
  39. m_TemplateFieldNames( nullptr )
  40. {
  41. EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
  42. int defaultLineThickness =
  43. appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_THICKNESS;
  44. int defaultWireThickness =
  45. appSettings ? appSettings->m_Drawing.default_wire_thickness : DEFAULT_WIRE_THICKNESS;
  46. int defaultBusThickness =
  47. appSettings ? appSettings->m_Drawing.default_bus_thickness : DEFAULT_BUS_THICKNESS;
  48. int defaultTextSize =
  49. appSettings ? appSettings->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
  50. int defaultPinSymbolSize =
  51. appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
  52. m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
  53. &m_DefaultLineWidth, Mils2iu( defaultLineThickness ),
  54. Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
  55. m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_wire_thickness",
  56. &m_DefaultWireThickness, Mils2iu( defaultWireThickness ),
  57. Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
  58. m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_bus_thickness",
  59. &m_DefaultBusThickness, Mils2iu( defaultBusThickness ),
  60. Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
  61. m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size", &m_DefaultTextSize,
  62. Mils2iu( defaultTextSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
  63. 1 / IU_PER_MILS ) );
  64. m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio", &m_TextOffsetRatio,
  65. (double) TXT_MARGIN / DEFAULT_SIZE_TEXT, -200.0, 200.0 ) );
  66. m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size", &m_PinSymbolSize,
  67. Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
  68. 1 / IU_PER_MILS ) );
  69. m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_junction_size", &m_JunctionSize,
  70. Mils2iu( DEFAULT_BUS_THICKNESS ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
  71. m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
  72. [&]() -> nlohmann::json
  73. {
  74. nlohmann::json ret = nlohmann::json::array();
  75. if( !m_TemplateFieldNames )
  76. return ret;
  77. for( const TEMPLATE_FIELDNAME& field :
  78. m_TemplateFieldNames->GetTemplateFieldNames( false ) )
  79. {
  80. ret.push_back( nlohmann::json( {
  81. { "name", field.m_Name },
  82. { "visible", field.m_Visible },
  83. { "url", field.m_URL }
  84. } ) );
  85. }
  86. return ret;
  87. },
  88. [&]( const nlohmann::json& aJson )
  89. {
  90. if( !m_TemplateFieldNames || aJson.empty() || !aJson.is_array() )
  91. return;
  92. m_TemplateFieldNames->DeleteAllFieldNameTemplates( false );
  93. for( const nlohmann::json& entry : aJson )
  94. {
  95. if( !entry.contains( "name" ) || !entry.contains( "url" )
  96. || !entry.contains( "visible" ) )
  97. continue;
  98. TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
  99. field.m_URL = entry["url"].get<bool>();
  100. field.m_Visible = entry["visible"].get<bool>();
  101. m_TemplateFieldNames->AddTemplateFieldName( field, false );
  102. }
  103. }, {} ) );
  104. // TOOD(JE) get rid of this static
  105. m_params.emplace_back( new PARAM<wxString>(
  106. "page_layout_descr_file", &BASE_SCREEN::m_PageLayoutDescrFileName, "" ) );
  107. m_params.emplace_back( new PARAM<wxString>( "plot_directory", &m_PlotDirectoryName, "" ) );
  108. m_params.emplace_back( new PARAM<wxString>( "net_format_name", &m_NetFormatName, "" ) );
  109. m_params.emplace_back(
  110. new PARAM<bool>( "spice_adjust_passive_values", &m_SpiceAdjustPassiveValues, false ) );
  111. // TODO(JE) should we keep these LIB_PART:: things around?
  112. m_params.emplace_back( new PARAM<int>(
  113. "subpart_id_separator", LIB_PART::SubpartIdSeparatorPtr(), 0, 0, 126 ) );
  114. m_params.emplace_back(
  115. new PARAM<int>( "subpart_first_id", LIB_PART::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
  116. }
  117. SCHEMATIC_SETTINGS::~SCHEMATIC_SETTINGS()
  118. {
  119. if( m_parent )
  120. {
  121. m_parent->ReleaseNestedSettings( this );
  122. m_parent = nullptr;
  123. }
  124. }