KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_rtg_diff_pair_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
28
29#include <base_units.h>
30#include <eda_base_frame.h>
31#include <widgets/unit_binder.h>
32
33#include <wx/textctrl.h>
34
35
37 wxWindow* aParent,
39 EDA_UNITS aUnits ) :
41 m_data( aData ),
43{
45
46 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
47
48 wxWindow* eventSource = nullptr;
49
50 for( wxWindow* win = aParent; win; win = win->GetParent() )
51 {
52 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
53 {
54 eventSource = win;
55 break;
56 }
57 }
58
59 auto* minWidthField = AddField<wxTextCtrl>( wxS( "min_width" ), positions[0], wxTE_CENTRE | wxTE_PROCESS_ENTER );
61 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minWidthField->GetControl(),
62 minWidthField->GetLabel(), false, false );
63 minWidthField->SetUnitBinder( m_minWidthBinder.get() );
64
65 auto* prefWidthField = AddField<wxTextCtrl>( wxS( "pref_width" ), positions[1],
66 wxTE_CENTRE | wxTE_PROCESS_ENTER );
68 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, prefWidthField->GetControl(),
69 prefWidthField->GetLabel(), false, false );
70 prefWidthField->SetUnitBinder( m_preferredWidthBinder.get() );
71
72 auto* maxWidthField = AddField<wxTextCtrl>( wxS( "max_width" ), positions[2],
73 wxTE_CENTRE | wxTE_PROCESS_ENTER );
75 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxWidthField->GetControl(),
76 maxWidthField->GetLabel(), false, false );
77 maxWidthField->SetUnitBinder( m_maxWidthBinder.get() );
78
79 // Create gap fields (min/pref/max) — positions[3..5]
80 auto* minGapField = AddField<wxTextCtrl>( wxS( "min_gap" ), positions[3],
81 wxTE_CENTRE | wxTE_PROCESS_ENTER );
82 m_minGapBinder = std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minGapField->GetControl(),
83 minGapField->GetLabel(), false, false );
84 minGapField->SetUnitBinder( m_minGapBinder.get() );
85
86 auto* prefGapField = AddField<wxTextCtrl>( wxS( "pref_gap" ), positions[4],
87 wxTE_CENTRE | wxTE_PROCESS_ENTER );
89 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, prefGapField->GetControl(),
90 prefGapField->GetLabel(), false, false );
91 prefGapField->SetUnitBinder( m_preferredGapBinder.get() );
92
93 auto* maxGapField = AddField<wxTextCtrl>( wxS( "max_gap" ), positions[5],
94 wxTE_CENTRE | wxTE_PROCESS_ENTER );
95 m_maxGapBinder = std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxGapField->GetControl(),
96 maxGapField->GetLabel(), false, false );
97 maxGapField->SetUnitBinder( m_maxGapBinder.get() );
98
99 // Create max uncoupled length field — positions[6]
100 auto* maxUncoupledField = AddField<wxTextCtrl>( wxS( "max_uncoupled" ), positions[6],
101 wxTE_CENTRE | wxTE_PROCESS_ENTER );
103 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxUncoupledField->GetControl(),
104 maxUncoupledField->GetLabel(), false, false );
105 maxUncoupledField->SetUnitBinder( m_maxUncoupledLengthBinder.get() );
106
107 auto* maxSkewField = AddField<wxTextCtrl>( wxS( "max_skew" ), positions[7], wxTE_CENTRE | wxTE_PROCESS_ENTER );
108 m_maxSkewBinder = std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxSkewField->GetControl(),
109 maxSkewField->GetLabel(), false, false );
110 maxSkewField->SetUnitBinder( m_maxSkewBinder.get() );
111
112 auto notifyModified = [this]( wxCommandEvent& )
113 {
115 if( dlg )
116 dlg->SetModified();
117 };
118
119 minWidthField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
120 prefWidthField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
121 maxWidthField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
122 minGapField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
123 prefGapField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
124 maxGapField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
125 maxUncoupledField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
126 maxSkewField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
127
128 auto notifySave = [this]( wxCommandEvent& aEvent )
129 {
131 if( dlg )
132 dlg->OnSave( aEvent );
133 };
134
135 minWidthField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
136 prefWidthField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
137 maxWidthField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
138 minGapField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
139 prefGapField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
140 maxGapField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
141 maxUncoupledField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
142 maxSkewField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
143
144 // Position all fields and update the panel layout
147}
148
149
151{
152 if( !m_data )
153 return false;
154
155 // Convert mm values to internal units and set them in the binders
156 m_minGapBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinGap() ) );
157 m_preferredGapBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetPreferredGap() ) );
158 m_maxGapBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxGap() ) );
159
160 m_minWidthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinWidth() ) );
161 m_preferredWidthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetPreferredWidth() ) );
162 m_maxWidthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxWidth() ) );
163
164 m_maxUncoupledLengthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxUncoupledLength() ) );
165 m_maxSkewBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxSkew() ) );
166
167 return true;
168}
169
170
172{
173 if( !m_data )
174 return false;
175
176 // Read values from binders (in internal units) and convert to mm for storage
177 m_data->SetMinGap( pcbIUScale.IUTomm( m_minGapBinder->GetDoubleValue() ) );
178 m_data->SetPreferredGap( pcbIUScale.IUTomm( m_preferredGapBinder->GetDoubleValue() ) );
179 m_data->SetMaxGap( pcbIUScale.IUTomm( m_maxGapBinder->GetDoubleValue() ) );
180
181 m_data->SetMinWidth( pcbIUScale.IUTomm( m_minWidthBinder->GetDoubleValue() ) );
182 m_data->SetPreferredWidth( pcbIUScale.IUTomm( m_preferredWidthBinder->GetDoubleValue() ) );
183 m_data->SetMaxWidth( pcbIUScale.IUTomm( m_maxWidthBinder->GetDoubleValue() ) );
184
185 m_data->SetMaxUncoupledLength( pcbIUScale.IUTomm( m_maxUncoupledLengthBinder->GetDoubleValue() ) );
186 m_data->SetMaxSkew( pcbIUScale.IUTomm( m_maxSkewBinder->GetDoubleValue() ) );
187
188 return true;
189}
190
191
193 wxString* aValidationMessage )
194{
196
197 VALIDATION_RESULT result = m_data->Validate();
198
199 if( !result.isValid )
200 {
201 *aErrorCount = result.errors.size();
202
203 for( size_t i = 0; i < result.errors.size(); i++ )
204 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
205
206 return false;
207 }
208
209 return true;
210}
211
212
214{
215 if( !m_data )
216 return wxEmptyString;
217
218 return m_data->GenerateRule( aContext );
219}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
@ constraint_routing_diff_pair
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.
DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA * m_data
DRC_RE_ROUTING_DIFF_PAIR_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA *aData, EDA_UNITS aUnits)
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
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.