KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_bool_input_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
24#include <wx/checkbox.h>
25
26
28 wxWindow* aParent, DRC_RE_BOOL_INPUT_CONSTRAINT_DATA* aData ) :
30 m_data( aData ),
31 m_boolInputCheckbox( nullptr )
32{
33 SetBackgroundBitmap( m_data->GetOverlayBitmap() );
34
35 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
36
37 DRC_RE_OVERLAY_FIELD* field = AddCheckbox( wxS( "bool_input" ), positions[0] );
38 m_boolInputCheckbox = static_cast<wxCheckBox*>( field->GetControl() );
39
42}
43
44
46{
48 return false;
49
50 m_boolInputCheckbox->SetValue( m_data->GetBoolInputValue() );
51
52 return true;
53}
54
55
57{
59 return false;
60
61 m_data->SetBoolInputValue( m_boolInputCheckbox->GetValue() );
62
63 return true;
64}
65
66
68 wxString* aValidationMessage )
69{
71
72 VALIDATION_RESULT result = m_data->Validate();
73
74 if( !result.isValid )
75 {
76 *aErrorCount = result.errors.size();
77
78 for( size_t i = 0; i < result.errors.size(); i++ )
79 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
80
81 return false;
82 }
83
84 return true;
85}
86
87
89{
90 if( !m_data )
91 return wxEmptyString;
92
93 return m_data->GenerateRule( aContext );
94}
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.
DRC_RE_BOOL_INPUT_CONSTRAINT_DATA * m_data
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_BOOL_INPUT_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_BOOL_INPUT_CONSTRAINT_DATA *aData)
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
Wraps a wxControl positioned over a bitmap overlay panel.
wxControl * GetControl() const
static wxString FormatErrorMessage(int aErrorCount, const wxString &aErrorMessage)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.