KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_via_style_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_VIA_STYLE_CONSTRAINT_DATA_H_
21#define DRC_RE_VIA_STYLE_CONSTRAINT_DATA_H_
22
24
25
34
35
37{
38public:
40
43 {
44 }
45
46 explicit DRC_RE_VIA_STYLE_CONSTRAINT_DATA( int aId, int aParentId, const wxString& aRuleName,
47 double aMinViaDiameter, double aMaxViaDiameter,
48 double aMinViaHoleSize, double aMaxViaHoleSize,
50
51 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
52 m_minViaDiameter( aMinViaDiameter ),
53 m_maxViaDiameter( aMaxViaDiameter ),
54 m_minViaHoleSize( aMinViaHoleSize ),
55 m_maxViaHoleSize( aMaxViaHoleSize ),
56 m_viaType( aViaType )
57 {
58 }
59
61
63
64 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
65 {
66 // Positions measured from constraint_via_style.png bitmap
67 // Format: { xStart, xEnd, yCenter }
68 return {
69 { 155, 210, 22, wxS( "mm" ), LABEL_POSITION::RIGHT,
70 _( "Smallest allowed via diameter" ) }, // [0] min_via_diameter
71 { 265, 320, 22, wxS( "mm" ), LABEL_POSITION::RIGHT, _( "Largest allowed via diameter" ),
72 wxS( "– " ) }, // [1] max_via_diameter
73 { 195, 250, 202, wxS( "mm" ), LABEL_POSITION::RIGHT,
74 _( "Smallest allowed via hole diameter" ) }, // [2] min_via_hole
75 { 305, 360, 202, wxS( "mm" ), LABEL_POSITION::RIGHT, _( "Largest allowed via hole diameter" ),
76 wxS( "– " ) }, // [3] max_via_hole
77 { 420, 525, 122, _( "Via type:" ), LABEL_POSITION::LEFT,
78 _( "Restrict this rule to a single via type" ) }, // [4] via_type dropdown
79 };
80 }
81
82 VALIDATION_RESULT Validate() const override
83 {
85
86 bool hasDiameter = m_minViaDiameter != 0 || m_maxViaDiameter != 0;
87 bool hasHoleSize = m_minViaHoleSize != 0 || m_maxViaHoleSize != 0;
88
89 if( hasDiameter )
90 {
91 if( m_minViaDiameter <= 0 )
92 result.AddError( _( "Minimum Via Diameter must be greater than 0" ) );
93
94 if( m_maxViaDiameter <= 0 )
95 result.AddError( _( "Maximum Via Diameter must be greater than 0" ) );
96
98 result.AddError( _( "Minimum Via Diameter cannot be greater than Maximum Via Diameter" ) );
99 }
100
101 if( hasHoleSize )
102 {
103 if( m_minViaHoleSize <= 0 )
104 result.AddError( _( "Minimum Via Hole Size must be greater than 0" ) );
105
106 if( m_maxViaHoleSize <= 0 )
107 result.AddError( _( "Maximum Via Hole Size must be greater than 0" ) );
108
110 result.AddError( _( "Minimum Via Hole Size cannot be greater than Maximum Via Hole Size" ) );
111 }
112
113 if( !hasDiameter && !hasHoleSize )
114 result.AddError( _( "At least one constraint must be specified" ) );
115
116 return result;
117 }
118
119 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
120 {
121 auto formatDimension = []( double aValue )
122 {
123 return formatDouble( aValue ) + wxS( "mm" );
124 };
125
126 std::vector<wxString> clauses;
127
128 if( m_minViaDiameter > 0 && m_maxViaDiameter > 0 )
129 {
131 {
132 clauses.push_back( wxString::Format( wxS( "(constraint via_diameter (min %s) (opt %s) (max %s))" ),
133 formatDimension( m_minViaDiameter ),
134 formatDimension( m_optViaDiameter ),
135 formatDimension( m_maxViaDiameter ) ) );
136 }
137 else
138 {
139 clauses.push_back( wxString::Format( wxS( "(constraint via_diameter (min %s) (max %s))" ),
140 formatDimension( m_minViaDiameter ),
141 formatDimension( m_maxViaDiameter ) ) );
142 }
143 }
144
145 if( m_minViaHoleSize > 0 && m_maxViaHoleSize > 0 )
146 {
148 {
149 clauses.push_back( wxString::Format(
150 wxS( "(constraint hole_size (min %s) (opt %s) (max %s))" ), formatDimension( m_minViaHoleSize ),
151 formatDimension( m_optViaHoleSize ), formatDimension( m_maxViaHoleSize ) ) );
152 }
153 else
154 {
155 clauses.push_back( wxString::Format( wxS( "(constraint hole_size (min %s) (max %s))" ),
156 formatDimension( m_minViaHoleSize ),
157 formatDimension( m_maxViaHoleSize ) ) );
158 }
159 }
160
161 return clauses;
162 }
163
164 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
165 {
166 RULE_GENERATION_CONTEXT ctx = aContext;
167
168 wxString viaTypeCondition = GetViaTypeCondition();
169
170 if( !viaTypeCondition.IsEmpty() )
171 {
172 if( ctx.conditionExpression.IsEmpty() )
173 ctx.conditionExpression = viaTypeCondition;
174 else
175 ctx.conditionExpression = viaTypeCondition + wxS( " && " ) + ctx.conditionExpression;
176 }
177
178 return buildRule( ctx, GetConstraintClauses( ctx ) );
179 }
180
182
183 void SetMinViaDiameter( double aMinViaDiameter ) { m_minViaDiameter = aMinViaDiameter; }
184
186
187 void SetMaxViaDiameter( double aMaxViaDiameter ) { m_maxViaDiameter = aMaxViaDiameter; }
188
190
191 void SetMinViaHoleSize( double aMinViaHoleSize ) { m_minViaHoleSize = aMinViaHoleSize; }
192
194
195 void SetMaxViaHoleSize( double aMaxViaHoleSize ) { m_maxViaHoleSize = aMaxViaHoleSize; }
196
197 // The panel has no fields for the optimums, so a loaded rule's values are carried
198 // through an edit unchanged.
199 double GetOptViaDiameter() const { return m_optViaDiameter; }
200
201 void SetOptViaDiameter( double aOptViaDiameter ) { m_optViaDiameter = aOptViaDiameter; }
202
203 double GetOptViaHoleSize() const { return m_optViaHoleSize; }
204
205 void SetOptViaHoleSize( double aOptViaHoleSize ) { m_optViaHoleSize = aOptViaHoleSize; }
206
208
209 void SetViaType( VIA_STYLE_TYPE aType ) { m_viaType = aType; }
210
211 wxString GetViaTypeCondition() const
212 {
213 switch( m_viaType )
214 {
215 case VIA_STYLE_TYPE::THROUGH: return wxS( "A.Via_Type == 'Through'" );
216 case VIA_STYLE_TYPE::MICRO: return wxS( "A.Via_Type == 'Micro'" );
217 case VIA_STYLE_TYPE::BLIND: return wxS( "A.Via_Type == 'Blind'" );
218 case VIA_STYLE_TYPE::BURIED: return wxS( "A.Via_Type == 'Buried'" );
220 default: return wxEmptyString;
221 }
222 }
223
224 void CopyFrom( const ICopyable& aSource ) override
225 {
226 const auto& source = dynamic_cast<const DRC_RE_VIA_STYLE_CONSTRAINT_DATA&>( aSource );
227
229
230 m_minViaDiameter = source.m_minViaDiameter;
231 m_maxViaDiameter = source.m_maxViaDiameter;
232 m_minViaHoleSize = source.m_minViaHoleSize;
233 m_maxViaHoleSize = source.m_maxViaHoleSize;
234 m_optViaDiameter = source.m_optViaDiameter;
235 m_optViaHoleSize = source.m_optViaHoleSize;
236
237 m_viaType = source.m_viaType;
238 }
239
240private:
241 double m_minViaDiameter{ 0 };
242 double m_maxViaDiameter{ 0 };
243 double m_minViaHoleSize{ 0 };
244 double m_maxViaHoleSize{ 0 };
245 double m_optViaDiameter{ 0 };
246 double m_optViaHoleSize{ 0 };
248};
249
250#endif // DRC_RE_VIA_STYLE_CONSTRAINT_DATA_H_
BITMAPS
A list of all bitmap identifiers.
@ constraint_via_style
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
DRC_RE_VIA_STYLE_CONSTRAINT_DATA(int aId, int aParentId, const wxString &aRuleName, double aMinViaDiameter, double aMaxViaDiameter, double aMinViaHoleSize, double aMaxViaHoleSize, VIA_STYLE_TYPE aViaType=VIA_STYLE_TYPE::ANY)
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
void CopyFrom(const ICopyable &aSource) override
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
virtual ~DRC_RE_VIA_STYLE_CONSTRAINT_DATA()=default
DRC_RE_VIA_STYLE_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.
VALIDATION_RESULT Validate() const override
Validates the constraint data.
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
Abstract interface class to enable polymorphic copying between objects.
@ RIGHT
Label to the right of the field.
@ LEFT
Label to the left of the field.
#define _(s)
std::string source
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.