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, 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_ALLOWED_ORIENTATION_CONSTRAINT_DATA_H_
25#define DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA_H_
26
28
29
31{
32public:
34
40
41 explicit DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA( int aId, int aParentId, bool aAllowZeroDegrees,
42 bool aAllowNinetyDegrees, bool aAllowOneEightyDegrees,
43 bool aAllowTwoSeventyDegrees, bool aAllowAllDegrees,
44 const wxString& aRuleName ) :
45 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
46 m_allowZeroDegrees( aAllowZeroDegrees || aAllowAllDegrees ),
47 m_allowNinetyDegrees( aAllowNinetyDegrees || aAllowAllDegrees ),
48 m_allowOneEightyDegrees( aAllowOneEightyDegrees || aAllowAllDegrees ),
49 m_allowTwoSeventyDegrees( aAllowTwoSeventyDegrees || aAllowAllDegrees ),
50 m_allowAllDegrees( aAllowAllDegrees )
51 {
52 }
53
55
57
58 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
59 {
60 // Positions measured from constraint_allowed_orientation.png (~280x180)
61 // Format: { xStart, xEnd, yTop, tabOrder }
62 // Checkboxes stacked vertically on the right side
63 return {
64 { 400 + DRC_RE_OVERLAY_XO, 414 + DRC_RE_OVERLAY_XO, 40 + DRC_RE_OVERLAY_YO, 1, _( "Allow 0°" ), LABEL_POSITION::RIGHT }, // 0 degrees checkbox
65 { 400 + DRC_RE_OVERLAY_XO, 414 + DRC_RE_OVERLAY_XO, 80 + DRC_RE_OVERLAY_YO, 2, _( "Allow 90°" ), LABEL_POSITION::RIGHT }, // 90 degrees checkbox
66 { 400 + DRC_RE_OVERLAY_XO, 414 + DRC_RE_OVERLAY_XO, 120 + DRC_RE_OVERLAY_YO, 3, _( "Allow 180°" ), LABEL_POSITION::RIGHT }, // 180 degrees checkbox
67 { 400 + DRC_RE_OVERLAY_XO, 414 + DRC_RE_OVERLAY_XO, 160 + DRC_RE_OVERLAY_YO, 4, _( "Allow 270°" ), LABEL_POSITION::RIGHT }, // 270 degrees checkbox
68 { 400 + DRC_RE_OVERLAY_XO, 414 + DRC_RE_OVERLAY_XO, 200 + DRC_RE_OVERLAY_YO, 5, _( "Allow All" ), LABEL_POSITION::RIGHT }, // 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.
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.
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.