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