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 1597 of file edit.cpp.

Constructor & Destructor Documentation

◆ LEGACY_ARRAY_CREATOR()

LEGACY_ARRAY_CREATOR::LEGACY_ARRAY_CREATOR ( PCB_BASE_EDIT_FRAME editFrame)
inline

Definition at line 1601 of file edit.cpp.

1601  :
1602  ARRAY_CREATOR( editFrame ),
1604  {}
BOARD_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected BOARD_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: pcb_screen.h:72
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD_ITEM * m_item
Definition: edit.cpp:1640
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

◆ finalise()

void LEGACY_ARRAY_CREATOR::finalise ( )
inlineoverrideprivatevirtual

Actions to perform after the array process is complete

Implements ARRAY_CREATOR.

Definition at line 1635 of file edit.cpp.

1636  {
1637  m_parent.GetCanvas()->Refresh();
1638  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:399
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)

References EDA_DRAW_FRAME::GetCanvas(), ARRAY_CREATOR::m_parent, and EDA_DRAW_PANEL::Refresh().

◆ getBoard()

BOARD* LEGACY_ARRAY_CREATOR::getBoard ( ) const
inlineoverrideprivatevirtual

Get the BOARD that is currently being edited.

Implements ARRAY_CREATOR.

Definition at line 1620 of file edit.cpp.

1621  {
1622  return m_parent.GetBoard();
1623  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD * GetBoard() const

References PCB_BASE_FRAME::GetBoard(), and ARRAY_CREATOR::m_parent.

◆ getModule()

MODULE* LEGACY_ARRAY_CREATOR::getModule ( ) const
inlineoverrideprivatevirtual

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

Implements ARRAY_CREATOR.

Definition at line 1625 of file edit.cpp.

1626  {
1627  return dynamic_cast<MODULE*>( m_item->GetParent() );
1628  }
BOARD_ITEM * m_item
Definition: edit.cpp:1640
BOARD_ITEM_CONTAINER * GetParent() const

References BOARD_ITEM::GetParent(), and m_item.

◆ getNthItemToArray()

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 1614 of file edit.cpp.

1615  {
1616  wxASSERT_MSG( n == 0, "Legacy array tool can only handle a single item" );
1617  return m_item;
1618  }
BOARD_ITEM * m_item
Definition: edit.cpp:1640

References m_item.

◆ getNumberOfItemsToArray()

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 1608 of file edit.cpp.

1609  {
1610  // only handle single items
1611  return (m_item != NULL) ? 1 : 0;
1612  }
BOARD_ITEM * m_item
Definition: edit.cpp:1640

References m_item.

◆ getRotationCentre()

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 1630 of file edit.cpp.

1631  {
1632  return m_item->GetCenter();
1633  }
BOARD_ITEM * m_item
Definition: edit.cpp:1640
virtual const wxPoint GetCenter() const
Function GetCenter()

References BOARD_ITEM::GetCenter(), and m_item.

◆ Invoke()

void ARRAY_CREATOR::Invoke ( )
inherited

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  // PCB items keep the same numbering
116 
117  // @TODO: renumber modules if asked. This needs UI to enable.
118  // something like this, but needs a "block offset" to prevent
119  // multiple selections overlapping.
120  // if( new_item->Type() == PCB_MODULE_T )
121  // static_cast<MODULE&>( *new_item ).IncrementReference( ptN );
122 
123  // @TODO: we should merge zones. This is a bit tricky, because
124  // the undo command needs saving old area, if it is merged.
125  }
126 
127  this_item = new_item.get();
128 
129  if( new_item )
130  {
131  prePushAction( this_item );
132  commit.Add( new_item.release() );
133  postPushAction( this_item );
134  }
135  }
136 
137  // always transform the item
138  if( this_item )
139  {
140  commit.Modify( this_item );
141  TransformItem( *array_opts, ptN, *this_item );
142  }
143 
144  // attempt to renumber items if the array parameters define
145  // a complete numbering scheme to number by (as opposed to
146  // implicit numbering by incrementing the items during creation
147  if( this_item && array_opts->ShouldNumberItems() )
148  {
149  // Renumber non-aperture pads.
150  if( this_item->Type() == PCB_PAD_T )
151  {
152  auto& pad = static_cast<D_PAD&>( *this_item );
153 
154  if( PAD_NAMING::PadCanHaveName( pad ) )
155  {
156  wxString newName = pad_name_provider.GetNextPadName();
157  pad.SetName( newName );
158  }
159  }
160  }
161  }
162  }
163 
164  commit.Push( _( "Create an array" ) );
165  finalise();
166 }
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
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:204

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

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

Member Data Documentation

◆ m_item

BOARD_ITEM* LEGACY_ARRAY_CREATOR::m_item
private

◆ m_parent

PCB_BASE_FRAME& ARRAY_CREATOR::m_parent
protectedinherited

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