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,
60 _( "Optimum width of each track in the pair" ) }, // opt_width
61 { 105, 160, 147, wxS( "mm" ), LABEL_POSITION::RIGHT,
62 _( "Allowed deviation above or below the optimum width" ), wxS( "\u00B1" ) }, // width_tolerance (±)
63 { 185, 240, 123, wxS( "mm" ), LABEL_POSITION::RIGHT,
64 _( "Optimum gap between the two tracks of the pair" ) }, // opt_gap
65 { 290, 345, 123, wxS( "mm" ), LABEL_POSITION::RIGHT,
66 _( "Allowed deviation above or below the optimum gap" ), wxS( "\u00B1" ) }, // gap_tolerance (±)
67 { 85, 140, 20, wxS( "mm" ), LABEL_POSITION::RIGHT,
68 _( "Maximum length over which the pair may run uncoupled" ) }, // max_uncoupled
69 };
70 }
71
72 VALIDATION_RESULT Validate() const override
73 {
75
76 if( m_optWidth < 0 )
77 result.AddError( _( "Optimum Width must be greater than or equal to 0" ) );
78
79 if( m_optGap < 0 )
80 result.AddError( _( "Optimum Gap must be greater than or equal to 0" ) );
81
82 bool hasWidth = m_optWidth > 0;
83
84 if( hasWidth )
85 {
86 if( m_widthTolerance < 0 )
87 result.AddError( _( "Width Tolerance must be greater than or equal to 0" ) );
88
90 result.AddError( _( "Width Tolerance must be less than Optimum Width" ) );
91 }
92
93 bool hasGap = m_optGap > 0;
94
95 if( hasGap )
96 {
97 if( m_gapTolerance < 0 )
98 result.AddError( _( "Gap Tolerance must be greater than or equal to 0" ) );
99
100 if( m_gapTolerance >= m_optGap )
101 result.AddError( _( "Gap Tolerance must be less than Optimum Gap" ) );
102 }
103
104 if( m_maxUncoupledLength < 0 )
105 result.AddError( _( "Maximum Uncoupled Length must be greater than or equal to 0" ) );
106
107 if( !hasWidth && !hasGap && m_maxUncoupledLength <= 0 )
108 result.AddError( _( "At least one constraint must be specified" ) );
109
110 return result;
111 }
112
113 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
114 {
115 auto formatDistance = []( double aValue )
116 {
117 return formatDouble( aValue ) + wxS( "mm" );
118 };
119
120 std::vector<wxString> clauses;
121
122 if( m_optWidth > 0 )
123 {
124 double minWidth = m_optWidth - m_widthTolerance;
125 double maxWidth = m_optWidth + m_widthTolerance;
126
127 clauses.push_back( wxString::Format( wxS( "(constraint track_width (min %s) (opt %s) (max %s))" ),
128 formatDistance( minWidth ), formatDistance( m_optWidth ),
129 formatDistance( maxWidth ) ) );
130 }
131
132 if( m_optGap > 0 )
133 {
134 double minGap = m_optGap - m_gapTolerance;
135 double maxGap = m_optGap + m_gapTolerance;
136
137 clauses.push_back( wxString::Format( wxS( "(constraint diff_pair_gap (min %s) (opt %s) (max %s))" ),
138 formatDistance( minGap ), formatDistance( m_optGap ),
139 formatDistance( maxGap ) ) );
140 }
141
142 if( m_maxUncoupledLength > 0 )
143 {
144 clauses.push_back( wxString::Format( wxS( "(constraint diff_pair_uncoupled (max %s))" ),
145 formatDistance( m_maxUncoupledLength ) ) );
146 }
147
148 return clauses;
149 }
150
151 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
152 {
153 return buildRule( aContext, GetConstraintClauses( aContext ) );
154 }
155
156 double GetOptWidth() { return m_optWidth; }
157 void SetOptWidth( double aOptWidth ) { m_optWidth = aOptWidth; }
158
160 void SetWidthTolerance( double aTolerance ) { m_widthTolerance = aTolerance; }
161
162 double GetOptGap() { return m_optGap; }
163 void SetOptGap( double aOptGap ) { m_optGap = aOptGap; }
164
165 double GetGapTolerance() { return m_gapTolerance; }
166 void SetGapTolerance( double aTolerance ) { m_gapTolerance = aTolerance; }
167
169 void SetMaxUncoupledLength( double aMaxUncoupledLength ) { m_maxUncoupledLength = aMaxUncoupledLength; }
170
171 void CopyFrom( const ICopyable& aSource ) override
172 {
173 const auto& source =
174 dynamic_cast<const DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
175
177
178 m_optWidth = source.m_optWidth;
179 m_widthTolerance = source.m_widthTolerance;
180 m_optGap = source.m_optGap;
181 m_gapTolerance = source.m_gapTolerance;
182 m_maxUncoupledLength = source.m_maxUncoupledLength;
183 }
184
185private:
186 double m_optWidth{ 0 };
187 double m_widthTolerance{ 0 };
188 double m_optGap{ 0 };
189 double m_gapTolerance{ 0 };
191};
192
193#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)
std::string source
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.