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.

199 lines
5.6 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@gmail.com>
  5. * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. * Copyright (C) 2019 CERN
  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 <macros.h>
  26. #include <trace_helpers.h>
  27. #include <ee_collectors.h>
  28. #include <lib_item.h>
  29. #include <sch_bus_entry.h>
  30. #include <sch_symbol.h>
  31. #include <sch_line.h>
  32. #include <sch_screen.h>
  33. #include <sch_sheet_path.h>
  34. #include <transform.h>
  35. #include "sch_reference_list.h"
  36. const std::vector<KICAD_T> EE_COLLECTOR::EditableItems = {
  37. SCH_SHAPE_T,
  38. SCH_TEXT_T,
  39. SCH_TEXTBOX_T,
  40. SCH_LABEL_T,
  41. SCH_GLOBAL_LABEL_T,
  42. SCH_HIER_LABEL_T,
  43. SCH_DIRECTIVE_LABEL_T,
  44. SCH_FIELD_T,
  45. SCH_SYMBOL_T,
  46. SCH_SHEET_PIN_T,
  47. SCH_SHEET_T,
  48. SCH_BITMAP_T,
  49. SCH_LINE_T,
  50. SCH_BUS_WIRE_ENTRY_T,
  51. SCH_JUNCTION_T
  52. };
  53. const std::vector<KICAD_T> EE_COLLECTOR::MovableItems =
  54. {
  55. SCH_MARKER_T,
  56. SCH_JUNCTION_T,
  57. SCH_NO_CONNECT_T,
  58. SCH_BUS_BUS_ENTRY_T,
  59. SCH_BUS_WIRE_ENTRY_T,
  60. SCH_LINE_T,
  61. SCH_BITMAP_T,
  62. SCH_SHAPE_T,
  63. SCH_TEXT_T,
  64. SCH_TEXTBOX_T,
  65. SCH_LABEL_T,
  66. SCH_GLOBAL_LABEL_T,
  67. SCH_HIER_LABEL_T,
  68. SCH_DIRECTIVE_LABEL_T,
  69. SCH_FIELD_T,
  70. SCH_SYMBOL_T,
  71. SCH_SHEET_PIN_T,
  72. SCH_SHEET_T
  73. };
  74. const std::vector<KICAD_T> EE_COLLECTOR::FieldOwners = {
  75. SCH_SYMBOL_T,
  76. SCH_SHEET_T,
  77. SCH_LABEL_LOCATE_ANY_T
  78. };
  79. INSPECT_RESULT EE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData )
  80. {
  81. if( m_Unit || m_Convert )
  82. {
  83. LIB_ITEM* lib_item = dynamic_cast<LIB_ITEM*>( aItem );
  84. // Special selection rules apply to pins of different units when edited in synchronized
  85. // pins mode. Leave it to EE_SELECTION_TOOL::Selectable() to decide what to do with them.
  86. if( lib_item && lib_item->Type() != LIB_PIN_T )
  87. {
  88. if( m_Unit && lib_item->GetUnit() && lib_item->GetUnit() != m_Unit )
  89. return INSPECT_RESULT::CONTINUE;
  90. if( m_Convert && lib_item->GetConvert() && lib_item->GetConvert() != m_Convert )
  91. return INSPECT_RESULT::CONTINUE;
  92. }
  93. }
  94. if( m_ShowPinElectricalTypes )
  95. aItem->SetFlags( SHOW_ELEC_TYPE );
  96. if( aItem->HitTest( m_refPos, m_Threshold ) )
  97. Append( aItem );
  98. aItem->ClearFlags( SHOW_ELEC_TYPE );
  99. return INSPECT_RESULT::CONTINUE;
  100. }
  101. void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen, const std::vector<KICAD_T>& aFilterList,
  102. const VECTOR2I& aPos, int aUnit, int aConvert )
  103. {
  104. Empty(); // empty the collection just in case
  105. SetScanTypes( aFilterList );
  106. m_Unit = aUnit;
  107. m_Convert = aConvert;
  108. // remember where the snapshot was taken from and pass refPos to the Inspect() function.
  109. SetRefPos( aPos );
  110. if( aScreen )
  111. {
  112. for( SCH_ITEM *item : aScreen->Items().Overlapping( SCH_LOCATE_ANY_T, aPos, m_Threshold ) )
  113. item->Visit( m_inspector, nullptr, m_scanTypes );
  114. }
  115. }
  116. void EE_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const std::vector<KICAD_T>& aFilterList,
  117. const VECTOR2I& aPos, int aUnit, int aConvert )
  118. {
  119. Empty(); // empty the collection just in case
  120. SetScanTypes( aFilterList );
  121. m_Unit = aUnit;
  122. m_Convert = aConvert;
  123. // remember where the snapshot was taken from and pass refPos to the Inspect() function.
  124. SetRefPos( aPos );
  125. for( LIB_ITEM& item : aItems )
  126. {
  127. if( item.Visit( m_inspector, nullptr, m_scanTypes ) == INSPECT_RESULT::QUIT )
  128. break;
  129. }
  130. }
  131. bool EE_COLLECTOR::IsCorner() const
  132. {
  133. if( GetCount() != 2 )
  134. return false;
  135. bool is_busentry0 = ( dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_list[0] ) != nullptr );
  136. bool is_busentry1 = ( dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_list[1] ) != nullptr );
  137. if(( m_list[0]->Type() == SCH_LINE_T) && ( m_list[1]->Type() == SCH_LINE_T) )
  138. return ( ( SCH_LINE* ) m_list[0])->GetLayer() == ( ( SCH_LINE* ) m_list[1])->GetLayer();
  139. if(( m_list[0]->Type() == SCH_LINE_T) && is_busentry1 )
  140. return true;
  141. if( is_busentry0 && ( m_list[1]->Type() == SCH_LINE_T) )
  142. return true;
  143. return false;
  144. }
  145. void CollectOtherUnits( const wxString& aRef, int aUnit, const LIB_ID& aLibId,
  146. SCH_SHEET_PATH& aSheet, std::vector<SCH_SYMBOL*>* otherUnits )
  147. {
  148. SCH_REFERENCE_LIST symbols;
  149. aSheet.GetSymbols( symbols );
  150. for( unsigned i = 0; i < symbols.GetCount(); i++ )
  151. {
  152. SCH_REFERENCE symbol = symbols[i];
  153. if( symbol.GetRef() == aRef
  154. && symbol.GetSymbol()->GetLibId() == aLibId
  155. && symbol.GetUnit() != aUnit )
  156. {
  157. otherUnits->push_back( symbol.GetSymbol() );
  158. }
  159. }
  160. }