KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
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
26#include <macros.h>
27#include <trace_helpers.h>
28#include <ee_collectors.h>
29#include <lib_item.h>
30#include <sch_bus_entry.h>
31#include <sch_symbol.h>
32#include <sch_line.h>
33#include <sch_screen.h>
34#include <sch_sheet_path.h>
35#include <transform.h>
36#include "sch_reference_list.h"
37
38
39const std::vector<KICAD_T> EE_COLLECTOR::EditableItems = {
56};
57
58
59const std::vector<KICAD_T> EE_COLLECTOR::MovableItems =
60{
72 SCH_TABLECELL_T, // will be promoted to parent table(s)
81};
82
83
84const std::vector<KICAD_T> EE_COLLECTOR::FieldOwners = {
88};
89
90
92{
93 if( m_Unit || m_BodyStyle )
94 {
95 LIB_ITEM* lib_item = dynamic_cast<LIB_ITEM*>( aItem );
96
97 // Special selection rules apply to pins of different units when edited in synchronized
98 // pins mode. Leave it to EE_SELECTION_TOOL::Selectable() to decide what to do with them.
99
100 if( lib_item && lib_item->Type() != LIB_PIN_T )
101 {
102 if( m_Unit && lib_item->GetUnit() && lib_item->GetUnit() != m_Unit )
103 return INSPECT_RESULT::CONTINUE;
104
105 if( m_BodyStyle && lib_item->GetBodyStyle() && lib_item->GetBodyStyle() != m_BodyStyle )
106 return INSPECT_RESULT::CONTINUE;
107 }
108 }
109
111 aItem->SetFlags( SHOW_ELEC_TYPE );
112
113 if( aItem->HitTest( m_refPos, m_Threshold ) )
114 Append( aItem );
115
116 aItem->ClearFlags( SHOW_ELEC_TYPE );
117
118 return INSPECT_RESULT::CONTINUE;
119}
120
121
122void EE_COLLECTOR::Collect( SCH_SCREEN* aScreen, const std::vector<KICAD_T>& aFilterList,
123 const VECTOR2I& aPos, int aUnit, int aConvert )
124{
125 Empty(); // empty the collection just in case
126
127 SetScanTypes( aFilterList );
128 m_Unit = aUnit;
129 m_BodyStyle = aConvert;
130
131 // remember where the snapshot was taken from and pass refPos to the Inspect() function.
132 SetRefPos( aPos );
133
134 if( aScreen )
135 {
136 for( SCH_ITEM *item : aScreen->Items().Overlapping( SCH_LOCATE_ANY_T, aPos, m_Threshold ) )
137 item->Visit( m_inspector, nullptr, m_scanTypes );
138 }
139}
140
141
142void EE_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const std::vector<KICAD_T>& aFilterList,
143 const VECTOR2I& aPos, int aUnit, int aConvert )
144{
145 Empty(); // empty the collection just in case
146
147 SetScanTypes( aFilterList );
148 m_Unit = aUnit;
149 m_BodyStyle = aConvert;
150
151 // remember where the snapshot was taken from and pass refPos to the Inspect() function.
152 SetRefPos( aPos );
153
154 for( LIB_ITEM& item : aItems )
155 {
156 if( item.Visit( m_inspector, nullptr, m_scanTypes ) == INSPECT_RESULT::QUIT )
157 break;
158 }
159}
160
161
163{
164 if( GetCount() != 2 )
165 return false;
166
167 bool is_busentry0 = ( dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_list[0] ) != nullptr );
168 bool is_busentry1 = ( dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_list[1] ) != nullptr );
169
170 if(( m_list[0]->Type() == SCH_LINE_T) && ( m_list[1]->Type() == SCH_LINE_T) )
171 return ( ( SCH_LINE* ) m_list[0])->GetLayer() == ( ( SCH_LINE* ) m_list[1])->GetLayer();
172
173 if(( m_list[0]->Type() == SCH_LINE_T) && is_busentry1 )
174 return true;
175
176 if( is_busentry0 && ( m_list[1]->Type() == SCH_LINE_T) )
177 return true;
178
179 return false;
180}
181
182
183void CollectOtherUnits( const wxString& aRef, int aUnit, const LIB_ID& aLibId,
184 SCH_SHEET_PATH& aSheet, std::vector<SCH_SYMBOL*>* otherUnits )
185{
186 SCH_REFERENCE_LIST symbols;
187 aSheet.GetSymbols( symbols );
188
189 for( unsigned i = 0; i < symbols.GetCount(); i++ )
190 {
191 SCH_REFERENCE symbol = symbols[i];
192
193 if( symbol.GetRef() == aRef
194 && symbol.GetSymbol()->GetLibId() == aLibId
195 && symbol.GetUnit() != aUnit )
196 {
197 otherUnits->push_back( symbol.GetSymbol() );
198 }
199 }
200}
201
202
INSPECTOR_FUNC m_inspector
Definition: collector.h:244
void Empty()
Clear the list.
Definition: collector.h:89
VECTOR2I m_refPos
Definition: collector.h:246
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
void SetScanTypes(const std::vector< KICAD_T > &aTypes)
Record the list of KICAD_T types to consider for collection by the Inspect() function.
Definition: collector.h:211
void SetRefPos(const VECTOR2I &aRefPos)
Definition: collector.h:213
std::vector< KICAD_T > m_scanTypes
Definition: collector.h:243
std::vector< EDA_ITEM * > m_list
Definition: collector.h:240
int m_Threshold
Definition: collector.h:234
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition: collector.h:99
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:123
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:125
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:212
bool m_ShowPinElectricalTypes
static const std::vector< KICAD_T > MovableItems
Definition: ee_collectors.h:43
bool IsCorner() const
Test if the collected items form a corner of two line segments.
INSPECT_RESULT Inspect(EDA_ITEM *aItem, void *aTestData) override
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
static const std::vector< KICAD_T > EditableItems
Definition: ee_collectors.h:42
static const std::vector< KICAD_T > FieldOwners
Definition: ee_collectors.h:44
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition: sch_rtree.h:243
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
int GetBodyStyle() const
Definition: lib_item.h:346
int GetUnit() const
Definition: lib_item.h:343
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:165
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
A helper to define a symbol's reference designator in a schematic.
SCH_SYMBOL * GetSymbol() const
wxString GetRef() const
int GetUnit() const
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:203
INSPECT_RESULT
Definition: eda_item.h:42
#define SHOW_ELEC_TYPE
Show pin electrical type. Shared with IS_ROLLOVER.
void CollectOtherUnits(const wxString &aRef, int aUnit, const LIB_ID &aLibId, SCH_SHEET_PATH &aSheet, std::vector< SCH_SYMBOL * > *otherUnits)
This file contains miscellaneous commonly used macros and functions.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
wxLogTrace helper definitions.
@ SCH_TABLE_T
Definition: typeinfo.h:153
@ SCH_LINE_T
Definition: typeinfo.h:148
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:145
@ SCH_SYMBOL_T
Definition: typeinfo.h:160
@ SCH_TABLECELL_T
Definition: typeinfo.h:154
@ SCH_FIELD_T
Definition: typeinfo.h:159
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:158
@ SCH_LABEL_T
Definition: typeinfo.h:155
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:187
@ SCH_SHEET_T
Definition: typeinfo.h:162
@ SCH_MARKER_T
Definition: typeinfo.h:143
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:157
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:147
@ LIB_PIN_T
Definition: typeinfo.h:206
@ SCH_LABEL_LOCATE_ANY_T
Definition: typeinfo.h:179
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:161
@ SCH_TEXT_T
Definition: typeinfo.h:152
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:146
@ SCH_BITMAP_T
Definition: typeinfo.h:150
@ SCH_TEXTBOX_T
Definition: typeinfo.h:151
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:156
@ SCH_JUNCTION_T
Definition: typeinfo.h:144