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, wxString aRuleName,
42 double aMinRoutingWidth,
43 double aPreferredRoutingWidth,
44 double aMaxRoutingWidth ) :
45 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
46 m_minRoutingWidth( aMinRoutingWidth ),
47 m_preferredRoutingWidth( aPreferredRoutingWidth ), m_maxRoutingWidth( aMaxRoutingWidth )
48 {
49 }
50
52
54
55 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
56 {
57 // Positions measured from constraint_routing_width.png bitmap
58 // Format: { xStart, xEnd, yTop, tabOrder }
59 return {
60 { 64, 104, 96, 1, wxS( "mm" ), LABEL_POSITION::RIGHT }, // min_width (left arrow)
61 { 126, 166, 40, 2, wxS( "mm" ), LABEL_POSITION::RIGHT }, // opt_width (bottom center arrow)
62 { 248, 288, 74, 3, wxS( "mm" ), LABEL_POSITION::RIGHT }, // max_width (right arrow)
63 };
64 }
65
66
67 VALIDATION_RESULT Validate() const override
68 {
70
71 if( m_minRoutingWidth <= 0 )
72 result.AddError( _( "Minimum Routing Width must be greater than 0" ) );
73
75 result.AddError( _( "Preferred Routing Width must be greater than 0" ) );
76
77 if( m_maxRoutingWidth <= 0 )
78 result.AddError( _( "Maximum Routing Width must be greater than 0" ) );
79
80 if( result.isValid )
81 {
83 result.AddError( _( "Minimum Routing Width cannot be greater than Preferred Routing Width" ) );
84
86 result.AddError( _( "Preferred Routing Width cannot be greater than Maximum Routing Width" ) );
87
89 result.AddError( _( "Minimum Routing Width cannot be greater than Maximum Routing Width" ) );
90 }
91
92 return result;
93 }
94
95
96 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
97 {
98 auto formatDistance = []( double aValue )
99 {
100 return formatDouble( aValue ) + wxS( "mm" );
101 };
102
103 wxString code = GetConstraintCode();
104
105 if( code.IsEmpty() )
106 code = wxS( "track_width" );
107
108 wxString clause = wxString::Format(
109 wxS( "(constraint %s (min %s) (opt %s) (max %s))" ),
110 code,
111 formatDistance( m_minRoutingWidth ),
112 formatDistance( m_preferredRoutingWidth ),
113 formatDistance( m_maxRoutingWidth ) );
114
115 return { clause };
116 }
117
118 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
119 {
120 return buildRule( aContext, GetConstraintClauses( aContext ) );
121 }
122
124
125 void SetMinRoutingWidth( double aMinRoutingWidth ) { m_minRoutingWidth = aMinRoutingWidth; }
126
128
129 void SetPreferredRoutingWidth( double aPreferredRoutingWidth )
130 {
131 m_preferredRoutingWidth = aPreferredRoutingWidth;
132 }
133
135
136 void SetMaxRoutingWidth( double aMaxRoutingWidth ) { m_maxRoutingWidth = aMaxRoutingWidth; }
137
138 void CopyFrom( const ICopyable& aSource ) override
139 {
140 const auto& source = dynamic_cast<const DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA&>( aSource );
141
143
144 m_minRoutingWidth = source.m_minRoutingWidth;
145 m_preferredRoutingWidth = source.m_preferredRoutingWidth;
146 m_maxRoutingWidth = source.m_maxRoutingWidth;
147 }
148
149private:
150 double m_minRoutingWidth{ 0 };
152 double m_maxRoutingWidth{ 0 };
153};
154
155#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.
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)
DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA(int aId, int aParentId, wxString aRuleName, double aMinRoutingWidth, double aPreferredRoutingWidth, double aMaxRoutingWidth)
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
void SetPreferredRoutingWidth(double aPreferredRoutingWidth)
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.