KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_abs_length_two_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_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA_H_
21#define DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA_H_
22
24
25
27{
28public:
30
36
37 explicit DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA( int aId, int aParentId, double aOptLength, double aTolerance,
38 const wxString& aRuleName ) :
39 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
40 m_optLength( aOptLength ),
41 m_tolerance( aTolerance )
42 {
43 }
44
46
48
49 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
50 {
51 wxString unit = m_isTimeDomain ? wxS( "ps" ) : wxS( "mm" );
52
53 // Format: { xStart, xEnd, yCenter }
54 // Two fields side-by-side, opt_length and tolerance
55 return {
56 { 80, 135, 127, unit, LABEL_POSITION::RIGHT, _( "Optimum routed length" ) }, // opt_length
57 { 185, 240, 127, unit, LABEL_POSITION::RIGHT, _( "Allowed deviation above or below the optimum length" ),
58 wxS( "\u00B1" ) }, // tolerance (±)
59 };
60 }
61
62 double GetOptimumLength() const { return m_optLength; }
63
64 void SetOptimumLength( double aLength ) { m_optLength = aLength; }
65
66 // When set, the values are picoseconds instead of millimeters.
67 bool IsTimeDomain() const { return m_isTimeDomain; }
68
69 void SetTimeDomain( bool aTimeDomain ) { m_isTimeDomain = aTimeDomain; }
70
71 double GetTolerance() const { return m_tolerance; }
72
73 void SetTolerance( double aTolerance ) { m_tolerance = aTolerance; }
74
75 // Computed from opt +/- tolerance
76 double GetMinimumLength() const { return m_optLength - m_tolerance; }
77
78 double GetMaximumLength() const { return m_optLength + m_tolerance; }
79
80 VALIDATION_RESULT Validate() const override
81 {
83
84 if( m_optLength <= 0 )
85 result.AddError( _( "Optimum Length must be greater than 0" ) );
86
87 if( m_tolerance < 0 )
88 result.AddError( _( "Tolerance must be greater than or equal to 0" ) );
89
90 if( result.isValid )
91 {
92 if( GetMinimumLength() <= 0 )
93 result.AddError( _( "Tolerance is too large: resulting minimum length is not positive" ) );
94 }
95
96 return result;
97 }
98
99 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
100 {
101 auto formatDistance = [this]( double aValue )
102 {
103 return formatDouble( aValue ) + ( m_isTimeDomain ? wxS( "ps" ) : wxS( "mm" ) );
104 };
105
106 wxString code = GetConstraintCode();
107
108 if( code.IsEmpty() )
109 code = wxS( "length" );
110
111 wxString clause = wxString::Format( wxS( "(constraint %s (min %s) (opt %s) (max %s))" ), code,
112 formatDistance( GetMinimumLength() ), formatDistance( m_optLength ),
113 formatDistance( GetMaximumLength() ) );
114
115 return { clause };
116 }
117
118 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
119 {
120 return buildRule( aContext, GetConstraintClauses( aContext ) );
121 }
122
123 void CopyFrom( const ICopyable& aSource ) override
124 {
125 const auto& source =
126 dynamic_cast<const DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA&>( aSource );
127
129
130 m_optLength = source.m_optLength;
131 m_tolerance = source.m_tolerance;
132 m_isTimeDomain = source.m_isTimeDomain;
133 }
134
135private:
136 double m_optLength{ 0 };
137 double m_tolerance{ 0 };
138 bool m_isTimeDomain{ false };
139};
140
142{
143public:
145
147
148 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
149 {
150 return {
151 { 80, 135, 142, wxS( "mm" ), LABEL_POSITION::RIGHT, _( "Optimum routed length" ) }, // opt_length
152 { 185, 240, 142, wxS( "mm" ), LABEL_POSITION::RIGHT,
153 _( "Allowed deviation above or below the optimum length" ), wxS( "\u00B1" ) }, // tolerance (±)
154 { 17, 72, 15, wxS( "mm" ), LABEL_POSITION::RIGHT,
155 _( "Maximum length difference between matched tracks" ) }, // max_skew
156 { 113, 313, 15, _( "Within diff pairs" ), LABEL_POSITION::RIGHT,
157 _( "Limit skew between the two tracks of each differential pair" ) }, // checkbox (within_diff_pairs)
158 };
159 }
160
161 double GetMaxSkew() const { return m_maxSkew; }
162
163 void SetMaxSkew( double aSkew ) { m_maxSkew = aSkew; }
164
165 bool GetWithinDiffPairs() const { return m_withinDiffPairs; }
166
167 void SetWithinDiffPairs( bool aWithinDiffPairs ) { m_withinDiffPairs = aWithinDiffPairs; }
168
169 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
170 {
171 std::vector<wxString> clauses;
172
173 if( GetOptimumLength() > 0 )
175
176 if( m_maxSkew > 0 )
177 {
178 wxString skewClause;
179
181 {
182 skewClause = wxString::Format( wxS( "(constraint skew (max %smm) (within_diff_pairs))" ),
184 }
185 else
186 {
187 skewClause = wxString::Format( wxS( "(constraint skew (max %smm))" ), formatDouble( m_maxSkew ) );
188 }
189
190 clauses.push_back( skewClause );
191 }
192
193 return clauses;
194 }
195
196 void CopyFrom( const ICopyable& aSource ) override
197 {
198 const auto& source =
199 dynamic_cast<const DRC_RE_MATCHED_LENGTH_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
200
202
203 m_maxSkew = source.m_maxSkew;
204 m_withinDiffPairs = source.m_withinDiffPairs;
205 }
206
208 {
210
211 bool hasLength = ( GetOptimumLength() > 0 || GetTolerance() > 0 );
212 bool hasSkew = ( m_maxSkew != 0 );
213
214 if( !hasLength && !hasSkew )
215 result.AddError( _( "At least one constraint must be defined" ) );
216
217 if( hasLength )
219
220 if( m_maxSkew < 0 )
221 result.AddError( _( "Maximum Skew must be greater than or equal to 0" ) );
222
223 return result;
224 }
225
226private:
227 double m_maxSkew{ 0 };
228 bool m_withinDiffPairs{ false };
229};
230
231#endif // DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA_H_
BITMAPS
A list of all bitmap identifiers.
@ constraint_matched_length_diff_pair_v2
@ constraint_absolute_length_2
VALIDATION_RESULT Validate() const override
Validates the constraint data.
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA(int aId, int aParentId, double aOptLength, double aTolerance, const wxString &aRuleName)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
std::vector< DRC_RE_FIELD_POSITION > GetFieldPositions() const override
Returns the field positions for controls overlaid on the constraint bitmap.
DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA(const DRC_RE_BASE_CONSTRAINT_DATA &aBaseData)
virtual ~DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA()=default
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
std::vector< DRC_RE_FIELD_POSITION > GetFieldPositions() const override
Returns the field positions for controls overlaid on the constraint bitmap.
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
VALIDATION_RESULT Validate() const override
Validates the constraint data.
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
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.