KiCad PCB EDA Suite
ARRAY_CREATOR Class Reference

#include <array_creator.h>

Public Member Functions

 ARRAY_CREATOR (PCB_BASE_FRAME &aParent, bool aIsFootprintEditor, const PCB_SELECTION &aSelection, TOOL_MANAGER *aToolManager)
 
virtual ~ARRAY_CREATOR ()
 
void Invoke ()
 

Private Attributes

PCB_BASE_FRAMEm_parent
 
bool m_isFootprintEditor
 
const PCB_SELECTION m_selection
 
TOOL_MANAGERm_toolMgr
 

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 41 of file array_creator.h.

Constructor & Destructor Documentation

◆ ARRAY_CREATOR()

ARRAY_CREATOR::ARRAY_CREATOR ( PCB_BASE_FRAME aParent,
bool  aIsFootprintEditor,
const PCB_SELECTION aSelection,
TOOL_MANAGER aToolManager 
)
inline

Definition at line 44 of file array_creator.h.

45  :
46  m_parent( aParent ),
47  m_isFootprintEditor( aIsFootprintEditor ),
48  m_selection( aSelection ),
49  m_toolMgr( aToolManager )
50  {}
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:60
bool m_isFootprintEditor
Definition: array_creator.h:61
TOOL_MANAGER * m_toolMgr
Definition: array_creator.h:63
const PCB_SELECTION m_selection
Definition: array_creator.h:62

◆ ~ARRAY_CREATOR()

virtual ARRAY_CREATOR::~ARRAY_CREATOR ( )
inlinevirtual

Definition at line 52 of file array_creator.h.

52 {}

Member Function Documentation

◆ Invoke()

void ARRAY_CREATOR::Invoke ( )

Open the dialog, gather parameters and create the array

Definition at line 52 of file array_creator.cpp.

53 {
54  // bail out if no items
55  if( m_selection.Size() == 0 )
56  return;
57 
59 
60  const bool enableArrayNumbering = m_isFootprintEditor;
61  const wxPoint rotPoint = (wxPoint) m_selection.GetCenter();
62 
63  std::unique_ptr<ARRAY_OPTIONS> array_opts;
64 
65  DIALOG_CREATE_ARRAY dialog( &m_parent, array_opts, enableArrayNumbering, rotPoint );
66 
67  int ret = dialog.ShowModal();
68 
69  if( ret != wxID_OK || array_opts == nullptr )
70  return;
71 
72  BOARD_COMMIT commit( &m_parent );
73 
74  ARRAY_PAD_NUMBER_PROVIDER pad_number_provider( fp, *array_opts );
75 
76  std::vector<EDA_ITEM*> all_added_items;
77 
78  // The first item in list is the original item. We do not modify it
79  for( int ptN = 0; ptN < array_opts->GetArraySize(); ptN++ )
80  {
81  PCB_SELECTION items_for_this_block;
82 
83  for ( int i = 0; i < m_selection.Size(); ++i )
84  {
85  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( m_selection[ i ] );
86 
87  if( item->Type() == PCB_PAD_T && !m_isFootprintEditor )
88  {
89  // If it is not the footprint editor, then duplicate the parent footprint instead
90  item = static_cast<FOOTPRINT*>( item )->GetParent();
91  }
92 
93  BOARD_ITEM* this_item = nullptr;
94 
95  if( ptN == 0 )
96  {
97  // the first point: we don't own this or add it, but
98  // we might still modify it (position or label)
99  this_item = item;
100  }
101  else
102  {
103  if( m_isFootprintEditor )
104  {
105  // Don't bother incrementing pads: the footprint won't update until commit,
106  // so we can only do this once
107  this_item = fp->DuplicateItem( item );
108  }
109  else
110  {
111  switch( item->Type() )
112  {
113  case PCB_FOOTPRINT_T:
114  case PCB_SHAPE_T:
115  case PCB_TEXT_T:
116  case PCB_TRACE_T:
117  case PCB_ARC_T:
118  case PCB_VIA_T:
119  case PCB_DIM_ALIGNED_T:
120  case PCB_DIM_CENTER_T:
122  case PCB_DIM_LEADER_T:
123  case PCB_TARGET_T:
124  case PCB_ZONE_T:
125  this_item = item->Duplicate();
126  break;
127 
128  case PCB_GROUP_T:
129  this_item = static_cast<PCB_GROUP*>( item )->DeepDuplicate();
130  break;
131 
132  default:
133  // Silently drop other items (such as footprint texts) from duplication
134  break;
135  }
136 
137  // @TODO: we should merge zones. This is a bit tricky, because
138  // the undo command needs saving old area, if it is merged.
139  }
140 
141  // Add new items to selection (footprints in the selection will be reannotated)
142  items_for_this_block.Add( this_item );
143 
144  if( this_item )
145  {
146  // Because aItem is/can be created from a selected item, and inherits from
147  // it this state, reset the selected stated of aItem:
148  this_item->ClearSelected();
149 
150  if( this_item->Type() == PCB_GROUP_T )
151  {
152  static_cast<PCB_GROUP*>( this_item )->RunOnDescendants(
153  [&]( BOARD_ITEM* aItem )
154  {
155  aItem->ClearSelected();
156  commit.Add( aItem );
157  });
158  }
159  else if( this_item->Type() == PCB_FOOTPRINT_T )
160  {
161  static_cast<FOOTPRINT*>( this_item )->RunOnChildren(
162  [&]( BOARD_ITEM* aItem )
163  {
164  aItem->ClearSelected();
165  });
166  }
167 
168  commit.Add( this_item );
169  }
170  }
171 
172  // always transform the item
173  if( this_item )
174  {
175  commit.Modify( this_item );
176  TransformItem( *array_opts, ptN, *this_item );
177  }
178 
179  // attempt to renumber items if the array parameters define
180  // a complete numbering scheme to number by (as opposed to
181  // implicit numbering by incrementing the items during creation
182  if( this_item && array_opts->ShouldNumberItems() )
183  {
184  // Renumber non-aperture pads.
185  if( this_item->Type() == PCB_PAD_T )
186  {
187  PAD& pad = static_cast<PAD&>( *this_item );
188 
189  if( pad.CanHaveNumber() )
190  {
191  wxString newNumber = pad_number_provider.GetNextPadNumber();
192  pad.SetNumber( newNumber );
193  }
194  }
195  }
196  }
197 
198  if( !m_isFootprintEditor && array_opts->ShouldReannotateFootprints() )
199  {
200  m_toolMgr->GetTool<BOARD_REANNOTATE_TOOL>()->ReannotateDuplicates( items_for_this_block,
201  all_added_items );
202  }
203 
204  for( EDA_ITEM* item : items_for_this_block )
205  all_added_items.push_back( item );
206  }
207 
209  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &all_added_items );
210 
211  commit.Push( _( "Create an array" ) );
212 }
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:66
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
BOARD_ITEM * DuplicateItem(const BOARD_ITEM *aItem, bool aAddToFootprint=false)
Duplicate a given item within the footprint, optionally adding it to the board.
Definition: footprint.cpp:1738
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:71
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
void ClearSelected()
Definition: eda_item.h:131
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:102
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:60
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:318
bool m_isFootprintEditor
Definition: array_creator.h:61
Simple class that sequentially provides numbers from an ARRAY_OPTIONS object, making sure that they d...
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
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.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
TOOL_MANAGER * m_toolMgr
Definition: array_creator.h:63
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:171
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
const PCB_SELECTION m_selection
Definition: array_creator.h:62
BOARD * GetBoard() const
Definition: pad.h:57
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:135
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, COMMIT::Add(), SELECTION::Add(), EDA_ITEM::ClearSelected(), BOARD_ITEM::Duplicate(), FOOTPRINT::DuplicateItem(), PCB_BASE_FRAME::GetBoard(), SELECTION::GetCenter(), BOARD::GetFirstFootprint(), ARRAY_PAD_NUMBER_PROVIDER::GetNextPadNumber(), BOARD_ITEM::GetParent(), TOOL_MANAGER::GetTool(), m_isFootprintEditor, m_parent, m_selection, m_toolMgr, COMMIT::Modify(), pad, PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FOOTPRINT_T, PCB_GROUP_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, BOARD_COMMIT::Push(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItems, SELECTION::Size(), TransformItem(), and EDA_ITEM::Type().

Referenced by EDIT_TOOL::CreateArray().

Member Data Documentation

◆ m_isFootprintEditor

bool ARRAY_CREATOR::m_isFootprintEditor
private

Definition at line 61 of file array_creator.h.

Referenced by Invoke().

◆ m_parent

PCB_BASE_FRAME& ARRAY_CREATOR::m_parent
private

Definition at line 60 of file array_creator.h.

Referenced by Invoke().

◆ m_selection

const PCB_SELECTION ARRAY_CREATOR::m_selection
private

Definition at line 62 of file array_creator.h.

Referenced by Invoke().

◆ m_toolMgr

TOOL_MANAGER* ARRAY_CREATOR::m_toolMgr
private

Definition at line 63 of file array_creator.h.

Referenced by Invoke().


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