KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_permitted_layers_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_PERMITTED_LAYERS_CONSTRAINT_DATA* aData ) :
30 m_data( aData ),
31 m_topLayerCheckbox( nullptr ),
32 m_bottomLayerCheckbox( nullptr )
33{
34 SetBackgroundBitmap( m_data->GetOverlayBitmap() );
35
36 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
37
38 DRC_RE_OVERLAY_FIELD* topField = AddCheckbox( wxS( "top_layer" ), positions[0] );
39 m_topLayerCheckbox = static_cast<wxCheckBox*>( topField->GetControl() );
40
41 DRC_RE_OVERLAY_FIELD* bottomField = AddCheckbox( wxS( "bottom_layer" ), positions[1] );
42 m_bottomLayerCheckbox = static_cast<wxCheckBox*>( bottomField->GetControl() );
43
46}
47
48
50{
52 return false;
53
54 m_topLayerCheckbox->SetValue( m_data->GetTopLayerEnabled() );
55 m_bottomLayerCheckbox->SetValue( m_data->GetBottomLayerEnabled() );
56
57 return true;
58}
59
60
62{
64 return false;
65
66 m_data->SetTopLayerEnabled( m_topLayerCheckbox->GetValue() );
67 m_data->SetBottomLayerEnabled( m_bottomLayerCheckbox->GetValue() );
68
69 return true;
70}
71
72
74 wxString* aValidationMessage )
75{
77
78 VALIDATION_RESULT result = m_data->Validate();
79
80 if( !result.isValid )
81 {
82 *aErrorCount = result.errors.size();
83
84 for( size_t i = 0; i < result.errors.size(); i++ )
85 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
86
87 return false;
88 }
89
90 return true;
91}
92
93
95{
96 if( !m_data )
97 return wxEmptyString;
98
99 return m_data->GenerateRule( aContext );
100}
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
DRC_RE_PERMITTED_LAYERS_CONSTRAINT_DATA * m_data
DRC_RE_PERMITTED_LAYERS_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_PERMITTED_LAYERS_CONSTRAINT_DATA *aData)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
static wxString FormatErrorMessage(int aErrorCount, const wxString &aErrorMessage)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.