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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA_H_
25#define DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA_H_
26
28
29
31{
32public:
34
40
41 explicit DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA( int aId, int aParentId, wxString aRuleName,
42 double aMaxUncoupledLength, double aMinWidth,
43 double aPreferredWidth, double aMaxWidth,
44 double aMinGap, double aPreferredGap,
45 double aMaxGap ) :
46 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
47 m_maxUncoupledLength( aMaxUncoupledLength ), m_minWidth( aMinWidth ),
48 m_preferredWidth( aPreferredWidth ), m_maxWidth( aMaxWidth ), m_minGap( aMinGap ),
49 m_preferredGap( aPreferredGap ), m_maxGap( aMaxGap )
50 {
51 }
52
54
56
57 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
58 {
59 // Positions measured from constraint_routing_diff_pair.png bitmap (~570x160)
60 // Format: { xStart, xEnd, yTop, tabOrder }
61 return {
62 { 164, 204, 55, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_width (left side, top arrow)
63 { 304, 344, 68, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_width (left side, middle)
64 { 480, 520, 50, 3, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_width (left side, bottom)
65 { 214, 254, 88, 4, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_gap (center-left, top)
66 { 386, 426, 80, 5, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_gap (center-left, middle)
67 { 600, 640, 64, 6, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_gap (center-left, bottom)
68 { 120, 160, 204, 7, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_uncoupled (right side)
69 { 800, 840, 168, 8, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_skew (to be added, right side)
70 };
71 }
72
73 VALIDATION_RESULT Validate() const override
74 {
76
77 if( m_minWidth <= 0 )
78 result.AddError( _( "Minimum Width must be greater than 0" ) );
79
80 if( m_preferredWidth <= 0 )
81 result.AddError( _( "Preferred Width must be greater than 0" ) );
82
83 if( m_maxWidth <= 0 )
84 result.AddError( _( "Maximum Width must be greater than 0" ) );
85
86 if( m_minGap <= 0 )
87 result.AddError( _( "Minimum Gap must be greater than 0" ) );
88
89 if( m_preferredGap <= 0 )
90 result.AddError( _( "Preferred Gap must be greater than 0" ) );
91
92 if( m_maxGap <= 0 )
93 result.AddError( _( "Maximum Gap must be greater than 0" ) );
94
95 if( m_maxUncoupledLength <= 0 )
96 result.AddError( _( "Maximum Uncoupled Length must be greater than 0" ) );
97
98 if( m_maxSkew < 0 )
99 result.AddError( _( "Maximum Skew must be greater than or equal to 0" ) );
100
101 if( result.isValid )
102 {
104 result.AddError( _( "Minimum Width cannot be greater than Preferred Width" ) );
105
107 result.AddError( _( "Preferred Width cannot be greater than Maximum Width" ) );
108
109 if( m_minWidth > m_maxWidth )
110 result.AddError( _( "Minimum Width cannot be greater than Maximum Width" ) );
111
113 result.AddError( _( "Minimum Gap cannot be greater than Preferred Gap" ) );
114
116 result.AddError( _( "Preferred Gap cannot be greater than Maximum Gap" ) );
117
118 if( m_minGap > m_maxGap )
119 result.AddError( _( "Minimum Gap cannot be greater than Maximum Gap" ) );
120 }
121
122 return result;
123 }
124
125 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
126 {
127 auto formatDistance = []( double aValue )
128 {
129 return formatDouble( aValue ) + wxS( "mm" );
130 };
131
132 wxString widthClause = wxString::Format(
133 wxS( "(constraint track_width (min %s) (opt %s) (max %s))" ),
134 formatDistance( m_minWidth ),
135 formatDistance( m_preferredWidth ),
136 formatDistance( m_maxWidth ) );
137
138 wxString gapClause = wxString::Format(
139 wxS( "(constraint diff_pair_gap (min %s) (opt %s) (max %s))" ),
140 formatDistance( m_minGap ),
141 formatDistance( m_preferredGap ),
142 formatDistance( m_maxGap ) );
143
144 wxString uncoupledClause = wxString::Format(
145 wxS( "(constraint diff_pair_uncoupled (max %s))" ),
146 formatDistance( m_maxUncoupledLength ) );
147
148 std::vector<wxString> clauses = { widthClause, gapClause, uncoupledClause };
149
150 if( m_maxSkew > 0 )
151 {
152 wxString skewClause = wxString::Format( wxS( "(constraint skew (max %s))" ), formatDistance( m_maxSkew ) );
153 clauses.push_back( skewClause );
154 }
155
156 return clauses;
157 }
158
159 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
160 {
161 return buildRule( aContext, GetConstraintClauses( aContext ) );
162 }
163
165
166 void SetMaxUncoupledLength( double aMaxUncoupledLength )
167 {
168 m_maxUncoupledLength = aMaxUncoupledLength;
169 }
170
171 double GetMinWidth() { return m_minWidth; }
172
173 void SetMinWidth( double aMinWidth ) { m_minWidth = aMinWidth; }
174
176
177 void SetPreferredWidth( double aPreferredWidth ) { m_preferredWidth = aPreferredWidth; }
178
179 double GetMaxWidth() { return m_maxWidth; }
180
181 void SetMaxWidth( double aMaxWidth ) { m_maxWidth = aMaxWidth; }
182
183 double GetMinGap() { return m_minGap; }
184
185 void SetMinGap( double aMinGap ) { m_minGap = aMinGap; }
186
187 double GetPreferredGap() { return m_preferredGap; }
188
189 void SetPreferredGap( double aPreferredGap ) { m_preferredGap = aPreferredGap; }
190
191 double GetMaxGap() { return m_maxGap; }
192
193 void SetMaxGap( double aMaxGap ) { m_maxGap = aMaxGap; }
194
195 double GetMaxSkew() { return m_maxSkew; }
196
197 void SetMaxSkew( double aMaxSkew ) { m_maxSkew = aMaxSkew; }
198
199 void CopyFrom( const ICopyable& aSource ) override
200 {
201 const auto& source =
202 dynamic_cast<const DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
203
205
206 m_maxUncoupledLength = source.m_maxUncoupledLength;
207 m_minWidth = source.m_minWidth;
208 m_preferredWidth = source.m_preferredWidth;
209 m_maxWidth = source.m_maxWidth;
210 m_minGap = source.m_minGap;
211 m_preferredGap = source.m_preferredGap;
212 m_maxGap = source.m_maxGap;
213 m_maxSkew = source.m_maxSkew;
214 }
215
216private:
218 double m_minWidth{ 0 };
219 double m_preferredWidth{ 0 };
220 double m_maxWidth{ 0 };
221 double m_minGap{ 0 };
222 double m_preferredGap{ 0 };
223 double m_maxGap{ 0 };
224 double m_maxSkew{ 0 };
225};
226
227#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.
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(int aId, int aParentId, wxString aRuleName, double aMaxUncoupledLength, double aMinWidth, double aPreferredWidth, double aMaxWidth, double aMinGap, double aPreferredGap, double aMaxGap)
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.