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 *new_item) override
 
void postPushAction (BOARD_ITEM *new_item) override
 
void finalise () override
 

Private Attributes

bool m_editModules
 
const SELECTIONm_selection
 

Detailed Description

Definition at line 834 of file edit_tool.cpp.

Constructor & Destructor Documentation

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

Definition at line 838 of file edit_tool.cpp.

839  :
840  ARRAY_CREATOR( editFrame ),
841  m_editModules( editModules ),
842  m_selection( selection )
843  {}
const SELECTION & m_selection
Definition: edit_tool.cpp:891
ARRAY_CREATOR(PCB_BASE_FRAME &parent)
Definition: array_creator.h:49

Member Function Documentation

void GAL_ARRAY_CREATOR::finalise ( )
inlineoverrideprivatevirtual

Actions to perform after the array process is complete

Implements ARRAY_CREATOR.

Definition at line 886 of file edit_tool.cpp.

887  {
888  }
BOARD* GAL_ARRAY_CREATOR::getBoard ( ) const
inlineoverrideprivatevirtual

Get the BOARD that is currently being edited.

Implements ARRAY_CREATOR.

Definition at line 858 of file edit_tool.cpp.

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

859  {
860  return m_parent.GetBoard();
861  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD * GetBoard() const
MODULE* GAL_ARRAY_CREATOR::getModule ( ) const
inlineoverrideprivatevirtual

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

Implements ARRAY_CREATOR.

Definition at line 863 of file edit_tool.cpp.

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

864  {
865  // Remember this is valid and used only in the module editor.
866  // in board editor, the parent of items is usually the board.
867  return m_editModules ? m_parent.GetBoard()->m_Modules.GetFirst() : NULL;
868  }
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
BOARD * GetBoard() const
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:243
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 853 of file edit_tool.cpp.

References m_selection.

854  {
855  return static_cast<BOARD_ITEM*>( m_selection[n] );
856  }
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:891
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 847 of file edit_tool.cpp.

References m_selection, and SELECTION::Size().

848  {
849  // only handle single items
850  return m_selection.Size();
851  }
const SELECTION & m_selection
Definition: edit_tool.cpp:891
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
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 870 of file edit_tool.cpp.

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

871  {
872  const VECTOR2I rp = m_selection.GetCenter();
873  return wxPoint( rp.x, rp.y );
874  }
const SELECTION & m_selection
Definition: edit_tool.cpp:891
VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
void ARRAY_CREATOR::Invoke ( )
inherited

Open the dialog, gather parameters and create the array

Definition at line 36 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(), ARRAY_CREATOR::m_parent, DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::NumberingStartIsSpecified(), PCB_PAD_T, ARRAY_CREATOR::postPushAction(), ARRAY_CREATOR::prePushAction(), BOARD_COMMIT::Push(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::ShouldNumberItems(), DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::TransformItem(), and EDA_ITEM::Type().

Referenced by PCB_BASE_EDIT_FRAME::createArray().

37 {
38  const int numItems = getNumberOfItemsToArray();
39 
40  // bail out if no items
41  if( numItems == 0 )
42  return;
43 
44  BOARD_COMMIT commit( &m_parent );
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  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  // PCB items keep the same numbering
83  new_item = getBoard()->Duplicate( item );
84 
85  // @TODO: we should merge zones. This is a bit tricky, because
86  // the undo command needs saving old area, if it is merged.
87  }
88 
89  if( new_item )
90  {
91  array_opts->TransformItem( ptN, new_item, rotPoint );
92  prePushAction( new_item );
93  commit.Add( new_item );
94  postPushAction( new_item );
95  }
96 
97  // attempt to renumber items if the array parameters define
98  // a complete numbering scheme to number by (as opposed to
99  // implicit numbering by incrementing the items during creation
100  if( new_item && array_opts->NumberingStartIsSpecified() )
101  {
102  // Renumber pads. Only new pad number renumbering has meaning,
103  // in the footprint editor.
104  if( new_item->Type() == PCB_PAD_T )
105  {
106  const wxString padName = array_opts->GetItemNumber( ptN );
107  static_cast<D_PAD*>( new_item )->SetPadName( padName );
108  }
109  }
110  }
111  }
112 
113  commit.Push( _( "Create an array" ) );
114  finalise();
115 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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:102
virtual MODULE * getModule() const =0
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
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)
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 882 of file edit_tool.cpp.

883  {
884  }
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 876 of file edit_tool.cpp.

References EDA_DRAW_FRAME::GetToolManager(), ARRAY_CREATOR::m_parent, TOOL_MANAGER::RunAction(), and PCB_ACTIONS::unselectItem.

877  {
879  true, new_item );
880  }
static TOOL_ACTION unselectItem
Unselects an item (specified as the event parameter).
Definition: pcb_actions.h:59
PCB_BASE_FRAME & m_parent
Definition: array_creator.h:61
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:810

Member Data Documentation

bool GAL_ARRAY_CREATOR::m_editModules
private

Definition at line 890 of file edit_tool.cpp.

Referenced by getModule().

PCB_BASE_FRAME& ARRAY_CREATOR::m_parent
protectedinherited
const SELECTION& GAL_ARRAY_CREATOR::m_selection
private

Definition at line 891 of file edit_tool.cpp.

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


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