2020-09-14 17:54:14 +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 change_log.txt for contributors.
|
2020-09-14 17:54:14 +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 <pcb_edit_frame.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/pcb_tool_base.h>
|
|
|
|
#include <tools/zone_filler_tool.h>
|
2021-07-11 17:04:57 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2020-09-14 17:54:14 +00:00
|
|
|
#include <tools/drc_tool.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-09-14 17:54:14 +00:00
|
|
|
#include <dialog_drc.h>
|
|
|
|
#include <board_commit.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <drc/drc_engine.h>
|
2021-12-01 14:42:44 +00:00
|
|
|
#include <drc/drc_item.h>
|
2020-09-14 17:54:14 +00:00
|
|
|
#include <netlist_reader/pcb_netlist.h>
|
2023-08-09 23:38:43 +00:00
|
|
|
#include <macros.h>
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
DRC_TOOL::DRC_TOOL() :
|
|
|
|
PCB_TOOL_BASE( "pcbnew.DRCTool" ),
|
|
|
|
m_editFrame( nullptr ),
|
|
|
|
m_pcb( nullptr ),
|
2020-09-21 19:39:46 +00:00
|
|
|
m_drcDialog( nullptr ),
|
|
|
|
m_drcRunning( false )
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DRC_TOOL::~DRC_TOOL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
m_editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
|
|
|
|
if( m_pcb != m_editFrame->GetBoard() )
|
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
2020-09-16 20:38:23 +00:00
|
|
|
DestroyDRCDialog();
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
m_pcb = m_editFrame->GetBoard();
|
2020-09-15 19:13:45 +00:00
|
|
|
m_drcEngine = m_pcb->GetDesignSettings().m_DRCEngine;
|
2020-09-14 17:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_TOOL::ShowDRCDialog( wxWindow* aParent )
|
|
|
|
{
|
|
|
|
bool show_dlg_modal = true;
|
|
|
|
|
|
|
|
// the dialog needs a parent frame. if it is not specified, this is the PCB editor frame
|
|
|
|
// specified in DRC_TOOL class.
|
|
|
|
if( !aParent )
|
|
|
|
{
|
|
|
|
// if any parent is specified, the dialog is modal.
|
|
|
|
// if this is the default PCB editor frame, it is not modal
|
|
|
|
show_dlg_modal = false;
|
|
|
|
aParent = m_editFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
Activate();
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
if( !m_drcDialog )
|
|
|
|
{
|
|
|
|
m_drcDialog = new DIALOG_DRC( m_editFrame, aParent );
|
2023-06-11 11:14:03 +00:00
|
|
|
updatePointers( false );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
if( show_dlg_modal )
|
|
|
|
m_drcDialog->ShowModal();
|
|
|
|
else
|
|
|
|
m_drcDialog->Show( true );
|
|
|
|
}
|
|
|
|
else // The dialog is just not visible (because the user has double clicked on an error item)
|
|
|
|
{
|
2023-06-11 11:14:03 +00:00
|
|
|
updatePointers( false );
|
2020-09-14 17:54:14 +00:00
|
|
|
m_drcDialog->Show( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DRC_TOOL::ShowDRCDialog( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
ShowDRCDialog( nullptr );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DRC_TOOL::IsDRCDialogShown()
|
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
|
|
|
return m_drcDialog->IsShown();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
void DRC_TOOL::DestroyDRCDialog()
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
|
|
|
{
|
|
|
|
m_drcDialog->Destroy();
|
|
|
|
m_drcDialog = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-28 17:55:57 +00:00
|
|
|
void DRC_TOOL::RunTests( PROGRESS_REPORTER* aProgressReporter, bool aRefillZones,
|
2023-05-11 13:53:28 +00:00
|
|
|
bool aReportAllTrackErrors, bool aTestFootprints )
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
2020-09-23 10:36:27 +00:00
|
|
|
// One at a time, please.
|
|
|
|
// Note that the main GUI entry points to get here are blocked, so this is really an
|
|
|
|
// insurance policy and as such we make no attempts to queue up the DRC run or anything.
|
|
|
|
if( m_drcRunning )
|
|
|
|
return;
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
ZONE_FILLER_TOOL* zoneFiller = m_toolMgr->GetTool<ZONE_FILLER_TOOL>();
|
2020-09-15 19:13:45 +00:00
|
|
|
BOARD_COMMIT commit( m_editFrame );
|
|
|
|
NETLIST netlist;
|
2020-10-28 19:56:08 +00:00
|
|
|
bool netlistFetched = false;
|
2020-09-16 20:38:23 +00:00
|
|
|
wxWindowDisabler disabler( /* disable everything except: */ m_drcDialog );
|
|
|
|
|
2020-09-21 19:39:46 +00:00
|
|
|
m_drcRunning = true;
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
if( aRefillZones )
|
|
|
|
{
|
|
|
|
aProgressReporter->AdvancePhase( _( "Refilling all zones..." ) );
|
|
|
|
|
2020-09-16 15:03:55 +00:00
|
|
|
zoneFiller->FillAllZones( m_drcDialog, aProgressReporter );
|
2020-09-14 17:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 16:59:34 +00:00
|
|
|
m_drcEngine->SetDrawingSheet( m_editFrame->GetCanvas()->GetDrawingSheet() );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
if( aTestFootprints && !Kiface().IsSingle() )
|
|
|
|
{
|
2021-01-30 16:30:35 +00:00
|
|
|
if( m_editFrame->FetchNetlistFromSchematic( netlist, _( "Schematic parity tests require a "
|
|
|
|
"fully annotated schematic." ) ) )
|
|
|
|
{
|
2020-10-28 19:56:08 +00:00
|
|
|
netlistFetched = true;
|
2021-01-30 16:30:35 +00:00
|
|
|
}
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
if( m_drcDialog )
|
|
|
|
m_drcDialog->Raise();
|
|
|
|
|
2020-09-15 19:13:45 +00:00
|
|
|
m_drcEngine->SetSchematicNetlist( &netlist );
|
2020-09-14 17:54:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 19:13:45 +00:00
|
|
|
m_drcEngine->SetProgressReporter( aProgressReporter );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
2020-09-15 19:13:45 +00:00
|
|
|
m_drcEngine->SetViolationHandler(
|
2022-08-15 16:59:34 +00:00
|
|
|
[&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
2022-08-15 16:59:34 +00:00
|
|
|
PCB_MARKER* marker = new PCB_MARKER( aItem, aPos, aLayer );
|
2021-12-01 14:42:44 +00:00
|
|
|
commit.Add( marker );
|
2020-09-14 17:54:14 +00:00
|
|
|
} );
|
|
|
|
|
2020-10-28 17:55:57 +00:00
|
|
|
m_drcEngine->RunTests( m_editFrame->GetUserUnits(), aReportAllTrackErrors, aTestFootprints );
|
2020-09-15 19:13:45 +00:00
|
|
|
|
|
|
|
m_drcEngine->SetProgressReporter( nullptr );
|
|
|
|
m_drcEngine->ClearViolationHandler();
|
2020-09-14 17:54:14 +00:00
|
|
|
|
2020-09-20 01:20:41 +00:00
|
|
|
if( m_drcDialog )
|
2020-09-21 11:04:41 +00:00
|
|
|
{
|
2020-09-20 01:20:41 +00:00
|
|
|
m_drcDialog->SetDrcRun();
|
2020-09-16 20:38:23 +00:00
|
|
|
|
2020-10-28 19:56:08 +00:00
|
|
|
if( aTestFootprints && netlistFetched )
|
2020-09-21 11:04:41 +00:00
|
|
|
m_drcDialog->SetFootprintTestsRun();
|
|
|
|
}
|
2020-09-16 20:38:23 +00:00
|
|
|
|
2022-04-07 00:02:10 +00:00
|
|
|
commit.Push( _( "DRC" ), SKIP_UNDO | SKIP_SET_DIRTY );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
2020-09-21 19:39:46 +00:00
|
|
|
m_drcRunning = false;
|
|
|
|
|
2021-08-12 16:58:30 +00:00
|
|
|
m_editFrame->ShowSolderMask();
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
// update the m_drcDialog listboxes
|
2023-06-11 11:14:03 +00:00
|
|
|
updatePointers( aProgressReporter->IsCancelled() );
|
2020-09-14 17:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-11 11:14:03 +00:00
|
|
|
void DRC_TOOL::updatePointers( bool aDRCWasCancelled )
|
2020-09-14 17:54:14 +00:00
|
|
|
{
|
|
|
|
// update my pointers, m_editFrame is the only unchangeable one
|
|
|
|
m_pcb = m_editFrame->GetBoard();
|
|
|
|
|
2023-06-11 11:14:03 +00:00
|
|
|
m_editFrame->ResolveDRCExclusions( aDRCWasCancelled );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
2022-08-30 11:03:40 +00:00
|
|
|
if( m_drcDialog )
|
|
|
|
m_drcDialog->UpdateData();
|
2020-09-14 17:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-01 22:35:11 +00:00
|
|
|
int DRC_TOOL::PrevMarker( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
|
|
|
{
|
|
|
|
m_drcDialog->Show( true );
|
|
|
|
m_drcDialog->Raise();
|
|
|
|
m_drcDialog->PrevMarker();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowDRCDialog( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DRC_TOOL::NextMarker( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
|
|
|
{
|
|
|
|
m_drcDialog->Show( true );
|
|
|
|
m_drcDialog->Raise();
|
|
|
|
m_drcDialog->NextMarker();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowDRCDialog( nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-11 17:04:57 +00:00
|
|
|
int DRC_TOOL::CrossProbe( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
|
|
|
{
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
PCB_SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
|
|
|
|
if( selection.GetSize() == 1 && selection.Front()->Type() == PCB_MARKER_T )
|
|
|
|
{
|
2021-10-05 22:33:30 +00:00
|
|
|
if( !m_drcDialog->IsShown() )
|
|
|
|
m_drcDialog->Show( true );
|
|
|
|
|
2021-07-11 17:04:57 +00:00
|
|
|
m_drcDialog->SelectMarker( static_cast<PCB_MARKER*>( selection.Front() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-05 22:33:30 +00:00
|
|
|
void DRC_TOOL::CrossProbe( const PCB_MARKER* aMarker )
|
|
|
|
{
|
|
|
|
if( !IsDRCDialogShown() )
|
|
|
|
ShowDRCDialog( nullptr );
|
|
|
|
|
|
|
|
m_drcDialog->SelectMarker( aMarker );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-01 22:35:11 +00:00
|
|
|
int DRC_TOOL::ExcludeMarker( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( m_drcDialog )
|
|
|
|
m_drcDialog->ExcludeMarker();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
void DRC_TOOL::setTransitions()
|
|
|
|
{
|
|
|
|
Go( &DRC_TOOL::ShowDRCDialog, PCB_ACTIONS::runDRC.MakeEvent() );
|
2020-12-01 22:35:11 +00:00
|
|
|
Go( &DRC_TOOL::PrevMarker, ACTIONS::prevMarker.MakeEvent() );
|
|
|
|
Go( &DRC_TOOL::NextMarker, ACTIONS::nextMarker.MakeEvent() );
|
|
|
|
Go( &DRC_TOOL::ExcludeMarker, ACTIONS::excludeMarker.MakeEvent() );
|
2022-07-19 15:00:35 +00:00
|
|
|
Go( &DRC_TOOL::CrossProbe, EVENTS::PointSelectedEvent );
|
2021-07-11 17:04:57 +00:00
|
|
|
Go( &DRC_TOOL::CrossProbe, EVENTS::SelectedEvent );
|
2023-08-09 23:38:43 +00:00
|
|
|
}
|