Pcbnew: Also transform and number the original item

The original item is part of the array, so give it a number
and put it in the right place (all current array tools have
a null transform for the first item, but it's not part of the
contract. For example, a circular array with an angle offset
might want to move the first point).
This commit is contained in:
John Beard 2019-01-25 21:03:25 +00:00 committed by Seth Hillbrand
parent ffaf99a600
commit 6558bd9381
1 changed files with 43 additions and 23 deletions

View File

@ -87,51 +87,71 @@ void ARRAY_CREATOR::Invoke()
} }
// The first item in list is the original item. We do not modify it // The first item in list is the original item. We do not modify it
for( int ptN = 1; ptN < array_opts->GetArraySize(); ptN++ ) for( int ptN = 0; ptN < array_opts->GetArraySize(); ptN++ )
{ {
BOARD_ITEM* new_item; BOARD_ITEM* this_item;
if( isModuleEditor ) if( ptN == 0 )
{ {
// Don't bother incrementing pads: the module won't update // the first point: we don't own this or add it, but
// until commit, so we can only do this once // we might still modify it (position or label)
new_item = module->Duplicate( item, false ); this_item = item;
} }
else else
{ {
new_item = getBoard()->Duplicate( item ); // Need to create a new item
std::unique_ptr<BOARD_ITEM> new_item;
// Incrementing the reference number won't always be correct, but leaving if( isModuleEditor )
// it the same is always incorrect. {
if( new_item->Type() == PCB_MODULE_T ) // Don't bother incrementing pads: the module won't update
static_cast<MODULE*>( new_item )->IncrementReference( ptN ); // until commit, so we can only do this once
new_item.reset( module->Duplicate( item, false ) );
}
else
{
new_item.reset( getBoard()->Duplicate( item ) );
// @TODO: we should merge zones. This is a bit tricky, because // Incrementing the reference number won't always be correct, but leaving
// the undo command needs saving old area, if it is merged. // it the same is always incorrect.
if( new_item->Type() == PCB_MODULE_T )
static_cast<MODULE&>( *new_item ).IncrementReference( ptN );
// @TODO: we should merge zones. This is a bit tricky, because
// the undo command needs saving old area, if it is merged.
}
this_item = new_item.get();
if( new_item )
{
prePushAction( this_item );
commit.Add( new_item.release() );
postPushAction( this_item );
}
} }
if( new_item ) // always transform the item
if( this_item )
{ {
TransformItem( *array_opts, ptN, *new_item ); commit.Modify( this_item );
prePushAction( new_item ); TransformItem( *array_opts, ptN, *this_item );
commit.Add( new_item );
postPushAction( new_item );
} }
// attempt to renumber items if the array parameters define // attempt to renumber items if the array parameters define
// a complete numbering scheme to number by (as opposed to // a complete numbering scheme to number by (as opposed to
// implicit numbering by incrementing the items during creation // implicit numbering by incrementing the items during creation
if( new_item && array_opts->ShouldNumberItems() ) if( this_item && array_opts->ShouldNumberItems() )
{ {
// Renumber non-aperture pads. // Renumber non-aperture pads.
if( new_item->Type() == PCB_PAD_T ) if( this_item->Type() == PCB_PAD_T )
{ {
D_PAD* pad = static_cast<D_PAD*>( new_item ); auto& pad = static_cast<D_PAD&>( *this_item );
if( PAD_NAMING::PadCanHaveName( *pad ) ) if( PAD_NAMING::PadCanHaveName( pad ) )
{ {
wxString newName = pad_name_provider.GetNextPadName(); wxString newName = pad_name_provider.GetNextPadName();
pad->SetName( newName ); pad.SetName( newName );
} }
} }
} }