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
3.8 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. * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <functional>
  27. using namespace std::placeholders;
  28. #include <board.h>
  29. #include <board_item.h>
  30. #include <footprint.h>
  31. #include <pcb_edit_frame.h>
  32. #include <pcb_group.h>
  33. #include <class_draw_panel_gal.h>
  34. #include <view/view_controls.h>
  35. #include <view/view_group.h>
  36. #include <gal/painter.h>
  37. #include <bitmaps.h>
  38. #include <tool/tool_event.h>
  39. #include <tool/tool_manager.h>
  40. #include <tools/pcb_selection.h>
  41. #include <connectivity/connectivity_data.h>
  42. #include "pcb_selection_tool.h"
  43. #include "pcb_actions.h"
  44. #include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
  45. EDA_ITEM* PCB_SELECTION::GetTopLeftItem( bool aFootprintsOnly ) const
  46. {
  47. EDA_ITEM* topLeftItem = nullptr;
  48. VECTOR2I pnt;
  49. // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
  50. for( EDA_ITEM* item : m_items )
  51. {
  52. pnt = item->GetPosition();
  53. if( ( item->Type() != PCB_FOOTPRINT_T ) && aFootprintsOnly )
  54. {
  55. continue;
  56. }
  57. else
  58. {
  59. if( topLeftItem == nullptr )
  60. {
  61. topLeftItem = item;
  62. }
  63. else if( ( pnt.x < topLeftItem->GetPosition().x ) ||
  64. ( ( topLeftItem->GetPosition().x == pnt.x ) &&
  65. ( pnt.y < topLeftItem->GetPosition().y ) ) )
  66. {
  67. topLeftItem = item;
  68. }
  69. }
  70. }
  71. return topLeftItem;
  72. }
  73. const std::vector<KIGFX::VIEW_ITEM*> PCB_SELECTION::updateDrawList() const
  74. {
  75. std::vector<VIEW_ITEM*> items;
  76. std::function<void ( EDA_ITEM* )> addItem =
  77. [&]( EDA_ITEM* item )
  78. {
  79. items.push_back( item );
  80. if( item->IsBOARD_ITEM() )
  81. {
  82. BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
  83. boardItem->RunOnChildren( [&]( BOARD_ITEM* childItem )
  84. {
  85. addItem( childItem );
  86. },
  87. RECURSE_MODE::NO_RECURSE );
  88. }
  89. };
  90. for( EDA_ITEM* item : m_items )
  91. addItem( item );
  92. return items;
  93. }
  94. BOX2I PCB_SELECTION::GetBoundingBox() const
  95. {
  96. BOX2I bbox;
  97. for( EDA_ITEM* item : m_items )
  98. {
  99. if( item->Type() == PCB_FOOTPRINT_T )
  100. {
  101. FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
  102. bbox.Merge( footprint->GetBoundingBox( true ) );
  103. }
  104. else
  105. {
  106. bbox.Merge( item->GetBoundingBox() );
  107. }
  108. }
  109. return bbox;
  110. }