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
42 int aId, int aParentId, bool aAllowZeroDegreess, bool aAllowNinetyDegreess,
43 bool aAllowOneEightyDegreess, bool aAllowTwoSeventyDegreess, bool aAllowAllDegreess,
44 wxString aRuleName ) :
45 DRC_RE_BASE_CONSTRAINT_DATA( aId, aParentId, aRuleName ),
46 m_allowZeroDegreess( aAllowZeroDegreess ), m_allowNinetyDegrees( aAllowNinetyDegreess ),
47 m_allowOneEightyDegrees( aAllowOneEightyDegreess ),
48 m_allowTwoSeventyDegrees( aAllowTwoSeventyDegreess ),
49 m_allowAllDegrees( aAllowAllDegreess )
50 {
51 }
52
54
56
57 std::vector<DRC_RE_FIELD_POSITION> GetFieldPositions() const override
58 {
59 // Positions measured from constraint_allowed_orientation.png (~280x180)
60 // Format: { xStart, xEnd, yTop, tabOrder }
61 // Checkboxes stacked vertically on the right side
62 return {
63 { 400, 414, 40, 1, _( "Allow 0°" ), LABEL_POSITION::RIGHT }, // 0 degrees checkbox
64 { 400, 414, 80, 2, _( "Allow 90°" ), LABEL_POSITION::RIGHT }, // 90 degrees checkbox
65 { 400, 414, 120, 3, _( "Allow 180°" ), LABEL_POSITION::RIGHT }, // 180 degrees checkbox
66 { 400, 414, 160, 4, _( "Allow 270°" ), LABEL_POSITION::RIGHT }, // 270 degrees checkbox
67 { 400, 414, 200, 5, _( "Allow All" ), LABEL_POSITION::RIGHT }, // all degrees checkbox
68 };
69 }
70
71 std::vector<wxString> GetConstraintClauses( const RULE_GENERATION_CONTEXT& aContext ) const override
72 {
74 return { wxS( "(constraint assertion \"A.Orientation == A.Orientation\")" ) };
75
76 wxArrayString terms;
77
79 terms.Add( wxS( "A.Orientation == 0 deg" ) );
80
82 terms.Add( wxS( "A.Orientation == 90 deg" ) );
83
85 terms.Add( wxS( "A.Orientation == 180 deg" ) );
86
88 terms.Add( wxS( "A.Orientation == 270 deg" ) );
89
90 if( terms.IsEmpty() )
91 return {};
92
93 wxString expr = wxJoin( terms, '|' );
94 expr.Replace( wxS( "|" ), wxS( " || " ) );
95
96 wxString clause = wxString::Format( wxS( "(constraint assertion \"%s\")" ), expr );
97
98 return { clause };
99 }
100
101 wxString GenerateRule( const RULE_GENERATION_CONTEXT& aContext ) override
102 {
103 return buildRule( aContext, GetConstraintClauses( aContext ) );
104 }
105
107 {
109
110 // At least one orientation must be selected
113 {
114 result.AddError( _( "At least one orientation must be selected" ) );
115 }
116
117 return result;
118 }
119
121
122 void SetIsZeroDegreesAllowed( bool aAllowZeroDegreess )
123 {
124 m_allowZeroDegreess = aAllowZeroDegreess;
125 }
126
128
129 void SetIsNinetyDegreesAllowed( bool aAllowNinetyDegrees )
130 {
131 m_allowNinetyDegrees = aAllowNinetyDegrees ;
132 }
133
135
136 void SetIsOneEightyDegreesAllowed( bool aAllowOneEightyDegrees )
137 {
138 m_allowOneEightyDegrees = aAllowOneEightyDegrees;
139 }
140
142
143 void SetIsTwoSeventyDegreesAllowed( bool aAllowTwoSeventyDegrees )
144 {
145 m_allowTwoSeventyDegrees = aAllowTwoSeventyDegrees;
146 }
147
149
150 void SetIsAllDegreesAllowed( bool aAllowAllDegrees )
151 {
152 m_allowAllDegrees = aAllowAllDegrees;
153 }
154
155 void CopyFrom( const ICopyable& aSource ) override
156 {
157 const auto& source =
158 dynamic_cast<const DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA&>( aSource );
159
161
162 m_allowZeroDegreess = source.m_allowZeroDegreess;
163 m_allowNinetyDegrees = source.m_allowNinetyDegrees;
164 m_allowOneEightyDegrees = source.m_allowOneEightyDegrees;
165 m_allowTwoSeventyDegrees = source.m_allowTwoSeventyDegrees;
166 m_allowAllDegrees = source.m_allowAllDegrees;
167 }
168
169private:
170 bool m_allowZeroDegreess{ false };
171 bool m_allowNinetyDegrees{ false };
174 bool m_allowAllDegrees{ false };
175};
176
177#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)
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.
DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA(int aId, int aParentId, bool aAllowZeroDegreess, bool aAllowNinetyDegreess, bool aAllowOneEightyDegreess, bool aAllowTwoSeventyDegreess, bool aAllowAllDegreess, wxString aRuleName)
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.