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, see <https://www.gnu.org/licenses/>.
18 */
19
23
24#include <eda_base_frame.h>
25#include <base_units.h>
26#include <widgets/unit_binder.h>
27
28#include <wx/textctrl.h>
29#include <wx/choice.h>
30#include <wx/stattext.h>
31
33 wxWindow* aParent, DRC_RE_VIA_STYLE_CONSTRAINT_DATA* aData, EDA_UNITS aUnits ) :
35 m_data( aData ),
37{
39
40 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
41
42 wxWindow* eventSource = nullptr;
43
44 for( wxWindow* win = aParent; win; win = win->GetParent() )
45 {
46 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
47 {
48 eventSource = win;
49 break;
50 }
51 }
52
53 // Via type dropdown
54 wxArrayString choices;
55 choices.Add( _( "Any" ) );
56 choices.Add( _( "Through" ) );
57 choices.Add( _( "Micro" ) );
58 choices.Add( _( "Blind" ) );
59 choices.Add( _( "Buried" ) );
60
61 m_viaTypeChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices );
62 m_viaTypeChoice->SetSelection( static_cast<int>( m_data->GetViaType() ) );
63
64 AddControl( wxS( "via_type" ), positions[4], m_viaTypeChoice );
65
66 // Create via diameter fields (min/max)
67 auto* minViaDiameterField =
68 AddField<wxTextCtrl>( wxS( "min_via_diameter" ), positions[0], wxTE_PROCESS_ENTER | wxTE_CENTRE );
70 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minViaDiameterField->GetControl(),
71 minViaDiameterField->GetLabel(), false, false );
72 minViaDiameterField->SetUnitBinder( m_minViaDiameterBinder.get() );
73
74 auto* maxViaDiameterField =
75 AddField<wxTextCtrl>( wxS( "max_via_diameter" ), positions[1], wxTE_PROCESS_ENTER | wxTE_CENTRE );
77 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxViaDiameterField->GetControl(),
78 maxViaDiameterField->GetLabel(), false, false );
79 maxViaDiameterField->SetUnitBinder( m_maxViaDiameterBinder.get() );
80
81 // Create via hole size fields (min/max)
82 auto* minViaHoleField =
83 AddField<wxTextCtrl>( wxS( "min_via_hole" ), positions[2], wxTE_PROCESS_ENTER | wxTE_CENTRE );
85 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minViaHoleField->GetControl(),
86 minViaHoleField->GetLabel(), false, false );
87 minViaHoleField->SetUnitBinder( m_minViaHoleSizeBinder.get() );
88
89 auto* maxViaHoleField =
90 AddField<wxTextCtrl>( wxS( "max_via_hole" ), positions[3], wxTE_PROCESS_ENTER | wxTE_CENTRE );
92 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxViaHoleField->GetControl(),
93 maxViaHoleField->GetLabel(), false, false );
94 maxViaHoleField->SetUnitBinder( m_maxViaHoleSizeBinder.get() );
95
96
97 // Position all fields and update the panel layout
100}
101
102
104{
105 if( !m_data )
106 return false;
107
108 // Convert mm values to internal units and set them in the unit binders
109 // Use ChangeDoubleValue to avoid triggering modification events during loading
110 auto show = []( UNIT_BINDER* aBinder, double aMM )
111 {
112 // An open end is shown as an empty field, not as zero.
113 if( aMM > 0 )
114 aBinder->ChangeDoubleValue( pcbIUScale.mmToIU( aMM ) );
115 else
116 aBinder->ChangeValue( wxEmptyString );
117 };
118
119 show( m_minViaDiameterBinder.get(), m_data->GetMinViaDiameter() );
120 show( m_maxViaDiameterBinder.get(), m_data->GetMaxViaDiameter() );
121 show( m_minViaHoleSizeBinder.get(), m_data->GetMinViaHoleSize() );
122 show( m_maxViaHoleSizeBinder.get(), m_data->GetMaxViaHoleSize() );
123
124 m_viaTypeChoice->SetSelection( static_cast<int>( m_data->GetViaType() ) );
125
126 return true;
127}
128
129
131{
132 if( !m_data )
133 return false;
134
135 // Read values from unit binders and convert from internal units to mm
136 m_data->SetMinViaDiameter( pcbIUScale.IUTomm( m_minViaDiameterBinder->GetDoubleValue() ) );
137 m_data->SetMaxViaDiameter( pcbIUScale.IUTomm( m_maxViaDiameterBinder->GetDoubleValue() ) );
138
139 m_data->SetMinViaHoleSize( pcbIUScale.IUTomm( m_minViaHoleSizeBinder->GetDoubleValue() ) );
140 m_data->SetMaxViaHoleSize( pcbIUScale.IUTomm( m_maxViaHoleSizeBinder->GetDoubleValue() ) );
141
142 m_data->SetViaType( static_cast<VIA_STYLE_TYPE>( m_viaTypeChoice->GetSelection() ) );
143
144 return true;
145}
146
147
148bool DRC_RE_VIA_STYLE_OVERLAY_PANEL::ValidateInputs( int* aErrorCount, wxString* aValidationMessage )
149{
151
152 VALIDATION_RESULT result = m_data->Validate();
153
154 if( !result.isValid )
155 {
156 *aErrorCount = result.errors.size();
157
158 for( size_t i = 0; i < result.errors.size(); i++ )
159 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
160
161 return false;
162 }
163
164 return true;
165}
166
167
169{
170 if( !m_data )
171 return wxEmptyString;
172
173 return m_data->GenerateRule( aContext );
174}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ constraint_via_style
DRC_RE_OVERLAY_FIELD * AddControl(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition, T *aControl)
Position a control on the bitmap overlay.
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
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
static wxString FormatErrorMessage(int aErrorCount, const wxString &aErrorMessage)
The base frame for deriving all KiCad main window classes.
virtual void ChangeDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
#define _(s)
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.