KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <macros.h>
23#include <trace_helpers.h>
24#include <sch_collectors.h>
25#include <sch_bus_entry.h>
26#include <sch_symbol.h>
27#include <sch_line.h>
28#include <sch_screen.h>
29#include <sch_sheet_path.h>
30#include <transform.h>
31#include "sch_reference_list.h"
32
33
34const std::vector<KICAD_T> SCH_COLLECTOR::EditableItems = {
53};
54
55
56const std::vector<KICAD_T> SCH_COLLECTOR::MovableItems =
57{
69 SCH_TABLECELL_T, // will be promoted to parent table(s)
80};
81
82
83const std::vector<KICAD_T> SCH_COLLECTOR::FieldOwners =
84{
88};
89
90
91const std::vector<KICAD_T> SCH_COLLECTOR::DeletableItems =
92{
103 SCH_TABLECELL_T, // Clear contents
113 SCH_FIELD_T, // Will be hidden
116};
117
118
120{
121 if( m_Unit || m_BodyStyle )
122 {
123 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem );
124
125 // Special selection rules apply to pins of different units when edited in synchronized
126 // pins mode. Leave it to SCH_SELECTION_TOOL::Selectable() to decide what to do with them.
127
128 if( schItem && schItem->Type() != SCH_PIN_T )
129 {
130 if( m_Unit != ALL_UNITS
131 && schItem->GetUnit() != ALL_UNITS
132 && schItem->GetUnit() != m_Unit )
133 {
135 }
136
138 && schItem->GetBodyStyle() != ALL_BODY_STYLES
139 && schItem->GetBodyStyle() != m_BodyStyle )
140 {
142 }
143 }
144 }
145
147 aItem->SetFlags( SHOW_ELEC_TYPE );
148
149 if( aItem->HitTest( m_refPos, m_Threshold ) )
150 Append( aItem );
151
152 aItem->ClearFlags( SHOW_ELEC_TYPE );
153
155}
156
157
158void SCH_COLLECTOR::Collect( SCH_SCREEN* aScreen, const std::vector<KICAD_T>& aFilterList,
159 const VECTOR2I& aPos, int aUnit, int aBodyStyle )
160{
161 Empty(); // empty the collection just in case
162
163 SetScanTypes( aFilterList );
164 m_Unit = aUnit;
165 m_BodyStyle = aBodyStyle;
166
167 // remember where the snapshot was taken from and pass refPos to the Inspect() function.
168 SetRefPos( aPos );
169
170 if( aScreen )
171 {
172 for( SCH_ITEM *item : aScreen->Items().Overlapping( SCH_LOCATE_ANY_T, aPos, m_Threshold ) )
173 item->Visit( m_inspector, nullptr, m_scanTypes );
174 }
175}
176
177
178void SCH_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const std::vector<KICAD_T>& aFilterList,
179 const VECTOR2I& aPos, int aUnit, int aBodyStyle )
180{
181 Empty(); // empty the collection just in case
182
183 SetScanTypes( aFilterList );
184 m_Unit = aUnit;
185 m_BodyStyle = aBodyStyle;
186
187 // remember where the snapshot was taken from and pass refPos to the Inspect() function.
188 SetRefPos( aPos );
189
190 for( SCH_ITEM& item : aItems )
191 {
192 if( item.Visit( m_inspector, nullptr, m_scanTypes ) == INSPECT_RESULT::QUIT )
193 break;
194 }
195}
196
197
199{
200 if( GetCount() != 2 )
201 return false;
202
203 bool is_busentry0 = ( dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_list[0] ) != nullptr );
204 bool is_busentry1 = ( dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_list[1] ) != nullptr );
205
206 if(( m_list[0]->Type() == SCH_LINE_T) && ( m_list[1]->Type() == SCH_LINE_T) )
207 return ( ( SCH_LINE* ) m_list[0])->GetLayer() == ( ( SCH_LINE* ) m_list[1])->GetLayer();
208
209 if(( m_list[0]->Type() == SCH_LINE_T) && is_busentry1 )
210 return true;
211
212 if( is_busentry0 && ( m_list[1]->Type() == SCH_LINE_T) )
213 return true;
214
215 return false;
216}
217
218
219void CollectOtherUnits( const wxString& aRef, int aUnit, const LIB_ID& aLibId, SCH_SHEET_PATH& aSheet,
220 std::vector<SCH_SYMBOL*>* otherUnits )
221{
222 SCH_REFERENCE_LIST symbols;
223 aSheet.GetSymbols( symbols, SYMBOL_FILTER_NON_POWER );
224
225 for( int i = 0; i < (int) symbols.GetCount(); i++ )
226 {
227 const SCH_REFERENCE& symbol = symbols[i];
228
229 if( symbol.GetRef() == aRef
230 && symbol.GetSymbol()->GetLibId() == aLibId
231 && symbol.GetUnit() != aUnit )
232 {
233 otherUnits->push_back( symbol.GetSymbol() );
234 }
235 }
236}
237
INSPECTOR_FUNC m_inspector
Definition collector.h:244
void Empty()
Clear the list.
Definition collector.h:87
VECTOR2I m_refPos
Definition collector.h:246
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
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:209
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:97
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
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:309
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition sch_rtree.h:253
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Base class for a bus or wire entry.
static const std::vector< KICAD_T > FieldOwners
static const std::vector< KICAD_T > EditableItems
INSPECT_RESULT Inspect(EDA_ITEM *aItem, void *aTestData) override
bool IsCorner() const
Test if the collected items form a corner of two line segments.
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aBodyStyle=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
static const std::vector< KICAD_T > DeletableItems
bool m_ShowPinElectricalTypes
static const std::vector< KICAD_T > MovableItems
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
int GetBodyStyle() const
Definition sch_item.h:253
int GetUnit() const
Definition sch_item.h:243
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
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()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
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, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:163
INSPECT_RESULT
Definition eda_item.h:44
#define SHOW_ELEC_TYPE
Show pin electrical type.
MULTIVECTOR< SCH_ITEM, SCH_SHAPE_T, SCH_PIN_T > LIB_ITEMS_CONTAINER
Definition lib_symbol.h:59
This file contains miscellaneous commonly used macros and functions.
void CollectOtherUnits(const wxString &aRef, int aUnit, const LIB_ID &aLibId, SCH_SHEET_PATH &aSheet, std::vector< SCH_SYMBOL * > *otherUnits)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
#define ALL_UNITS
Definition symbol.h:150
#define ALL_BODY_STYLES
Definition symbol.h:151
wxLogTrace helper definitions.
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_TABLE_T
Definition typeinfo.h:161
@ SCH_LINE_T
Definition typeinfo.h:159
@ LIB_SYMBOL_T
Definition typeinfo.h:144
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:167
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:195
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_MARKER_T
Definition typeinfo.h:154
@ SCH_SHAPE_T
Definition typeinfo.h:145
@ SCH_RULE_AREA_T
Definition typeinfo.h:166
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:158
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:187
@ SCH_SHEET_PIN_T
Definition typeinfo.h:170
@ SCH_TEXT_T
Definition typeinfo.h:147
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:157
@ SCH_BITMAP_T
Definition typeinfo.h:160
@ SCH_TEXTBOX_T
Definition typeinfo.h:148
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
@ SCH_JUNCTION_T
Definition typeinfo.h:155
@ SCH_PIN_T
Definition typeinfo.h:149
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708