KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_generator.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) 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef GENERATOR_H_
22#define GENERATOR_H_
23
24
25#include <memory>
26#include <unordered_set>
27#include <utility>
28#include <vector>
29#include <string_any_map.h>
30
31#include <lset.h>
32#include <pcb_group.h>
34
35class EDIT_POINTS;
36class BOARD;
37class BOARD_ITEM;
38class ZONE;
40class GENERATOR_TOOL;
41class STATUS_MIN_MAX_POPUP;
42class ACTION_MENU;
44
45
47{
48public:
49
50 PCB_GENERATOR( BOARD_ITEM* aParent, PCB_LAYER_ID aLayer );
51
52 virtual ~PCB_GENERATOR();
53
54 /*
55 * Clone() this and all descendants
56 */
57 PCB_GENERATOR* DeepClone() const;
58
59 virtual void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0;
60 virtual bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0;
61 virtual void EditFinish( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0;
62 virtual void EditCancel( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0;
63
64 virtual void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0;
65
69 virtual bool ChildrenAreIndividuallySelectable() const { return false; }
70
77 virtual ACTION_MENU* GetChildContextMenu( TOOL_INTERACTIVE* aTool ) const { return nullptr; }
78
83 virtual bool ChildrenAreReadOnly() const { return true; }
84
92 virtual std::vector<std::pair<wxString, const BOARD_ITEM*>> GetTemplateItems() const { return {}; }
93
100 virtual void SetTemplateItem( const wxString& aName, std::unique_ptr<BOARD_ITEM> aItem ) {}
101
102#define STATUS_ITEMS_ONLY true
103
104 virtual std::vector<EDA_ITEM*> GetPreviewItems( GENERATOR_TOOL* aTool,
105 PCB_BASE_EDIT_FRAME* aFrame,
106 bool aStatusItemsOnly = false );
107
108 virtual bool MakeEditPoints( EDIT_POINTS& aEditPoints ) const;
109
110 virtual bool UpdateFromEditPoints( EDIT_POINTS& aEditPoints );
111
112 virtual bool UpdateEditPoints( EDIT_POINTS& aEditPoints );
113
114 const BOX2I GetBoundingBox() const override;
115
116 VECTOR2I GetPosition() const override { return m_origin; }
117 void SetPosition( const VECTOR2I& aPos ) override { m_origin = aPos; }
118
119 void Move( const VECTOR2I& aMoveVector ) override;
120
121 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
122
123 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
124
125 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aMirrorDirection ) override;
126
127 LSET GetLayerSet() const override;
128
129 PCB_LAYER_ID GetLayer() const override { return m_layer; }
130 void SetLayer( PCB_LAYER_ID aLayer ) override { m_layer = aLayer; }
131
132 virtual wxString GetGeneratorType() const;
133
134 virtual bool LayerFollowsMembers() const { return true; }
135
136 virtual bool CanDuplicate() const { return false; }
137
138 virtual const STRING_ANY_MAP GetProperties() const;
139
140 virtual void SetProperties( const STRING_ANY_MAP& aProps );
141
142 virtual std::vector<std::pair<wxString, wxVariant>> GetRowData();
143
144 virtual void ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) {};
145
146 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
147
148 virtual wxString GetPluralName() const = 0;
149 virtual wxString GetCommitMessage() const = 0;
150
151#if defined(DEBUG)
152 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
153#endif
154
155 wxString GetClass() const override;
156
157 static inline bool ClassOf( const EDA_ITEM* aItem );
158
159#ifdef GENERATOR_ORDER
160 int GetUpdateOrder() const { return m_updateOrder; }
161 void SetUpdateOrder( int aValue ) { m_updateOrder = aValue; }
162#endif
163
168 bool IsDirty() const { return m_isDirty; }
169 void MarkDirty() { m_isDirty = true; }
170 void ClearDirty() { m_isDirty = false; }
171
175 virtual void OnZoneFillChanged( const std::vector<ZONE*>& aZones ) {}
176
180 virtual std::vector<ZONE*> GetZonesNeedingRefillAfterUpdate() const { return {}; }
181
182protected:
184
186
188
189#ifdef GENERATOR_ORDER
190 int m_updateOrder = 0;
191#endif
192
193 friend class GENERATORS_MGR;
194
195 void baseMirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
196};
197
199{
200public:
202 PCB_GENERATOR( aParent, aLayer )
203 {
204 }
205
206 const SHAPE_POLY_SET& Outline() const { return m_outline; }
208
209 void SetOutline( const SHAPE_POLY_SET& aOutline ) { m_outline = aOutline; MarkDirty(); }
210
211 void Move( const VECTOR2I& aMoveVector ) override
212 {
213 m_outline.Move( aMoveVector );
214 PCB_GENERATOR::Move( aMoveVector );
215 MarkDirty();
216 }
217
218 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override
219 {
220 m_outline.Rotate( aAngle, aRotCentre );
221 PCB_GENERATOR::Rotate( aRotCentre, aAngle );
222 MarkDirty();
223 }
224
225 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override
226 {
227 m_outline.Mirror( aCentre, aFlipDirection );
228 PCB_GENERATOR::Flip( aCentre, aFlipDirection );
229 MarkDirty();
230 }
231
232 void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aMirrorDirection ) override
233 {
234 m_outline.Mirror( aCentre, aMirrorDirection );
235 PCB_GENERATOR::Mirror( aCentre, aMirrorDirection );
236 MarkDirty();
237 }
238
239protected:
241};
242
243#endif /* GENERATOR_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
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
friend class BOARD
Definition board_item.h:578
PCB_LAYER_ID m_layer
Definition board_item.h:571
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
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.
void SetOutline(const SHAPE_POLY_SET &aOutline)
PCB_GENERATOR_POLY(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.
const SHAPE_POLY_SET & Outline() const
SHAPE_POLY_SET m_outline
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
SHAPE_POLY_SET & Outline()
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
virtual ~PCB_GENERATOR()
virtual ACTION_MENU * GetChildContextMenu(TOOL_INTERACTIVE *aTool) const
Get a context menu when interacting with a generator child.
virtual void Remove(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
virtual void EditCancel(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
virtual void SetProperties(const STRING_ANY_MAP &aProps)
void baseMirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
wxString m_generatorType
virtual wxString GetCommitMessage() const =0
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
virtual void EditStart(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
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)
virtual bool ChildrenAreIndividuallySelectable() const
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.
virtual std::vector< std::pair< wxString, const BOARD_ITEM * > > GetTemplateItems() const
Named template items used by the generator.
PCB_GENERATOR(BOARD_ITEM *aParent, PCB_LAYER_ID aLayer)
bool IsDirty() const
Dirty flag system to for determining if generator output is not up to date It is up to each generator...
friend class GENERATORS_MGR
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aMirrorDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
virtual void ShowPropertiesDialog(PCB_BASE_EDIT_FRAME *aEditFrame)
virtual bool LayerFollowsMembers() const
virtual bool Update(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
virtual wxString GetPluralName() const =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.
virtual bool MakeEditPoints(EDIT_POINTS &aEditPoints) const
PCB_GENERATOR * DeepClone() const
void SetPosition(const VECTOR2I &aPos) override
virtual bool ChildrenAreReadOnly() const
virtual std::vector< ZONE * > GetZonesNeedingRefillAfterUpdate() const
Zones that need to be refilled after the generator runs Update()
virtual void EditFinish(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit)=0
virtual bool UpdateEditPoints(EDIT_POINTS &aEditPoints)
virtual std::vector< EDA_ITEM * > GetPreviewItems(GENERATOR_TOOL *aTool, PCB_BASE_EDIT_FRAME *aFrame, bool aStatusItemsOnly=false)
VECTOR2I GetPosition() const override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
virtual bool CanDuplicate() const
virtual void OnZoneFillChanged(const std::vector< ZONE * > &aZones)
Callback to be informed zones have changed.
virtual std::vector< std::pair< wxString, wxVariant > > GetRowData()
virtual void SetTemplateItem(const wxString &aName, std::unique_ptr< BOARD_ITEM > aItem)
Insert a template item (from board file loading)
virtual const STRING_ANY_MAP GetProperties() const
virtual wxString GetGeneratorType() const
PCB_GROUP(BOARD_ITEM *aParent)
Definition pcb_group.cpp:43
Represent a set of closed polygons.
A name/value tuple with unique names and wxAny values.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
FLIP_DIRECTION
Definition mirror.h:23
Class to handle a set of BOARD_ITEMs.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683