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.

142 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018-2019 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 <view/wx_view_controls.h>
  24. #include <drawing_sheet/ds_proxy_view_item.h>
  25. #include <gal/graphics_abstraction_layer.h>
  26. #include <sch_preview_panel.h>
  27. #include <sch_view.h>
  28. #include <sch_painter.h>
  29. #include <sch_edit_frame.h>
  30. #include <settings/settings_manager.h>
  31. #include <preview_items/selection_area.h>
  32. #include <zoom_defines.h>
  33. #include <functional>
  34. #include <sch_sheet.h>
  35. #include <pgm_base.h>
  36. using namespace std::placeholders;
  37. SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
  38. const wxPoint& aPosition, const wxSize& aSize,
  39. KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
  40. EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
  41. {
  42. m_view = new KIGFX::SCH_VIEW( true, nullptr );
  43. m_view->SetGAL( m_gal );
  44. m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
  45. m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) );
  46. m_painter->GetSettings()->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
  47. m_view->SetPainter( m_painter.get() );
  48. // This fixes the zoom in and zoom out limits:
  49. m_view->SetScaleLimits( ZOOM_MAX_LIMIT_EESCHEMA_PREVIEW, ZOOM_MIN_LIMIT_EESCHEMA_PREVIEW );
  50. m_view->SetMirror( false, false );
  51. setDefaultLayerOrder();
  52. setDefaultLayerDeps();
  53. view()->UpdateAllLayersOrder();
  54. // View controls is the first in the event handler chain, so the Tool Framework operates
  55. // on updated viewport data.
  56. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
  57. m_gal->SetGridColor( m_painter->GetSettings()->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
  58. m_gal->SetCursorEnabled( false );
  59. m_gal->SetGridSize( VECTOR2D( Mils2iu( 100.0 ), Mils2iu( 100.0 ) ) );
  60. SetEvtHandlerEnabled( true );
  61. SetFocus();
  62. Show( true );
  63. Raise();
  64. StartDrawing();
  65. }
  66. SCH_PREVIEW_PANEL::~SCH_PREVIEW_PANEL()
  67. {
  68. }
  69. void SCH_PREVIEW_PANEL::OnShow()
  70. {
  71. //m_view->RecacheAllItems();
  72. }
  73. void SCH_PREVIEW_PANEL::setDefaultLayerOrder()
  74. {
  75. for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
  76. {
  77. LAYER_NUM layer = SCH_LAYER_ORDER[i];
  78. wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
  79. m_view->SetLayerOrder( layer, i );
  80. }
  81. }
  82. void SCH_PREVIEW_PANEL::setDefaultLayerDeps()
  83. {
  84. // An alias's fields don't know how to substitute in their parent's values, so we
  85. // don't let them draw themselves. This means no caching.
  86. auto target = KIGFX::TARGET_NONCACHED;
  87. for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
  88. m_view->SetLayerTarget( i, target );
  89. m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
  90. m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
  91. m_view->SetLayerTarget( LAYER_SELECT_OVERLAY , KIGFX::TARGET_OVERLAY );
  92. m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
  93. m_view->SetLayerTarget( LAYER_DRAWINGSHEET , KIGFX::TARGET_NONCACHED );
  94. m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
  95. }
  96. KIGFX::SCH_VIEW* SCH_PREVIEW_PANEL::view() const
  97. {
  98. return static_cast<KIGFX::SCH_VIEW*>( m_view );
  99. }
  100. void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
  101. {
  102. EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
  103. }
  104. void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
  105. {
  106. if( IsShown() )
  107. EDA_DRAW_PANEL_GAL::onPaint( aEvent );
  108. }