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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#ifndef CLASS_PCB_GROUP_H_
27#define CLASS_PCB_GROUP_H_
28
29#include <board_commit.h>
30#include <board_item.h>
31#include <eda_group.h>
32#include <kiid.h>
33#include <lset.h>
34#include <map>
35#include <unordered_set>
36
37namespace KIGFX
38{
39class VIEW;
40}
41
50class PCB_GROUP : public BOARD_ITEM, public EDA_GROUP
51{
52public:
53 PCB_GROUP( BOARD_ITEM* aParent );
54
55 void Serialize( google::protobuf::Any& aContainer ) const override;
56 bool Deserialize( const google::protobuf::Any& aContainer ) override;
57 bool DeserializeGroup( const google::protobuf::Any& aContainer, COMMIT* aCommit ) override;
58
59 EDA_ITEM* AsEdaItem() override { return this; }
60
61 static inline bool ClassOf( const EDA_ITEM* aItem )
62 {
63 return aItem && PCB_GROUP_T == aItem->Type();
64 }
65
66 wxString GetClass() const override
67 {
68 return wxT( "PCB_GROUP" );
69 }
70
71 std::unordered_set<BOARD_ITEM*> GetBoardItems() const;
72
73 /*
74 * Search for highest level group inside of aScope, containing item.
75 *
76 * @param aScope restricts the search to groups within the group scope.
77 * @param isFootprintEditor true if we should stop promoting at the footprint level
78 * @return group inside of aScope, containing item, if exists, otherwise, nullptr
79 */
80 static EDA_GROUP* TopLevelGroup( BOARD_ITEM* aItem, EDA_GROUP* aScope, bool isFootprintEditor );
81
82 static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
83
84 double Similarity( const BOARD_ITEM& aOther ) const override;
85
86 bool operator==( const PCB_GROUP& aOther ) const;
87 bool operator==( const BOARD_ITEM& aBoardItem ) const override;
88
89#if defined( DEBUG )
90 void Show( int nestLevel, std::ostream& os ) const override
91 {
92 ShowDummy( os );
93 }
94#endif
95
97 VECTOR2I GetPosition() const override;
98
100 void SetPosition( const VECTOR2I& aNewpos ) override;
101
102 PCB_LAYER_ID GetLayer() const override
103 {
104 wxFAIL_MSG( wxT( "PCB_GROUP::GetLayer() isn't well-defined. Don't call it." ) );
105 return UNDEFINED_LAYER;
106 }
107
109 LSET GetLayerSet() const override;
110
112 bool IsLayerAgnostic() const override { return true; }
113
115 void SetLayer( PCB_LAYER_ID aLayer ) override
116 {
117 // NOP
118 }
119
120 bool IsOnCopperLayer() const override
121 {
122 // A group might have members on a copper layer, but isn't itself on any layer.
123 return false;
124 }
125
126 void SetLocked( bool aLocked ) override;
127
129 EDA_ITEM* Clone() const override;
130
131 /*
132 * Clone this and all descendants
133 */
134 PCB_GROUP* DeepClone() const;
135
136 /*
137 * Duplicate this and all descendants
138 *
139 * @param addToParentGroup if the original is part of a group then the new member will also
140 * be added to said group
141 * @param aKIIDMap if non-null orig-to-dupe KIID map for group and descendants captured at
142 * clone time members iterate unordered so this is the only reliable pairing
143 * eg for re-pointing constraints
144 */
145 PCB_GROUP* DeepDuplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr,
146 std::map<KIID, KIID>* aKIIDMap = nullptr ) const;
147
149 bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
150
152 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
153
155 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
156
158 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
159
161 const BOX2I GetBoundingBox() const override;
162
163 // @copydoc BOARD_ITEM::GetEffectiveShape
164 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
166 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const override;
167
169 INSPECT_RESULT Visit( INSPECTOR aInspector, void* aTestData,
170 const std::vector<KICAD_T>& aScanTypes ) override;
171
173 std::vector<int> ViewGetLayers() const override;
174
176 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
177
179 void Move( const VECTOR2I& aMoveVector ) override;
180
182 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
183
185 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
186
188 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
189
191 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
192
194 BITMAPS GetMenuImage() const override;
195
197 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
198
200 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
201
203 void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
204
205protected:
206 PCB_GROUP( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu );
207
209 void swapData( BOARD_ITEM* aImage ) override;
210
218 void swapChildOwnership( PCB_GROUP* aImage );
219};
220
221#endif // CLASS_PCB_GROUP_H_
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:68
The base class for create windows for drawing purpose.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
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
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
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:51
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
static bool WithinScope(BOARD_ITEM *aItem, PCB_GROUP *aScope, bool isFootprintEditor)
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
PCB_GROUP * DeepClone() const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition pcb_group.h:115
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition pcb_group.cpp:82
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_group.h:102
static EDA_GROUP * TopLevelGroup(BOARD_ITEM *aItem, EDA_GROUP *aScope, bool isFootprintEditor)
bool IsOnCopperLayer() const override
Definition pcb_group.h:120
bool operator==(const PCB_GROUP &aOther) const
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_group.h:61
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
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
void Move(const VECTOR2I &aMoveVector) override
Move this object.
bool DeserializeGroup(const google::protobuf::Any &aContainer, COMMIT *aCommit) override
Deserializes the given protobuf message into this group.
Definition pcb_group.cpp:87
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
wxString GetClass() const override
Return the class name.
Definition pcb_group.h:66
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...
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
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.
VECTOR2I GetPosition() const override
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
PCB_GROUP * DeepDuplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr, std::map< KIID, KIID > *aKIIDMap=nullptr) const
EDA_ITEM * AsEdaItem() override
Definition pcb_group.h:59
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
void swapChildOwnership(PCB_GROUP *aImage)
Re-point the children of this group and aImage at whichever group now holds them.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
PCB_GROUP(BOARD_ITEM *aParent)
Definition pcb_group.cpp:43
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool IsLayerAgnostic() const override
Check if this item's layer set must not be confined to a board's enabled layers.
Definition pcb_group.h:112
void swapData(BOARD_ITEM *aImage) override
void SetLocked(bool aLocked) override
std::vector< int > ViewGetLayers() const override
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ NULL_CONSTRAINT
Definition drc_rule.h:50
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:180
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
FLIP_DIRECTION
Definition mirror.h:23
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683