36#include <wx/hyperlink.h>
37#include <wx/popupwin.h>
38#include <wx/scrolwin.h>
39#include <wx/settings.h>
40#include <wx/textctrl.h>
41#include <wx/tooltip.h>
42#include <wx/treebook.h>
55constexpr int MAX_POPUP_HEIGHT = 360;
58constexpr int MAX_POPUP_WIDTH = 720;
61constexpr size_t MAX_NAME_LENGTH = 60;
64constexpr int NAME_GAP = 8;
70class OVERRIDING_RULES_POPUP :
public wxPopupTransientWindow
73 explicit OVERRIDING_RULES_POPUP( wxWindow* aParent ) :
74 wxPopupTransientWindow( aParent, wxBORDER_SIMPLE )
76 m_panel =
new wxPanel(
this, wxID_ANY );
77 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
79 m_scrolled =
new wxScrolledWindow( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
80 m_scrolled->SetScrollRate( 0, 10 );
81 m_scrolled->SetBackgroundColour( m_panel->GetBackgroundColour() );
83 m_rows =
new wxBoxSizer( wxVERTICAL );
84 m_scrolled->SetSizer( m_rows );
86 m_outer =
new wxBoxSizer( wxVERTICAL );
87 m_outer->Add( m_scrolled, 1, wxEXPAND | wxALL, FromDIP( 8 ) );
88 m_panel->SetSizer( m_outer );
91 void AddHeading(
const wxString& aText )
93 wxStaticText* heading =
new wxStaticText( m_scrolled, wxID_ANY, aText );
95 heading->SetFont( heading->GetFont().Bold() );
96 m_naturalWidth = std::max( m_naturalWidth, heading->GetTextExtent( aText ).x );
97 m_rows->Add( heading, 0, wxTOP, m_rows->GetItemCount() ? FromDIP( 10 ) : 0 );
101 void AddEntry(
const wxString& aName,
const wxString& aDetail, std::function<
void()> aOpen )
103 wxBoxSizer* row =
new wxBoxSizer( wxHORIZONTAL );
104 wxString
name = aName;
106 if(
name.length() > MAX_NAME_LENGTH )
107 name =
name.Left( MAX_NAME_LENGTH ) + wxS(
"..." );
109 wxHyperlinkCtrl*
link =
new wxHyperlinkCtrl( m_scrolled, wxID_ANY,
name, wxEmptyString );
112 link->SetToolTip( aName );
114 link->Bind( wxEVT_HYPERLINK,
115 [
this, aOpen]( wxHyperlinkEvent& )
118 std::function<void()> open = aOpen;
123 row->Add(
link, 0, wxALIGN_CENTER_VERTICAL );
124 row->Add( shortenable( aDetail,
link->GetBestSize().x + FromDIP( NAME_GAP ) ), 1,
125 wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP( NAME_GAP ) );
127 m_rows->Add( row, 0, wxEXPAND | wxTOP, FromDIP( 3 ) );
131 void AddLink(
const wxString& aText, std::function<
void()> aOpen )
133 wxHyperlinkCtrl*
link =
new wxHyperlinkCtrl( m_scrolled, wxID_ANY, aText, wxEmptyString );
135 link->Bind( wxEVT_HYPERLINK,
136 [
this, aOpen]( wxHyperlinkEvent& )
138 std::function<void()> open = aOpen;
143 m_naturalWidth = std::max( m_naturalWidth,
link->GetBestSize().x );
144 m_rows->Add(
link, 0, wxTOP, m_rows->GetItemCount() ? FromDIP( 10 ) : 0 );
148 void SetOnDismiss( std::function<
void()> aFn ) { m_onDismiss = std::move( aFn ); }
151 void CloseNow() { DismissAndNotify(); }
154 void OnDismiss()
override
162 void PopupUnder( wxWindow* aAnchor )
164 int contentHeight = m_rows->GetMinSize().y;
165 int width = std::min( m_naturalWidth, FromDIP( MAX_POPUP_WIDTH ) );
166 int height = contentHeight;
168 if( height > FromDIP( MAX_POPUP_HEIGHT ) )
170 height = FromDIP( MAX_POPUP_HEIGHT );
171 width += wxSystemSettings::GetMetric( wxSYS_VSCROLL_X, m_scrolled );
174 m_scrolled->SetMinSize( wxSize( width, height ) );
176 m_outer->Fit( m_panel );
177 SetClientSize( m_panel->GetSize() );
181 m_scrolled->SetVirtualSize( wxSize( m_scrolled->GetClientSize().x, contentHeight ) );
182 m_scrolled->Layout();
184 Position( aAnchor->GetScreenPosition(), wxSize( 0, aAnchor->GetSize().y ) );
190 wxStaticText* shortenable(
const wxString& aText,
int aLeading = 0 )
193 new wxStaticText( m_scrolled, wxID_ANY, aText, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END );
197 m_naturalWidth = std::max( m_naturalWidth, aLeading + line->GetTextExtent( aText ).x );
199 line->SetMinSize( wxSize( 1, -1 ) );
200 line->SetToolTip( aText );
206 wxScrolledWindow* m_scrolled;
209 int m_naturalWidth = 0;
211 std::function<void()> m_onDismiss;
226 page->ShowRule( aType, aIndex );
320 field.m_Ctrl->Bind( wxEVT_TEXT,
321 [
this]( wxCommandEvent& aEvent )
340 field.m_Override->ShowAsBadge();
341 field.m_Override->SetCursor( wxCURSOR_HAND );
343 field.m_Override->Bind( wxEVT_LEFT_DOWN,
344 [
this, setting = field.m_Setting, icon = field.m_Override]( wxMouseEvent& )
347 showOverridingRules( setting, icon, false );
351 field.m_Override->Bind( wxEVT_ENTER_WINDOW,
352 [
this, setting = field.m_Setting, icon = field.m_Override]( wxMouseEvent& aEvent )
356 if( m_popup && m_popupAnchor == icon )
360 wxToolTip::Enable( false );
362 m_hoverSetting = setting;
363 m_hoverAnchor = icon;
364 m_hoverTimer.StartOnce( 400 );
367 field.m_Override->Bind( wxEVT_LEAVE_WINDOW,
368 [
this]( wxMouseEvent& aEvent )
374 wxToolTip::Enable(
true );
382 [
this]( wxTimerEvent& )
390 [
this]( wxTimerEvent& )
399 [
this]( wxTimerEvent& )
414 wxWindow* under = wxFindWindowAtPoint( wxGetMousePosition() );
416 for( wxWindow* w = under; w; w = w->GetParent() )
422 static_cast<OVERRIDING_RULES_POPUP*
>(
m_popup )->CloseNow();
453 fieldToControl[field.m_Setting] = field.m_Ctrl;
457 auto it = fieldToControl.find( error.setting_name );
459 if( it == fieldToControl.end() )
479 int value = field.m_Binder->GetValue();
481 if( value != field.m_Loaded )
483 field.m_Loaded = value;
500 aSettings.*( field.m_Member ) = field.m_Binder->GetValue();
509 field.m_Binder->SetValue( field.m_Loaded );
522 static_cast<OVERRIDING_RULES_POPUP*
>(
m_popup )->CloseNow();
525 std::vector<int> indices;
528 indices =
m_document->IndicesSetting( constraint );
531 const std::map<int, std::vector<wxString>> netclasses =
535 if( indices.empty() && netclasses.empty() && defaultsPage.IsEmpty() )
538 OVERRIDING_RULES_POPUP* popup =
new OVERRIDING_RULES_POPUP(
this );
541 popup->AddHeading(
_(
"User clearance rules" ) );
542 else if( !indices.empty() )
543 popup->AddHeading(
_(
"Overridden by user rules" ) );
547 for(
int index : indices )
559 detail = wxString::Format(
_(
"%s, everywhere" ), value );
568 [
this, page, type,
index]()
570 openRuleInEditor( this, page, type, index );
577 if( !netclasses.empty() )
579 popup->AddHeading(
_(
"Net class values" ) );
581 for(
const auto& [value, names] : netclasses )
585 for(
const wxString&
name : names )
587 if( !classes.IsEmpty() )
588 classes << wxS(
", " );
593 popup->AddEntry( classes,
m_Frame->StringFromValue( value,
true ),
596 if( PAGED_DIALOG* dialog = PAGED_DIALOG::GetDialog( this ) )
597 dialog->ShowPage( _(
"Net Classes" ) );
603 if( !defaultsPage.IsEmpty() )
605 popup->AddLink( wxString::Format(
_(
"Edit on the %s page" ), defaultsPage ),
606 [
this, defaultsPage]()
615 aAnchor->UnsetToolTip();
619 if( field.m_Setting == aSetting && field.m_Ctrl->GetToolTip() )
623 field.m_Ctrl->UnsetToolTip();
631 aAnchor->SetToolTip( wxS(
" " ) );
637 wxToolTip::Enable(
true );
647 popup->PopupUnder( aAnchor );
663 std::map<wxString, wxString> messages;
665 for(
const std::vector<BOARD_DESIGN_SETTINGS::VALIDATION_ERROR>& issues :
670 wxString& msg = messages[issue.setting_name];
675 msg += issue.error_message;
681 auto it = messages.find( field.m_Setting );
682 bool show = it != messages.end() && field.m_Ctrl->IsShown();
684 field.m_Warning->SetWarning( show ? it->second : wxString() );
694 for(
int BDS::* member :
695 { &BDS::m_MinClearance, &BDS::m_MinConn, &BDS::m_TrackMinWidth, &BDS::m_ViasMinAnnularWidth,
696 &BDS::m_ViasMinSize, &BDS::m_MinThroughDrill, &BDS::m_MicroViasMinSize, &BDS::m_MicroViasMinDrill,
697 &BDS::m_HoleToHoleMin, &BDS::m_HoleClearance, &BDS::m_SilkClearance, &BDS::m_MinGrooveWidth,
698 &BDS::m_MinSilkTextHeight, &BDS::m_MinSilkLineWidth, &BDS::m_CopperEdgeClearance, &BDS::m_MaxError,
699 &BDS::m_MinResolvedSpokes } )
701 aTo.*member = aFrom.*member;
constexpr int ARC_HIGH_DEF
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
@ edge_to_copper_clearance
@ hole_to_copper_clearance
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.
bool m_ZoneKeepExternalFillets
static wxString ConstraintText(const DRC_RE_LOADED_PANEL_ENTRY &aEntry, DRC_RULE_EDITOR_CONSTRAINT_NAME aType, UNITS_PROVIDER *aUnits)
The constraint a rule sets, written the way the rule table shows it.
Maps DRC rule constraints to appropriate editor panels.
DRC_RULE_EDITOR_CONSTRAINT_NAME GetHomePanel(DRC_CONSTRAINT_T aConstraintType)
The panel whose page lists a text rule that sets this constraint, or CUSTOM_RULE when no panel edits ...
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,...
NET_SETTINGS stores various net-related settings in a project context.
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
wxWindow * ShowPage(const wxString &aTitle)
Select the page with the given title.
wxCheckBox * m_useHeightForLengthCalcs
wxStaticText * m_lineWidthUnits
wxTextCtrl * m_MinDrillCtrl
wxStaticText * m_TrackMinWidthTitle
wxStaticText * m_TrackMinWidthUnits
wxStaticText * m_uviaMinSizeLabel
wxStaticText * m_MinDrillTitle
wxStaticBitmap * m_bitmapMinViaDiameter
wxStaticText * m_lineWidthLabel
wxStaticText * m_ViaMinTitle
wxTextCtrl * m_SetHoleToHoleCtrl
wxTextCtrl * m_ViaMinAnnulusCtrl
wxStaticBitmap * m_bitmapMinuViaDrill
wxStaticText * m_MinConnUnits
wxStaticText * m_HoleClearanceUnits
wxTextCtrl * m_textHeightCtrl
wxStaticText * m_MinDrillUnits
wxTextCtrl * m_minGrooveWidthCtrl
wxTextCtrl * m_clearanceCtrl
wxStaticBitmap * m_bitmapMinViaAnnulus
wxStaticText * m_EdgeClearanceLabel
wxStaticBitmap * m_bitmapMinTrackWidth
wxTextCtrl * m_uviaMinSizeCtrl
wxStaticText * m_ViaMinAnnulusTitle
wxStaticText * m_textHeightLabel
wxStaticText * m_minGrooveWidthUnits
wxStaticText * m_HoleToHoleTitle
wxCheckBox * m_allowExternalFilletsOpt
wxStaticText * m_maxErrorTitle
wxStaticText * m_MinConnTitle
wxStaticText * m_ViaMinUnits
wxStaticText * m_uviaMinDrillUnits
wxStaticText * m_uviaMinSizeUnits
wxStaticBitmap * m_spokeBitmap
wxStaticText * m_minGrooveWidthLabel
wxStaticBitmap * m_bitmapMinGrooveWidth
wxTextCtrl * m_maxErrorCtrl
wxStaticText * m_HoleClearanceLabel
wxStaticBitmap * m_bitmapEdgeClearance
wxStaticBitmap * m_bitmapClearance
wxStaticText * m_EdgeClearanceUnits
wxStaticText * m_clearanceTitle
wxStaticText * m_stCircleToPolyWarning
wxTextCtrl * m_SetViasMinSizeCtrl
wxStaticText * m_clearanceUnits
wxStaticBitmap * m_bitmapHoleClearance
wxStaticText * m_ViaMinAnnulusUnits
wxTextCtrl * m_lineWidthCtrl
wxStaticText * m_textHeightUnits
wxStaticBitmap * m_filletBitmap
wxStaticText * m_uviaMinDrillLabel
wxStaticText * m_HoleToHoleUnits
wxStaticBitmap * m_bitmapMinuViaDiameter
wxStaticText * m_silkClearanceLabel
wxStaticText * m_maxErrorUnits
wxTextCtrl * m_EdgeClearanceCtrl
wxTextCtrl * m_HoleClearanceCtrl
wxStaticBitmap * m_bitmapMinViaDrill
wxTextCtrl * m_uviaMinDrillCtrl
wxTextCtrl * m_silkClearanceCtrl
wxStaticText * m_silkClearanceUnits
wxStaticBitmap * m_bitmapMinConn
wxSpinCtrl * m_minResolvedSpokeCountCtrl
wxTextCtrl * m_MinConnCtrl
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)
wxTextCtrl * m_TrackMinWidthCtrl
wxStaticBitmap * m_bitmapMinHoleClearance
UNIT_BINDER m_minGrooveWidth
PANEL_SETUP_CONSTRAINTS(wxWindow *aParentWindow, PCB_EDIT_FRAME *aFrame, DRC_RULE_DOCUMENT *aDocument, BOARD_DESIGN_SETTINGS &aSettings)
DRC_RULE_DOCUMENT * m_document
wxPopupTransientWindow * m_popup
The popup a hover or a click opened, while it is up.
UNIT_BINDER m_holeClearance
void RefreshDefaults()
Reads the values a rule page edits back into their fields.
wxString m_hoverSetting
The field a hover is waiting to open, and the icon it would hang under.
static void CopySettings(const BOARD_DESIGN_SETTINGS &aFrom, BOARD_DESIGN_SETTINGS &aTo)
Copies every value this page edits, which is what the Constraints import group carries.
void closeHoveredPopup()
Close a popup opened by hovering once the pointer has left both it and its icon.
UNIT_BINDER m_silkClearance
UNIT_BINDER m_holeToHoleMin
std::vector< CONSTRAINT_FIELD > m_fields
int m_spokeCountLoaded
The spoke count as this page last read it.
UNIT_BINDER m_trackMinWidth
UNIT_BINDER m_throughHoleMin
UNIT_BINDER m_uviaMinSize
UNIT_BINDER m_uviaMinDrill
BOARD_DESIGN_SETTINGS * m_BrdSettings
wxString m_spokeCountPage
The rule page that also holds the spoke count, a spin control rather than a bound field.
void showOverridingRules(const wxString &aSetting, wxWindow *aAnchor, bool aFromHover)
Pop up what a board constraint is read with, each entry a link to where it is set.
bool TransferDataToWindow() override
UNIT_BINDER m_viaMinAnnulus
wxWindow * m_popupAnchor
The icon that popup belongs to, which the pointer may return to without closing it.
bool m_popupFromHover
A popup a click opened stays until it is dismissed; one a hover opened follows the pointer.
void applyValues(BOARD_DESIGN_SETTINGS &aSettings) const
UNIT_BINDER m_minLineWidth
UNIT_BINDER m_minTextHeight
wxTimer m_validationTimer
UNIT_BINDER m_minClearance
UNIT_BINDER m_edgeClearance
wxWindow * m_mutedField
The field whose own help is held back while a popup covers it, and the text to give back.
void updateWarnings()
Show a warning icon, with the reason as its tooltip, over each field whose value has an issue.
bool TransferDataFromWindow() override
static wxString PageEditingDefault(const wxString &aSetting)
The title of the page that edits a board default, or empty where no rule page edits one.
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::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.
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.
The main frame for Pcbnew.
DRC_RULE_EDITOR_CONSTRAINT_NAME
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...
Represents a rule loaded from a .kicad_dru file and mapped to a panel.
wxString layerSource
Original layer text: "inner", "outer", or layer name.
DRC_RULE_EDITOR_CONSTRAINT_NAME panelType