KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_abs_length_two_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_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA_H_
25#define DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA_H_
26
28
29
31{
32public:
34
40
41 explicit DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA( int aId, int aParentId,
42 double aMinLength,
43 double aOptLength,
44 double aMaxLength,
45 wxString aRuleName ) :
46 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
47 m_minLength( aMinLength ),
48 m_optLength( aOptLength ),
49 m_maxLength( aMaxLength )
50 {
51 }
52
54
56
57 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
58 {
59 // Positions measured from constraint_absolute_lenght_2.png (~340x130)
60 // Format: { xStart, xEnd, yTop, tabOrder }
61 return {
62 { 285, 315, 62, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_length (left arrow)
63 { 245, 275, 131, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_length (bottom center arrow)
64 { 15, 45, 37, 3, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_length (right arrow)
65 };
66 }
67
68 double GetMinimumLength() const { return m_minLength; }
69
70 void SetMinimumLength( double aLength ) { m_minLength = aLength; }
71
72 double GetOptimumLength() const { return m_optLength; }
73
74 void SetOptimumLength( double aLength ) { m_optLength = aLength; }
75
76 double GetMaximumLength() const { return m_maxLength; }
77
78 void SetMaximumLength( double aLength ) { m_maxLength = aLength; }
79
80 VALIDATION_RESULT Validate() const override
81 {
83
84 // Validate length values are positive
85 if( m_minLength <= 0 )
86 result.AddError( _( "Minimum Length must be greater than 0" ) );
87
88 if( m_optLength <= 0 )
89 result.AddError( _( "Optimum Length must be greater than 0" ) );
90
91 if( m_maxLength <= 0 )
92 result.AddError( _( "Maximum Length must be greater than 0" ) );
93
94 // Validate min <= opt <= max
96 result.AddError( _( "Minimum Length cannot be greater than Optimum Length" ) );
97
99 result.AddError( _( "Optimum Length cannot be greater than Maximum Length" ) );
100
102 result.AddError( _( "Minimum Length cannot be greater than Maximum Length" ) );
103
104 return result;
105 }
106
107 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
108 {
109 auto formatDistance = []( double aValue )
110 {
111 return formatDouble( aValue ) + wxS( "mm" );
112 };
113
114 wxString code = GetConstraintCode();
115
116 if( code.IsEmpty() )
117 code = wxS( "length" );
118
119 wxString clause = wxString::Format(
120 wxS( "(constraint %s (min %s) (opt %s) (max %s))" ),
121 code,
122 formatDistance( m_minLength ),
123 formatDistance( m_optLength ),
124 formatDistance( m_maxLength ) );
125
126 return { clause };
127 }
128
129 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
130 {
131 return buildRule( aContext, GetConstraintClauses( aContext ) );
132 }
133
134 void CopyFrom( const ICopyable& aSource ) override
135 {
136 const auto& source =
137 dynamic_cast<const DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA&>( aSource );
138
140
141 m_minLength = source.m_minLength;
142 m_optLength = source.m_optLength;
143 m_maxLength = source.m_maxLength;
144 }
145
146private:
147 double m_minLength{ 0 };
148 double m_optLength{ 0 };
149 double m_maxLength{ 0 };
150};
151
153{
154public:
156
158
159 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
160 {
161 return {
162 { 335, 365, 33, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_length
163 { 335, 365, 103, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_length
164 { 335, 365, 173, 3, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_length
165 };
166 }
167
168 double GetMaxSkew() const { return m_maxSkew; }
169
170 void SetMaxSkew( double aSkew ) { m_maxSkew = aSkew; }
171
172 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
173 {
174 std::vector<wxString> clauses = DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA::GetConstraintClauses( aContext );
175
176 if( m_maxSkew > 0 )
177 {
178 wxString skewClause = wxString::Format(
179 wxS( "(constraint skew (max %smm))" ), formatDouble( m_maxSkew ) );
180 clauses.push_back( skewClause );
181 }
182
183 return clauses;
184 }
185
186 void CopyFrom( const ICopyable& aSource ) override
187 {
188 const auto& source =
189 dynamic_cast<const DRC_RE_MATCHED_LENGTH_DIFF_PAIR_CONSTRAINT_DATA&>( aSource );
190
192
193 m_maxSkew = source.m_maxSkew;
194 }
195
196private:
197 double m_maxSkew{ 0 };
198};
199
200#endif // DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA_H_
BITMAPS
A list of all bitmap identifiers.
@ constraint_absolute_length_2
@ constraint_matched_length_diff_pair
VALIDATION_RESULT Validate() const override
Validates the constraint data.
DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA(int aId, int aParentId, double aMinLength, double aOptLength, double aMaxLength, wxString aRuleName)
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
std::vector< DRC_RE_FIELD_POSITION > GetFieldPositions() const override
Returns the field positions for controls overlaid on the constraint bitmap.
DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA(const DRC_RE_BASE_CONSTRAINT_DATA &aBaseData)
virtual ~DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA()=default
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
std::vector< DRC_RE_FIELD_POSITION > GetFieldPositions() const override
Returns the field positions for controls overlaid on the constraint bitmap.
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
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.