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, yTop, tabOrder }
53 return {
54 { 30 + DRC_RE_OVERLAY_XO, 70 + DRC_RE_OVERLAY_XO, 15 + DRC_RE_OVERLAY_YO, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_width
55 { 110 + DRC_RE_OVERLAY_XO, 150 + DRC_RE_OVERLAY_XO, 15 + DRC_RE_OVERLAY_YO, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // width_tolerance (±)
56 };
57 }
58
59
60 VALIDATION_RESULT Validate() const override
61 {
63
64 if( m_optWidth <= 0 )
65 result.AddError( _( "Optimum Width must be greater than 0" ) );
66
67 if( m_widthTolerance < 0 )
68 result.AddError( _( "Width Tolerance must be greater than or equal to 0" ) );
69
71 result.AddError( _( "Width Tolerance must be less than Optimum Width" ) );
72
73 return result;
74 }
75
76
77 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
78 {
79 auto formatDistance = []( double aValue )
80 {
81 return formatDouble( aValue ) + wxS( "mm" );
82 };
83
84 wxString code = GetConstraintCode();
85
86 if( code.IsEmpty() )
87 code = wxS( "track_width" );
88
89 double minWidth = m_optWidth - m_widthTolerance;
90 double maxWidth = m_optWidth + m_widthTolerance;
91
92 wxString clause =
93 wxString::Format( wxS( "(constraint %s (min %s) (opt %s) (max %s))" ), code, formatDistance( minWidth ),
94 formatDistance( m_optWidth ), formatDistance( maxWidth ) );
95
96 return { clause };
97 }
98
99 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
100 {
101 return buildRule( aContext, GetConstraintClauses( aContext ) );
102 }
103
104 double GetOptWidth() { return m_optWidth; }
105 void SetOptWidth( double aOptWidth ) { m_optWidth = aOptWidth; }
106
108 void SetWidthTolerance( double aTolerance ) { m_widthTolerance = aTolerance; }
109
110 void CopyFrom( const ICopyable& aSource ) override
111 {
112 const auto& source = dynamic_cast<const DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA&>( aSource );
113
115
116 m_optWidth = source.m_optWidth;
117 m_widthTolerance = source.m_widthTolerance;
118 }
119
120private:
121 double m_optWidth{ 0 };
122 double m_widthTolerance{ 0 };
123};
124
125#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.
constexpr int DRC_RE_OVERLAY_XO
constexpr int DRC_RE_OVERLAY_YO
@ 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.