KiCad PCB EDA Suite
ARRAY_CREATOR Class Reference

#include <array_creator.h>

Public Member Functions

 ARRAY_CREATOR (PCB_BASE_FRAME &aParent, bool editModules, const PCBNEW_SELECTION &aSelection)
 
virtual ~ARRAY_CREATOR ()
 
void Invoke ()
 

Private Attributes

PCB_BASE_FRAMEm_parent
 
bool m_editModules
 
const PCBNEW_SELECTIONm_selection
 

Detailed Description

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

Definition at line 39 of file array_creator.h.

Constructor & Destructor Documentation

◆ ARRAY_CREATOR()

ARRAY_CREATOR::ARRAY_CREATOR ( PCB_BASE_FRAME aParent,
bool  editModules,
const PCBNEW_SELECTION aSelection 
)
inline

Definition at line 42 of file array_creator.h.

42  :
43  m_parent( aParent ),
44  m_editModules( editModules ),
45  m_selection( aSelection )
46  {}
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:56
const PCBNEW_SELECTION & m_selection
Definition: array_creator.h:58

◆ ~ARRAY_CREATOR()

virtual ARRAY_CREATOR::~ARRAY_CREATOR ( )
inlinevirtual

Definition at line 48 of file array_creator.h.

48 {}

Member Function Documentation

◆ Invoke()

void ARRAY_CREATOR::Invoke ( )

Open the dialog, gather parameters and create the array

Definition at line 49 of file array_creator.cpp.

50 {
51  // bail out if no items
52  if( m_selection.Size() == 0 )
53  return;
54 
55  MODULE* const module = m_editModules ? m_parent.GetBoard()->GetFirstModule() : nullptr;
56 
57  const bool enableArrayNumbering = m_editModules;
58  const wxPoint rotPoint = (wxPoint) m_selection.GetCenter();
59 
60  std::unique_ptr<ARRAY_OPTIONS> array_opts;
61 
62  DIALOG_CREATE_ARRAY dialog( &m_parent, array_opts, enableArrayNumbering, rotPoint );
63 
64  int ret = dialog.ShowModal();
65 
66  if( ret != wxID_OK || array_opts == NULL )
67  return;
68 
69  BOARD_COMMIT commit( &m_parent );
70 
71  ARRAY_PAD_NAME_PROVIDER pad_name_provider( module, *array_opts );
72 
73  for ( int i = 0; i < m_selection.Size(); ++i )
74  {
75  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_selection[ i ] );
76 
77  if( item->Type() == PCB_PAD_T && !m_editModules )
78  {
79  // If it is not the module editor, then duplicate the parent module instead
80  item = static_cast<MODULE*>( item )->GetParent();
81  }
82 
83  // The first item in list is the original item. We do not modify it
84  for( int ptN = 0; ptN < array_opts->GetArraySize(); ptN++ )
85  {
86  BOARD_ITEM* this_item;
87 
88  if( ptN == 0 )
89  {
90  // the first point: we don't own this or add it, but
91  // we might still modify it (position or label)
92  this_item = item;
93  }
94  else
95  {
96  // Need to create a new item
97  std::unique_ptr<BOARD_ITEM> new_item;
98 
99  if( m_editModules )
100  {
101  // Don't bother incrementing pads: the module won't update
102  // until commit, so we can only do this once
103  new_item.reset( module->Duplicate( item, false ) );
104  }
105  else
106  {
107  new_item.reset( m_parent.GetBoard()->Duplicate( item ) );
108 
109  // PCB items keep the same numbering
110 
111  // @TODO: renumber modules if asked. This needs UI to enable.
112  // something like this, but needs a "block offset" to prevent
113  // multiple selections overlapping.
114  // if( new_item->Type() == PCB_MODULE_T )
115  // static_cast<MODULE&>( *new_item ).IncrementReference( ptN );
116 
117  // @TODO: we should merge zones. This is a bit tricky, because
118  // the undo command needs saving old area, if it is merged.
119  }
120 
121  this_item = new_item.get();
122 
123  if( new_item )
124  {
125  // Because aItem is/can be created from a selected item, and inherits from
126  // it this state, reset the selected stated of aItem:
127  this_item->ClearSelected();
128 
129  if( this_item->Type() == PCB_MODULE_T )
130  {
131  static_cast<MODULE*>( this_item )->RunOnChildren( [&] ( BOARD_ITEM* aItem )
132  {
133  aItem->ClearSelected();
134  });
135  }
136 
137  commit.Add( new_item.release() );
138  }
139  }
140 
141  // always transform the item
142  if( this_item )
143  {
144  commit.Modify( this_item );
145  TransformItem( *array_opts, ptN, *this_item );
146  }
147 
148  // attempt to renumber items if the array parameters define
149  // a complete numbering scheme to number by (as opposed to
150  // implicit numbering by incrementing the items during creation
151  if( this_item && array_opts->ShouldNumberItems() )
152  {
153  // Renumber non-aperture pads.
154  if( this_item->Type() == PCB_PAD_T )
155  {
156  auto& pad = static_cast<D_PAD&>( *this_item );
157 
158  if( PAD_NAMING::PadCanHaveName( pad ) )
159  {
160  wxString newName = pad_name_provider.GetNextPadName();
161  pad.SetName( newName );
162  }
163  }
164  }
165  }
166  }
167 
168  commit.Push( _( "Create an array" ) );
169 }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void ClearSelected()
Definition: base_struct.h:243
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.h:136
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.
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:56
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
Simple class that sequentially provides names from an ARRAY_OPTIONS object, making sure that they do ...
class MODULE, a footprint
Definition: typeinfo.h:89
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:285
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.
#define _(s)
size_t i
Definition: json11.cpp:597
int Size() const
Returns the number of selected parts.
Definition: selection.h:125
BOARD * GetBoard() const
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aAddToBoard=false)
const PCBNEW_SELECTION & m_selection
Definition: array_creator.h:58

References _, COMMIT::Add(), EDA_ITEM::ClearSelected(), BOARD::Duplicate(), MODULE::Duplicate(), PCB_BASE_FRAME::GetBoard(), SELECTION::GetCenter(), BOARD::GetFirstModule(), ARRAY_PAD_NAME_PROVIDER::GetNextPadName(), BOARD_ITEM::GetParent(), i, m_editModules, m_parent, m_selection, COMMIT::Modify(), PAD_NAMING::PadCanHaveName(), PCB_MODULE_T, PCB_PAD_T, BOARD_COMMIT::Push(), SELECTION::Size(), TransformItem(), and EDA_ITEM::Type().

Referenced by EDIT_TOOL::CreateArray().

Member Data Documentation

◆ m_editModules

bool ARRAY_CREATOR::m_editModules
private

Definition at line 57 of file array_creator.h.

Referenced by Invoke().

◆ m_parent

PCB_BASE_FRAME& ARRAY_CREATOR::m_parent
private

Definition at line 56 of file array_creator.h.

Referenced by Invoke().

◆ m_selection

const PCBNEW_SELECTION& ARRAY_CREATOR::m_selection
private

Definition at line 58 of file array_creator.h.

Referenced by Invoke().


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