KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_via_style_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
37 wxWindow* aParent, DRC_RE_VIA_STYLE_CONSTRAINT_DATA* aData, EDA_UNITS aUnits ) :
39 m_data( aData ),
41{
43
44 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
45
46 wxWindow* eventSource = nullptr;
47
48 for( wxWindow* win = aParent; win; win = win->GetParent() )
49 {
50 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
51 {
52 eventSource = win;
53 break;
54 }
55 }
56
57 // Create via diameter fields (min/pref/max)
58 auto* minViaDiameterField = AddField<wxTextCtrl>( wxS( "min_via_diameter" ), positions[0], wxTE_PROCESS_ENTER );
60 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minViaDiameterField->GetControl(),
61 minViaDiameterField->GetLabel(), false, false );
62 minViaDiameterField->SetUnitBinder( m_minViaDiameterBinder.get() );
63
64 auto* prefViaDiameterField = AddField<wxTextCtrl>( wxS( "pref_via_diameter" ), positions[1], wxTE_PROCESS_ENTER );
66 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, prefViaDiameterField->GetControl(),
67 prefViaDiameterField->GetLabel(), false, false );
68 prefViaDiameterField->SetUnitBinder( m_prefViaDiameterBinder.get() );
69
70 auto* maxViaDiameterField = AddField<wxTextCtrl>( wxS( "max_via_diameter" ), positions[2], wxTE_PROCESS_ENTER );
72 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxViaDiameterField->GetControl(),
73 maxViaDiameterField->GetLabel(), false, false );
74 maxViaDiameterField->SetUnitBinder( m_maxViaDiameterBinder.get() );
75
76 // Create via hole size fields (min/pref/max)
77 auto* minViaHoleField = AddField<wxTextCtrl>( wxS( "min_via_hole" ), positions[3], wxTE_PROCESS_ENTER );
79 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minViaHoleField->GetControl(),
80 minViaHoleField->GetLabel(), false, false );
81 minViaHoleField->SetUnitBinder( m_minViaHoleSizeBinder.get() );
82
83 auto* prefViaHoleField = AddField<wxTextCtrl>( wxS( "pref_via_hole" ), positions[4], wxTE_PROCESS_ENTER );
85 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, prefViaHoleField->GetControl(),
86 prefViaHoleField->GetLabel(), false, false );
87 prefViaHoleField->SetUnitBinder( m_prefViaHoleSizeBinder.get() );
88
89 auto* maxViaHoleField = AddField<wxTextCtrl>( wxS( "max_via_hole" ), positions[5], wxTE_PROCESS_ENTER );
91 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxViaHoleField->GetControl(),
92 maxViaHoleField->GetLabel(), false, false );
93 maxViaHoleField->SetUnitBinder( m_maxViaHoleSizeBinder.get() );
94
95 auto notifyModified = [this]( wxCommandEvent& )
96 {
98 if( dlg )
99 dlg->SetModified();
100 };
101
102 auto notifySave = [this]( wxCommandEvent& aEvent )
103 {
105 if( dlg )
106 dlg->OnSave( aEvent );
107 };
108
109 minViaDiameterField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
110 maxViaDiameterField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
111 prefViaDiameterField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
112 minViaHoleField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
113 maxViaHoleField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
114 prefViaHoleField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
115
116 minViaDiameterField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
117 maxViaDiameterField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
118 prefViaDiameterField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
119 minViaHoleField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
120 maxViaHoleField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
121 prefViaHoleField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
122
123 // Position all fields and update the panel layout
126}
127
128
130{
131 if( !m_data )
132 return false;
133
134 // Convert mm values to internal units and set them in the unit binders
135 m_minViaDiameterBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinViaDiameter() ) );
136 m_prefViaDiameterBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetPreferredViaDiameter() ) );
137 m_maxViaDiameterBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxViaDiameter() ) );
138
139 m_minViaHoleSizeBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinViaHoleSize() ) );
140 m_prefViaHoleSizeBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetPreferredViaHoleSize() ) );
141 m_maxViaHoleSizeBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxViaHoleSize() ) );
142
143 return true;
144}
145
146
148{
149 if( !m_data )
150 return false;
151
152 // Read values from unit binders and convert from internal units to mm
153 m_data->SetMinViaDiameter( pcbIUScale.IUTomm( m_minViaDiameterBinder->GetDoubleValue() ) );
154 m_data->SetPreferredViaDiameter( pcbIUScale.IUTomm( m_prefViaDiameterBinder->GetDoubleValue() ) );
155 m_data->SetMaxViaDiameter( pcbIUScale.IUTomm( m_maxViaDiameterBinder->GetDoubleValue() ) );
156
157 m_data->SetMinViaHoleSize( pcbIUScale.IUTomm( m_minViaHoleSizeBinder->GetDoubleValue() ) );
158 m_data->SetPreferredViaHoleSize( pcbIUScale.IUTomm( m_prefViaHoleSizeBinder->GetDoubleValue() ) );
159 m_data->SetMaxViaHoleSize( pcbIUScale.IUTomm( m_maxViaHoleSizeBinder->GetDoubleValue() ) );
160
161 return true;
162}
163
164
165bool DRC_RE_VIA_STYLE_OVERLAY_PANEL::ValidateInputs( int* aErrorCount, wxString* aValidationMessage )
166{
168
169 VALIDATION_RESULT result = m_data->Validate();
170
171 if( !result.isValid )
172 {
173 *aErrorCount = result.errors.size();
174
175 for( size_t i = 0; i < result.errors.size(); i++ )
176 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
177
178 return false;
179 }
180
181 return true;
182}
183
184
186{
187 if( !m_data )
188 return wxEmptyString;
189
190 return m_data->GenerateRule( aContext );
191}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
@ constraint_via_style
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.
std::unique_ptr< UNIT_BINDER > m_maxViaDiameterBinder
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_VIA_STYLE_CONSTRAINT_DATA * m_data
std::unique_ptr< UNIT_BINDER > m_minViaHoleSizeBinder
std::unique_ptr< UNIT_BINDER > m_prefViaDiameterBinder
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RE_VIA_STYLE_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_VIA_STYLE_CONSTRAINT_DATA *aData, EDA_UNITS aUnits)
std::unique_ptr< UNIT_BINDER > m_minViaDiameterBinder
std::unique_ptr< UNIT_BINDER > m_maxViaHoleSizeBinder
std::unique_ptr< UNIT_BINDER > m_prefViaHoleSizeBinder
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.