KiCad PCB EDA Suite
LEGACY_ARRAY_CREATOR Class Reference
Inheritance diagram for LEGACY_ARRAY_CREATOR:
ARRAY_CREATOR

Public Member Functions

 LEGACY_ARRAY_CREATOR (PCB_BASE_EDIT_FRAME &editFrame)
 
void Invoke ()
 

Protected Attributes

PCB_BASE_FRAMEm_parent
 

Private Member Functions

int getNumberOfItemsToArray () const override
 
BOARD_ITEMgetNthItemToArray (int n) const override
 
BOARDgetBoard () const override
 
MODULEgetModule () const override
 
wxPoint getRotationCentre () const override
 
void finalise () override
 

Private Attributes

BOARD_ITEMm_item
 

Detailed Description

Definition at line 1631 of file edit.cpp.

Constructor & Destructor Documentation

LEGACY_ARRAY_CREATOR::LEGACY_ARRAY_CREATOR ( PCB_BASE_EDIT_FRAME editFrame)
inline

Definition at line 1635 of file edit.cpp.

1635  :
1636  ARRAY_CREATOR( editFrame ),
1638  {}
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected BOARD_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: pcb_screen.h:72
BOARD_ITEM * m_item
Definition: edit.cpp:1674
ARRAY_CREATOR(PCB_BASE_FRAME &parent)
Definition: array_creator.h:49
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.

Member Function Documentation

void LEGACY_ARRAY_CREATOR::finalise ( )
inlineoverrideprivatevirtual

Actions to perform after the array process is complete

Implements ARRAY_CREATOR.

Definition at line 1669 of file edit.cpp.

1670  {
1671  m_parent.GetCanvas()->Refresh();
1672  }
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:388
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
BOARD* LEGACY_ARRAY_CREATOR::getBoard ( ) const
inlineoverrideprivatevirtual

Get the BOARD that is currently being edited.

Implements ARRAY_CREATOR.

Definition at line 1654 of file edit.cpp.

References BOARD_ITEM::GetBoard().

1655  {
1656  return m_parent.GetBoard();
1657  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD * GetBoard() const
MODULE* LEGACY_ARRAY_CREATOR::getModule ( ) const
inlineoverrideprivatevirtual

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

Implements ARRAY_CREATOR.

Definition at line 1659 of file edit.cpp.

1660  {
1661  return dynamic_cast<MODULE*>( m_item->GetParent() );
1662  }
BOARD_ITEM_CONTAINER * GetParent() const
BOARD_ITEM * m_item
Definition: edit.cpp:1674
BOARD_ITEM* LEGACY_ARRAY_CREATOR::getNthItemToArray ( int  n) const
inlineoverrideprivatevirtual
Returns
the n'th original item to be arrayed

Implements ARRAY_CREATOR.

Definition at line 1648 of file edit.cpp.

1649  {
1650  wxASSERT_MSG( n == 0, "Legacy array tool can only handle a single item" );
1651  return m_item;
1652  }
BOARD_ITEM * m_item
Definition: edit.cpp:1674
int LEGACY_ARRAY_CREATOR::getNumberOfItemsToArray ( ) const
inlineoverrideprivatevirtual
Returns
number of original items to put into an array (eg size of the selection)

Implements ARRAY_CREATOR.

Definition at line 1642 of file edit.cpp.

1643  {
1644  // only handle single items
1645  return (m_item != NULL) ? 1 : 0;
1646  }
BOARD_ITEM * m_item
Definition: edit.cpp:1674
wxPoint LEGACY_ARRAY_CREATOR::getRotationCentre ( ) const
inlineoverrideprivatevirtual
Returns
the rotation centre of all the items to be arrayed, when taken together

Implements ARRAY_CREATOR.

Definition at line 1664 of file edit.cpp.

1665  {
1666  return m_item->GetCenter();
1667  }
virtual const wxPoint GetCenter() const
Function GetCenter()
BOARD_ITEM * m_item
Definition: edit.cpp:1674
void ARRAY_CREATOR::Invoke ( )
inherited

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(), ARRAY_CREATOR::finalise(), DIALOG_CREATE_ARRAY::GetArrayOptions(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::GetArraySize(), ARRAY_CREATOR::getBoard(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::GetItemNumber(), ARRAY_CREATOR::getModule(), ARRAY_CREATOR::getNthItemToArray(), ARRAY_CREATOR::getNumberOfItemsToArray(), ARRAY_CREATOR::getRotationCentre(), i, D_PAD::IsAperturePad(), ARRAY_CREATOR::m_parent, DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::NumberingStartIsSpecified(), PCB_MODULE_T, PCB_PAD_T, ARRAY_CREATOR::postPushAction(), ARRAY_CREATOR::prePushAction(), BOARD_COMMIT::Push(), D_PAD::SetName(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::ShouldNumberItems(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::TransformItem(), and EDA_ITEM::Type().

Referenced by ARRAY_CREATOR::ARRAY_CREATOR(), and 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  new_item = getBoard()->Duplicate( item );
83 
84  // Incrementing the reference number won't always be correct, but leaving
85  // it the same is always incorrect.
86  if( new_item->Type() == PCB_MODULE_T )
87  static_cast<MODULE*>( new_item )->IncrementReference( ptN );
88 
89  // @TODO: we should merge zones. This is a bit tricky, because
90  // the undo command needs saving old area, if it is merged.
91  }
92 
93  if( new_item )
94  {
95  array_opts->TransformItem( ptN, new_item, rotPoint );
96  prePushAction( new_item );
97  commit.Add( new_item );
98  postPushAction( new_item );
99  }
100 
101  // attempt to renumber items if the array parameters define
102  // a complete numbering scheme to number by (as opposed to
103  // implicit numbering by incrementing the items during creation
104  if( new_item && array_opts->NumberingStartIsSpecified() )
105  {
106  // Renumber non-aperture pads.
107  if( new_item->Type() == PCB_PAD_T )
108  {
109  D_PAD* pad = static_cast<D_PAD*>( new_item );
110 
111  if( !pad->IsAperturePad() )
112  pad->SetName( array_opts->GetItemNumber( ptN ) );
113  }
114  }
115  }
116  }
117 
118  commit.Push( _( "Create an array" ) );
119  finalise();
120 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
bool IsAperturePad() const
Definition: class_pad.h:409
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:90
virtual MODULE * getModule() const =0
class MODULE, a footprint
Definition: typeinfo.h:89
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:182
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
size_t i
Definition: json11.cpp:597
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)

Member Data Documentation

BOARD_ITEM* LEGACY_ARRAY_CREATOR::m_item
private

Definition at line 1674 of file edit.cpp.

PCB_BASE_FRAME& ARRAY_CREATOR::m_parent
protectedinherited

Definition at line 61 of file array_creator.h.

Referenced by ARRAY_CREATOR::Invoke().


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