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.

144 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  5. * Copyright (C) 2004-2011 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <macros.h>
  25. #include <general.h>
  26. #include <transform.h>
  27. #include <lib_collectors.h>
  28. const KICAD_T LIB_COLLECTOR::AllItems[] = {
  29. LIB_ARC_T,
  30. LIB_CIRCLE_T,
  31. LIB_TEXT_T,
  32. LIB_RECTANGLE_T,
  33. LIB_POLYLINE_T,
  34. LIB_BEZIER_T,
  35. LIB_PIN_T,
  36. LIB_FIELD_T,
  37. EOT
  38. };
  39. const KICAD_T LIB_COLLECTOR::AllItemsButPins[] = {
  40. LIB_ARC_T,
  41. LIB_CIRCLE_T,
  42. LIB_TEXT_T,
  43. LIB_RECTANGLE_T,
  44. LIB_POLYLINE_T,
  45. LIB_BEZIER_T,
  46. LIB_FIELD_T,
  47. EOT
  48. };
  49. const KICAD_T LIB_COLLECTOR::EditableItems[] = {
  50. LIB_ARC_T,
  51. LIB_CIRCLE_T,
  52. LIB_TEXT_T,
  53. LIB_RECTANGLE_T,
  54. LIB_POLYLINE_T,
  55. LIB_BEZIER_T,
  56. LIB_PIN_T,
  57. LIB_FIELD_T,
  58. EOT
  59. };
  60. const KICAD_T LIB_COLLECTOR::MovableItems[] = {
  61. LIB_ARC_T,
  62. LIB_CIRCLE_T,
  63. LIB_TEXT_T,
  64. LIB_RECTANGLE_T,
  65. LIB_POLYLINE_T,
  66. LIB_BEZIER_T,
  67. LIB_PIN_T,
  68. LIB_FIELD_T,
  69. EOT
  70. };
  71. const KICAD_T LIB_COLLECTOR::RotatableItems[] = {
  72. LIB_ARC_T,
  73. LIB_CIRCLE_T,
  74. LIB_TEXT_T,
  75. LIB_RECTANGLE_T,
  76. LIB_POLYLINE_T,
  77. LIB_BEZIER_T,
  78. LIB_PIN_T,
  79. LIB_FIELD_T,
  80. EOT
  81. };
  82. const KICAD_T LIB_COLLECTOR::DoubleClickItems[] = {
  83. LIB_PIN_T,
  84. LIB_ARC_T,
  85. LIB_CIRCLE_T,
  86. LIB_RECTANGLE_T,
  87. LIB_POLYLINE_T,
  88. LIB_TEXT_T,
  89. LIB_FIELD_T,
  90. LIB_BEZIER_T,
  91. EOT
  92. };
  93. SEARCH_RESULT LIB_COLLECTOR::Inspect( EDA_ITEM* aItem, void* testData )
  94. {
  95. LIB_ITEM* item = (LIB_ITEM*) aItem;
  96. // wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ),
  97. // GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() );
  98. if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) )
  99. || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) )
  100. || !item->HitTest( m_RefPos, -1, DefaultTransform ) )
  101. return SEARCH_CONTINUE;
  102. Append( aItem );
  103. return SEARCH_CONTINUE;
  104. }
  105. void LIB_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[],
  106. const wxPoint& aPosition, int aUnit, int aConvert )
  107. {
  108. Empty(); // empty the collection just in case
  109. SetScanTypes( aFilterList );
  110. // remember where the snapshot was taken from and pass refPos to the Inspect() function.
  111. SetRefPos( aPosition );
  112. m_data.m_unit = aUnit;
  113. m_data.m_convert = aConvert;
  114. for( LIB_ITEM& item : aItems )
  115. {
  116. if( SEARCH_QUIT == item.Visit( m_inspector, NULL, m_ScanTypes ) )
  117. break;
  118. }
  119. }