7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 14:50:11 +00:00

Array: add option to centre grid on the original location

Especially for SMD footprint array, it's awkward to have to
offset the pad to the corner first before making the array.

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/16882
This commit is contained in:
John Beard 2024-10-27 22:13:44 +08:00
parent 3ad92bc8db
commit b931dc5299
7 changed files with 485 additions and 294 deletions

View File

@ -49,7 +49,7 @@ VECTOR2I ARRAY_GRID_OPTIONS::getGridCoords( int n ) const
}
ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform( int n, const VECTOR2I& aPos ) const
VECTOR2I ARRAY_GRID_OPTIONS::gtItemPosRelativeToItem0( int n ) const
{
VECTOR2I point;
@ -74,7 +74,25 @@ ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform( int n, const VECTOR2I
point += stagger_delta * copysign( stagger_idx, m_stagger ) / stagger;
}
// this is already relative to the first array entry
return point;
}
ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform( int n, const VECTOR2I& aPos ) const
{
VECTOR2I point = gtItemPosRelativeToItem0( n );
// Bump the item by half the array size
if( m_centred )
{
// Get the array extents
const int arrayExtentX = ( m_nx - 1 ) * m_delta.x + ( m_ny - 1 ) * m_offset.x;
const int arrayExtentY = ( m_ny - 1 ) * m_delta.y + ( m_nx - 1 ) * m_offset.y;
std::cout << "Subtracting " << VECTOR2I( arrayExtentX, arrayExtentY ) / 2 << std::endl;
point -= VECTOR2I( arrayExtentX, arrayExtentY ) / 2;
}
return { point, ANGLE_0 };
}

View File

@ -145,6 +145,7 @@ struct KICOMMON_API ARRAY_GRID_OPTIONS : public ARRAY_OPTIONS
{
ARRAY_GRID_OPTIONS()
: ARRAY_OPTIONS( ARRAY_GRID ),
m_centred( false ),
m_nx( 0 ),
m_ny( 0 ),
m_horizontalThenVertical( true ),
@ -155,6 +156,8 @@ struct KICOMMON_API ARRAY_GRID_OPTIONS : public ARRAY_OPTIONS
{
}
// Are the grid positions relative to item (0, 0), or the grid center?
bool m_centred;
long m_nx, m_ny;
bool m_horizontalThenVertical, m_reverseNumberingAlternate;
VECTOR2I m_delta;
@ -169,6 +172,7 @@ struct KICOMMON_API ARRAY_GRID_OPTIONS : public ARRAY_OPTIONS
wxString GetItemNumber( int n ) const override;
private:
VECTOR2I gtItemPosRelativeToItem0( int n ) const;
VECTOR2I getGridCoords( int n ) const;
};

View File

@ -44,6 +44,8 @@ static void TransformItem( const ARRAY_OPTIONS& aArrOpts, int aIndex, BOARD_ITEM
{
const ARRAY_OPTIONS::TRANSFORM transform = aArrOpts.GetTransform( aIndex, aItem.GetPosition() );
std::cout << "Offset for item " << aIndex << ": " << transform.m_offset << std::endl;
aItem.Move( transform.m_offset );
aItem.Rotate( aItem.GetPosition(), transform.m_rotation );
}
@ -80,8 +82,9 @@ void ARRAY_CREATOR::Invoke()
EDA_ITEMS all_added_items;
// The first item in list is the original item. We do not modify it
for( int ptN = 0; ptN < array_opts->GetArraySize(); ptN++ )
// Iterate in reverse so the original items go last, and we can
// use them for the positions of the clones.
for( int ptN = array_opts->GetArraySize() - 1; ptN >= 0; --ptN )
{
PCB_SELECTION items_for_this_block;
std::set<FOOTPRINT*> fpDeDupe;

View File

@ -50,6 +50,7 @@ struct CREATE_ARRAY_DIALOG_ENTRIES
m_GridOffsetY( 0 ),
m_GridStagger( 1 ),
m_GridStaggerRows( true ),
m_GridPositionCentreOnItems( true ),
m_GridNumberingAxis( 0 ), // h then v
m_GridNumReverseAlt( false ),
m_GridNumStartSet( 1 ), // use specified start
@ -76,24 +77,25 @@ struct CREATE_ARRAY_DIALOG_ENTRIES
bool m_OptionsSet;
long m_GridNx;
long m_GridNy;
long m_GridDx;
long m_GridDy;
long m_GridOffsetX;
long m_GridOffsetY;
long m_GridStagger;
bool m_GridStaggerRows;
long m_GridNumberingAxis;
bool m_GridNumReverseAlt;
long m_GridNumStartSet;
long m_Grid2dArrayNumbering;
long m_GridPrimaryAxisScheme;
long m_GridSecondaryAxisScheme;
wxString m_GridPrimaryNumOffset;
wxString m_GridSecondaryNumOffset;
long m_GridPrimaryAxisStep;
long m_GridSecondaryAxisStep;
long m_GridNx;
long m_GridNy;
long m_GridDx;
long m_GridDy;
long m_GridOffsetX;
long m_GridOffsetY;
long m_GridStagger;
bool m_GridStaggerRows;
bool m_GridPositionCentreOnItems;
long m_GridNumberingAxis;
bool m_GridNumReverseAlt;
long m_GridNumStartSet;
long m_Grid2dArrayNumbering;
long m_GridPrimaryAxisScheme;
long m_GridSecondaryAxisScheme;
wxString m_GridPrimaryNumOffset;
wxString m_GridSecondaryNumOffset;
long m_GridPrimaryAxisStep;
long m_GridSecondaryAxisStep;
long m_CircCentreX;
long m_CircCentreY;
@ -202,6 +204,8 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent,
m_cfg_persister.Add( *m_staggerRows, s_arrayOptions.m_GridStaggerRows );
m_cfg_persister.Add( *m_rbCentreOnSource, s_arrayOptions.m_GridPositionCentreOnItems );
m_cfg_persister.Add( *m_radioBoxGridNumberingAxis, s_arrayOptions.m_GridNumberingAxis );
m_cfg_persister.Add( *m_checkBoxGridReverseNumbering, s_arrayOptions.m_GridNumReverseAlt );
@ -391,6 +395,8 @@ bool DIALOG_CREATE_ARRAY::TransferDataFromWindow()
newGrid->m_offset.x = m_hOffset.GetIntValue();
newGrid->m_offset.y = m_vOffset.GetIntValue();
newGrid->m_centred = m_rbCentreOnSource->GetValue();
ok &= validateLongEntry(*m_entryStagger, newGrid->m_stagger, _("stagger"), errors);
newGrid->m_stagger_rows = m_staggerRows->GetValue();

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf02)
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -171,6 +171,18 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID
bSizerGridLeft->Add( sbSizerStagger, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 );
wxStaticBoxSizer* sbGridPosition;
sbGridPosition = new wxStaticBoxSizer( new wxStaticBox( m_gridPanel, wxID_ANY, _("Grid Position") ), wxVERTICAL );
m_rbItemsRemainInPlace = new wxRadioButton( sbGridPosition->GetStaticBox(), wxID_ANY, _("Source items remain in place"), wxDefaultPosition, wxDefaultSize, 0 );
sbGridPosition->Add( m_rbItemsRemainInPlace, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
m_rbCentreOnSource = new wxRadioButton( sbGridPosition->GetStaticBox(), wxID_ANY, _("Centre on source items"), wxDefaultPosition, wxDefaultSize, 0 );
sbGridPosition->Add( m_rbCentreOnSource, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
bSizerGridLeft->Add( sbGridPosition, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 10 );
bSizerGridArray->Add( bSizerGridLeft, 1, wxEXPAND, 5 );
@ -275,7 +287,7 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID
m_gridPanel->SetSizer( bSizerGridArray );
m_gridPanel->Layout();
bSizerGridArray->Fit( m_gridPanel );
m_gridTypeNotebook->AddPage( m_gridPanel, _("Grid Array"), false );
m_gridTypeNotebook->AddPage( m_gridPanel, _("Grid Array"), true );
m_circularPanel = new wxPanel( m_gridTypeNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxHORIZONTAL );
@ -286,7 +298,7 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID
wxStaticBoxSizer* sbSizerInfo;
sbSizerInfo = new wxStaticBoxSizer( new wxStaticBox( m_circularPanel, wxID_ANY, _("Reference Position") ), wxVERTICAL );
m_stInfoItems = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("Position of the selected item (or group) to duplicate"), wxDefaultPosition, wxDefaultSize, 0 );
m_stInfoItems = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("Position of the selected item (or group) to duplicate"), wxDefaultPosition, wxDefaultSize, 0 );
m_stInfoItems->Wrap( -1 );
sbSizerInfo->Add( m_stInfoItems, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
@ -541,7 +553,7 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID
m_circularPanel->SetSizer( bSizer4 );
m_circularPanel->Layout();
bSizer4->Fit( m_circularPanel );
m_gridTypeNotebook->AddPage( m_circularPanel, _("Circular Array"), true );
m_gridTypeNotebook->AddPage( m_circularPanel, _("Circular Array"), false );
bSizer7->Add( m_gridTypeNotebook, 1, wxALL|wxEXPAND, 10 );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf02)
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -36,7 +36,7 @@ class TEXT_CTRL_EVAL;
///////////////////////////////////////////////////////////////////////////
#define wxID_DIALOG_CREATE_ARRAY 1000
#define wxID_DIALOG_CREATE_ARRAY 10000
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_CREATE_ARRAY_BASE
@ -68,6 +68,8 @@ class DIALOG_CREATE_ARRAY_BASE : public DIALOG_SHIM
TEXT_CTRL_EVAL* m_entryStagger;
wxRadioButton* m_staggerRows;
wxRadioButton* m_staggerCols;
wxRadioButton* m_rbItemsRemainInPlace;
wxRadioButton* m_rbCentreOnSource;
wxPanel* m_gridPadNumberingPanel;
wxBoxSizer* m_gridPadNumberingSizer;
wxRadioBox* m_radioBoxGridNumberingAxis;