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.

119 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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 <pcb_base_edit_frame.h>
  25. #include <tool/tool_manager.h>
  26. #include <pcb_draw_panel_gal.h>
  27. #include <gal/graphics_abstraction_layer.h>
  28. #include <class_board.h>
  29. #include <view/view.h>
  30. #include "footprint_info_impl.h"
  31. #include <project.h>
  32. #include <tools/pcb_actions.h>
  33. PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
  34. FRAME_T aFrameType, const wxString& aTitle,
  35. const wxPoint& aPos, const wxSize& aSize, long aStyle,
  36. const wxString& aFrameName ) :
  37. PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
  38. m_rotationAngle( 900 ), m_undoRedoBlocked( false )
  39. {
  40. if( !GFootprintList.GetCount() )
  41. {
  42. wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
  43. GFootprintList.ReadCacheFromFile( &footprintInfoCache );
  44. }
  45. }
  46. PCB_BASE_EDIT_FRAME::~PCB_BASE_EDIT_FRAME()
  47. {
  48. wxTextFile footprintInfoCache( Prj().GetProjectPath() + "fp-info-cache" );
  49. GFootprintList.WriteCacheToFile( &footprintInfoCache );
  50. }
  51. void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
  52. {
  53. wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900,
  54. wxT( "Invalid rotation angle, defaulting to 90." ) );
  55. m_rotationAngle = aRotationAngle;
  56. }
  57. void PCB_BASE_EDIT_FRAME::UseGalCanvas( bool aEnable )
  58. {
  59. PCB_BASE_FRAME::UseGalCanvas( aEnable );
  60. // No matter what, reenable undo/redo on switching to the legacy canvas
  61. if( !aEnable )
  62. UndoRedoBlock( false );
  63. else
  64. static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( m_Pcb );
  65. }
  66. void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard )
  67. {
  68. bool new_board = ( aBoard != m_Pcb );
  69. if( new_board )
  70. {
  71. if( m_toolManager )
  72. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  73. GetGalCanvas()->GetView()->Clear();
  74. }
  75. PCB_BASE_FRAME::SetBoard( aBoard );
  76. GetGalCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetGridOrigin() ) );
  77. // update the tool manager with the new board and its view.
  78. if( m_toolManager )
  79. {
  80. PCB_DRAW_PANEL_GAL* drawPanel = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
  81. drawPanel->DisplayBoard( aBoard );
  82. drawPanel->UseColorScheme( &Settings().Colors() );
  83. m_toolManager->SetEnvironment( aBoard, drawPanel->GetView(),
  84. drawPanel->GetViewControls(), this );
  85. if( new_board )
  86. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  87. }
  88. }
  89. void PCB_BASE_EDIT_FRAME::unitsChangeRefresh()
  90. {
  91. PCB_BASE_FRAME::unitsChangeRefresh();
  92. ReCreateAuxiliaryToolbar();
  93. if( m_toolManager )
  94. m_toolManager->RunAction( PCB_ACTIONS::updateUnits, true );
  95. }