47 m_scintillaTricks( nullptr ),
48 m_helpWindow( nullptr )
52 [
this]( wxKeyEvent& aEvent )
55 wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
58 [
this]( wxStyledTextEvent& aEvent )
67 m_typeRegex.Compile(
"^Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
68 m_viaTypeRegex.Compile(
"^Via_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
69 m_padTypeRegex.Compile(
"^Pad_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
70 m_pinTypeRegex.Compile(
"^Pin_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
71 m_fabPropRegex.Compile(
"^Fabrication_Property\\s*[!=]=\\s*$", wxRE_ADVANCED );
72 m_shapeRegex.Compile(
"^Shape\\s*[!=]=\\s*$", wxRE_ADVANCED );
77 m_hJustRegex.Compile(
"^Horizontal_Justification\\s*[!=]=\\s*$", wxRE_ADVANCED );
78 m_vJustRegex.Compile(
"^Vertical_Justification\\s*[!=]=\\s*$", wxRE_ADVANCED );
103 if( aEvent.GetKeyCode() == WXK_ESCAPE && !
m_textEditor->AutoCompActive() )
107 if(
IsOK( wxGetTopLevelParent(
this ),
_(
"Cancel Changes?" ) ) )
125 menu.Append( wxID_UNDO,
_(
"Undo" ) );
126 menu.Append( wxID_REDO,
_(
"Redo" ) );
128 menu.AppendSeparator();
130 menu.Append( 1,
_(
"Cut" ) );
131 menu.Append( 2,
_(
"Copy" ) );
132 menu.Append( 3,
_(
"Paste" ) );
133 menu.Append( 4,
_(
"Delete" ) );
135 menu.AppendSeparator();
137 menu.Append( 5,
_(
"Select All" ) );
139 menu.AppendSeparator();
141 menu.Append( wxID_ZOOM_IN,
_(
"Zoom In" ) );
142 menu.Append( wxID_ZOOM_OUT,
_(
"Zoom Out" ) );
145 switch( GetPopupMenuSelectionFromUser( menu ) )
190 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKey() ==
' ' )
204 for(
int line =
m_textEditor->LineFromPosition( currentPos ); line > 0; line-- )
207 wxString beginning =
m_textEditor->GetTextRange( lineStart, lineStart + 10 );
209 if( beginning.StartsWith( wxT(
"(rule " ) ) )
211 startPos = lineStart;
226 auto isDisallowToken =
227 [](
const wxString& token ) ->
bool
229 return token == wxT(
"buried_via" )
230 || token == wxT(
"graphic" )
231 || token == wxT(
"hole" )
232 || token == wxT(
"micro_via" )
233 || token == wxT(
"pad" )
234 || token == wxT(
"text" )
235 || token == wxT(
"track" )
236 || token == wxT(
"via" )
237 || token == wxT(
"zone" );
240 auto isConstraintTypeToken =
241 [](
const wxString& token ) ->
bool
243 return token == wxT(
"annular_width" )
244 || token == wxT(
"assertion" )
245 || token == wxT(
"clearance" )
246 || token == wxT(
"connection_width" )
247 || token == wxT(
"courtyard_clearance" )
248 || token == wxT(
"diff_pair_gap" )
249 || token == wxT(
"diff_pair_uncoupled" )
250 || token == wxT(
"disallow" )
251 || token == wxT(
"edge_clearance" )
252 || token == wxT(
"length" )
253 || token == wxT(
"hole_clearance" )
254 || token == wxT(
"hole_size" )
255 || token == wxT(
"hole_to_hole" )
256 || token == wxT(
"min_resolved_spokes" )
257 || token == wxT(
"physical_clearance" )
258 || token == wxT(
"physical_hole_clearance" )
259 || token == wxT(
"silk_clearance" )
260 || token == wxT(
"skew" )
261 || token == wxT(
"solder_mask_expansion" )
262 || token == wxT(
"solder_paste_abs_margin" )
263 || token == wxT(
"solder_paste_rel_margin" )
264 || token == wxT(
"text_height" )
265 || token == wxT(
"text_thickness" )
266 || token == wxT(
"thermal_relief_gap" )
267 || token == wxT(
"thermal_spoke_width" )
268 || token == wxT(
"track_width" )
269 || token == wxT(
"track_angle" )
270 || token == wxT(
"track_segment_length" )
271 || token == wxT(
"via_count" )
272 || token == wxT(
"via_diameter" )
273 || token == wxT(
"zone_connection" );
276 std::stack<wxString> sexprs;
279 wxString constraintType;
280 int context = NO_CONTEXT;
281 int expr_context = NO_CONTEXT;
283 for(
int i = startPos; i < currentPos; ++i )
291 else if( context ==
STRING )
295 context = NO_CONTEXT;
299 if( expr_context ==
STRING )
302 expr_context = NO_CONTEXT;
309 partial = wxEmptyString;
314 partial = wxEmptyString;
315 expr_context = STRUCT_REF;
326 partial = wxEmptyString;
331 if( context == SEXPR_OPEN && !partial.IsEmpty() )
334 sexprs.push( partial );
337 partial = wxEmptyString;
338 context = SEXPR_OPEN;
342 while( !sexprs.empty() && ( sexprs.top() == wxT(
"assertion" )
343 || sexprs.top() == wxT(
"disallow" )
344 || isDisallowToken( sexprs.top() )
345 || sexprs.top() == wxT(
"min_resolved_spokes" )
346 || sexprs.top() == wxT(
"zone_connection" ) ) )
351 if( !sexprs.empty() )
354 if( partial == wxT(
"within_diff_pairs" ) )
356 partial = wxEmptyString;
360 if( sexprs.top() == wxT(
"constraint" ) )
362 constraintType = wxEmptyString;
369 context = NO_CONTEXT;
373 if( context == SEXPR_OPEN && !partial.IsEmpty() )
376 sexprs.push( partial );
378 if( partial == wxT(
"constraint" )
379 || partial == wxT(
"layer" )
380 || partial == wxT(
"severity" ) )
382 context = SEXPR_TOKEN;
384 else if( partial == wxT(
"rule" )
385 || partial == wxT(
"condition" ) )
387 context = SEXPR_STRING;
391 context = NO_CONTEXT;
394 partial = wxEmptyString;
397 else if( partial == wxT(
"disallow" )
398 || isDisallowToken( partial )
399 || partial == wxT(
"min_resolved_spokes" )
400 || partial == wxT(
"zone_connection" ) )
403 sexprs.push( partial );
405 partial = wxEmptyString;
406 context = SEXPR_TOKEN;
409 else if( partial == wxT(
"assertion" ) )
412 sexprs.push( partial );
414 partial = wxEmptyString;
415 context = SEXPR_STRING;
418 else if( isConstraintTypeToken( partial ) )
420 constraintType = partial;
423 context = NO_CONTEXT;
433 if( context == SEXPR_OPEN )
437 tokens = wxT(
"rule|"
440 else if( sexprs.top() == wxT(
"rule" ) )
442 tokens = wxT(
"condition|"
447 else if( sexprs.top() == wxT(
"constraint" ) )
449 if( constraintType == wxT(
"skew" ) )
450 tokens = wxT(
"max|min|opt|within_diff_pairs" );
452 tokens = wxT(
"max|min|opt" );
455 else if( context == SEXPR_TOKEN )
461 else if( sexprs.top() == wxT(
"constraint" ) )
463 tokens = wxT(
"annular_width|"
467 "courtyard_clearance|"
470 "diff_pair_uncoupled|"
477 "min_resolved_spokes|"
478 "physical_clearance|"
479 "physical_hole_clearance|"
482 "solder_mask_expansion|"
483 "solder_paste_abs_margin|"
484 "solder_paste_rel_margin|"
487 "thermal_relief_gap|"
488 "thermal_spoke_width|"
491 "track_segment_length|"
496 else if( sexprs.top() == wxT(
"disallow" ) || isDisallowToken( sexprs.top() ) )
498 tokens = wxT(
"buried_via|"
509 else if( sexprs.top() == wxT(
"zone_connection" ) )
511 tokens = wxT(
"none|solid|thermal_reliefs" );
513 else if( sexprs.top() == wxT(
"min_resolved_spokes" ) )
515 tokens = wxT(
"0|1|2|3|4" );
517 else if( sexprs.top() == wxT(
"layer" ) )
519 tokens = wxT(
"inner|outer|\"x\"" );
521 else if( sexprs.top() == wxT(
"severity" ) )
523 tokens = wxT(
"warning|error|ignore|exclusion" );
526 else if( context == SEXPR_STRING && !sexprs.empty()
527 && ( sexprs.top() == wxT(
"condition" ) || sexprs.top() == wxT(
"assertion" ) ) )
531 else if( context ==
STRING && !sexprs.empty()
532 && ( sexprs.top() == wxT(
"condition" ) || sexprs.top() == wxT(
"assertion" ) ) )
534 if( expr_context == STRUCT_REF )
537 std::set<wxString> propNames;
548 if( prop->IsHiddenFromRulesEditor() )
551 wxString ref( prop->Name() );
552 ref.Replace( wxT(
" " ), wxT(
"_" ) );
553 propNames.insert( ref );
557 for(
const wxString& propName : propNames )
558 tokens += wxT(
"|" ) + propName;
564 if( !funcSig.Contains(
"DEPRECATED" ) )
565 tokens += wxT(
"|" ) + funcSig;
568 else if( expr_context ==
STRING )
573 std::shared_ptr<NET_SETTINGS>& netSettings = bds.
m_NetSettings;
575 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
576 tokens += wxT(
"|" ) +
name;
583 tokens += wxT(
"|" ) + netnameCandidate;
587 tokens = wxT(
"Bitmap|"
603 tokens = wxT(
"Through|"
609 tokens = wxT(
"Through-hole|"
612 "NPTH, mechanical" );
616 tokens = wxT(
"Input|"
631 tokens = wxT(
"None|"
633 "Fiducial, global to board|"
634 "Fiducial, local to footprint|"
641 tokens = wxT(
"Segment|"
650 tokens = wxT(
"Circle|"
655 "Chamfered rectangle|"
660 tokens = wxT(
"Inherited|"
664 "Thermal reliefs for PTH" );
668 tokens = wxT(
"Inherited|"
675 tokens = wxT(
"Default|"
684 tokens = wxT(
"Left|"
697 if( !tokens.IsEmpty() )
708 std::vector<std::shared_ptr<DRC_RULE>> dummyRules;
710 std::function<bool( wxString* )>
resolver =
711 [&]( wxString* token ) ->
bool
727 wxString msg = wxString::Format( wxT(
"%s <a href='%d:%d'>%s</a>%s" ),
743 wxString link =
event.GetLinkInfo().GetHref();
745 long line = 0, offset = 0;
749 if( parts.size() > 1 )
751 parts[0].ToLong( &line );
752 parts[1].ToLong( &offset );
755 int pos =
m_textEditor->PositionFromLine( line - 1 ) + ( offset - 1 );
767 if( rulesFile.FileExists() )
769 wxTextFile file( rulesFile.GetFullPath() );
773 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
781 wxCommandEvent
dummy;
795 m_textEditor->AddText(
_(
"Design rules cannot be added without a project" ) );
839 std::vector<wxString> msg;
843#include "dialogs/panel_setup_rules_help_1clauses.h"
845 msg.emplace_back( t );
847#include "dialogs/panel_setup_rules_help_2constraints.h"
849 msg.emplace_back( t );
851#include "dialogs/panel_setup_rules_help_3items.h"
853 msg.emplace_back( t );
855#include "dialogs/panel_setup_rules_help_4severity_names.h"
857 msg.emplace_back( t );
859#include "dialogs/panel_setup_rules_help_5examples.h"
861 msg.emplace_back( t );
863#include "dialogs/panel_setup_rules_help_6notes.h"
865 msg.emplace_back( t );
867#include "dialogs/panel_setup_rules_help_7properties.h"
869 msg.emplace_back( t );
871#include "dialogs/panel_setup_rules_help_8expression_functions.h"
873 msg.emplace_back( t );
875#include "dialogs/panel_setup_rules_help_9more_examples.h"
877 msg.emplace_back( t );
879#include "dialogs/panel_setup_rules_help_10documentation.h"
881 msg.emplace_back( t );
883 wxString msg_txt = wxEmptyString;
885 for( wxString i : msg )
886 msg_txt << wxGetTranslation( i );
889 msg_txt.Replace( wxT(
"Ctrl+" ), wxT(
"Cmd+" ) );
891 const wxString& msGg_txt = msg_txt;
896 wxString html_txt = wxEmptyString;
899 html_txt.Replace( wxS(
"<td" ), wxS(
"<td valign=top" ) );
915 if( absFile.FileExists() )
917 wxTextFile file( absFile.GetFullPath() );
923 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
931 wxCommandEvent
dummy;
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
std::shared_ptr< DRC_ENGINE > m_DRCEngine
Information pertinent to a Pcbnew printed circuit board.
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
const wxString & GetFileName() const
PROJECT * GetProject() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
void SetDialogSizeInDU(int aWidth, int aHeight)
Set the dialog size, using a "logical" value.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
Class PANEL_SETUP_RULES_BASE.
STD_BITMAP_BUTTON * m_compileButton
wxStyledTextCtrl * m_textEditor
WX_HTML_REPORT_BOX * m_errorsReport
bool TransferDataToWindow() override
void OnErrorLinkClicked(wxHtmlLinkEvent &event) override
void onScintillaCharAdded(wxStyledTextEvent &aEvent)
void ImportSettingsFrom(BOARD *aBoard)
void OnContextMenu(wxMouseEvent &event) override
~PANEL_SETUP_RULES() override
HTML_MESSAGE_BOX * m_helpWindow
void OnCompile(wxCommandEvent &event) override
wxRegEx m_padConnectionsRegex
wxRegEx m_zoneConnStyleRegex
bool TransferDataFromWindow() override
void OnSyntaxHelp(wxHyperlinkEvent &aEvent) override
PANEL_SETUP_RULES(wxWindow *aParentWindow, PCB_EDIT_FRAME *aFrame)
void onCharHook(wxKeyEvent &aEvent)
SCINTILLA_TRICKS * m_scintillaTricks
const wxArrayString GetSignatures() const
static PCBEXPR_BUILTIN_FUNCTIONS & Instance()
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
The main frame for Pcbnew.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual bool TextVarResolver(wxString *aToken) const
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Provide class metadata.Helper macro to map type hashes to names.
CLASSES_INFO GetAllClasses()
const PROPERTY_LIST & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
static PROPERTY_MANAGER & Instance()
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
void Clear() override
Delete the stored messages.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Flush()
Build the HTML messages page.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
This file is part of the common library.
static FILENAME_RESOLVER * resolver
static const std::string DesignRulesFileExtension
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< PROPERTY_BASE * > PROPERTY_LIST
std::vector< FAB_LAYER_COLOR > dummy
bool ConvertSmartQuotesAndDashes(wxString *aString)
Convert curly quotes and em/en dashes to straight quotes and dashes.
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)
A filename or source description, a problem input line, a line number, a byte offset,...
int lineNumber
at which line number, 1 based index.
const wxString ParseProblem()
int byteIndex
at which byte offset within the line, 1 based index
Definition of file extensions used in Kicad.