From dd5b024903af14eb17326965c5a55c76e61dbde8 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 10 Feb 2017 20:44:02 +0100 Subject: [PATCH] Pad export/import settings functions: remove duplicate code. --- pcbnew/class_pad.cpp | 56 ++++++++++++++++++++++ pcbnew/class_pad.h | 8 ++++ pcbnew/pad_edition_functions.cpp | 51 ++------------------ pcbnew/tools/pad_tool.cpp | 80 ++------------------------------ 4 files changed, 73 insertions(+), 122 deletions(-) diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index cab4376e27..b4c7c246f8 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -1036,3 +1036,59 @@ wxString LayerMaskDescribe( const BOARD *aBoard, LSET aMask ) return layerInfo; } + + +void D_PAD::ImportSettingsFromMaster( const D_PAD& aMasterPad ) +{ + SetShape( aMasterPad.GetShape() ); + SetLayerSet( aMasterPad.GetLayerSet() ); + SetAttribute( aMasterPad.GetAttribute() ); + + // The pad orientation, for historical reasons is the + // pad rotation + parent rotation. + // So we have to manage this parent rotation + double pad_rot = aMasterPad.GetOrientation(); + + if( aMasterPad.GetParent() ) + pad_rot -= aMasterPad.GetParent()->GetOrientation(); + + if( GetParent() ) + pad_rot += GetParent()->GetOrientation(); + + SetOrientation( pad_rot ); + + SetSize( aMasterPad.GetSize() ); + SetDelta( wxSize( 0, 0 ) ); + SetOffset( aMasterPad.GetOffset() ); + SetDrillSize( aMasterPad.GetDrillSize() ); + SetDrillShape( aMasterPad.GetDrillShape() ); + SetRoundRectRadiusRatio( aMasterPad.GetRoundRectRadiusRatio() ); + + switch( aMasterPad.GetShape() ) + { + case PAD_SHAPE_TRAPEZOID: + SetDelta( aMasterPad.GetDelta() ); + break; + + case PAD_SHAPE_CIRCLE: + // ensure size.y == size.x + SetSize( wxSize( GetSize().x, GetSize().x ) ); + break; + + default: + ; + } + + switch( aMasterPad.GetAttribute() ) + { + case PAD_ATTRIB_SMD: + case PAD_ATTRIB_CONN: + // These pads do not have hole (they are expected to be only on one + // external copper layer) + SetDrillSize( wxSize( 0, 0 ) ); + break; + + default: + ; + } +} diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 6072fec054..d8c26a8f8d 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -107,6 +107,14 @@ public: MODULE* GetParent() const { return (MODULE*) m_Parent; } + /** + * Imports the pad settings from aMasterPad. + * The result is "this" has the same settinds (sizes, shapes ... ) + * as aMasterPad + * @param aMasterPad = the template pad + */ + void ImportSettingsFromMaster( const D_PAD& aMasterPad ); + /** * @return true if the pad has a footprint parent flipped * (on the back/bottom layer) diff --git a/pcbnew/pad_edition_functions.cpp b/pcbnew/pad_edition_functions.cpp index 49ced41c22..65cbb5699c 100644 --- a/pcbnew/pad_edition_functions.cpp +++ b/pcbnew/pad_edition_functions.cpp @@ -50,13 +50,9 @@ void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad ) SetMsgPanel( aPad ); - D_PAD& mp = GetDesignSettings().m_Pad_Master; - // Copy all settings. Some of them are not used, but they break anything - mp = *aPad; - // The pad orientation, for historical reasons is the - // pad rotation + parent rotation. - // store only the pad rotation. - mp.SetOrientation( aPad->GetOrientation() - aPad->GetParent()->GetOrientation() ); + D_PAD& masterPad = GetDesignSettings().m_Pad_Master; + + masterPad.ImportSettingsFromMaster( *aPad ); } @@ -73,46 +69,9 @@ void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw ) aPad->ClearFlags( DO_NOT_DRAW ); } - D_PAD& mp = GetDesignSettings().m_Pad_Master; + const D_PAD& mp = GetDesignSettings().m_Pad_Master; - aPad->SetShape( mp.GetShape() ); - aPad->SetLayerSet( mp.GetLayerSet() ); - aPad->SetAttribute( mp.GetAttribute() ); - aPad->SetOrientation( mp.GetOrientation() + aPad->GetParent()->GetOrientation() ); - aPad->SetSize( mp.GetSize() ); - aPad->SetDelta( wxSize( 0, 0 ) ); - aPad->SetOffset( mp.GetOffset() ); - aPad->SetDrillSize( mp.GetDrillSize() ); - aPad->SetDrillShape( mp.GetDrillShape() ); - aPad->SetRoundRectRadiusRatio( mp.GetRoundRectRadiusRatio() ); - - switch( mp.GetShape() ) - { - case PAD_SHAPE_TRAPEZOID: - aPad->SetDelta( mp.GetDelta() ); - break; - - case PAD_SHAPE_CIRCLE: - // ensure size.y == size.x - aPad->SetSize( wxSize( aPad->GetSize().x, aPad->GetSize().x ) ); - break; - - default: - ; - } - - switch( mp.GetAttribute() ) - { - case PAD_ATTRIB_SMD: - case PAD_ATTRIB_CONN: - // These pads do not have hole (they are expected to be only on one - // external copper layer) - aPad->SetDrillSize( wxSize( 0, 0 ) ); - break; - - default: - ; - } + aPad->ImportSettingsFromMaster( mp ); if( aDraw ) m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() ); diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index c96e25e757..97626082c0 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -132,76 +132,6 @@ bool PAD_TOOL::Init() } -/** - * Function doCopyPadSettings - * - * Copy a given pad setting to the destination pad. Normally, the destination - * would be a board reference settings master pad. - */ -static void doCopyPadSettings( const D_PAD& aSrc, D_PAD& aDest ) -{ - // Copy all settings. Some of them are not used, but they break anything - aDest = aSrc; - - // The pad orientation, for historical reasons is the - // pad rotation + parent rotation. - // store only the pad rotation. - aDest.SetOrientation( aSrc.GetOrientation() - aSrc.GetParent()->GetOrientation() ); -} - - -/** - * Function doApplyPadSettings - * - * Apply pad settings from a "reference" source to a destination. - * Often, the reference source will be a board reference settings - * master pad. - */ -static void doApplyPadSettings( const D_PAD& aSrc, D_PAD& aDest ) -{ - const auto& destParent = *aDest.GetParent(); - - aDest.SetShape( aSrc.GetShape() ); - aDest.SetLayerSet( aSrc.GetLayerSet() ); - aDest.SetAttribute( aSrc.GetAttribute() ); - aDest.SetOrientation( aSrc.GetOrientation() + destParent.GetOrientation() ); - aDest.SetSize( aSrc.GetSize() ); - aDest.SetDelta( wxSize( 0, 0 ) ); - aDest.SetOffset( aSrc.GetOffset() ); - aDest.SetDrillSize( aSrc.GetDrillSize() ); - aDest.SetDrillShape( aSrc.GetDrillShape() ); - aDest.SetRoundRectRadiusRatio( aSrc.GetRoundRectRadiusRatio() ); - - switch( aSrc.GetShape() ) - { - case PAD_SHAPE_TRAPEZOID: - aDest.SetDelta( aSrc.GetDelta() ); - break; - - case PAD_SHAPE_CIRCLE: - // ensure size.y == size.x - aDest.SetSize( wxSize( aDest.GetSize().x, aDest.GetSize().x ) ); - break; - - default: - ; - } - - switch( aSrc.GetAttribute() ) - { - case PAD_ATTRIB_SMD: - case PAD_ATTRIB_CONN: - // These pads do not have hole (they are expected to be only on one - // external copper layer) - aDest.SetDrillSize( wxSize( 0, 0 ) ); - break; - - default: - ; - } -} - - int PAD_TOOL::applyPadSettings( const TOOL_EVENT& aEvent ) { auto& selTool = *m_toolMgr->GetTool(); @@ -220,9 +150,8 @@ int PAD_TOOL::applyPadSettings( const TOOL_EVENT& aEvent ) { commit.Modify( item ); - auto& destPad = static_cast( *item ); - - doApplyPadSettings( masterPad, destPad ); + D_PAD& destPad = static_cast( *item ); + destPad.ImportSettingsFromMaster( masterPad ); } } @@ -252,8 +181,7 @@ int PAD_TOOL::copyPadSettings( const TOOL_EVENT& aEvent ) if( item->Type() == PCB_PAD_T ) { const auto& selPad = static_cast( *item ); - - doCopyPadSettings( selPad, masterPad ); + masterPad.ImportSettingsFromMaster( selPad ); } } @@ -309,7 +237,7 @@ static void globalChangePadSettings( BOARD& board, commit.Modify( pad ); // Apply source pad settings to this pad - doApplyPadSettings( aSrcPad, *pad ); + pad->ImportSettingsFromMaster( aSrcPad ); } } }