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.

172 lines
6.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 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( true );
  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. SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
  49. PL_EDITOR_SETTINGS* cfg = settingsManager.GetAppSettings<PL_EDITOR_SETTINGS>();
  50. m_painter->GetSettings()->LoadColors( settingsManager.GetColorSettings( cfg->m_ColorTheme ) );
  51. m_view->SetPainter( m_painter.get() );
  52. // This fixes the zoom in and zoom out limits
  53. m_view->SetScaleLimits( ZOOM_MAX_LIMIT_PLEDITOR, ZOOM_MIN_LIMIT_PLEDITOR );
  54. setDefaultLayerDeps();
  55. m_view->SetLayerVisible( LAYER_DRAWINGSHEET, true );
  56. m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, true );
  57. m_view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, false );
  58. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
  59. }
  60. PL_DRAW_PANEL_GAL::~PL_DRAW_PANEL_GAL()
  61. {
  62. }
  63. void PL_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
  64. std::vector<MSG_PANEL_ITEM>& aList )
  65. {
  66. }
  67. void PL_DRAW_PANEL_GAL::DisplayDrawingSheet()
  68. {
  69. PL_SELECTION_TOOL* selTool = m_edaFrame->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  70. DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
  71. selTool->GetSelection().Clear();
  72. m_view->Clear();
  73. m_pageDrawItem.reset();
  74. model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), drawSheetIUScale.IU_PER_MILS );
  75. // To show the formatted texts instead of raw texts in drawing sheet editor, we need
  76. // a dummy DS_DRAW_ITEM_LIST.
  77. DS_DRAW_ITEM_LIST dummy;
  78. dummy.SetPaperFormat( m_edaFrame->GetPageSettings().GetType() );
  79. dummy.SetTitleBlock( &m_edaFrame->GetTitleBlock() );
  80. dummy.SetProject( &m_edaFrame->Prj() );
  81. dummy.SetMilsToIUfactor( drawSheetIUScale.IU_PER_MILS );
  82. for( DS_DATA_ITEM* dataItem : model.GetItems() )
  83. dataItem->SyncDrawItems( &dummy, m_view );
  84. // Build and add a DS_DRAW_ITEM_PAGE to show the page limits and the corner position
  85. // of the selected corner for coord origin of new items
  86. // Not also this item has no peer in DS_DATA_MODEL list.
  87. const int penWidth = 0; // This value is to use the default thickness line
  88. constexpr double markerSize = drawSheetIUScale.mmToIU( 5 );
  89. m_pageDrawItem = std::make_unique<DS_DRAW_ITEM_PAGE>( penWidth, markerSize );
  90. m_view->Add( m_pageDrawItem.get() );
  91. selTool->RebuildSelection();
  92. // Gives a reasonable boundary to the view area
  93. // Otherwise scroll bars are not usable
  94. // A full size = 2 * page size allows a margin around the drawing sheet.
  95. // (Note: no need to have a large working area: nothing can be drawn outside th page size).
  96. double size_x = m_edaFrame->GetPageSizeIU().x;
  97. double size_y = m_edaFrame->GetPageSizeIU().y;
  98. BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ), VECTOR2D( size_x * 1.5, size_y * 1.5) );
  99. m_view->SetBoundary( boundary );
  100. m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );
  101. VECTOR2I originCoord = static_cast<PL_EDITOR_FRAME*>( m_edaFrame )->ReturnCoordOriginCorner();
  102. m_pageDrawItem->SetMarkerPos( originCoord );
  103. }
  104. bool PL_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
  105. {
  106. bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
  107. setDefaultLayerDeps();
  108. GetGAL()->SetWorldUnitLength( 1.0/drawSheetIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
  109. return rv;
  110. }
  111. void PL_DRAW_PANEL_GAL::setDefaultLayerDeps()
  112. {
  113. for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
  114. m_view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
  115. m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
  116. m_view->SetLayerTarget( LAYER_SELECT_OVERLAY, KIGFX::TARGET_OVERLAY );
  117. m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
  118. m_view->SetLayerTarget( LAYER_GP_OVERLAY, KIGFX::TARGET_OVERLAY );
  119. m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
  120. }
  121. void PL_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
  122. {
  123. m_view->ClearTopLayers();
  124. m_view->SetTopLayer( aLayer );
  125. m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
  126. m_view->SetTopLayer( LAYER_GP_OVERLAY );
  127. m_view->UpdateAllLayersOrder();
  128. }