2020-06-17 12:46:50 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-08-30 11:03:40 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-06-17 12:46:50 +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 <dialog_cleanup_graphics.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <board_commit.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <footprint.h>
|
2022-09-24 16:29:14 +00:00
|
|
|
#include <pad.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <graphics_cleaner.h>
|
2020-09-15 19:13:45 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
DIALOG_CLEANUP_GRAPHICS::DIALOG_CLEANUP_GRAPHICS( PCB_BASE_FRAME* aParent,
|
|
|
|
bool aIsFootprintEditor ) :
|
2020-06-17 12:46:50 +00:00
|
|
|
DIALOG_CLEANUP_GRAPHICS_BASE( aParent ),
|
|
|
|
m_parentFrame( aParent ),
|
2020-11-08 21:29:04 +00:00
|
|
|
m_isFootprintEditor( aIsFootprintEditor )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
m_changesTreeModel = new RC_TREE_MODEL( m_parentFrame, m_changesDataView );
|
|
|
|
m_changesDataView->AssociateModel( m_changesTreeModel );
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
if( aIsFootprintEditor )
|
2022-09-24 16:29:14 +00:00
|
|
|
{
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Update Footprint" ) } } );
|
2022-09-24 16:29:14 +00:00
|
|
|
m_nettieHint->SetFont( KIUI::GetInfoFont( aParent ).Italic() );
|
|
|
|
}
|
2021-11-16 19:39:58 +00:00
|
|
|
else
|
2022-09-24 16:29:14 +00:00
|
|
|
{
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
|
2022-09-24 16:29:14 +00:00
|
|
|
m_mergePadsOpt->Show( false );
|
|
|
|
m_nettieHint->Show( false );
|
|
|
|
}
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_CLEANUP_GRAPHICS::~DIALOG_CLEANUP_GRAPHICS()
|
|
|
|
{
|
|
|
|
m_changesTreeModel->DecRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CLEANUP_GRAPHICS::OnCheckBox( wxCommandEvent& anEvent )
|
|
|
|
{
|
|
|
|
doCleanup( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_CLEANUP_GRAPHICS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
doCleanup( true );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_CLEANUP_GRAPHICS::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
doCleanup( false );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CLEANUP_GRAPHICS::doCleanup( bool aDryRun )
|
|
|
|
{
|
|
|
|
wxBusyCursor busy;
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( m_parentFrame );
|
|
|
|
BOARD* board = m_parentFrame->GetBoard();
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* fp = m_isFootprintEditor ? board->GetFirstFootprint() : nullptr;
|
2022-09-24 16:29:14 +00:00
|
|
|
GRAPHICS_CLEANER cleaner( fp ? fp->GraphicalItems() : board->Drawings(), fp, commit,
|
|
|
|
m_parentFrame->GetToolManager() );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
if( !aDryRun )
|
|
|
|
{
|
|
|
|
// Clear current selection list to avoid selection of deleted items
|
2023-06-26 22:16:51 +00:00
|
|
|
m_parentFrame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
// ... and to keep the treeModel from trying to refresh a deleted item
|
2022-08-30 11:03:40 +00:00
|
|
|
m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
|
2020-06-17 12:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_items.clear();
|
|
|
|
|
|
|
|
// Old model has to be refreshed, GAL normally does not keep updating it
|
|
|
|
m_parentFrame->Compile_Ratsnest( false );
|
|
|
|
|
|
|
|
cleaner.CleanupBoard( aDryRun, &m_items, m_createRectanglesOpt->GetValue(),
|
2022-09-24 16:29:14 +00:00
|
|
|
m_deleteRedundantOpt->GetValue(),
|
|
|
|
m_mergePadsOpt->GetValue() );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
if( aDryRun )
|
|
|
|
{
|
2022-08-30 11:03:40 +00:00
|
|
|
m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
|
|
|
|
RPT_SEVERITY_ACTION );
|
2020-06-17 12:46:50 +00:00
|
|
|
}
|
|
|
|
else if( !commit.Empty() )
|
|
|
|
{
|
|
|
|
// Clear undo and redo lists to avoid inconsistencies between lists
|
|
|
|
commit.Push( _( "Graphics cleanup" ) );
|
|
|
|
m_parentFrame->GetCanvas()->Refresh( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CLEANUP_GRAPHICS::OnSelectItem( wxDataViewEvent& aEvent )
|
|
|
|
{
|
|
|
|
const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
|
|
|
|
BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
|
|
|
|
WINDOW_THAWER thawer( m_parentFrame );
|
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
if( item && !item->GetLayerSet().test( m_parentFrame->GetActiveLayer() ) )
|
|
|
|
m_parentFrame->SetActiveLayer( item->GetLayerSet().UIOrder().front() );
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
m_parentFrame->FocusOnItem( item );
|
|
|
|
m_parentFrame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CLEANUP_GRAPHICS::OnLeftDClickItem( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
|
|
|
|
if( m_changesDataView->GetCurrentItem().IsOk() )
|
|
|
|
{
|
|
|
|
if( !IsModal() )
|
|
|
|
Show( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|