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
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 );
Add( newFootprint, ADD_APPEND );
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.
wxCHECK_RET( aModule != NULL && aModule != this, wxT( "Cannot copy to NULL or yourself." ) );
@ -391,20 +391,25 @@ void MODULE::CopyNetlistSettings( MODULE* aModule )
if( aModule->GetOrientation() != GetOrientation() )
aModule->Rotate( aModule->GetPosition(), GetOrientation() );
aModule->SetLocalSolderMaskMargin( GetLocalSolderMaskMargin() );
aModule->SetLocalClearance( GetLocalClearance() );
aModule->SetLocalSolderPasteMargin( GetLocalSolderPasteMargin() );
aModule->SetLocalSolderPasteMarginRatio( GetLocalSolderPasteMarginRatio() );
aModule->SetZoneConnection( GetZoneConnection() );
aModule->SetThermalWidth( GetThermalWidth() );
aModule->SetThermalGap( GetThermalGap() );
aModule->SetLocked( IsLocked() );
if( aCopyLocalSettings )
{
aModule->SetLocalSolderMaskMargin( GetLocalSolderMaskMargin() );
aModule->SetLocalClearance( GetLocalClearance() );
aModule->SetLocalSolderPasteMargin( GetLocalSolderPasteMargin() );
aModule->SetLocalSolderPasteMarginRatio( GetLocalSolderPasteMarginRatio() );
aModule->SetZoneConnection( GetZoneConnection() );
aModule->SetThermalWidth( GetThermalWidth() );
aModule->SetThermalGap( GetThermalGap() );
}
for( D_PAD* pad = Pads(); pad; pad = pad->Next() )
{
D_PAD* newPad = aModule->FindPadByName( pad->GetPadName() );
if( newPad )
pad->CopyNetlistSettings( newPad );
pad->CopyNetlistSettings( newPad, aCopyLocalSettings );
}
// Not sure about copying description, keywords, 3D models or any other

View File

@ -570,15 +570,20 @@ public:
/**
* Function CopyNetlistSettings
* 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
* 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
* copied.
*
* @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

View File

@ -460,20 +460,23 @@ 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.
wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) );
aPad->SetNetCode( GetNetCode() );
aPad->SetLocalClearance( m_LocalClearance );
aPad->SetLocalSolderMaskMargin( m_LocalSolderMaskMargin );
aPad->SetLocalSolderPasteMargin( m_LocalSolderPasteMargin );
aPad->SetLocalSolderPasteMarginRatio( m_LocalSolderPasteMarginRatio );
aPad->SetZoneConnection( m_ZoneConnection );
aPad->SetThermalWidth( m_ThermalWidth );
aPad->SetThermalGap( m_ThermalGap );
if( aCopyLocalSettings )
{
aPad->SetLocalClearance( m_LocalClearance );
aPad->SetLocalSolderMaskMargin( m_LocalSolderMaskMargin );
aPad->SetLocalSolderPasteMargin( m_LocalSolderPasteMargin );
aPad->SetLocalSolderPasteMarginRatio( m_LocalSolderPasteMarginRatio );
aPad->SetZoneConnection( m_ZoneConnection );
aPad->SetThermalWidth( m_ThermalWidth );
aPad->SetThermalGap( m_ThermalGap );
}
}

View File

@ -472,15 +472,20 @@ public:
/**
* 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
* a netlist. These setting include local clearances, net names, etc. The pad
* physical geometry settings are not copied.
* a netlist.
* 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 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)
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
*/
PlaceModule( aNewModule, NULL, true );
aNewModule->SetPosition( aOldModule->GetPosition() );
// Flip footprint if needed
if( aOldModule->GetLayer() != aNewModule->GetLayer() )
{
aNewModule->Flip( aNewModule->GetPosition() );
}
// Copy full placement and pad net names (when possible)
// but not local settings like clearances (use library values)
aOldModule->CopyNetlistSettings( aNewModule, false );
// Rotate footprint if needed
if( aOldModule->GetOrientation() != aNewModule->GetOrientation() )
{
Rotate_Module( NULL, aNewModule, aOldModule->GetOrientation(), false );
}
// Update reference and value
// Copy reference and value
aNewModule->SetReference( aOldModule->GetReference() );
aNewModule->SetValue( aOldModule->GetValue() );
@ -452,18 +443,6 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
aNewModule->SetTimeStamp( aOldModule->GetTimeStamp() );
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 )
{
GetBoard()->Remove( aOldModule );