2017-01-21 21:06:18 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2017-01-21 21:06:18 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2017-01-21 21:06:18 +00:00
|
|
|
|
|
|
|
#include <class_board_item.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <board_commit.h>
|
|
|
|
|
|
|
|
#include <dialogs/dialog_global_pads_edition.h>
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2017-01-21 21:06:18 +00:00
|
|
|
#include "selection_tool.h"
|
2017-02-28 03:04:44 +00:00
|
|
|
#include "pcb_selection_conditions.h"
|
2017-01-21 21:06:18 +00:00
|
|
|
#include "edit_tool.h"
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Pad tools
|
|
|
|
TOOL_ACTION PCB_ACTIONS::copyPadSettings(
|
|
|
|
"pcbnew.PadTool.CopyPadSettings",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-12 23:42:37 +00:00
|
|
|
_( "Copy Pad Properties" ), _( "Copy current pad's properties to the default pad properties" ),
|
2017-02-20 18:10:20 +00:00
|
|
|
copy_pad_settings_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::applyPadSettings(
|
|
|
|
"pcbnew.PadTool.ApplyPadSettings",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-12 23:42:37 +00:00
|
|
|
_( "Apply Pad Properties" ), _( "Copy the default pad properties to the current pad" ),
|
2017-02-20 18:10:20 +00:00
|
|
|
apply_pad_settings_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::pushPadSettings(
|
|
|
|
"pcbnew.PadTool.PushPadSettings",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-12 23:42:37 +00:00
|
|
|
_( "Push Pad Properties..." ), _( "Copy the current pad settings to other pads" ),
|
2017-02-20 18:10:20 +00:00
|
|
|
push_pad_settings_xpm );
|
|
|
|
|
|
|
|
|
2017-01-21 21:06:18 +00:00
|
|
|
class PAD_CONTEXT_MENU : public CONTEXT_MENU
|
|
|
|
{
|
|
|
|
public:
|
2017-02-08 15:45:56 +00:00
|
|
|
|
|
|
|
using SHOW_FUNCTOR = std::function<bool()>;
|
|
|
|
|
2017-02-09 00:54:32 +00:00
|
|
|
PAD_CONTEXT_MENU( bool aEditingFootprint,
|
|
|
|
SHOW_FUNCTOR aHaveGlobalPadSetting ):
|
|
|
|
m_editingFootprint( aEditingFootprint ),
|
2017-09-23 09:20:10 +00:00
|
|
|
m_haveGlobalPadSettings( std::move( aHaveGlobalPadSetting ) )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
SetIcon( pad_xpm );
|
|
|
|
SetTitle( _( "Pads" ) );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Add( PCB_ACTIONS::copyPadSettings );
|
|
|
|
Add( PCB_ACTIONS::applyPadSettings );
|
|
|
|
Add( PCB_ACTIONS::pushPadSettings );
|
2017-02-09 00:54:32 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2017-02-09 00:54:32 +00:00
|
|
|
// show modedit-specific items
|
|
|
|
if( m_editingFootprint )
|
|
|
|
{
|
|
|
|
AppendSeparator();
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Add( PCB_ACTIONS::enumeratePads );
|
2017-02-09 00:54:32 +00:00
|
|
|
}
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
CONTEXT_MENU* create() const override
|
|
|
|
{
|
2017-02-09 00:54:32 +00:00
|
|
|
return new PAD_CONTEXT_MENU( m_editingFootprint, m_haveGlobalPadSettings );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-02-08 15:45:56 +00:00
|
|
|
struct ENABLEMENTS
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
2017-02-08 15:45:56 +00:00
|
|
|
bool canImport;
|
|
|
|
bool canExport;
|
|
|
|
bool canPush;
|
|
|
|
};
|
|
|
|
|
|
|
|
ENABLEMENTS getEnablements( const SELECTION& aSelection )
|
|
|
|
{
|
|
|
|
using S_C = SELECTION_CONDITIONS;
|
|
|
|
ENABLEMENTS enablements;
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2017-02-08 15:45:56 +00:00
|
|
|
auto anyPadSel = S_C::HasType( PCB_PAD_T );
|
2017-02-16 17:39:09 +00:00
|
|
|
auto singlePadSel = S_C::Count( 1 ) && S_C::OnlyType( PCB_PAD_T );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
// Apply pads enabled when any pads selected (it applies to each one
|
2017-02-08 15:45:56 +00:00
|
|
|
// individually), plus need a valid global pad setting
|
2017-02-16 17:39:09 +00:00
|
|
|
enablements.canImport = m_haveGlobalPadSettings() && ( anyPadSel )( aSelection );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
// Copy pads item enabled only when there is a single pad selected
|
|
|
|
// (otherwise how would we know which one to copy?)
|
2017-02-08 15:45:56 +00:00
|
|
|
enablements.canExport = ( singlePadSel )( aSelection );
|
|
|
|
|
|
|
|
// Push pads available when there is a single pad to push from
|
2017-02-16 17:39:09 +00:00
|
|
|
enablements.canPush = ( singlePadSel )( aSelection );
|
2017-02-08 15:45:56 +00:00
|
|
|
|
|
|
|
return enablements;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update() override
|
|
|
|
{
|
|
|
|
auto selTool = getToolManager()->GetTool<SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selTool->GetSelection();
|
|
|
|
|
|
|
|
auto enablements = getEnablements( selection );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Enable( getMenuId( PCB_ACTIONS::applyPadSettings ), enablements.canImport );
|
|
|
|
Enable( getMenuId( PCB_ACTIONS::copyPadSettings ), enablements.canExport );
|
|
|
|
Enable( getMenuId( PCB_ACTIONS::pushPadSettings ), enablements.canPush );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
2017-02-08 15:45:56 +00:00
|
|
|
|
2017-02-09 00:54:32 +00:00
|
|
|
bool m_editingFootprint;
|
2017-02-08 15:45:56 +00:00
|
|
|
SHOW_FUNCTOR m_haveGlobalPadSettings;
|
2017-01-21 21:06:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PAD_TOOL::PAD_TOOL() :
|
2017-02-16 17:39:09 +00:00
|
|
|
PCB_TOOL( "pcbnew.PadTool" ), m_padCopied( false )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PAD_TOOL::~PAD_TOOL()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void PAD_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2017-02-16 17:39:09 +00:00
|
|
|
m_padCopied = false;
|
2017-02-08 15:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PAD_TOOL::haveFootprints()
|
|
|
|
{
|
|
|
|
auto& board = *getModel<BOARD>();
|
|
|
|
return board.m_Modules.GetCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-21 21:06:18 +00:00
|
|
|
bool PAD_TOOL::Init()
|
|
|
|
{
|
2017-02-16 17:39:09 +00:00
|
|
|
auto contextMenu = std::make_shared<PAD_CONTEXT_MENU>( EditingModules(),
|
|
|
|
[this]() { return m_padCopied; } );
|
2017-01-21 21:06:18 +00:00
|
|
|
contextMenu->SetTool( this );
|
|
|
|
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
|
|
|
|
if( selTool )
|
|
|
|
{
|
|
|
|
auto& toolMenu = selTool->GetToolMenu();
|
|
|
|
auto& menu = toolMenu.GetMenu();
|
|
|
|
|
|
|
|
toolMenu.AddSubMenu( contextMenu );
|
|
|
|
|
2018-02-14 23:46:33 +00:00
|
|
|
auto canShowMenuCond = [this, contextMenu] ( const SELECTION& aSel ) {
|
2017-02-08 15:45:56 +00:00
|
|
|
contextMenu->UpdateAll();
|
2018-02-14 23:46:33 +00:00
|
|
|
return frame()->GetToolId() == ID_NO_TOOL_SELECTED
|
|
|
|
&& haveFootprints()
|
|
|
|
&& contextMenu->HasEnabledItems();
|
2017-02-08 15:45:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// show menu when there is a footprint, and the menu has any items
|
|
|
|
auto showCond = canShowMenuCond &&
|
|
|
|
( SELECTION_CONDITIONS::HasType( PCB_PAD_T )
|
|
|
|
|| SELECTION_CONDITIONS::Count( 0 ) );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2018-02-12 23:42:37 +00:00
|
|
|
menu.AddMenu( contextMenu.get(), false, showCond, 1000 );
|
2018-02-14 23:46:33 +00:00
|
|
|
|
|
|
|
// we need a separator only when the selection is empty
|
|
|
|
auto separatorCond = canShowMenuCond && SELECTION_CONDITIONS::Count( 0 );
|
|
|
|
menu.AddSeparator( separatorCond, 1000 );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
int PAD_TOOL::applyPadSettings( const TOOL_EVENT& aEvent )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
2017-02-10 19:44:02 +00:00
|
|
|
D_PAD& destPad = static_cast<D_PAD&>( *item );
|
|
|
|
destPad.ImportSettingsFromMaster( masterPad );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 23:42:37 +00:00
|
|
|
commit.Push( _( "Apply Pad Properties" ) );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
2017-01-21 21:06:18 +00:00
|
|
|
frame.Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
int PAD_TOOL::copyPadSettings( const TOOL_EVENT& aEvent )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
// can only copy from a single pad
|
2017-01-21 21:06:18 +00:00
|
|
|
if( selection.Size() == 1 )
|
|
|
|
{
|
|
|
|
auto item = selection[0];
|
|
|
|
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
const auto& selPad = static_cast<const D_PAD&>( *item );
|
2017-02-10 19:44:02 +00:00
|
|
|
masterPad.ImportSettingsFromMaster( selPad );
|
2017-02-16 17:39:09 +00:00
|
|
|
m_padCopied = true;
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
// If there is no module, we can't make the comparisons to see which
|
|
|
|
// pads to apply the source pad settings to
|
2017-01-21 21:06:18 +00:00
|
|
|
if( moduleRef == nullptr )
|
|
|
|
{
|
2017-02-04 09:21:41 +00:00
|
|
|
wxLogDebug( "globalChangePadSettings() Error: NULL module" );
|
2017-01-21 21:06:18 +00:00
|
|
|
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;
|
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
// 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 );
|
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
// Apply source pad settings to this pad
|
2017-02-10 19:44:02 +00:00
|
|
|
pad->ImportSettingsFromMaster( aSrcPad );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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?
|
2017-02-03 18:56:56 +00:00
|
|
|
// maybe master->selection? same as apply multiple?
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
2018-02-12 23:42:37 +00:00
|
|
|
commit.Push( _( "Apply Pad Properties" ) );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2017-04-20 10:10:53 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionModified, true );
|
2017-01-21 21:06:18 +00:00
|
|
|
frame.Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-16 17:39:09 +00:00
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void PAD_TOOL::setTransitions()
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &PAD_TOOL::applyPadSettings, PCB_ACTIONS::applyPadSettings.MakeEvent() );
|
|
|
|
Go( &PAD_TOOL::copyPadSettings, PCB_ACTIONS::copyPadSettings.MakeEvent() );
|
|
|
|
Go( &PAD_TOOL::pushPadSettings, PCB_ACTIONS::pushPadSettings.MakeEvent() );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|