2017-01-21 21:06:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2024-01-11 14:36:20 +00:00
|
|
|
* Copyright (C) 2017-2024 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"
|
2023-01-06 11:13:34 +00:00
|
|
|
#include "pcb_painter.h"
|
2023-09-18 03:13:09 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <macros.h>
|
2017-01-21 21:06:18 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-14 18:11:28 +00:00
|
|
|
#include <board_item.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_shape.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2022-01-04 01:16:51 +00:00
|
|
|
#include <pcbnew_settings.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>
|
2022-01-04 01:16:51 +00:00
|
|
|
#include <tools/pcb_grid_helper.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2019-06-08 21:48:22 +00:00
|
|
|
#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>
|
2022-12-28 22:03:03 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
|
2023-01-06 11:13:34 +00:00
|
|
|
|
|
|
|
using KIGFX::PCB_RENDER_SETTINGS;
|
|
|
|
|
|
|
|
|
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" ),
|
2023-10-13 12:51:27 +00:00
|
|
|
m_previousHighContrastMode( HIGH_CONTRAST_MODE::NORMAL ),
|
2020-06-27 11:57:40 +00:00
|
|
|
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 )
|
2021-08-23 23:10:21 +00:00
|
|
|
m_lastPadNumber = wxT( "1" );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2022-10-12 23:00:16 +00:00
|
|
|
if( board() && board()->GetItem( m_editPad ) == DELETED_BOARD_ITEM::GetInstance() )
|
2022-02-19 19:29:27 +00:00
|
|
|
{
|
|
|
|
PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
|
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
if( m_previousHighContrastMode != opts.m_ContrastModeDisplay )
|
|
|
|
{
|
|
|
|
opts.m_ContrastModeDisplay = m_previousHighContrastMode;
|
|
|
|
frame()->SetDisplayOptions( opts );
|
|
|
|
}
|
2022-02-19 19:29:27 +00:00
|
|
|
|
|
|
|
frame()->GetInfoBar()->Dismiss();
|
|
|
|
|
2022-10-12 23:00:16 +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()
|
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2017-01-21 21:06:18 +00:00
|
|
|
|
|
|
|
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 ) &&
|
2022-08-20 09:27:35 +00:00
|
|
|
SELECTION_CONDITIONS::OnlyTypes( { PCB_PAD_T } );
|
2019-08-24 16:08:33 +00:00
|
|
|
|
2021-09-13 16:18:58 +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;
|
|
|
|
};
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2019-08-24 16:08:33 +00:00
|
|
|
menu.AddSeparator( 400 );
|
2019-11-26 18:42:11 +00:00
|
|
|
|
2020-11-07 17:50:22 +00:00
|
|
|
if( m_isFootprintEditor )
|
2019-11-26 18:42:11 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2021-01-15 00:50:52 +00:00
|
|
|
auto& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
// cancel current tool goes in main context menu at the top if present
|
|
|
|
ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 );
|
|
|
|
ctxMenu.AddSeparator( 1 );
|
|
|
|
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::ShowAlways );
|
2022-09-20 23:16:00 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::mirrorH, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::mirrorV, SELECTION_CONDITIONS::ShowAlways );
|
2021-01-15 00:50:52 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
|
|
|
|
// Finally, add the standard zoom/grid items
|
|
|
|
getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
|
|
|
|
|
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
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const PCB_SELECTION& selection = selTool->GetSelection();
|
2021-06-06 19:03:10 +00:00
|
|
|
const PAD* masterPad = frame()->GetDesignSettings().m_Pad_Master.get();
|
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
|
2020-11-12 22:30:02 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
commit.Modify( item );
|
2021-06-06 19:03:10 +00:00
|
|
|
static_cast<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
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const PCB_SELECTION& selection = selTool->GetSelection();
|
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 )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
EDA_ITEM* item = selection[0];
|
2017-01-21 21:06:18 +00:00
|
|
|
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
const PAD& selPad = static_cast<const PAD&>( *item );
|
2021-06-06 19:03:10 +00:00
|
|
|
frame()->GetDesignSettings().m_Pad_Master->ImportSettingsFrom( selPad );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
static void doPushPadProperties( BOARD& board, const PAD& aSrcPad, BOARD_COMMIT& commit,
|
2023-06-24 18:54:50 +00:00
|
|
|
bool aSameFootprints, bool aPadShapeFilter, bool aPadOrientFilter,
|
|
|
|
bool aPadLayerFilter, bool aPadTypeFilter )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
2023-06-24 18:54:50 +00:00
|
|
|
const FOOTPRINT* refFootprint = aSrcPad.GetParentFootprint();
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
EDA_ANGLE srcPadAngle = aSrcPad.GetOrientation() - refFootprint->GetOrientation();
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : board.Footprints() )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
if( !aSameFootprints && ( footprint != refFootprint ) )
|
2017-01-21 21:06:18 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->GetFPID() != refFootprint->GetFPID() )
|
2017-01-21 21:06:18 +00:00
|
|
|
continue;
|
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2017-01-21 21:06:18 +00:00
|
|
|
{
|
|
|
|
if( aPadShapeFilter && ( pad->GetShape() != aSrcPad.GetShape() ) )
|
|
|
|
continue;
|
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
EDA_ANGLE padAngle = pad->GetOrientation() - footprint->GetOrientation();
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
if( aPadOrientFilter && ( padAngle != srcPadAngle ) )
|
2017-01-21 21:06:18 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aPadLayerFilter && ( pad->GetLayerSet() != aSrcPad.GetLayerSet() ) )
|
|
|
|
continue;
|
|
|
|
|
2019-09-08 22:50:17 +00:00
|
|
|
if( aPadTypeFilter && ( pad->GetAttribute() != aSrcPad.GetAttribute() ) )
|
2024-01-26 13:56:52 +00:00
|
|
|
continue;
|
2019-09-08 22:50:17 +00:00
|
|
|
|
|
|
|
// Special-case for aperture pads
|
2021-05-01 14:46:50 +00:00
|
|
|
if( aPadTypeFilter && pad->GetAttribute() == PAD_ATTRIB::CONN )
|
2019-09-08 22:50:17 +00:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
const PCB_SELECTION& selection = selTool->GetSelection();
|
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 )
|
2023-06-24 18:54:50 +00:00
|
|
|
{
|
|
|
|
PAD* srcPad = static_cast<PAD*>( selection[0] );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
if( FOOTPRINT* footprint = srcPad->GetParentFootprint() )
|
|
|
|
{
|
|
|
|
frame()->SetMsgPanel( footprint );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
DIALOG_PUSH_PAD_PROPERTIES dlg( frame() );
|
|
|
|
int dialogRet = dlg.ShowModal();
|
2018-07-05 16:14:19 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
if( dialogRet == wxID_CANCEL )
|
|
|
|
return 0;
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
const bool edit_Same_Modules = (dialogRet == 1);
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
BOARD_COMMIT commit( frame() );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +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,
|
|
|
|
DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Layer_Filter,
|
|
|
|
DIALOG_PUSH_PAD_PROPERTIES::m_Pad_Type_Filter );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
commit.Push( _( "Push Pad Settings" ) );
|
2017-01-21 21:06:18 +00:00
|
|
|
|
2023-06-24 18:54:50 +00:00
|
|
|
m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
|
|
|
|
frame()->Refresh();
|
|
|
|
}
|
|
|
|
}
|
2019-06-09 23:51:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
/**
|
|
|
|
* @brief Prompts the user for parameters for sequential pad numbering
|
|
|
|
*
|
|
|
|
* @param aFrame The parent window for the dialog
|
|
|
|
* @return The parameters, or nullopt if no parameters, e.g. user cancelled the dialog
|
|
|
|
*/
|
|
|
|
static std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS>
|
|
|
|
GetSequentialPadNumberingParams( wxWindow* aFrame )
|
|
|
|
{
|
|
|
|
// Persistent settings for the pad enumeration dialog.
|
|
|
|
static SEQUENTIAL_PAD_ENUMERATION_PARAMS s_lastUsedParams;
|
|
|
|
|
|
|
|
DIALOG_ENUM_PADS settingsDlg( aFrame, s_lastUsedParams );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() != wxID_OK )
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return s_lastUsedParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-09 23:51:25 +00:00
|
|
|
int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2023-03-06 14:30:58 +00:00
|
|
|
if( !m_isFootprintEditor )
|
|
|
|
return 0;
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() )
|
2019-06-09 23:51:25 +00:00
|
|
|
return 0;
|
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
GENERAL_COLLECTOR collector;
|
2019-06-09 23:51:25 +00:00
|
|
|
GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
|
|
|
|
guide.SetIgnoreMTextsMarkedNoShow( true );
|
|
|
|
guide.SetIgnoreMTextsOnBack( true );
|
|
|
|
guide.SetIgnoreMTextsOnFront( true );
|
|
|
|
guide.SetIgnoreModulesVals( true );
|
|
|
|
guide.SetIgnoreModulesRefs( true );
|
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
const std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> params =
|
|
|
|
GetSequentialPadNumberingParams( frame() );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
// Cancelled or otherwise failed to get any useful parameters
|
|
|
|
if( !params )
|
2021-09-13 12:23:10 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
int seqPadNum = params->m_start_number;
|
|
|
|
|
|
|
|
std::deque<int> storedPadNumbers;
|
2021-09-13 12:23:10 +00:00
|
|
|
std::map<wxString, std::pair<int, wxString>> oldNumbers;
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
frame()->PushTool( aEvent );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
|
|
|
|
std::list<PAD*> selectedPads;
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
bool isFirstPoint = true; // make sure oldCursorPos is initialized at least once
|
2022-01-04 01:16:51 +00:00
|
|
|
PADS pads = board()->GetFirstFootprint()->Pads();
|
|
|
|
|
|
|
|
MAGNETIC_SETTINGS mag_settings;
|
|
|
|
mag_settings.graphics = false;
|
|
|
|
mag_settings.tracks = MAGNETIC_OPTIONS::NO_EFFECT;
|
|
|
|
mag_settings.pads = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, &mag_settings );
|
|
|
|
|
|
|
|
grid.SetSnap( true );
|
|
|
|
grid.SetUseGrid( false );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2020-10-13 15:35:38 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2022-09-04 20:04:17 +00:00
|
|
|
canvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
|
2020-10-08 02:47:01 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
getViewControls()->ShowCursor( true );
|
2022-04-10 22:14:30 +00:00
|
|
|
getViewControls()->ForceCursorPosition( false );
|
2020-10-08 02:47:01 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
STATUS_TEXT_POPUP statusPopup( frame() );
|
2023-07-16 14:37:12 +00:00
|
|
|
|
|
|
|
// Callable lambda to construct the pad number string for the given value
|
2023-11-29 16:15:03 +00:00
|
|
|
const auto constructPadNumber =
|
|
|
|
[&]( int aValue )
|
|
|
|
{
|
|
|
|
return wxString::Format( wxT( "%s%d" ), params->m_prefix.value_or( "" ), aValue );
|
|
|
|
};
|
2023-07-16 14:37:12 +00:00
|
|
|
|
|
|
|
// Callable lambda to set the popup text for the given pad value
|
2023-11-29 16:15:03 +00:00
|
|
|
const auto setPopupTextForValue =
|
|
|
|
[&]( int aValue )
|
|
|
|
{
|
|
|
|
const wxString msg = _( "Click on pad %s\n"
|
|
|
|
"Press <esc> to cancel all; double-click to finish" );
|
|
|
|
statusPopup.SetText( wxString::Format( msg, constructPadNumber( aValue ) ) );
|
|
|
|
};
|
2023-07-16 14:37:12 +00:00
|
|
|
|
|
|
|
setPopupTextForValue( seqPadNum );
|
2021-09-13 12:23:10 +00:00
|
|
|
statusPopup.Popup();
|
2023-09-18 03:13:09 +00:00
|
|
|
statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
|
2022-09-04 20:04:17 +00:00
|
|
|
canvas()->SetStatusPopup( statusPopup.GetPanel() );
|
2021-09-13 12:23:10 +00:00
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2019-06-27 21:33:48 +00:00
|
|
|
|
2022-01-04 01:16:51 +00:00
|
|
|
VECTOR2I cursorPos = grid.AlignToNearestPad( getViewControls()->GetMousePosition(), pads );
|
|
|
|
getViewControls()->ForceCursorPosition( true, cursorPos );
|
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsCancelInteractive() )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2019-07-01 21:01:33 +00:00
|
|
|
commit.Revert();
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
frame()->PopTool( aEvent );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
commit.Push( _( "Renumber pads" ) );
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
frame()->PopTool( aEvent );
|
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();
|
|
|
|
|
|
|
|
// 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:
|
2023-02-19 03:40:07 +00:00
|
|
|
int segments = distance / int( 0.1 * pcbIUScale.IU_PER_MM ) + 1;
|
|
|
|
const VECTOR2I line_step( ( cursorPos - oldCursorPos ) / segments );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
|
|
|
collector.Empty();
|
|
|
|
|
|
|
|
for( int j = 0; j < segments; ++j )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I testpoint( cursorPos.x - j * line_step.x, cursorPos.y - j * line_step.y );
|
2022-08-20 09:27:35 +00:00
|
|
|
collector.Collect( board(), { PCB_PAD_T }, testpoint, guide );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < collector.GetCount(); ++i )
|
2020-11-12 22:30:02 +00:00
|
|
|
selectedPads.push_back( static_cast<PAD*>( collector[i] ) );
|
2019-06-09 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
selectedPads.unique();
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : selectedPads )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
|
|
|
// 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
|
2023-07-16 14:37:12 +00:00
|
|
|
{
|
|
|
|
newval = seqPadNum;
|
|
|
|
seqPadNum += params->m_step;
|
|
|
|
}
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
const wxString newNumber = constructPadNumber( newval );
|
2021-08-23 23:10:21 +00:00
|
|
|
oldNumbers[newNumber] = { newval, pad->GetNumber() };
|
|
|
|
pad->SetNumber( newNumber );
|
|
|
|
SetLastPadNumber( newNumber );
|
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;
|
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
setPopupTextForValue( 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 ) )
|
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
auto it = oldNumbers.find( pad->GetNumber() );
|
|
|
|
wxASSERT( it != oldNumbers.end() );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
if( it != oldNumbers.end() )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
|
|
|
storedPadNumbers.push_back( it->second.first );
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( it->second.second );
|
|
|
|
SetLastPadNumber( it->second.second );
|
|
|
|
oldNumbers.erase( it );
|
2019-06-09 23:51:25 +00:00
|
|
|
|
2023-07-16 14:37:12 +00:00
|
|
|
const int newval = storedPadNumbers.front();
|
|
|
|
setPopupTextForValue( newval );
|
2019-06-09 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->ClearSelected();
|
|
|
|
getView()->Update( pad );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-13 13:14:18 +00:00
|
|
|
else if( evt->IsDblClick( BUT_LEFT ) )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
|
|
|
commit.Push( _( "Renumber pads" ) );
|
2022-09-14 17:31:56 +00:00
|
|
|
frame()->PopTool( aEvent );
|
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
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
|
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();
|
2023-09-18 03:13:09 +00:00
|
|
|
statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
|
2019-06-09 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* p : board()->GetFirstFootprint()->Pads() )
|
2019-06-09 23:51:25 +00:00
|
|
|
{
|
|
|
|
p->ClearSelected();
|
2021-09-13 12:23:10 +00:00
|
|
|
getView()->Update( p );
|
2019-06-09 23:51:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 20:04:17 +00:00
|
|
|
canvas()->SetStatusPopup( nullptr );
|
2019-06-09 23:51:25 +00:00
|
|
|
statusPopup.Hide();
|
2022-09-04 20:04:17 +00:00
|
|
|
|
|
|
|
canvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2022-04-10 22:14:30 +00:00
|
|
|
getViewControls()->ForceCursorPosition( false );
|
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 )
|
|
|
|
{
|
2023-12-30 19:14:07 +00:00
|
|
|
// When creating a new pad (in FP editor) we can use a new pad number
|
|
|
|
// or the last entered pad number
|
|
|
|
// neednewPadNumber = true to create a new pad number, false to use the last
|
|
|
|
// entered pad number
|
|
|
|
static bool neednewPadNumber;
|
|
|
|
|
2023-03-06 14:30:58 +00:00
|
|
|
if( !m_isFootprintEditor )
|
|
|
|
return 0;
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( !board()->GetFirstFootprint() )
|
2020-06-27 11:57:40 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
|
|
|
|
{
|
|
|
|
PAD_PLACER( PAD_TOOL* aPadTool )
|
|
|
|
{
|
2023-12-30 19:14:07 +00:00
|
|
|
neednewPadNumber = true; // Use a new pad number when creatin a pad by default
|
2020-06-27 11:57:40 +00:00
|
|
|
m_padTool = aPadTool;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PAD_PLACER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = new PAD( m_board->GetFirstFootprint() );
|
2021-10-19 23:36:11 +00:00
|
|
|
PAD* master = m_frame->GetDesignSettings().m_Pad_Master.get();
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2021-10-19 23:36:11 +00:00
|
|
|
pad->ImportSettingsFrom( *master );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2021-10-19 23:36:11 +00:00
|
|
|
// If the footprint type and master pad type directly conflict then make some
|
|
|
|
// adjustments. Otherwise assume the user set what they wanted.
|
2024-01-11 14:36:20 +00:00
|
|
|
// Note also a HEATSINK pad (thermal via) is allowed in SMD footprint
|
2021-10-19 23:36:11 +00:00
|
|
|
if( ( m_board->GetFirstFootprint()->GetAttributes() & FP_SMD )
|
|
|
|
&& master->GetAttribute() == PAD_ATTRIB::PTH )
|
2021-10-07 18:09:14 +00:00
|
|
|
{
|
2024-01-11 14:36:20 +00:00
|
|
|
if( pad->GetProperty() != PAD_PROP::HEATSINK )
|
|
|
|
{
|
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
|
|
|
pad->SetShape( PAD_SHAPE::ROUNDRECT );
|
|
|
|
pad->SetSizeX( 1.5 * pad->GetSizeY() );
|
|
|
|
pad->SetLayerSet( PAD::SMDMask() );
|
|
|
|
}
|
2021-10-07 18:09:14 +00:00
|
|
|
}
|
2021-10-19 23:36:11 +00:00
|
|
|
else if( ( m_board->GetFirstFootprint()->GetAttributes() & FP_THROUGH_HOLE )
|
|
|
|
&& master->GetAttribute() == PAD_ATTRIB::SMD )
|
|
|
|
{
|
|
|
|
pad->SetAttribute( PAD_ATTRIB::PTH );
|
|
|
|
pad->SetShape( PAD_SHAPE::CIRCLE );
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( pad->GetSizeX(), pad->GetSizeX() ) );
|
2024-01-11 14:36:20 +00:00
|
|
|
|
|
|
|
// Gives an acceptable drill size: it cannot be 0, but from pad master
|
|
|
|
// it is currently 0, therefore change it:
|
|
|
|
pad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
|
|
|
|
int hole_size = pad->GetSizeX() / 2;
|
|
|
|
pad->SetDrillSize( VECTOR2I( hole_size, hole_size ) );
|
|
|
|
|
2021-10-19 23:36:11 +00:00
|
|
|
pad->SetLayerSet( PAD::PTHMask() );
|
|
|
|
}
|
2021-10-07 18:09:14 +00:00
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
if( pad->CanHaveNumber() )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
wxString padNumber = m_padTool->GetLastPadNumber();
|
2023-12-30 19:14:07 +00:00
|
|
|
|
|
|
|
// Use the last entered pad number when recreating a pad without using the
|
|
|
|
// previously created pad, and a new number when creating a really new pad
|
|
|
|
if( neednewPadNumber )
|
|
|
|
padNumber = m_board->GetFirstFootprint()->GetNextPadNumber( padNumber );
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( padNumber );
|
|
|
|
m_padTool->SetLastPadNumber( padNumber );
|
2023-12-30 19:14:07 +00:00
|
|
|
|
|
|
|
// If a pad is recreated and the previously created was not placed, use
|
|
|
|
// the last entered pad number
|
|
|
|
neednewPadNumber = false;
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::unique_ptr<BOARD_ITEM>( pad );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = dynamic_cast<PAD*>( aItem );
|
2023-12-30 19:14:07 +00:00
|
|
|
// We are using this pad number.
|
|
|
|
// therefore use a new pad number for a newly created pad
|
|
|
|
neednewPadNumber = true;
|
2020-06-27 11:57:40 +00:00
|
|
|
|
|
|
|
if( pad )
|
|
|
|
{
|
2021-06-06 19:03:10 +00:00
|
|
|
m_frame->GetDesignSettings().m_Pad_Master->ImportSettingsFrom( *pad );
|
2020-06-27 11:57:40 +00:00
|
|
|
aCommit.Add( aItem );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PAD_TOOL* m_padTool;
|
|
|
|
};
|
|
|
|
|
|
|
|
PAD_PLACER placer( this );
|
|
|
|
|
2022-09-14 17:31:56 +00:00
|
|
|
doInteractiveItemPlacement( aEvent, &placer, _( "Place pad" ),
|
2020-06-27 11:57:40 +00:00
|
|
|
IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2023-03-06 14:30:58 +00:00
|
|
|
if( !m_isFootprintEditor )
|
|
|
|
return 0;
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
Activate();
|
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
|
|
|
|
PCB_RENDER_SETTINGS* settings = painter->GetSettings();
|
2023-01-06 11:13:34 +00:00
|
|
|
PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
|
2020-06-27 11:57:40 +00:00
|
|
|
|
|
|
|
if( m_editPad != niluuid )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = dynamic_cast<PAD*>( frame()->GetItem( m_editPad ) );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
|
|
|
if( pad )
|
2022-09-24 16:29:14 +00:00
|
|
|
{
|
|
|
|
BOARD_COMMIT commit( frame() );
|
2024-01-31 15:45:39 +00:00
|
|
|
commit.Modify( pad );
|
2023-11-29 16:15:03 +00:00
|
|
|
|
2024-01-31 15:45:39 +00:00
|
|
|
std::vector<PCB_SHAPE*> mergedShapes = RecombinePad( pad, false );
|
2023-11-29 16:15:03 +00:00
|
|
|
|
2024-01-31 15:45:39 +00:00
|
|
|
for( PCB_SHAPE* shape : mergedShapes )
|
2023-11-29 16:15:03 +00:00
|
|
|
commit.Remove( shape );
|
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
commit.Push( _( "Edit Pad" ) );
|
2022-09-24 16:29:14 +00:00
|
|
|
}
|
2020-06-27 11:57:40 +00:00
|
|
|
|
|
|
|
m_editPad = niluuid;
|
|
|
|
}
|
|
|
|
else if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
|
|
|
|
{
|
2023-10-13 12:51:27 +00:00
|
|
|
PCB_LAYER_ID layer;
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( selection[0] );
|
2023-10-13 12:51:27 +00:00
|
|
|
BOARD_COMMIT commit( frame() );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2024-01-31 15:45:39 +00:00
|
|
|
commit.Modify( pad );
|
|
|
|
|
|
|
|
std::vector<PCB_SHAPE*> newShapes = explodePad( pad, &layer );
|
|
|
|
|
|
|
|
for( PCB_SHAPE* shape : newShapes )
|
|
|
|
commit.Added( shape );
|
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
commit.Push( _( "Edit Pad" ) );
|
2023-09-01 17:46:51 +00:00
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2020-06-27 11:57:40 +00:00
|
|
|
frame()->SetActiveLayer( layer );
|
|
|
|
|
2023-01-06 11:13:34 +00:00
|
|
|
settings->m_PadEditModePad = pad;
|
2023-09-01 17:46:51 +00:00
|
|
|
enterPadEditMode();
|
|
|
|
}
|
2023-01-06 11:13:34 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
if( m_editPad == niluuid )
|
2024-01-26 13:48:41 +00:00
|
|
|
ExitPadEditMode();
|
2023-01-06 11:13:34 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
|
|
|
|
int PAD_TOOL::OnUndoRedo( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PAD* flaggedPad = nullptr;
|
|
|
|
KIID flaggedPadId = niluuid;
|
|
|
|
|
|
|
|
for( FOOTPRINT* fp : board()->Footprints() )
|
|
|
|
{
|
|
|
|
for( PAD* pad : fp->Pads() )
|
2021-01-15 00:50:52 +00:00
|
|
|
{
|
2023-09-01 17:46:51 +00:00
|
|
|
if( pad->IsEntered() )
|
|
|
|
{
|
|
|
|
flaggedPad = pad;
|
|
|
|
flaggedPadId = pad->m_Uuid;
|
|
|
|
break;
|
|
|
|
}
|
2021-01-15 00:50:52 +00:00
|
|
|
}
|
2023-09-01 17:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( flaggedPadId != m_editPad )
|
|
|
|
{
|
|
|
|
KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
|
|
|
|
PCB_RENDER_SETTINGS* settings = painter->GetSettings();
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
m_editPad = flaggedPadId;
|
|
|
|
settings->m_PadEditModePad = flaggedPad;
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
if( flaggedPad )
|
|
|
|
enterPadEditMode();
|
|
|
|
else
|
2024-01-26 13:48:41 +00:00
|
|
|
ExitPadEditMode();
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-11 17:40:23 +00:00
|
|
|
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
void PAD_TOOL::enterPadEditMode()
|
|
|
|
{
|
|
|
|
PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
|
|
|
|
WX_INFOBAR* infoBar = frame()->GetInfoBar();
|
|
|
|
wxString msg;
|
2023-01-06 11:13:34 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
canvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
|
|
|
|
[&]( KIGFX::VIEW_ITEM* aItem ) -> bool
|
|
|
|
{
|
|
|
|
return dynamic_cast<PAD*>( aItem ) != nullptr;
|
|
|
|
} );
|
2023-01-06 11:13:34 +00:00
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
m_previousHighContrastMode = opts.m_ContrastModeDisplay;
|
|
|
|
|
|
|
|
if( opts.m_ContrastModeDisplay == HIGH_CONTRAST_MODE::NORMAL )
|
|
|
|
{
|
|
|
|
opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::DIMMED;
|
|
|
|
frame()->SetDisplayOptions( opts );
|
|
|
|
}
|
2023-01-06 11:13:34 +00:00
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
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() ) );
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 17:46:51 +00:00
|
|
|
infoBar->RemoveAllButtons();
|
|
|
|
infoBar->ShowMessage( msg, wxICON_INFORMATION );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 13:48:41 +00:00
|
|
|
void PAD_TOOL::ExitPadEditMode()
|
2023-09-01 17:46:51 +00:00
|
|
|
{
|
2024-01-26 13:48:41 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
|
|
|
|
PCB_RENDER_SETTINGS* settings = painter->GetSettings();
|
|
|
|
PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
|
|
|
|
|
|
|
|
settings->m_PadEditModePad = nullptr;
|
2023-09-01 17:46:51 +00:00
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
if( m_previousHighContrastMode != opts.m_ContrastModeDisplay )
|
|
|
|
{
|
|
|
|
opts.m_ContrastModeDisplay = m_previousHighContrastMode;
|
|
|
|
frame()->SetDisplayOptions( opts );
|
|
|
|
}
|
2023-09-01 17:46:51 +00:00
|
|
|
|
|
|
|
// Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
|
|
|
|
// they won't be found in the view layer's itemset for re-painting.
|
|
|
|
canvas()->GetView()->UpdateAllItemsConditionally( KIGFX::ALL,
|
|
|
|
[&]( KIGFX::VIEW_ITEM* aItem ) -> bool
|
|
|
|
{
|
|
|
|
return dynamic_cast<PAD*>( aItem ) != nullptr;
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Refresh now (otherwise there's an uncomfortably long pause while the infoBar
|
|
|
|
// closes before refresh).
|
|
|
|
canvas()->ForceRefresh();
|
|
|
|
|
|
|
|
frame()->GetInfoBar()->Dismiss();
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-31 15:45:39 +00:00
|
|
|
std::vector<PCB_SHAPE*> PAD_TOOL::explodePad( PAD* aPad, PCB_LAYER_ID* aLayer )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2024-01-31 15:45:39 +00:00
|
|
|
std::vector<PCB_SHAPE*> createdShapes;
|
|
|
|
|
2020-06-27 11:57:40 +00:00
|
|
|
if( aPad->IsOnLayer( F_Cu ) )
|
2023-10-13 12:51:27 +00:00
|
|
|
*aLayer = F_Cu;
|
2020-06-27 11:57:40 +00:00
|
|
|
else if( aPad->IsOnLayer( B_Cu ) )
|
2023-10-13 12:51:27 +00:00
|
|
|
*aLayer = B_Cu;
|
2020-06-27 11:57:40 +00:00
|
|
|
else
|
2023-10-13 12:51:27 +00:00
|
|
|
*aLayer = *aPad->GetLayerSet().UIOrder();
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives() )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( primitive->Duplicate() );
|
2021-07-17 19:56:18 +00:00
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
shape->SetParent( board()->GetFirstFootprint() );
|
2023-09-01 12:21:10 +00:00
|
|
|
shape->Rotate( VECTOR2I( 0, 0 ), aPad->GetOrientation() );
|
|
|
|
shape->Move( aPad->ShapePos() );
|
2023-10-13 12:51:27 +00:00
|
|
|
shape->SetLayer( *aLayer );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::SEGMENT )
|
|
|
|
{
|
|
|
|
if( aPad->GetThermalSpokeWidth() )
|
|
|
|
shape->SetWidth( aPad->GetThermalSpokeWidth() );
|
|
|
|
else
|
|
|
|
shape->SetWidth( pcbIUScale.mmToIU( ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM ) );
|
|
|
|
}
|
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
board()->GetFirstFootprint()->Add( shape );
|
|
|
|
frame()->GetCanvas()->GetView()->Add( shape );
|
2024-01-31 15:45:39 +00:00
|
|
|
createdShapes.push_back( shape );
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aPad->SetShape( aPad->GetAnchorPadShape() );
|
|
|
|
aPad->DeletePrimitivesList();
|
|
|
|
}
|
|
|
|
|
2023-09-11 20:27:08 +00:00
|
|
|
aPad->SetFlags( ENTERED );
|
|
|
|
m_editPad = aPad->m_Uuid;
|
2024-01-31 15:45:39 +00:00
|
|
|
|
|
|
|
return createdShapes;
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
std::vector<PCB_SHAPE*> PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2022-09-24 16:29:14 +00:00
|
|
|
int maxError = board()->GetDesignSettings().m_MaxError;
|
2023-03-30 11:49:23 +00:00
|
|
|
FOOTPRINT* footprint = aPad->GetParentFootprint();
|
2020-10-13 10:55:24 +00:00
|
|
|
|
2023-09-01 12:21:10 +00:00
|
|
|
// Don't leave an object in the point editor that might no longer exist after recombining.
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2022-06-02 14:55:16 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
|
|
|
item->ClearFlags( SKIP_STRUCT );
|
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
auto findNext =
|
2023-03-30 11:49:23 +00:00
|
|
|
[&]( PCB_LAYER_ID aLayer ) -> PCB_SHAPE*
|
2020-10-13 10:55:24 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET padPoly;
|
2022-10-21 12:48:45 +00:00
|
|
|
aPad->TransformShapeToPolygon( padPoly, aLayer, 0, maxError, ERROR_INSIDE );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
2020-10-13 10:55:24 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
if( !shape || ( shape->GetFlags() & SKIP_STRUCT ) )
|
2020-10-13 10:55:24 +00:00
|
|
|
continue;
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2020-11-29 14:00:39 +00:00
|
|
|
if( shape->GetLayer() != aLayer )
|
2020-10-13 10:55:24 +00:00
|
|
|
continue;
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
if( shape->IsProxyItem() ) // Pad number (and net name) box
|
2023-03-30 11:49:23 +00:00
|
|
|
return shape;
|
2022-09-14 10:34:10 +00:00
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
SHAPE_POLY_SET drawPoly;
|
2022-10-21 12:48:45 +00:00
|
|
|
shape->TransformShapeToPolygon( drawPoly, aLayer, 0, maxError, ERROR_INSIDE );
|
2020-10-13 10:55:24 +00:00
|
|
|
drawPoly.BooleanIntersection( padPoly, SHAPE_POLY_SET::PM_FAST );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
if( !drawPoly.IsEmpty() )
|
2023-03-30 11:49:23 +00:00
|
|
|
return shape;
|
2020-10-13 10:55:24 +00:00
|
|
|
}
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
return nullptr;
|
|
|
|
};
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
auto findMatching =
|
2023-03-30 11:49:23 +00:00
|
|
|
[&]( PCB_SHAPE* aShape ) -> std::vector<PCB_SHAPE*>
|
2022-09-24 16:29:14 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
std::vector<PCB_SHAPE*> matching;
|
2022-09-24 16:29:14 +00:00
|
|
|
|
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* other = dynamic_cast<PCB_SHAPE*>( item );
|
2022-09-24 16:29:14 +00:00
|
|
|
|
|
|
|
if( !other || ( other->GetFlags() & SKIP_STRUCT ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aPad->GetLayerSet().test( other->GetLayer() )
|
|
|
|
&& aShape->Compare( other ) == 0 )
|
|
|
|
{
|
|
|
|
matching.push_back( other );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matching;
|
|
|
|
};
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_LAYER_ID layer;
|
|
|
|
std::vector<PCB_SHAPE*> mergedShapes;
|
2020-06-27 11:57:40 +00:00
|
|
|
|
|
|
|
if( aPad->IsOnLayer( F_Cu ) )
|
|
|
|
layer = F_Cu;
|
|
|
|
else if( aPad->IsOnLayer( B_Cu ) )
|
|
|
|
layer = B_Cu;
|
|
|
|
else
|
|
|
|
layer = *aPad->GetLayerSet().UIOrder();
|
|
|
|
|
2023-08-25 12:04:46 +00:00
|
|
|
// If there are intersecting items to combine, we need to first make sure the pad is a
|
|
|
|
// custom-shape pad.
|
|
|
|
if( !aIsDryRun && findNext( layer ) && aPad->GetShape() != PAD_SHAPE::CUSTOM )
|
|
|
|
{
|
2023-09-01 12:21:10 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CIRCLE || aPad->GetShape() == PAD_SHAPE::RECTANGLE )
|
2023-08-28 17:05:58 +00:00
|
|
|
{
|
2023-09-01 12:21:10 +00:00
|
|
|
// Use the existing pad as an anchor
|
|
|
|
aPad->SetAnchorPadShape( aPad->GetShape() );
|
|
|
|
aPad->SetShape( PAD_SHAPE::CUSTOM );
|
2023-08-28 17:05:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-01 12:21:10 +00:00
|
|
|
// Create a new circular anchor and convert existing pad to a polygon primitive
|
|
|
|
SHAPE_POLY_SET existingOutline;
|
|
|
|
aPad->TransformShapeToPolygon( existingOutline, layer, 0, maxError, ERROR_INSIDE );
|
|
|
|
|
|
|
|
int minExtent = std::min( aPad->GetSize().x, aPad->GetSize().y );
|
|
|
|
aPad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
|
|
|
|
aPad->SetSize( VECTOR2I( minExtent, minExtent ) );
|
|
|
|
aPad->SetShape( PAD_SHAPE::CUSTOM );
|
|
|
|
|
|
|
|
PCB_SHAPE* shape = new PCB_SHAPE( nullptr, SHAPE_T::POLY );
|
|
|
|
shape->SetFilled( true );
|
2023-11-25 13:05:45 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( 0, LINE_STYLE::SOLID ) );
|
2023-09-01 12:21:10 +00:00
|
|
|
shape->SetPolyShape( existingOutline );
|
|
|
|
shape->Rotate( VECTOR2I( 0, 0 ), - aPad->GetOrientation() );
|
|
|
|
shape->Move( - aPad->ShapePos() );
|
|
|
|
aPad->AddPrimitive( shape );
|
2023-08-28 17:05:58 +00:00
|
|
|
}
|
2023-08-25 12:04:46 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
while( PCB_SHAPE* fpShape = findNext( layer ) )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2022-09-24 16:29:14 +00:00
|
|
|
fpShape->SetFlags( SKIP_STRUCT );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
mergedShapes.push_back( fpShape );
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
if( !aIsDryRun )
|
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
PCB_SHAPE* primitive = static_cast<PCB_SHAPE*>( fpShape->Duplicate() );
|
2022-09-24 16:29:14 +00:00
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
primitive->SetParent( nullptr );
|
2023-09-01 12:21:10 +00:00
|
|
|
primitive->Move( - aPad->ShapePos() );
|
|
|
|
primitive->Rotate( VECTOR2I( 0, 0 ), - aPad->GetOrientation() );
|
2023-08-25 12:04:46 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
aPad->AddPrimitive( primitive );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2020-10-04 23:34:59 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
// See if there are other shapes that match and mark them for delete. (KiCad won't
|
|
|
|
// produce these, but old footprints from other vendors have them.)
|
2023-03-30 11:49:23 +00:00
|
|
|
for( PCB_SHAPE* other : findMatching( fpShape ) )
|
2022-09-24 16:29:14 +00:00
|
|
|
{
|
|
|
|
other->SetFlags( SKIP_STRUCT );
|
|
|
|
mergedShapes.push_back( other );
|
|
|
|
}
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
|
|
|
item->ClearFlags( SKIP_STRUCT );
|
|
|
|
|
|
|
|
if( !aIsDryRun )
|
|
|
|
aPad->ClearFlags( ENTERED );
|
2022-09-14 10:34:10 +00:00
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
return mergedShapes;
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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() );
|
2023-09-01 17:46:51 +00:00
|
|
|
|
|
|
|
Go( &PAD_TOOL::OnUndoRedo, EVENTS::UndoRedoPostEvent );
|
2017-01-21 21:06:18 +00:00
|
|
|
}
|