2014-07-09 13:02:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-21 20:03:36 +00:00
|
|
|
* Copyright (C) 2014-2019 CERN
|
2019-06-06 11:45:28 +00:00
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-07-09 13:02:56 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-02-16 19:26:55 +00:00
|
|
|
#include "footprint_editor_tools.h"
|
2017-05-18 17:21:30 +00:00
|
|
|
#include "kicad_clipboard.h"
|
2014-07-09 13:02:56 +00:00
|
|
|
#include "selection_tool.h"
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view_group.h>
|
2014-07-09 13:10:32 +00:00
|
|
|
#include <pcb_painter.h>
|
2015-09-05 19:47:35 +00:00
|
|
|
#include <origin_viewitem.h>
|
2019-01-17 13:23:03 +00:00
|
|
|
#include <status_popup.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include <footprint_edit_frame.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <kicad_plugin.h>
|
|
|
|
#include <pcbnew_id.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <collectors.h>
|
|
|
|
#include <confirm.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2019-06-06 11:45:28 +00:00
|
|
|
#include <project.h>
|
2017-02-04 05:09:50 +00:00
|
|
|
#include <tools/tool_event_utils.h>
|
2019-06-06 11:45:28 +00:00
|
|
|
#include <fp_lib_table.h>
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2014-07-09 13:10:32 +00:00
|
|
|
#include <wx/defs.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2019-06-03 23:50:44 +00:00
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
MODULE_EDITOR_TOOLS::MODULE_EDITOR_TOOLS() :
|
2019-06-05 19:15:57 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.ModuleEditor" ),
|
|
|
|
m_frame( nullptr )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2015-09-05 19:47:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
MODULE_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS()
|
2015-09-05 19:47:35 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
void MODULE_EDITOR_TOOLS::Reset( RESET_REASON aReason )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
m_frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MODULE_EDITOR_TOOLS::Init()
|
|
|
|
{
|
|
|
|
// Build a context menu for the footprint tree
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
auto libSelectedCondition = [ this ] ( const SELECTION& aSel ) {
|
|
|
|
LIB_ID sel = m_frame->GetTreeFPID();
|
|
|
|
return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
|
|
|
|
};
|
|
|
|
auto fpSelectedCondition = [ this ] ( const SELECTION& aSel ) {
|
|
|
|
LIB_ID sel = m_frame->GetTreeFPID();
|
|
|
|
return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
|
|
|
|
};
|
|
|
|
|
|
|
|
ctxMenu.AddItem( ACTIONS::newLibrary, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
ctxMenu.AddItem( ACTIONS::addLibrary, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
ctxMenu.AddItem( ACTIONS::save, libSelectedCondition );
|
|
|
|
ctxMenu.AddItem( ACTIONS::saveAs, libSelectedCondition );
|
|
|
|
ctxMenu.AddItem( ACTIONS::revert, libSelectedCondition );
|
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator();
|
2019-06-05 19:15:57 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::newFootprint, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
#ifdef KICAD_SCRIPTING
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::createFootprint, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
#endif
|
2019-06-06 11:45:28 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::editFootprint, fpSelectedCondition );
|
2019-06-05 19:15:57 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator();
|
2019-06-05 19:15:57 +00:00
|
|
|
ctxMenu.AddItem( ACTIONS::save, fpSelectedCondition );
|
|
|
|
ctxMenu.AddItem( ACTIONS::saveCopyAs, fpSelectedCondition );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::deleteFootprint, fpSelectedCondition );
|
|
|
|
ctxMenu.AddItem( ACTIONS::revert, fpSelectedCondition );
|
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator();
|
2019-06-06 11:45:28 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::cutFootprint, fpSelectedCondition );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::copyFootprint, fpSelectedCondition );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::pasteFootprint, SELECTION_CONDITIONS::ShowAlways );
|
2019-06-05 19:15:57 +00:00
|
|
|
|
2019-06-15 16:40:14 +00:00
|
|
|
ctxMenu.AddSeparator();
|
2019-06-06 11:45:28 +00:00
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::importFootprint, SELECTION_CONDITIONS::ShowAlways );
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::exportFootprint, fpSelectedCondition );
|
2019-07-19 16:15:23 +00:00
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
return true;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-04 18:46:52 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::NewFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, ID_MODEDIT_NEW_MODULE );
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->Process_Special_Functions( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::CreateFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, ID_MODEDIT_NEW_MODULE_FROM_WIZARD );
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->Process_Special_Functions( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-03 23:50:44 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::Save( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, ID_MODEDIT_SAVE );
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->Process_Special_Functions( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::SaveAs( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_NULL, ID_MODEDIT_SAVE_AS );
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->Process_Special_Functions( evt );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::Revert( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->RevertFootprint();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2019-06-06 11:45:28 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::CutCopyFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
LIB_ID fpID = m_frame->GetTreeFPID();
|
|
|
|
|
|
|
|
if( fpID == m_frame->GetLoadedFPID() )
|
|
|
|
m_copiedModule.reset( new MODULE( *m_frame->GetBoard()->GetFirstModule() ) );
|
|
|
|
else
|
|
|
|
m_copiedModule.reset( m_frame->LoadFootprint( fpID ) );
|
2019-07-19 16:15:23 +00:00
|
|
|
|
2019-06-06 11:45:28 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::cutFootprint ) )
|
|
|
|
DeleteFootprint(aEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::PasteFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( m_copiedModule && !m_frame->GetTreeFPID().GetLibNickname().empty() )
|
|
|
|
{
|
|
|
|
wxString newLib = m_frame->GetTreeFPID().GetLibNickname();
|
|
|
|
MODULE* newModule( m_copiedModule.get() );
|
|
|
|
wxString newName = newModule->GetFPID().GetLibItemName();
|
|
|
|
|
|
|
|
while( m_frame->Prj().PcbFootprintLibs()->FootprintExists( newLib, newName ) )
|
|
|
|
newName += _( "_copy" );
|
|
|
|
|
|
|
|
newModule->SetFPID( LIB_ID( newLib, newName ) );
|
|
|
|
m_frame->SaveFootprintInLibrary( newModule, newLib );
|
|
|
|
|
|
|
|
m_frame->SyncLibraryTree( true );
|
|
|
|
m_frame->FocusOnLibID( newModule->GetFPID() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::DeleteFootprint( const TOOL_EVENT& aEvent )
|
2019-06-03 23:50:44 +00:00
|
|
|
{
|
|
|
|
FOOTPRINT_EDIT_FRAME* frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
|
|
|
|
|
|
|
|
if( frame->DeleteModuleFromLibrary( frame->GetTargetFPID(), true ) )
|
|
|
|
{
|
|
|
|
if( frame->GetTargetFPID() == frame->GetLoadedFPID() )
|
|
|
|
frame->Clear_Pcb( false );
|
|
|
|
|
|
|
|
frame->SyncLibraryTree( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-06 11:45:28 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::ImportFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( !m_frame->Clear_Pcb( true ) )
|
|
|
|
return -1; // this command is aborted
|
|
|
|
|
2019-06-13 13:34:38 +00:00
|
|
|
getViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
|
2019-06-06 11:45:28 +00:00
|
|
|
m_frame->Import_Module();
|
|
|
|
|
|
|
|
if( m_frame->GetBoard()->GetFirstModule() )
|
|
|
|
m_frame->GetBoard()->GetFirstModule()->ClearFlags();
|
|
|
|
|
|
|
|
// Clear undo and redo lists because we don't have handling to in
|
|
|
|
// FP editor to undo across imports (the module _is_ the board with the stack)
|
|
|
|
// todo: Abstract undo/redo stack to a higher element or keep consistent board item in fpeditor
|
|
|
|
frame()->GetScreen()->ClearUndoRedoList();
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( ACTIONS::zoomFitScreen, true );
|
|
|
|
m_frame->OnModify();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::ExportFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
LIB_ID fpID = m_frame->GetTreeFPID();
|
|
|
|
MODULE* fp;
|
2019-07-19 16:15:23 +00:00
|
|
|
|
2019-06-18 20:50:21 +00:00
|
|
|
if( !fpID.IsValid() )
|
2019-06-06 11:45:28 +00:00
|
|
|
fp = m_frame->GetBoard()->GetFirstModule();
|
|
|
|
else
|
|
|
|
fp = m_frame->LoadFootprint( fpID );
|
2019-07-19 16:15:23 +00:00
|
|
|
|
2019-06-06 11:45:28 +00:00
|
|
|
m_frame->Export_Module( fp );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::EditFootprint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->LoadModuleFromLibrary( m_frame->GetTreeFPID() );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::ToggleFootprintTree( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->ToggleSearchTree();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-03 23:50:44 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::Properties( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
MODULE* footprint = m_frame->GetBoard()->GetFirstModule();
|
2019-06-03 23:50:44 +00:00
|
|
|
|
|
|
|
if( footprint )
|
|
|
|
{
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->OnEditItemRequest( footprint );
|
2019-06-13 17:28:55 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-06-03 23:50:44 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::DefaultPadProperties( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
getEditFrame<FOOTPRINT_EDIT_FRAME>()->InstallPadOptionsFrame( nullptr );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-27 11:07:29 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-07-19 21:13:52 +00:00
|
|
|
if( !m_frame->GetBoard()->GetFirstModule() )
|
|
|
|
return 0;
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2017-04-22 15:46:31 +00:00
|
|
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-05-31 00:15:57 +00:00
|
|
|
D_PAD* pad = new D_PAD( m_board->GetFirstModule() );
|
2019-06-13 13:34:38 +00:00
|
|
|
pad->ImportSettingsFrom( m_frame->GetDesignSettings().m_Pad_Master );
|
2017-06-23 13:19:04 +00:00
|
|
|
pad->IncrementPadName( true, true );
|
2017-04-22 15:46:31 +00:00
|
|
|
return std::unique_ptr<BOARD_ITEM>( pad );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
2018-10-21 12:50:31 +00:00
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
|
2018-10-21 12:50:31 +00:00
|
|
|
{
|
2019-01-21 20:33:37 +00:00
|
|
|
D_PAD* pad = dynamic_cast<D_PAD*>( aItem );
|
|
|
|
|
|
|
|
if( pad )
|
|
|
|
{
|
2019-06-13 13:34:38 +00:00
|
|
|
m_frame->GetDesignSettings().m_Pad_Master.ImportSettingsFrom( *pad );
|
2019-01-21 20:33:37 +00:00
|
|
|
pad->SetLocalCoord();
|
|
|
|
aCommit.Add( aItem );
|
2019-01-23 15:18:44 +00:00
|
|
|
return true;
|
2019-01-21 20:33:37 +00:00
|
|
|
}
|
2019-01-23 15:18:44 +00:00
|
|
|
|
|
|
|
return false;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
2017-04-22 15:46:31 +00:00
|
|
|
};
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
PAD_PLACER placer;
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place pad" ),
|
2019-06-24 15:27:05 +00:00
|
|
|
IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
if( selection.Size() != 1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( selection[0]->Type() != PCB_PAD_T )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
auto pad = static_cast<D_PAD*>( selection[0] );
|
|
|
|
|
|
|
|
if( pad->GetShape() != PAD_SHAPE_CUSTOM )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
commit.Modify( pad );
|
|
|
|
|
|
|
|
wxPoint anchor = pad->GetPosition();
|
|
|
|
|
|
|
|
for( auto prim : pad->GetPrimitives() )
|
|
|
|
{
|
2019-05-31 00:15:57 +00:00
|
|
|
auto ds = new EDGE_MODULE( board()->GetFirstModule() );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2017-10-21 06:48:26 +00:00
|
|
|
prim.ExportTo( ds ); // ExportTo exports to a DRAWSEGMENT
|
|
|
|
// Fix an arbitray draw layer for this EDGE_MODULE
|
|
|
|
ds->SetLayer( Dwgs_User ); //pad->GetLayer() );
|
|
|
|
ds->Move( anchor );
|
2019-07-11 08:48:11 +00:00
|
|
|
ds->Rotate( anchor, pad->GetOrientation() );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
commit.Add( ds );
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetShape( pad->GetAnchorPadShape() );
|
2018-04-24 15:00:29 +00:00
|
|
|
// Cleanup the pad primitives data, because the initial pad was a custom
|
|
|
|
// shaped pad, and it contains primitives, that does not exist in non custom pads,
|
|
|
|
// and can create issues later:
|
|
|
|
if( pad->GetShape() != PAD_SHAPE_CUSTOM ) // should be always the case
|
|
|
|
{
|
|
|
|
pad->DeletePrimitivesList();
|
|
|
|
}
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
commit.Push( _("Explode pad to shapes") );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
PCBNEW_SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
std::unique_ptr<D_PAD> pad( new D_PAD( board()->GetFirstModule() ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
D_PAD *refPad = nullptr;
|
|
|
|
bool multipleRefPadsFound = false;
|
|
|
|
bool illegalItemsFound = false;
|
|
|
|
|
|
|
|
std::vector<PAD_CS_PRIMITIVE> shapes;
|
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
for( auto item : selection )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
if( refPad )
|
|
|
|
multipleRefPadsFound = true;
|
|
|
|
|
|
|
|
refPad = static_cast<D_PAD*>( item );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
auto em = static_cast<EDGE_MODULE*> ( item );
|
|
|
|
|
|
|
|
PAD_CS_PRIMITIVE shape( em->GetShape() );
|
|
|
|
shape.m_Start = em->GetStart();
|
|
|
|
shape.m_End = em->GetEnd();
|
|
|
|
shape.m_Radius = em->GetRadius();
|
|
|
|
shape.m_Thickness = em->GetWidth();
|
|
|
|
shape.m_ArcAngle = em->GetAngle();
|
2019-04-14 17:58:35 +00:00
|
|
|
shape.m_Ctrl1 = em->GetBezControl1();
|
|
|
|
shape.m_Ctrl2 = em->GetBezControl2();
|
2018-01-24 13:22:43 +00:00
|
|
|
shape.m_Poly = em->BuildPolyPointsList();
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
shapes.push_back(shape);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
illegalItemsFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( refPad && selection.Size() == 1 )
|
|
|
|
{
|
|
|
|
// don't convert a pad into itself...
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( multipleRefPadsFound )
|
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
DisplayErrorMessage( m_frame, _( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"selection contains more than one reference pad." ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( illegalItemsFound )
|
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
DisplayErrorMessage( m_frame, _( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"selection contains unsupported items.\n"
|
|
|
|
"Only graphical lines, circles, arcs and polygons "
|
|
|
|
"are allowed." ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-11 08:48:11 +00:00
|
|
|
double refOrientation = 0.0;
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
if( refPad )
|
|
|
|
{
|
|
|
|
pad.reset( static_cast<D_PAD*>( refPad->Clone() ) );
|
2018-03-05 16:51:43 +00:00
|
|
|
|
|
|
|
if( refPad->GetShape() == PAD_SHAPE_RECT )
|
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE_RECT );
|
|
|
|
|
2019-07-11 08:48:11 +00:00
|
|
|
// ignore the pad offset for the moment. Makes more trouble than it's worth.
|
2018-03-05 16:51:43 +00:00
|
|
|
pad->SetOffset( wxPoint( 0, 0 ) );
|
2019-07-11 08:48:11 +00:00
|
|
|
refOrientation = pad->GetOrientation();
|
|
|
|
pad->SetOrientation( 0.0 );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:48:26 +00:00
|
|
|
// Create a default pad anchor:
|
2017-10-19 21:16:06 +00:00
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE_CIRCLE );
|
|
|
|
pad->SetAttribute( PAD_ATTRIB_SMD );
|
|
|
|
pad->SetLayerSet( D_PAD::SMDMask() );
|
2017-10-21 06:48:26 +00:00
|
|
|
int radius = Millimeter2iu( 0.2 );
|
|
|
|
pad->SetSize ( wxSize( radius, radius ) );
|
2017-10-19 21:16:06 +00:00
|
|
|
pad->IncrementPadName( true, true );
|
2018-03-05 16:51:43 +00:00
|
|
|
pad->SetOrientation( 0 );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetShape ( PAD_SHAPE_CUSTOM );
|
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
OPT<VECTOR2I> anchor;
|
2017-10-19 21:16:06 +00:00
|
|
|
VECTOR2I tmp;
|
|
|
|
|
|
|
|
if( refPad )
|
|
|
|
{
|
2017-11-01 11:14:16 +00:00
|
|
|
anchor = VECTOR2I( pad->GetPosition() );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
else if( pad->GetBestAnchorPosition( tmp ) )
|
|
|
|
{
|
|
|
|
anchor = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !anchor )
|
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
DisplayErrorMessage( m_frame, _( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"unable to determine the anchor point position.\n"
|
|
|
|
"Consider adding a small anchor pad to the selection "
|
|
|
|
"and try again.") );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// relocate the shapes, they are relative to the anchor pad position
|
|
|
|
for( auto& shape : shapes )
|
|
|
|
{
|
2017-10-21 09:00:59 +00:00
|
|
|
shape.Move( wxPoint( -anchor->x, -anchor->y ) );
|
2019-07-11 08:48:11 +00:00
|
|
|
shape.Rotate( wxPoint( 0, 0 ), -refOrientation );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetPosition( wxPoint( anchor->x, anchor->y ) );
|
2018-03-06 13:58:25 +00:00
|
|
|
pad->AddPrimitives( shapes );
|
|
|
|
pad->ClearFlags();
|
2018-04-24 15:00:29 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
bool result = pad->MergePrimitivesAsPolygon();
|
2019-07-11 08:48:11 +00:00
|
|
|
pad->Rotate( wxPoint( anchor->x, anchor->y ), refOrientation );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
if( !result )
|
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
DisplayErrorMessage( m_frame, _( "Cannot convert items to a custom-shaped pad:\n"
|
|
|
|
"selected items do not form a single solid shape.") );
|
2017-10-19 21:16:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto padPtr = pad.release();
|
|
|
|
|
|
|
|
commit.Add( padPtr );
|
|
|
|
for ( auto item : selection )
|
|
|
|
{
|
|
|
|
commit.Remove( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2017-10-21 09:00:59 +00:00
|
|
|
commit.Push(_("Create Pad from Selected Shapes") );
|
2018-03-06 13:58:25 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, padPtr );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-09 13:10:32 +00:00
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void MODULE_EDITOR_TOOLS::setTransitions()
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
2019-06-04 18:46:52 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::NewFootprint, PCB_ACTIONS::newFootprint.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::CreateFootprint, PCB_ACTIONS::createFootprint.MakeEvent() );
|
2019-06-03 23:50:44 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::Save, ACTIONS::save.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::Save, PCB_ACTIONS::saveToBoard.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::Save, PCB_ACTIONS::saveToLibrary.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::SaveAs, ACTIONS::saveAs.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::SaveAs, ACTIONS::saveCopyAs.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::Revert, ACTIONS::revert.MakeEvent() );
|
2019-06-06 11:45:28 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::DeleteFootprint, PCB_ACTIONS::deleteFootprint.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::EditFootprint, PCB_ACTIONS::editFootprint.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::CutCopyFootprint, PCB_ACTIONS::cutFootprint.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::CutCopyFootprint, PCB_ACTIONS::copyFootprint.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::PasteFootprint, PCB_ACTIONS::pasteFootprint.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::ImportFootprint, PCB_ACTIONS::importFootprint.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::ExportFootprint, PCB_ACTIONS::exportFootprint.MakeEvent() );
|
2019-06-03 23:50:44 +00:00
|
|
|
|
2019-06-06 11:45:28 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::ToggleFootprintTree, PCB_ACTIONS::toggleFootprintTree.MakeEvent() );
|
2019-06-03 23:50:44 +00:00
|
|
|
Go( &MODULE_EDITOR_TOOLS::Properties, PCB_ACTIONS::footprintProperties.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::DefaultPadProperties, PCB_ACTIONS::defaultPadProperties.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::PlacePad, PCB_ACTIONS::placePad.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::CreatePadFromShapes, PCB_ACTIONS::createPadFromShapes.MakeEvent() );
|
|
|
|
Go( &MODULE_EDITOR_TOOLS::ExplodePadToShapes, PCB_ACTIONS::explodePadToShapes.MakeEvent() );
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|