2017-01-21 21:06:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-24 16:08:33 +00:00
|
|
|
* Copyright (C) 2017-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-21 21:06:18 +00:00
|
|
|
*
|
|
|
|
* 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 <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>
|
2020-06-27 11:57:40 +00:00
|
|
|
#include <class_edge_mod.h>
|
2017-01-21 21:06:18 +00:00
|
|
|
#include <board_commit.h>
|
2018-07-05 16:14:19 +00:00
|
|
|
#include <dialogs/dialog_push_pad_properties.h>
|
2019-06-08 21:48:22 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/selection_tool.h>
|
|
|
|
#include <tools/pcb_selection_conditions.h>
|
|
|
|
#include <tools/edit_tool.h>
|
2019-06-09 23:51:25 +00:00
|
|
|
#include <dialogs/dialog_enum_pads.h>
|
2020-06-27 11:57:40 +00:00
|
|
|
#include <pad_naming.h>
|
|
|
|
#include <widgets/infobar.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2017-01-21 21:06:18 +00:00
|
|
|
PAD_TOOL::PAD_TOOL() :
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.PadTool" ),
|
2020-06-27 11:57:40 +00:00
|
|
|
m_padCopied( false ),
|
|
|
|
m_editPad( niluuid )
|
2018-07-05 16:14:19 +00:00
|
|
|
{}
|
2017-01-21 21:06:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
PAD_TOOL::~PAD_TOOL()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void PAD_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2020-06-27 11:57:40 +00:00
|
|
|
if( aReason == MODEL_RELOAD )
|
|
|
|
m_lastPadName = wxT( "1" );
|
|
|
|
|
2017-02-16 17:39:09 +00:00
|
|
|
m_padCopied = false;
|
2020-06-27 11:57:40 +00:00
|
|
|
m_editPad = niluuid;
|
2017-02-08 15:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-21 21:06:18 +00:00
|
|
|
bool PAD_TOOL::Init()
|
|
|
|
{
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
|
|
|
|
if( selTool )
|
|
|
|
{
|
2019-08-24 16:08:33 +00:00
|
|
|
// Add context menu entries that are displayed when selection tool is active
|
|
|
|
CONDITIONAL_MENU& menu = selTool->GetToolMenu().GetMenu();
|
|
|
|
|
2019-11-26 18:42:11 +00:00
|
|
|
SELECTION_CONDITION padSel = SELECTION_CONDITIONS::HasType( PCB_PAD_T );
|
|
|
|
SELECTION_CONDITION singlePadSel = SELECTION_CONDITIONS::Count( 1 ) &&
|
|
|
|
SELECTION_CONDITIONS::OnlyType( PCB_PAD_T );
|
2019-08-24 16:08:33 +00:00
|
|
|
|
2020-06-27 11:57:40 +00:00
|
|
|
auto explodeCondition = [&]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_editPad == niluuid
|
|
|
|
&& aSel.Size() == 1 && aSel[0]->Type() == PCB_PAD_T;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto recombineCondition = [&]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_editPad != niluuid;
|
|
|
|
};
|
|
|
|
|
2019-08-24 16:08:33 +00:00
|
|
|
menu.AddSeparator( 400 );
|
2019-11-26 18:42:11 +00:00
|
|
|
|
|
|
|
if( m_editModules )
|
|
|
|
{
|
2020-06-27 11:57:40 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::enumeratePads, SELECTION_CONDITIONS::ShowAlways, 400 );
|
|
|
|
menu.AddItem( PCB_ACTIONS::recombinePad, recombineCondition, 400 );
|
|
|
|
menu.AddItem( PCB_ACTIONS::explodePad, explodeCondition, 400 );
|
2019-11-26 18:42:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-27 11:57:40 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::copyPadSettings, singlePadSel, 400 );
|
|
|
|
menu.AddItem( PCB_ACTIONS::applyPadSettings, padSel, 400 );
|
|
|
|
menu.AddItem( PCB_ACTIONS::pushPadSettings, singlePadSel, 400 );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
int PAD_TOOL::pastePadProperties( const TOOL_EVENT& aEvent )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
auto& selTool = *m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const auto& selection = selTool.GetSelection();
|
2019-06-09 23:51:25 +00:00
|
|
|
const D_PAD& masterPad = frame()->GetDesignSettings().m_Pad_Master;
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
BOARD_COMMIT commit( frame() );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
// for every selected pad, paste global settings
|
2017-01-21 21:06:18 +00:00
|
|
|
for( auto item : selection )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
commit.Modify( item );
|
2019-06-13 13:34:38 +00:00
|
|
|
static_cast<D_PAD&>( *item ).ImportSettingsFrom( masterPad );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
commit.Push( _( "Paste Pad Properties" ) );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2019-06-09 23:51:25 +00:00
|
|
|
frame()->Refresh();
|
2017-01-21 21:06:18 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
D_PAD& masterPad = frame()->GetDesignSettings().m_Pad_Master;
|
2017-01-21 21:06:18 +00:00
|
|
|
|
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 );
|
2019-06-13 13:34:38 +00:00
|
|
|
masterPad.ImportSettingsFrom( selPad );
|
2017-02-16 17:39:09 +00:00
|
|
|
m_padCopied = true;
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
static void doPushPadProperties( BOARD& board, const D_PAD& aSrcPad, BOARD_COMMIT& commit,
|
|
|
|
bool aSameFootprints,
|
|
|
|
bool aPadShapeFilter,
|
|
|
|
bool aPadOrientFilter,
|
2019-09-08 22:50:17 +00:00
|
|
|
bool aPadLayerFilter,
|
|
|
|
bool aPadTypeFilter )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
const MODULE* moduleRef = aSrcPad.GetParent();
|
|
|
|
|
|
|
|
double pad_orient = aSrcPad.GetOrientation() - moduleRef->GetOrientation();
|
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto module : board.Modules() )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
if( !aSameFootprints && ( module != moduleRef ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( module->GetFPID() != moduleRef->GetFPID() )
|
|
|
|
continue;
|
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : module->Pads() )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2019-09-08 22:50:17 +00:00
|
|
|
if( aPadTypeFilter && ( pad->GetAttribute() != aSrcPad.GetAttribute() ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Special-case for aperture pads
|
|
|
|
if( aPadTypeFilter && pad->GetAttribute() == PAD_ATTRIB_CONN )
|
|
|
|
{
|
|
|
|
if( pad->IsAperturePad() != aSrcPad.IsAperturePad() )
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-21 21:06:18 +00:00
|
|
|
|
|
|
|
commit.Modify( pad );
|
|
|
|
|
2017-02-03 18:56:56 +00:00
|
|
|
// Apply source pad settings to this pad
|
2019-06-13 13:34:38 +00:00
|
|
|
pad->ImportSettingsFrom( aSrcPad );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-07-05 16:14:19 +00:00
|
|
|
auto& selTool = *m_toolMgr->GetTool<SELECTION_TOOL>();
|
2017-01-21 21:06:18 +00:00
|
|
|
const auto& selection = selTool.GetSelection();
|
2018-07-05 16:14:19 +00:00
|
|
|
D_PAD* srcPad;
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
|
|
|
|
srcPad = static_cast<D_PAD*>( selection[0] );
|
2017-01-21 21:06:18 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
MODULE* module = srcPad->GetParent();
|
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
if( !module )
|
|
|
|
return 0;
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
frame()->SetMsgPanel( module );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
DIALOG_PUSH_PAD_PROPERTIES dlg( frame() );
|
2018-07-05 16:14:19 +00:00
|
|
|
int dialogRet = dlg.ShowModal();
|
|
|
|
|
|
|
|
if( dialogRet == wxID_CANCEL )
|
2017-01-21 21:06:18 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
const bool edit_Same_Modules = (dialogRet == 1);
|
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
BOARD_COMMIT commit( frame() );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2018-07-05 16:14:19 +00:00
|
|
|
doPushPadProperties( *getModel<BOARD>(), *srcPad, commit, edit_Same_Modules,
|
|
|
|
DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Shape_Filter,
|
|
|
|
DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Orient_Filter,
|
2019-09-08 22:50:17 +00:00
|
|
|
DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Layer_Filter,
|
|
|
|
DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Type_Filter );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2019-01-02 00:14:11 +00:00
|
|
|
commit.Push( _( "Push Pad Settings" ) );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
2019-06-09 23:51:25 +00:00
|
|
|
frame()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-07-03 17:08:28 +00:00
|
|
|
if( !board()->GetFirstModule() || board()->GetFirstModule()->Pads().empty() )
|
2019-06-09 23:51:25 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
DIALOG_ENUM_PADS settingsDlg( frame() );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() != wxID_OK )
|
|
|
|
return 0;
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
frame()->PushTool( tool );
|
2019-06-09 23:51:25 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
GENERAL_COLLECTOR collector;
|
|
|
|
const KICAD_T types[] = { PCB_PAD_T, EOT };
|
|
|
|
|
|
|
|
GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
|
|
|
|
guide.SetIgnoreMTextsMarkedNoShow( true );
|
|
|
|
guide.SetIgnoreMTextsOnBack( true );
|
|
|
|
guide.SetIgnoreMTextsOnFront( true );
|
|
|
|
guide.SetIgnoreModulesVals( true );
|
|
|
|
guide.SetIgnoreModulesRefs( true );
|
|
|
|
|
|
|
|
int seqPadNum = settingsDlg.GetStartNumber();
|
|
|
|
wxString padPrefix = settingsDlg.GetPrefix();
|
|
|
|
std::deque<int> storedPadNumbers;
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
getViewControls()->ShowCursor( true );
|
|
|
|
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
|
|
|
|
std::list<D_PAD*> selectedPads;
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
std::map<wxString, std::pair<int, wxString>> oldNames;
|
|
|
|
bool isFirstPoint = true; // used to be sure oldCursorPos will be initialized at least once.
|
|
|
|
|
|
|
|
STATUS_TEXT_POPUP statusPopup( frame() );
|
2019-07-11 23:28:46 +00:00
|
|
|
wxString msg = _( "Click on pad %s%d\nPress <esc> to cancel or double-click to commit" );
|
|
|
|
statusPopup.SetText( wxString::Format( msg, padPrefix, seqPadNum ) );
|
2019-06-09 23:51:25 +00:00
|
|
|
statusPopup.Popup();
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_BULLSEYE );
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
commit.Revert();
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
frame()->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
commit.Push( _( "Renumber pads" ) );
|
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
frame()->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
|
|
|
selectedPads.clear();
|
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
|
|
|
|
// Be sure the old cursor mouse position was initialized:
|
|
|
|
if( isFirstPoint )
|
|
|
|
{
|
|
|
|
oldCursorPos = cursorPos;
|
|
|
|
isFirstPoint = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wxWidgets deliver mouse move events not frequently enough, resulting in skipping
|
|
|
|
// pads if the user moves cursor too fast. To solve it, create a line that approximates
|
|
|
|
// the mouse move and search pads that are on the line.
|
|
|
|
int distance = ( cursorPos - oldCursorPos ).EuclideanNorm();
|
|
|
|
// Search will be made every 0.1 mm:
|
|
|
|
int segments = distance / int( 0.1*IU_PER_MM ) + 1;
|
|
|
|
const wxPoint line_step( ( cursorPos - oldCursorPos ) / segments );
|
|
|
|
|
|
|
|
collector.Empty();
|
|
|
|
|
|
|
|
for( int j = 0; j < segments; ++j )
|
|
|
|
{
|
2019-08-24 16:08:33 +00:00
|
|
|
wxPoint testpoint( cursorPos.x - j * line_step.x, cursorPos.y - j * line_step.y );
|
2019-06-09 23:51:25 +00:00
|
|
|
collector.Collect( board(), types, testpoint, guide );
|
|
|
|
|
|
|
|
for( int i = 0; i < collector.GetCount(); ++i )
|
|
|
|
selectedPads.push_back( static_cast<D_PAD*>( collector[i] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedPads.unique();
|
|
|
|
|
|
|
|
for( D_PAD* pad : selectedPads )
|
|
|
|
{
|
|
|
|
// If pad was not selected, then enumerate it
|
|
|
|
if( !pad->IsSelected() )
|
|
|
|
{
|
|
|
|
commit.Modify( pad );
|
|
|
|
|
|
|
|
// Rename pad and store the old name
|
|
|
|
int newval;
|
|
|
|
|
|
|
|
if( storedPadNumbers.size() > 0 )
|
|
|
|
{
|
|
|
|
newval = storedPadNumbers.front();
|
|
|
|
storedPadNumbers.pop_front();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newval = seqPadNum++;
|
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix, newval );
|
2019-06-09 23:51:25 +00:00
|
|
|
oldNames[newName] = { newval, pad->GetName() };
|
|
|
|
pad->SetName( newName );
|
2020-06-27 11:57:40 +00:00
|
|
|
SetLastPadName( newName );
|
2019-06-09 23:51:25 +00:00
|
|
|
pad->SetSelected();
|
|
|
|
getView()->Update( pad );
|
|
|
|
|
|
|
|
// Ensure the popup text shows the correct next value
|
|
|
|
if( storedPadNumbers.size() > 0 )
|
|
|
|
newval = storedPadNumbers.front();
|
|
|
|
else
|
|
|
|
newval = seqPadNum;
|
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
statusPopup.SetText( wxString::Format( msg, padPrefix, newval ) );
|
2019-06-09 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
// ... or restore the old name if it was enumerated and clicked again
|
2019-06-09 23:51:25 +00:00
|
|
|
else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
auto it = oldNames.find( pad->GetName() );
|
|
|
|
wxASSERT( it != oldNames.end() );
|
|
|
|
|
|
|
|
if( it != oldNames.end() )
|
|
|
|
{
|
|
|
|
storedPadNumbers.push_back( it->second.first );
|
|
|
|
pad->SetName( it->second.second );
|
2020-06-27 11:57:40 +00:00
|
|
|
SetLastPadName( it->second.second );
|
2019-06-09 23:51:25 +00:00
|
|
|
oldNames.erase( it );
|
|
|
|
|
2019-07-11 23:28:46 +00:00
|
|
|
int newval = storedPadNumbers.front();
|
|
|
|
|
|
|
|
statusPopup.SetText( wxString::Format( msg, padPrefix, newval ) );
|
2019-06-09 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->ClearSelected();
|
|
|
|
getView()->Update( pad );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( ( evt->IsKeyPressed() && evt->KeyCode() == WXK_RETURN ) ||
|
|
|
|
evt->IsDblClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
commit.Push( _( "Renumber pads" ) );
|
2019-07-15 12:15:58 +00:00
|
|
|
frame()->PopTool( tool );
|
2019-06-09 23:51:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( selection() );
|
|
|
|
}
|
|
|
|
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
// Prepare the next loop by updating the old cursor mouse position
|
|
|
|
// to this last mouse cursor position
|
|
|
|
oldCursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto p : board()->GetFirstModule()->Pads() )
|
|
|
|
{
|
|
|
|
p->ClearSelected();
|
|
|
|
view->Update( p );
|
|
|
|
}
|
|
|
|
|
|
|
|
statusPopup.Hide();
|
2017-01-21 21:06:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-16 17:39:09 +00:00
|
|
|
|
2020-06-27 11:57:40 +00:00
|
|
|
int PAD_TOOL::PlacePad( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( !board()->GetFirstModule() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
|
|
|
|
{
|
|
|
|
PAD_PLACER( PAD_TOOL* aPadTool )
|
|
|
|
{
|
|
|
|
m_padTool = aPadTool;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PAD_PLACER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
|
|
|
{
|
|
|
|
D_PAD* pad = new D_PAD( m_board->GetFirstModule() );
|
|
|
|
|
|
|
|
pad->ImportSettingsFrom( m_frame->GetDesignSettings().m_Pad_Master );
|
|
|
|
|
|
|
|
if( PAD_NAMING::PadCanHaveName( *pad ) )
|
|
|
|
{
|
|
|
|
wxString padName = m_padTool->GetLastPadName();
|
|
|
|
padName = m_board->GetFirstModule()->GetNextPadName( padName );
|
|
|
|
pad->SetName( padName );
|
|
|
|
m_padTool->SetLastPadName( padName );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::unique_ptr<BOARD_ITEM>( pad );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
|
|
|
|
{
|
|
|
|
D_PAD* pad = dynamic_cast<D_PAD*>( aItem );
|
|
|
|
|
|
|
|
if( pad )
|
|
|
|
{
|
|
|
|
m_frame->GetDesignSettings().m_Pad_Master.ImportSettingsFrom( *pad );
|
|
|
|
pad->SetLocalCoord();
|
|
|
|
aCommit.Add( aItem );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PAD_TOOL* m_padTool;
|
|
|
|
};
|
|
|
|
|
|
|
|
PAD_PLACER placer( this );
|
|
|
|
|
|
|
|
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place pad" ),
|
|
|
|
IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
|
|
|
|
WX_INFOBAR* infoBar = frame()->GetInfoBar();
|
|
|
|
PCBNEW_SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( m_editPad != niluuid )
|
|
|
|
{
|
|
|
|
D_PAD* pad = dynamic_cast<D_PAD*>( frame()->GetItem( m_editPad ) );
|
|
|
|
|
|
|
|
if( pad )
|
|
|
|
recombinePad( pad );
|
|
|
|
|
|
|
|
m_editPad = niluuid;
|
|
|
|
}
|
|
|
|
else if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
D_PAD* pad = static_cast<D_PAD*>( selection[0] );
|
|
|
|
PCB_LAYER_ID layer = explodePad( pad );
|
|
|
|
|
|
|
|
m_wasHighContrast = opts.m_ContrastModeDisplay;
|
|
|
|
frame()->SetActiveLayer( layer );
|
|
|
|
|
|
|
|
if( !opts.m_ContrastModeDisplay )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::highContrastMode, false );
|
|
|
|
|
|
|
|
if( PCB_ACTIONS::explodePad.GetHotKey() == PCB_ACTIONS::recombinePad.GetHotKey() )
|
|
|
|
msg.Printf( _( "Pad Edit Mode. Press %s again to exit." ),
|
|
|
|
KeyNameFromKeyCode( PCB_ACTIONS::recombinePad.GetHotKey() ) );
|
|
|
|
else
|
|
|
|
msg.Printf( _( "Pad Edit Mode. Press %s to exit." ),
|
|
|
|
KeyNameFromKeyCode( PCB_ACTIONS::recombinePad.GetHotKey() ) );
|
|
|
|
|
|
|
|
infoBar->RemoveAllButtons();
|
|
|
|
infoBar->ShowMessage( msg, wxICON_INFORMATION );
|
|
|
|
|
|
|
|
m_editPad = pad->m_Uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_editPad == niluuid )
|
|
|
|
{
|
|
|
|
if( m_wasHighContrast != opts.m_ContrastModeDisplay )
|
|
|
|
m_toolMgr->RunAction( ACTIONS::highContrastMode, false );
|
|
|
|
|
|
|
|
infoBar->Dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCB_LAYER_ID PAD_TOOL::explodePad( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer;
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
|
|
|
|
if( aPad->IsOnLayer( F_Cu ) )
|
|
|
|
layer = F_Cu;
|
|
|
|
else if( aPad->IsOnLayer( B_Cu ) )
|
|
|
|
layer = B_Cu;
|
|
|
|
else
|
|
|
|
layer = *aPad->GetLayerSet().UIOrder();
|
|
|
|
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
|
|
|
|
{
|
|
|
|
commit.Modify( aPad );
|
|
|
|
|
|
|
|
for( const std::shared_ptr<DRAWSEGMENT>& primitive : aPad->GetPrimitives() )
|
|
|
|
{
|
|
|
|
EDGE_MODULE* ds = new EDGE_MODULE( board()->GetFirstModule() );
|
|
|
|
|
|
|
|
ds->SetShape( primitive->GetShape() );
|
|
|
|
ds->SetWidth( primitive->GetWidth() );
|
|
|
|
ds->SetStart( primitive->GetStart() );
|
|
|
|
ds->SetEnd( primitive->GetEnd() );
|
|
|
|
ds->SetBezControl1( primitive->GetBezControl1() );
|
|
|
|
ds->SetBezControl2( primitive->GetBezControl2() );
|
|
|
|
ds->SetAngle( primitive->GetAngle() );
|
|
|
|
ds->SetPolyShape( primitive->GetPolyShape() );
|
|
|
|
ds->SetLocalCoord();
|
|
|
|
ds->Move( aPad->GetPosition() );
|
|
|
|
ds->Rotate( aPad->GetPosition(), aPad->GetOrientation() );
|
|
|
|
ds->SetLayer( layer );
|
|
|
|
|
|
|
|
commit.Add( ds );
|
|
|
|
}
|
|
|
|
|
|
|
|
aPad->SetShape( aPad->GetAnchorPadShape() );
|
|
|
|
aPad->DeletePrimitivesList();
|
|
|
|
m_editPad = aPad->m_Uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( _("Edit pad shapes") );
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PAD_TOOL::recombinePad( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
auto findNext = [&]( PCB_LAYER_ID aLayer ) -> EDGE_MODULE*
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET padPoly;
|
|
|
|
aPad->TransformShapeWithClearanceToPolygon( padPoly, 0 );
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : board()->GetFirstModule()->GraphicalItems() )
|
|
|
|
{
|
|
|
|
DRAWSEGMENT* draw = dynamic_cast<DRAWSEGMENT*>( item );
|
|
|
|
|
|
|
|
if( !draw || ( draw->GetEditFlags() & STRUCT_DELETED ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( draw->GetLayer() != aLayer )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SHAPE_POLY_SET drawPoly;
|
|
|
|
draw->TransformShapeWithClearanceToPolygon( drawPoly, 0 );
|
|
|
|
drawPoly.BooleanIntersection( padPoly, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
if( !drawPoly.IsEmpty() )
|
|
|
|
return (EDGE_MODULE*) item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
PCB_LAYER_ID layer;
|
|
|
|
|
|
|
|
if( aPad->IsOnLayer( F_Cu ) )
|
|
|
|
layer = F_Cu;
|
|
|
|
else if( aPad->IsOnLayer( B_Cu ) )
|
|
|
|
layer = B_Cu;
|
|
|
|
else
|
|
|
|
layer = *aPad->GetLayerSet().UIOrder();
|
|
|
|
|
|
|
|
while( EDGE_MODULE* edge = findNext( layer ) )
|
|
|
|
{
|
|
|
|
commit.Modify( aPad );
|
|
|
|
|
|
|
|
// We've found an intersecting item. First convert the pad to a custom-shape
|
|
|
|
// pad (if it isn't already)
|
|
|
|
//
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_RECT || aPad->GetShape() == PAD_SHAPE_CIRCLE )
|
|
|
|
{
|
|
|
|
aPad->SetAnchorPadShape( aPad->GetShape() );
|
|
|
|
}
|
|
|
|
else if( aPad->GetShape() != PAD_SHAPE_CUSTOM )
|
|
|
|
{
|
|
|
|
// Create a new minimally-sized circular anchor and convert existing pad
|
|
|
|
// to a polygon primitive
|
|
|
|
SHAPE_POLY_SET existingOutline;
|
|
|
|
int maxError = board()->GetDesignSettings().m_MaxError;
|
|
|
|
aPad->TransformShapeWithClearanceToPolygon( existingOutline, 0, maxError );
|
|
|
|
|
|
|
|
aPad->SetAnchorPadShape( PAD_SHAPE_CIRCLE );
|
2020-06-28 22:34:10 +00:00
|
|
|
wxSize minAnnulus( Millimeter2iu( 0.2 ), Millimeter2iu( 0.2 ) );
|
|
|
|
aPad->SetSize( aPad->GetDrillSize() + minAnnulus );
|
2020-06-27 11:57:40 +00:00
|
|
|
aPad->SetOffset( wxPoint( 0, 0 ) );
|
|
|
|
|
|
|
|
DRAWSEGMENT* shape = new DRAWSEGMENT;
|
|
|
|
shape->SetShape( S_POLYGON );
|
|
|
|
shape->SetPolyShape( existingOutline );
|
|
|
|
shape->Move( - aPad->GetPosition() );
|
|
|
|
shape->Rotate( wxPoint( 0, 0 ), - aPad->GetOrientation() );
|
|
|
|
|
|
|
|
aPad->AddPrimitive( shape );
|
|
|
|
}
|
|
|
|
|
|
|
|
aPad->SetShape( PAD_SHAPE_CUSTOM );
|
|
|
|
|
|
|
|
// Now add the new shape to the primitives list
|
|
|
|
//
|
|
|
|
DRAWSEGMENT* ds = new DRAWSEGMENT;
|
|
|
|
|
|
|
|
ds->SetShape( edge->GetShape() );
|
|
|
|
ds->SetWidth( edge->GetWidth() );
|
|
|
|
ds->SetStart( edge->GetStart() );
|
|
|
|
ds->SetEnd( edge->GetEnd() );
|
|
|
|
ds->SetBezControl1( edge->GetBezControl1() );
|
|
|
|
ds->SetBezControl2( edge->GetBezControl2() );
|
|
|
|
ds->SetAngle( edge->GetAngle() );
|
|
|
|
ds->SetPolyShape( edge->GetPolyShape() );
|
|
|
|
|
|
|
|
ds->Move( - aPad->GetPosition() );
|
|
|
|
ds->Rotate( wxPoint( 0, 0 ), - aPad->GetOrientation() );
|
|
|
|
aPad->AddPrimitive( ds );
|
|
|
|
|
|
|
|
edge->SetFlags( STRUCT_DELETED );
|
|
|
|
commit.Remove( edge );
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push(_("Recombine pads") );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void PAD_TOOL::setTransitions()
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
2020-06-27 11:57:40 +00:00
|
|
|
Go( &PAD_TOOL::pastePadProperties, PCB_ACTIONS::applyPadSettings.MakeEvent() );
|
|
|
|
Go( &PAD_TOOL::copyPadSettings, PCB_ACTIONS::copyPadSettings.MakeEvent() );
|
|
|
|
Go( &PAD_TOOL::pushPadSettings, PCB_ACTIONS::pushPadSettings.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &PAD_TOOL::PlacePad, PCB_ACTIONS::placePad.MakeEvent() );
|
|
|
|
Go( &PAD_TOOL::EnumeratePads, PCB_ACTIONS::enumeratePads.MakeEvent() );
|
2019-11-26 18:42:11 +00:00
|
|
|
|
2020-06-27 11:57:40 +00:00
|
|
|
Go( &PAD_TOOL::EditPad, PCB_ACTIONS::explodePad.MakeEvent() );
|
|
|
|
Go( &PAD_TOOL::EditPad, PCB_ACTIONS::recombinePad.MakeEvent() );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|