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.

132 lines
4.2 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() / 2 + coord_limits::epsilon();
  42. double size = coord_limits::max() - 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. BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
  52. if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
  53. {
  54. FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
  55. footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
  56. {
  57. VIEW::Add( aChild );
  58. } );
  59. }
  60. VIEW::Add( aItem, aDrawPriority );
  61. }
  62. void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem )
  63. {
  64. BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
  65. if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
  66. {
  67. FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
  68. footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
  69. {
  70. VIEW::Remove( aChild );
  71. } );
  72. }
  73. VIEW::Remove( aItem );
  74. }
  75. void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
  76. {
  77. const BOARD_ITEM* boardItem = dynamic_cast<const BOARD_ITEM*>( aItem );
  78. if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
  79. {
  80. const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( boardItem );
  81. footprint->RunOnChildren(
  82. [this, aUpdateFlags]( BOARD_ITEM* child )
  83. {
  84. VIEW::Update( child, aUpdateFlags );
  85. } );
  86. }
  87. else if( boardItem && boardItem->Type() == PCB_GROUP_T )
  88. {
  89. const PCB_GROUP* group = static_cast<const PCB_GROUP*>( boardItem );
  90. group->RunOnChildren(
  91. [this, aUpdateFlags]( BOARD_ITEM* child )
  92. {
  93. Update( child, aUpdateFlags );
  94. } );
  95. }
  96. VIEW::Update( aItem, aUpdateFlags );
  97. }
  98. void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
  99. {
  100. PCB_VIEW::Update( aItem, KIGFX::ALL );
  101. }
  102. void PCB_VIEW::UpdateDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
  103. {
  104. auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
  105. auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
  106. settings->LoadDisplayOptions( aOptions );
  107. }
  108. }