KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_min_txt_ht_th_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
24
25#include <eda_base_frame.h>
26#include <base_units.h>
27#include <widgets/unit_binder.h>
28
29#include <wx/textctrl.h>
30
31
34 EDA_UNITS aUnits ) :
36 m_data( aData ),
38{
40
41 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
42
43 wxWindow* eventSource = nullptr;
44
45 for( wxWindow* win = aParent; win; win = win->GetParent() )
46 {
47 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
48 {
49 eventSource = win;
50 break;
51 }
52 }
53
54 auto* minTextHeightField = AddField<wxTextCtrl>( wxS( "min_text_height" ), positions[0], wxTE_CENTRE | wxTE_PROCESS_ENTER );
56 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minTextHeightField->GetControl(),
57 minTextHeightField->GetLabel(), false, false );
58 minTextHeightField->SetUnitBinder( m_minTextHeightBinder.get() );
59 minTextHeightField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
60
61 auto* minTextThicknessField = AddField<wxTextCtrl>( wxS( "min_text_thickness" ), positions[1], wxTE_CENTRE | wxTE_PROCESS_ENTER );
63 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minTextThicknessField->GetControl(),
64 minTextThicknessField->GetLabel(), false, false );
65 minTextThicknessField->SetUnitBinder( m_minTextThicknessBinder.get() );
66 minTextThicknessField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
67
70}
71
72
74{
75 if( !m_data )
76 return false;
77
78 // Use ChangeDoubleValue to avoid triggering modification events during loading
79 m_minTextHeightBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetMinTextHeight() ) );
80 m_minTextThicknessBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetMinTextThickness() ) );
81
82 return true;
83}
84
85
87{
88 if( !m_data )
89 return false;
90
91 m_data->SetMinTextHeight( pcbIUScale.IUTomm( m_minTextHeightBinder->GetDoubleValue() ) );
92 m_data->SetMinTextThickness( pcbIUScale.IUTomm( m_minTextThicknessBinder->GetDoubleValue() ) );
93
94 return true;
95}
96
97
99 wxString* aValidationMessage )
100{
102
103 VALIDATION_RESULT result = m_data->Validate();
104
105 if( !result.isValid )
106 {
107 *aErrorCount = result.errors.size();
108
109 for( size_t i = 0; i < result.errors.size(); i++ )
110 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
111
112 return false;
113 }
114
115 return true;
116}
117
118
120{
121 if( !m_data )
122 return wxEmptyString;
123
124 return m_data->GenerateRule( aContext );
125}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ constraint_minimum_text_height_and_thickness
DRC_RE_OVERLAY_FIELD * AddField(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, long aStyle=0)
Create and position a field 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.
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RE_MIN_TXT_HT_TH_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_MINIMUM_TEXT_HEIGHT_THICKNESS_CONSTRAINT_DATA *aData, EDA_UNITS aUnits)
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_MINIMUM_TEXT_HEIGHT_THICKNESS_CONSTRAINT_DATA * m_data
std::unique_ptr< UNIT_BINDER > m_minTextThicknessBinder
static wxString FormatErrorMessage(int aErrorCount, const wxString &aErrorMessage)
The base frame for deriving all KiCad main window classes.
Base window classes and related definitions.
EDA_UNITS
Definition eda_units.h:45
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.