KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_allowed_orientation_panel.cpp
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
25
26#include <wx/arrstr.h>
27#include <wx/log.h>
28
29
31 wxString* aConstraintTitle,
32 std::shared_ptr<DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA> aConstraintData ) :
33 DRC_RE_ALLOWED_ORIENTATION_PANEL_BASE( aParent ), m_constraintData( aConstraintData )
34{
36 0, wxALL | wxEXPAND, 10 );
37
38 m_zeroDegreesChkCtrl->Bind( wxEVT_CHECKBOX,
40 m_ninetyDegreesChkCtrl->Bind( wxEVT_CHECKBOX,
42 m_oneEightyDegreesChkCtrl->Bind( wxEVT_CHECKBOX,
44 m_twoSeventyDegreesChkCtrl->Bind( wxEVT_CHECKBOX,
46 m_allOrientationsChkCtrl->Bind( wxEVT_CHECKBOX,
48 this );
49}
50
51
66
67
69{
71 {
72 m_zeroDegreesChkCtrl->SetValue( m_constraintData->GetIsZeroDegreesAllowed() );
73 m_ninetyDegreesChkCtrl->SetValue( m_constraintData->GetIsNinetyDegreesAllowed() );
74 m_oneEightyDegreesChkCtrl->SetValue( m_constraintData->GetIsOneEightyDegreesAllowed() );
75 m_twoSeventyDegreesChkCtrl->SetValue( m_constraintData->GetIsTwoSeventyDegreesAllowed() );
76 m_allOrientationsChkCtrl->SetValue( m_constraintData->GetIsAllDegreesAllowed() );
77 }
78
79 return true;
80}
81
82
84{
85 m_constraintData->SetIsZeroDegreesAllowed( m_zeroDegreesChkCtrl->GetValue() );
86 m_constraintData->SetIsNinetyDegreesAllowed( m_ninetyDegreesChkCtrl->GetValue() );
87 m_constraintData->SetIsOneEightyDegreesAllowed( m_oneEightyDegreesChkCtrl->GetValue() );
88 m_constraintData->SetIsTwoSeventyDegreesAllowed( m_twoSeventyDegreesChkCtrl->GetValue() );
89 m_constraintData->SetIsAllDegreesAllowed( m_allOrientationsChkCtrl->GetValue() );
90
91 return true;
92}
93
95{
96 if( !m_zeroDegreesChkCtrl->IsChecked() || !m_ninetyDegreesChkCtrl->IsChecked()
97 || !m_oneEightyDegreesChkCtrl->IsChecked() || !m_twoSeventyDegreesChkCtrl->IsChecked() )
98 {
99 m_allOrientationsChkCtrl->SetValue( false );
100 }
101 else
102 {
103 m_allOrientationsChkCtrl->SetValue( true );
104 }
105}
106
108{
109 bool enable = false;
110
111 if( m_allOrientationsChkCtrl->IsChecked() )
112 {
113 enable = true;
114 }
115
116 m_zeroDegreesChkCtrl->SetValue( enable );
117 m_ninetyDegreesChkCtrl->SetValue( enable );
118 m_oneEightyDegreesChkCtrl->SetValue( enable );
119 m_twoSeventyDegreesChkCtrl->SetValue( enable );
120}
121
122
124 std::string* aValidationMessage )
125{
127
128 if( !result.isValid )
129 {
130 if( aErrorCount )
131 *aErrorCount += static_cast<int>( result.errors.size() );
132
133 if( aValidationMessage )
134 {
135 for( const std::string& error : result.errors )
136 {
137 if( !aValidationMessage->empty() )
138 *aValidationMessage += "\n";
139
140 *aValidationMessage += error;
141 }
142 }
143 }
144
145 return result.isValid;
146}
147
148
150{
151 if( !m_constraintData )
152 return wxEmptyString;
153
154 wxString code = m_constraintData->GetConstraintCode();
155
156 if( code.IsEmpty() )
157 code = wxS( "allowed_orientation" );
158
159 wxString clause;
160
161 if( m_constraintData->GetIsAllDegreesAllowed() )
162 {
163 clause = wxString::Format( wxS( "(constraint %s (any true))" ), code );
164 }
165 else
166 {
167 wxArrayString angles;
168
169 if( m_constraintData->GetIsZeroDegreesAllowed() )
170 angles.Add( wxS( "0" ) );
171 if( m_constraintData->GetIsNinetyDegreesAllowed() )
172 angles.Add( wxS( "90" ) );
173 if( m_constraintData->GetIsOneEightyDegreesAllowed() )
174 angles.Add( wxS( "180" ) );
175 if( m_constraintData->GetIsTwoSeventyDegreesAllowed() )
176 angles.Add( wxS( "270" ) );
177
178 if( angles.IsEmpty() )
179 clause = wxString::Format( wxS( "(constraint %s (angles none))" ), code );
180 else
181 clause = wxString::Format( wxS( "(constraint %s (angles %s))" ), code,
182 wxJoin( angles, ' ' ) );
183 }
184
185 wxLogTrace( wxS( "KI_TRACE_DRC_RULE_EDITOR" ), wxS( "Allowed orientation clause: %s" ), clause );
186
187 return buildRule( aContext, { clause } );
188}
@ constraint_allowed_orientation
DRC_RE_ALLOWED_ORIENTATION_PANEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 300), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void onAllOrientationCheckboxClicked(wxCommandEvent &aEvent)
DRC_RE_ALLOWED_ORIENTATION_PANEL(wxWindow *aParent, wxString *aConstraintTitle, std::shared_ptr< DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA > aConstraintData)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
bool ValidateInputs(int *aErrorCount, std::string *aValidationMessage) override
std::shared_ptr< DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA > m_constraintData
wxString buildRule(const RULE_GENERATION_CONTEXT &aContext, const std::vector< wxString > &aConstraintClauses) const
wxStaticBitmap * GetConstraintImage(wxPanel *aParent, BITMAPS aBitMap)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.