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 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
25#include "pcb_generator.h"
26
27#include <board.h>
28#include <properties/property.h>
30
31
33 PCB_GROUP( aParent, PCB_GENERATOR_T, aLayer )
34{
35}
36
37
41
42
44{
45 // Use copy constructor to get the same uuid and other fields
46 PCB_GENERATOR* newGenerator = static_cast<PCB_GENERATOR*>( Clone() );
47 newGenerator->m_items.clear();
48
49 for( EDA_ITEM* member : m_items )
50 {
51 if( member->Type() == PCB_GROUP_T )
52 newGenerator->AddItem( static_cast<PCB_GROUP*>( member )->DeepClone() );
53 else if( member->Type() == PCB_GENERATOR_T )
54 newGenerator->AddItem( static_cast<PCB_GENERATOR*>( member )->DeepClone() );
55 else
56 newGenerator->AddItem( static_cast<BOARD_ITEM*>( member->Clone() ) );
57 }
58
59 return newGenerator;
60}
61
62
63std::vector<EDA_ITEM*> PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool,
64 PCB_BASE_EDIT_FRAME* aFrame,
65 bool aStatusItemsOnly )
66{
67 return std::vector<EDA_ITEM*>();
68}
69
70
72{
73 return true;
74}
75
76
78{
79 return true;
80}
81
82
84{
85 return true;
86}
87
88
90{
91 BOX2I bbox;
92 return bbox;
93}
94
95
96void PCB_GENERATOR::Move( const VECTOR2I& aMoveVector )
97{
98 m_origin += aMoveVector;
99
100 PCB_GROUP::Move( aMoveVector );
101}
102
103void PCB_GENERATOR::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
104{
105 RotatePoint( m_origin, aRotCentre, aAngle );
106
107 PCB_GROUP::Rotate( aRotCentre, aAngle );
108}
109
110void PCB_GENERATOR::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
111{
112 baseMirror( aCentre, aFlipDirection );
113
115
116 PCB_GROUP::Flip( aCentre, aFlipDirection );
117}
118
119void PCB_GENERATOR::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
120{
121 baseMirror( aCentre, aFlipDirection );
122
123 PCB_GROUP::Mirror( aCentre, aFlipDirection );
124}
125
126void PCB_GENERATOR::baseMirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
127{
128 if( aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
129 MIRROR( m_origin.y, aCentre.y );
130 else
131 MIRROR( m_origin.x, aCentre.x );
132}
133
135{
136 return PCB_GROUP::GetLayerSet() | LSET( { GetLayer() } );
137}
138
139
141{
142 m_layer = aLayer;
143}
144
145
147{
148 return m_generatorType;
149}
150
151
153{
154 STRING_ANY_MAP props( pcbIUScale.IU_PER_MM );
155
156#ifdef GENERATOR_ORDER
157 props.set( "update_order", m_updateOrder );
158#endif
159
160 props.set( "origin", m_origin );
161
162 return props;
163}
164
165
167{
168#ifdef GENERATOR_ORDER
169 aProps.get_to( "update_order", m_updateOrder );
170#endif
171
172 aProps.get_to( "origin", m_origin );
173}
174
175
176std::vector<std::pair<wxString, wxVariant>> PCB_GENERATOR::GetRowData()
177{
178#ifdef GENERATOR_ORDER
179 return { { _HKI( "Update Order" ), wxString::FromCDouble( GetUpdateOrder() ) } };
180#else
181 return { {} };
182#endif
183}
184
185
186wxString PCB_GENERATOR::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
187{
188 return wxString( _( "Generator" ) );
189}
190
191
193{
194 return wxS( "PCB_GENERATOR" );
195}
196
197
199{
200 return aItem && PCB_GENERATOR_T == aItem->Type();
201}
202
203
204#ifdef GENERATOR_ORDER
205static struct PCB_GENERATOR_DESC
206{
207 PCB_GENERATOR_DESC()
208 {
213
214 const wxString groupTab = _HKI( "Generator Properties" );
215
216 propMgr.AddProperty( new PROPERTY<PCB_GENERATOR, int>( _HKI( "Update Order" ),
217 &PCB_GENERATOR::SetUpdateOrder,
218 &PCB_GENERATOR::GetUpdateOrder ),
219 groupTab );
220 }
221} _PCB_GENERATOR_DESC;
222#endif
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:237
PCB_LAYER_ID m_layer
Definition board_item.h:459
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
std::unordered_set< EDA_ITEM * > m_items
Definition eda_group.h:76
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:27
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
Handle actions specific to filling copper zones.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
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.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
wxString GetClass() const override
Return the class name.
virtual bool UpdateFromEditPoints(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.
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.
virtual bool MakeEditPoints(EDIT_POINTS &aEditPoints) const
PCB_GENERATOR * DeepClone() const
virtual bool UpdateEditPoints(EDIT_POINTS &aEditPoints)
virtual std::vector< EDA_ITEM * > GetPreviewItems(GENERATOR_TOOL *aTool, PCB_BASE_EDIT_FRAME *aFrame, bool aStatusItemsOnly=false)
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
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.
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
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:47
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
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 _(s)
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition layer_id.cpp:172
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
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:29
#define _HKI(x)
Definition page_info.cpp:44
#define TYPE_HASH(x)
Definition property.h:74
#define REGISTER_TYPE(x)
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:111
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695