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
28
29
31{
32public:
34
39
40 explicit DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA( int aId, int aParentId, wxString aRuleName,
41 double aMinRoutingWidth,
42 double aPreferredRoutingWidth,
43 double aMaxRoutingWidth ) :
44 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
45 m_minRoutingWidth( aMinRoutingWidth ),
46 m_preferredRoutingWidth( aPreferredRoutingWidth ), m_maxRoutingWidth( aMaxRoutingWidth )
47 {
48 }
49
51
52 VALIDATION_RESULT Validate() const override
53 {
55
56 // Validate routing width values are positive
57 if( m_minRoutingWidth <= 0 )
58 result.AddError( "Minimum Routing Width must be greater than 0" );
59
61 result.AddError( "Preferred Routing Width must be greater than 0" );
62
63 if( m_maxRoutingWidth <= 0 )
64 result.AddError( "Maximum Routing Width must be greater than 0" );
65
66 // Validate min <= preferred <= max
68 result.AddError( "Minimum Routing Width cannot be greater than Preferred Routing Width" );
69
71 result.AddError( "Preferred Routing Width cannot be greater than Maximum Routing Width" );
72
74 result.AddError( "Minimum Routing Width cannot be greater than Maximum Routing Width" );
75
76 return result;
77 }
78
79 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
80 {
81 auto formatDistance = [&]( double aValue )
82 {
83 return formatDouble( aValue ) + wxS( "mm" );
84 };
85
86 wxString code = GetConstraintCode();
87
88 if( code.IsEmpty() )
89 code = wxS( "track_width" );
90
91 wxString clause = wxString::Format(
92 wxS( "(constraint %s (min %s) (opt %s) (max %s))" ),
93 code,
94 formatDistance( m_minRoutingWidth ),
95 formatDistance( m_preferredRoutingWidth ),
96 formatDistance( m_maxRoutingWidth ) );
97
98 return buildRule( aContext, { clause } );
99 }
100
102
103 void SetMinRoutingWidth( double aMinRoutingWidth ) { m_minRoutingWidth = aMinRoutingWidth; }
104
106
107 void SetPreferredRoutingWidth( double aPreferredRoutingWidth )
108 {
109 m_preferredRoutingWidth = aPreferredRoutingWidth;
110 }
111
113
114 void SetMaxRoutingWidth( double aMaxRoutingWidth ) { m_maxRoutingWidth = aMaxRoutingWidth; }
115
116 void CopyFrom( const ICopyable& aSource ) override
117 {
118 const auto& source = dynamic_cast<const DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA&>( aSource );
119
121
122 m_minRoutingWidth = source.m_minRoutingWidth;
123 m_preferredRoutingWidth = source.m_preferredRoutingWidth;
124 m_maxRoutingWidth = source.m_maxRoutingWidth;
125 }
126
127private:
128 double m_minRoutingWidth{ 0 };
130 double m_maxRoutingWidth{ 0 };
131};
132
133#endif // DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA_H_
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
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.
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.