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.

136 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2018 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 <ws_proxy_view_item.h>
  25. #include <ws_draw_item.h>
  26. #include <ws_data_item.h>
  27. #include <gal/graphics_abstraction_layer.h>
  28. #include <painter.h>
  29. #include <layers_id_colors_and_visibility.h>
  30. #include <page_info.h>
  31. #include <view/view.h>
  32. #include <ws_painter.h>
  33. using namespace KIGFX;
  34. WS_PROXY_VIEW_ITEM::WS_PROXY_VIEW_ITEM( int aMils2IUscalefactor, const PAGE_INFO* aPageInfo,
  35. const TITLE_BLOCK* aTitleBlock ) :
  36. EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
  37. m_mils2IUscalefactor( aMils2IUscalefactor ),
  38. m_titleBlock( aTitleBlock ),
  39. m_pageInfo( aPageInfo ),
  40. m_sheetNumber( 1 ),
  41. m_sheetCount( 1 )
  42. {
  43. }
  44. void WS_PROXY_VIEW_ITEM::SetPageInfo( const PAGE_INFO* aPageInfo )
  45. {
  46. m_pageInfo = aPageInfo;
  47. }
  48. void WS_PROXY_VIEW_ITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock )
  49. {
  50. m_titleBlock = aTitleBlock;
  51. }
  52. const BOX2I WS_PROXY_VIEW_ITEM::ViewBBox() const
  53. {
  54. BOX2I bbox;
  55. if( m_pageInfo != NULL )
  56. {
  57. bbox.SetOrigin( VECTOR2I( 0, 0 ) );
  58. bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor,
  59. m_pageInfo->GetHeightMils() * m_mils2IUscalefactor ) );
  60. }
  61. else
  62. {
  63. bbox.SetMaximum();
  64. }
  65. return bbox;
  66. }
  67. void WS_PROXY_VIEW_ITEM::ViewDraw( int aLayer, VIEW* aView ) const
  68. {
  69. auto gal = aView->GetGAL();
  70. auto settings = aView->GetPainter()->GetSettings();
  71. wxString fileName( m_fileName.c_str(), wxConvUTF8 );
  72. wxString sheetName( m_sheetName.c_str(), wxConvUTF8 );
  73. WS_DRAW_ITEM_LIST drawList;
  74. drawList.SetDefaultPenSize( (int) settings->GetWorksheetLineWidth() );
  75. // Adjust the scaling factor for worksheet items:
  76. // worksheet items coordinates and sizes are stored in mils,
  77. // and must be scaled to the same units as the caller
  78. drawList.SetMilsToIUfactor( m_mils2IUscalefactor );
  79. drawList.SetSheetNumber( m_sheetNumber );
  80. drawList.SetSheetCount( m_sheetCount );
  81. drawList.SetFileName( fileName );
  82. drawList.SetSheetName( sheetName );
  83. drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock );
  84. // Draw the title block normally even if the view is flipped
  85. bool flipped = gal->IsFlippedX();
  86. if( flipped )
  87. {
  88. gal->Save();
  89. gal->Translate( VECTOR2D( m_pageInfo->GetWidthMils() * m_mils2IUscalefactor, 0 ) );
  90. gal->Scale( VECTOR2D( -1.0, 1.0 ) );
  91. }
  92. WS_PAINTER ws_painter( gal );
  93. WS_RENDER_SETTINGS* ws_settings =static_cast<WS_RENDER_SETTINGS*>( ws_painter.GetSettings() );
  94. ws_settings->SetNormalColor( settings->GetLayerColor( LAYER_WORKSHEET ) );
  95. ws_settings->SetSelectedColor( settings->GetLayerColor( LAYER_SELECT_OVERLAY ) );
  96. ws_settings->SetBrightenedColor( settings->GetLayerColor( LAYER_BRIGHTENED ) );
  97. // Draw all the components that make the page layout
  98. for( WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); item; item = drawList.GetNext() )
  99. ws_painter.Draw( item, LAYER_WORKSHEET );
  100. // Draw gray line that outlines the sheet size
  101. if( settings->GetShowPageLimits() )
  102. ws_painter.DrawBorder( m_pageInfo, m_mils2IUscalefactor );
  103. if( flipped )
  104. gal->Restore();
  105. }
  106. void WS_PROXY_VIEW_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
  107. {
  108. aCount = 1;
  109. aLayers[0] = LAYER_WORKSHEET;
  110. }