KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_matched_length_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
24
25#include <base_units.h>
26#include <eda_base_frame.h>
27#include <widgets/unit_binder.h>
28
29#include <wx/textctrl.h>
30#include <wx/stattext.h>
31#include <wx/checkbox.h>
32
34 wxWindow* aParent, DRC_RE_MATCHED_LENGTH_DIFF_PAIR_CONSTRAINT_DATA* aData, EDA_UNITS aUnits ) :
36 m_data( aData ),
38{
40
41 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
42
43 wxWindow* eventSource = nullptr;
44
45 for( wxWindow* win = aParent; win; win = win->GetParent() )
46 {
47 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
48 {
49 eventSource = win;
50 break;
51 }
52 }
53
54 // Create opt length field
55 auto* optLengthField = AddField<wxTextCtrl>( wxS( "opt_length" ), positions[0], wxTE_CENTRE | wxTE_PROCESS_ENTER );
57 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, optLengthField->GetControl(),
58 optLengthField->GetLabel(), false, false );
59 optLengthField->SetUnitBinder( m_optLengthBinder.get() );
60 optLengthField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
61
62 // Create tolerance field
63 auto* toleranceField = AddField<wxTextCtrl>( wxS( "tolerance" ), positions[1], wxTE_CENTRE | wxTE_PROCESS_ENTER );
65 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, toleranceField->GetControl(),
66 toleranceField->GetLabel(), false, false );
67 toleranceField->SetUnitBinder( m_toleranceBinder.get() );
68 toleranceField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
69
70 // Create max skew field
71 auto* maxSkewField = AddField<wxTextCtrl>( wxS( "max_skew" ), positions[2], wxTE_CENTRE | wxTE_PROCESS_ENTER );
72 m_maxSkewBinder = std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxSkewField->GetControl(),
73 maxSkewField->GetLabel(), false, false );
74 maxSkewField->SetUnitBinder( m_maxSkewBinder.get() );
75 maxSkewField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
76
77 auto* withinDiffPairs = AddCheckbox( wxS( "within_diff_pairs" ), positions[3] );
78 m_withinDiffPairsCheckbox = static_cast<wxCheckBox*>( withinDiffPairs->GetControl() );
79
80 // Position all fields and update the panel layout
83}
84
85
87{
88 if( !m_data )
89 return false;
90
91 m_optLengthBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetOptimumLength() ) );
92 m_toleranceBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetTolerance() ) );
93 m_maxSkewBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxSkew() ) );
94 m_withinDiffPairsCheckbox->SetValue( m_data->GetWithinDiffPairs() );
95
96 return true;
97}
98
99
101{
102 if( !m_data )
103 return false;
104
105 m_data->SetOptimumLength( pcbIUScale.IUTomm( m_optLengthBinder->GetDoubleValue() ) );
106 m_data->SetTolerance( pcbIUScale.IUTomm( m_toleranceBinder->GetDoubleValue() ) );
107 m_data->SetMaxSkew( pcbIUScale.IUTomm( m_maxSkewBinder->GetDoubleValue() ) );
108 m_data->SetWithinDiffPairs( m_withinDiffPairsCheckbox->GetValue() );
109
110 return true;
111}
112
113
114bool DRC_RE_MATCHED_LENGTH_DIFF_PAIR_OVERLAY_PANEL::ValidateInputs( int* aErrorCount, wxString* aValidationMessage )
115{
117
118 VALIDATION_RESULT result = m_data->Validate();
119
120 if( !result.isValid )
121 {
122 *aErrorCount = result.errors.size();
123
124 for( size_t i = 0; i < result.errors.size(); i++ )
125 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
126
127 return false;
128 }
129
130 return true;
131}
132
133
135{
136 if( !m_data )
137 return wxEmptyString;
138
139 return m_data->GenerateRule( aContext );
140}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
DRC_RE_OVERLAY_FIELD * AddCheckbox(const wxString &aId, const DRC_RE_FIELD_POSITION &aPosition)
Create and position a checkbox 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.
BITMAPS GetOverlayBitmap() const override
Returns the bitmap to use for the overlay panel background.
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_MATCHED_LENGTH_DIFF_PAIR_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_MATCHED_LENGTH_DIFF_PAIR_CONSTRAINT_DATA *aData, EDA_UNITS aUnits)
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.