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() ==
' ' )
205 for(
int line =
m_textEditor->LineFromPosition( currentPos ); line > 0; line-- )
208 wxString beginning =
m_textEditor->GetTextRange( lineStart, lineStart + 10 );
210 if( beginning.StartsWith( wxT(
"(rule " ) ) )
212 startPos = lineStart;
227 auto isDisallowToken =
228 [](
const wxString& token ) ->
bool
230 return token == wxT(
"buried_via" )
231 || token == wxT(
"graphic" )
232 || token == wxT(
"hole" )
233 || token == wxT(
"micro_via" )
234 || token == wxT(
"pad" )
235 || token == wxT(
"text" )
236 || token == wxT(
"track" )
237 || token == wxT(
"via" )
238 || token == wxT(
"zone" );
241 auto isConstraintTypeToken =
242 [](
const wxString& token ) ->
bool
244 return token == wxT(
"annular_width" )
245 || token == wxT(
"assertion" )
246 || token == wxT(
"clearance" )
247 || token == wxT(
"connection_width" )
248 || token == wxT(
"courtyard_clearance" )
249 || token == wxT(
"diff_pair_gap" )
250 || token == wxT(
"diff_pair_uncoupled" )
251 || token == wxT(
"disallow" )
252 || token == wxT(
"edge_clearance" )
253 || token == wxT(
"length" )
254 || token == wxT(
"hole_clearance" )
255 || token == wxT(
"hole_size" )
256 || token == wxT(
"hole_to_hole" )
257 || token == wxT(
"min_resolved_spokes" )
258 || token == wxT(
"physical_clearance" )
259 || token == wxT(
"physical_hole_clearance" )
260 || token == wxT(
"silk_clearance" )
261 || token == wxT(
"skew" )
262 || token == wxT(
"text_height" )
263 || token == wxT(
"text_thickness" )
264 || token == wxT(
"thermal_relief_gap" )
265 || token == wxT(
"thermal_spoke_width" )
266 || token == wxT(
"track_width" )
267 || token == wxT(
"track_angle" )
268 || token == wxT(
"track_segment_length" )
269 || token == wxT(
"via_count" )
270 || token == wxT(
"via_diameter" )
271 || token == wxT(
"zone_connection" );
274 std::stack<wxString> sexprs;
277 wxString constraintType;
279 int expr_context =
NONE;
281 for(
int i = startPos; i < currentPos; ++i )
289 else if( context ==
STRING )
297 if( expr_context ==
STRING )
307 partial = wxEmptyString;
312 partial = wxEmptyString;
313 expr_context = STRUCT_REF;
324 partial = wxEmptyString;
329 if( context == SEXPR_OPEN && !partial.IsEmpty() )
332 sexprs.push( partial );
335 partial = wxEmptyString;
336 context = SEXPR_OPEN;
340 while( !sexprs.empty() && ( sexprs.top() == wxT(
"assertion" )
341 || sexprs.top() == wxT(
"disallow" )
342 || isDisallowToken( sexprs.top() )
343 || sexprs.top() == wxT(
"min_resolved_spokes" )
344 || sexprs.top() == wxT(
"zone_connection" ) ) )
349 if( !sexprs.empty() )
352 if( partial == wxT(
"within_diff_pairs" ) )
354 partial = wxEmptyString;
358 if( sexprs.top() == wxT(
"constraint" ) )
360 constraintType = wxEmptyString;
371 if( context == SEXPR_OPEN && !partial.IsEmpty() )
374 sexprs.push( partial );
376 if( partial == wxT(
"constraint" )
377 || partial == wxT(
"layer" )
378 || partial == wxT(
"severity" ) )
380 context = SEXPR_TOKEN;
382 else if( partial == wxT(
"rule" )
383 || partial == wxT(
"condition" ) )
385 context = SEXPR_STRING;
392 partial = wxEmptyString;
395 else if( partial == wxT(
"disallow" )
396 || isDisallowToken( partial )
397 || partial == wxT(
"min_resolved_spokes" )
398 || partial == wxT(
"zone_connection" ) )
401 sexprs.push( partial );
403 partial = wxEmptyString;
404 context = SEXPR_TOKEN;
407 else if( partial == wxT(
"assertion" ) )
410 sexprs.push( partial );
412 partial = wxEmptyString;
413 context = SEXPR_STRING;
416 else if( isConstraintTypeToken( partial ) )
418 constraintType = partial;
431 if( context == SEXPR_OPEN )
435 tokens = wxT(
"rule|"
438 else if( sexprs.top() == wxT(
"rule" ) )
440 tokens = wxT(
"condition|"
445 else if( sexprs.top() == wxT(
"constraint" ) )
447 if( constraintType == wxT(
"skew" ) )
448 tokens = wxT(
"max|min|opt|within_diff_pairs" );
450 tokens = wxT(
"max|min|opt" );
453 else if( context == SEXPR_TOKEN )
459 else if( sexprs.top() == wxT(
"constraint" ) )
461 tokens = wxT(
"annular_width|"
465 "courtyard_clearance|"
468 "diff_pair_uncoupled|"
475 "min_resolved_spokes|"
476 "physical_clearance|"
477 "physical_hole_clearance|"
482 "thermal_relief_gap|"
483 "thermal_spoke_width|"
486 "track_segment_length|"
491 else if( sexprs.top() == wxT(
"disallow" ) || isDisallowToken( sexprs.top() ) )
493 tokens = wxT(
"buried_via|"
504 else if( sexprs.top() == wxT(
"zone_connection" ) )
506 tokens = wxT(
"none|solid|thermal_reliefs" );
508 else if( sexprs.top() == wxT(
"min_resolved_spokes" ) )
510 tokens = wxT(
"0|1|2|3|4" );
512 else if( sexprs.top() == wxT(
"layer" ) )
514 tokens = wxT(
"inner|outer|\"x\"" );
516 else if( sexprs.top() == wxT(
"severity" ) )
518 tokens = wxT(
"warning|error|ignore|exclusion" );
521 else if( context == SEXPR_STRING && !sexprs.empty()
522 && ( sexprs.top() == wxT(
"condition" ) || sexprs.top() == wxT(
"assertion" ) ) )
526 else if( context ==
STRING && !sexprs.empty()
527 && ( sexprs.top() == wxT(
"condition" ) || sexprs.top() == wxT(
"assertion" ) ) )
529 if( expr_context == STRUCT_REF )
532 std::set<wxString> propNames;
543 if( prop->IsHiddenFromRulesEditor() )
546 wxString ref( prop->Name() );
547 ref.Replace( wxT(
" " ), wxT(
"_" ) );
548 propNames.insert( ref );
552 for(
const wxString& propName : propNames )
553 tokens += wxT(
"|" ) + propName;
559 if( !funcSig.Contains(
"DEPRECATED" ) )
560 tokens += wxT(
"|" ) + funcSig;
563 else if( expr_context ==
STRING )
568 std::shared_ptr<NET_SETTINGS>& netSettings = bds.
m_NetSettings;
570 for(
const auto& [
name, netclass] : netSettings->GetNetclasses() )
571 tokens += wxT(
"|" ) +
name;
578 tokens += wxT(
"|" ) + netnameCandidate;
582 tokens = wxT(
"Bitmap|"
598 tokens = wxT(
"Through|"
604 tokens = wxT(
"Through-hole|"
607 "NPTH, mechanical" );
611 tokens = wxT(
"Input|"
626 tokens = wxT(
"None|"
628 "Fiducial, global to board|"
629 "Fiducial, local to footprint|"
636 tokens = wxT(
"Segment|"
645 tokens = wxT(
"Circle|"
650 "Chamfered rectangle|"
655 tokens = wxT(
"Inherited|"
659 "Thermal reliefs for PTH" );
663 tokens = wxT(
"Inherited|"
670 tokens = wxT(
"Default|"
679 tokens = wxT(
"Left|"
692 if( !tokens.IsEmpty() )
703 std::vector<std::shared_ptr<DRC_RULE>> dummyRules;
711 wxString msg = wxString::Format( wxT(
"%s <a href='%d:%d'>%s</a>%s" ),
727 wxString link =
event.GetLinkInfo().GetHref();
729 long line = 0, offset = 0;
733 if( parts.size() > 1 )
735 parts[0].ToLong( &line );
736 parts[1].ToLong( &offset );
739 int pos =
m_textEditor->PositionFromLine( line - 1 ) + ( offset - 1 );
751 if( rulesFile.FileExists() )
753 wxTextFile file( rulesFile.GetFullPath() );
757 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
765 wxCommandEvent
dummy;
779 m_textEditor->AddText(
_(
"Design rules cannot be added without a project" ) );
823 std::vector<wxString> msg;
829 msg.emplace_back( t );
833 msg.emplace_back( t );
837 msg.emplace_back( t );
841 msg.emplace_back( t );
845 msg.emplace_back( t );
849 msg.emplace_back( t );
853 msg.emplace_back( t );
857 msg.emplace_back( t );
861 msg.emplace_back( t );
865 msg.emplace_back( t );
867 wxString msg_txt = wxEmptyString;
869 for( wxString i : msg )
870 msg_txt << wxGetTranslation( i );
873 msg_txt.Replace( wxT(
"Ctrl+" ), wxT(
"Cmd+" ) );
875 const wxString& msGg_txt = msg_txt;
880 wxString html_txt = wxEmptyString;
883 html_txt.Replace( wxS(
"<td" ), wxS(
"<td valign=top" ) );
899 if( absFile.FileExists() )
901 wxTextFile file( absFile.GetFullPath() );
907 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
915 wxCommandEvent
dummy;
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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 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()
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.
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 const std::string DesignRulesFileExtension
PGM_BASE & Pgm()
The global Program "get" accessor.
std::vector< PROPERTY_BASE * > PROPERTY_LIST
@ NONE
No connection to this item.
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.