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.

123 lines
4.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
  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 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 <pgm_base.h>
  21. #include <settings/settings_manager.h>
  22. #include <pcbnew_settings.h>
  23. #include <config_map.h>
  24. #include <panel_pcb_display_options.h>
  25. #include <widgets/gal_options_panel.h>
  26. static const UTIL::CFG_MAP<TRACK_CLEARANCE_MODE> clearanceModeMap =
  27. {
  28. { SHOW_WITH_VIA_WHILE_ROUTING, 2 }, // Default
  29. { DO_NOT_SHOW_CLEARANCE, 0 },
  30. { SHOW_WHILE_ROUTING, 1 },
  31. { SHOW_WITH_VIA_WHILE_ROUTING_OR_DRAGGING, 3 },
  32. { SHOW_WITH_VIA_ALWAYS, 4 },
  33. };
  34. PANEL_PCB_DISPLAY_OPTIONS::PANEL_PCB_DISPLAY_OPTIONS( wxWindow* aParent, APP_SETTINGS_BASE* aAppSettings ) :
  35. PANEL_PCB_DISPLAY_OPTIONS_BASE( aParent ),
  36. m_isPCBEdit( dynamic_cast<PCBNEW_SETTINGS*>( aAppSettings ) != nullptr )
  37. {
  38. m_galOptsPanel = new GAL_OPTIONS_PANEL( this, aAppSettings );
  39. m_galOptionsSizer->Add( m_galOptsPanel, 1, wxEXPAND|wxRIGHT, 15 );
  40. m_optionsBook->SetSelection( m_isPCBEdit ? 1 : 0 );
  41. }
  42. void PANEL_PCB_DISPLAY_OPTIONS::loadPCBSettings( PCBNEW_SETTINGS* aCfg )
  43. {
  44. int i = UTIL::GetConfigForVal( clearanceModeMap, aCfg->m_Display.m_TrackClearance );
  45. m_OptDisplayTracksClearance->SetSelection( i );
  46. m_OptDisplayPadClearence->SetValue( aCfg->m_Display.m_PadClearance );
  47. m_OptDisplayPadNumber->SetValue( aCfg->m_ViewersDisplay.m_DisplayPadNumbers );
  48. m_ShowNetNamesOption->SetSelection( aCfg->m_Display.m_NetNames );
  49. m_checkForceShowFieldsWhenFPSelected->SetValue( aCfg->m_Display.m_ForceShowFieldsWhenFPSelected );
  50. m_live3Drefresh->SetValue( aCfg->m_Display.m_Live3DRefresh );
  51. m_checkCrossProbeOnSelection->SetValue( aCfg->m_CrossProbing.on_selection );
  52. m_checkCrossProbeCenter->SetValue( aCfg->m_CrossProbing.center_on_items );
  53. m_checkCrossProbeZoom->SetValue( aCfg->m_CrossProbing.zoom_to_fit );
  54. m_checkCrossProbeAutoHighlight->SetValue( aCfg->m_CrossProbing.auto_highlight );
  55. }
  56. bool PANEL_PCB_DISPLAY_OPTIONS::TransferDataToWindow()
  57. {
  58. if( m_isPCBEdit )
  59. {
  60. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  61. PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>();
  62. loadPCBSettings( cfg );
  63. }
  64. m_galOptsPanel->TransferDataToWindow();
  65. return true;
  66. }
  67. /*
  68. * Update variables with new options
  69. */
  70. bool PANEL_PCB_DISPLAY_OPTIONS::TransferDataFromWindow()
  71. {
  72. m_galOptsPanel->TransferDataFromWindow();
  73. if( m_isPCBEdit )
  74. {
  75. PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
  76. int i = m_OptDisplayTracksClearance->GetSelection();
  77. cfg->m_Display.m_TrackClearance = UTIL::GetValFromConfig( clearanceModeMap, i );
  78. cfg->m_Display.m_PadClearance = m_OptDisplayPadClearence->GetValue();
  79. cfg->m_ViewersDisplay.m_DisplayPadNumbers = m_OptDisplayPadNumber->GetValue();
  80. cfg->m_Display.m_NetNames = m_ShowNetNamesOption->GetSelection();
  81. cfg->m_Display.m_ForceShowFieldsWhenFPSelected = m_checkForceShowFieldsWhenFPSelected->GetValue();
  82. cfg->m_Display.m_Live3DRefresh = m_live3Drefresh->GetValue();
  83. cfg->m_CrossProbing.on_selection = m_checkCrossProbeOnSelection->GetValue();
  84. cfg->m_CrossProbing.center_on_items = m_checkCrossProbeCenter->GetValue();
  85. cfg->m_CrossProbing.zoom_to_fit = m_checkCrossProbeZoom->GetValue();
  86. cfg->m_CrossProbing.auto_highlight = m_checkCrossProbeAutoHighlight->GetValue();
  87. }
  88. return true;
  89. }
  90. void PANEL_PCB_DISPLAY_OPTIONS::ResetPanel()
  91. {
  92. PCBNEW_SETTINGS cfg;
  93. cfg.Load(); // Loading without a file will init to defaults
  94. if( m_isPCBEdit )
  95. loadPCBSettings( &cfg );
  96. m_galOptsPanel->ResetPanel( &cfg );
  97. }