KiCad PCB EDA Suite
ee_selection.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) 2019 CERN
5  * Copyright (C) 2019-2021 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <tools/ee_selection.h>
26 #include <sch_item.h>
27 #include <sch_reference_list.h>
28 #include <sch_sheet_path.h>
29 #include <sch_symbol.h>
30 #include <sch_sheet.h>
31 
32 
34  SELECTION()
35 {
36  m_screen = aScreen;
37 }
38 
39 
40 EDA_ITEM* EE_SELECTION::GetTopLeftItem( bool onlyModules ) const
41 {
42  EDA_ITEM* topLeftItem = nullptr;
43  wxPoint topLeftPos;
44 
45  // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item
46  // in the selection
47  for( EDA_ITEM* item : m_items )
48  {
49  wxPoint pos = item->GetPosition();
50 
51  if( ( topLeftItem == nullptr )
52  || ( pos.x < topLeftPos.x )
53  || ( topLeftPos.x == pos.x && pos.y < topLeftPos.y ) )
54  {
55  topLeftItem = item;
56  topLeftPos = pos;
57  }
58  }
59 
60  return topLeftItem;
61 }
62 
63 
65 {
66  EDA_RECT bbox;
67 
68  for( EDA_ITEM* item : m_items )
69  {
70  if( item->Type() == SCH_SYMBOL_T )
71  {
72  // Quiet Coverity warning. The LIB_SYMBOL field container is a Boost ptr_vector
73  // so the exception is legit.
74  try
75  {
76  bbox.Merge( static_cast<SCH_SYMBOL*>( item )->GetBoundingBox( false ) );
77  }
78  catch( const boost::bad_pointer& exc )
79  {
80  wxFAIL_MSG( "Invalid pointer." );
81  }
82  }
83  else if( item->Type() == SCH_SHEET_T )
84  {
85  bbox.Merge( static_cast<SCH_SHEET*>( item )->GetBodyBoundingBox() );
86  }
87  else
88  {
89  bbox.Merge( item->GetBoundingBox() );
90  }
91  }
92 
93  return bbox;
94 }
95 
96 
98  const SCH_SHEET_PATH& aSelectionPath,
99  bool aIncludePowerSymbols,
100  bool aForceIncludeOrphanSymbols )
101 {
102  for( EDA_ITEM* item : Items() )
103  {
104  if( item->Type() != SCH_SYMBOL_T )
105  continue;
106 
107  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
108  aSelectionPath.AppendSymbol( aReferences, symbol, aIncludePowerSymbols,
109  aForceIncludeOrphanSymbols );
110  }
111 }
112 
113 
115  const SCH_SHEET_PATH& aSelectionPath,
116  bool aIncludePowerSymbols )
117 {
118  for( EDA_ITEM* item : Items() )
119  {
120  if( item->Type() != SCH_SYMBOL_T )
121  continue;
122 
123  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
124  aSelectionPath.AppendMultiUnitSymbol( aRefList, symbol, aIncludePowerSymbols );
125  }
126 }
127 
128 
130 {
131  for( const EDA_ITEM* item : m_items )
132  {
133  const SCH_ITEM* schItem = dynamic_cast<const SCH_ITEM*>( item );
134 
135  if( !schItem || !schItem->HasLineStroke() )
136  return false;
137  }
138 
139  return true;
140 }
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:432
std::deque< EDA_ITEM * > & Items()
Definition: selection.h:149
EDA_RECT GetBoundingBox() const override
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
EE_SELECTION(SCH_SCREEN *aScreen=nullptr)
SCH_SCREEN * m_screen
Screen of selected objects.
Definition: ee_selection.h:41
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
std::deque< EDA_ITEM * > m_items
Definition: selection.h:205
void AppendMultiUnitSymbol(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true) const
Append a SCH_REFERENCE_LIST object to aRefList based on aSymbol, storing same-reference set of multi-...
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:458
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, const SCH_SHEET_PATH &aSelectionPath, bool aIncludePowerSymbols=true)
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the se...
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
bool AllItemsHaveLineStroke() const
Checks if all items in the selection support line strokes.
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
Schematic symbol object.
Definition: sch_symbol.h:78
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSelectionPath, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false)
Adds SCH_REFERENCE object to aReferences for each symbol in the selection.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193