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.

171 lines
7.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2021 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 <string_utils.h>
  25. #include <panel_edit_options.h>
  26. #include <pcb_edit_frame.h>
  27. #include <pcb_painter.h>
  28. #include <pcb_view.h>
  29. #include <pcbnew_settings.h>
  30. #include <ratsnest/ratsnest_view_item.h>
  31. #include <widgets/paged_dialog.h>
  32. #include <footprint_edit_frame.h>
  33. #include <wx/treebook.h>
  34. PANEL_EDIT_OPTIONS::PANEL_EDIT_OPTIONS( PCB_BASE_EDIT_FRAME* aFrame, PAGED_DIALOG* aParent ) :
  35. PANEL_EDIT_OPTIONS_BASE( aParent->GetTreebook() ), m_frame( aFrame )
  36. {
  37. m_magneticPads->Show( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) != nullptr );
  38. m_magneticGraphics->Show( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) != nullptr );
  39. m_flipLeftRight->Show( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) != nullptr );
  40. m_allowFreePads->Show( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) != nullptr );
  41. #ifdef __WXOSX_MAC__
  42. m_mouseCmdsOSX->Show( true );
  43. m_mouseCmdsWinLin->Show( false );
  44. #else
  45. m_mouseCmdsWinLin->Show( true );
  46. m_mouseCmdsOSX->Show( false );
  47. #endif
  48. m_optionsBook->SetSelection( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) ? 1 : 0 );
  49. }
  50. bool PANEL_EDIT_OPTIONS::TransferDataToWindow()
  51. {
  52. const PCB_DISPLAY_OPTIONS& displ_opts = m_frame->GetDisplayOptions();
  53. const PCBNEW_SETTINGS& general_opts = m_frame->Settings();
  54. wxString rotationAngle;
  55. rotationAngle = AngleToStringDegrees( (double) m_frame->GetRotationAngle() );
  56. m_rotationAngle->SetValue( rotationAngle );
  57. if( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
  58. {
  59. const MAGNETIC_SETTINGS& mag_opts = general_opts.m_MagneticItems;
  60. /* Set display options */
  61. m_OptDisplayCurvedRatsnestLines->SetValue( displ_opts.m_DisplayRatsnestLinesCurved );
  62. m_showSelectedRatsnest->SetValue( displ_opts.m_ShowModuleRatsnest );
  63. m_magneticPadChoice->SetSelection( static_cast<int>( mag_opts.pads ) );
  64. m_magneticTrackChoice->SetSelection( static_cast<int>( mag_opts.tracks ) );
  65. m_magneticGraphicsChoice->SetSelection( !mag_opts.graphics );
  66. m_flipLeftRight->SetValue( general_opts.m_FlipLeftRight );
  67. switch( general_opts.m_TrackDragAction )
  68. {
  69. case TRACK_DRAG_ACTION::MOVE: m_rbTrackDragMove->SetValue( true ); break;
  70. case TRACK_DRAG_ACTION::DRAG: m_rbTrackDrag45->SetValue( true ); break;
  71. case TRACK_DRAG_ACTION::DRAG_FREE_ANGLE: m_rbTrackDragFree->SetValue( true ); break;
  72. }
  73. m_showPageLimits->SetValue( m_frame->ShowPageLimits() );
  74. m_autoRefillZones->SetValue( general_opts.m_AutoRefillZones );
  75. m_allowFreePads->SetValue( general_opts.m_AllowFreePads );
  76. m_cbPcbGraphic45Mode->SetValue( general_opts.m_PcbUse45DegreeLimit );
  77. }
  78. else if( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
  79. {
  80. const MAGNETIC_SETTINGS* mag_opts = m_frame->GetMagneticItemsSettings();
  81. m_magneticPads->SetValue( mag_opts->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS );
  82. m_magneticGraphics->SetValue( mag_opts->graphics );
  83. m_cbFpGraphic45Mode->SetValue( general_opts.m_FpeditUse45DegreeLimit );
  84. }
  85. return true;
  86. }
  87. bool PANEL_EDIT_OPTIONS::TransferDataFromWindow()
  88. {
  89. PCB_DISPLAY_OPTIONS displ_opts = m_frame->GetDisplayOptions();
  90. m_frame->SetRotationAngle( wxRound( 10.0 * wxAtof( m_rotationAngle->GetValue() ) ) );
  91. if( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
  92. {
  93. PCBNEW_SETTINGS& pcbnewSettings = m_frame->Settings();
  94. MAGNETIC_SETTINGS& mag_opts = pcbnewSettings.m_MagneticItems;
  95. displ_opts.m_DisplayRatsnestLinesCurved = m_OptDisplayCurvedRatsnestLines->GetValue();
  96. displ_opts.m_ShowModuleRatsnest = m_showSelectedRatsnest->GetValue();
  97. mag_opts.pads = static_cast<MAGNETIC_OPTIONS>( m_magneticPadChoice->GetSelection() );
  98. mag_opts.tracks = static_cast<MAGNETIC_OPTIONS>( m_magneticTrackChoice->GetSelection() );
  99. mag_opts.graphics = !m_magneticGraphicsChoice->GetSelection();
  100. pcbnewSettings.m_FlipLeftRight = m_flipLeftRight->GetValue();
  101. pcbnewSettings.m_AutoRefillZones = m_autoRefillZones->GetValue();
  102. pcbnewSettings.m_AllowFreePads = m_allowFreePads->GetValue();
  103. m_frame->SetShowPageLimits( m_showPageLimits->GetValue() );
  104. if( m_rbTrackDragMove->GetValue() )
  105. pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::MOVE;
  106. else if( m_rbTrackDrag45->GetValue() )
  107. pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::DRAG;
  108. else if( m_rbTrackDragFree->GetValue() )
  109. pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::DRAG_FREE_ANGLE;
  110. pcbnewSettings.m_PcbUse45DegreeLimit = m_cbPcbGraphic45Mode->GetValue();
  111. }
  112. else if( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
  113. {
  114. MAGNETIC_SETTINGS* mag_opts = m_frame->GetMagneticItemsSettings();
  115. mag_opts->pads = m_magneticPads->GetValue() ? MAGNETIC_OPTIONS::CAPTURE_ALWAYS
  116. : MAGNETIC_OPTIONS::NO_EFFECT;
  117. mag_opts->graphics = m_magneticGraphics->GetValue();
  118. m_frame->Settings().m_FpeditUse45DegreeLimit = m_cbFpGraphic45Mode->GetValue();
  119. }
  120. // Apply changes to the GAL
  121. KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
  122. KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
  123. KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
  124. m_frame->SetDisplayOptions( displ_opts, false );
  125. settings->LoadDisplayOptions( displ_opts, m_frame->ShowPageLimits() );
  126. view->UpdateAllItemsConditionally( KIGFX::REPAINT,
  127. []( KIGFX::VIEW_ITEM* aItem ) -> bool
  128. {
  129. return dynamic_cast<RATSNEST_VIEW_ITEM*>( aItem );
  130. } );
  131. view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  132. m_frame->GetCanvas()->Refresh();
  133. return true;
  134. }