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, yTop, tabOrder }
68 return {
69 { 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
70 { 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
71 { 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
72 { 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
73 { 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
74 };
75 }
76
77 VALIDATION_RESULT Validate() const override
78 {
80
81 bool hasDiameter = m_minViaDiameter > 0 || m_maxViaDiameter > 0;
82 bool hasHoleSize = m_minViaHoleSize > 0 || m_maxViaHoleSize > 0;
83
84 if( hasDiameter )
85 {
86 if( m_minViaDiameter <= 0 )
87 result.AddError( _( "Minimum Via Diameter must be greater than 0" ) );
88
89 if( m_maxViaDiameter <= 0 )
90 result.AddError( _( "Maximum Via Diameter must be greater than 0" ) );
91
93 result.AddError( _( "Minimum Via Diameter cannot be greater than Maximum Via Diameter" ) );
94 }
95
96 if( hasHoleSize )
97 {
98 if( m_minViaHoleSize <= 0 )
99 result.AddError( _( "Minimum Via Hole Size must be greater than 0" ) );
100
101 if( m_maxViaHoleSize <= 0 )
102 result.AddError( _( "Maximum Via Hole Size must be greater than 0" ) );
103
105 result.AddError( _( "Minimum Via Hole Size cannot be greater than Maximum Via Hole Size" ) );
106 }
107
108 if( !hasDiameter && !hasHoleSize )
109 result.AddError( _( "At least one constraint must be specified" ) );
110
111 return result;
112 }
113
114 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
115 {
116 auto formatDimension = []( double aValue )
117 {
118 return formatDouble( aValue ) + wxS( "mm" );
119 };
120
121 std::vector<wxString> clauses;
122
123 if( m_minViaDiameter > 0 && m_maxViaDiameter > 0 )
124 {
125 clauses.push_back( wxString::Format( wxS( "(constraint via_diameter (min %s) (max %s))" ),
126 formatDimension( m_minViaDiameter ),
127 formatDimension( m_maxViaDiameter ) ) );
128 }
129
130 if( m_minViaHoleSize > 0 && m_maxViaHoleSize > 0 )
131 {
132 clauses.push_back( wxString::Format( wxS( "(constraint hole_size (min %s) (max %s))" ),
133 formatDimension( m_minViaHoleSize ),
134 formatDimension( m_maxViaHoleSize ) ) );
135 }
136
137 return clauses;
138 }
139
140 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
141 {
142 RULE_GENERATION_CONTEXT ctx = aContext;
143
144 wxString viaTypeCondition = GetViaTypeCondition();
145
146 if( !viaTypeCondition.IsEmpty() )
147 {
148 if( ctx.conditionExpression.IsEmpty() )
149 ctx.conditionExpression = viaTypeCondition;
150 else
151 ctx.conditionExpression = viaTypeCondition + wxS( " && " ) + ctx.conditionExpression;
152 }
153
154 return buildRule( ctx, GetConstraintClauses( ctx ) );
155 }
156
158
159 void SetMinViaDiameter( double aMinViaDiameter ) { m_minViaDiameter = aMinViaDiameter; }
160
162
163 void SetMaxViaDiameter( double aMaxViaDiameter ) { m_maxViaDiameter = aMaxViaDiameter; }
164
166
167 void SetMinViaHoleSize( double aMinViaHoleSize ) { m_minViaHoleSize = aMinViaHoleSize; }
168
170
171 void SetMaxViaHoleSize( double aMaxViaHoleSize ) { m_maxViaHoleSize = aMaxViaHoleSize; }
172
174
175 void SetViaType( VIA_STYLE_TYPE aType ) { m_viaType = aType; }
176
177 wxString GetViaTypeCondition() const
178 {
179 switch( m_viaType )
180 {
181 case VIA_STYLE_TYPE::THROUGH: return wxS( "A.Via_Type == 'Through'" );
182 case VIA_STYLE_TYPE::MICRO: return wxS( "A.Via_Type == 'Micro'" );
183 case VIA_STYLE_TYPE::BLIND: return wxS( "A.Via_Type == 'Blind'" );
184 case VIA_STYLE_TYPE::BURIED: return wxS( "A.Via_Type == 'Buried'" );
186 default: return wxEmptyString;
187 }
188 }
189
190 void CopyFrom( const ICopyable& aSource ) override
191 {
192 const auto& source = dynamic_cast<const DRC_RE_VIA_STYLE_CONSTRAINT_DATA&>( aSource );
193
195
196 m_minViaDiameter = source.m_minViaDiameter;
197 m_maxViaDiameter = source.m_maxViaDiameter;
198 m_minViaHoleSize = source.m_minViaHoleSize;
199 m_maxViaHoleSize = source.m_maxViaHoleSize;
200
201 m_viaType = source.m_viaType;
202 }
203
204private:
205 double m_minViaDiameter{ 0 };
206 double m_maxViaDiameter{ 0 };
207 double m_minViaHoleSize{ 0 };
208 double m_maxViaHoleSize{ 0 };
210};
211
212#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.