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, 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_VIA_STYLE_CONSTRAINT_DATA_H_
25#define DRC_RE_VIA_STYLE_CONSTRAINT_DATA_H_
26
28
29
38
39
41{
42public:
44
47 {
48 }
49
50 explicit DRC_RE_VIA_STYLE_CONSTRAINT_DATA( int aId, int aParentId, const wxString& aRuleName,
51 double aMinViaDiameter, double aMaxViaDiameter,
52 double aMinViaHoleSize, double aMaxViaHoleSize,
54
55 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
56 m_minViaDiameter( aMinViaDiameter ),
57 m_maxViaDiameter( aMaxViaDiameter ),
58 m_minViaHoleSize( aMinViaHoleSize ),
59 m_maxViaHoleSize( aMaxViaHoleSize ),
60 m_viaType( aViaType )
61 {
62 }
63
65
67
68 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
69 {
70 // Positions measured from constraint_via_style.png bitmap
71 // Format: { xStart, xEnd, yTop, tabOrder }
72 return {
73 { 155 + DRC_RE_OVERLAY_XO, 195 + DRC_RE_OVERLAY_XO, 10 + DRC_RE_OVERLAY_YO, 0, wxS( "mm" ), LABEL_POSITION::RIGHT }, // [0] min_via_diameter
74 { 245 + DRC_RE_OVERLAY_XO, 285 + DRC_RE_OVERLAY_XO, 10 + DRC_RE_OVERLAY_YO, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // [1] max_via_diameter
75 { 195 + DRC_RE_OVERLAY_XO, 235 + DRC_RE_OVERLAY_XO, 190 + DRC_RE_OVERLAY_YO, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // [2] min_via_hole
76 { 285 + DRC_RE_OVERLAY_XO, 325 + DRC_RE_OVERLAY_XO, 190 + DRC_RE_OVERLAY_YO, 3, wxS( "mm" ), LABEL_POSITION::RIGHT }, // [3] max_via_hole
77 { 420 + DRC_RE_OVERLAY_XO, 510 + DRC_RE_OVERLAY_XO, 110 + DRC_RE_OVERLAY_YO, 4, _( "Via type:" ), LABEL_POSITION::LEFT }, // [4] via_type dropdown
78 };
79 }
80
81 VALIDATION_RESULT Validate() const override
82 {
84
85 bool hasDiameter = m_minViaDiameter > 0 || m_maxViaDiameter > 0;
86 bool hasHoleSize = m_minViaHoleSize > 0 || m_maxViaHoleSize > 0;
87
88 if( hasDiameter )
89 {
90 if( m_minViaDiameter <= 0 )
91 result.AddError( _( "Minimum Via Diameter must be greater than 0" ) );
92
93 if( m_maxViaDiameter <= 0 )
94 result.AddError( _( "Maximum Via Diameter must be greater than 0" ) );
95
97 result.AddError( _( "Minimum Via Diameter cannot be greater than Maximum Via Diameter" ) );
98 }
99
100 if( hasHoleSize )
101 {
102 if( m_minViaHoleSize <= 0 )
103 result.AddError( _( "Minimum Via Hole Size must be greater than 0" ) );
104
105 if( m_maxViaHoleSize <= 0 )
106 result.AddError( _( "Maximum Via Hole Size must be greater than 0" ) );
107
109 result.AddError( _( "Minimum Via Hole Size cannot be greater than Maximum Via Hole Size" ) );
110 }
111
112 if( !hasDiameter && !hasHoleSize )
113 result.AddError( _( "At least one constraint must be specified" ) );
114
115 return result;
116 }
117
118 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
119 {
120 auto formatDimension = []( double aValue )
121 {
122 return formatDouble( aValue ) + wxS( "mm" );
123 };
124
125 std::vector<wxString> clauses;
126
127 if( m_minViaDiameter > 0 && m_maxViaDiameter > 0 )
128 {
129 clauses.push_back( wxString::Format( wxS( "(constraint via_diameter (min %s) (max %s))" ),
130 formatDimension( m_minViaDiameter ),
131 formatDimension( m_maxViaDiameter ) ) );
132 }
133
134 if( m_minViaHoleSize > 0 && m_maxViaHoleSize > 0 )
135 {
136 clauses.push_back( wxString::Format( wxS( "(constraint hole_size (min %s) (max %s))" ),
137 formatDimension( m_minViaHoleSize ),
138 formatDimension( m_maxViaHoleSize ) ) );
139 }
140
141 return clauses;
142 }
143
144 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
145 {
146 RULE_GENERATION_CONTEXT ctx = aContext;
147
148 wxString viaTypeCondition = GetViaTypeCondition();
149
150 if( !viaTypeCondition.IsEmpty() )
151 {
152 if( ctx.conditionExpression.IsEmpty() )
153 ctx.conditionExpression = viaTypeCondition;
154 else
155 ctx.conditionExpression = viaTypeCondition + wxS( " && " ) + ctx.conditionExpression;
156 }
157
158 return buildRule( ctx, GetConstraintClauses( ctx ) );
159 }
160
162
163 void SetMinViaDiameter( double aMinViaDiameter ) { m_minViaDiameter = aMinViaDiameter; }
164
166
167 void SetMaxViaDiameter( double aMaxViaDiameter ) { m_maxViaDiameter = aMaxViaDiameter; }
168
170
171 void SetMinViaHoleSize( double aMinViaHoleSize ) { m_minViaHoleSize = aMinViaHoleSize; }
172
174
175 void SetMaxViaHoleSize( double aMaxViaHoleSize ) { m_maxViaHoleSize = aMaxViaHoleSize; }
176
178
179 void SetViaType( VIA_STYLE_TYPE aType ) { m_viaType = aType; }
180
181 wxString GetViaTypeCondition() const
182 {
183 switch( m_viaType )
184 {
185 case VIA_STYLE_TYPE::THROUGH: return wxS( "A.Via_Type == 'Through'" );
186 case VIA_STYLE_TYPE::MICRO: return wxS( "A.Via_Type == 'Micro'" );
187 case VIA_STYLE_TYPE::BLIND: return wxS( "A.Via_Type == 'Blind'" );
188 case VIA_STYLE_TYPE::BURIED: return wxS( "A.Via_Type == 'Buried'" );
190 default: return wxEmptyString;
191 }
192 }
193
194 void CopyFrom( const ICopyable& aSource ) override
195 {
196 const auto& source = dynamic_cast<const DRC_RE_VIA_STYLE_CONSTRAINT_DATA&>( aSource );
197
199
200 m_minViaDiameter = source.m_minViaDiameter;
201 m_maxViaDiameter = source.m_maxViaDiameter;
202 m_minViaHoleSize = source.m_minViaHoleSize;
203 m_maxViaHoleSize = source.m_maxViaHoleSize;
204
205 m_viaType = source.m_viaType;
206 }
207
208private:
209 double m_minViaDiameter{ 0 };
210 double m_maxViaDiameter{ 0 };
211 double m_minViaHoleSize{ 0 };
212 double m_maxViaHoleSize{ 0 };
214};
215
216#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.
constexpr int DRC_RE_OVERLAY_XO
constexpr int DRC_RE_OVERLAY_YO
@ RIGHT
Label to the right of the field.
@ LEFT
Label to the left of the field.
#define _(s)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.