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.

203 lines
5.7 KiB

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