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.

150 lines
6.2 KiB

  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-2020 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 <board_design_settings.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 <widgets/paged_dialog.h>
  31. #include <footprint_edit_frame.h>
  32. PANEL_EDIT_OPTIONS::PANEL_EDIT_OPTIONS( PCB_BASE_EDIT_FRAME* aFrame, PAGED_DIALOG* aParent ) :
  33. PANEL_EDIT_OPTIONS_BASE( aParent->GetTreebook() ), m_frame( aFrame )
  34. {
  35. m_magneticPads->Show( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) != nullptr );
  36. m_magneticGraphics->Show( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) != nullptr );
  37. m_flipLeftRight->Show( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) != nullptr );
  38. #ifdef __WXOSX_MAC__
  39. m_mouseCmdsOSX->Show( true );
  40. m_mouseCmdsWinLin->Show( false );
  41. #else
  42. m_mouseCmdsWinLin->Show( true );
  43. m_mouseCmdsOSX->Show( false );
  44. #endif
  45. m_optionsBook->SetSelection( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) ? 1 : 0 );
  46. }
  47. bool PANEL_EDIT_OPTIONS::TransferDataToWindow()
  48. {
  49. const PCB_DISPLAY_OPTIONS& displ_opts = m_frame->GetDisplayOptions();
  50. const PCBNEW_SETTINGS& general_opts = m_frame->Settings();
  51. m_segments45OnlyCtrl->SetValue( general_opts.m_Use45DegreeGraphicSegments );
  52. wxString rotationAngle;
  53. rotationAngle = AngleToStringDegrees( (double) m_frame->GetRotationAngle() );
  54. m_rotationAngle->SetValue( rotationAngle );
  55. if( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
  56. {
  57. /* Set display options */
  58. m_OptDisplayCurvedRatsnestLines->SetValue( displ_opts.m_DisplayRatsnestLinesCurved );
  59. m_showSelectedRatsnest->SetValue( displ_opts.m_ShowModuleRatsnest );
  60. m_magneticPadChoice->SetSelection( static_cast<int>( general_opts.m_MagneticItems.pads ) );
  61. m_magneticTrackChoice->SetSelection( static_cast<int>( general_opts.m_MagneticItems.tracks ) );
  62. m_magneticGraphicsChoice->SetSelection( !general_opts.m_MagneticItems.graphics );
  63. m_flipLeftRight->SetValue( general_opts.m_FlipLeftRight );
  64. m_Show_Page_Limits->SetValue( m_frame->ShowPageLimits() );
  65. switch( general_opts.m_TrackDragAction )
  66. {
  67. case TRACK_DRAG_ACTION::MOVE: m_rbTrackDragMove->SetValue( true ); break;
  68. case TRACK_DRAG_ACTION::DRAG: m_rbTrackDrag45->SetValue( true ); break;
  69. case TRACK_DRAG_ACTION::DRAG_FREE_ANGLE: m_rbTrackDragFree->SetValue( true ); break;
  70. }
  71. }
  72. else if( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
  73. {
  74. m_magneticPads->SetValue( m_frame->GetMagneticItemsSettings()->pads
  75. == MAGNETIC_OPTIONS::CAPTURE_ALWAYS );
  76. m_magneticGraphics->SetValue( m_frame->GetMagneticItemsSettings()->graphics );
  77. }
  78. return true;
  79. }
  80. bool PANEL_EDIT_OPTIONS::TransferDataFromWindow()
  81. {
  82. PCB_DISPLAY_OPTIONS displ_opts = m_frame->GetDisplayOptions();
  83. m_frame->SetRotationAngle( wxRound( 10.0 * wxAtof( m_rotationAngle->GetValue() ) ) );
  84. m_frame->Settings().m_Use45DegreeGraphicSegments = m_segments45OnlyCtrl->GetValue();
  85. if( dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
  86. {
  87. PCBNEW_SETTINGS& pcbnewSettings = m_frame->Settings();
  88. displ_opts.m_DisplayRatsnestLinesCurved = m_OptDisplayCurvedRatsnestLines->GetValue();
  89. displ_opts.m_ShowModuleRatsnest = m_showSelectedRatsnest->GetValue();
  90. m_frame->Settings().m_MagneticItems.pads =
  91. static_cast<MAGNETIC_OPTIONS>( m_magneticPadChoice->GetSelection() );
  92. m_frame->Settings().m_MagneticItems.tracks =
  93. static_cast<MAGNETIC_OPTIONS>( m_magneticTrackChoice->GetSelection() );
  94. m_frame->Settings().m_MagneticItems.graphics = !m_magneticGraphicsChoice->GetSelection();
  95. m_frame->Settings().m_FlipLeftRight = m_flipLeftRight->GetValue();
  96. m_frame->SetShowPageLimits( m_Show_Page_Limits->GetValue() );
  97. if( m_rbTrackDragMove->GetValue() )
  98. pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::MOVE;
  99. else if( m_rbTrackDrag45->GetValue() )
  100. pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::DRAG;
  101. else if( m_rbTrackDragFree->GetValue() )
  102. pcbnewSettings.m_TrackDragAction = TRACK_DRAG_ACTION::DRAG_FREE_ANGLE;
  103. }
  104. else if( dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
  105. {
  106. m_frame->GetMagneticItemsSettings()->pads = m_magneticPads->GetValue()
  107. ? MAGNETIC_OPTIONS::CAPTURE_ALWAYS
  108. : MAGNETIC_OPTIONS::NO_EFFECT;
  109. m_frame->GetMagneticItemsSettings()->graphics = m_magneticGraphics->GetValue();
  110. }
  111. // Apply changes to the GAL
  112. KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
  113. KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() );
  114. KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
  115. m_frame->SetDisplayOptions( displ_opts );
  116. settings->LoadDisplayOptions( displ_opts, m_frame->ShowPageLimits() );
  117. view->RecacheAllItems();
  118. view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  119. m_frame->GetCanvas()->Refresh();
  120. return true;
  121. }