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.

128 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2023 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  6. * @author Maciej Suminski <maciej.suminski@cern.ch>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <functional>
  26. using namespace std::placeholders;
  27. #include <pcb_view.h>
  28. #include <pcb_display_options.h>
  29. #include <pcb_painter.h>
  30. #include <footprint.h>
  31. namespace KIGFX {
  32. PCB_VIEW::PCB_VIEW() :
  33. VIEW()
  34. {
  35. // Set m_boundary to define the max area size. The default value is acceptable for Pcbnew
  36. // and Gerbview.
  37. // However, ensure this area has the right size (max size allowed by integer coordinates) in
  38. // case of the default value is changed. Could be a size depending on the drawing-sheet size.
  39. typedef std::numeric_limits<int> coord_limits;
  40. double pos = coord_limits::lowest() + coord_limits::epsilon();
  41. double size = static_cast<double>( coord_limits::max() - coord_limits::epsilon() )
  42. - static_cast<double>( coord_limits::min() + coord_limits::epsilon() );
  43. m_boundary.SetOrigin( pos, pos );
  44. m_boundary.SetSize( size, size );
  45. }
  46. PCB_VIEW::~PCB_VIEW()
  47. {
  48. }
  49. void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
  50. {
  51. if( aItem->IsBOARD_ITEM() )
  52. {
  53. BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
  54. if( boardItem->Type() == PCB_FOOTPRINT_T )
  55. {
  56. static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Add, this,
  57. _1, aDrawPriority ) );
  58. }
  59. }
  60. VIEW::Add( aItem, aDrawPriority );
  61. }
  62. void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem )
  63. {
  64. if( aItem->IsBOARD_ITEM() )
  65. {
  66. BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
  67. if( boardItem->Type() == PCB_FOOTPRINT_T )
  68. {
  69. static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Remove,
  70. this, _1 ) );
  71. }
  72. }
  73. VIEW::Remove( aItem );
  74. }
  75. void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
  76. {
  77. if( aItem->IsBOARD_ITEM() )
  78. {
  79. const BOARD_ITEM* boardItem = static_cast<const BOARD_ITEM*>( aItem );
  80. if( boardItem->Type() == PCB_TABLECELL_T )
  81. {
  82. VIEW::Update( boardItem->GetParent() );
  83. }
  84. else
  85. {
  86. boardItem->RunOnChildren(
  87. [this, aUpdateFlags]( BOARD_ITEM* child )
  88. {
  89. VIEW::Update( child, aUpdateFlags );
  90. } );
  91. }
  92. }
  93. VIEW::Update( aItem, aUpdateFlags );
  94. }
  95. void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
  96. {
  97. PCB_VIEW::Update( aItem, KIGFX::ALL );
  98. }
  99. void PCB_VIEW::UpdateDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
  100. {
  101. KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
  102. KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
  103. settings->LoadDisplayOptions( aOptions );
  104. }
  105. }