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.

160 lines
4.9 KiB

2 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2023 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 <widgets/gal_options_panel.h>
  24. #include <settings/app_settings.h>
  25. #include <eda_draw_frame.h>
  26. #include <config_map.h>
  27. /*
  28. * Spin control parameters
  29. */
  30. static const double gridThicknessMin = 0.5;
  31. static const double gridThicknessMax = 10.0;
  32. static const double gridThicknessStep = 0.5;
  33. static const int gridMinSpacingMin = 5;
  34. static const int gridMinSpacingMax = 200;
  35. static const int gridMinSpacingStep = 5;
  36. ///TODO: These are duplicated in gal_display_options - Unify!
  37. static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleSelectMap =
  38. {
  39. { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
  40. { KIGFX::GRID_STYLE::LINES, 1 },
  41. { KIGFX::GRID_STYLE::SMALL_CROSS, 2 },
  42. };
  43. static const UTIL::CFG_MAP<KIGFX::GRID_SNAPPING> gridSnapConfigVals =
  44. {
  45. { KIGFX::GRID_SNAPPING::ALWAYS, 0 },
  46. { KIGFX::GRID_SNAPPING::WITH_GRID, 1 },
  47. { KIGFX::GRID_SNAPPING::NEVER, 2 }
  48. };
  49. GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, APP_SETTINGS_BASE* aAppSettings ) :
  50. GAL_OPTIONS_PANEL_BASE( aParent ),
  51. m_cfg( aAppSettings )
  52. {
  53. // Rendering engine
  54. #ifdef __WXMAC__
  55. // On MAC, Cairo render does not work.
  56. m_renderingSizer->Show( false );
  57. #endif
  58. // Grid settings subpanel
  59. int selection = 0; // default selection
  60. for( double size = gridThicknessMin; size <= gridThicknessMax; size += gridThicknessStep )
  61. {
  62. m_gridThicknessList.push_back( size );
  63. m_gridLineWidth->Append( wxString::Format( wxT( "%.1f" ), size ) );
  64. if( m_cfg->m_Window.grid.line_width == size )
  65. selection = m_gridLineWidth->GetCount() - 1;
  66. }
  67. m_gridLineWidth->SetSelection( selection );
  68. m_gridMinSpacing->SetRange( gridMinSpacingMin, gridMinSpacingMax );
  69. m_gridMinSpacing->SetIncrement( gridMinSpacingStep );
  70. }
  71. bool GAL_OPTIONS_PANEL::TransferDataToWindow()
  72. {
  73. #ifndef __WXMAC__
  74. auto canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( m_cfg->m_Graphics.canvas_type );
  75. if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL )
  76. m_rbAccelerated->SetValue( true );
  77. else
  78. m_rbFallback->SetValue( true );
  79. #endif
  80. m_gridSnapOptions->SetSelection( m_cfg->m_Window.grid.snap );
  81. if( m_cfg->m_Window.grid.style == 0 )
  82. m_rbDots->SetValue( true );
  83. else if( m_cfg->m_Window.grid.style == 1 )
  84. m_rbLines->SetValue( true );
  85. else
  86. m_rbCrosses->SetValue( true );
  87. m_gridMinSpacing->SetValue( m_cfg->m_Window.grid.min_spacing );
  88. if( m_cfg->m_Window.cursor.fullscreen_cursor )
  89. m_rbFullWindowCrosshairs->SetValue( true );
  90. else
  91. m_rbSmallCrosshairs->SetValue( true );
  92. m_forceCursorDisplay->SetValue( m_cfg->m_Window.cursor.always_show_cursor );
  93. return true;
  94. }
  95. bool GAL_OPTIONS_PANEL::TransferDataFromWindow()
  96. {
  97. m_cfg->m_Window.grid.snap = m_gridSnapOptions->GetSelection();
  98. if( m_rbDots->GetValue() )
  99. m_cfg->m_Window.grid.style = 0;
  100. else if( m_rbLines->GetValue() )
  101. m_cfg->m_Window.grid.style = 1;
  102. else
  103. m_cfg->m_Window.grid.style = 2;
  104. if( m_gridLineWidth->GetSelection() >= 0 )
  105. m_cfg->m_Window.grid.line_width = m_gridThicknessList[ m_gridLineWidth->GetSelection() ];
  106. m_cfg->m_Window.grid.min_spacing = m_gridMinSpacing->GetValue();
  107. m_cfg->m_Window.cursor.fullscreen_cursor = m_rbFullWindowCrosshairs->GetValue();
  108. m_cfg->m_Window.cursor.always_show_cursor = m_forceCursorDisplay->GetValue();
  109. #ifndef __WXMAC__
  110. m_cfg->m_Graphics.canvas_type = m_rbAccelerated->GetValue() ?
  111. EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL :
  112. EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO;
  113. #endif
  114. return true;
  115. }
  116. bool GAL_OPTIONS_PANEL::ResetPanel( APP_SETTINGS_BASE* aAppSettings )
  117. {
  118. APP_SETTINGS_BASE* saved = m_cfg;
  119. m_cfg = aAppSettings;
  120. TransferDataToWindow();
  121. m_cfg = saved;
  122. return true;
  123. }