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.

120 lines
3.5 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 <class_module.h>
  31. namespace KIGFX {
  32. PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
  33. VIEW( aIsDynamic )
  34. {
  35. // Set m_boundary to define the max area size. The default value
  36. // is acceptable for Pcbnew and Gerbview.
  37. // However, ensure this area has the right size (max size allowed by integer coordinates)
  38. // in case of the default value is changed.
  39. // Could be a size depending on the worksheet 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. auto item = static_cast<BOARD_ITEM*>( aItem );
  52. if( item->Type() == PCB_MODULE_T )
  53. {
  54. auto mod = static_cast<MODULE*>( item );
  55. mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) {
  56. VIEW::Add( aModItem );
  57. } );
  58. }
  59. VIEW::Add( item, aDrawPriority );
  60. }
  61. void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem )
  62. {
  63. auto item = static_cast<BOARD_ITEM*>( aItem );
  64. if( item->Type() == PCB_MODULE_T )
  65. {
  66. auto mod = static_cast<MODULE*>( item );
  67. mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) {
  68. VIEW::Remove( aModItem );
  69. } );
  70. }
  71. VIEW::Remove( item );
  72. }
  73. void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem, int aUpdateFlags )
  74. {
  75. auto item = static_cast<BOARD_ITEM*>( aItem );
  76. if( item->Type() == PCB_MODULE_T )
  77. {
  78. auto mod = static_cast<MODULE*>( item );
  79. mod->RunOnChildren([this, aUpdateFlags] ( BOARD_ITEM* aModItem ) {
  80. VIEW::Update( aModItem, aUpdateFlags );
  81. } );
  82. }
  83. VIEW::Update( item, aUpdateFlags );
  84. }
  85. void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem )
  86. {
  87. PCB_VIEW::Update( aItem, KIGFX::ALL );
  88. }
  89. void PCB_VIEW::UpdateDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
  90. {
  91. auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
  92. auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
  93. settings->LoadDisplayOptions( aOptions, settings->GetShowPageLimits() );
  94. }
  95. }