KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_generator.cpp
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) 2023 Alex Shvartzkop <[email protected]>
5 * Copyright (C) 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
25#include "pcb_generator.h"
26
27#include <board.h>
28
29
31 PCB_GROUP( aParent, PCB_GENERATOR_T, aLayer )
32{
33}
34
35
37{
38}
39
40
42{
43 // Use copy constructor to get the same uuid and other fields
44 PCB_GENERATOR* newGenerator = static_cast<PCB_GENERATOR*>( Clone() );
45 newGenerator->m_items.clear();
46
47 for( BOARD_ITEM* member : m_items )
48 {
49 if( member->Type() == PCB_GROUP_T )
50 newGenerator->AddItem( static_cast<PCB_GROUP*>( member )->DeepClone() );
51 else
52 newGenerator->AddItem( static_cast<BOARD_ITEM*>( member->Clone() ) );
53 }
54
55 return newGenerator;
56}
57
58
60{
61 aCommit->Modify( this );
62}
63
64
66 const wxString& aCommitMsg, int aCommitFlags )
67{
68 aCommit->Push( aCommitMsg, aCommitFlags );
69}
70
71
73{
74 aCommit->Revert();
75}
76
77
78void PCB_GENERATOR::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
79{
80 aCommit->Remove( this );
81}
82
83
84bool PCB_GENERATOR::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
85{
86 return true;
87}
88
89
90std::vector<EDA_ITEM*> PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool,
91 PCB_BASE_EDIT_FRAME* aFrame,
92 bool aStatusItemsOnly )
93{
94 return std::vector<EDA_ITEM*>();
95}
96
97
98bool PCB_GENERATOR::MakeEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) const
99{
100 return true;
101}
102
103
104bool PCB_GENERATOR::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
105 BOARD_COMMIT* aCommit )
106{
107 return true;
108}
109
110
111bool PCB_GENERATOR::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
112{
113 return true;
114}
115
116
118{
119 BOX2I bbox;
120 return bbox;
121}
122
123
124void PCB_GENERATOR::Move( const VECTOR2I& aMoveVector )
125{
126 m_origin += aMoveVector;
127
128 PCB_GROUP::Move( aMoveVector );
129}
130
131void PCB_GENERATOR::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
132{
133 RotatePoint( m_origin, aRotCentre, aAngle );
134
135 PCB_GROUP::Rotate( aRotCentre, aAngle );
136}
137
138void PCB_GENERATOR::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
139{
140 baseMirror( aCentre, aFlipDirection );
141
143
144 PCB_GROUP::Flip( aCentre, aFlipDirection );
145}
146
147void PCB_GENERATOR::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
148{
149 baseMirror( aCentre, aFlipDirection );
150
151 PCB_GROUP::Mirror( aCentre, aFlipDirection );
152}
153
154void PCB_GENERATOR::baseMirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
155{
156 if( aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
157 MIRROR( m_origin.y, aCentre.y );
158 else
159 MIRROR( m_origin.x, aCentre.x );
160}
161
163{
164 // Items can only be in one group at a time
165 if( aItem->GetParentGroup() )
166 aItem->GetParentGroup()->RemoveItem( aItem );
167
168 m_items.insert( aItem );
169 aItem->SetParentGroup( this );
170 return true;
171}
172
173
175{
176 return PCB_GROUP::GetLayerSet() | LSET( { GetLayer() } );
177}
178
179
181{
182 m_layer = aLayer;
183}
184
185
187{
188 return m_generatorType;
189}
190
191
193{
195
196#ifdef GENERATOR_ORDER
197 props.set( "update_order", m_updateOrder );
198#endif
199
200 props.set( "origin", m_origin );
201
202 return props;
203}
204
205
207{
208#ifdef GENERATOR_ORDER
209 aProps.get_to( "update_order", m_updateOrder );
210#endif
211
212 aProps.get_to( "origin", m_origin );
213}
214
215
216std::vector<std::pair<wxString, wxVariant>> PCB_GENERATOR::GetRowData()
217{
218#ifdef GENERATOR_ORDER
219 return { { _HKI( "Update Order" ), wxString::FromCDouble( GetUpdateOrder() ) } };
220#else
221 return { {} };
222#endif
223}
224
225
226wxString PCB_GENERATOR::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
227{
228 return wxString( _( "Generator" ) );
229}
230
231
233{
234 return wxS( "PCB_GENERATOR" );
235}
236
237
239{
240 return aItem && PCB_GENERATOR_T == aItem->Type();
241}
242
243
244#ifdef GENERATOR_ORDER
245static struct PCB_GENERATOR_DESC
246{
247 PCB_GENERATOR_DESC()
248 {
253
254 const wxString groupTab = _HKI( "Generator Properties" );
255
256 propMgr.AddProperty( new PROPERTY<PCB_GENERATOR, int>( _HKI( "Update Order" ),
257 &PCB_GENERATOR::SetUpdateOrder,
258 &PCB_GENERATOR::GetUpdateOrder ),
259 groupTab );
260 }
261} _PCB_GENERATOR_DESC;
262#endif
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
virtual void Revert() override
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:237
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:89
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:90
PCB_LAYER_ID m_layer
Definition: board_item.h:436
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been removed.
Definition: commit.h:92
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
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
Handle actions specific to filling copper zones.
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
Common, abstract interface for edit frames.
virtual ~PCB_GENERATOR()
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
virtual void SetProperties(const STRING_ANY_MAP &aProps)
void baseMirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
wxString m_generatorType
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
virtual void Remove(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)
virtual void EditRevert(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
wxString GetClass() const override
Return the class name.
virtual bool UpdateEditPoints(std::shared_ptr< EDIT_POINTS > aEditPoints)
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
PCB_GENERATOR(BOARD_ITEM *aParent, PCB_LAYER_ID aLayer)
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aMirrorDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
virtual bool MakeEditPoints(std::shared_ptr< EDIT_POINTS > aEditPoints) const
bool AddItem(BOARD_ITEM *aItem) override
Add item to group.
virtual void EditPush(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit, const wxString &aCommitMsg=wxEmptyString, int aCommitFlags=0)
VECTOR2I m_origin
static bool ClassOf(const EDA_ITEM *aItem)
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
PCB_GENERATOR * DeepClone() const
virtual void EditStart(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)
virtual std::vector< EDA_ITEM * > GetPreviewItems(GENERATOR_TOOL *aTool, PCB_BASE_EDIT_FRAME *aFrame, bool aStatusItemsOnly=false)
virtual bool Update(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)
void Move(const VECTOR2I &aMoveVector) override
Move this object.
virtual std::vector< std::pair< wxString, wxVariant > > GetRowData()
virtual const STRING_ANY_MAP GetProperties() const
virtual wxString GetGeneratorType() const
virtual bool UpdateFromEditPoints(std::shared_ptr< EDIT_POINTS > aEditPoints, BOARD_COMMIT *aCommit)
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
std::unordered_set< BOARD_ITEM * > m_items
Definition: pcb_group.h:221
PCB_GROUP * DeepClone() const
Definition: pcb_group.cpp:204
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:369
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_group.cpp:355
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_group.cpp:308
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_group.cpp:348
virtual bool RemoveItem(BOARD_ITEM *aItem)
Remove item from group.
Definition: pcb_group.cpp:96
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_group.cpp:362
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_group.cpp:196
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
A name/value tuple with unique names and wxAny values.
bool get_to(const std::string &aKey, T &aVar) const
void set(const std::string &aKey, const T &aVar)
#define _HKI(x)
#define _(s)
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: layer_id.cpp:211
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:45
FLIP_DIRECTION
Definition: mirror.h:27
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
const double IU_PER_MM
Definition: base_units.h:76
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition: typeinfo.h:91
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110