2012-03-17 17:30:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-03-17 17:30:03 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file pcbnew_scripting_helpers.cpp
|
|
|
|
* @brief Scripting helper functions for pcbnew functionality
|
|
|
|
*/
|
|
|
|
|
2012-04-20 21:20:56 +00:00
|
|
|
#include <Python.h>
|
2018-08-05 10:28:10 +00:00
|
|
|
#undef HAVE_CLOCK_GETTIME // macro is defined in Python.h and causes redefine warning
|
2012-03-17 17:30:03 +00:00
|
|
|
|
2021-03-19 23:38:11 +00:00
|
|
|
#include "pcbnew_scripting_helpers.h"
|
|
|
|
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <action_plugin.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-14 18:11:28 +00:00
|
|
|
#include <pcb_marker.h>
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <cstdlib>
|
2020-09-23 00:23:14 +00:00
|
|
|
#include <drc/drc_engine.h>
|
|
|
|
#include <drc/drc_item.h>
|
2020-06-05 22:21:41 +00:00
|
|
|
#include <fp_lib_table.h>
|
2012-03-17 15:17:13 +00:00
|
|
|
#include <io_mgr.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <pcbnew_scripting_helpers.h>
|
2020-06-05 22:21:41 +00:00
|
|
|
#include <project.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2021-07-28 19:48:03 +00:00
|
|
|
#include <specctra.h>
|
2020-09-29 15:30:04 +00:00
|
|
|
#include <project/project_local_settings.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-04-28 12:02:47 +00:00
|
|
|
#include <locale_io.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/app.h>
|
2021-04-28 12:02:47 +00:00
|
|
|
|
2012-03-17 15:17:13 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
static PCB_EDIT_FRAME* s_PcbEditFrame = nullptr;
|
2020-05-31 21:42:04 +00:00
|
|
|
static SETTINGS_MANAGER* s_SettingsManager = nullptr;
|
|
|
|
|
2020-09-26 01:27:39 +00:00
|
|
|
|
2013-03-15 16:35:24 +00:00
|
|
|
BOARD* GetBoard()
|
2012-03-17 15:17:13 +00:00
|
|
|
{
|
2017-08-27 06:04:12 +00:00
|
|
|
if( s_PcbEditFrame )
|
|
|
|
return s_PcbEditFrame->GetBoard();
|
2013-03-15 16:35:24 +00:00
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2012-03-17 15:17:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 16:35:24 +00:00
|
|
|
|
2017-08-27 06:04:12 +00:00
|
|
|
void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame )
|
2012-03-17 15:17:13 +00:00
|
|
|
{
|
2017-08-27 06:04:12 +00:00
|
|
|
s_PcbEditFrame = aPcbEditFrame;
|
2012-03-17 15:17:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 16:35:24 +00:00
|
|
|
|
2012-07-31 21:00:33 +00:00
|
|
|
BOARD* LoadBoard( wxString& aFileName )
|
2012-04-14 21:18:27 +00:00
|
|
|
{
|
2021-08-14 13:18:11 +00:00
|
|
|
// Loading a new board is not possible if running inside KiCad
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
return nullptr;
|
|
|
|
|
2021-03-03 01:06:25 +00:00
|
|
|
if( aFileName.EndsWith( KiCadPcbFileExtension ) )
|
2017-10-03 10:23:52 +00:00
|
|
|
return LoadBoard( aFileName, IO_MGR::KICAD_SEXP );
|
2021-03-03 01:06:25 +00:00
|
|
|
else if( aFileName.EndsWith( LegacyPcbFileExtension ) )
|
2013-03-15 16:35:24 +00:00
|
|
|
return LoadBoard( aFileName, IO_MGR::LEGACY );
|
2013-01-16 12:38:30 +00:00
|
|
|
|
2012-04-22 11:14:58 +00:00
|
|
|
// as fall back for any other kind use the legacy format
|
2013-03-15 16:35:24 +00:00
|
|
|
return LoadBoard( aFileName, IO_MGR::LEGACY );
|
2012-04-14 21:18:27 +00:00
|
|
|
}
|
2012-03-17 15:17:13 +00:00
|
|
|
|
2013-03-15 16:35:24 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
SETTINGS_MANAGER* GetSettingsManager()
|
|
|
|
{
|
|
|
|
if( !s_SettingsManager )
|
2020-09-26 01:27:39 +00:00
|
|
|
{
|
2021-08-14 13:18:11 +00:00
|
|
|
if( s_PcbEditFrame )
|
|
|
|
{
|
|
|
|
s_SettingsManager = s_PcbEditFrame->GetSettingsManager();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ensure wx system settings stuff is available
|
|
|
|
static_cast<void>( wxTheApp );
|
|
|
|
s_SettingsManager = new SETTINGS_MANAGER( true );
|
|
|
|
}
|
2020-09-26 01:27:39 +00:00
|
|
|
}
|
2020-05-31 21:42:04 +00:00
|
|
|
|
|
|
|
return s_SettingsManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PROJECT* GetDefaultProject()
|
|
|
|
{
|
2021-07-23 09:28:02 +00:00
|
|
|
// For some reasons, LoadProject() needs a C locale, so ensure we have the right locale
|
|
|
|
// This is mainly when running QA Python tests
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
PROJECT* project = GetSettingsManager()->GetProject( "" );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
if( !project )
|
2020-05-31 21:42:04 +00:00
|
|
|
{
|
|
|
|
GetSettingsManager()->LoadProject( "" );
|
|
|
|
project = GetSettingsManager()->GetProject( "" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-31 21:00:33 +00:00
|
|
|
BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat )
|
2012-03-17 15:17:13 +00:00
|
|
|
{
|
2021-08-14 13:18:11 +00:00
|
|
|
// Loading a new board is not possible if running inside KiCad
|
|
|
|
wxASSERT( !s_PcbEditFrame );
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
wxFileName pro = aFileName;
|
|
|
|
pro.SetExt( ProjectFileExtension );
|
|
|
|
pro.MakeAbsolute();
|
|
|
|
wxString projectPath = pro.GetFullPath();
|
|
|
|
|
2021-04-28 12:02:47 +00:00
|
|
|
// Ensure the "C" locale is temporary set, before reading any file
|
|
|
|
// It also avoid wxWidget alerts about locale issues, later, when using Python 3
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
PROJECT* project = GetSettingsManager()->GetProject( projectPath );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2020-06-20 14:36:16 +00:00
|
|
|
if( !project )
|
2020-05-31 21:42:04 +00:00
|
|
|
{
|
2020-06-20 14:36:16 +00:00
|
|
|
GetSettingsManager()->LoadProject( projectPath );
|
2020-09-23 00:23:14 +00:00
|
|
|
project = GetSettingsManager()->GetProject( projectPath );
|
2020-05-31 21:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Board cannot be loaded without a project, so create the default project
|
|
|
|
if( !project )
|
|
|
|
project = GetDefaultProject();
|
|
|
|
|
2017-08-17 15:55:05 +00:00
|
|
|
BOARD* brd = IO_MGR::Load( aFormat, aFileName );
|
|
|
|
|
|
|
|
if( brd )
|
2018-12-04 01:03:44 +00:00
|
|
|
{
|
2020-05-31 21:42:04 +00:00
|
|
|
brd->SetProject( project );
|
2020-09-29 11:33:44 +00:00
|
|
|
|
|
|
|
// Move legacy view settings to local project settings
|
|
|
|
if( !brd->m_LegacyVisibleLayers.test( Rescue ) )
|
2020-09-29 15:30:04 +00:00
|
|
|
project->GetLocalSettings().m_VisibleLayers = brd->m_LegacyVisibleLayers;
|
2020-09-29 11:33:44 +00:00
|
|
|
|
|
|
|
if( !brd->m_LegacyVisibleItems.test( GAL_LAYER_INDEX( GAL_LAYER_ID_BITMASK_END ) ) )
|
2020-09-29 15:30:04 +00:00
|
|
|
project->GetLocalSettings().m_VisibleItems = brd->m_LegacyVisibleItems;
|
2020-09-29 11:33:44 +00:00
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = brd->GetDesignSettings();
|
|
|
|
bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( brd, &bds );
|
|
|
|
|
2020-10-01 22:43:34 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
wxFileName rules = pro;
|
|
|
|
rules.SetExt( DesignRulesFileExtension );
|
|
|
|
bds.m_DRCEngine->InitEngine( rules );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// Best efforts...
|
|
|
|
}
|
|
|
|
|
2020-11-14 18:11:28 +00:00
|
|
|
for( PCB_MARKER* marker : brd->ResolveDRCExclusions() )
|
2020-09-29 11:33:44 +00:00
|
|
|
brd->Add( marker );
|
|
|
|
|
2017-08-17 15:55:05 +00:00
|
|
|
brd->BuildConnectivity();
|
2018-12-04 01:03:44 +00:00
|
|
|
brd->BuildListOfNets();
|
|
|
|
brd->SynchronizeNetsAndNetClasses();
|
|
|
|
}
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
return brd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOARD* CreateEmptyBoard()
|
|
|
|
{
|
2021-08-14 13:18:11 +00:00
|
|
|
// Creating a new board is not possible if running inside KiCad
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
return nullptr;
|
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
BOARD* brd = new BOARD();
|
|
|
|
|
|
|
|
brd->SetProject( GetDefaultProject() );
|
2017-08-17 15:55:05 +00:00
|
|
|
|
|
|
|
return brd;
|
2012-03-17 15:17:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 16:35:24 +00:00
|
|
|
|
2017-06-23 17:22:27 +00:00
|
|
|
bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat )
|
2012-03-17 15:17:13 +00:00
|
|
|
{
|
2017-08-17 15:55:05 +00:00
|
|
|
aBoard->BuildConnectivity();
|
2013-03-15 16:35:24 +00:00
|
|
|
aBoard->SynchronizeNetsAndNetClasses();
|
2012-03-17 15:17:13 +00:00
|
|
|
|
2021-08-14 13:18:11 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
IO_MGR::Save( aFormat, aFileName, aBoard, nullptr );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-24 16:08:15 +00:00
|
|
|
|
2020-05-31 21:42:04 +00:00
|
|
|
wxFileName pro = aFileName;
|
|
|
|
pro.SetExt( ProjectFileExtension );
|
|
|
|
pro.MakeAbsolute();
|
|
|
|
wxString projectPath = pro.GetFullPath();
|
|
|
|
|
2021-08-14 13:18:11 +00:00
|
|
|
GetSettingsManager()->SaveProjectAs( pro.GetFullPath() );
|
2020-05-31 21:42:04 +00:00
|
|
|
|
2013-03-15 16:35:24 +00:00
|
|
|
return true;
|
2012-03-17 15:17:13 +00:00
|
|
|
}
|
2017-03-17 14:41:00 +00:00
|
|
|
|
|
|
|
|
2017-06-23 17:22:27 +00:00
|
|
|
bool SaveBoard( wxString& aFileName, BOARD* aBoard )
|
|
|
|
{
|
2017-10-03 10:23:52 +00:00
|
|
|
return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
|
2017-06-23 17:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-05 22:21:41 +00:00
|
|
|
FP_LIB_TABLE* GetFootprintLibraryTable()
|
|
|
|
{
|
|
|
|
BOARD* board = GetBoard();
|
|
|
|
|
|
|
|
if( !board )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
PROJECT* project = board->GetProject();
|
|
|
|
|
|
|
|
if( !project )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return project->PcbFootprintLibs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString GetFootprintLibraries()
|
|
|
|
{
|
|
|
|
wxArrayString footprintLibraryNames;
|
|
|
|
|
|
|
|
FP_LIB_TABLE* tbl = GetFootprintLibraryTable();
|
|
|
|
|
|
|
|
if( !tbl )
|
|
|
|
return footprintLibraryNames;
|
|
|
|
|
|
|
|
for( const wxString& name : tbl->GetLogicalLibs() )
|
|
|
|
footprintLibraryNames.Add( name );
|
|
|
|
|
|
|
|
return footprintLibraryNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString GetFootprints( const wxString& aNickName )
|
|
|
|
{
|
|
|
|
wxArrayString footprintNames;
|
|
|
|
|
|
|
|
FP_LIB_TABLE* tbl = GetFootprintLibraryTable();
|
|
|
|
|
|
|
|
if( !tbl )
|
|
|
|
return footprintNames;
|
|
|
|
|
|
|
|
tbl->FootprintEnumerate( footprintNames, aNickName, true );
|
|
|
|
|
|
|
|
return footprintNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-15 22:54:47 +00:00
|
|
|
bool ExportSpecctraDSN( wxString& aFullFilename )
|
|
|
|
{
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
{
|
|
|
|
bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename );
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:48:03 +00:00
|
|
|
|
|
|
|
bool ExportSpecctraDSN( BOARD* aBoard, wxString& aFullFilename )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ExportBoardToSpecctraFile( aBoard, aFullFilename );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit, bool aExport3DFiles,
|
|
|
|
bool aUseRelativePaths, const wxString& a3D_Subdir, double aXRef, double aYRef )
|
2020-08-28 11:17:50 +00:00
|
|
|
{
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
{
|
|
|
|
bool ok = s_PcbEditFrame->ExportVRML_File( aFullFileName, aMMtoWRMLunit,
|
2021-02-21 10:38:10 +00:00
|
|
|
aExport3DFiles, aUseRelativePaths,
|
2021-03-18 18:53:36 +00:00
|
|
|
a3D_Subdir, aXRef, aYRef );
|
2020-08-28 11:17:50 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 22:54:47 +00:00
|
|
|
|
|
|
|
bool ImportSpecctraSES( wxString& aFullFilename )
|
|
|
|
{
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
{
|
|
|
|
bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename );
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-09 16:45:36 +00:00
|
|
|
bool ExportFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath )
|
2019-04-15 22:54:47 +00:00
|
|
|
{
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
{
|
2020-11-09 16:45:36 +00:00
|
|
|
s_PcbEditFrame->ExportFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
|
2019-04-15 22:54:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:41:00 +00:00
|
|
|
void Refresh()
|
|
|
|
{
|
2017-08-27 06:04:12 +00:00
|
|
|
if( s_PcbEditFrame )
|
|
|
|
{
|
2017-12-03 10:19:42 +00:00
|
|
|
auto board = s_PcbEditFrame->GetBoard();
|
|
|
|
board->BuildConnectivity();
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
// Re-init everything: this is the easy way to do that
|
2019-05-30 12:25:08 +00:00
|
|
|
s_PcbEditFrame->ActivateGalCanvas();
|
2019-06-13 17:28:55 +00:00
|
|
|
s_PcbEditFrame->GetCanvas()->Refresh();
|
2017-08-27 06:04:12 +00:00
|
|
|
}
|
2017-03-17 14:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-27 06:04:12 +00:00
|
|
|
void UpdateUserInterface()
|
|
|
|
{
|
|
|
|
if( s_PcbEditFrame )
|
|
|
|
s_PcbEditFrame->UpdateUserInterface();
|
2017-03-17 14:41:00 +00:00
|
|
|
}
|
2018-03-06 08:28:57 +00:00
|
|
|
|
|
|
|
|
2019-02-19 13:46:08 +00:00
|
|
|
int GetUserUnits()
|
|
|
|
{
|
|
|
|
if( s_PcbEditFrame )
|
2019-12-20 14:47:41 +00:00
|
|
|
return static_cast<int>( s_PcbEditFrame->GetUserUnits() );
|
2019-02-19 13:46:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-06 08:28:57 +00:00
|
|
|
bool IsActionRunning()
|
|
|
|
{
|
|
|
|
return ACTION_PLUGINS::IsActionRunning();
|
|
|
|
}
|
2020-09-23 00:23:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits,
|
2020-11-11 23:05:59 +00:00
|
|
|
bool aReportAllTrackErrors )
|
2020-09-23 00:23:14 +00:00
|
|
|
{
|
|
|
|
wxCHECK( aBoard, false );
|
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
|
|
|
|
std::shared_ptr<DRC_ENGINE> engine = bds.m_DRCEngine;
|
|
|
|
|
|
|
|
if( !engine )
|
|
|
|
{
|
|
|
|
bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard, &bds );
|
|
|
|
engine = bds.m_DRCEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxCHECK( engine, false );
|
|
|
|
|
2020-09-26 01:20:54 +00:00
|
|
|
wxFileName fn = aBoard->GetFileName();
|
2020-09-25 01:26:23 +00:00
|
|
|
fn.SetExt( DesignRulesFileExtension );
|
|
|
|
wxString drcRulesPath = s_SettingsManager->Prj().AbsolutePath( fn.GetFullName() );
|
|
|
|
|
2020-09-23 00:23:14 +00:00
|
|
|
try
|
|
|
|
{
|
2020-09-25 01:26:23 +00:00
|
|
|
engine->InitEngine( drcRulesPath );
|
2020-09-23 00:23:14 +00:00
|
|
|
}
|
2021-02-20 19:29:11 +00:00
|
|
|
catch( PARSE_ERROR& )
|
2020-09-23 00:23:14 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<DRC_ITEM>> footprints;
|
|
|
|
std::vector<std::shared_ptr<DRC_ITEM>> unconnected;
|
|
|
|
std::vector<std::shared_ptr<DRC_ITEM>> violations;
|
|
|
|
|
|
|
|
engine->SetProgressReporter( nullptr );
|
|
|
|
|
|
|
|
engine->SetViolationHandler(
|
|
|
|
[&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
|
|
|
|
{
|
|
|
|
if( aItem->GetErrorCode() == DRCE_MISSING_FOOTPRINT
|
|
|
|
|| aItem->GetErrorCode() == DRCE_DUPLICATE_FOOTPRINT
|
|
|
|
|| aItem->GetErrorCode() == DRCE_EXTRA_FOOTPRINT
|
|
|
|
|| aItem->GetErrorCode() == DRCE_NET_CONFLICT )
|
|
|
|
{
|
|
|
|
footprints.push_back( aItem );
|
|
|
|
}
|
|
|
|
else if( aItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
|
|
|
|
{
|
|
|
|
unconnected.push_back( aItem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
violations.push_back( aItem );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-10-28 17:55:57 +00:00
|
|
|
engine->RunTests( aUnits, aReportAllTrackErrors, false );
|
2020-09-23 00:23:14 +00:00
|
|
|
engine->ClearViolationHandler();
|
|
|
|
|
|
|
|
// TODO: Unify this with DIALOG_DRC::writeReport
|
|
|
|
|
|
|
|
FILE* fp = wxFopen( aFileName, wxT( "w" ) );
|
|
|
|
|
|
|
|
if( fp == nullptr )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::map<KIID, EDA_ITEM*> itemMap;
|
|
|
|
aBoard->FillItemMap( itemMap );
|
|
|
|
|
|
|
|
fprintf( fp, "** Drc report for %s **\n", TO_UTF8( aBoard->GetFileName() ) );
|
|
|
|
|
|
|
|
wxDateTime now = wxDateTime::Now();
|
|
|
|
|
|
|
|
fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
|
|
|
|
|
|
|
|
fprintf( fp, "\n** Found %d DRC violations **\n", static_cast<int>( violations.size() ) );
|
|
|
|
|
|
|
|
for( const std::shared_ptr<DRC_ITEM>& item : violations )
|
|
|
|
{
|
2020-12-14 13:33:51 +00:00
|
|
|
SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
|
2020-09-23 00:23:14 +00:00
|
|
|
fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( fp, "\n** Found %d unconnected pads **\n", static_cast<int>( unconnected.size() ) );
|
|
|
|
|
|
|
|
for( const std::shared_ptr<DRC_ITEM>& item : unconnected )
|
|
|
|
{
|
2020-12-14 13:33:51 +00:00
|
|
|
SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
|
2020-09-23 00:23:14 +00:00
|
|
|
fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( fp, "\n** Found %d Footprint errors **\n", static_cast<int>( footprints.size() ) );
|
|
|
|
|
|
|
|
for( const std::shared_ptr<DRC_ITEM>& item : footprints )
|
|
|
|
{
|
2020-12-14 13:33:51 +00:00
|
|
|
SEVERITY severity = bds.GetSeverity( item->GetErrorCode() );
|
2020-09-23 00:23:14 +00:00
|
|
|
fprintf( fp, "%s", TO_UTF8( item->ShowReport( aUnits, severity, itemMap ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( fp, "\n** End of Report **\n" );
|
|
|
|
fclose( fp );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|