36#include <wx/hyperlink.h>
38#include <wx/scrolwin.h>
40#include <wx/statline.h>
41#include <wx/stattext.h>
42#include <wx/textctrl.h>
51 wxPanel( aParent, wxID_ANY ),
61 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
63 m_scrolled =
new wxScrolledWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
65 m_scrolled->SetSizer(
new wxBoxSizer( wxVERTICAL ) );
70 SetSizer( mainSizer );
73 [
this]( wxSizeEvent& aEvent )
81 [
this]( wxTimerEvent& )
93 wxStaticText* heading =
new wxStaticText( parent, wxID_ANY,
m_section.title );
94 wxBoxSizer* settings =
new wxBoxSizer( wxVERTICAL );
96 heading->SetFont( heading->GetFont().Bold() );
97 box->Add( heading, 0, wxLEFT | wxTOP | wxBOTTOM, 8 );
98 box->Add( settings, 0, wxEXPAND | wxLEFT, 8 );
102 wxFlexGridSizer*
grid =
new wxFlexGridSizer( 0, 3, 4, 8 );
106 wxStaticText* label =
new wxStaticText( parent, wxID_ANY, field.
label );
107 wxTextCtrl* value =
new wxTextCtrl( parent, wxID_ANY );
108 wxStaticText* units =
new wxStaticText( parent, wxID_ANY, wxEmptyString );
114 value->SetMinSize( wxSize(
KIUI::GetTextSize( wxT(
"XXXXXXXXXX" ), value ).x, -1 ) );
116 grid->Add( label, 0, wxALIGN_CENTER_VERTICAL );
117 grid->Add( value, 0, wxALIGN_CENTER_VERTICAL );
118 grid->Add( units, 0, wxALIGN_CENTER_VERTICAL );
125 entry.
binder = std::make_unique<UNIT_BINDER>(
m_frame, label, value, units );
132 value->Bind( wxEVT_TEXT,
133 [
this]( wxCommandEvent& aEvent )
142 settings->Add(
grid, 0, wxEXPAND | wxALL, 5 );
146 m_defaultsNoteText =
_(
"Used where no rule below matches. Kept with the board, not in the "
151 settings->Add(
m_defaultsNote, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
158 box->Add(
new wxStaticLine( parent ), 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
162 wxBoxSizer* row =
new wxBoxSizer( wxHORIZONTAL );
166 wxStaticText* rules =
new wxStaticText( parent, wxID_ANY,
_(
"Rules" ) );
168 rules->SetFont( rules->GetFont().Bold() );
169 row->Add( rules, 0, wxALIGN_CENTER_VERTICAL );
172 row->AddStretchSpacer();
176 wxHyperlinkCtrl*
link =
new wxHyperlinkCtrl( parent, wxID_ANY,
_(
"Edit net classes" ), wxEmptyString );
179 link->Bind( wxEVT_HYPERLINK,
180 [
this]( wxHyperlinkEvent& )
185 row->Add(
link, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 12 );
188 box->Add( row, 0, wxEXPAND | wxLEFT | wxTOP, 8 );
191 m_noteText =
_(
"The rules below are read from top to bottom and the last one that matches "
192 "decides the value. A value a net class sets is read before any of them." );
196 box->Add(
m_note, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 8 );
200 list->SetTitleWindow( heading );
204 std::vector<std::pair<wxString, std::function<wxString()>>> defaults;
206 for(
size_t d = 0; d <
m_section.defaults.size(); ++d )
215 if(
name.EndsWith( wxS(
":" ) ) )
220 defaults.emplace_back(
name,
227 list->SetDefaults( std::move( defaults ) );
233 list->SetChangeCallback(
238 box->Add( list, 1, wxEXPAND | wxALL, 8 );
247 dialog->ShowPage( aTitle );
254 if(
m_scrolled->GetClientSize().x - 180 < 200 )
257 for(
const auto& [label,
text] :
262 label->SetLabel(
text );
263 label->Wrap( GetClientSize().x - 32 );
278 field.binder->SetValue( field.loaded );
300 if( field.settingName != error.setting_name )
304 dialog->SetError( error.error_message,
this, field.ctrl );
314 int value = field.binder->GetValue();
316 if( value != field.loaded )
319 field.loaded = value;
330 aSettings.*( field.member ) = field.binder->GetValue();
348 std::map<wxString, wxString> messages;
350 for(
const std::vector<BOARD_DESIGN_SETTINGS::VALIDATION_ERROR>& issues :
355 wxString& msg = messages[issue.setting_name];
360 msg += issue.error_message;
366 auto it = messages.find( field.settingName );
368 field.warning->SetWarning( it != messages.end() ? it->second : wxString() );
373 m_list->RefreshOverrideNote();
424 std::vector<std::pair<wxString, CONSTRAINT_DEFAULT_FIELD>> fields;
434 fields.emplace_back(
group, field );
452 return std::move( section );
463 static const std::map<wxString, DRC_CONSTRAINT_T> constraints = {
481 auto it = constraints.find( aSetting );
483 if( it == constraints.end() )
487 *aConstraint = it->second;
497 return section ? section->title : wxString();
507 link->SetWarning( wxString::Format(
_(
"Also on the %s page. Click to open it." ), aPage ) );
508 link->SetCursor( wxCURSOR_HAND );
509 link->Bind( wxEVT_LEFT_DOWN,
510 [aField, aPage]( wxMouseEvent& )
513 dialog->ShowPage( aPage );
521std::map<int, std::vector<wxString>> groupByValue(
const std::function<std::optional<int>(
const NETCLASS& )>& aValue,
524 std::map<int, std::vector<wxString>> byValue;
526 auto collect = [&](
const std::shared_ptr<NETCLASS>& aNetclass )
531 if( std::optional<int> value = aValue( *aNetclass ) )
532 byValue[*value].push_back( aNetclass->GetName() );
551 if( !section || !section->netclassValue )
554 return groupByValue( section->netclassValue, aNetSettings );
561 m_list->EditRule( aIndex );
572 if( section.ruleType == aType )
573 return section.title;
577 return wxEmptyString;
587 return aNetclass.GetClearanceOpt();
589 auto trackWidth = [](
const NETCLASS& aNetclass )
591 return aNetclass.GetTrackWidthOpt();
593 auto viaDiameter = [](
const NETCLASS& aNetclass )
595 return aNetclass.GetViaDiameterOpt();
597 auto viaDrill = [](
const NETCLASS& aNetclass )
599 return aNetclass.GetViaDrillOpt();
605 return { {
_(
"Minimum clearance" ),
606 { {
_(
"Board default:" ), &BDS::m_MinClearance, wxS(
"min_clearance" ) } },
609 {
_(
"Copper to hole clearance" ),
610 { {
_(
"Board default:" ), &BDS::m_HoleClearance, wxS(
"min_hole_clearance" ) } },
613 {
_(
"Copper to edge clearance" ),
614 { {
_(
"Board default:" ), &BDS::m_CopperEdgeClearance, wxS(
"min_copper_edge_clearance" ) } },
619 {
_(
"Minimum thermal relief spoke count" ),
620 { {
_(
"Board default:" ), &BDS::m_MinResolvedSpokes, wxS(
"min_resolved_spokes" ),
626 return { {
_(
"Minimum track width" ),
627 { {
_(
"Board default:" ), &BDS::m_TrackMinWidth, wxS(
"min_track_width" ) } },
632 {
_(
"Minimum connection width" ),
633 { {
_(
"Board default:" ), &BDS::m_MinConn, wxS(
"min_connection" ) } },
636 {
_(
"Minimum annular width" ),
637 { {
_(
"Board default:" ), &BDS::m_ViasMinAnnularWidth, wxS(
"min_via_annular_width" ) } },
640 {
_(
"Minimum via diameter" ),
641 { {
_(
"Board default:" ), &BDS::m_ViasMinSize, wxS(
"min_via_diameter" ) },
642 {
_(
"Microvia default:" ), &BDS::m_MicroViasMinSize, wxS(
"min_microvia_diameter" ) } },
651 return { {
_(
"Minimum drill size" ),
652 { {
_(
"Board default:" ), &BDS::m_MinThroughDrill, wxS(
"min_through_hole_diameter" ) },
653 {
_(
"Microvia default:" ), &BDS::m_MicroViasMinDrill, wxS(
"min_microvia_drill" ) } },
659 {
_(
"Hole to hole clearance" ),
660 { {
_(
"Board default:" ), &BDS::m_HoleToHoleMin, wxS(
"min_hole_to_hole" ) } },
667 return { {
_(
"Silk to silk clearance" ),
668 { {
_(
"Board default:" ), &BDS::m_SilkClearance, wxS(
"min_silk_clearance" ) } },
671 {
_(
"Minimum text height and thickness" ),
672 { {
_(
"Minimum text height:" ), &BDS::m_MinSilkTextHeight, wxS(
"min_text_height" ) },
673 {
_(
"Minimum line width:" ), &BDS::m_MinSilkLineWidth, wxS(
"min_silk_line_width" ) } },
684 return { {
_(
"Solder mask expansion" ),
685 { {
_(
"Board default:" ), &BDS::m_SolderMaskExpansion, wxS(
"solder_mask_expansion" ) } },
688 _(
"Solder Mask/Paste" ) },
689 {
_(
"Minimum solder mask sliver" ),
690 { {
_(
"Board default:" ), &BDS::m_SolderMaskMinWidth, wxS(
"solder_mask_min_width" ) } },
693 _(
"Solder Mask/Paste" ) },
694 {
_(
"Solder paste expansion" ),
695 { {
_(
"Board default:" ), &BDS::m_SolderPasteMargin, wxS(
"solder_paste_margin" ) } },
698 _(
"Solder Mask/Paste" ) } };
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.
The rules of one constraint type, in evaluation order, with an editor that opens in place.
The custom rules of one board, held in memory while Board Setup is open.
A warning icon drawn inside the right edge of a field, left of its dropdown button when it has one,...
A collection of nets and the parameters used to route or test these nets.
NET_SETTINGS stores various net-related settings in a project context.
const std::map< wxString, std::shared_ptr< NETCLASS > > & GetNetclasses() const
Gets all netclasses.
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
PANEL_SETUP_CONSTRAINT_RULES(wxWindow *aParent, PCB_EDIT_FRAME *aFrame, DRC_RULE_DOCUMENT *aDocument, BOARD_DESIGN_SETTINGS &aSettings, const CONSTRAINT_SECTION &aSection)
CONSTRAINT_SECTION m_section
void showPage(const wxString &aTitle)
bool TransferDataToWindow() override
wxStaticText * m_defaultsNote
wxTimer m_validationTimer
static wxString PageEditingDefault(const wxString &aSetting)
The title of the page that edits a board default, or empty where no rule page edits one.
void RefreshFromDocument()
std::vector< DEFAULT_FIELD > m_defaults
static std::vector< CONSTRAINT_SECTION > SectionsFor(FAMILY aFamily)
The sections of one family, in the order they are shown in the tree.
wxScrolledWindow * m_scrolled
bool Validate() override
The rule form is always on screen, so its fields are empty until a rule is being written.
static bool RulesCanOverride(const wxString &aSetting, DRC_CONSTRAINT_T *aConstraint)
Whether rules can set a value other than this board default, and the DRC constraint that does it.
static wxString PageTitleFor(DRC_RULE_EDITOR_CONSTRAINT_NAME aType)
The title of the page that edits rules of this type, or empty when no page does.
static std::vector< std::pair< wxString, CONSTRAINT_DEFAULT_FIELD > > EditedDefaults()
Every board default a rule page edits, each with the group it is imported with.
DRC_RULE_DOCUMENT * m_document
BOARD_DESIGN_SETTINGS * m_settings
bool TransferDataFromWindow() override
Called when the dialog is accepted.
void updateWarnings()
Shows a warning icon, with the reason as its tooltip, over each default whose value has an issue.
wxString m_defaultsNoteText
wxString ImportGroup() const
The Import Settings group this page's defaults travel with.
static std::map< int, std::vector< wxString > > NetclassValuesFor(const wxString &aSetting, const NET_SETTINGS &aNetSettings)
The net class values set for a constraint, grouped by value so equal classes list together.
bool confirmPendingRule()
Offers what to do with a rule the form holds.
void RefreshDefaults()
Reads the board defaults back into their fields, after something other than this page changed them.
void writeDefaults(BOARD_DESIGN_SETTINGS &aSettings) const
Copies the defaults this page edits into aSettings.
bool applyDefaults()
Writes the default fields to the board, or reports the first value out of range.
static void LinkToPage(wxWindow *aField, const wxString &aPage, int aSlot=1)
Puts a link to another page holding the same value at the field's right edge.
CONSTRAINT_RULES_LIST * m_list
Null until the section is built, and where a section carries no rules of its own.
void ShowRule(DRC_RULE_EDITOR_CONSTRAINT_NAME aType, int aIndex)
Opens one of this page's rules in its editor, when the page holds that rule type.
static std::optional< CONSTRAINT_SECTION > sectionForSetting(const wxString &aSetting)
The section whose board defaults include a setting, where one holds it.
The main frame for Pcbnew.
virtual void SetUnits(EDA_UNITS aUnits)
Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DE...
@ ANNULAR_WIDTH_CONSTRAINT
@ VIA_DIAMETER_CONSTRAINT
@ SOLDER_MASK_SLIVER_CONSTRAINT
@ SILK_CLEARANCE_CONSTRAINT
@ EDGE_CLEARANCE_CONSTRAINT
@ CONNECTION_WIDTH_CONSTRAINT
@ HOLE_CLEARANCE_CONSTRAINT
@ SOLDER_PASTE_ABS_MARGIN_CONSTRAINT
@ SOLDER_MASK_EXPANSION_CONSTRAINT
@ HOLE_TO_HOLE_CONSTRAINT
DRC_RULE_EDITOR_CONSTRAINT_NAME
@ SILK_TO_SOLDERMASK_CLEARANCE
@ MINIMUM_CONNECTION_WIDTH
@ MINIMUM_THERMAL_RELIEF_SPOKE_COUNT
@ MINIMUM_TEXT_HEIGHT_AND_THICKNESS
@ COPPER_TO_HOLE_CLEARANCE
@ MATCHED_LENGTH_DIFF_PAIR
@ COPPER_TO_EDGE_CLEARANCE
@ MINIMUM_SOLDERMASK_SLIVER
KICOMMON_API wxFont GetInfoFont(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...
static wxString importGroup(const CONSTRAINT_SECTION &aSection)
@ OPTIMUM
Asks for a value without raising the minimum, as a net class track width does.
@ COUNT
A plain number, which no change of units rescales.
int BOARD_DESIGN_SETTINGS::* member
One constraint on a Design Rules page: its board default, the net class values that apply to it,...
wxString settingsPage
The group this section's defaults are imported with.
One board default, as this page shows it.
int BOARD_DESIGN_SETTINGS::* member
FIELD_WARNING_ICON * warning
std::unique_ptr< UNIT_BINDER > binder
Functions to provide common constants and other functions to assist in making a consistent UI.