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
5.8 KiB

  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 modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <functional>
  20. #include <memory>
  21. #include <view/view.h>
  22. #include <tool/tool_manager.h>
  23. #include <view/wx_view_controls.h>
  24. #include <drawing_sheet/ds_proxy_view_item.h>
  25. #include <drawing_sheet/ds_data_item.h>
  26. #include <drawing_sheet/ds_data_model.h>
  27. #include <drawing_sheet/ds_painter.h>
  28. #include <pgm_base.h>
  29. #include <kiway.h>
  30. #include <settings/settings_manager.h>
  31. #include <gal/graphics_abstraction_layer.h>
  32. #include "pl_draw_panel_gal.h"
  33. #include "pl_editor_frame.h"
  34. #include "pl_editor_settings.h"
  35. #include "tools/pl_actions.h"
  36. #include "tools/pl_selection_tool.h"
  37. #include <zoom_defines.h>
  38. using namespace std::placeholders;
  39. PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
  40. const wxPoint& aPosition, const wxSize& aSize,
  41. KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
  42. EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
  43. {
  44. m_view = new KIGFX::VIEW();
  45. m_view->SetGAL( m_gal );
  46. GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
  47. m_painter = std::make_unique<KIGFX::DS_PAINTER>( m_gal );
  48. PL_EDITOR_SETTINGS* cfg = GetAppSettings<PL_EDITOR_SETTINGS>( "pl_editor" );
  49. m_painter->GetSettings()->LoadColors( ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME ) );
  50. m_view->SetPainter( m_painter.get() );
  51. // This fixes the zoom in and zoom out limits
  52. m_view->SetScaleLimits( ZOOM_MAX_LIMIT_PLEDITOR, ZOOM_MIN_LIMIT_PLEDITOR );
  53. setDefaultLayerDeps();
  54. m_view->SetLayerVisible( LAYER_DRAWINGSHEET, true );
  55. m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, true );
  56. m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, false );
  57. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
  58. }
  59. PL_DRAW_PANEL_GAL::~PL_DRAW_PANEL_GAL()
  60. {
  61. }
  62. void PL_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
  63. std::vector<MSG_PANEL_ITEM>& aList )
  64. {
  65. }
  66. void PL_DRAW_PANEL_GAL::DisplayDrawingSheet()
  67. {
  68. PL_SELECTION_TOOL* selTool = m_edaFrame->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  69. DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
  70. selTool->GetSelection().Clear();
  71. m_view->Clear();
  72. m_pageDrawItem.reset();
  73. model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), drawSheetIUScale.IU_PER_MILS );
  74. // To show the formatted texts instead of raw texts in drawing sheet editor, we need
  75. // a dummy DS_DRAW_ITEM_LIST.
  76. DS_DRAW_ITEM_LIST dummy( drawSheetIUScale );
  77. dummy.SetPaperFormat( m_edaFrame->GetPageSettings().GetType() );
  78. dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
  79. dummy.SetProject( &m_edaFrame->Prj() );
  80. for( DS_DATA_ITEM* dataItem : model.GetItems() )
  81. dataItem->SyncDrawItems( &dummy, m_view );
  82. // Build and add a DS_DRAW_ITEM_PAGE to show the page limits and the corner position
  83. // of the selected corner for coord origin of new items
  84. // Not also this item has no peer in DS_DATA_MODEL list.
  85. const int penWidth = 0; // This value is to use the default thickness line
  86. constexpr double markerSize = drawSheetIUScale.mmToIU( 5 );
  87. m_pageDrawItem = std::make_unique<DS_DRAW_ITEM_PAGE>( penWidth, markerSize );
  88. m_view->Add( m_pageDrawItem.get() );
  89. selTool->RebuildSelection();
  90. // Gives a reasonable boundary to the view area
  91. // Otherwise scroll bars are not usable
  92. // A full size = 2 * page size allows a margin around the drawing sheet.
  93. // (Note: no need to have a large working area: nothing can be drawn outside th page size).
  94. double size_x = m_edaFrame->GetPageSizeIU().x;
  95. double size_y = m_edaFrame->GetPageSizeIU().y;
  96. BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ), VECTOR2D( size_x * 1.5, size_y * 1.5) );
  97. m_view->SetBoundary( boundary );
  98. m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
  99. VECTOR2I originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
  100. m_pageDrawItem->SetMarkerPos( originCoord );
  101. }
  102. bool PL_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
  103. {
  104. bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
  105. setDefaultLayerDeps();
  106. GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
  107. return rv;
  108. }
  109. void PL_DRAW_PANEL_GAL::setDefaultLayerDeps()
  110. {
  111. for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
  112. m_view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
  113. m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
  114. m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
  115. m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
  116. m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
  117. m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
  118. }
  119. void PL_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
  120. {
  121. m_view->ClearTopLayers();
  122. m_view->SetTopLayer( aLayer );
  123. m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
  124. m_view->SetTopLayer( LAYER_GP_OVERLAY );
  125. m_view->UpdateAllLayersOrder();
  126. }