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.

153 lines
4.7 KiB

4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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( 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. SCH_RENDER_SETTINGS* renderSettings = GetRenderSettings();
  47. renderSettings->LoadColors( ::GetColorSettings( DEFAULT_THEME ) );
  48. renderSettings->m_ShowPinsElectricalType = false;
  49. renderSettings->m_ShowPinNumbers = false;
  50. renderSettings->m_TextOffsetRatio = 0.35;
  51. m_view->SetPainter( m_painter.get() );
  52. // This fixes the zoom in and zoom out limits:
  53. m_view->SetScaleLimits( ZOOM_MAX_LIMIT_EESCHEMA_PREVIEW, ZOOM_MIN_LIMIT_EESCHEMA_PREVIEW );
  54. m_view->SetMirror( false, false );
  55. setDefaultLayerOrder();
  56. setDefaultLayerDeps();
  57. view()->UpdateAllLayersOrder();
  58. // View controls is the first in the event handler chain, so the Tool Framework operates
  59. // on updated viewport data.
  60. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
  61. m_gal->SetGridColor( m_painter->GetSettings()->GetLayerColor( LAYER_SCHEMATIC_GRID ) );
  62. m_gal->SetCursorEnabled( false );
  63. m_gal->SetGridSize( VECTOR2D( schIUScale.MilsToIU( 100.0 ), schIUScale.MilsToIU( 100.0 ) ) );
  64. SetEvtHandlerEnabled( true );
  65. SetFocus();
  66. Show( true );
  67. Raise();
  68. StartDrawing();
  69. }
  70. SCH_PREVIEW_PANEL::~SCH_PREVIEW_PANEL()
  71. {
  72. }
  73. SCH_RENDER_SETTINGS* SCH_PREVIEW_PANEL::GetRenderSettings() const
  74. {
  75. return static_cast<SCH_RENDER_SETTINGS*>( m_painter->GetSettings() );
  76. }
  77. void SCH_PREVIEW_PANEL::OnShow()
  78. {
  79. //m_view->RecacheAllItems();
  80. }
  81. void SCH_PREVIEW_PANEL::setDefaultLayerOrder()
  82. {
  83. for( int i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( int ); ++i )
  84. {
  85. int layer = SCH_LAYER_ORDER[i];
  86. wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
  87. m_view->SetLayerOrder( layer, i );
  88. }
  89. }
  90. void SCH_PREVIEW_PANEL::setDefaultLayerDeps()
  91. {
  92. // An alias's fields don't know how to substitute in their parent's values, so we
  93. // don't let them draw themselves. This means no caching.
  94. auto target = KIGFX::TARGET_NONCACHED;
  95. for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
  96. m_view->SetLayerTarget( i, target );
  97. m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
  98. m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
  99. m_view->SetLayerTarget( LAYER_SELECT_OVERLAY , KIGFX::TARGET_OVERLAY );
  100. m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
  101. m_view->SetLayerTarget( LAYER_DRAWINGSHEET , KIGFX::TARGET_NONCACHED );
  102. m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET ) ;
  103. }
  104. KIGFX::SCH_VIEW* SCH_PREVIEW_PANEL::view() const
  105. {
  106. return static_cast<KIGFX::SCH_VIEW*>( m_view );
  107. }
  108. void SCH_PREVIEW_PANEL::Refresh( bool aEraseBackground, const wxRect* aRect )
  109. {
  110. EDA_DRAW_PANEL_GAL::Refresh( aEraseBackground, aRect );
  111. }
  112. void SCH_PREVIEW_PANEL::onPaint( wxPaintEvent& aEvent )
  113. {
  114. if( IsShownOnScreen() )
  115. EDA_DRAW_PANEL_GAL::onPaint( aEvent );
  116. }