KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_routing_width_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
32
34 wxWindow* aParent,
36 EDA_UNITS aUnits ) :
38 m_data( aData ),
40{
42
43 std::vector<DRC_RE_FIELD_POSITION> positions = m_data->GetFieldPositions();
44
45 wxWindow* eventSource = nullptr;
46
47 for( wxWindow* win = aParent; win; win = win->GetParent() )
48 {
49 if( dynamic_cast<EDA_BASE_FRAME*>( win ) )
50 {
51 eventSource = win;
52 break;
53 }
54 }
55
56 // Create opt width field
57 auto* optWidthField = AddField<wxTextCtrl>( wxS( "opt_width" ), positions[0], wxTE_CENTRE | wxTE_PROCESS_ENTER );
59 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, optWidthField->GetControl(),
60 optWidthField->GetLabel(), false, false );
61 optWidthField->SetUnitBinder( m_optWidthBinder.get() );
62 optWidthField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
63
64 // Create width tolerance field
65 auto* widthTolField =
66 AddField<wxTextCtrl>( wxS( "width_tolerance" ), positions[1], wxTE_CENTRE | wxTE_PROCESS_ENTER );
68 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, widthTolField->GetControl(),
69 widthTolField->GetLabel(), false, false );
70 widthTolField->SetUnitBinder( m_widthToleranceBinder.get() );
71 widthTolField->GetControl()->SetValidator( VALIDATOR_NUMERIC_CTRL( false, false ) );
72
73
74 // Position all fields and update the panel layout
77}
78
79
81{
82 if( !m_data )
83 return false;
84
85 m_optWidthBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetOptWidth() ) );
86 m_widthToleranceBinder->ChangeDoubleValue( pcbIUScale.mmToIU( m_data->GetWidthTolerance() ) );
87
88 return true;
89}
90
91
93{
94 if( !m_data )
95 return false;
96
97 m_data->SetOptWidth( pcbIUScale.IUTomm( m_optWidthBinder->GetDoubleValue() ) );
98 m_data->SetWidthTolerance( pcbIUScale.IUTomm( m_widthToleranceBinder->GetDoubleValue() ) );
99
100 return true;
101}
102
103
105 wxString* aValidationMessage )
106{
108
109 VALIDATION_RESULT result = m_data->Validate();
110
111 if( !result.isValid )
112 {
113 *aErrorCount = result.errors.size();
114
115 for( size_t i = 0; i < result.errors.size(); i++ )
116 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
117
118 return false;
119 }
120
121 return true;
122}
123
124
126{
127 if( !m_data )
128 return wxEmptyString;
129
130 return m_data->GenerateRule( aContext );
131}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ constraint_routing_width
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.
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA * m_data
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RE_ROUTING_WIDTH_OVERLAY_PANEL(wxWindow *aParent, DRC_RE_ROUTING_WIDTH_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.