KiCad PCB EDA Suite
ee_collectors.cpp
Go to the documentation of this file.
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-2019 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 
26 #include <macros.h>
27 #include <trace_helpers.h>
28 
29 #include <sch_sheet_path.h>
30 #include <transform.h>
31 #include <ee_collectors.h>
32 #include <sch_component.h>
33 #include <sch_line.h>
34 #include <sch_bus_entry.h>
35 
36 
39  EOT
40 };
41 
42 
44  SCH_TEXT_T,
53  SCH_LINE_T,
54  EOT
55 };
56 
57 
60  EOT
61 };
62 
63 
66  EOT
67 };
68 
69 
70 SEARCH_RESULT EE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData )
71 {
72  if( aItem->Type() == LIB_PIN_T )
73  {
74  // Special selection rules apply to pins of different units when edited in
75  // synchronized pins mode. Leave it to EE_SELECTION_TOOL::isSelectable() to
76  // decide what to do with them.
77  }
78  else if( m_Unit || m_Convert )
79  {
80  LIB_ITEM* lib_item = dynamic_cast<LIB_ITEM*>( aItem );
81 
82  if( m_Unit && lib_item && lib_item->GetUnit() && lib_item->GetUnit() != m_Unit )
83  return SEARCH_CONTINUE;
84 
85  if( m_Convert && lib_item && lib_item->GetConvert() && lib_item->GetConvert() != m_Convert )
86  return SEARCH_CONTINUE;
87  }
88 
89  if( aItem->HitTest( m_RefPos, m_Threshold ) )
90  Append( aItem );
91 
92  return SEARCH_CONTINUE;
93 }
94 
95 
96 void EE_COLLECTOR::Collect( EDA_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPos,
97  int aUnit, int aConvert )
98 {
99  Empty(); // empty the collection just in case
100 
101  SetScanTypes( aFilterList );
102  m_Unit = aUnit;
103  m_Convert = aConvert;
104 
105  // remember where the snapshot was taken from and pass refPos to the Inspect() function.
106  SetRefPos( aPos );
107 
108  // aItem can be null for empty schematics
109  if( aItem && aItem->Type() == LIB_PART_T )
110  static_cast<LIB_PART*>( aItem )->Visit( m_inspector, nullptr, m_ScanTypes );
111  else
113 }
114 
115 
117 {
118  if( GetCount() != 2 )
119  return false;
120 
121  bool is_busentry0 = (dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_List[0] ) != NULL);
122  bool is_busentry1 = (dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_List[1] ) != NULL);
123 
124  if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_LINE_T) )
125  return ( ( SCH_LINE* ) m_List[0])->GetLayer() == ( ( SCH_LINE* ) m_List[1])->GetLayer();
126 
127  if( (m_List[0]->Type() == SCH_LINE_T) && is_busentry1 )
128  return true;
129 
130  if( is_busentry0 && (m_List[1]->Type() == SCH_LINE_T) )
131  return true;
132 
133  return false;
134 }
135 
136 
138 {
139  for( size_t i = 0; i < m_List.size(); i++ )
140  if( ( (SCH_ITEM*) m_List[ i ] )->Type() == SCH_JUNCTION_T )
141  return true;
142 
143  return false;
144 }
145 
146 
148 {
149  // The Vist() function only visits the testItem if its type was in the
150  // the scanList, so therefore we can collect anything given to us here.
151  Append( aItem );
152 
153  return SEARCH_CONTINUE;
154 }
155 
156 
157 void EE_TYPE_COLLECTOR::Collect( EDA_ITEM* aItem, const KICAD_T aFilterList[] )
158 {
159  Empty(); // empty the collection
160 
161  SetScanTypes( aFilterList );
162 
164 }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:122
void Collect(EDA_ITEM *aItem, const KICAD_T aScanList[])
Function Collect scans a DLIST using this class's Inspector method, which does the collection.
int m_Threshold
Definition: collector.h:68
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
Definition: collector.h:214
static const KICAD_T ComponentsOnly[]
Definition: ee_collectors.h:44
static const KICAD_T SheetsOnly[]
Definition: ee_collectors.h:45
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
SEARCH_RESULT Inspect(EDA_ITEM *testItem, void *testData) override
Function Inspect is the examining function within the INSPECTOR which is passed to the Iterate functi...
This file contains miscellaneous commonly used macros and functions.
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:132
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:340
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
int GetUnit() const
Definition: lib_item.h:301
INSPECTOR_FUNC m_inspector
Definition: collector.h:61
void SetRefPos(const wxPoint &aRefPos)
Definition: collector.h:229
void Collect(EDA_ITEM *aItem, const KICAD_T aFilterList[], const wxPoint &aPos, int aUnit=0, int aConvert=0)
Function Collect scans a EDA_ITEM using this class's Inspector method, which does the collection.
bool IsDraggableJunction() const
Function IsDraggableJunction tests to see if the collected items form a draggable junction.
static SEARCH_RESULT IterateForward(EDA_ITEM *listStart, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function IterateForward walks through the object tree calling the inspector() on each object type req...
Definition: base_struct.h:418
wxLogTrace helper definitions.
bool IsCorner() const
Function IsCorner tests if the collected items forms as corner of two line segments.
int GetConvert() const
Definition: lib_item.h:304
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
size_t i
Definition: json11.cpp:597
static const KICAD_T AllItems[]
Definition: ee_collectors.h:42
SEARCH_RESULT Inspect(EDA_ITEM *aItem, void *aTestData) override
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
wxPoint m_RefPos
Definition: collector.h:62
SEARCH_RESULT
Definition: base_struct.h:54
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< EDA_ITEM * > m_List
Definition: collector.h:58
const KICAD_T * m_ScanTypes
Definition: collector.h:60
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
static const KICAD_T EditableItems[]
Definition: ee_collectors.h:43
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210