2020-06-13 23:28:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-07-03 16:37:08 +00:00
|
|
|
* Copyright (C) 2019-2020 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 <board_commit.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_marker_pcb.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <tools/pcb_tool_base.h>
|
|
|
|
#include <vector>
|
|
|
|
|
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;
|
|
|
|
class PCB_EDIT_FRAME;
|
|
|
|
class DIALOG_DRC;
|
|
|
|
class BOARD_ITEM;
|
|
|
|
class BOARD;
|
|
|
|
class D_PAD;
|
|
|
|
class ZONE_CONTAINER;
|
|
|
|
class TRACK;
|
|
|
|
class MARKER_PCB;
|
|
|
|
class NETCLASS;
|
|
|
|
class EDA_TEXT;
|
|
|
|
class DRAWSEGMENT;
|
|
|
|
class NETLIST;
|
|
|
|
class PROGRESS_REPORTER;
|
2020-06-17 22:36:54 +00:00
|
|
|
class REPORTER;
|
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
|
|
|
{
|
|
|
|
class WS_PROXY_VIEW_ITEM;
|
|
|
|
};
|
2020-08-12 22:19:34 +00:00
|
|
|
|
|
|
|
void drcPrintDebugMessage( int level, wxString msg, const char *function, int line );
|
|
|
|
|
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;
|
2020-09-11 15:04:11 +00:00
|
|
|
class LEGACY_DRC_TEST_PROVIDER;
|
2020-06-13 23:28:08 +00:00
|
|
|
class DRC_CONSTRAINT;
|
|
|
|
|
2020-08-11 22:15:50 +00:00
|
|
|
enum DRC_CONSTRAINT_QUERY_T
|
|
|
|
{
|
|
|
|
DRCCQ_LARGEST_MINIMUM = 0
|
|
|
|
// fixme: more to come I guess...
|
|
|
|
};
|
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-08-11 22:15:50 +00:00
|
|
|
class DRC_REPORT
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct ENTRY
|
|
|
|
{
|
|
|
|
std::shared_ptr<DRC_ITEM> m_item;
|
2020-09-11 23:25:10 +00:00
|
|
|
MARKER_PCB* m_marker;
|
2020-08-11 22:15:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<ENTRY> ENTRIES;
|
|
|
|
|
|
|
|
DRC_REPORT() {};
|
|
|
|
~DRC_REPORT();
|
|
|
|
|
|
|
|
void AddItem( std::shared_ptr<DRC_ITEM> aItem, ::MARKER_PCB *aMarker = nullptr)
|
|
|
|
{
|
|
|
|
ENTRY ent;
|
|
|
|
ent.m_item = aItem;
|
|
|
|
ent.m_marker = aMarker;
|
|
|
|
m_entries.push_back(ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ENTRIES& GetReportEntries() const { return m_entries; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
ENTRIES m_entries;
|
|
|
|
};
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Design Rule Checker object that performs all the DRC tests. The output of
|
|
|
|
* the checking goes to the BOARD file in the form of two MARKER lists. Those
|
|
|
|
* two lists are displayable in the drc dialog box. And they can optionally
|
|
|
|
* be sent to a text file on disk.
|
|
|
|
* This class is given access to the windows and the BOARD
|
|
|
|
* that it needs via its constructor or public access functions.
|
|
|
|
*/
|
|
|
|
class DRC_ENGINE
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
DRC_ENGINE( BOARD* aBoard, BOARD_DESIGN_SETTINGS* aSettings );
|
|
|
|
~DRC_ENGINE();
|
|
|
|
|
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
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
// JEY TODO: why isn't this called?
|
|
|
|
void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ) { m_worksheet = aWorksheet; }
|
|
|
|
KIGFX::WS_PROXY_VIEW_ITEM* GetWorksheet() const { return m_worksheet; }
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
// JEY TODO: rationalize old progress report style with new...
|
|
|
|
void SetProgressReporter( PROGRESS_REPORTER* aProgRep ) { m_progressReporter = aProgRep; }
|
2020-08-25 17:42:52 +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-12 00:22:46 +00:00
|
|
|
bool LoadRules( wxFileName aPath );
|
|
|
|
|
|
|
|
void InitEngine( wxFileName aRulePath );
|
2020-09-11 23:25:10 +00:00
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
void RunTests();
|
|
|
|
|
|
|
|
void SetErrorLimit( int aLimit );
|
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
BOARD_DESIGN_SETTINGS* GetDesignSettings() const { return m_designSettings; }
|
2020-08-11 22:17:43 +00:00
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
BOARD* GetBoard() const { return m_board; }
|
|
|
|
|
|
|
|
bool IsErrorLimitExceeded( int error_code )
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-12 19:28:22 +00:00
|
|
|
m_errorLimits[ error_code ] -= 1;
|
|
|
|
|
|
|
|
return m_errorLimits[ error_code ] <= 0;
|
2020-06-13 23:28:08 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
DRC_CONSTRAINT EvalRulesForItems( DRC_CONSTRAINT_TYPE_T ruleID, BOARD_ITEM* a,
|
|
|
|
BOARD_ITEM* b = nullptr,
|
2020-09-11 23:25:10 +00:00
|
|
|
PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
|
|
|
|
REPORTER* aReporter = nullptr );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
std::vector<DRC_CONSTRAINT> QueryConstraintsById( DRC_CONSTRAINT_TYPE_T ruleID );
|
2020-08-25 17:42:52 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
bool HasCorrectRulesForId( DRC_CONSTRAINT_TYPE_T ruleID );
|
2020-07-23 14:22:45 +00:00
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
EDA_UNITS UserUnits() const
|
|
|
|
{
|
2020-09-11 16:24:27 +00:00
|
|
|
// JEY TODO
|
2020-06-13 23:28:08 +00:00
|
|
|
return EDA_UNITS::MILLIMETRES;
|
|
|
|
}
|
|
|
|
|
2020-09-11 16:24:27 +00:00
|
|
|
bool GetTestTracksAgainstZones() const
|
|
|
|
{
|
|
|
|
// JEY TODO
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
bool CompileRules();
|
|
|
|
|
2020-09-12 19:28:22 +00:00
|
|
|
void Report( std::shared_ptr<DRC_ITEM> aItem, MARKER_PCB *Marker );
|
2020-06-18 16:55:22 +00:00
|
|
|
void ReportProgress( double aProgress );
|
|
|
|
void ReportStage ( const wxString& aStageName, int index, int total );
|
|
|
|
void ReportAux( const wxString& aStr );
|
|
|
|
|
2020-08-11 22:15:50 +00:00
|
|
|
std::shared_ptr<DRC_REPORT> GetReport() const { return m_drcReport; }
|
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
bool QueryWorstConstraint( DRC_CONSTRAINT_TYPE_T aRuleId, DRC_CONSTRAINT& aConstraint,
|
|
|
|
DRC_CONSTRAINT_QUERY_T aQueryType );
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2020-06-13 23:28:08 +00:00
|
|
|
private:
|
2020-09-11 15:04:11 +00:00
|
|
|
void addRule( 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-07-27 13:33:06 +00:00
|
|
|
void freeCompiledRules();
|
|
|
|
|
2020-08-12 22:19:34 +00:00
|
|
|
struct CONSTRAINT_WITH_CONDITIONS
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-09-11 15:04:11 +00:00
|
|
|
std::vector<DRC_RULE_CONDITION*> conditions;
|
|
|
|
DRC_RULE* parentRule;
|
|
|
|
DRC_CONSTRAINT constraint;
|
2020-06-13 23:28:08 +00:00
|
|
|
};
|
|
|
|
|
2020-08-12 22:19:34 +00:00
|
|
|
struct CONSTRAINT_SET
|
2020-06-13 23:28:08 +00:00
|
|
|
{
|
2020-08-12 22:19:34 +00:00
|
|
|
std::vector<CONSTRAINT_WITH_CONDITIONS*> sortedConstraints;
|
2020-09-11 15:04:11 +00:00
|
|
|
DRC_TEST_PROVIDER* provider;
|
2020-06-13 23:28:08 +00:00
|
|
|
};
|
|
|
|
|
2020-08-26 22:07:31 +00:00
|
|
|
void inferLegacyRules();
|
2020-06-13 23:28:08 +00:00
|
|
|
void loadTestProviders();
|
2020-09-11 15:04:11 +00:00
|
|
|
DRC_RULE* createInferredRule( const wxString& name, std::set<BOARD_ITEM*> items, int priority );
|
2020-06-13 23:28:08 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
protected:
|
|
|
|
BOARD_DESIGN_SETTINGS* m_designSettings;
|
|
|
|
BOARD* m_board;
|
|
|
|
KIGFX::WS_PROXY_VIEW_ITEM* m_worksheet;
|
|
|
|
NETLIST* m_schematicNetlist;
|
2020-08-11 22:15:50 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
std::shared_ptr<DRC_REPORT> m_drcReport;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
std::vector<DRC_RULE_CONDITION*> m_ruleConditions;
|
|
|
|
std::vector<DRC_RULE*> m_rules;
|
|
|
|
std::vector<DRC_TEST_PROVIDER*> m_testProviders;
|
2020-09-12 19:28:22 +00:00
|
|
|
std::vector<int> m_errorLimits;
|
|
|
|
|
|
|
|
std::unordered_map<EDA_ITEM*, CONSTRAINT_SET*> m_implicitRules;
|
|
|
|
std::unordered_map<DRC_CONSTRAINT_TYPE_T, CONSTRAINT_SET*> m_constraintMap;
|
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
REPORTER* m_reporter;
|
|
|
|
PROGRESS_REPORTER* m_progressReporter;
|
2020-06-13 23:28:08 +00:00
|
|
|
|
|
|
|
// condition -> rule -> provider
|
2020-09-11 16:24:27 +00:00
|
|
|
|
|
|
|
wxString m_msg; // Allocating strings gets expensive enough to want to avoid it
|
2020-06-13 23:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DRC_H
|