KiCad PCB EDA Suite
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-2021 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 <unordered_set>
36 
37 namespace KIGFX
38 {
39 class VIEW;
40 }
41 
50 class PCB_GROUP : public BOARD_ITEM
51 {
52 public:
53  PCB_GROUP( BOARD_ITEM* aParent );
54 
55  static inline bool ClassOf( const EDA_ITEM* aItem )
56  {
57  return aItem && PCB_GROUP_T == aItem->Type();
58  }
59 
60  wxString GetClass() const override
61  {
62  return wxT( "PCB_GROUP" );
63  }
64 
65  wxString GetName() const { return m_name; }
66  void SetName( wxString aName ) { m_name = aName; }
67 
68  std::unordered_set<BOARD_ITEM*>& GetItems()
69  {
70  return m_items;
71  }
72 
73  const std::unordered_set<BOARD_ITEM*>& GetItems() const
74  {
75  return m_items;
76  }
77 
83  bool AddItem( BOARD_ITEM* aItem );
84 
90  bool RemoveItem( BOARD_ITEM* aItem );
91 
92  void RemoveAll();
93 
94  /*
95  * Search for highest level group containing item.
96  *
97  * @param aScope restricts the search to groups within the group scope.
98  * @param isFootprintEditor true if we should stop promoting at the footprint level
99  * @return group containing item, if it exists, otherwise, NULL
100  */
101  static PCB_GROUP* TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
102 
103  static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
104 
105 #if defined( DEBUG )
106  void Show( int nestLevel, std::ostream& os ) const override
107  {
108  ShowDummy( os );
109  }
110 #endif
111 
113  wxPoint GetPosition() const override;
114 
116  void SetPosition( const wxPoint& aNewpos ) override;
117 
119  LSET GetLayerSet() const override;
120 
122  void SetLayer( PCB_LAYER_ID aLayer ) override
123  {
124  wxFAIL_MSG( "groups don't support layer SetLayer" );
125  }
126 
131  void SetLayerRecursive( PCB_LAYER_ID aLayer, int aDepth );
132 
134  EDA_ITEM* Clone() const override;
135 
136  /*
137  * Clone() this and all descendants
138  */
139  PCB_GROUP* DeepClone() const;
140 
141  /*
142  * Duplicate() this and all descendants
143  */
144  PCB_GROUP* DeepDuplicate() const;
145 
147  void SwapData( BOARD_ITEM* aImage ) override;
148 
150  bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
151 
153  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
154 
156  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
157 
159  const EDA_RECT GetBoundingBox() const override;
160 
162  SEARCH_RESULT Visit( INSPECTOR aInspector, void* aTestData,
163  const KICAD_T aScanTypes[] ) override;
164 
166  void ViewGetLayers( int aLayers[], int& aCount ) const override;
167 
169  double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
170 
172  void Move( const wxPoint& aMoveVector ) override;
173 
175  void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
176 
178  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
179 
181  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
182 
184  BITMAPS GetMenuImage() const override;
185 
186 
194  {
195  RunOnChildren( [&]( BOARD_ITEM* bItem )
196  {
197  aCommit.Add( bItem );
198  } );
199  }
200 
201 
203  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
204 
212  void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const;
213 
220  void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction ) const;
221 
222 private:
223  std::unordered_set<BOARD_ITEM*> m_items; // Members of the group
224  wxString m_name; // Optional group name
225 };
226 
227 #endif // CLASS_PCB_GROUP_H_
void RemoveAll()
Definition: pcb_group.cpp:63
void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: pcb_group.cpp:263
bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:38
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_group.h:55
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return a pointer to an image to be used in menus.
Definition: pcb_group.cpp:300
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_group.cpp:314
void SwapData(BOARD_ITEM *aImage) override
Test to see if this object is on the given layer.
Definition: pcb_group.cpp:188
wxString GetClass() const override
Return the class name.
Definition: pcb_group.h:60
void AddChildrenToCommit(BOARD_COMMIT &aCommit)
Add all the immediate children of this group to the board commit.
Definition: pcb_group.h:193
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:194
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
wxPoint GetPosition() const override
Definition: pcb_group.cpp:115
SEARCH_RESULT Visit(INSPECTOR aInspector, void *aTestData, const KICAD_T aScanTypes[]) override
Definition: pcb_group.cpp:223
PCB_GROUP * DeepClone() const
Definition: pcb_group.cpp:153
static PCB_GROUP * TopLevelGroup(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:99
const EDA_RECT GetBoundingBox() const 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:210
The base class for create windows for drawing purpose.
const std::unordered_set< BOARD_ITEM * > & GetItems() const
Definition: pcb_group.h:73
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:68
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: pcb_group.cpp:293
PCB_GROUP * DeepDuplicate() const
Swap data between aItem and aImage.
Definition: pcb_group.cpp:171
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_group.h:122
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:320
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Flip this object, i.e.
Definition: pcb_group.cpp:286
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
wxString GetName() const
Definition: pcb_group.h:65
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: pcb_group.cpp:196
void Move(const wxPoint &aMoveVector) override
Rotate this object.
Definition: pcb_group.cpp:279
wxString m_name
Definition: pcb_group.h:224
LSET GetLayerSet() const override
Set the layer this item is on.
Definition: pcb_group.cpp:239
bool RemoveItem(BOARD_ITEM *aItem)
Remove item from group.
Definition: pcb_group.cpp:50
static bool WithinScope(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:107
void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all descendants of the group.
Definition: pcb_group.cpp:341
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Move this object.
Definition: pcb_group.cpp:270
EDA_UNITS
Definition: eda_units.h:38
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: pcb_group.cpp:250
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void SetLayerRecursive(PCB_LAYER_ID aLayer, int aDepth)
Set layer for all items within the group.
Definition: pcb_group.cpp:129
void SetPosition(const wxPoint &aNewpos) override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_group.cpp:121
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
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all members of the group.
Definition: pcb_group.cpp:327
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
SEARCH_RESULT
Definition: eda_item.h:41
std::unordered_set< BOARD_ITEM * > m_items
Definition: pcb_group.h:223
PCB_GROUP(BOARD_ITEM *aParent)
Definition: pcb_group.cpp:32
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_group.cpp:145
void SetName(wxString aName)
Definition: pcb_group.h:66
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113