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
55 VALIDATION_RESULT Validate() const override
56 {
58
59 // Validate max uncoupled length is positive
60 if( m_maxUncoupledLength <= 0 )
61 result.AddError( "Maximum Uncoupled Length must be greater than 0" );
62
63 // Validate width values are positive
64 if( m_minWidth <= 0 )
65 result.AddError( "Minimum Width must be greater than 0" );
66
67 if( m_preferredWidth <= 0 )
68 result.AddError( "Preferred Width must be greater than 0" );
69
70 if( m_maxWidth <= 0 )
71 result.AddError( "Maximum Width must be greater than 0" );
72
73 // Validate gap values are positive
74 if( m_minGap <= 0 )
75 result.AddError( "Minimum Gap must be greater than 0" );
76
77 if( m_preferredGap <= 0 )
78 result.AddError( "Preferred Gap must be greater than 0" );
79
80 if( m_maxGap <= 0 )
81 result.AddError( "Maximum Gap must be greater than 0" );
82
83 // Validate min <= preferred <= max for width
85 result.AddError( "Minimum Width cannot be greater than Preferred Width" );
86
88 result.AddError( "Preferred Width cannot be greater than Maximum Width" );
89
91 result.AddError( "Minimum Width cannot be greater than Maximum Width" );
92
93 // Validate min <= preferred <= max for gap
95 result.AddError( "Minimum Gap cannot be greater than Preferred Gap" );
96
98 result.AddError( "Preferred Gap cannot be greater than Maximum Gap" );
99
100 if( m_minGap > m_maxGap )
101 result.AddError( "Minimum Gap cannot be greater than Maximum Gap" );
102
103 return result;
104 }
105
106 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
107 {
108 auto formatDistance = [&]( double aValue )
109 {
110 return formatDouble( aValue ) + wxS( "mm" );
111 };
112
113 wxString widthClause = wxString::Format(
114 wxS( "(constraint track_width (min %s) (opt %s) (max %s))" ),
115 formatDistance( m_minWidth ),
116 formatDistance( m_preferredWidth ),
117 formatDistance( m_maxWidth ) );
118
119 wxString gapClause = wxString::Format(
120 wxS( "(constraint diff_pair_gap (min %s) (opt %s) (max %s))" ),
121 formatDistance( m_minGap ),
122 formatDistance( m_preferredGap ),
123 formatDistance( m_maxGap ) );
124
125 wxString uncoupledClause = wxString::Format(
126 wxS( "(constraint diff_pair_uncoupled (max %s))" ),
127 formatDistance( m_maxUncoupledLength ) );
128
129 return buildRule( aContext, { widthClause, gapClause, uncoupledClause } );
130 }
131
133
134 void SetMaxUncoupledLength( double aMaxUncoupledLength )
135 {
136 m_maxUncoupledLength = aMaxUncoupledLength;
137 }
138
139 double GetMinWidth() { return m_minWidth; }
140
141 void SetMinWidth( double aMinWidth ) { m_minWidth = aMinWidth; }
142
144
145 void SetPreferredWidth( double aPreferredWidth ) { m_preferredWidth = aPreferredWidth; }
146
147 double GetMaxWidth() { return m_maxWidth; }
148
149 void SetMaxWidth( double aMaxWidth ) { m_maxWidth = aMaxWidth; }
150
151 double GetMinGap() { return m_minGap; }
152
153 void SetMinGap( double aMinGap ) { m_minGap = aMinGap; }
154
155 double GetPreferredGap() { return m_preferredGap; }
156
157 void SetPreferredGap( double aPreferredGap ) { m_preferredGap = aPreferredGap; }
158
159 double GetMaxGap() { return m_maxGap; }
160
161 void SetMaxGap( double aMaxGap ) { m_maxGap = aMaxGap; }
162
163 void CopyFrom( const ICopyable& aSource ) override
164 {
165 const auto& source =
166 dynamic_cast<const DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
167
169
170 m_maxUncoupledLength = source.m_maxUncoupledLength;
171 m_minWidth = source.m_minWidth;
172 m_preferredWidth = source.m_preferredWidth;
173 m_maxWidth = source.m_maxWidth;
174 m_minGap = source.m_minGap;
175 m_preferredGap = source.m_preferredGap;
176 m_maxGap = source.m_maxGap;
177 }
178
179private:
181 double m_minWidth{ 0 };
182 double m_preferredWidth{ 0 };
183 double m_maxWidth{ 0 };
184 double m_minGap{ 0 };
185 double m_preferredGap{ 0 };
186 double m_maxGap{ 0 };
187};
188
189#endif // DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA_H_
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
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)
virtual ~DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA()=default
Abstract interface class to enable polymorphic copying between objects.
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.