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, 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_ROUTING_WIDTH_CONSTRAINT_DATA_H_
25#define DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA_H_
26
29
30
32{
33public:
35
40
41 explicit DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA( int aId, int aParentId, const wxString& aRuleName, double aOptWidth,
42 double aWidthTolerance ) :
43 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
44 m_optWidth( aOptWidth ),
45 m_widthTolerance( aWidthTolerance )
46 {
47 }
48
50
52
53 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
54 {
55 // Positions measured from constraint_routing_width.png bitmap
56 // Format: { xStart, xEnd, yTop, tabOrder }
57 return {
58 { 30 + DRC_RE_OVERLAY_XO, 70 + DRC_RE_OVERLAY_XO, 15 + DRC_RE_OVERLAY_YO, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_width
59 { 110 + DRC_RE_OVERLAY_XO, 150 + DRC_RE_OVERLAY_XO, 15 + DRC_RE_OVERLAY_YO, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // width_tolerance (±)
60 };
61 }
62
63
64 VALIDATION_RESULT Validate() const override
65 {
67
68 if( m_optWidth <= 0 )
69 result.AddError( _( "Optimum Width must be greater than 0" ) );
70
71 if( m_widthTolerance < 0 )
72 result.AddError( _( "Width Tolerance must be greater than or equal to 0" ) );
73
75 result.AddError( _( "Width Tolerance must be less than Optimum Width" ) );
76
77 return result;
78 }
79
80
81 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
82 {
83 auto formatDistance = []( double aValue )
84 {
85 return formatDouble( aValue ) + wxS( "mm" );
86 };
87
88 wxString code = GetConstraintCode();
89
90 if( code.IsEmpty() )
91 code = wxS( "track_width" );
92
93 double minWidth = m_optWidth - m_widthTolerance;
94 double maxWidth = m_optWidth + m_widthTolerance;
95
96 wxString clause =
97 wxString::Format( wxS( "(constraint %s (min %s) (opt %s) (max %s))" ), code, formatDistance( minWidth ),
98 formatDistance( m_optWidth ), formatDistance( maxWidth ) );
99
100 return { clause };
101 }
102
103 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
104 {
105 return buildRule( aContext, GetConstraintClauses( aContext ) );
106 }
107
108 double GetOptWidth() { return m_optWidth; }
109 void SetOptWidth( double aOptWidth ) { m_optWidth = aOptWidth; }
110
112 void SetWidthTolerance( double aTolerance ) { m_widthTolerance = aTolerance; }
113
114 void CopyFrom( const ICopyable& aSource ) override
115 {
116 const auto& source = dynamic_cast<const DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA&>( aSource );
117
119
120 m_optWidth = source.m_optWidth;
121 m_widthTolerance = source.m_widthTolerance;
122 }
123
124private:
125 double m_optWidth{ 0 };
126 double m_widthTolerance{ 0 };
127};
128
129#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.