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 The 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 <eda_group.h>
36#include <lset.h>
37#include <unordered_set>
38
39namespace KIGFX
40{
41class VIEW;
42}
43
52class PCB_GROUP : public BOARD_ITEM, public EDA_GROUP
53{
54public:
55 PCB_GROUP( BOARD_ITEM* aParent );
56
57 void Serialize( google::protobuf::Any &aContainer ) const override;
58 bool Deserialize( const google::protobuf::Any &aContainer ) override;
59
60 EDA_ITEM* AsEdaItem() override { return this; }
61
62 static inline bool ClassOf( const EDA_ITEM* aItem )
63 {
64 return aItem && PCB_GROUP_T == aItem->Type();
65 }
66
67 wxString GetClass() const override
68 {
69 return wxT( "PCB_GROUP" );
70 }
71
72 std::unordered_set<BOARD_ITEM*> GetBoardItems() const;
73
74 /*
75 * Search for highest level group inside of aScope, containing item.
76 *
77 * @param aScope restricts the search to groups within the group scope.
78 * @param isFootprintEditor true if we should stop promoting at the footprint level
79 * @return group inside of aScope, containing item, if exists, otherwise, nullptr
80 */
81 static EDA_GROUP* TopLevelGroup( BOARD_ITEM* aItem, EDA_GROUP* aScope, bool isFootprintEditor );
82
83 static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
84
85 double Similarity( const BOARD_ITEM& aOther ) const override;
86
87 bool operator==( const PCB_GROUP& aOther ) const;
88 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
89
90#if defined( DEBUG )
91 void Show( int nestLevel, std::ostream& os ) const override
92 {
93 ShowDummy( os );
94 }
95#endif
96
98 VECTOR2I GetPosition() const override;
99
101 void SetPosition( const VECTOR2I& aNewpos ) override;
102
104 LSET GetLayerSet() const override;
105
107 void SetLayer( PCB_LAYER_ID aLayer ) override
108 {
109 // NOP
110 }
111
112 bool IsOnCopperLayer() const override
113 {
114 // A group might have members on a copper layer, but isn't itself on any layer.
115 return false;
116 }
117
118 void SetLocked( bool aLocked ) override;
119
121 EDA_ITEM* Clone() const override;
122
123 /*
124 * Clone this and all descendants
125 */
126 PCB_GROUP* DeepClone() const;
127
128 /*
129 * Duplicate this and all descendants
130 *
131 * @param addToParentGroup if the original is part of a group then the new member will also
132 * be added to said group
133 */
134 PCB_GROUP* DeepDuplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
135
137 bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
138
140 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
141
143 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
144
146 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
147
149 const BOX2I GetBoundingBox() const override;
150
151 // @copydoc BOARD_ITEM::GetEffectiveShape
152 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
153 FLASHING aFlash = FLASHING::DEFAULT ) const override;
154
156 INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
157 const std::vector<KICAD_T>& aScanTypes ) override;
158
160 std::vector<int> ViewGetLayers() const override;
161
163 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
164
166 void Move( const VECTOR2I& aMoveVector ) override;
167
169 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
170
172 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
173
175 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
176
178 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
179
181 BITMAPS GetMenuImage() const override;
182
184 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
185
187 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
188
190 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
191
192protected:
193 PCB_GROUP( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu );
194
196 void swapData( BOARD_ITEM* aImage ) override;
197};
198
199#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 set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:53
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_group.cpp:266
static bool WithinScope(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:151
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_group.cpp:378
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: pcb_group.cpp:403
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
Definition: pcb_group.cpp:409
PCB_GROUP * DeepClone() const
Definition: pcb_group.cpp:199
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_group.h:107
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_group.cpp:72
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
Definition: pcb_group.cpp:371
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_group.cpp:357
static EDA_GROUP * TopLevelGroup(BOARD_ITEM *aItem, EDA_GROUP *aScope, bool isFootprintEditor)
Definition: pcb_group.cpp:145
bool IsOnCopperLayer() const override
Definition: pcb_group.h:112
bool operator==(const PCB_GROUP &aOther) const
Definition: pcb_group.cpp:441
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition: pcb_group.cpp:322
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_group.h:62
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_group.cpp:311
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_group.cpp:54
void SetPosition(const VECTOR2I &aNewpos) override
Definition: pcb_group.cpp:170
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_group.cpp:350
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:463
wxString GetClass() const override
Return the class name.
Definition: pcb_group.h:67
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:295
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Definition: pcb_group.cpp:341
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:284
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
Definition: pcb_group.cpp:98
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:393
VECTOR2I GetPosition() const override
Definition: pcb_group.cpp:164
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_group.cpp:364
EDA_ITEM * AsEdaItem() override
Definition: pcb_group.h:60
PCB_GROUP * DeepDuplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Definition: pcb_group.cpp:219
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:245
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_group.cpp:191
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_group.cpp:387
void swapData(BOARD_ITEM *aImage) override
Definition: pcb_group.cpp:236
void SetLocked(bool aLocked) override
Definition: pcb_group.cpp:178
std::vector< int > ViewGetLayers() const override
Definition: pcb_group.cpp:335
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
RECURSE_MODE
Definition: eda_item.h:50
INSPECT_RESULT
Definition: eda_item.h:44
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition: eda_item.h:91
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:184
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
FLIP_DIRECTION
Definition: mirror.h:27
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:33
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