2020-06-13 23:28:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-07-31 15:02:04 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-06-13 23:28:08 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DRC_ENGINE_H
|
|
|
|
#define DRC_ENGINE_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2020-09-13 10:37:20 +00:00
|
|
|
#include <unordered_map>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
#include <units_provider.h>
|
2021-02-01 22:45:56 +00:00
|
|
|
#include <geometry/shape.h>
|
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
#include <drc/drc_rule.h>
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BOARD_DESIGN_SETTINGS;
|
2020-09-13 10:37:20 +00:00
|
|
|
class DRC_TEST_PROVIDER;
|
2020-06-13 23:28:08 +00:00
|
|
|
class PCB_EDIT_FRAME;
|
2021-02-22 23:47:17 +00:00
|
|
|
class DS_PROXY_VIEW_ITEM;
|
2020-06-13 23:28:08 +00:00
|
|
|
class BOARD_ITEM;
|
|
|
|
class BOARD;
|
2020-11-14 18:11:28 +00:00
|
|
|
class PCB_MARKER;
|
2020-06-13 23:28:08 +00:00
|
|
|
class NETCLASS;
|
|
|
|
class NETLIST;
|
2020-10-10 15:10:04 +00:00
|
|
|
class NETINFO_ITEM;
|
2020-06-13 23:28:08 +00:00
|
|
|
class PROGRESS_REPORTER;
|
2020-06-17 22:36:54 +00:00
|
|
|
class REPORTER;
|
2020-10-24 14:45:37 +00:00
|
|
|
class wxFileName;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-11 15:40:36 +00:00
|
|
|
namespace KIGFX
|
2020-08-25 17:42:52 +00:00
|
|
|
{
|
2020-10-06 09:24:19 +00:00
|
|
|
class VIEW_OVERLAY;
|
2020-08-25 17:42:52 +00:00
|
|
|
};
|
2020-08-12 22:19:34 +00:00
|
|
|
|
2020-09-15 11:06:15 +00:00
|
|
|
void drcPrintDebugMessage( int level, const wxString& msg, const char *function, int line );
|
2020-08-12 22:19:34 +00:00
|
|
|
|
2020-08-11 22:15:50 +00:00
|
|
|
#define drc_dbg(level, fmt, ...) \
|
2020-08-12 22:19:34 +00:00
|
|
|
drcPrintDebugMessage(level, wxString::Format( fmt, __VA_ARGS__ ), __FUNCTION__, __LINE__ );
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
class DRC_RULE_CONDITION;
|
|
|
|
class DRC_ITEM;
|
|
|
|
class DRC_RULE;
|
|
|
|
class DRC_CONSTRAINT;
|
|
|
|
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2022-08-15 16:59:34 +00:00
|
|
|
typedef std::function<void( const std::shared_ptr<DRC_ITEM>& aItem,
|
|
|
|
const VECTOR2I& aPos,
|
|
|
|
int aLayer )> DRC_VIOLATION_HANDLER;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-16 20:38:23 +00:00
|
|
|
* Design Rule Checker object that performs all the DRC tests.
|
|
|
|
*
|
|
|
|
* Optionally reports violations via a DRC_VIOLATION_HANDLER, user-level progress via a
|
|
|
|
* PROGRESS_REPORTER and rule parse errors via a REPORTER, all set through various setter
|
|
|
|
* calls.
|
|
|
|
*
|
2021-02-08 14:53:49 +00:00
|
|
|
* Note that EvalRules() has yet another optional REPORTER for reporting resolution info to
|
|
|
|
* the user.
|
2020-06-13 23:28:08 +00:00
|
|
|
*/
|
2022-09-19 16:09:59 +00:00
|
|
|
class DRC_ENGINE : public UNITS_PROVIDER
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-09-18 14:24:09 +00:00
|
|
|
DRC_ENGINE( BOARD* aBoard = nullptr, BOARD_DESIGN_SETTINGS* aSettings = nullptr );
|
2022-12-05 14:42:05 +00:00
|
|
|
virtual ~DRC_ENGINE();
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-18 14:24:09 +00:00
|
|
|
void SetBoard( BOARD* aBoard ) { m_board = aBoard; }
|
|
|
|
BOARD* GetBoard() const { return m_board; }
|
|
|
|
|
|
|
|
void SetDesignSettings( BOARD_DESIGN_SETTINGS* aSettings ) { m_designSettings = aSettings; }
|
|
|
|
BOARD_DESIGN_SETTINGS* GetDesignSettings() const { return m_designSettings; }
|
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
void SetSchematicNetlist( NETLIST* aNetlist ) { m_schematicNetlist = aNetlist; }
|
|
|
|
NETLIST* GetSchematicNetlist() const { return m_schematicNetlist; }
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void SetDrawingSheet( DS_PROXY_VIEW_ITEM* aDrawingSheet ) { m_drawingSheet = aDrawingSheet; }
|
|
|
|
DS_PROXY_VIEW_ITEM* GetDrawingSheet() const { return m_drawingSheet; }
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
void SetDebugOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
|
|
|
|
{
|
|
|
|
m_debugOverlay = aOverlay;
|
|
|
|
}
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
std::shared_ptr<KIGFX::VIEW_OVERLAY> GetDebugOverlay() const { return m_debugOverlay; }
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
/**
|
|
|
|
* Set an optional DRC violation handler (receives DRC_ITEMs and positions).
|
2020-09-14 17:54:14 +00:00
|
|
|
*/
|
|
|
|
void SetViolationHandler( DRC_VIOLATION_HANDLER aHandler )
|
|
|
|
{
|
|
|
|
m_violationHandler = std::move( aHandler );
|
|
|
|
}
|
|
|
|
|
2020-09-15 19:13:45 +00:00
|
|
|
void ClearViolationHandler()
|
|
|
|
{
|
|
|
|
m_violationHandler = DRC_VIOLATION_HANDLER();
|
|
|
|
}
|
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
/**
|
|
|
|
* Set an optional reporter for user-level progress info.
|
2020-09-14 17:54:14 +00:00
|
|
|
*/
|
2020-09-12 19:28:22 +00:00
|
|
|
void SetProgressReporter( PROGRESS_REPORTER* aProgRep ) { m_progressReporter = aProgRep; }
|
2020-09-23 10:46:41 +00:00
|
|
|
PROGRESS_REPORTER* GetProgressReporter() const { return m_progressReporter; }
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
/*
|
2020-09-16 20:38:23 +00:00
|
|
|
* Set an optional reporter for rule parse/compile/run-time errors and log-level progress
|
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* Note: if no log reporter is installed rule parse/compile/run-time errors are returned
|
|
|
|
* via a thrown PARSE_ERROR exception.
|
2020-09-14 17:54:14 +00:00
|
|
|
*/
|
2020-09-12 19:28:22 +00:00
|
|
|
void SetLogReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
/**
|
2021-07-26 19:35:12 +00:00
|
|
|
* Initialize the DRC engine.
|
2020-09-16 20:38:23 +00:00
|
|
|
*
|
|
|
|
* @throws PARSE_ERROR if the rules file contains errors
|
|
|
|
*/
|
2020-09-12 23:38:35 +00:00
|
|
|
void InitEngine( const wxFileName& aRulePath );
|
2020-09-11 23:25:10 +00:00
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
/**
|
2021-07-26 19:35:12 +00:00
|
|
|
* Run the DRC tests.
|
2020-09-16 20:38:23 +00:00
|
|
|
*/
|
2020-10-28 17:55:57 +00:00
|
|
|
void RunTests( EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
bool IsErrorLimitExceeded( int error_code );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2021-08-06 12:15:01 +00:00
|
|
|
DRC_CONSTRAINT EvalRules( DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM* a,
|
2021-02-08 14:53:49 +00:00
|
|
|
const BOARD_ITEM* b, PCB_LAYER_ID aLayer,
|
|
|
|
REPORTER* aReporter = nullptr );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2021-08-08 13:37:14 +00:00
|
|
|
DRC_CONSTRAINT EvalZoneConnection( const BOARD_ITEM* a, const BOARD_ITEM* b,
|
|
|
|
PCB_LAYER_ID aLayer, REPORTER* aReporter = nullptr );
|
|
|
|
|
2021-09-22 21:20:18 +00:00
|
|
|
void ProcessAssertions( const BOARD_ITEM* a,
|
|
|
|
std::function<void( const DRC_CONSTRAINT* )> aFailureHandler,
|
|
|
|
REPORTER* aReporter = nullptr );
|
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
bool HasRulesForConstraintType( DRC_CONSTRAINT_T constraintID );
|
2020-07-23 14:22:45 +00:00
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
bool GetReportAllTrackErrors() const { return m_reportAllTrackErrors; }
|
|
|
|
bool GetTestFootprints() const { return m_testFootprints; }
|
2020-09-11 16:24:27 +00:00
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
bool RulesValid() { return m_rulesValid; }
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void ReportViolation( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos,
|
2022-08-15 16:59:34 +00:00
|
|
|
int aMarkerLayer );
|
2021-12-26 13:47:00 +00:00
|
|
|
|
2022-06-15 00:41:10 +00:00
|
|
|
bool KeepRefreshing( bool aWait = false );
|
|
|
|
void AdvanceProgress();
|
|
|
|
void SetMaxProgress( int aSize );
|
2020-09-18 19:57:54 +00:00
|
|
|
bool ReportProgress( double aProgress );
|
|
|
|
bool ReportPhase( const wxString& aMessage );
|
2020-06-18 16:55:22 +00:00
|
|
|
void ReportAux( const wxString& aStr );
|
2022-03-11 20:13:47 +00:00
|
|
|
bool IsCancelled() const;
|
2020-06-18 16:55:22 +00:00
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
bool QueryWorstConstraint( DRC_CONSTRAINT_T aRuleId, DRC_CONSTRAINT& aConstraint );
|
2022-07-31 15:02:04 +00:00
|
|
|
std::set<int> QueryDistinctConstraints( DRC_CONSTRAINT_T aConstraintId );
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
std::vector<DRC_TEST_PROVIDER*> GetTestProviders() const { return m_testProviders; };
|
2020-09-18 14:24:09 +00:00
|
|
|
|
2020-09-23 21:48:11 +00:00
|
|
|
DRC_TEST_PROVIDER* GetTestProvider( const wxString& name ) const;
|
|
|
|
|
2021-02-01 00:38:20 +00:00
|
|
|
static bool IsNetADiffPair( BOARD* aBoard, NETINFO_ITEM* aNet, int& aNetP, int& aNetN );
|
2020-10-08 21:57:53 +00:00
|
|
|
|
2021-02-28 00:54:55 +00:00
|
|
|
/**
|
2021-07-26 19:35:12 +00:00
|
|
|
* Check if the given net is a diff pair, returning its polarity and complement if so
|
2021-02-28 00:54:55 +00:00
|
|
|
* @param aNetName is the input net name, like DIFF_P
|
|
|
|
* @param aComplementNet will be filled with the complement, like DIFF_N
|
|
|
|
* @param aBaseDpName will be filled with the base name, like DIFF
|
|
|
|
* @return 1 if aNetName is the positive half of a pair, -1 if negative, 0 if not a diff pair
|
|
|
|
*/
|
|
|
|
static int MatchDpSuffix( const wxString& aNetName, wxString& aComplementNet,
|
|
|
|
wxString& aBaseDpName );
|
|
|
|
|
2022-08-19 17:34:53 +00:00
|
|
|
/**
|
|
|
|
* Check if the given collision between a track and another item occurs during the track's
|
|
|
|
* entry into a net-tie pad.
|
|
|
|
*/
|
|
|
|
static bool IsNetTieExclusion( int aTrackNetCode, PCB_LAYER_ID aTrackLayer,
|
|
|
|
const VECTOR2I& aCollisionPos, BOARD_ITEM* aCollidingItem );
|
2021-02-01 22:45:56 +00:00
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
private:
|
2022-01-10 21:05:14 +00:00
|
|
|
void addRule( std::shared_ptr<DRC_RULE>& rule )
|
2020-08-26 22:07:31 +00:00
|
|
|
{
|
|
|
|
m_rules.push_back(rule);
|
|
|
|
}
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2020-09-17 17:56:20 +00:00
|
|
|
/**
|
2021-07-26 19:35:12 +00:00
|
|
|
* Load and parse a rule set from an sexpr text file.
|
2020-09-17 17:56:20 +00:00
|
|
|
*
|
|
|
|
* @throws PARSE_ERROR
|
|
|
|
*/
|
|
|
|
void loadRules( const wxFileName& aPath );
|
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
void compileRules();
|
2020-07-27 13:33:06 +00:00
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
struct DRC_ENGINE_CONSTRAINT
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2022-01-10 21:05:14 +00:00
|
|
|
LSET layerTest;
|
|
|
|
DRC_RULE_CONDITION* condition;
|
|
|
|
std::shared_ptr<DRC_RULE> parentRule;
|
|
|
|
DRC_CONSTRAINT constraint;
|
2020-06-13 23:28:08 +00:00
|
|
|
};
|
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
void loadImplicitRules();
|
2022-01-10 21:05:14 +00:00
|
|
|
std::shared_ptr<DRC_RULE> createImplicitRule( const wxString& name );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
protected:
|
2022-01-10 21:05:14 +00:00
|
|
|
BOARD_DESIGN_SETTINGS* m_designSettings;
|
|
|
|
BOARD* m_board;
|
|
|
|
DS_PROXY_VIEW_ITEM* m_drawingSheet;
|
|
|
|
NETLIST* m_schematicNetlist;
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2022-01-10 21:05:14 +00:00
|
|
|
std::vector<std::shared_ptr<DRC_RULE>> m_rules;
|
|
|
|
bool m_rulesValid;
|
|
|
|
std::vector<DRC_TEST_PROVIDER*> m_testProviders;
|
2020-09-14 17:54:14 +00:00
|
|
|
|
2022-01-10 21:05:14 +00:00
|
|
|
std::vector<int> m_errorLimits;
|
|
|
|
bool m_reportAllTrackErrors;
|
|
|
|
bool m_testFootprints;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2020-09-13 10:37:20 +00:00
|
|
|
// constraint -> rule -> provider
|
2022-08-26 02:51:11 +00:00
|
|
|
std::map<DRC_CONSTRAINT_T, std::vector<DRC_ENGINE_CONSTRAINT*>*> m_constraintMap;
|
2020-09-12 19:28:22 +00:00
|
|
|
|
2022-01-10 21:05:14 +00:00
|
|
|
DRC_VIOLATION_HANDLER m_violationHandler;
|
|
|
|
REPORTER* m_reporter;
|
|
|
|
PROGRESS_REPORTER* m_progressReporter;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-10-06 09:24:19 +00:00
|
|
|
std::shared_ptr<KIGFX::VIEW_OVERLAY> m_debugOverlay;
|
2020-06-13 23:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DRC_H
|