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, bool aAllowZeroDegrees, bool aAllowNinetyDegrees,
38 bool aAllowOneEightyDegrees, bool aAllowTwoSeventyDegrees,
39 bool aAllowAllDegrees, const wxString& aRuleName ) :
40 DRC_RE_BASE_CONSTRAINT_DATA( aId, aRuleName ),
41 m_allowZeroDegrees( aAllowZeroDegrees || aAllowAllDegrees ),
42 m_allowNinetyDegrees( aAllowNinetyDegrees || aAllowAllDegrees ),
43 m_allowOneEightyDegrees( aAllowOneEightyDegrees || aAllowAllDegrees ),
44 m_allowTwoSeventyDegrees( aAllowTwoSeventyDegrees || aAllowAllDegrees ),
45 m_allowAllDegrees( aAllowAllDegrees )
46 {
47 }
48
50
52
53 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
54 {
55 // Positions measured from constraint_allowed_orientation.png (~280x180)
56 // Format: { xStart, xEnd, yCenter }
57 // Checkboxes stacked vertically on the right side
58 return {
59 { 400, 615, 52, _( "Allow 0°" ), LABEL_POSITION::RIGHT,
60 _( "Allow footprints placed at 0 degrees" ) }, // 0 degrees checkbox
61 { 400, 615, 92, _( "Allow 90°" ), LABEL_POSITION::RIGHT,
62 _( "Allow footprints placed at 90 degrees" ) }, // 90 degrees checkbox
63 { 400, 615, 132, _( "Allow 180°" ), LABEL_POSITION::RIGHT,
64 _( "Allow footprints placed at 180 degrees" ) }, // 180 degrees checkbox
65 { 400, 615, 172, _( "Allow 270°" ), LABEL_POSITION::RIGHT,
66 _( "Allow footprints placed at 270 degrees" ) }, // 270 degrees checkbox
67 { 400, 615, 212, _( "Allow All" ), LABEL_POSITION::RIGHT,
68 _( "Allow footprints at any orientation" ) }, // all degrees checkbox
69 };
70 }
71
72 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
73 {
74 wxArrayString terms;
75
77 terms.Add( wxS( "A.Orientation == 0 deg" ) );
78
80 terms.Add( wxS( "A.Orientation == 90 deg" ) );
81
83 terms.Add( wxS( "A.Orientation == 180 deg" ) );
84
86 terms.Add( wxS( "A.Orientation == 270 deg" ) );
87
88 if( terms.IsEmpty() )
89 return {};
90
91 wxString expr = wxJoin( terms, '|' );
92 expr.Replace( wxS( "|" ), wxS( " || " ) );
93
94 wxString clause = wxString::Format( wxS( "(constraint assertion \"%s\")" ), expr );
95
96 return { clause };
97 }
98
99 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
100 {
101 return buildRule( aContext, GetConstraintClauses( aContext ) );
102 }
103
105 {
107
108 // At least one orientation must be selected
110 {
111 result.AddError( _( "At least one orientation must be selected" ) );
112 }
113
114 return result;
115 }
116
118
119 void SetIsZeroDegreesAllowed( bool aAllowZeroDegrees ) { m_allowZeroDegrees = aAllowZeroDegrees; }
120
122
123 void SetIsNinetyDegreesAllowed( bool aAllowNinetyDegrees )
124 {
125 m_allowNinetyDegrees = aAllowNinetyDegrees ;
126 }
127
129
130 void SetIsOneEightyDegreesAllowed( bool aAllowOneEightyDegrees )
131 {
132 m_allowOneEightyDegrees = aAllowOneEightyDegrees;
133 }
134
136
137 void SetIsTwoSeventyDegreesAllowed( bool aAllowTwoSeventyDegrees )
138 {
139 m_allowTwoSeventyDegrees = aAllowTwoSeventyDegrees;
140 }
141
143
144 void SetIsAllDegreesAllowed( bool aAllowAllDegrees )
145 {
146 m_allowAllDegrees = aAllowAllDegrees;
147
148 if( aAllowAllDegrees )
149 {
150 m_allowZeroDegrees = true;
154 }
155 }
156
157 void CopyFrom( const ICopyable& aSource ) override
158 {
159 const auto& source =
160 dynamic_cast<const DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA&>( aSource );
161
163
164 m_allowZeroDegrees = source.m_allowZeroDegrees;
165 m_allowNinetyDegrees = source.m_allowNinetyDegrees;
166 m_allowOneEightyDegrees = source.m_allowOneEightyDegrees;
167 m_allowTwoSeventyDegrees = source.m_allowTwoSeventyDegrees;
168 m_allowAllDegrees = source.m_allowAllDegrees;
169 }
170
171private:
172 bool m_allowZeroDegrees{ false };
173 bool m_allowNinetyDegrees{ false };
176 bool m_allowAllDegrees{ false };
177};
178
179#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.
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA(const DRC_RE_BASE_CONSTRAINT_DATA &aBaseData)
DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA(int aId, bool aAllowZeroDegrees, bool aAllowNinetyDegrees, bool aAllowOneEightyDegrees, bool aAllowTwoSeventyDegrees, bool aAllowAllDegrees, const wxString &aRuleName)
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)
std::string source
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.