KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_allowed_orientation_overlay_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
27
29#include <wx/checkbox.h>
30
31
33 wxWindow* aParent, DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA* aData ) :
35 m_data( aData ),
36 m_zeroDegreesCheckbox( nullptr ),
37 m_ninetyDegreesCheckbox( nullptr ),
40 m_allDegreesCheckbox( nullptr )
41{
42 SetBackgroundBitmap( m_data->GetOverlayBitmap() );
43
44 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
45
46 DRC_RE_OVERLAY_FIELD* field = AddCheckbox( wxS( "zero_degrees" ), positions[0] );
47 m_zeroDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
48
49 field = AddCheckbox( wxS( "ninety_degrees" ), positions[1] );
50 m_ninetyDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
51
52 field = AddCheckbox( wxS( "one_eighty_degrees" ), positions[2] );
53 m_oneEightyDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
54
55 field = AddCheckbox( wxS( "two_seventy_degrees" ), positions[3] );
56 m_twoSeventyDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
57
58 field = AddCheckbox( wxS( "all_degrees" ), positions[4] );
59 m_allDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
60
61 auto notifyModified = [this]( wxCommandEvent& )
62 {
64 if( dlg )
65 dlg->SetModified();
66 };
67
68 auto onIndividualCheckbox = [this, notifyModified]( wxCommandEvent& evt )
69 {
70 bool allChecked = m_zeroDegreesCheckbox->GetValue() && m_ninetyDegreesCheckbox->GetValue()
71 && m_oneEightyDegreesCheckbox->GetValue() && m_twoSeventyDegreesCheckbox->GetValue();
72 m_allDegreesCheckbox->SetValue( allChecked );
73
74 notifyModified( evt );
75 };
76
77 auto onAllDegreesCheckbox = [this, notifyModified]( wxCommandEvent& evt )
78 {
79 bool checked = m_allDegreesCheckbox->GetValue();
80 m_zeroDegreesCheckbox->SetValue( checked );
81 m_ninetyDegreesCheckbox->SetValue( checked );
82 m_oneEightyDegreesCheckbox->SetValue( checked );
83 m_twoSeventyDegreesCheckbox->SetValue( checked );
84
85 notifyModified( evt );
86 };
87
88 m_zeroDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
89 m_ninetyDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
90 m_oneEightyDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
91 m_twoSeventyDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
92 m_allDegreesCheckbox->Bind( wxEVT_CHECKBOX, onAllDegreesCheckbox );
93
96}
97
98
100{
103 {
104 return false;
105 }
106
107 m_zeroDegreesCheckbox->SetValue( m_data->GetIsZeroDegreesAllowed() );
108 m_ninetyDegreesCheckbox->SetValue( m_data->GetIsNinetyDegreesAllowed() );
109 m_oneEightyDegreesCheckbox->SetValue( m_data->GetIsOneEightyDegreesAllowed() );
110 m_twoSeventyDegreesCheckbox->SetValue( m_data->GetIsTwoSeventyDegreesAllowed() );
111 m_allDegreesCheckbox->SetValue( m_data->GetIsAllDegreesAllowed() );
112
113 return true;
114}
115
116
118{
121 {
122 return false;
123 }
124
125 m_data->SetIsZeroDegreesAllowed( m_zeroDegreesCheckbox->GetValue() );
126 m_data->SetIsNinetyDegreesAllowed( m_ninetyDegreesCheckbox->GetValue() );
127 m_data->SetIsOneEightyDegreesAllowed( m_oneEightyDegreesCheckbox->GetValue() );
128 m_data->SetIsTwoSeventyDegreesAllowed( m_twoSeventyDegreesCheckbox->GetValue() );
129 m_data->SetIsAllDegreesAllowed( m_zeroDegreesCheckbox->GetValue() && m_ninetyDegreesCheckbox->GetValue()
130 && m_oneEightyDegreesCheckbox->GetValue()
131 && m_twoSeventyDegreesCheckbox->GetValue() );
132
133 return true;
134}
135
136
138 wxString* aValidationMessage )
139{
141
142 VALIDATION_RESULT result = m_data->Validate();
143
144 if( !result.isValid )
145 {
146 *aErrorCount = result.errors.size();
147
148 for( size_t i = 0; i < result.errors.size(); i++ )
149 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
150
151 return false;
152 }
153
154 return true;
155}
156
157
159{
160 if( !m_data )
161 return wxEmptyString;
162
163 return m_data->GenerateRule( aContext );
164}
DRC_RE_ALLOWED_ORIENTATION_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA *aData)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA * m_data
DRC_RE_OVERLAY_FIELD * AddCheckbox(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition)
Create and position a checkbox control on the bitmap overlay.
void SetBackgroundBitmap(BITMAPS aBitmap)
Set the background bitmap for this panel.
DRC_RE_BITMAP_OVERLAY_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY)
void PositionFields()
Position all fields based on the current scale factor.
Wraps a wxControl positioned over a bitmap overlay panel.
wxControl * GetControl() const
static wxString FormatErrorMessage(int aErrorCount, const wxString &aErrorMessage)
void SetModified()
Marks the dialog as modified, indicating unsaved changes.
static RULE_EDITOR_DIALOG_BASE * GetDialog(wxWindow *aWindow)
Static method to retrieve the rule editor dialog instance associated with a given window.
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.