← Back to team overview

kicad-developers team mailing list archive

Re: Pad import/export/push and modedit mirror

 

Sorry, attached the wrong version of the "import export" patch - this
is the correct sequence.

On Wed, Jan 25, 2017 at 12:41 AM, John Beard <john.j.beard@xxxxxxxxx> wrote:
> 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 e170571678476336da2f4074aa7b3d58e88bdbc3 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 1/2] Add pad import/export/push to GAL canvas

This implements the pad import/export to the board's master pad setting
in the GAL canvases.

Implemented as a new GAL tool: PAD_TOOL.

It uses the same dialog, which has been split out into its own files in
pcbnew/dialogs, rather than along with frame methods in
pcbnew/globaleditpad.cpp.

Fixes: lp:1619304
* https://bugs.launchpad.net/kicad/+bug/1619304
---
 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/moduleframe.cpp                        |   3 +
 pcbnew/tools/common_actions.cpp               |  18 ++
 pcbnew/tools/common_actions.h                 |  10 +
 pcbnew/tools/pad_tool.cpp                     | 395 ++++++++++++++++++++++++++
 pcbnew/tools/pad_tool.h                       |  64 +++++
 pcbnew/tools/tools_common.cpp                 |   3 +
 10 files changed, 643 insertions(+), 90 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 f6f702353..4b10ca678 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
@@ -292,6 +293,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/moduleframe.cpp b/pcbnew/moduleframe.cpp
index 3a283201f..43ce535b5 100644
--- a/pcbnew/moduleframe.cpp
+++ b/pcbnew/moduleframe.cpp
@@ -67,6 +67,7 @@
 #include "tools/module_tools.h"
 #include "tools/placement_tool.h"
 #include "tools/picker_tool.h"
+#include "tools/pad_tool.h"
 #include "tools/common_actions.h"
 
 
@@ -950,6 +951,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools()
     m_toolManager->RegisterTool( new SELECTION_TOOL );
     m_toolManager->RegisterTool( new ZOOM_TOOL );
     m_toolManager->RegisterTool( new EDIT_TOOL );
+    m_toolManager->RegisterTool( new PAD_TOOL );
     m_toolManager->RegisterTool( new DRAWING_TOOL );
     m_toolManager->RegisterTool( new POINT_EDITOR );
     m_toolManager->RegisterTool( new PCBNEW_CONTROL );
@@ -957,6 +959,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools()
     m_toolManager->RegisterTool( new PLACEMENT_TOOL );
     m_toolManager->RegisterTool( new PICKER_TOOL );
 
+
     m_toolManager->GetTool<SELECTION_TOOL>()->SetEditModules( true );
     m_toolManager->GetTool<EDIT_TOOL>()->SetEditModules( true );
     m_toolManager->GetTool<DRAWING_TOOL>()->SetEditModules( true );
diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp
index 209cbcdee..dc65bf6e3 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..c66ce2c71
--- /dev/null
+++ b/pcbnew/tools/pad_tool.cpp
@@ -0,0 +1,395 @@
+/*
+ * 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 "selection_conditions.h"
+#include "edit_tool.h"
+
+class PAD_CONTEXT_MENU : public CONTEXT_MENU
+{
+public:
+    PAD_CONTEXT_MENU()
+    {
+        SetIcon( pad_xpm );
+        SetTitle( _( "Pads" ) );
+
+        Add( COMMON_ACTIONS::importPadSettings );
+        Add( COMMON_ACTIONS::exportPadSettings );
+        Add( COMMON_ACTIONS::pushPadSettings );
+    }
+
+protected:
+
+    CONTEXT_MENU* create() const override
+    {
+        return new PAD_CONTEXT_MENU();
+    }
+
+private:
+
+    void update() override
+    {
+        auto selTool = getToolManager()->GetTool<SELECTION_TOOL>();
+        const SELECTION& selection = selTool->GetSelection();
+
+        auto anyPadSel = SELECTION_CONDITIONS::HasType( PCB_PAD_T );
+
+        auto singlePadSel = SELECTION_CONDITIONS::Count( 1 )
+                                && SELECTION_CONDITIONS::OnlyType( PCB_PAD_T );
+        auto emptySel = SELECTION_CONDITIONS::Count( 0 );
+
+        // Import pads enabled when any pads selected (it applies to each one
+        // individually)
+        const bool canImport = ( anyPadSel )( selection );
+        Enable( getMenuId( COMMON_ACTIONS::importPadSettings ), canImport );
+
+        // Export pads item enabled only when there is a single pad selected
+        // (otherwise how would we know which one to export?)
+        const bool canExport = ( singlePadSel )( selection );
+        Enable( getMenuId( COMMON_ACTIONS::exportPadSettings ), canExport );
+
+        // Push pads available when nothing selected, or a single pad
+        const bool canPush = ( singlePadSel || emptySel ) ( selection );
+        Enable( getMenuId( COMMON_ACTIONS::pushPadSettings ), canPush);
+    }
+};
+
+
+PAD_TOOL::PAD_TOOL() :
+        PCB_TOOL( "pcbnew.PadTool" )
+{
+}
+
+
+PAD_TOOL::~PAD_TOOL()
+{}
+
+
+void PAD_TOOL::Reset( RESET_REASON aReason )
+{
+}
+
+
+bool PAD_TOOL::Init()
+{
+    auto contextMenu = std::make_shared<PAD_CONTEXT_MENU>();
+    contextMenu->SetTool( this );
+
+    SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
+
+    if( selTool )
+    {
+        auto& toolMenu = selTool->GetToolMenu();
+        auto& menu = toolMenu.GetMenu();
+
+        toolMenu.AddSubMenu( contextMenu );
+
+        // show menu when any pads selected, or nothing selected
+        // (push settings works on no selection)
+        auto showCond = SELECTION_CONDITIONS::HasType( PCB_PAD_T )
+                        || SELECTION_CONDITIONS::Count( 0 );
+
+        menu.AddMenu( contextMenu.get(), false, showCond );
+    }
+
+    return true;
+}
+
+/**
+ * Function doExportPadSettings
+ *
+ * Export a given pad to the destination pad. Normally, the destination
+ * would be a board reference settings master pad.
+ */
+static void doExportPadSettings( 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 doImportPadSettings
+ *
+ * Import pad settings from a "reference" source to a destination.
+ * Often, the reference source will be a board reference settings
+ * master pad.
+ */
+static void doImportPadSettings( 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 );
+
+            doImportPadSettings( 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 );
+
+            doExportPadSettings( 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 there is no moudle, we can't make the comparisons to see which
+    // pads to aply the src pad settings to
+    if( moduleRef == nullptr )
+    {
+        wxLogDebug( _( "globalChangePadSettings() 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 && ( pad->GetLayerSet() != aSrcPad.GetLayerSet() ) )
+                continue;
+
+            commit.Modify( pad );
+
+            // copy source pad settings to this pad
+            doImportPadSettings( 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 nothing selected, use the master pad setting,
+    // otherwise, if one pad selected, use the selected pad
+    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..4d4458c41
--- /dev/null
+++ b/pcbnew/tools/pad_tool.h
@@ -0,0 +1,64 @@
+/*
+ * 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 CONTEXT_MENU;
+
+/**
+ * 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;
+
+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..fd727ff93 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>
@@ -49,9 +50,11 @@ void registerAllTools( TOOL_MANAGER *aToolManager )
     aToolManager->RegisterTool( new ROUTER_TOOL );
     aToolManager->RegisterTool( new LENGTH_TUNER_TOOL );
     aToolManager->RegisterTool( new EDIT_TOOL );
+    aToolManager->RegisterTool( new PAD_TOOL );
     aToolManager->RegisterTool( new DRAWING_TOOL );
     aToolManager->RegisterTool( new POINT_EDITOR );
     aToolManager->RegisterTool( new PCBNEW_CONTROL );
     aToolManager->RegisterTool( new PCB_EDITOR_CONTROL );
     aToolManager->RegisterTool( new PLACEMENT_TOOL );
+
 }
-- 
2.11.0

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


Follow ups

References