KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_setup_constraints.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 The 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
20#include <algorithm>
21#include <map>
22
24#include <board.h>
25#include <math/util.h>
28#include <pcb_edit_frame.h>
31#include <wx/treebook.h>
32#include <bitmaps.h>
33#include <advanced_config.h>
34
35
37 PANEL_SETUP_CONSTRAINTS_BASE( aParentWindow ),
54 m_validationTimer( this )
55{
56 m_Frame = aFrame;
57 m_BrdSettings = &m_Frame->GetBoard()->GetDesignSettings();
58
72
73 m_stCircleToPolyWarning->SetFont( KIUI::GetSmallInfoFont( this ).Italic() );
74
75 wxSize ctrlSize = m_minResolvedSpokeCountCtrl->GetSize();
76 ctrlSize.x = KIUI::GetTextSize( wxT( "XXX" ), m_minResolvedSpokeCountCtrl ).x;
77 m_minResolvedSpokeCountCtrl->SetSize( ctrlSize );
78
79 if( !ADVANCED_CFG::GetCfg().m_EnableCreepageSlot )
80 {
81 m_bitmapMinGrooveWidth->Show( false );
82 m_minGrooveWidthLabel->Show( false );
83 m_minGrooveWidthCtrl->Show( false );
84 m_minGrooveWidthUnits->Show( false );
85 }
86
87 m_fields = {
88 { wxS( "min_clearance" ), m_clearanceCtrl, nullptr },
89 { wxS( "min_connection" ), m_MinConnCtrl, nullptr },
90 { wxS( "min_track_width" ), m_TrackMinWidthCtrl, nullptr },
91 { wxS( "min_via_annular_width" ), m_ViaMinAnnulusCtrl, nullptr },
92 { wxS( "min_via_diameter" ), m_SetViasMinSizeCtrl, nullptr },
93 { wxS( "min_through_hole_diameter" ), m_MinDrillCtrl, nullptr },
94 { wxS( "min_microvia_diameter" ), m_uviaMinSizeCtrl, nullptr },
95 { wxS( "min_microvia_drill" ), m_uviaMinDrillCtrl, nullptr },
96 { wxS( "min_hole_to_hole" ), m_SetHoleToHoleCtrl, nullptr },
97 { wxS( "min_hole_clearance" ), m_HoleClearanceCtrl, nullptr },
98 { wxS( "min_silk_clearance" ), m_silkClearanceCtrl, nullptr },
99 { wxS( "min_groove_width" ), m_minGrooveWidthCtrl, nullptr },
100 { wxS( "min_text_height" ), m_textHeightCtrl, nullptr },
101 { wxS( "min_text_thickness" ), m_textThicknessCtrl, nullptr },
102 { wxS( "min_copper_edge_clearance" ), m_EdgeClearanceCtrl, nullptr },
103 { wxS( "max_error" ), m_maxErrorCtrl, nullptr }
104 };
105
106 for( CONSTRAINT_FIELD& field : m_fields )
107 {
108 field.m_Warning = new FIELD_WARNING_ICON( field.m_Ctrl );
109
110 // Debounced so a half-typed value does not flash a warning
111 field.m_Ctrl->Bind( wxEVT_TEXT,
112 [this]( wxCommandEvent& aEvent )
113 {
114 m_validationTimer.StartOnce( 250 );
115 aEvent.Skip();
116 } );
117 }
118
119 Bind( wxEVT_TIMER,
120 [this]( wxTimerEvent& )
121 {
123 },
124 m_validationTimer.GetId() );
125}
126
127
129{
130 wxString msg;
131 msg.Printf( m_stCircleToPolyWarning->GetLabel(), m_Frame->StringFromValue( ARC_HIGH_DEF, true ) );
132 m_stCircleToPolyWarning->SetLabel( msg );
133
134 m_useHeightForLengthCalcs->SetValue( m_BrdSettings->m_UseHeightForLengthCalcs );
135
136 m_maxError.SetValue( m_BrdSettings->m_MaxError );
137
138 m_allowExternalFilletsOpt->SetValue( m_BrdSettings->m_ZoneKeepExternalFillets );
139 m_minResolvedSpokeCountCtrl->SetValue( m_BrdSettings->m_MinResolvedSpokes );
140
141 m_minClearance.SetValue( m_BrdSettings->m_MinClearance );
142 m_minConn.SetValue( m_BrdSettings->m_MinConn );
143 m_trackMinWidth.SetValue( m_BrdSettings->m_TrackMinWidth );
144 m_viaMinAnnulus.SetValue( m_BrdSettings->m_ViasMinAnnularWidth );
145 m_viaMinSize.SetValue(m_BrdSettings->m_ViasMinSize );
146 m_holeClearance.SetValue( m_BrdSettings->m_HoleClearance );
147 m_edgeClearance.SetValue( m_BrdSettings->m_CopperEdgeClearance );
148 m_minGrooveWidth.SetValue( m_BrdSettings->m_MinGrooveWidth );
149
150 m_throughHoleMin.SetValue( m_BrdSettings->m_MinThroughDrill );
151 m_holeToHoleMin.SetValue( m_BrdSettings->m_HoleToHoleMin );
152
153 m_uviaMinSize.SetValue( m_BrdSettings->m_MicroViasMinSize );
154 m_uviaMinDrill.SetValue( m_BrdSettings->m_MicroViasMinDrill );
155
156 m_silkClearance.SetValue( m_BrdSettings->m_SilkClearance );
157 m_minTextHeight.SetValue( m_BrdSettings->m_MinSilkTextHeight );
158 m_minTextThickness.SetValue( m_BrdSettings->m_MinSilkTextThickness );
159
161
162 return true;
163}
164
165
167{
168 // These are all stored in project file, not board, so no need for OnModify()
169
171
172 std::vector<BOARD_DESIGN_SETTINGS::VALIDATION_ERROR> errors =
173 m_BrdSettings->ValidateDesignRules( m_Frame->GetUserUnits() );
174
175 if( !errors.empty() )
176 {
177 const BOARD_DESIGN_SETTINGS::VALIDATION_ERROR& error = errors.front();
178
179 const std::map<wxString, wxWindow*> fieldToControl = {
180 { wxS( "min_clearance" ), m_clearanceCtrl },
181 { wxS( "min_connection" ), m_MinConnCtrl },
182 { wxS( "min_track_width" ), m_TrackMinWidthCtrl },
183 { wxS( "min_via_annular_width" ), m_ViaMinAnnulusCtrl },
184 { wxS( "min_via_diameter" ), m_SetViasMinSizeCtrl },
185 { wxS( "min_through_hole_diameter" ), m_MinDrillCtrl },
186 { wxS( "min_microvia_diameter" ), m_uviaMinSizeCtrl },
187 { wxS( "min_microvia_drill" ), m_uviaMinDrillCtrl },
188 { wxS( "min_hole_to_hole" ), m_SetHoleToHoleCtrl },
189 { wxS( "min_hole_clearance" ), m_HoleClearanceCtrl },
190 { wxS( "min_silk_clearance" ), m_silkClearanceCtrl },
191 { wxS( "min_groove_width" ), m_minGrooveWidthCtrl },
192 { wxS( "min_text_height" ), m_textHeightCtrl },
193 { wxS( "min_text_thickness" ), m_textThicknessCtrl },
194 { wxS( "min_copper_edge_clearance" ), m_EdgeClearanceCtrl },
195 { wxS( "max_error" ), m_maxErrorCtrl },
196 { wxS( "min_resolved_spokes" ), m_minResolvedSpokeCountCtrl }
197 };
198
199 wxWindow* control = nullptr;
200
201 if( auto it = fieldToControl.find( error.setting_name ); it != fieldToControl.end() )
202 control = it->second;
203
204 PAGED_DIALOG::GetDialog( this )->SetError( error.error_message, this, control ? control : this );
205 return false;
206 }
207
208 return true;
209}
210
211
213{
215
216 aSettings.m_MaxError = m_maxError.GetValue();
217
219 aSettings.m_MinResolvedSpokes = m_minResolvedSpokeCountCtrl->GetValue();
220
221 aSettings.m_MinClearance = m_minClearance.GetValue();
222 aSettings.m_MinConn = m_minConn.GetValue();
223 aSettings.m_TrackMinWidth = m_trackMinWidth.GetValue();
224 aSettings.m_ViasMinAnnularWidth = m_viaMinAnnulus.GetValue();
225 aSettings.m_ViasMinSize = m_viaMinSize.GetValue();
226 aSettings.m_HoleClearance = m_holeClearance.GetValue();
227 aSettings.m_CopperEdgeClearance = m_edgeClearance.GetValue();
228 aSettings.m_MinGrooveWidth = m_minGrooveWidth.GetValue();
229
230 aSettings.m_MinThroughDrill = m_throughHoleMin.GetValue();
231 aSettings.m_HoleToHoleMin = m_holeToHoleMin.GetValue();
232
233 aSettings.m_MicroViasMinSize = m_uviaMinSize.GetValue();
234 aSettings.m_MicroViasMinDrill = m_uviaMinDrill.GetValue();
235
236 aSettings.m_SilkClearance = m_silkClearance.GetValue();
237 aSettings.m_MinSilkTextHeight = m_minTextHeight.GetValue();
238 aSettings.m_MinSilkTextThickness = m_minTextThickness.GetValue();
239}
240
241
243{
244 m_validationTimer.Stop();
245
247 applyValues( candidate );
248
249 EDA_UNITS units = m_Frame->GetUserUnits();
250 std::map<wxString, wxString> messages;
251
252 for( const std::vector<BOARD_DESIGN_SETTINGS::VALIDATION_ERROR>& issues :
253 { candidate.ValidateDesignRules( units ), candidate.GetDesignRuleWarnings( units ) } )
254 {
255 for( const BOARD_DESIGN_SETTINGS::VALIDATION_ERROR& issue : issues )
256 {
257 wxString& msg = messages[issue.setting_name];
258
259 if( !msg.IsEmpty() )
260 msg += wxS( "\n" );
261
262 msg += issue.error_message;
263 }
264 }
265
266 for( const CONSTRAINT_FIELD& field : m_fields )
267 {
268 auto it = messages.find( field.m_Setting );
269 bool show = it != messages.end() && field.m_Ctrl->IsShown();
270
271 field.m_Warning->SetWarning( show ? it->second : wxString() );
272 }
273}
274
275
277{
278 BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
279
280 m_BrdSettings = &aBoard->GetDesignSettings();
282
283 m_BrdSettings = savedSettings;
284}
constexpr int ARC_HIGH_DEF
Definition base_units.h:144
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ via_hole_diameter
@ hole_to_hole_clearance
@ edge_to_copper_clearance
@ hole_to_copper_clearance
@ ps_diff_pair_gap
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Container for design settings for a BOARD object.
std::vector< VALIDATION_ERROR > GetDesignRuleWarnings(std::optional< EDA_UNITS > aUnits=std::nullopt) const
Find design rule values that are legal but have no effect because other rules imply a stricter limit.
std::vector< VALIDATION_ERROR > ValidateDesignRules(std::optional< EDA_UNITS > aUnits=std::nullopt) const
Validate design settings values and return per-field errors.
bool m_UseHeightForLengthCalcs
Enable inclusion of stackup height in track length measurements and length tuning.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1290
A warning icon drawn inside the right edge of a field, left of its dropdown button when it has one,...
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
PANEL_SETUP_CONSTRAINTS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
PANEL_SETUP_CONSTRAINTS(wxWindow *aParentWindow, PCB_EDIT_FRAME *aFrame)
std::vector< CONSTRAINT_FIELD > m_fields
BOARD_DESIGN_SETTINGS * m_BrdSettings
void applyValues(BOARD_DESIGN_SETTINGS &aSettings) const
void updateWarnings()
Show a warning icon, with the reason as its tooltip, over each field whose value has an issue.
The main frame for Pcbnew.
EDA_UNITS
Definition eda_units.h:44
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:80