KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_routing_width_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_ROUTING_WIDTH_CONSTRAINT_DATA_H_
21#define DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA_H_
22
25
26
28{
29public:
31
36
37 explicit DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA( int aId, int aParentId, const wxString& aRuleName, double aOptWidth,
38 double aWidthTolerance ) :
39 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
40 m_optWidth( aOptWidth ),
41 m_widthTolerance( aWidthTolerance )
42 {
43 }
44
46
48
49 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
50 {
51 // Positions measured from constraint_routing_width.png bitmap
52 // Format: { xStart, xEnd, yCenter }
53 return {
54 { 30, 85, 27, wxS( "mm" ), LABEL_POSITION::RIGHT, _( "Optimum track width" ) }, // opt_width
55 { 135, 190, 27, wxS( "mm" ), LABEL_POSITION::RIGHT,
56 _( "Allowed deviation above or below the optimum width" ), wxS( "\u00B1" ) }, // width_tolerance (±)
57 };
58 }
59
60
61 VALIDATION_RESULT Validate() const override
62 {
64
65 if( m_optWidth <= 0 )
66 result.AddError( _( "Optimum Width must be greater than 0" ) );
67
68 if( m_widthTolerance < 0 )
69 result.AddError( _( "Width Tolerance must be greater than or equal to 0" ) );
70
72 result.AddError( _( "Width Tolerance must be less than Optimum Width" ) );
73
74 return result;
75 }
76
77
78 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
79 {
80 auto formatDistance = []( double aValue )
81 {
82 return formatDouble( aValue ) + wxS( "mm" );
83 };
84
85 wxString code = GetConstraintCode();
86
87 if( code.IsEmpty() )
88 code = wxS( "track_width" );
89
90 double minWidth = m_optWidth - m_widthTolerance;
91 double maxWidth = m_optWidth + m_widthTolerance;
92
93 wxString clause =
94 wxString::Format( wxS( "(constraint %s (min %s) (opt %s) (max %s))" ), code, formatDistance( minWidth ),
95 formatDistance( m_optWidth ), formatDistance( maxWidth ) );
96
97 return { clause };
98 }
99
100 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
101 {
102 return buildRule( aContext, GetConstraintClauses( aContext ) );
103 }
104
105 double GetOptWidth() { return m_optWidth; }
106 void SetOptWidth( double aOptWidth ) { m_optWidth = aOptWidth; }
107
109 void SetWidthTolerance( double aTolerance ) { m_widthTolerance = aTolerance; }
110
111 void CopyFrom( const ICopyable& aSource ) override
112 {
113 const auto& source = dynamic_cast<const DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA&>( aSource );
114
116
117 m_optWidth = source.m_optWidth;
118 m_widthTolerance = source.m_widthTolerance;
119 }
120
121private:
122 double m_optWidth{ 0 };
123 double m_widthTolerance{ 0 };
124};
125
126#endif // DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA_H_
BITMAPS
A list of all bitmap identifiers.
@ constraint_routing_width
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.
DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA(int aId, int aParentId, const wxString &aRuleName, double aOptWidth, double aWidthTolerance)
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.
DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA(const DRC_RE_BASE_CONSTRAINT_DATA &aBaseData)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
VALIDATION_RESULT Validate() const override
Validates the constraint data.
void CopyFrom(const ICopyable &aSource) override
virtual ~DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA()=default
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.