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, yTop, tabOrder }
57 // TODO: measure actual positions from PNG
58 return {
59 { 0 + DRC_RE_OVERLAY_XO, 40 + DRC_RE_OVERLAY_XO, 135 + DRC_RE_OVERLAY_YO, 1, wxS( "mm" ),
60 LABEL_POSITION::RIGHT }, // opt_width
61 { 80 + DRC_RE_OVERLAY_XO, 120 + DRC_RE_OVERLAY_XO, 135 + DRC_RE_OVERLAY_YO, 2, wxS( "mm" ),
62 LABEL_POSITION::RIGHT }, // width_tolerance (±)
63 { 185 + DRC_RE_OVERLAY_XO, 225 + DRC_RE_OVERLAY_XO, 115 + DRC_RE_OVERLAY_YO, 3, wxS( "mm" ),
64 LABEL_POSITION::RIGHT }, // opt_gap
65 { 265 + DRC_RE_OVERLAY_XO, 305 + DRC_RE_OVERLAY_XO, 115 + DRC_RE_OVERLAY_YO, 4, wxS( "mm" ),
66 LABEL_POSITION::RIGHT }, // gap_tolerance (±)
67 { 95 + DRC_RE_OVERLAY_XO, 135 + DRC_RE_OVERLAY_XO, 10 + DRC_RE_OVERLAY_YO, 5, wxS( "mm" ),
68 LABEL_POSITION::RIGHT }, // max_uncoupled
69 };
70 }
71
72 VALIDATION_RESULT Validate() const override
73 {
75
76 bool hasWidth = m_optWidth > 0;
77
78 if( hasWidth )
79 {
80 if( m_widthTolerance < 0 )
81 result.AddError( _( "Width Tolerance must be greater than or equal to 0" ) );
82
84 result.AddError( _( "Width Tolerance must be less than Optimum Width" ) );
85 }
86
87 bool hasGap = m_optGap > 0;
88
89 if( hasGap )
90 {
91 if( m_gapTolerance < 0 )
92 result.AddError( _( "Gap Tolerance must be greater than or equal to 0" ) );
93
95 result.AddError( _( "Gap Tolerance must be less than Optimum Gap" ) );
96 }
97
98 if( m_maxUncoupledLength < 0 )
99 result.AddError( _( "Maximum Uncoupled Length must be greater than or equal to 0" ) );
100
101 if( !hasWidth && !hasGap && m_maxUncoupledLength <= 0 )
102 result.AddError( _( "At least one constraint must be specified" ) );
103
104 return result;
105 }
106
107 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
108 {
109 auto formatDistance = []( double aValue )
110 {
111 return formatDouble( aValue ) + wxS( "mm" );
112 };
113
114 std::vector<wxString> clauses;
115
116 if( m_optWidth > 0 )
117 {
118 double minWidth = m_optWidth - m_widthTolerance;
119 double maxWidth = m_optWidth + m_widthTolerance;
120
121 clauses.push_back( wxString::Format( wxS( "(constraint track_width (min %s) (opt %s) (max %s))" ),
122 formatDistance( minWidth ), formatDistance( m_optWidth ),
123 formatDistance( maxWidth ) ) );
124 }
125
126 if( m_optGap > 0 )
127 {
128 double minGap = m_optGap - m_gapTolerance;
129 double maxGap = m_optGap + m_gapTolerance;
130
131 clauses.push_back( wxString::Format( wxS( "(constraint diff_pair_gap (min %s) (opt %s) (max %s))" ),
132 formatDistance( minGap ), formatDistance( m_optGap ),
133 formatDistance( maxGap ) ) );
134 }
135
136 if( m_maxUncoupledLength > 0 )
137 {
138 clauses.push_back( wxString::Format( wxS( "(constraint diff_pair_uncoupled (max %s))" ),
139 formatDistance( m_maxUncoupledLength ) ) );
140 }
141
142 return clauses;
143 }
144
145 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
146 {
147 return buildRule( aContext, GetConstraintClauses( aContext ) );
148 }
149
150 double GetOptWidth() { return m_optWidth; }
151 void SetOptWidth( double aOptWidth ) { m_optWidth = aOptWidth; }
152
154 void SetWidthTolerance( double aTolerance ) { m_widthTolerance = aTolerance; }
155
156 double GetOptGap() { return m_optGap; }
157 void SetOptGap( double aOptGap ) { m_optGap = aOptGap; }
158
159 double GetGapTolerance() { return m_gapTolerance; }
160 void SetGapTolerance( double aTolerance ) { m_gapTolerance = aTolerance; }
161
163 void SetMaxUncoupledLength( double aMaxUncoupledLength ) { m_maxUncoupledLength = aMaxUncoupledLength; }
164
165 void CopyFrom( const ICopyable& aSource ) override
166 {
167 const auto& source =
168 dynamic_cast<const DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
169
171
172 m_optWidth = source.m_optWidth;
173 m_widthTolerance = source.m_widthTolerance;
174 m_optGap = source.m_optGap;
175 m_gapTolerance = source.m_gapTolerance;
176 m_maxUncoupledLength = source.m_maxUncoupledLength;
177 }
178
179private:
180 double m_optWidth{ 0 };
181 double m_widthTolerance{ 0 };
182 double m_optGap{ 0 };
183 double m_gapTolerance{ 0 };
185};
186
187#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.
constexpr int DRC_RE_OVERLAY_XO
constexpr int DRC_RE_OVERLAY_YO
@ 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.