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, see <https://www.gnu.org/licenses/>.
18 */
19
23
24#include <base_units.h>
25#include <eda_base_frame.h>
26#include <widgets/unit_binder.h>
27
28#include <wx/textctrl.h>
29#include <wx/stattext.h>
30
31
33 wxWindow* aParent,
35 EDA_UNITS aUnits ) :
37 m_data( aData ),
39{
41
42 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
43
44 wxWindow* eventSource = nullptr;
45
46 for( wxWindow* win = aParent; win; win = win->GetParent() )
47 {
48 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
49 {
50 eventSource = win;
51 break;
52 }
53 }
54
55 auto* optWidthField = AddField<wxTextCtrl>( wxS( "opt_width" ), positions[0], wxTE_CENTRE | wxTE_PROCESS_ENTER );
57 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, optWidthField->GetControl(),
58 optWidthField->GetLabel(), false, false );
59 optWidthField->SetUnitBinder( m_optWidthBinder.get() );
60
61 auto* widthTolField =
62 AddField<wxTextCtrl>( wxS( "width_tolerance" ), positions[1], wxTE_CENTRE | wxTE_PROCESS_ENTER );
64 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, widthTolField->GetControl(),
65 widthTolField->GetLabel(), false, false );
66 widthTolField->SetUnitBinder( m_widthToleranceBinder.get() );
67
68 auto* optGapField = AddField<wxTextCtrl>( wxS( "opt_gap" ), positions[2], wxTE_CENTRE | wxTE_PROCESS_ENTER );
69 m_optGapBinder = std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, optGapField->GetControl(),
70 optGapField->GetLabel(), false, false );
71 optGapField->SetUnitBinder( m_optGapBinder.get() );
72
73 auto* gapTolField = AddField<wxTextCtrl>( wxS( "gap_tolerance" ), positions[3], wxTE_CENTRE | wxTE_PROCESS_ENTER );
74 m_gapToleranceBinder = std::make_unique<UNIT_BINDER>(
75 &m_unitsProvider, eventSource, nullptr, gapTolField->GetControl(), gapTolField->GetLabel(), false, false );
76 gapTolField->SetUnitBinder( m_gapToleranceBinder.get() );
77
78 auto* maxUncoupledField =
79 AddField<wxTextCtrl>( wxS( "max_uncoupled" ), positions[4], wxTE_CENTRE | wxTE_PROCESS_ENTER );
81 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxUncoupledField->GetControl(),
82 maxUncoupledField->GetLabel(), false, false );
83 maxUncoupledField->SetUnitBinder( m_maxUncoupledLengthBinder.get() );
84
85
86 // Position all fields and update the panel layout
89}
90
91
93{
94 if( !m_data )
95 return false;
96
97 // Convert mm values to internal units and set them in the binders
98 // Use ChangeDoubleValue to avoid triggering modification events during loading
99 m_optWidthBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetOptWidth() ) );
100 m_widthToleranceBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetWidthTolerance() ) );
101
102 m_optGapBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetOptGap() ) );
103 m_gapToleranceBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetGapTolerance() ) );
104
105 m_maxUncoupledLengthBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxUncoupledLength() ) );
106
107 return true;
108}
109
110
112{
113 if( !m_data )
114 return false;
115
116 // Read values from binders (in internal units) and convert to mm for storage
117 m_data->SetOptWidth( pcbIUScale.IUTomm( m_optWidthBinder->GetDoubleValue() ) );
118 m_data->SetWidthTolerance( pcbIUScale.IUTomm( m_widthToleranceBinder->GetDoubleValue() ) );
119
120 m_data->SetOptGap( pcbIUScale.IUTomm( m_optGapBinder->GetDoubleValue() ) );
121 m_data->SetGapTolerance( pcbIUScale.IUTomm( m_gapToleranceBinder->GetDoubleValue() ) );
122
123 m_data->SetMaxUncoupledLength( pcbIUScale.IUTomm( m_maxUncoupledLengthBinder->GetDoubleValue() ) );
124
125 return true;
126}
127
128
130 wxString* aValidationMessage )
131{
133
134 VALIDATION_RESULT result = m_data->Validate();
135
136 if( !result.isValid )
137 {
138 *aErrorCount = result.errors.size();
139
140 for( size_t i = 0; i < result.errors.size(); i++ )
141 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
142
143 return false;
144 }
145
146 return true;
147}
148
149
151{
152 if( !m_data )
153 return wxEmptyString;
154
155 return m_data->GenerateRule( aContext );
156}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ 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.
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.