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.

117 lines
4.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Wayne Stambaugh <stambaughw@verizon.net>
  5. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <pgm_base.h>
  25. #include <widgets/ui_common.h>
  26. #include <settings/settings_manager.h>
  27. #include <symbol_editor/symbol_editor_settings.h>
  28. #include "panel_sym_editing_options.h"
  29. #define MIN_GRID 25
  30. PANEL_SYM_EDITING_OPTIONS::PANEL_SYM_EDITING_OPTIONS( wxWindow* aWindow,
  31. UNITS_PROVIDER* aUnitsProvider,
  32. wxWindow* aEventSource ) :
  33. PANEL_SYM_EDITING_OPTIONS_BASE( aWindow ),
  34. m_lineWidth( aUnitsProvider, aEventSource, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits ),
  35. m_textSize( aUnitsProvider, aEventSource, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits ),
  36. m_pinLength( aUnitsProvider, aEventSource, m_pinLengthLabel, m_pinLengthCtrl, m_pinLengthUnits ),
  37. m_pinNameSize( aUnitsProvider, aEventSource ,m_pinNameSizeLabel, m_pinNameSizeCtrl, m_pinNameSizeUnits ),
  38. m_pinNumberSize( aUnitsProvider, aEventSource, m_pinNumSizeLabel, m_pinNumSizeCtrl, m_pinNumSizeUnits ),
  39. m_pinPitch( aUnitsProvider, aEventSource, m_pinPitchLabel, m_pinPitchCtrl, m_pinPitchUnits )
  40. {
  41. m_widthHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
  42. }
  43. void PANEL_SYM_EDITING_OPTIONS::loadSymEditorSettings( SYMBOL_EDITOR_SETTINGS* aCfg )
  44. {
  45. m_lineWidth.SetValue( schIUScale.MilsToIU( aCfg->m_Defaults.line_width ) );
  46. m_textSize.SetValue( schIUScale.MilsToIU( aCfg->m_Defaults.text_size ) );
  47. m_pinLength.SetValue( schIUScale.MilsToIU( aCfg->m_Defaults.pin_length ) );
  48. m_pinNumberSize.SetValue( schIUScale.MilsToIU( aCfg->m_Defaults.pin_num_size ) );
  49. m_pinNameSize.SetValue( schIUScale.MilsToIU( aCfg->m_Defaults.pin_name_size ) );
  50. m_pinPitch.SetValue( schIUScale.MilsToIU( aCfg->m_Repeat.pin_step ) );
  51. m_spinRepeatLabel->SetValue( aCfg->m_Repeat.label_delta );
  52. m_cbShowPinElectricalType->SetValue( aCfg->m_ShowPinElectricalType );
  53. m_dragPinsWithEdges->SetValue( aCfg->m_dragPinsAlongWithEdges );
  54. }
  55. bool PANEL_SYM_EDITING_OPTIONS::TransferDataToWindow()
  56. {
  57. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  58. SYMBOL_EDITOR_SETTINGS* settings = mgr.GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
  59. loadSymEditorSettings( settings );
  60. return true;
  61. }
  62. bool PANEL_SYM_EDITING_OPTIONS::TransferDataFromWindow()
  63. {
  64. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  65. SYMBOL_EDITOR_SETTINGS* settings = mgr.GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
  66. settings->m_Defaults.line_width = schIUScale.IUToMils( m_lineWidth.GetIntValue() );
  67. settings->m_Defaults.text_size = schIUScale.IUToMils( m_textSize.GetIntValue() );
  68. settings->m_Defaults.pin_length = schIUScale.IUToMils( m_pinLength.GetIntValue() );
  69. settings->m_Defaults.pin_num_size = schIUScale.IUToMils( m_pinNumberSize.GetIntValue() );
  70. settings->m_Defaults.pin_name_size = schIUScale.IUToMils( m_pinNameSize.GetIntValue() );
  71. settings->m_Repeat.label_delta = m_spinRepeatLabel->GetValue();
  72. settings->m_Repeat.pin_step = schIUScale.IUToMils( m_pinPitch.GetIntValue() );
  73. settings->m_ShowPinElectricalType = m_cbShowPinElectricalType->GetValue();
  74. settings->m_dragPinsAlongWithEdges = m_dragPinsWithEdges->GetValue();
  75. // Force pin_step to a grid multiple
  76. settings->m_Repeat.pin_step = KiROUND( double( settings->m_Repeat.pin_step ) / MIN_GRID ) * MIN_GRID;
  77. return true;
  78. }
  79. void PANEL_SYM_EDITING_OPTIONS::onKillFocusPinPitch( wxFocusEvent& aEvent )
  80. {
  81. int pitch_mils = schIUScale.IUToMils( m_pinPitch.GetIntValue() );
  82. // Force pin_step to a grid multiple
  83. pitch_mils = KiROUND( double( pitch_mils ) / MIN_GRID ) * MIN_GRID;
  84. m_pinPitch.SetValue( schIUScale.MilsToIU( pitch_mils ) );
  85. aEvent.Skip();
  86. }
  87. void PANEL_SYM_EDITING_OPTIONS::ResetPanel()
  88. {
  89. SYMBOL_EDITOR_SETTINGS cfg;
  90. cfg.Load(); // Loading without a file will init to defaults
  91. loadSymEditorSettings( &cfg );
  92. }