KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_rtg_diff_pair_constraint_data.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA_H_
21#define DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA_H_
22
24
25
27{
28public:
30
36
37 explicit DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA( int aId, int aParentId, const wxString& aRuleName,
38 double aOptWidth, double aWidthTolerance, double aOptGap,
39 double aGapTolerance, double aMaxUncoupledLength ) :
40 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
41 m_optWidth( aOptWidth ),
42 m_widthTolerance( aWidthTolerance ),
43 m_optGap( aOptGap ),
44 m_gapTolerance( aGapTolerance ),
45 m_maxUncoupledLength( aMaxUncoupledLength )
46 {
47 }
48
50
52
53 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
54 {
55 // Positions measured from constraint_routing_diff_pair.png bitmap (~423x133)
56 // Format: { xStart, xEnd, yCenter }
57 // TODO: measure actual positions from PNG
58 return {
59 { 0, 55, 147, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_width
60 { 105, 160, 147, wxS( "mm" ), LABEL_POSITION::RIGHT, wxS( "\u00B1" ) }, // width_tolerance (±)
61 { 185, 240, 123, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_gap
62 { 290, 345, 123, wxS( "mm" ), LABEL_POSITION::RIGHT, wxS( "\u00B1" ) }, // gap_tolerance (±)
63 { 85, 140, 20, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_uncoupled
64 };
65 }
66
67 VALIDATION_RESULT Validate() const override
68 {
70
71 bool hasWidth = m_optWidth > 0;
72
73 if( hasWidth )
74 {
75 if( m_widthTolerance < 0 )
76 result.AddError( _( "Width Tolerance must be greater than or equal to 0" ) );
77
79 result.AddError( _( "Width Tolerance must be less than Optimum Width" ) );
80 }
81
82 bool hasGap = m_optGap > 0;
83
84 if( hasGap )
85 {
86 if( m_gapTolerance < 0 )
87 result.AddError( _( "Gap Tolerance must be greater than or equal to 0" ) );
88
90 result.AddError( _( "Gap Tolerance must be less than Optimum Gap" ) );
91 }
92
93 if( m_maxUncoupledLength < 0 )
94 result.AddError( _( "Maximum Uncoupled Length must be greater than or equal to 0" ) );
95
96 if( !hasWidth && !hasGap && m_maxUncoupledLength <= 0 )
97 result.AddError( _( "At least one constraint must be specified" ) );
98
99 return result;
100 }
101
102 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
103 {
104 auto formatDistance = []( double aValue )
105 {
106 return formatDouble( aValue ) + wxS( "mm" );
107 };
108
109 std::vector<wxString> clauses;
110
111 if( m_optWidth > 0 )
112 {
113 double minWidth = m_optWidth - m_widthTolerance;
114 double maxWidth = m_optWidth + m_widthTolerance;
115
116 clauses.push_back( wxString::Format( wxS( "(constraint track_width (min %s) (opt %s) (max %s))" ),
117 formatDistance( minWidth ), formatDistance( m_optWidth ),
118 formatDistance( maxWidth ) ) );
119 }
120
121 if( m_optGap > 0 )
122 {
123 double minGap = m_optGap - m_gapTolerance;
124 double maxGap = m_optGap + m_gapTolerance;
125
126 clauses.push_back( wxString::Format( wxS( "(constraint diff_pair_gap (min %s) (opt %s) (max %s))" ),
127 formatDistance( minGap ), formatDistance( m_optGap ),
128 formatDistance( maxGap ) ) );
129 }
130
131 if( m_maxUncoupledLength > 0 )
132 {
133 clauses.push_back( wxString::Format( wxS( "(constraint diff_pair_uncoupled (max %s))" ),
134 formatDistance( m_maxUncoupledLength ) ) );
135 }
136
137 return clauses;
138 }
139
140 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
141 {
142 return buildRule( aContext, GetConstraintClauses( aContext ) );
143 }
144
145 double GetOptWidth() { return m_optWidth; }
146 void SetOptWidth( double aOptWidth ) { m_optWidth = aOptWidth; }
147
149 void SetWidthTolerance( double aTolerance ) { m_widthTolerance = aTolerance; }
150
151 double GetOptGap() { return m_optGap; }
152 void SetOptGap( double aOptGap ) { m_optGap = aOptGap; }
153
154 double GetGapTolerance() { return m_gapTolerance; }
155 void SetGapTolerance( double aTolerance ) { m_gapTolerance = aTolerance; }
156
158 void SetMaxUncoupledLength( double aMaxUncoupledLength ) { m_maxUncoupledLength = aMaxUncoupledLength; }
159
160 void CopyFrom( const ICopyable& aSource ) override
161 {
162 const auto& source =
163 dynamic_cast<const DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
164
166
167 m_optWidth = source.m_optWidth;
168 m_widthTolerance = source.m_widthTolerance;
169 m_optGap = source.m_optGap;
170 m_gapTolerance = source.m_gapTolerance;
171 m_maxUncoupledLength = source.m_maxUncoupledLength;
172 }
173
174private:
175 double m_optWidth{ 0 };
176 double m_widthTolerance{ 0 };
177 double m_optGap{ 0 };
178 double m_gapTolerance{ 0 };
180};
181
182#endif // DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA_H_
BITMAPS
A list of all bitmap identifiers.
@ constraint_routing_diff_pair
static wxString formatDouble(double aValue, int aPrecision=6)
wxString buildRule(const RULE_GENERATION_CONTEXT &aContext, const std::vector< wxString > &aConstraintClauses) const
void CopyFrom(const ICopyable &aSource) override
VALIDATION_RESULT Validate() const override
Validates the constraint data.
DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA(int aId, int aParentId, const wxString &aRuleName, double aOptWidth, double aWidthTolerance, double aOptGap, double aGapTolerance, double aMaxUncoupledLength)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA(const DRC_RE_BASE_CONSTRAINT_DATA &aBaseData)
std::vector< DRC_RE_FIELD_POSITION > GetFieldPositions() const override
Returns the field positions for controls overlaid on the constraint bitmap.
virtual ~DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA()=default
Abstract interface class to enable polymorphic copying between objects.
@ RIGHT
Label to the right of the field.
#define _(s)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.