KiCad PCB EDA Suite
ARRAY_CREATOR Class Referenceabstract

#include <array_creator.h>

Inheritance diagram for ARRAY_CREATOR:
GAL_ARRAY_CREATOR LEGACY_ARRAY_CREATOR

Public Member Functions

 ARRAY_CREATOR (PCB_BASE_FRAME &parent)
 
void Invoke ()
 

Protected Member Functions

virtual ~ARRAY_CREATOR ()
 

Protected Attributes

PCB_BASE_FRAMEm_parent
 

Private Member Functions

virtual BOARDgetBoard () const =0
 
virtual MODULEgetModule () const =0
 
virtual int getNumberOfItemsToArray () const =0
 
virtual BOARD_ITEMgetNthItemToArray (int n) const =0
 
virtual wxPoint getRotationCentre () const =0
 
virtual void prePushAction (BOARD_ITEM *new_item)
 
virtual void postPushAction (BOARD_ITEM *new_item)
 
virtual void finalise ()=0
 

Detailed Description

Class that performs array creation by producing a dialog to gather parameters and then creating and laying out the items.

This is a template class which needs to be implemented by the relevant edit tooling, since the details of how the document is manipulated varies between edit modes (e.g. legacy or GAL)

Definition at line 46 of file array_creator.h.

Constructor & Destructor Documentation

◆ ARRAY_CREATOR()

ARRAY_CREATOR::ARRAY_CREATOR ( PCB_BASE_FRAME parent)
inline

Definition at line 49 of file array_creator.h.

49  :
50  m_parent( parent )
51  {}
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61

◆ ~ARRAY_CREATOR()

virtual ARRAY_CREATOR::~ARRAY_CREATOR ( )
inlineprotectedvirtual

Definition at line 59 of file array_creator.h.

59 {}

Member Function Documentation

◆ finalise()

virtual void ARRAY_CREATOR::finalise ( )
privatepure virtual

Actions to perform after the array process is complete

Implemented in LEGACY_ARRAY_CREATOR, and GAL_ARRAY_CREATOR.

Referenced by Invoke().

◆ getBoard()

virtual BOARD* ARRAY_CREATOR::getBoard ( ) const
privatepure virtual

Get the BOARD that is currently being edited.

Implemented in LEGACY_ARRAY_CREATOR, and GAL_ARRAY_CREATOR.

Referenced by Invoke().

◆ getModule()

virtual MODULE* ARRAY_CREATOR::getModule ( ) const
privatepure virtual

If editing a footprint, returns the relevant MODULE, else NULL

Implemented in LEGACY_ARRAY_CREATOR, and GAL_ARRAY_CREATOR.

Referenced by Invoke().

◆ getNthItemToArray()

virtual BOARD_ITEM* ARRAY_CREATOR::getNthItemToArray ( int  n) const
privatepure virtual
Returns
the n'th original item to be arrayed

Implemented in LEGACY_ARRAY_CREATOR, and GAL_ARRAY_CREATOR.

Referenced by Invoke().

◆ getNumberOfItemsToArray()

virtual int ARRAY_CREATOR::getNumberOfItemsToArray ( ) const
privatepure virtual
Returns
number of original items to put into an array (eg size of the selection)

Implemented in LEGACY_ARRAY_CREATOR, and GAL_ARRAY_CREATOR.

Referenced by Invoke().

◆ getRotationCentre()

virtual wxPoint ARRAY_CREATOR::getRotationCentre ( ) const
privatepure virtual
Returns
the rotation centre of all the items to be arrayed, when taken together

Implemented in LEGACY_ARRAY_CREATOR, and GAL_ARRAY_CREATOR.

Referenced by Invoke().

◆ Invoke()

void ARRAY_CREATOR::Invoke ( )

Open the dialog, gather parameters and create the array

Definition at line 53 of file array_creator.cpp.

54 {
55  const int numItems = getNumberOfItemsToArray();
56 
57  // bail out if no items
58  if( numItems == 0 )
59  return;
60 
61  MODULE* const module = getModule();
62  const bool isModuleEditor = module != NULL;
63 
64  const bool enableArrayNumbering = isModuleEditor;
65  const wxPoint rotPoint = getRotationCentre();
66 
67  DIALOG_CREATE_ARRAY dialog( &m_parent, enableArrayNumbering, rotPoint );
68  int ret = dialog.ShowModal();
69 
70  ARRAY_OPTIONS* const array_opts = dialog.GetArrayOptions();
71 
72  if( ret != wxID_OK || array_opts == NULL )
73  return;
74 
75  BOARD_COMMIT commit( &m_parent );
76 
77  ARRAY_PAD_NAME_PROVIDER pad_name_provider( module, *array_opts );
78 
79  for ( int i = 0; i < numItems; ++i )
80  {
81  BOARD_ITEM* item = getNthItemToArray( i );
82 
83  if( item->Type() == PCB_PAD_T && !isModuleEditor )
84  {
85  // If it is not the module editor, then duplicate the parent module instead
86  item = static_cast<MODULE*>( item )->GetParent();
87  }
88 
89  // The first item in list is the original item. We do not modify it
90  for( int ptN = 0; ptN < array_opts->GetArraySize(); ptN++ )
91  {
92  BOARD_ITEM* this_item;
93 
94  if( ptN == 0 )
95  {
96  // the first point: we don't own this or add it, but
97  // we might still modify it (position or label)
98  this_item = item;
99  }
100  else
101  {
102  // Need to create a new item
103  std::unique_ptr<BOARD_ITEM> new_item;
104 
105  if( isModuleEditor )
106  {
107  // Don't bother incrementing pads: the module won't update
108  // until commit, so we can only do this once
109  new_item.reset( module->Duplicate( item, false ) );
110  }
111  else
112  {
113  new_item.reset( getBoard()->Duplicate( item ) );
114 
115  // Incrementing the reference number won't always be correct, but leaving
116  // it the same is always incorrect.
117  if( new_item->Type() == PCB_MODULE_T )
118  static_cast<MODULE&>( *new_item ).IncrementReference( ptN );
119 
120  // @TODO: we should merge zones. This is a bit tricky, because
121  // the undo command needs saving old area, if it is merged.
122  }
123 
124  this_item = new_item.get();
125 
126  if( new_item )
127  {
128  prePushAction( this_item );
129  commit.Add( new_item.release() );
130  postPushAction( this_item );
131  }
132  }
133 
134  // always transform the item
135  if( this_item )
136  {
137  commit.Modify( this_item );
138  TransformItem( *array_opts, ptN, *this_item );
139  }
140 
141  // attempt to renumber items if the array parameters define
142  // a complete numbering scheme to number by (as opposed to
143  // implicit numbering by incrementing the items during creation
144  if( this_item && array_opts->ShouldNumberItems() )
145  {
146  // Renumber non-aperture pads.
147  if( this_item->Type() == PCB_PAD_T )
148  {
149  auto& pad = static_cast<D_PAD&>( *this_item );
150 
151  if( PAD_NAMING::PadCanHaveName( pad ) )
152  {
153  wxString newName = pad_name_provider.GetNextPadName();
154  pad.SetName( newName );
155  }
156  }
157  }
158  }
159  }
160 
161  commit.Push( _( "Create an array" ) );
162  finalise();
163 }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
bool ShouldNumberItems() const
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aIncrementPadNumbers, bool aAddToModule=false)
Function Duplicate Duplicate a given item within the module, without adding to the board.
virtual void postPushAction(BOARD_ITEM *new_item)
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
bool PadCanHaveName(const D_PAD &aPad)
Check if a pad should be named.
Definition: pad_naming.cpp:26
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual int GetArraySize() const =0
The number of points in this array.
virtual MODULE * getModule() const =0
Simple class that sequentially provides names from an ARRAY_OPTIONS object, making sure that they do ...
Options that govern the setup of an "array" of multiple item.
Definition: array_options.h:34
class MODULE, a footprint
Definition: typeinfo.h:89
virtual wxPoint getRotationCentre() const =0
virtual BOARD * getBoard() const =0
static void TransformItem(const ARRAY_OPTIONS &aArrOpts, int aIndex, BOARD_ITEM &aItem)
Transform a BOARD_ITEM from the given ARRAY_OPTIONS and an index into the array.
virtual int getNumberOfItemsToArray() const =0
virtual void finalise()=0
size_t i
Definition: json11.cpp:597
virtual BOARD_ITEM * getNthItemToArray(int n) const =0
BOARD_ITEM_CONTAINER * GetParent() const
virtual void prePushAction(BOARD_ITEM *new_item)
Definition: array_creator.h:96
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201

References COMMIT::Add(), MODULE::Duplicate(), finalise(), DIALOG_CREATE_ARRAY::GetArrayOptions(), ARRAY_OPTIONS::GetArraySize(), getBoard(), getModule(), ARRAY_PAD_NAME_PROVIDER::GetNextPadName(), getNthItemToArray(), getNumberOfItemsToArray(), BOARD_ITEM::GetParent(), getRotationCentre(), i, m_parent, COMMIT::Modify(), PAD_NAMING::PadCanHaveName(), PCB_MODULE_T, PCB_PAD_T, postPushAction(), prePushAction(), BOARD_COMMIT::Push(), ARRAY_OPTIONS::ShouldNumberItems(), TransformItem(), and EDA_ITEM::Type().

Referenced by EDIT_TOOL::CreateArray(), and PCB_BASE_EDIT_FRAME::createArray().

◆ postPushAction()

virtual void ARRAY_CREATOR::postPushAction ( BOARD_ITEM new_item)
inlineprivatevirtual

Perform any actions needed after pushing an item to the BOARD

Reimplemented in GAL_ARRAY_CREATOR.

Definition at line 102 of file array_creator.h.

103  {}

Referenced by Invoke().

◆ prePushAction()

virtual void ARRAY_CREATOR::prePushAction ( BOARD_ITEM new_item)
inlineprivatevirtual

Perform any relevant action before pushing a newly created array item to the BOARD

Reimplemented in GAL_ARRAY_CREATOR.

Definition at line 96 of file array_creator.h.

97  {}

Referenced by Invoke().

Member Data Documentation

◆ m_parent


The documentation for this class was generated from the following files: