KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_permitted_layers_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/log.h>
27
28
29DRC_RE_PERMITTED_LAYERS_PANEL::DRC_RE_PERMITTED_LAYERS_PANEL( wxWindow* aParent, wxString* aConstraintTitle,
30 std::shared_ptr<DRC_RE_PERMITTED_LAYERS_CONSTRAINT_DATA> aConstraintData ) :
31 DRC_RE_PERMITTED_LAYERS_PANEL_BASE( aParent ), m_constraintData( aConstraintData )
32{
34 wxALL | wxEXPAND, 10 );
35}
36
37
41
42
44{
46 {
47 m_topLayerChkCtrl->SetValue( m_constraintData->GetTopLayerEnabled() );
48 m_bottomLayerChkCtrl->SetValue( m_constraintData->GetBottomLayerEnabled() );
49 }
50
51 return true;
52}
53
54
56{
57 m_constraintData->SetTopLayerEnabled( m_topLayerChkCtrl->GetValue() );
58 m_constraintData->SetBottomLayerEnabled( m_bottomLayerChkCtrl->GetValue() );
59 return true;
60}
61
62
64 std::string* aValidationMessage )
65{
68
69 if( !result.isValid )
70 {
71 *aErrorCount = result.errors.size();
72
73 for( size_t i = 0; i < result.errors.size(); i++ )
74 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
75
76 return false;
77 }
78
79 return true;
80}
81
82
84{
85 if( !m_constraintData )
86 return wxEmptyString;
87
88 wxString code = m_constraintData->GetConstraintCode();
89
90 if( code.IsEmpty() )
91 code = wxS( "permitted_layers" );
92
93 const wxString topState = m_constraintData->GetTopLayerEnabled() ? wxS( "true" ) : wxS( "false" );
94 const wxString bottomState = m_constraintData->GetBottomLayerEnabled() ? wxS( "true" ) : wxS( "false" );
95
96 wxString clause = wxString::Format( wxS( "(constraint %s (top %s) (bottom %s))" ), code,
97 topState, bottomState );
98
99 wxLogTrace( wxS( "KI_TRACE_DRC_RULE_EDITOR" ), wxS( "Permitted layers clause: %s" ), clause );
100
101 return buildRule( aContext, { clause } );
102}
@ constraint_permitted_layers
DRC_RE_PERMITTED_LAYERS_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)
std::shared_ptr< DRC_RE_PERMITTED_LAYERS_CONSTRAINT_DATA > m_constraintData
DRC_RE_PERMITTED_LAYERS_PANEL(wxWindow *aParent, wxString *aConstraintTitle, std::shared_ptr< DRC_RE_PERMITTED_LAYERS_CONSTRAINT_DATA > aConstraintData)
bool ValidateInputs(int *aErrorCount, std::string *aValidationMessage) override
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
wxString buildRule(const RULE_GENERATION_CONTEXT &aContext, const std::vector< wxString > &aConstraintClauses) const
wxStaticBitmap * GetConstraintImage(wxPanel *aParent, BITMAPS aBitMap)
static std::string FormatErrorMessage(const int &aErrorCount, const std::string aErrorMessage)
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.