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 ( 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
virtual ARRAY_CREATOR::~ARRAY_CREATOR ( )
inlineprotectedvirtual

Definition at line 59 of file array_creator.h.

59 {}

Member Function Documentation

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().

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().

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().

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().

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().

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().

void ARRAY_CREATOR::Invoke ( )

Open the dialog, gather parameters and create the array

Definition at line 35 of file array_creator.cpp.

References COMMIT::Add(), BOARD::Duplicate(), MODULE::Duplicate(), finalise(), DIALOG_CREATE_ARRAY::GetArrayOptions(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::GetArraySize(), getBoard(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::GetItemNumber(), getModule(), getNthItemToArray(), getNumberOfItemsToArray(), getRotationCentre(), m_parent, DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::NumberingStartIsSpecified(), PCB_PAD_T, postPushAction(), prePushAction(), BOARD_COMMIT::Push(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::ShouldNumberItems(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::TransformItem(), and EDA_ITEM::Type().

Referenced by PCB_BASE_EDIT_FRAME::createArray().

36 {
37  const int numItems = getNumberOfItemsToArray();
38 
39  // bail out if no items
40  if( numItems == 0 )
41  return;
42 
43  MODULE* const module = getModule();
44  const bool isModuleEditor = module != NULL;
45 
46  const bool enableArrayNumbering = isModuleEditor;
47  const wxPoint rotPoint = getRotationCentre();
48 
49  DIALOG_CREATE_ARRAY dialog( &m_parent, enableArrayNumbering, rotPoint );
50  int ret = dialog.ShowModal();
51 
52  DIALOG_CREATE_ARRAY::ARRAY_OPTIONS* const array_opts = dialog.GetArrayOptions();
53 
54  if( ret != wxID_OK || array_opts == NULL )
55  return;
56 
57  BOARD_COMMIT commit( &m_parent );
58 
59  for ( int i = 0; i < numItems; ++i )
60  {
61  BOARD_ITEM* item = getNthItemToArray( i );
62 
63  if( item->Type() == PCB_PAD_T && !isModuleEditor )
64  {
65  // If it is not the module editor, then duplicate the parent module instead
66  item = static_cast<MODULE*>( item )->GetParent();
67  }
68 
69  // The first item in list is the original item. We do not modify it
70  for( int ptN = 1; ptN < array_opts->GetArraySize(); ptN++ )
71  {
72  BOARD_ITEM* new_item;
73 
74  if( isModuleEditor )
75  {
76  // increment pad numbers if do any renumbering
77  // (we will number again later according to the numbering scheme if set)
78  new_item = module->Duplicate( item, array_opts->ShouldNumberItems() );
79  }
80  else
81  {
82  // PCB items keep the same numbering
83  new_item = getBoard()->Duplicate( item );
84 
85  // @TODO: we should merge zones. This is a bit tricky, because
86  // the undo command needs saving old area, if it is merged.
87  }
88 
89  if( new_item )
90  {
91  array_opts->TransformItem( ptN, new_item, rotPoint );
92  prePushAction( new_item );
93  commit.Add( new_item );
94  postPushAction( new_item );
95  }
96 
97  // attempt to renumber items if the array parameters define
98  // a complete numbering scheme to number by (as opposed to
99  // implicit numbering by incrementing the items during creation
100  if( new_item && array_opts->NumberingStartIsSpecified() )
101  {
102  // Renumber pads. Only new pad number renumbering has meaning,
103  // in the footprint editor.
104  if( new_item->Type() == PCB_PAD_T )
105  {
106  const wxString padName = array_opts->GetItemNumber( ptN );
107  static_cast<D_PAD*>( new_item )->SetPadName( padName );
108  }
109  }
110  }
111  }
112 
113  commit.Push( _( "Create an array" ) );
114  finalise();
115 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual wxString GetItemNumber(int n) const =0
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
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
virtual MODULE * getModule() const =0
virtual void TransformItem(int n, BOARD_ITEM *item, const wxPoint &rotPoint) const =0
virtual wxPoint getRotationCentre() const =0
virtual BOARD * getBoard() const =0
virtual int getNumberOfItemsToArray() const =0
virtual void finalise()=0
virtual BOARD_ITEM * getNthItemToArray(int n) const =0
virtual int GetArraySize() const =0
virtual void prePushAction(BOARD_ITEM *new_item)
Definition: array_creator.h:96
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aAddToBoard=false)
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.

Referenced by Invoke().

103  {}
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.

Referenced by Invoke().

97  {}

Member Data Documentation


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