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

Public Member Functions

 GAL_ARRAY_CREATOR (PCB_BASE_FRAME &editFrame, bool editModules, const SELECTION &selection)
 
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 prePushAction (BOARD_ITEM *aItem) override
 
void postPushAction (BOARD_ITEM *new_item) override
 
void finalise () override
 

Private Attributes

bool m_editModules
 
const SELECTIONm_selection
 

Detailed Description

Definition at line 1145 of file edit_tool.cpp.

Constructor & Destructor Documentation

◆ GAL_ARRAY_CREATOR()

GAL_ARRAY_CREATOR::GAL_ARRAY_CREATOR ( PCB_BASE_FRAME editFrame,
bool  editModules,
const SELECTION selection 
)
inline

Definition at line 1149 of file edit_tool.cpp.

1150  :
1151  ARRAY_CREATOR( editFrame ),
1152  m_editModules( editModules ),
1153  m_selection( selection )
1154  {}
const SELECTION & m_selection
Definition: edit_tool.cpp:1212
ARRAY_CREATOR(PCB_BASE_FRAME &parent)
Definition: array_creator.h:49

Member Function Documentation

◆ finalise()

void GAL_ARRAY_CREATOR::finalise ( )
inlineoverrideprivatevirtual

Actions to perform after the array process is complete

Implements ARRAY_CREATOR.

Definition at line 1207 of file edit_tool.cpp.

1208  {
1209  }

◆ getBoard()

BOARD* GAL_ARRAY_CREATOR::getBoard ( ) const
inlineoverrideprivatevirtual

Get the BOARD that is currently being edited.

Implements ARRAY_CREATOR.

Definition at line 1169 of file edit_tool.cpp.

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

1170  {
1171  return m_parent.GetBoard();
1172  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD * GetBoard() const

◆ getModule()

MODULE* GAL_ARRAY_CREATOR::getModule ( ) const
inlineoverrideprivatevirtual

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

Implements ARRAY_CREATOR.

Definition at line 1174 of file edit_tool.cpp.

References PCB_BASE_FRAME::GetBoard(), DLIST< T >::GetFirst(), m_editModules, BOARD::m_Modules, and ARRAY_CREATOR::m_parent.

1175  {
1176  // Remember this is valid and used only in the module editor.
1177  // in board editor, the parent of items is usually the board.
1178  return m_editModules ? m_parent.GetBoard()->m_Modules.GetFirst() : NULL;
1179  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
DLIST< MODULE > m_Modules
Definition: class_board.h:249
BOARD * GetBoard() const

◆ getNthItemToArray()

BOARD_ITEM* GAL_ARRAY_CREATOR::getNthItemToArray ( int  n) const
inlineoverrideprivatevirtual
Returns
the n'th original item to be arrayed

Implements ARRAY_CREATOR.

Definition at line 1164 of file edit_tool.cpp.

References m_selection.

1165  {
1166  return static_cast<BOARD_ITEM*>( m_selection[n] );
1167  }
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
const SELECTION & m_selection
Definition: edit_tool.cpp:1212

◆ getNumberOfItemsToArray()

int GAL_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 1158 of file edit_tool.cpp.

References m_selection, and SELECTION::Size().

1159  {
1160  // only handle single items
1161  return m_selection.Size();
1162  }
const SELECTION & m_selection
Definition: edit_tool.cpp:1212
int Size() const
Returns the number of selected parts.
Definition: selection.h:122

◆ getRotationCentre()

wxPoint GAL_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 1181 of file edit_tool.cpp.

References SELECTION::GetCenter(), m_selection, VECTOR2< T >::x, and VECTOR2< T >::y.

1182  {
1183  const VECTOR2I rp = m_selection.GetCenter();
1184  return wxPoint( rp.x, rp.y );
1185  }
VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:67
const SELECTION & m_selection
Definition: edit_tool.cpp:1212

◆ Invoke()

void ARRAY_CREATOR::Invoke ( )
inherited

Open the dialog, gather parameters and create the array

Definition at line 37 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, ARRAY_CREATOR::m_parent, DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::NumberingStartIsSpecified(), PAD_NAMING::PadCanHaveName(), 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 PCB_BASE_EDIT_FRAME::createArray().

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

◆ postPushAction()

void GAL_ARRAY_CREATOR::postPushAction ( BOARD_ITEM new_item)
inlineoverrideprivatevirtual

Perform any actions needed after pushing an item to the BOARD

Reimplemented from ARRAY_CREATOR.

Definition at line 1203 of file edit_tool.cpp.

1204  {
1205  }

◆ prePushAction()

void GAL_ARRAY_CREATOR::prePushAction ( BOARD_ITEM new_item)
inlineoverrideprivatevirtual

Perform any relevant action before pushing a newly created array item to the BOARD

Reimplemented from ARRAY_CREATOR.

Definition at line 1187 of file edit_tool.cpp.

References EDA_ITEM::ClearSelected(), PCB_MODULE_T, and EDA_ITEM::Type().

1188  {
1189  // Because aItem is/can be created from a selected item, and inherits from
1190  // it this state, reset the selected stated of aItem:
1191  aItem->ClearSelected();
1192 
1193  if( aItem->Type() == PCB_MODULE_T )
1194  {
1195  static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
1196  {
1197  item->ClearSelected();
1198  }
1199  );
1200  }
1201  }
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:234
class MODULE, a footprint
Definition: typeinfo.h:89

Member Data Documentation

◆ m_editModules

bool GAL_ARRAY_CREATOR::m_editModules
private

Definition at line 1211 of file edit_tool.cpp.

Referenced by getModule().

◆ m_parent

PCB_BASE_FRAME& ARRAY_CREATOR::m_parent
protectedinherited

◆ m_selection

const SELECTION& GAL_ARRAY_CREATOR::m_selection
private

Definition at line 1212 of file edit_tool.cpp.

Referenced by getNthItemToArray(), getNumberOfItemsToArray(), and getRotationCentre().


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