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, see <https://www.gnu.org/licenses/>.
18 */
19
23
25#include <wx/checkbox.h>
26
27
29 wxWindow* aParent, DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA* aData ) :
31 m_data( aData ),
32 m_zeroDegreesCheckbox( nullptr ),
33 m_ninetyDegreesCheckbox( nullptr ),
36 m_allDegreesCheckbox( nullptr )
37{
38 SetBackgroundBitmap( m_data->GetOverlayBitmap() );
39
40 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
41
42 DRC_RE_OVERLAY_FIELD* field = AddCheckbox( wxS( "zero_degrees" ), positions[0] );
43 m_zeroDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
44
45 field = AddCheckbox( wxS( "ninety_degrees" ), positions[1] );
46 m_ninetyDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
47
48 field = AddCheckbox( wxS( "one_eighty_degrees" ), positions[2] );
49 m_oneEightyDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
50
51 field = AddCheckbox( wxS( "two_seventy_degrees" ), positions[3] );
52 m_twoSeventyDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
53
54 field = AddCheckbox( wxS( "all_degrees" ), positions[4] );
55 m_allDegreesCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
56
57 auto notifyModified = [this]( wxCommandEvent& )
58 {
60 if( dlg )
61 dlg->SetModified();
62 };
63
64 auto onIndividualCheckbox = [this, notifyModified]( wxCommandEvent& evt )
65 {
66 bool allChecked = m_zeroDegreesCheckbox->GetValue() && m_ninetyDegreesCheckbox->GetValue()
67 && m_oneEightyDegreesCheckbox->GetValue() && m_twoSeventyDegreesCheckbox->GetValue();
68 m_allDegreesCheckbox->SetValue( allChecked );
69
70 notifyModified( evt );
71 };
72
73 auto onAllDegreesCheckbox = [this, notifyModified]( wxCommandEvent& evt )
74 {
75 bool checked = m_allDegreesCheckbox->GetValue();
76 m_zeroDegreesCheckbox->SetValue( checked );
77 m_ninetyDegreesCheckbox->SetValue( checked );
78 m_oneEightyDegreesCheckbox->SetValue( checked );
79 m_twoSeventyDegreesCheckbox->SetValue( checked );
80
81 notifyModified( evt );
82 };
83
84 m_zeroDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
85 m_ninetyDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
86 m_oneEightyDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
87 m_twoSeventyDegreesCheckbox->Bind( wxEVT_CHECKBOX, onIndividualCheckbox );
88 m_allDegreesCheckbox->Bind( wxEVT_CHECKBOX, onAllDegreesCheckbox );
89
92}
93
94
96{
99 {
100 return false;
101 }
102
103 m_zeroDegreesCheckbox->SetValue( m_data->GetIsZeroDegreesAllowed() );
104 m_ninetyDegreesCheckbox->SetValue( m_data->GetIsNinetyDegreesAllowed() );
105 m_oneEightyDegreesCheckbox->SetValue( m_data->GetIsOneEightyDegreesAllowed() );
106 m_twoSeventyDegreesCheckbox->SetValue( m_data->GetIsTwoSeventyDegreesAllowed() );
107 m_allDegreesCheckbox->SetValue( m_data->GetIsAllDegreesAllowed() );
108
109 return true;
110}
111
112
114{
117 {
118 return false;
119 }
120
121 m_data->SetIsZeroDegreesAllowed( m_zeroDegreesCheckbox->GetValue() );
122 m_data->SetIsNinetyDegreesAllowed( m_ninetyDegreesCheckbox->GetValue() );
123 m_data->SetIsOneEightyDegreesAllowed( m_oneEightyDegreesCheckbox->GetValue() );
124 m_data->SetIsTwoSeventyDegreesAllowed( m_twoSeventyDegreesCheckbox->GetValue() );
125 m_data->SetIsAllDegreesAllowed( m_zeroDegreesCheckbox->GetValue() && m_ninetyDegreesCheckbox->GetValue()
126 && m_oneEightyDegreesCheckbox->GetValue()
127 && m_twoSeventyDegreesCheckbox->GetValue() );
128
129 return true;
130}
131
132
134 wxString* aValidationMessage )
135{
137
138 VALIDATION_RESULT result = m_data->Validate();
139
140 if( !result.isValid )
141 {
142 *aErrorCount = result.errors.size();
143
144 for( size_t i = 0; i < result.errors.size(); i++ )
145 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
146
147 return false;
148 }
149
150 return true;
151}
152
153
155{
156 if( !m_data )
157 return wxEmptyString;
158
159 return m_data->GenerateRule( aContext );
160}
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.