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, 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
27
29#include <eda_base_frame.h>
30#include <base_units.h>
31#include <widgets/unit_binder.h>
32
33#include <wx/textctrl.h>
34
35
38 EDA_UNITS aUnits ) :
40 m_data( aData ),
42{
44
45 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
46
47 wxWindow* eventSource = nullptr;
48
49 for( wxWindow* win = aParent; win; win = win->GetParent() )
50 {
51 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
52 {
53 eventSource = win;
54 break;
55 }
56 }
57
58 auto* minTextHeightField = AddField<wxTextCtrl>( wxS( "min_text_height" ), positions[0], wxTE_PROCESS_ENTER );
60 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minTextHeightField->GetControl(),
61 minTextHeightField->GetLabel(), false, false );
62 minTextHeightField->SetUnitBinder( m_minTextHeightBinder.get() );
63
64 auto* minTextThicknessField = AddField<wxTextCtrl>( wxS( "min_text_thickness" ), positions[1], wxTE_PROCESS_ENTER );
66 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minTextThicknessField->GetControl(),
67 minTextThicknessField->GetLabel(), false, false );
68 minTextThicknessField->SetUnitBinder( m_minTextThicknessBinder.get() );
69
70 auto notifyModified = [this]( wxCommandEvent& )
71 {
73 if( dlg )
74 dlg->SetModified();
75 };
76
77 auto notifySave = [this]( wxCommandEvent& aEvent )
78 {
80 if( dlg )
81 dlg->OnSave( aEvent );
82 };
83
84 minTextHeightField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
85 minTextThicknessField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
86
87 minTextHeightField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
88 minTextThicknessField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
89
92}
93
94
96{
97 if( !m_data )
98 return false;
99
100 m_minTextHeightBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinTextHeight() ) );
101 m_minTextThicknessBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinTextThickness() ) );
102
103 return true;
104}
105
106
108{
109 if( !m_data )
110 return false;
111
112 m_data->SetMinTextHeight( pcbIUScale.IUTomm( m_minTextHeightBinder->GetDoubleValue() ) );
113 m_data->SetMinTextThickness( pcbIUScale.IUTomm( m_minTextThicknessBinder->GetDoubleValue() ) );
114
115 return true;
116}
117
118
120 wxString* aValidationMessage )
121{
123
124 VALIDATION_RESULT result = m_data->Validate();
125
126 if( !result.isValid )
127 {
128 *aErrorCount = result.errors.size();
129
130 for( size_t i = 0; i < result.errors.size(); i++ )
131 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
132
133 return false;
134 }
135
136 return true;
137}
138
139
141{
142 if( !m_data )
143 return wxEmptyString;
144
145 return m_data->GenerateRule( aContext );
146}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
@ 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.
void SetModified()
Marks the dialog as modified, indicating unsaved changes.
static RULE_EDITOR_DIALOG_BASE * GetDialog(wxWindow *aWindow)
Static method to retrieve the rule editor dialog instance associated with a given window.
virtual void OnSave(wxCommandEvent &aEvent)=0
Base window classes and related definitions.
EDA_UNITS
Definition eda_units.h:48
Result of a validation operation.
wxString result
Test unit parsing edge cases and error handling.