KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_bool_input_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
26
27#include <wx/log.h>
28
29
30const std::map<DRC_RULE_EDITOR_CONSTRAINT_NAME, BITMAPS> BoolConstraintBitMapPairs =
31{
33};
34
35
37 const DRC_RE_BOOL_INPUT_CONSTRAINT_PANEL_PARAMS& aConstraintPanelParams ) :
39 m_constraintData( aConstraintPanelParams.m_constraintData )
40{
41 auto it = BoolConstraintBitMapPairs.find( aConstraintPanelParams.m_constraintType );
42
43 bConstraintImageSizer->Add( GetConstraintImage( this, it->second ), 0, wxALL | wxEXPAND, 10 );
44
45 if( !aConstraintPanelParams.m_customLabelText.IsEmpty() )
46 m_boolConstraintChkCtrl->SetLabelText( aConstraintPanelParams.m_customLabelText );
47 else
48 m_boolConstraintChkCtrl->SetLabelText( aConstraintPanelParams.m_constraintTitle );
49}
50
51
55
56
58{
60 {
61 m_boolConstraintChkCtrl->SetValue( m_constraintData->GetBoolInputValue() );
62 }
63
64 return true;
65}
66
67
69{
70 m_constraintData->SetBoolInputValue( m_boolConstraintChkCtrl->GetValue() );
71 return true;
72}
73
74
75bool DRC_RE_BOOL_INPUT_PANEL::ValidateInputs( int* aErrorCount, std::string* aValidationMessage )
76{
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_constraintData )
97 return wxEmptyString;
98
99 wxString code = m_constraintData->GetConstraintCode();
100
101 if( code.IsEmpty() )
102 code = wxS( "boolean_constraint" );
103
104 const bool enabled = m_constraintData->GetBoolInputValue();
105 const wxString state = enabled ? wxS( "true" ) : wxS( "false" );
106
107 wxLogTrace( wxS( "KI_TRACE_DRC_RULE_EDITOR" ),
108 wxS( "Generating boolean constraint '%s' with state %s." ), code, state );
109
110 wxString clause = wxString::Format( wxS( "(constraint %s (enabled %s))" ), code, state );
111 return buildRule( aContext, { clause } );
112}
@ constraint_vias_under_smd
DRC_RE_BOOL_INPUT_PANEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
bool ValidateInputs(int *aErrorCount, std::string *aValidationMessage) override
DRC_RE_BOOL_INPUT_PANEL(wxWindow *aParent, const DRC_RE_BOOL_INPUT_CONSTRAINT_PANEL_PARAMS &aConstraintPanelParams)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
std::shared_ptr< DRC_RE_BOOL_INPUT_CONSTRAINT_DATA > m_constraintData
DRC_RULE_EDITOR_CONSTRAINT_NAME m_constraintType
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)
const std::map< DRC_RULE_EDITOR_CONSTRAINT_NAME, BITMAPS > BoolConstraintBitMapPairs
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.