2007-12-01 03:42:52 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2007-12-01 03:42:52 +00:00
|
|
|
*
|
2019-01-26 12:01:48 +00:00
|
|
|
* Copyright (C) 2004-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2014-08-13 15:47:02 +00:00
|
|
|
* Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com
|
2020-02-24 23:17:30 +00:00
|
|
|
* Copyright (C) 2017-2020 KiCad Developers, see change_log.txt for contributors.
|
2007-12-01 03:42:52 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2018-02-02 20:57:12 +00:00
|
|
|
#include <board_design_settings.h>
|
2018-08-27 13:50:50 +00:00
|
|
|
#include <class_drawsegment.h>
|
2016-01-20 14:22:09 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-06-03 13:49:17 +00:00
|
|
|
#include <tools/pcb_tool_base.h>
|
2019-11-17 12:58:38 +00:00
|
|
|
#include <netlist_reader/pcb_netlist.h>
|
2020-05-24 14:54:26 +00:00
|
|
|
#include <drc/drc.h>
|
2020-05-18 00:20:16 +00:00
|
|
|
#include <drc/drc_rule_parser.h>
|
2020-05-24 14:54:26 +00:00
|
|
|
#include <dialogs/panel_setup_rules.h>
|
2020-09-14 17:54:14 +00:00
|
|
|
#include <project.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <reporter.h>
|
2020-08-09 10:55:00 +00:00
|
|
|
|
2020-07-04 18:48:22 +00:00
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
DRC::DRC() :
|
2020-09-14 17:54:14 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.legacyDRCTool" ),
|
|
|
|
m_editFrame( nullptr )
|
2019-06-03 13:49:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DRC::~DRC()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2020-05-24 14:54:26 +00:00
|
|
|
m_editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
2007-12-01 03:42:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 10:25:13 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
// JEY TODO: make DRC_TOOL's DRC_ENGINE be long-lived so it can be used for BOARD_CONNECTED_ITEM's
|
|
|
|
// GetClearance() and the retire this.
|
2007-11-27 01:34:35 +00:00
|
|
|
|
2020-05-24 14:54:26 +00:00
|
|
|
bool DRC::LoadRules()
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
2020-05-24 14:54:26 +00:00
|
|
|
wxString rulesFilepath = m_editFrame->Prj().AbsolutePath( "drc-rules" );
|
2020-05-16 19:12:56 +00:00
|
|
|
wxFileName rulesFile( rulesFilepath );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-05-16 19:12:56 +00:00
|
|
|
if( rulesFile.FileExists() )
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
2020-05-18 16:11:57 +00:00
|
|
|
m_rules.clear();
|
2020-05-16 19:12:56 +00:00
|
|
|
|
2020-05-18 16:11:57 +00:00
|
|
|
FILE* fp = wxFopen( rulesFilepath, wxT( "rt" ) );
|
2020-05-16 19:12:56 +00:00
|
|
|
|
2020-05-18 16:11:57 +00:00
|
|
|
if( fp )
|
|
|
|
{
|
|
|
|
try
|
2020-05-16 19:12:56 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
DRC_RULES_PARSER parser( m_editFrame->GetBoard(), fp, rulesFilepath );
|
2020-07-30 11:24:29 +00:00
|
|
|
parser.Parse( m_rules, &NULL_REPORTER::GetInstance() );
|
2020-05-18 16:11:57 +00:00
|
|
|
}
|
|
|
|
catch( PARSE_ERROR& pe )
|
|
|
|
{
|
|
|
|
// Don't leave possibly malformed stuff around for us to trip over
|
|
|
|
m_rules.clear();
|
2020-05-16 19:12:56 +00:00
|
|
|
|
2020-05-24 14:54:26 +00:00
|
|
|
wxSafeYield( m_editFrame );
|
|
|
|
m_editFrame->ShowBoardSetupDialog( _( "Rules" ), pe.What(), ID_RULES_EDITOR,
|
|
|
|
pe.lineNumber, pe.byteIndex );
|
|
|
|
|
|
|
|
return false;
|
2020-05-16 19:12:56 +00:00
|
|
|
}
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-16 19:12:56 +00:00
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
std::reverse( std::begin( m_rules ), std::end( m_rules ) );
|
2020-05-23 21:48:24 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_editFrame->GetBoard()->GetDesignSettings();
|
2020-05-16 19:12:56 +00:00
|
|
|
bds.m_DRCRules = m_rules;
|
2020-05-24 14:54:26 +00:00
|
|
|
|
|
|
|
return true;
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|