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
31{
32public:
34
37 {
38 }
39
40 explicit DRC_RE_VIA_STYLE_CONSTRAINT_DATA( int aId, int aParentId, wxString aRuleName,
41 double aMinViaDiameter, double aMaxViaDiameter,
42 double aPreferredViaDiameter, double aMinViaHoleSize,
43 double aMaxViaHoleSize,
44 double aPreferredViaHoleSize ) :
45 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
46 m_minViaDiameter( aMinViaDiameter ), m_preferredViaDiameter( aPreferredViaDiameter ),
47 m_maxViaDiameter( aMaxViaDiameter ), m_minViaHoleSize( aMinViaHoleSize ),
48 m_preferredViaHoleSize( aPreferredViaHoleSize ), m_maxViaHoleSize( aMaxViaHoleSize )
49 {
50 }
51
53
55
56 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
57 {
58 // Positions measured from constraint_via_style.png bitmap
59 // Format: { xStart, xEnd, yTop, tabOrder }
60 return {
61 { 300, 340, 15, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_via_diameter (right side, top)
62 { 300, 340, 45, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_via_diameter (right side, middle)
63 { 300, 340, 75, 3, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_via_diameter (right side, bottom)
64 { 300, 340, 125, 4, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_via_hole (right side, below diameter)
65 { 300, 340, 155, 5, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_via_hole
66 { 300, 340, 185, 6, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_via_hole
67 };
68 }
69
70 VALIDATION_RESULT Validate() const override
71 {
73
74 // Validate via diameter values are positive
75 if( m_minViaDiameter <= 0 )
76 result.AddError( _( "Minimum Via Diameter must be greater than 0" ) );
77
78 if( m_preferredViaDiameter <= 0 )
79 result.AddError( _( "Preferred Via Diameter must be greater than 0" ) );
80
81 if( m_maxViaDiameter <= 0 )
82 result.AddError( _( "Maximum Via Diameter must be greater than 0" ) );
83
84 // Validate via hole size values are positive
85 if( m_minViaHoleSize <= 0 )
86 result.AddError( _( "Minimum Via Hole Size must be greater than 0" ) );
87
88 if( m_preferredViaHoleSize <= 0 )
89 result.AddError( _( "Preferred Via Hole Size must be greater than 0" ) );
90
91 if( m_maxViaHoleSize <= 0 )
92 result.AddError( _( "Maximum Via Hole Size must be greater than 0" ) );
93
94 // Validate min <= preferred <= max for diameter
96 result.AddError( _( "Minimum Via Diameter cannot be greater than Preferred Via Diameter" ) );
97
99 result.AddError( _( "Preferred Via Diameter cannot be greater than Maximum Via Diameter" ) );
100
102 result.AddError( _( "Minimum Via Diameter cannot be greater than Maximum Via Diameter" ) );
103
104 // Validate min <= preferred <= max for hole size
106 result.AddError( _( "Minimum Via Hole Size cannot be greater than Preferred Via Hole Size" ) );
107
109 result.AddError( _( "Preferred Via Hole Size cannot be greater than Maximum Via Hole Size" ) );
110
112 result.AddError( _( "Minimum Via Hole Size cannot be greater than Maximum Via Hole Size" ) );
113
114 return result;
115 }
116
117 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
118 {
119 auto formatDimension = []( double aValue )
120 {
121 return formatDouble( aValue ) + wxS( "mm" );
122 };
123
124 wxString diaClause = wxString::Format(
125 wxS( "(constraint via_diameter (min %s) (opt %s) (max %s))" ),
126 formatDimension( m_minViaDiameter ),
127 formatDimension( m_preferredViaDiameter ),
128 formatDimension( m_maxViaDiameter ) );
129
130 wxString drillClause = wxString::Format(
131 wxS( "(constraint hole_size (min %s) (opt %s) (max %s))" ),
132 formatDimension( m_minViaHoleSize ),
133 formatDimension( m_preferredViaHoleSize ),
134 formatDimension( m_maxViaHoleSize ) );
135
136 return { diaClause, drillClause };
137 }
138
139 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
140 {
141 return buildRule( aContext, GetConstraintClauses( aContext ) );
142 }
143
145
146 void SetMinViaDiameter( double aMinViaDiameter ) { m_minViaDiameter = aMinViaDiameter; }
147
149
150 void SetMaxViaDiameter( double aMaxViaDiameter ) { m_maxViaDiameter = aMaxViaDiameter; }
151
153
154 void SetPreferredViaDiameter( double aPreferredViaDiameter )
155 {
156 m_preferredViaDiameter = aPreferredViaDiameter;
157 }
158
160
161 void SetMinViaHoleSize( double aMinViaHoleSize ) { m_minViaHoleSize = aMinViaHoleSize; }
162
164
165 void SetMaxViaHoleSize( double aMaxViaHoleSize ) { m_maxViaHoleSize = aMaxViaHoleSize; }
166
168
169 void SetPreferredViaHoleSize( double aPreferredViaHoleSize )
170 {
171 m_preferredViaHoleSize = aPreferredViaHoleSize;
172 }
173
174 void CopyFrom( const ICopyable& aSource ) override
175 {
176 const auto& source = dynamic_cast<const DRC_RE_VIA_STYLE_CONSTRAINT_DATA&>( aSource );
177
179
180 m_minViaDiameter = source.m_minViaDiameter;
181 m_maxViaDiameter = source.m_maxViaDiameter;
182 m_preferredViaDiameter = source.m_preferredViaDiameter;
183 m_minViaHoleSize = source.m_minViaHoleSize;
184 m_maxViaHoleSize = source.m_maxViaHoleSize;
185 m_preferredViaHoleSize = source.m_preferredViaHoleSize;
186 }
187
188private:
189 double m_minViaDiameter{ 0 };
191 double m_maxViaDiameter{ 0 };
192 double m_minViaHoleSize{ 0 };
194 double m_maxViaHoleSize{ 0 };
195};
196
197#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
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
DRC_RE_VIA_STYLE_CONSTRAINT_DATA(int aId, int aParentId, wxString aRuleName, double aMinViaDiameter, double aMaxViaDiameter, double aPreferredViaDiameter, double aMinViaHoleSize, double aMaxViaHoleSize, double aPreferredViaHoleSize)
void SetPreferredViaDiameter(double aPreferredViaDiameter)
void SetPreferredViaHoleSize(double aPreferredViaHoleSize)
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.
#define _(s)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.