KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_allowed_orientation_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_ALLOWED_ORIENTATION_CONSTRAINT_DATA_H_
21#define DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA_H_
22
24
25
27{
28public:
30
36
37 explicit DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA( int aId, int aParentId, bool aAllowZeroDegrees,
38 bool aAllowNinetyDegrees, bool aAllowOneEightyDegrees,
39 bool aAllowTwoSeventyDegrees, bool aAllowAllDegrees,
40 const wxString& aRuleName ) :
41 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
42 m_allowZeroDegrees( aAllowZeroDegrees || aAllowAllDegrees ),
43 m_allowNinetyDegrees( aAllowNinetyDegrees || aAllowAllDegrees ),
44 m_allowOneEightyDegrees( aAllowOneEightyDegrees || aAllowAllDegrees ),
45 m_allowTwoSeventyDegrees( aAllowTwoSeventyDegrees || aAllowAllDegrees ),
46 m_allowAllDegrees( aAllowAllDegrees )
47 {
48 }
49
51
53
54 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
55 {
56 // Positions measured from constraint_allowed_orientation.png (~280x180)
57 // Format: { xStart, xEnd, yCenter }
58 // Checkboxes stacked vertically on the right side
59 return {
60 { 400, 615, 52, _( "Allow 0°" ), LABEL_POSITION::RIGHT,
61 _( "Allow footprints placed at 0 degrees" ) }, // 0 degrees checkbox
62 { 400, 615, 92, _( "Allow 90°" ), LABEL_POSITION::RIGHT,
63 _( "Allow footprints placed at 90 degrees" ) }, // 90 degrees checkbox
64 { 400, 615, 132, _( "Allow 180°" ), LABEL_POSITION::RIGHT,
65 _( "Allow footprints placed at 180 degrees" ) }, // 180 degrees checkbox
66 { 400, 615, 172, _( "Allow 270°" ), LABEL_POSITION::RIGHT,
67 _( "Allow footprints placed at 270 degrees" ) }, // 270 degrees checkbox
68 { 400, 615, 212, _( "Allow All" ), LABEL_POSITION::RIGHT,
69 _( "Allow footprints at any orientation" ) }, // all degrees checkbox
70 };
71 }
72
73 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
74 {
75 wxArrayString terms;
76
78 terms.Add( wxS( "A.Orientation == 0 deg" ) );
79
81 terms.Add( wxS( "A.Orientation == 90 deg" ) );
82
84 terms.Add( wxS( "A.Orientation == 180 deg" ) );
85
87 terms.Add( wxS( "A.Orientation == 270 deg" ) );
88
89 if( terms.IsEmpty() )
90 return {};
91
92 wxString expr = wxJoin( terms, '|' );
93 expr.Replace( wxS( "|" ), wxS( " || " ) );
94
95 wxString clause = wxString::Format( wxS( "(constraint assertion \"%s\")" ), expr );
96
97 return { clause };
98 }
99
100 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
101 {
102 return buildRule( aContext, GetConstraintClauses( aContext ) );
103 }
104
106 {
108
109 // At least one orientation must be selected
111 {
112 result.AddError( _( "At least one orientation must be selected" ) );
113 }
114
115 return result;
116 }
117
119
120 void SetIsZeroDegreesAllowed( bool aAllowZeroDegrees ) { m_allowZeroDegrees = aAllowZeroDegrees; }
121
123
124 void SetIsNinetyDegreesAllowed( bool aAllowNinetyDegrees )
125 {
126 m_allowNinetyDegrees = aAllowNinetyDegrees ;
127 }
128
130
131 void SetIsOneEightyDegreesAllowed( bool aAllowOneEightyDegrees )
132 {
133 m_allowOneEightyDegrees = aAllowOneEightyDegrees;
134 }
135
137
138 void SetIsTwoSeventyDegreesAllowed( bool aAllowTwoSeventyDegrees )
139 {
140 m_allowTwoSeventyDegrees = aAllowTwoSeventyDegrees;
141 }
142
144
145 void SetIsAllDegreesAllowed( bool aAllowAllDegrees )
146 {
147 m_allowAllDegrees = aAllowAllDegrees;
148
149 if( aAllowAllDegrees )
150 {
151 m_allowZeroDegrees = true;
155 }
156 }
157
158 void CopyFrom( const ICopyable& aSource ) override
159 {
160 const auto& source =
161 dynamic_cast<const DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA&>( aSource );
162
164
165 m_allowZeroDegrees = source.m_allowZeroDegrees;
166 m_allowNinetyDegrees = source.m_allowNinetyDegrees;
167 m_allowOneEightyDegrees = source.m_allowOneEightyDegrees;
168 m_allowTwoSeventyDegrees = source.m_allowTwoSeventyDegrees;
169 m_allowAllDegrees = source.m_allowAllDegrees;
170 }
171
172private:
173 bool m_allowZeroDegrees{ false };
174 bool m_allowNinetyDegrees{ false };
177 bool m_allowAllDegrees{ false };
178};
179
180#endif // DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA_H_
BITMAPS
A list of all bitmap identifiers.
@ constraint_allowed_orientation
std::vector< wxString > GetConstraintClauses(const RULE_GENERATION_CONTEXT &aContext) const override
Returns just the constraint clauses without the rule wrapper.
DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA(int aId, int aParentId, bool aAllowZeroDegrees, bool aAllowNinetyDegrees, bool aAllowOneEightyDegrees, bool aAllowTwoSeventyDegrees, bool aAllowAllDegrees, const wxString &aRuleName)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA(const DRC_RE_BASE_CONSTRAINT_DATA &aBaseData)
std::vector< DRC_RE_FIELD_POSITION > GetFieldPositions() const override
Returns the field positions for controls overlaid on the constraint bitmap.
virtual ~DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA()=default
VALIDATION_RESULT Validate() const override
Validates the constraint data.
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
wxString buildRule(const RULE_GENERATION_CONTEXT &aContext, const std::vector< wxString > &aConstraintClauses) const
void CopyFrom(const ICopyable &aSource) override
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.