KiCad PCB EDA Suite
class_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-2020 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 
35 #ifndef CLASS_PCB_GROUP_H_
36 #define CLASS_PCB_GROUP_H_
37 
38 #include <board_commit.h>
39 #include <class_board_item.h>
40 #include <unordered_set>
41 
42 namespace KIGFX
43 {
44 class VIEW;
45 }
46 
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  const std::unordered_set<BOARD_ITEM*>& GetItems() const
69  {
70  return m_items;
71  }
72 
78  bool AddItem( BOARD_ITEM* aItem );
79 
85  bool RemoveItem( BOARD_ITEM* aItem );
86 
87  void RemoveAll();
88 
89  /*
90  * Searches for highest level group containing item.
91  * @param scope restricts the search to groups within the group scope.
92  * @return group containing item, if it exists, otherwise, NULL
93  */
94  static PCB_GROUP* TopLevelGroup( BOARD_ITEM* item, PCB_GROUP* scope );
95 
96  static bool WithinScope( BOARD_ITEM* item, PCB_GROUP* scope );
97 
98 #if defined( DEBUG )
99  void Show( int nestLevel, std::ostream& os ) const override
100  {
101  ShowDummy( os );
102  }
103 #endif
104 
106  wxPoint GetPosition() const override;
107 
109  void SetPosition( const wxPoint& aNewpos ) override;
110 
112  LSET GetLayerSet() const override;
113 
115  void SetLayer( PCB_LAYER_ID aLayer ) override
116  {
117  wxFAIL_MSG( "groups don't support layer SetLayer" );
118  }
119 
121  EDA_ITEM* Clone() const override;
122 
123  /*
124  * Clone() this and all descendents
125  */
126  PCB_GROUP* DeepClone() const;
127 
128  /*
129  * Duplicate() this and all descendents
130  */
131  PCB_GROUP* DeepDuplicate() const;
132 
134  void SwapData( BOARD_ITEM* aImage ) override;
135 
137  bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
138 
140  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
141 
143  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
144 
146  const EDA_RECT GetBoundingBox() const override;
147 
149  SEARCH_RESULT Visit( INSPECTOR aInspector, void* aTestData, const KICAD_T aScanTypes[] ) override;
150 
152  void ViewGetLayers( int aLayers[], int& aCount ) const override;
153 
155  double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
156 
158  void Move( const wxPoint& aMoveVector ) override;
159 
161  void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
162 
164  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
165 
167  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
168 
170  BITMAP_DEF GetMenuImage() const override;
171 
173  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
174 
181  void AddChildrenToCommit( BOARD_COMMIT& aCommit ) const
182  {
183  RunOnChildren( [&]( BOARD_ITEM* bItem )
184  {
185  aCommit.Add( bItem );
186  } );
187  }
188 
194  void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const;
195 
202  void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction ) const;
203 
204 private:
205  std::unordered_set<BOARD_ITEM*> m_items; // Members of the group
206  wxString m_name; // Optional group name
207 };
208 
209 #endif // CLASS_PCB_GROUP_H_
void RemoveAll()
void ViewGetLayers(int aLayers[], int &aCount) const override
bool AddItem(BOARD_ITEM *aItem)
Adds item to group.
static bool ClassOf(const EDA_ITEM *aItem)
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
PNG memory record (file in memory).
Definition: bitmap_def.h:29
void SwapData(BOARD_ITEM *aImage) override
wxString GetClass() const override
Function GetClass returns the class name.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
static bool WithinScope(BOARD_ITEM *item, PCB_GROUP *scope)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
wxPoint GetPosition() const override
SEARCH_RESULT Visit(INSPECTOR aInspector, void *aTestData, const KICAD_T aScanTypes[]) override
PCB_GROUP * DeepClone() const
const EDA_RECT GetBoundingBox() const override
The base class for create windows for drawing purpose.
const std::unordered_set< BOARD_ITEM * > & GetItems() const
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
PCB_GROUP * DeepDuplicate() const
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void SetLayer(PCB_LAYER_ID aLayer) override
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
void Rotate(const wxPoint &aRotCentre, double aAngle) override
PCB_LAYER_ID
A quick note on layer IDs:
void AddChildrenToCommit(BOARD_COMMIT &aCommit) const
Add all the immediate children of this group to the board commit.
LSET is a set of PCB_LAYER_IDs.
wxString GetName() const
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
void Move(const wxPoint &aMoveVector) override
wxString m_name
LSET GetLayerSet() const override
bool RemoveItem(BOARD_ITEM *aItem)
Removes item from group.
void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invokes a function on all descendents of the group.
BITMAP_DEF GetMenuImage() const override
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
static PCB_GROUP * TopLevelGroup(BOARD_ITEM *item, PCB_GROUP *scope)
EDA_UNITS
Definition: eda_units.h:38
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
void SetPosition(const wxPoint &aNewpos) override
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invokes a function on all members of the group.
VIEW.
Definition: view.h:63
SEARCH_RESULT
Definition: eda_item.h:40
std::unordered_set< BOARD_ITEM * > m_items
PCB_GROUP(BOARD_ITEM *aParent)
EDA_ITEM * Clone() const override
void SetName(wxString aName)
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182