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, 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
27
28#include <base_units.h>
29#include <eda_base_frame.h>
30#include <widgets/unit_binder.h>
31
32#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
60 // Create min width field
61 auto* minWidthField = AddField<wxTextCtrl>( wxS( "min_width" ), positions[0],
62 wxTE_CENTRE | wxTE_PROCESS_ENTER );
64 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, minWidthField->GetControl(),
65 minWidthField->GetLabel(), false, false );
66 minWidthField->SetUnitBinder( m_minRoutingWidthBinder.get() );
67
68 // Create preferred width field
69 auto* prefWidthField = AddField<wxTextCtrl>( wxS( "pref_width" ), positions[1],
70 wxTE_CENTRE | wxTE_PROCESS_ENTER );
72 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, prefWidthField->GetControl(),
73 prefWidthField->GetLabel(), false, false );
74 prefWidthField->SetUnitBinder( m_preferredRoutingWidthBinder.get() );
75
76 // Create max width field
77 auto* maxWidthField = AddField<wxTextCtrl>( wxS( "max_width" ), positions[2],
78 wxTE_CENTRE | wxTE_PROCESS_ENTER );
80 std::make_unique<UNIT_BINDER>( &m_unitsProvider, eventSource, nullptr, maxWidthField->GetControl(),
81 maxWidthField->GetLabel(), false, false );
82 maxWidthField->SetUnitBinder( m_maxRoutingWidthBinder.get() );
83
84 auto notifyModified = [this]( wxCommandEvent& )
85 {
87 if( dlg )
88 dlg->SetModified();
89 };
90
91 minWidthField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
92 prefWidthField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
93 maxWidthField->GetControl()->Bind( wxEVT_TEXT, notifyModified );
94
95 auto notifySave = [this]( wxCommandEvent& aEvent )
96 {
98 if( dlg )
99 dlg->OnSave( aEvent );
100 };
101
102 minWidthField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
103 prefWidthField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
104 maxWidthField->GetControl()->Bind( wxEVT_TEXT_ENTER, notifySave );
105
106 // Position all fields and update the panel layout
109}
110
111
113{
114 if( !m_data )
115 return false;
116
117 // Convert mm values to internal units and set them in the binders
118 m_minRoutingWidthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMinRoutingWidth() ) );
119 m_preferredRoutingWidthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetPreferredRoutingWidth() ) );
120 m_maxRoutingWidthBinder->SetDoubleValue( pcbIUScale.mmToIU( m_data->GetMaxRoutingWidth() ) );
121
122 return true;
123}
124
125
127{
128 if( !m_data )
129 return false;
130
131 // Read values from binders (in internal units) and convert to mm for storage
132 m_data->SetMinRoutingWidth( pcbIUScale.IUTomm( m_minRoutingWidthBinder->GetDoubleValue() ) );
133 m_data->SetPreferredRoutingWidth( pcbIUScale.IUTomm( m_preferredRoutingWidthBinder->GetDoubleValue() ) );
134 m_data->SetMaxRoutingWidth( pcbIUScale.IUTomm( m_maxRoutingWidthBinder->GetDoubleValue() ) );
135
136 return true;
137}
138
139
141 wxString* aValidationMessage )
142{
144
145 VALIDATION_RESULT result = m_data->Validate();
146
147 if( !result.isValid )
148 {
149 *aErrorCount = result.errors.size();
150
151 for( size_t i = 0; i < result.errors.size(); i++ )
152 *aValidationMessage += DRC_RULE_EDITOR_UTILS::FormatErrorMessage( i + 1, result.errors[i] );
153
154 return false;
155 }
156
157 return true;
158}
159
160
162{
163 if( !m_data )
164 return wxEmptyString;
165
166 return m_data->GenerateRule( aContext );
167}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
@ 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.
std::unique_ptr< UNIT_BINDER > m_preferredRoutingWidthBinder
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.
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.