2020-05-16 00:25:33 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2020-05-16 00:25:33 +01: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
|
|
|
|
*/
|
|
|
|
|
2023-10-11 11:48:43 +01:00
|
|
|
#ifndef DRC_RULE_H
|
|
|
|
#define DRC_RULE_H
|
2020-05-16 00:25:33 +01:00
|
|
|
|
2024-07-29 00:05:13 +01:00
|
|
|
#include <bitset>
|
2022-12-21 18:20:04 +00:00
|
|
|
#include <kiid.h>
|
2020-05-16 00:25:33 +01:00
|
|
|
#include <core/typeinfo.h>
|
2022-08-25 15:50:47 -07:00
|
|
|
#include <optional>
|
2020-10-06 11:23:31 +02:00
|
|
|
#include <core/minoptmax.h>
|
2021-07-29 10:47:43 +01:00
|
|
|
#include <layer_ids.h>
|
2024-07-08 20:58:47 -07:00
|
|
|
#include <lset.h>
|
2020-08-07 21:18:33 +01:00
|
|
|
#include <netclass.h>
|
2021-08-08 14:37:14 +01:00
|
|
|
#include <zones.h>
|
2020-07-19 22:22:49 +01:00
|
|
|
#include <libeval_compiler/libeval_compiler.h>
|
2020-10-24 10:45:37 -04:00
|
|
|
#include <wx/intl.h>
|
2021-09-05 16:06:12 +01:00
|
|
|
#include <widgets/report_severity.h>
|
2020-05-16 00:25:33 +01:00
|
|
|
|
|
|
|
class BOARD_ITEM;
|
2023-08-21 15:26:03 +01:00
|
|
|
class PCBEXPR_UCODE;
|
2020-09-13 00:05:32 +01:00
|
|
|
class DRC_CONSTRAINT;
|
2020-09-11 16:04:11 +01:00
|
|
|
class DRC_RULE_CONDITION;
|
2020-05-23 22:48:24 +01:00
|
|
|
|
2020-09-13 00:05:32 +01:00
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
enum DRC_CONSTRAINT_T
|
2020-08-07 21:18:33 +01:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
NULL_CONSTRAINT = 0,
|
|
|
|
CLEARANCE_CONSTRAINT,
|
2024-10-15 18:04:51 +00:00
|
|
|
CREEPAGE_CONSTRAINT,
|
2020-11-02 16:20:00 +00:00
|
|
|
HOLE_CLEARANCE_CONSTRAINT,
|
2020-11-29 22:01:40 +00:00
|
|
|
HOLE_TO_HOLE_CONSTRAINT,
|
2020-11-02 16:20:00 +00:00
|
|
|
EDGE_CLEARANCE_CONSTRAINT,
|
|
|
|
HOLE_SIZE_CONSTRAINT,
|
|
|
|
COURTYARD_CLEARANCE_CONSTRAINT,
|
|
|
|
SILK_CLEARANCE_CONSTRAINT,
|
2021-07-11 16:12:28 +01:00
|
|
|
TEXT_HEIGHT_CONSTRAINT,
|
|
|
|
TEXT_THICKNESS_CONSTRAINT,
|
2020-11-02 16:20:00 +00:00
|
|
|
TRACK_WIDTH_CONSTRAINT,
|
2024-10-18 19:48:08 +00:00
|
|
|
TRACK_SEGMENT_LENGTH_CONSTRAINT,
|
2020-11-02 16:20:00 +00:00
|
|
|
ANNULAR_WIDTH_CONSTRAINT,
|
2021-08-08 14:37:14 +01:00
|
|
|
ZONE_CONNECTION_CONSTRAINT,
|
|
|
|
THERMAL_RELIEF_GAP_CONSTRAINT,
|
|
|
|
THERMAL_SPOKE_WIDTH_CONSTRAINT,
|
2021-08-09 11:10:09 +01:00
|
|
|
MIN_RESOLVED_SPOKES_CONSTRAINT,
|
2025-06-03 11:34:08 +01:00
|
|
|
SOLDER_MASK_EXPANSION_CONSTRAINT,
|
|
|
|
SOLDER_PASTE_ABS_MARGIN_CONSTRAINT,
|
|
|
|
SOLDER_PASTE_REL_MARGIN_CONSTRAINT,
|
2020-11-02 16:20:00 +00:00
|
|
|
DISALLOW_CONSTRAINT,
|
|
|
|
VIA_DIAMETER_CONSTRAINT,
|
|
|
|
LENGTH_CONSTRAINT,
|
|
|
|
SKEW_CONSTRAINT,
|
|
|
|
DIFF_PAIR_GAP_CONSTRAINT,
|
2023-10-15 22:45:18 +01:00
|
|
|
MAX_UNCOUPLED_CONSTRAINT,
|
2020-11-02 16:20:00 +00:00
|
|
|
DIFF_PAIR_INTRA_SKEW_CONSTRAINT,
|
2021-08-13 20:10:30 +01:00
|
|
|
VIA_COUNT_CONSTRAINT,
|
2022-05-06 14:46:24 +01:00
|
|
|
PHYSICAL_CLEARANCE_CONSTRAINT,
|
|
|
|
PHYSICAL_HOLE_CLEARANCE_CONSTRAINT,
|
2022-07-31 16:02:04 +01:00
|
|
|
ASSERTION_CONSTRAINT,
|
2024-10-16 19:16:42 +00:00
|
|
|
CONNECTION_WIDTH_CONSTRAINT,
|
2025-09-02 08:25:29 -07:00
|
|
|
TRACK_ANGLE_CONSTRAINT,
|
2025-02-06 11:18:16 +01:00
|
|
|
VIA_DANGLING_CONSTRAINT,
|
2025-02-06 15:25:06 +01:00
|
|
|
PAD_FANOUT_RATIO_CONSTRAINT,
|
2025-02-06 18:43:58 +01:00
|
|
|
PAD_FANOUT_VIA_DISTANCE_CONSTRAINT,
|
2025-06-15 15:03:56 +02:00
|
|
|
FOOTPRINT_FANOUT_MIRROR_SYMMETRY_CONSTRAINT,
|
|
|
|
FOOTPRINT_FANOUT_POINT_SYMMETRY_CONSTRAINT,
|
2020-09-11 16:04:11 +01:00
|
|
|
};
|
|
|
|
|
2020-09-13 00:05:32 +01:00
|
|
|
|
2020-09-11 16:04:11 +01:00
|
|
|
enum DRC_DISALLOW_T
|
|
|
|
{
|
|
|
|
DRC_DISALLOW_VIAS = (1 << 0),
|
|
|
|
DRC_DISALLOW_MICRO_VIAS = (1 << 1),
|
|
|
|
DRC_DISALLOW_BB_VIAS = (1 << 2),
|
|
|
|
DRC_DISALLOW_TRACKS = (1 << 3),
|
|
|
|
DRC_DISALLOW_PADS = (1 << 4),
|
|
|
|
DRC_DISALLOW_ZONES = (1 << 5),
|
|
|
|
DRC_DISALLOW_TEXTS = (1 << 6),
|
|
|
|
DRC_DISALLOW_GRAPHICS = (1 << 7),
|
|
|
|
DRC_DISALLOW_HOLES = (1 << 8),
|
|
|
|
DRC_DISALLOW_FOOTPRINTS = (1 << 9)
|
2020-08-07 21:18:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-05-16 00:25:33 +01:00
|
|
|
class DRC_RULE
|
|
|
|
{
|
2020-05-18 21:29:59 +01:00
|
|
|
public:
|
2020-08-07 21:18:33 +01:00
|
|
|
DRC_RULE();
|
2021-08-20 18:25:07 +01:00
|
|
|
DRC_RULE( const wxString& aName );
|
|
|
|
|
2020-08-07 21:18:33 +01:00
|
|
|
virtual ~DRC_RULE();
|
2020-05-23 22:48:24 +01:00
|
|
|
|
2020-09-11 16:04:11 +01:00
|
|
|
virtual bool AppliesTo( const BOARD_ITEM* a, const BOARD_ITEM* b = nullptr ) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AddConstraint( DRC_CONSTRAINT& aConstraint );
|
2022-08-25 15:50:47 -07:00
|
|
|
std::optional<DRC_CONSTRAINT> FindConstraint( DRC_CONSTRAINT_T aType );
|
2020-09-11 16:04:11 +01:00
|
|
|
|
2020-05-16 00:25:33 +01:00
|
|
|
public:
|
2020-09-11 16:04:11 +01:00
|
|
|
bool m_Unary;
|
2020-09-13 11:37:20 +01:00
|
|
|
bool m_Implicit;
|
2022-12-21 18:20:04 +00:00
|
|
|
KIID m_ImplicitItemId;
|
2020-08-07 21:18:33 +01:00
|
|
|
wxString m_Name;
|
2020-09-10 20:58:05 +01:00
|
|
|
wxString m_LayerSource;
|
2020-08-07 21:18:33 +01:00
|
|
|
LSET m_LayerCondition;
|
2020-09-11 16:04:11 +01:00
|
|
|
DRC_RULE_CONDITION* m_Condition;
|
2020-08-07 21:18:33 +01:00
|
|
|
std::vector<DRC_CONSTRAINT> m_Constraints;
|
2021-09-05 16:06:12 +01:00
|
|
|
SEVERITY m_Severity;
|
2020-09-13 00:05:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DRC_CONSTRAINT
|
|
|
|
{
|
2024-10-29 16:30:32 +00:00
|
|
|
public:
|
2021-01-01 22:29:15 +00:00
|
|
|
DRC_CONSTRAINT( DRC_CONSTRAINT_T aType = NULL_CONSTRAINT,
|
2020-09-13 00:05:32 +01:00
|
|
|
const wxString& aName = wxEmptyString ) :
|
|
|
|
m_Type( aType ),
|
2021-05-30 19:47:57 -04:00
|
|
|
m_Value(),
|
2020-09-13 00:05:32 +01:00
|
|
|
m_DisallowFlags( 0 ),
|
2021-08-08 14:37:14 +01:00
|
|
|
m_ZoneConnection( ZONE_CONNECTION::INHERITED ),
|
2021-09-22 22:20:18 +01:00
|
|
|
m_Test( nullptr ),
|
2024-10-29 16:30:32 +00:00
|
|
|
m_ImplicitMin( false ),
|
2020-09-13 00:05:32 +01:00
|
|
|
m_name( aName ),
|
|
|
|
m_parentRule( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-07-29 00:05:13 +01:00
|
|
|
enum class OPTIONS : std::size_t
|
|
|
|
{
|
2025-02-10 20:57:51 +00:00
|
|
|
SKEW_WITHIN_DIFF_PAIRS = 0,
|
|
|
|
SPACE_DOMAIN,
|
|
|
|
TIME_DOMAIN,
|
|
|
|
|
|
|
|
// Keep this last value - used to statically size the options bitset
|
|
|
|
NUM_OPTIONS
|
2024-07-29 00:05:13 +01:00
|
|
|
};
|
|
|
|
|
2020-09-23 23:47:35 +02:00
|
|
|
bool IsNull() const
|
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
return m_Type == NULL_CONSTRAINT;
|
2020-09-23 23:47:35 +02:00
|
|
|
}
|
|
|
|
|
2020-09-13 00:05:32 +01:00
|
|
|
const MINOPTMAX<int>& GetValue() const { return m_Value; }
|
|
|
|
MINOPTMAX<int>& Value() { return m_Value; }
|
|
|
|
|
|
|
|
void SetParentRule( DRC_RULE *aParentRule ) { m_parentRule = aParentRule; }
|
|
|
|
DRC_RULE* GetParentRule() const { return m_parentRule; }
|
|
|
|
|
2021-08-21 01:58:21 +01:00
|
|
|
void SetName( const wxString& aName ) { m_name = aName; }
|
|
|
|
|
2020-09-13 00:05:32 +01:00
|
|
|
wxString GetName() const
|
|
|
|
{
|
|
|
|
if( m_parentRule )
|
2020-09-13 11:37:20 +01:00
|
|
|
{
|
|
|
|
if( m_parentRule->m_Implicit )
|
|
|
|
return m_parentRule->m_Name;
|
|
|
|
else
|
2023-10-11 11:48:43 +01:00
|
|
|
return wxString::Format( _( "rule '%s'" ), m_parentRule->m_Name );
|
2020-09-13 11:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_name;
|
2020-09-13 00:05:32 +01:00
|
|
|
}
|
|
|
|
|
2021-09-05 16:06:12 +01:00
|
|
|
SEVERITY GetSeverity() const
|
|
|
|
{
|
|
|
|
if( m_parentRule )
|
|
|
|
return m_parentRule->m_Severity;
|
|
|
|
else
|
|
|
|
return RPT_SEVERITY_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2024-07-29 00:05:13 +01:00
|
|
|
void SetOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), true ); }
|
|
|
|
|
2025-02-10 20:57:51 +00:00
|
|
|
void ClearOption( OPTIONS option ) { m_options.set( static_cast<std::size_t>( option ), false ); }
|
|
|
|
|
2024-07-29 00:05:13 +01:00
|
|
|
bool GetOption( OPTIONS option ) const
|
|
|
|
{
|
|
|
|
return m_options.test( static_cast<std::size_t>( option ) );
|
|
|
|
}
|
|
|
|
|
2025-02-10 20:57:51 +00:00
|
|
|
void SetOptionsFromOther( const DRC_CONSTRAINT& aOther ) { m_options = aOther.m_options; }
|
|
|
|
|
2020-09-13 00:05:32 +01:00
|
|
|
public:
|
2021-09-22 22:20:18 +01:00
|
|
|
DRC_CONSTRAINT_T m_Type;
|
|
|
|
MINOPTMAX<int> m_Value;
|
|
|
|
int m_DisallowFlags;
|
|
|
|
ZONE_CONNECTION m_ZoneConnection;
|
|
|
|
DRC_RULE_CONDITION* m_Test;
|
2024-10-29 16:30:32 +00:00
|
|
|
bool m_ImplicitMin;
|
2020-09-13 00:05:32 +01:00
|
|
|
|
|
|
|
private:
|
2021-09-22 22:20:18 +01:00
|
|
|
wxString m_name; // For just-in-time constraints
|
|
|
|
DRC_RULE* m_parentRule; // For constraints found in rules
|
2025-02-10 20:57:51 +00:00
|
|
|
std::bitset<static_cast<int>( OPTIONS::NUM_OPTIONS )> m_options; // Constraint-specific option bits
|
|
|
|
// (indexed from DRC_CONSTRAINT::OPTIONS)
|
2020-05-16 00:25:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-07 21:18:33 +01:00
|
|
|
const DRC_CONSTRAINT* GetConstraint( const BOARD_ITEM* aItem, const BOARD_ITEM* bItem,
|
2020-09-10 20:58:05 +01:00
|
|
|
int aConstraint, PCB_LAYER_ID aLayer,
|
2020-09-13 00:05:32 +01:00
|
|
|
wxString* aRuleName = nullptr );
|
2020-05-16 00:25:33 +01:00
|
|
|
|
|
|
|
|
2020-09-11 16:04:11 +01:00
|
|
|
#endif // DRC_RULE_H
|