KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_group.h
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) 2020 Joshua Redstone redstone at gmail.com
5 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.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
30#ifndef CLASS_PCB_GROUP_H_
31#define CLASS_PCB_GROUP_H_
32
33#include <board_commit.h>
34#include <board_item.h>
35#include <lset.h>
36#include <unordered_set>
37
38namespace KIGFX
39{
40class VIEW;
41}
42
51class PCB_GROUP : public BOARD_ITEM
52{
53public:
54 PCB_GROUP( BOARD_ITEM* aParent );
55
56 static inline bool ClassOf( const EDA_ITEM* aItem )
57 {
58 return aItem && PCB_GROUP_T == aItem->Type();
59 }
60
61 wxString GetClass() const override
62 {
63 return wxT( "PCB_GROUP" );
64 }
65
66 wxString GetName() const { return m_name; }
67 void SetName( const wxString& aName ) { m_name = aName; }
68
69 std::unordered_set<BOARD_ITEM*>& GetItems()
70 {
71 return m_items;
72 }
73
74 const std::unordered_set<BOARD_ITEM*>& GetItems() const
75 {
76 return m_items;
77 }
78
84 virtual bool AddItem( BOARD_ITEM* aItem );
85
91 virtual bool RemoveItem( BOARD_ITEM* aItem );
92
93 void RemoveAll();
94
95 /*
96 * Search for highest level group inside of aScope, containing item.
97 *
98 * @param aScope restricts the search to groups within the group scope.
99 * @param isFootprintEditor true if we should stop promoting at the footprint level
100 * @return group inside of aScope, containing item, if exists, otherwise, nullptr
101 */
102 static PCB_GROUP* TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
103
104 static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
105
106 double Similarity( const BOARD_ITEM& aOther ) const override;
107
108 bool operator==( const PCB_GROUP& aOther ) const;
109 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
110
111#if defined( DEBUG )
112 void Show( int nestLevel, std::ostream& os ) const override
113 {
114 ShowDummy( os );
115 }
116#endif
117
119 VECTOR2I GetPosition() const override;
120
122 void SetPosition( const VECTOR2I& aNewpos ) override;
123
125 LSET GetLayerSet() const override;
126
128 void SetLayer( PCB_LAYER_ID aLayer ) override
129 {
130 // NOP
131 }
132
133 bool IsOnCopperLayer() const override
134 {
135 // A group might have members on a copper layer, but isn't itself on any layer.
136 return false;
137 }
138
139 void SetLocked( bool aLocked ) override;
140
142 EDA_ITEM* Clone() const override;
143
144 /*
145 * Clone() this and all descendants
146 */
147 PCB_GROUP* DeepClone() const;
148
149 /*
150 * Duplicate() this and all descendants
151 */
152 PCB_GROUP* DeepDuplicate() const;
153
155 bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
156
158 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
159
161 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
162
164 const BOX2I GetBoundingBox() const override;
165
166 // @copydoc BOARD_ITEM::GetEffectiveShape
167 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
168 FLASHING aFlash = FLASHING::DEFAULT ) const override;
169
171 INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
172 const std::vector<KICAD_T>& aScanTypes ) override;
173
175 void ViewGetLayers( int aLayers[], int& aCount ) const override;
176
178 double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
179
181 void Move( const VECTOR2I& aMoveVector ) override;
182
184 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
185
187 void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
188
190 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
191
193 BITMAPS GetMenuImage() const override;
194
196 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
197
199 void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const override;
200
202 void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction,
203 int aDepth = 0 ) const override;
204
210 static bool IsGroupableType( KICAD_T aType );
211
212protected:
213 PCB_GROUP( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu );
214
216 void swapData( BOARD_ITEM* aImage ) override;
217
218 std::unordered_set<BOARD_ITEM*> m_items; // Members of the group
219 wxString m_name; // Optional group name
220};
221
222#endif // CLASS_PCB_GROUP_H_
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_group.cpp:260
std::unordered_set< BOARD_ITEM * > m_items
Definition: pcb_group.h:218
static bool WithinScope(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:156
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_group.cpp:366
PCB_GROUP * DeepClone() const
Definition: pcb_group.cpp:203
static PCB_GROUP * TopLevelGroup(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:150
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_group.h:128
void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction, int aDepth=0) const override
Invoke a function on all descendants.
Definition: pcb_group.cpp:405
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:69
static bool IsGroupableType(KICAD_T aType)
Check if the proposed type can be added to a group.
Definition: pcb_group.cpp:49
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_group.cpp:352
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Definition: pcb_group.cpp:336
bool IsOnCopperLayer() const override
Definition: pcb_group.h:133
void RemoveAll()
Definition: pcb_group.cpp:108
bool operator==(const PCB_GROUP &aOther) const
Definition: pcb_group.cpp:440
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition: pcb_group.cpp:316
PCB_GROUP * DeepDuplicate() const
Definition: pcb_group.cpp:221
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_group.h:56
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_group.cpp:305
void SetName(const wxString &aName)
Definition: pcb_group.h:67
void SetPosition(const VECTOR2I &aNewpos) override
Definition: pcb_group.cpp:175
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_group.cpp:345
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_group.cpp:462
wxString GetClass() const override
Return the class name.
Definition: pcb_group.h:61
INSPECT_RESULT Visit(INSPECTOR aInspector, void *aTestData, const std::vector< KICAD_T > &aScanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: pcb_group.cpp:289
virtual bool RemoveItem(BOARD_ITEM *aItem)
Remove item from group.
Definition: pcb_group.cpp:95
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pcb_group.cpp:278
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_group.cpp:359
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: pcb_group.cpp:381
VECTOR2I GetPosition() const override
Definition: pcb_group.cpp:169
virtual bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:80
void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: pcb_group.cpp:329
const std::unordered_set< BOARD_ITEM * > & GetItems() const
Definition: pcb_group.h:74
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const override
Invoke a function on all descendants.
Definition: pcb_group.cpp:391
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: pcb_group.cpp:246
wxString GetName() const
Definition: pcb_group.h:66
wxString m_name
Definition: pcb_group.h:219
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_group.cpp:195
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_group.cpp:375
void swapData(BOARD_ITEM *aImage) override
Definition: pcb_group.cpp:238
void SetLocked(bool aLocked) override
Definition: pcb_group.cpp:183
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:82
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:149
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110