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.

133 lines
4.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2017 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 <pcb_group.h>
  31. #include <footprint.h>
  32. namespace KIGFX {
  33. PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
  34. VIEW( aIsDynamic )
  35. {
  36. // Set m_boundary to define the max area size. The default value is acceptable for Pcbnew
  37. // and Gerbview.
  38. // However, ensure this area has the right size (max size allowed by integer coordinates) in
  39. // case of the default value is changed. Could be a size depending on the drawing-sheet size.
  40. typedef std::numeric_limits<int> coord_limits;
  41. double pos = coord_limits::lowest() + coord_limits::epsilon();
  42. double size = static_cast<double>( coord_limits::max() - coord_limits::epsilon() )
  43. - static_cast<double>( coord_limits::min() + coord_limits::epsilon() );
  44. m_boundary.SetOrigin( pos, pos );
  45. m_boundary.SetSize( size, size );
  46. }
  47. PCB_VIEW::~PCB_VIEW()
  48. {
  49. }
  50. void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
  51. {
  52. BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
  53. if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
  54. {
  55. FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
  56. footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
  57. {
  58. VIEW::Add( aChild );
  59. } );
  60. }
  61. VIEW::Add( aItem, aDrawPriority );
  62. }
  63. void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem )
  64. {
  65. BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
  66. if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
  67. {
  68. FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
  69. footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
  70. {
  71. VIEW::Remove( aChild );
  72. } );
  73. }
  74. VIEW::Remove( aItem );
  75. }
  76. void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
  77. {
  78. const BOARD_ITEM* boardItem = dynamic_cast<const BOARD_ITEM*>( aItem );
  79. if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
  80. {
  81. const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( boardItem );
  82. footprint->RunOnChildren(
  83. [this, aUpdateFlags]( BOARD_ITEM* child )
  84. {
  85. VIEW::Update( child, aUpdateFlags );
  86. } );
  87. }
  88. else if( boardItem && boardItem->Type() == PCB_GROUP_T )
  89. {
  90. const PCB_GROUP* group = static_cast<const PCB_GROUP*>( boardItem );
  91. group->RunOnChildren(
  92. [this, aUpdateFlags]( BOARD_ITEM* child )
  93. {
  94. Update( child, aUpdateFlags );
  95. } );
  96. }
  97. VIEW::Update( aItem, aUpdateFlags );
  98. }
  99. void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
  100. {
  101. PCB_VIEW::Update( aItem, KIGFX::ALL );
  102. }
  103. void PCB_VIEW::UpdateDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
  104. {
  105. KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
  106. KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
  107. settings->LoadDisplayOptions( aOptions );
  108. }
  109. }