← Back to team overview

kicad-developers team mailing list archive

Pad import/export/push and modedit mirror

 

Hi,

Here are two patches for outstanding GAL functionality: pad
import/export/push and modedit mirroring.

Pad "push" is what I termed global edit, since I think that describes
the action of taking a reference and "pushing" it to a filtered subset
of other pads. I am happy to keep the old name too, if that's
preferred.

I have implemented in a new PAD_TOOL GAL tool as I think there could
be more pad-only function in future that can all stick together in
there.

Let me know if there are any suggestions!

John
From a37f96d130a5fbd86e662360e02159aad5e1ef54 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Mon, 23 Jan 2017 14:47:39 +0800
Subject: [PATCH 2/2] Add mirror tool action for GAL module editor

This is basically a simple clone of the legacy tool with a few minor
tidy-ups for GAL mode.

Fixes: lp:1619301
* https://bugs.launchpad.net/kicad/+bug/1619301
---
 pcbnew/tools/common_actions.cpp |   4 ++
 pcbnew/tools/common_actions.h   |   3 ++
 pcbnew/tools/edit_tool.cpp      | 117 ++++++++++++++++++++++++++++++++++++++++
 pcbnew/tools/edit_tool.h        |   7 +++
 4 files changed, 131 insertions(+)

diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp
index dc65bf6e3..da2694db5 100644
--- a/pcbnew/tools/common_actions.cpp
+++ b/pcbnew/tools/common_actions.cpp
@@ -125,6 +125,10 @@ TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveEdit.flip",
         AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_FLIP_ITEM ),
         _( "Flip" ), _( "Flips selected item(s)" ), swap_layer_xpm );
 
+TOOL_ACTION COMMON_ACTIONS::mirror( "pcbnew.InteractiveEdit.mirror",
+        AS_GLOBAL, 0,
+        _( "Mirror" ), _( "Mirrors selected item" ), mirror_h_xpm );
+
 TOOL_ACTION COMMON_ACTIONS::remove( "pcbnew.InteractiveEdit.remove",
         AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ),
         _( "Remove" ), _( "Deletes selected item(s)" ), delete_xpm );
diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h
index 2cf312ad3..a878520da 100644
--- a/pcbnew/tools/common_actions.h
+++ b/pcbnew/tools/common_actions.h
@@ -76,6 +76,9 @@ public:
     /// Flipping of selected objects
     static TOOL_ACTION flip;
 
+    /// Mirroring of selected items
+    static TOOL_ACTION mirror;
+
     /// Activation of the edit tool
     static TOOL_ACTION properties;
 
diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp
index 7c831774b..1c9466fb8 100644
--- a/pcbnew/tools/edit_tool.cpp
+++ b/pcbnew/tools/edit_tool.cpp
@@ -86,6 +86,10 @@ bool EDIT_TOOL::Init()
         return false;
     }
 
+    auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
+        return m_editModules;
+    };
+
     // Add context menu entries that are displayed when selection tool is active
     CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu();
     menu.AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
@@ -98,6 +102,9 @@ bool EDIT_TOOL::Init()
     menu.AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
     menu.AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
 
+    // Mirror only available in modedit
+    menu.AddItem( COMMON_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
+
     // Footprint actions
     menu.AddItem( COMMON_ACTIONS::editFootprintInFpEditor,
                                         SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) &&
@@ -404,6 +411,115 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
     return 0;
 }
 
+/*!
+ * Mirror a point about the vertical axis passing though another point
+ */
+static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
+{
+    wxPoint mirrored = aPoint;
+
+    mirrored.x -= aMirrorPoint.x;
+    mirrored.x = -mirrored.x;
+    mirrored.x += aMirrorPoint.x;
+
+    return mirrored;
+}
+
+
+/**
+ * Mirror a pad in the vertical axis passing though a point
+ */
+static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
+{
+    wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
+
+    aPad.SetPosition( tmpPt );
+
+    aPad.SetX0( aPad.GetPosition().x );
+
+    tmpPt = aPad.GetOffset();
+    tmpPt.x = -tmpPt.x;
+    aPad.SetOffset( tmpPt );
+
+    auto tmpz = aPad.GetDelta();
+    tmpz.x = -tmpz.x;
+    aPad.SetDelta( tmpz );
+
+    aPad.SetOrientation( -aPad.GetOrientation() );
+}
+
+
+int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
+{
+    const SELECTION& selection = m_selectionTool->GetSelection();
+    PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
+
+    // Shall the selection be cleared at the end?
+    bool unselect = selection.Empty();
+
+    if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED )
+        return 0;
+
+    wxPoint mirrorPoint = getModificationPoint( selection );
+
+    for( auto item : selection )
+    {
+        // only modify items we can mirror
+        switch( item->Type() )
+        {
+        case PCB_MODULE_EDGE_T:
+        case PCB_MODULE_TEXT_T:
+        case PCB_PAD_T:
+            m_commit->Modify( item );
+            break;
+        default:
+            continue;
+        }
+
+        // modify each object as necessary
+        switch( item->Type() )
+        {
+        case PCB_MODULE_EDGE_T:
+        {
+            auto& edge = static_cast<EDGE_MODULE&>( *item );
+            edge.Mirror( mirrorPoint, false );
+            break;
+        }
+
+        case PCB_MODULE_TEXT_T:
+        {
+            auto& modText = static_cast<TEXTE_MODULE&>( *item );
+            modText.Mirror( mirrorPoint, false );
+            break;
+        }
+
+        case PCB_PAD_T:
+        {
+            auto& pad = static_cast<D_PAD&>( *item );
+            mirrorPadX( pad, mirrorPoint );
+            break;
+        }
+
+        default:
+            // it's likely the commit object is wrong if you get here
+            assert( false );
+            break;
+        }
+    }
+
+    if( !m_dragging )
+        m_commit->Push( _( "Mirror" ) );
+
+    if( unselect )
+        m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
+
+    // TODO selectionModified
+    m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true );
+    editFrame->Refresh();
+
+    return 0;
+}
+
 
 int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
 {
@@ -671,6 +787,7 @@ void EDIT_TOOL::SetTransitions()
     Go( &EDIT_TOOL::Duplicate,  COMMON_ACTIONS::duplicate.MakeEvent() );
     Go( &EDIT_TOOL::Duplicate,  COMMON_ACTIONS::duplicateIncrement.MakeEvent() );
     Go( &EDIT_TOOL::CreateArray,COMMON_ACTIONS::createArray.MakeEvent() );
+    Go( &EDIT_TOOL::Mirror,     COMMON_ACTIONS::mirror.MakeEvent() );
     Go( &EDIT_TOOL::editFootprintInFpEditor, COMMON_ACTIONS::editFootprintInFpEditor.MakeEvent() );
 }
 
diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h
index 0f9b509db..b9f3d3fc9 100644
--- a/pcbnew/tools/edit_tool.h
+++ b/pcbnew/tools/edit_tool.h
@@ -81,6 +81,13 @@ public:
     int Flip( const TOOL_EVENT& aEvent );
 
     /**
+     * Function Mirror
+     *
+     * Mirrors the current selection. The mirror axis passes though the current point.
+     */
+    int Mirror( const TOOL_EVENT& aEvent );
+
+    /**
      * Function Remove()
      *
      * Deletes currently selected items. The rotation point is the current cursor position.
-- 
2.11.0

From 50b6e8807421fe19de24a465bfd76949d42ad551 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Sun, 22 Jan 2017 05:06:18 +0800
Subject: [PATCH 2/2] Add pad import/export/push to GAL canvas

---
 pcbnew/CMakeLists.txt                         |   2 +
 pcbnew/dialogs/dialog_global_pads_edition.cpp |  91 +++++++
 pcbnew/dialogs/dialog_global_pads_edition.h   |  56 +++++
 pcbnew/globaleditpad.cpp                      |  91 +------
 pcbnew/pad_edition_functions.cpp              |  49 +---
 pcbnew/tools/common_actions.cpp               |  18 ++
 pcbnew/tools/common_actions.h                 |  10 +
 pcbnew/tools/pad_tool.cpp                     | 342 ++++++++++++++++++++++++++
 pcbnew/tools/pad_tool.h                       |  68 +++++
 pcbnew/tools/tools_common.cpp                 |   2 +
 10 files changed, 595 insertions(+), 134 deletions(-)
 create mode 100644 pcbnew/dialogs/dialog_global_pads_edition.cpp
 create mode 100644 pcbnew/dialogs/dialog_global_pads_edition.h
 create mode 100644 pcbnew/tools/pad_tool.cpp
 create mode 100644 pcbnew/tools/pad_tool.h

diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index be46007f9..9683ac97d 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -87,6 +87,7 @@ set( PCBNEW_DIALOGS
     dialogs/dialog_global_modules_fields_edition.cpp
     dialogs/dialog_global_modules_fields_edition_base.cpp
     dialogs/dialog_global_pads_edition_base.cpp
+    dialogs/dialog_global_pads_edition.cpp
     dialogs/dialog_graphic_items_options.cpp
     dialogs/dialog_graphic_items_options_base.cpp
     dialogs/dialog_graphic_item_properties.cpp
@@ -291,6 +292,7 @@ set( PCBNEW_CLASS_SRCS
     tools/placement_tool.cpp
     tools/common_actions.cpp
     tools/grid_helper.cpp
+    tools/pad_tool.cpp
     tools/picker_tool.cpp
     tools/zoom_tool.cpp
     tools/tools_common.cpp
diff --git a/pcbnew/dialogs/dialog_global_pads_edition.cpp b/pcbnew/dialogs/dialog_global_pads_edition.cpp
new file mode 100644
index 000000000..c2c449b5d
--- /dev/null
+++ b/pcbnew/dialogs/dialog_global_pads_edition.cpp
@@ -0,0 +1,91 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+
+#include <dialog_global_pads_edition.h>
+
+#include <class_pad.h>
+#include <wxPcbStruct.h>
+
+
+DIALOG_GLOBAL_PADS_EDITION::DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad ) :
+    DIALOG_GLOBAL_PADS_EDITION_BASE( aParent )
+{
+    m_parent     = aParent;
+    m_currentPad = aPad;
+
+    // Pad filter selection.
+    m_Pad_Shape_Filter_CB->SetValue( m_Pad_Shape_Filter );
+    m_Pad_Layer_Filter_CB->SetValue( m_Pad_Layer_Filter );
+    m_Pad_Orient_Filter_CB->SetValue( m_Pad_Orient_Filter );
+
+    SetFocus();
+
+    GetSizer()->Fit( this );
+    Centre();
+}
+
+
+// Class DIALOG_GLOBAL_PADS_EDITION static variables
+bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter  = true;
+bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter  = true;
+bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter = true;
+
+
+void DIALOG_GLOBAL_PADS_EDITION::OnCancelClick( wxCommandEvent& event )
+{
+    EndModal( -1 );
+}
+
+
+/* Calls the Pad editor.
+ */
+void DIALOG_GLOBAL_PADS_EDITION::InstallPadEditor( wxCommandEvent& event )
+{
+    m_parent->InstallPadOptionsFrame( m_currentPad );
+}
+
+
+/* Update the parameters for the component being edited.
+ */
+void DIALOG_GLOBAL_PADS_EDITION::PadPropertiesAccept( wxCommandEvent& event )
+{
+    int returncode = 0;
+
+    switch( event.GetId() )
+    {
+    case ID_CHANGE_ID_MODULES:
+        returncode = 1;
+
+    // Fall through
+
+    case ID_CHANGE_CURRENT_MODULE:
+        m_Pad_Shape_Filter  = m_Pad_Shape_Filter_CB->GetValue();
+        m_Pad_Layer_Filter  = m_Pad_Layer_Filter_CB->GetValue();
+        m_Pad_Orient_Filter = m_Pad_Orient_Filter_CB->GetValue();
+        EndModal( returncode );
+        break;
+    }
+
+    m_parent->OnModify();
+}
diff --git a/pcbnew/dialogs/dialog_global_pads_edition.h b/pcbnew/dialogs/dialog_global_pads_edition.h
new file mode 100644
index 000000000..b8b7e7d2c
--- /dev/null
+++ b/pcbnew/dialogs/dialog_global_pads_edition.h
@@ -0,0 +1,56 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+#ifndef __DIALOG_GLOBAL_PADS_EDITION_H
+#define __DIALOG_GLOBAL_PADS_EDITION_H
+
+#include <dialog_global_pads_edition_base.h>
+
+class D_PAD;
+class PCB_BASE_FRAME;
+/************************************/
+/* class DIALOG_GLOBAL_PADS_EDITION */
+/************************************/
+
+class DIALOG_GLOBAL_PADS_EDITION : public DIALOG_GLOBAL_PADS_EDITION_BASE
+{
+private:
+    PCB_BASE_FRAME* m_parent;
+    D_PAD*    m_currentPad;
+
+public:
+    static bool m_Pad_Shape_Filter;
+    static bool m_Pad_Layer_Filter;
+    static bool m_Pad_Orient_Filter;
+
+public:
+    DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad );
+
+private:
+    void InstallPadEditor( wxCommandEvent& event ) override;
+    void PadPropertiesAccept( wxCommandEvent& event ) override;
+    void OnCancelClick( wxCommandEvent& event ) override;
+};
+
+
+#endif // __DIALOG_GLOBAL_PADS_EDITION_H
diff --git a/pcbnew/globaleditpad.cpp b/pcbnew/globaleditpad.cpp
index 8cfc46a87..fbb20e328 100644
--- a/pcbnew/globaleditpad.cpp
+++ b/pcbnew/globaleditpad.cpp
@@ -37,96 +37,7 @@
 #include <class_module.h>
 
 #include <pcbnew.h>
-#include <dialog_global_pads_edition_base.h>
-
-
-/************************************/
-/* class DIALOG_GLOBAL_PADS_EDITION */
-/************************************/
-
-class DIALOG_GLOBAL_PADS_EDITION : public DIALOG_GLOBAL_PADS_EDITION_BASE
-{
-private:
-    PCB_BASE_FRAME* m_parent;
-    D_PAD*      m_currentPad;
-
-public:
-    static bool m_Pad_Shape_Filter;
-    static bool m_Pad_Layer_Filter;
-    static bool m_Pad_Orient_Filter;
-
-public:
-    DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad );
-
-private:
-    void InstallPadEditor( wxCommandEvent& event ) override;
-    void PadPropertiesAccept( wxCommandEvent& event ) override;
-    void OnCancelClick( wxCommandEvent& event ) override;
-};
-
-
-DIALOG_GLOBAL_PADS_EDITION::DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad ) :
-    DIALOG_GLOBAL_PADS_EDITION_BASE( aParent )
-{
-    m_parent     = aParent;
-    m_currentPad = aPad;
-
-    // Pad filter selection.
-    m_Pad_Shape_Filter_CB->SetValue( m_Pad_Shape_Filter );
-    m_Pad_Layer_Filter_CB->SetValue( m_Pad_Layer_Filter );
-    m_Pad_Orient_Filter_CB->SetValue( m_Pad_Orient_Filter );
-
-    SetFocus();
-
-    GetSizer()->Fit( this );
-    Centre();
-}
-
-
-// Class DIALOG_GLOBAL_PADS_EDITION static variables
-bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter  = true;
-bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter  = true;
-bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter = true;
-
-
-void DIALOG_GLOBAL_PADS_EDITION::OnCancelClick( wxCommandEvent& event )
-{
-    EndModal( -1 );
-}
-
-
-/* Calls the Pad editor.
- */
-void DIALOG_GLOBAL_PADS_EDITION::InstallPadEditor( wxCommandEvent& event )
-{
-    m_parent->InstallPadOptionsFrame( m_currentPad );
-}
-
-
-/* Update the parameters for the component being edited.
- */
-void DIALOG_GLOBAL_PADS_EDITION::PadPropertiesAccept( wxCommandEvent& event )
-{
-    int returncode = 0;
-
-    switch( event.GetId() )
-    {
-    case ID_CHANGE_ID_MODULES:
-        returncode = 1;
-
-    // Fall through
-
-    case ID_CHANGE_CURRENT_MODULE:
-        m_Pad_Shape_Filter  = m_Pad_Shape_Filter_CB->GetValue();
-        m_Pad_Layer_Filter  = m_Pad_Layer_Filter_CB->GetValue();
-        m_Pad_Orient_Filter = m_Pad_Orient_Filter_CB->GetValue();
-        EndModal( returncode );
-        break;
-    }
-
-    m_parent->OnModify();
-}
-
+#include <dialog_global_pads_edition.h>
 
 /*
  * PCB_EDIT_FRAME::Function DlgGlobalChange_PadSettings
diff --git a/pcbnew/pad_edition_functions.cpp b/pcbnew/pad_edition_functions.cpp
index 49ced41c2..8e04cf227 100644
--- a/pcbnew/pad_edition_functions.cpp
+++ b/pcbnew/pad_edition_functions.cpp
@@ -41,6 +41,8 @@
 #include <class_pad.h>
 #include <class_board_design_settings.h>
 
+#include <tools/pad_tool.h>
+
 /* Exports the current pad settings to board design settings.
  */
 void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad )
@@ -51,12 +53,8 @@ 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() );
+
+    PAD_TOOL::ExportPadSettings( *aPad, mp );
 }
 
 
@@ -75,44 +73,7 @@ void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw )
 
     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:
-        ;
-    }
+    PAD_TOOL::ImportPadSettings( mp, *aPad );
 
     if( aDraw )
         m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp
index b9af35915..e2dc3cac2 100644
--- a/pcbnew/tools/common_actions.cpp
+++ b/pcbnew/tools/common_actions.cpp
@@ -459,6 +459,24 @@ TOOL_ACTION COMMON_ACTIONS::moduleTextOutlines( "pcbnew.ModuleEditor.textOutline
        AS_GLOBAL, 0,
        "", "" );
 
+// Pad tools
+TOOL_ACTION COMMON_ACTIONS::exportPadSettings(
+        "pcbnew.PadTool.ExportPadSettings",
+        AS_GLOBAL, 0,
+        _( "Export pad settings" ), _( "Copy current pad's settings to the board design settings" ),
+        export_options_pad_xpm );
+
+TOOL_ACTION COMMON_ACTIONS::importPadSettings(
+        "pcbnew.PadTool.ImportPadSettings",
+        AS_GLOBAL, 0,
+        _( "Import pad settings" ), _( "Copy the board design settings pad properties to the current pad" ),
+        options_new_pad_xpm );
+
+TOOL_ACTION COMMON_ACTIONS::pushPadSettings(
+        "pcbnew.PadTool.PushPadSettings",
+        AS_GLOBAL, 0,
+        _( "Push pad settings" ), _( "Copy the current pad settings to other pads" ),
+        global_options_pad_xpm );
 
 // Cursor control
 TOOL_ACTION COMMON_ACTIONS::cursorUp( "pcbnew.Control.cursorUp",
diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h
index 962b6b436..2cf312ad3 100644
--- a/pcbnew/tools/common_actions.h
+++ b/pcbnew/tools/common_actions.h
@@ -272,6 +272,16 @@ public:
     /// Display module texts as outlines
     static TOOL_ACTION moduleTextOutlines;
 
+    // Pad tools
+    /// Copy the selected pad's settings to the board design settings
+    static TOOL_ACTION exportPadSettings;
+
+    /// Copy the pad settings in the board design settings to the selected pad
+    static TOOL_ACTION importPadSettings;
+
+    /// Copy the current pad's settings to other pads in the module or on the board
+    static TOOL_ACTION pushPadSettings;
+
     /// Cursor control with keyboard
     static TOOL_ACTION cursorUp;
     static TOOL_ACTION cursorDown;
diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp
new file mode 100644
index 000000000..8ec1d5fc4
--- /dev/null
+++ b/pcbnew/tools/pad_tool.cpp
@@ -0,0 +1,342 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+
+#include "pad_tool.h"
+
+#include <wxPcbStruct.h>
+#include <class_draw_panel_gal.h>
+#include <view/view_controls.h>
+#include <view/view.h>
+#include <tool/tool_manager.h>
+
+#include <class_board_item.h>
+#include <class_module.h>
+#include <board_commit.h>
+
+#include <dialogs/dialog_global_pads_edition.h>
+
+#include "common_actions.h"
+#include "selection_tool.h"
+#include "edit_tool.h"
+
+class PAD_CONTEXT_MENU : public CONTEXT_MENU
+{
+public:
+    PAD_CONTEXT_MENU()
+    {
+        SetIcon( pad_xpm );
+
+        // These are all awlays available when the menu is
+        Add( COMMON_ACTIONS::importPadSettings );
+        Add( COMMON_ACTIONS::exportPadSettings );
+        Add( COMMON_ACTIONS::pushPadSettings );
+    }
+};
+
+
+PAD_TOOL::PAD_TOOL() :
+        PCB_TOOL( "pcbnew.PadTool" )
+{
+}
+
+
+PAD_TOOL::~PAD_TOOL()
+{}
+
+
+void PAD_TOOL::Reset( RESET_REASON aReason )
+{
+}
+
+
+bool PAD_TOOL::Init()
+{
+    auto padMenu = std::make_shared<PAD_CONTEXT_MENU>();
+    padMenu->SetTool( this );
+
+    SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
+
+    if( selTool )
+    {
+        auto& toolMenu = selTool->GetToolMenu();
+        auto& menu = toolMenu.GetMenu();
+
+        toolMenu.AddSubMenu( padMenu );
+
+        menu.AddMenu( padMenu.get(), _( "Pads" ), false,
+                      SELECTION_CONDITIONS::HasType( PCB_PAD_T ) );
+    }
+
+    return true;
+}
+
+// will become static free function when not needed externally
+void PAD_TOOL::ExportPadSettings( 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() );
+}
+
+void PAD_TOOL::ImportPadSettings( 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::importPadSettings( const TOOL_EVENT& aEvent )
+{
+    auto& selTool = *m_toolMgr->GetTool<SELECTION_TOOL>();
+    const auto& selection = selTool.GetSelection();
+
+    auto& frame = *getEditFrame<PCB_EDIT_FRAME>();
+
+    const D_PAD& masterPad = frame.GetDesignSettings().m_Pad_Master;
+
+    BOARD_COMMIT commit( &frame );
+
+    // for every selected pad, copy global settings
+    for( auto item : selection )
+    {
+        if ( item->Type() == PCB_PAD_T )
+        {
+            commit.Modify( item );
+
+            auto& destPad = static_cast<D_PAD&>( *item );
+
+            ImportPadSettings( masterPad, destPad );
+        }
+    }
+
+    commit.Push( _( "Import pad settings" ) );
+
+    m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true );
+    frame.Refresh();
+
+    return 0;
+}
+
+
+int PAD_TOOL::exportPadSettings( const TOOL_EVENT& aEvent )
+{
+    auto& selTool = *m_toolMgr->GetTool<SELECTION_TOOL>();
+    const auto& selection = selTool.GetSelection();
+
+    auto& frame = *getEditFrame<PCB_EDIT_FRAME>();
+
+    D_PAD& masterPad = frame.GetDesignSettings().m_Pad_Master;
+
+    // can only export from a single pad
+    if( selection.Size() == 1 )
+    {
+        auto item = selection[0];
+
+        if ( item->Type() == PCB_PAD_T )
+        {
+            const auto& selPad = static_cast<const D_PAD&>( *item );
+
+            ExportPadSettings( selPad, masterPad );
+        }
+    }
+    return 0;
+}
+
+
+static void globalChangePadSettings( BOARD& board,
+                                     const D_PAD& aSrcPad,
+                                     BOARD_COMMIT& commit,
+                                     bool aSameFootprints,
+                                     bool aPadShapeFilter,
+                                     bool aPadOrientFilter,
+                                     bool aPadLayerFilter )
+{
+    const MODULE* moduleRef = aSrcPad.GetParent();
+
+    if( moduleRef == nullptr )
+    {
+        wxLogDebug( _( "Global_Import_Pad_Settings() Error: NULL module" ) );
+        return;
+    }
+
+    double pad_orient = aSrcPad.GetOrientation() - moduleRef->GetOrientation();
+
+    for( const MODULE* module = board.m_Modules; module; module = module->Next() )
+    {
+        if( !aSameFootprints && ( module != moduleRef ) )
+            continue;
+
+        if( module->GetFPID() != moduleRef->GetFPID() )
+            continue;
+
+        for( D_PAD* pad = module->Pads();  pad;  pad = pad->Next() )
+        {
+            // Filters changes prohibited.
+            if( aPadShapeFilter && ( pad->GetShape() != aSrcPad.GetShape() ) )
+                continue;
+
+            double currpad_orient = pad->GetOrientation() - module->GetOrientation();
+
+            if( aPadOrientFilter && ( currpad_orient != pad_orient ) )
+                continue;
+
+            if( aPadLayerFilter  &&  pad->GetLayerSet() != aSrcPad.GetLayerSet() )
+                continue;
+
+            if( aPadLayerFilter )
+            {
+                if( pad->GetLayerSet() != aSrcPad.GetLayerSet() )
+                    continue;
+                else
+                    board.m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
+            }
+
+            commit.Modify( pad );
+
+            PAD_TOOL::ImportPadSettings( aSrcPad, *pad );
+        }
+    }
+}
+
+
+
+int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent )
+{
+    auto& selTool = *m_toolMgr->GetTool<SELECTION_TOOL>();
+    const auto& selection = selTool.GetSelection();
+
+    auto& frame = *getEditFrame<PCB_EDIT_FRAME>();
+
+    // not const - can be changed in the dialog
+    D_PAD* srcPad = nullptr;
+
+    if( selection.Size() == 0 )
+    {
+        srcPad = &frame.GetDesignSettings().m_Pad_Master;
+    }
+    else if ( selection.Size() == 1 )
+    {
+        if ( selection[0]->Type() == PCB_PAD_T )
+        {
+            srcPad = static_cast<D_PAD*>( selection[0] );
+        }
+    }
+    else
+    {
+        // multiple selected what to do?
+        // maybe master->selection? same as import multiple?
+    }
+
+    // no valid selection, nothing to do
+    if( !srcPad )
+    {
+        return 0;
+    }
+
+    MODULE* module = srcPad->GetParent();
+
+    if( module != nullptr )
+    {
+        frame.SetMsgPanel( module );
+    }
+
+    int dialogRet;
+    {
+        DIALOG_GLOBAL_PADS_EDITION dlg( &frame, srcPad );
+        dialogRet = dlg.ShowModal();
+    }
+
+    // cancel
+    if( dialogRet == -1 )
+    {
+        return 0;
+    }
+
+    const bool edit_Same_Modules = (dialogRet == 1);
+
+    BOARD_COMMIT commit( &frame );
+
+    globalChangePadSettings( *getModel<BOARD>(), *srcPad, commit,
+                              edit_Same_Modules,
+                              DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
+                              DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
+                              DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter );
+
+    commit.Push( _( "Import pad settings" ) );
+
+    m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true );
+    frame.Refresh();
+
+    return 0;
+}
+
+
+void PAD_TOOL::SetTransitions()
+{
+    Go( &PAD_TOOL::importPadSettings, COMMON_ACTIONS::importPadSettings.MakeEvent() );
+    Go( &PAD_TOOL::exportPadSettings, COMMON_ACTIONS::exportPadSettings.MakeEvent() );
+    Go( &PAD_TOOL::pushPadSettings,   COMMON_ACTIONS::pushPadSettings.MakeEvent() );
+}
diff --git a/pcbnew/tools/pad_tool.h b/pcbnew/tools/pad_tool.h
new file mode 100644
index 000000000..77bed3f77
--- /dev/null
+++ b/pcbnew/tools/pad_tool.h
@@ -0,0 +1,68 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+#ifndef __PAD_TOOL_H
+#define __PAD_TOOL_H
+
+
+#include <tools/pcb_tool.h>
+
+
+/**
+ * Class PAD_TOOL
+ *
+ * Tools relating to pads and pad settings
+ */
+class PAD_TOOL : public PCB_TOOL
+{
+public:
+    PAD_TOOL();
+    ~PAD_TOOL();
+
+    ///> React to model/view changes
+    void Reset( RESET_REASON aReason ) override;
+
+    ///> Basic initalization
+    bool Init() override;
+
+    ///> Bind handlers to corresponding TOOL_ACTIONs
+    void SetTransitions() override;
+
+    ///> Static helper functions for use by legacy tools
+    // When legacy is removed, these can become static in the cpp
+    static void ImportPadSettings( const D_PAD& aSrc, D_PAD& aDest );
+    static void ExportPadSettings( const D_PAD& aSrc, D_PAD& aDest );
+
+private:
+    ///> Import pad settings from board design settings to a pad
+    int importPadSettings( const TOOL_EVENT& aEvent );
+
+    ///> Export pad settings from a pad to the board design settings
+    int exportPadSettings( const TOOL_EVENT& aEvent );
+
+    ///> Push pad settings from a pad to other pads on board or module
+    int pushPadSettings( const TOOL_EVENT& aEvent );
+};
+
+
+#endif // __PAD_TOOL_H
diff --git a/pcbnew/tools/tools_common.cpp b/pcbnew/tools/tools_common.cpp
index d74a3dfb4..540545ff6 100644
--- a/pcbnew/tools/tools_common.cpp
+++ b/pcbnew/tools/tools_common.cpp
@@ -36,6 +36,7 @@
 #include <tools/pcbnew_control.h>
 #include <tools/pcb_editor_control.h>
 #include <tools/placement_tool.h>
+#include <tools/pad_tool.h>
 #include <tools/common_actions.h>
 
 #include <router/router_tool.h>
@@ -54,4 +55,5 @@ void registerAllTools( TOOL_MANAGER *aToolManager )
     aToolManager->RegisterTool( new PCBNEW_CONTROL );
     aToolManager->RegisterTool( new PCB_EDITOR_CONTROL );
     aToolManager->RegisterTool( new PLACEMENT_TOOL );
+    aToolManager->RegisterTool( new PAD_TOOL );
 }
-- 
2.11.0


Follow ups