Exchange footprints: remove duplicate code, and keep the "Locked" attribute state after exchange/replace.

This commit is contained in:
jean-pierre charras 2015-10-22 18:50:27 +02:00
parent ad10218a58
commit d63c017a0a
6 changed files with 51 additions and 49 deletions

View File

@ -2386,7 +2386,12 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
else else
newFootprint->SetPath( footprint->GetPath() ); newFootprint->SetPath( footprint->GetPath() );
footprint->CopyNetlistSettings( newFootprint ); // Copy placement and pad net names.
// optionally, copy or not local settings (like local clearances)
// if the second param is "true", previous values will be used.
// if "false", default library values will be used
footprint->CopyNetlistSettings( newFootprint, true );
Remove( footprint ); Remove( footprint );
Add( newFootprint, ADD_APPEND ); Add( newFootprint, ADD_APPEND );
footprint = newFootprint; footprint = newFootprint;

View File

@ -377,7 +377,7 @@ BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem )
} }
void MODULE::CopyNetlistSettings( MODULE* aModule ) void MODULE::CopyNetlistSettings( MODULE* aModule, bool aCopyLocalSettings )
{ {
// Don't do anything foolish like trying to copy to yourself. // Don't do anything foolish like trying to copy to yourself.
wxCHECK_RET( aModule != NULL && aModule != this, wxT( "Cannot copy to NULL or yourself." ) ); wxCHECK_RET( aModule != NULL && aModule != this, wxT( "Cannot copy to NULL or yourself." ) );
@ -391,6 +391,10 @@ void MODULE::CopyNetlistSettings( MODULE* aModule )
if( aModule->GetOrientation() != GetOrientation() ) if( aModule->GetOrientation() != GetOrientation() )
aModule->Rotate( aModule->GetPosition(), GetOrientation() ); aModule->Rotate( aModule->GetPosition(), GetOrientation() );
aModule->SetLocked( IsLocked() );
if( aCopyLocalSettings )
{
aModule->SetLocalSolderMaskMargin( GetLocalSolderMaskMargin() ); aModule->SetLocalSolderMaskMargin( GetLocalSolderMaskMargin() );
aModule->SetLocalClearance( GetLocalClearance() ); aModule->SetLocalClearance( GetLocalClearance() );
aModule->SetLocalSolderPasteMargin( GetLocalSolderPasteMargin() ); aModule->SetLocalSolderPasteMargin( GetLocalSolderPasteMargin() );
@ -398,13 +402,14 @@ void MODULE::CopyNetlistSettings( MODULE* aModule )
aModule->SetZoneConnection( GetZoneConnection() ); aModule->SetZoneConnection( GetZoneConnection() );
aModule->SetThermalWidth( GetThermalWidth() ); aModule->SetThermalWidth( GetThermalWidth() );
aModule->SetThermalGap( GetThermalGap() ); aModule->SetThermalGap( GetThermalGap() );
}
for( D_PAD* pad = Pads(); pad; pad = pad->Next() ) for( D_PAD* pad = Pads(); pad; pad = pad->Next() )
{ {
D_PAD* newPad = aModule->FindPadByName( pad->GetPadName() ); D_PAD* newPad = aModule->FindPadByName( pad->GetPadName() );
if( newPad ) if( newPad )
pad->CopyNetlistSettings( newPad ); pad->CopyNetlistSettings( newPad, aCopyLocalSettings );
} }
// Not sure about copying description, keywords, 3D models or any other // Not sure about copying description, keywords, 3D models or any other

View File

@ -570,15 +570,20 @@ public:
/** /**
* Function CopyNetlistSettings * Function CopyNetlistSettings
* copies the netlist settings to \a aModule. * copies the netlist settings to \a aModule.
* Used to copy some footprint parameters when replacing a footprint by an other
* footprint when reading a netlist, or in exchange footprint dialog
* *
* The netlist settings are all of the #MODULE settings not define by a #MODULE in * The netlist settings are all of the #MODULE settings not define by a #MODULE in
* a netlist. These setting include position, orientation, local clearances, ets. * a netlist. These setting include placement prms (position, orientation, side)
* and optionally local prms( clearances, zone connection type, etc).
* The reference designator, value, path, and physical geometry settings are not * The reference designator, value, path, and physical geometry settings are not
* copied. * copied.
* *
* @param aModule is the #MODULE to copy the settings to. * @param aModule is the #MODULE to copy the settings to.
* @param aCopyLocalSettings = false to copy only module placement
* true to also copy local prms
*/ */
void CopyNetlistSettings( MODULE* aModule ); void CopyNetlistSettings( MODULE* aModule, bool aCopyLocalSettings );
/** /**
* static function IsLibNameValid * static function IsLibNameValid

View File

@ -460,13 +460,15 @@ void D_PAD::Copy( D_PAD* source )
} }
void D_PAD::CopyNetlistSettings( D_PAD* aPad ) void D_PAD::CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings )
{ {
// Don't do anything foolish like trying to copy to yourself. // Don't do anything foolish like trying to copy to yourself.
wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) ); wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) );
aPad->SetNetCode( GetNetCode() ); aPad->SetNetCode( GetNetCode() );
if( aCopyLocalSettings )
{
aPad->SetLocalClearance( m_LocalClearance ); aPad->SetLocalClearance( m_LocalClearance );
aPad->SetLocalSolderMaskMargin( m_LocalSolderMaskMargin ); aPad->SetLocalSolderMaskMargin( m_LocalSolderMaskMargin );
aPad->SetLocalSolderPasteMargin( m_LocalSolderPasteMargin ); aPad->SetLocalSolderPasteMargin( m_LocalSolderPasteMargin );
@ -475,6 +477,7 @@ void D_PAD::CopyNetlistSettings( D_PAD* aPad )
aPad->SetThermalWidth( m_ThermalWidth ); aPad->SetThermalWidth( m_ThermalWidth );
aPad->SetThermalGap( m_ThermalGap ); aPad->SetThermalGap( m_ThermalGap );
} }
}
int D_PAD::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const int D_PAD::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const

View File

@ -472,15 +472,20 @@ public:
/** /**
* Function CopyNetlistSettings * Function CopyNetlistSettings
* copies the netlist settings to \a aPad. * copies the netlist settings to \a aPad, and the net name.
* Used to copy some pad parameters when replacing a footprint by an other
* footprint when reading a netlist, or in exchange footprint dialog
* *
* The netlist settings are all of the #D_PAD settings not define by a #D_PAD in * The netlist settings are all of the #D_PAD settings not define by a #D_PAD in
* a netlist. These setting include local clearances, net names, etc. The pad * a netlist.
* physical geometry settings are not copied. * The copied settings are the net name and optionally include local clearance, etc.
* The pad physical geometry settings are not copied.
* *
* @param aPad is the #D_PAD to copy the settings to. * @param aPad is the #D_PAD to copy the settings to.
* @param aCopyLocalSettings = false to copy only the net name
* true to also copy local prms
*/ */
void CopyNetlistSettings( D_PAD* aPad ); void CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings );
#if defined(DEBUG) #if defined(DEBUG)
virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override

View File

@ -430,21 +430,12 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
* when all modules are on board * when all modules are on board
*/ */
PlaceModule( aNewModule, NULL, true ); PlaceModule( aNewModule, NULL, true );
aNewModule->SetPosition( aOldModule->GetPosition() );
// Flip footprint if needed // Copy full placement and pad net names (when possible)
if( aOldModule->GetLayer() != aNewModule->GetLayer() ) // but not local settings like clearances (use library values)
{ aOldModule->CopyNetlistSettings( aNewModule, false );
aNewModule->Flip( aNewModule->GetPosition() );
}
// Rotate footprint if needed // Copy reference and value
if( aOldModule->GetOrientation() != aNewModule->GetOrientation() )
{
Rotate_Module( NULL, aNewModule, aOldModule->GetOrientation(), false );
}
// Update reference and value
aNewModule->SetReference( aOldModule->GetReference() ); aNewModule->SetReference( aOldModule->GetReference() );
aNewModule->SetValue( aOldModule->GetValue() ); aNewModule->SetValue( aOldModule->GetValue() );
@ -452,18 +443,6 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() ); aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() );
aNewModule->SetPath( aOldModule->GetPath() ); aNewModule->SetPath( aOldModule->GetPath() );
// Update pad netnames (when possible)
for( D_PAD* pad = aNewModule->Pads(); pad != NULL; pad = pad->Next() )
{
pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
for( D_PAD* old_pad = aOldModule->Pads(); old_pad != NULL; old_pad = old_pad->Next() )
{
if( pad->PadNameEqual( old_pad ) )
pad->SetNetCode( old_pad->GetNetCode() );
}
}
if( aUndoPickList ) if( aUndoPickList )
{ {
GetBoard()->Remove( aOldModule ); GetBoard()->Remove( aOldModule );