KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_setup_rules.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 (C) 2020-2024 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <bitmaps.h>
25#include <confirm.h>
28#include <pcb_edit_frame.h>
29#include <pcbexpr_evaluator.h>
30#include <board.h>
32#include <project.h>
33#include <string_utils.h>
34#include <tool/tool_manager.h>
35#include <panel_setup_rules.h>
38#include <scintilla_tricks.h>
39#include <drc/drc_rule_parser.h>
40#include <tools/drc_tool.h>
41#include <pgm_base.h>
43
44PANEL_SETUP_RULES::PANEL_SETUP_RULES( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) :
45 PANEL_SETUP_RULES_BASE( aParentWindow ),
46 m_frame( aFrame ),
47 m_scintillaTricks( nullptr ),
48 m_helpWindow( nullptr )
49{
50 m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ), false,
51 // onAcceptFn
52 [this]( wxKeyEvent& aEvent )
53 {
54 wxPostEvent( PAGED_DIALOG::GetDialog( this ),
55 wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
56 },
57 // onCharFn
58 [this]( wxStyledTextEvent& aEvent )
59 {
60 onScintillaCharAdded( aEvent );
61 } );
62
63 m_textEditor->AutoCompSetSeparator( '|' );
64
65 m_netClassRegex.Compile( "^NetClass\\s*[!=]=\\s*$", wxRE_ADVANCED );
66 m_netNameRegex.Compile( "^NetName\\s*[!=]=\\s*$", wxRE_ADVANCED );
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 );
73 m_padShapeRegex.Compile( "^Pad_Shape\\s*[!=]=\\s*$", wxRE_ADVANCED );
74 m_padConnectionsRegex.Compile( "^Pad_Connections\\s*[!=]=\\s*$", wxRE_ADVANCED );
75 m_zoneConnStyleRegex.Compile( "^Zone_Connection_Style\\s*[!=]=\\s*$", wxRE_ADVANCED );
76 m_lineStyleRegex.Compile( "^Line_Style\\s*[!=]=\\s*$", wxRE_ADVANCED );
77 m_hJustRegex.Compile( "^Horizontal_Justification\\s*[!=]=\\s*$", wxRE_ADVANCED );
78 m_vJustRegex.Compile( "^Vertical_Justification\\s*[!=]=\\s*$", wxRE_ADVANCED );
79
80 m_compileButton->SetBitmap( KiBitmapBundle( BITMAPS::drc ) );
81
83
84 m_textEditor->UsePopUp( 0 );
85 m_textEditor->Bind( wxEVT_CHAR_HOOK, &PANEL_SETUP_RULES::onCharHook, this );
86}
87
88
90{
91 m_textEditor->Unbind( wxEVT_CHAR_HOOK, &PANEL_SETUP_RULES::onCharHook, this );
93
94 delete m_scintillaTricks;
95
96 if( m_helpWindow )
97 m_helpWindow->Destroy();
98};
99
100
101void PANEL_SETUP_RULES::onCharHook( wxKeyEvent& aEvent )
102{
103 if( aEvent.GetKeyCode() == WXK_ESCAPE && !m_textEditor->AutoCompActive() )
104 {
105 if( m_originalText != m_textEditor->GetText() )
106 {
107 if( IsOK( wxGetTopLevelParent( this ), _( "Cancel Changes?" ) ) )
108 {
109 m_textEditor->SetText( m_originalText );
110 m_textEditor->SelectAll();
111 }
112
113 return;
114 }
115 }
116
117 aEvent.Skip();
118}
119
120
121void PANEL_SETUP_RULES::OnContextMenu(wxMouseEvent &event)
122{
123 wxMenu menu;
124
125 menu.Append( wxID_UNDO, _( "Undo" ) );
126 menu.Append( wxID_REDO, _( "Redo" ) );
127
128 menu.AppendSeparator();
129
130 menu.Append( 1, _( "Cut" ) ); // Don't use wxID_CUT, wxID_COPY, etc. On Mac (at least),
131 menu.Append( 2, _( "Copy" ) ); // wxWidgets never delivers them to us.
132 menu.Append( 3, _( "Paste" ) );
133 menu.Append( 4, _( "Delete" ) );
134
135 menu.AppendSeparator();
136
137 menu.Append( 5, _( "Select All" ) );
138
139 menu.AppendSeparator();
140
141 menu.Append( wxID_ZOOM_IN, _( "Zoom In" ) );
142 menu.Append( wxID_ZOOM_OUT, _( "Zoom Out" ) );
143
144
145 switch( GetPopupMenuSelectionFromUser( menu ) )
146 {
147 case wxID_UNDO:
148 m_textEditor->Undo();
149 break;
150 case wxID_REDO:
151 m_textEditor->Redo();
152 break;
153
154 case 1:
155 m_textEditor->Cut();
156 break;
157 case 2:
158 m_textEditor->Copy();
159 break;
160 case 3:
161 m_textEditor->Paste();
162 break;
163 case 4:
164 {
165 long from, to;
166 m_textEditor->GetSelection( &from, &to );
167
168 if( to > from )
169 m_textEditor->DeleteRange( from, to );
170
171 break;
172 }
173
174 case 5:
175 m_textEditor->SelectAll();
176 break;
177
178 case wxID_ZOOM_IN:
179 m_textEditor->ZoomIn();
180 break;
181 case wxID_ZOOM_OUT:
182 m_textEditor->ZoomOut();
183 break;
184 }
185}
186
187
188void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
189{
190 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKey() == ' ' )
191 {
192 // This is just a short-cut for do-auto-complete
193 }
194 else
195 {
197 }
198
199 m_textEditor->SearchAnchor();
200
201 wxString rules = m_textEditor->GetText();
202 int currentPos = m_textEditor->GetCurrentPos();
203 int startPos = 0;
204
205 for( int line = m_textEditor->LineFromPosition( currentPos ); line > 0; line-- )
206 {
207 int lineStart = m_textEditor->PositionFromLine( line );
208 wxString beginning = m_textEditor->GetTextRange( lineStart, lineStart + 10 );
209
210 if( beginning.StartsWith( wxT( "(rule " ) ) )
211 {
212 startPos = lineStart;
213 break;
214 }
215 }
216
217 enum
218 {
219 NONE,
220 STRING,
221 SEXPR_OPEN,
222 SEXPR_TOKEN,
223 SEXPR_STRING,
224 STRUCT_REF
225 };
226
227 auto isDisallowToken =
228 []( const wxString& token ) -> bool
229 {
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" );
239 };
240
241 auto isConstraintTypeToken =
242 []( const wxString& token ) -> bool
243 {
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( "via_count" )
268 || token == wxT( "via_diameter" )
269 || token == wxT( "zone_connection" );
270 };
271
272 std::stack<wxString> sexprs;
273 wxString partial;
274 wxString last;
275 wxString constraintType;
276 int context = NONE;
277 int expr_context = NONE;
278
279 for( int i = startPos; i < currentPos; ++i )
280 {
281 wxChar c = m_textEditor->GetCharAt( i );
282
283 if( c == '\\' )
284 {
285 i++; // skip escaped char
286 }
287 else if( context == STRING )
288 {
289 if( c == '"' )
290 {
291 context = NONE;
292 }
293 else
294 {
295 if( expr_context == STRING )
296 {
297 if( c == '\'' )
298 expr_context = NONE;
299 else
300 partial += c;
301 }
302 else if( c == '\'' )
303 {
304 last = partial;
305 partial = wxEmptyString;
306 expr_context = STRING;
307 }
308 else if( c == '.' )
309 {
310 partial = wxEmptyString;
311 expr_context = STRUCT_REF;
312 }
313 else
314 {
315 partial += c;
316 }
317 }
318 }
319 else if( c == '"' )
320 {
321 last = partial;
322 partial = wxEmptyString;
323 context = STRING;
324 }
325 else if( c == '(' )
326 {
327 if( context == SEXPR_OPEN && !partial.IsEmpty() )
328 {
329 m_textEditor->AutoCompCancel();
330 sexprs.push( partial );
331 }
332
333 partial = wxEmptyString;
334 context = SEXPR_OPEN;
335 }
336 else if( c == ')' )
337 {
338 while( !sexprs.empty() && ( sexprs.top() == wxT( "assertion" )
339 || sexprs.top() == wxT( "disallow" )
340 || isDisallowToken( sexprs.top() )
341 || sexprs.top() == wxT( "min_resolved_spokes" )
342 || sexprs.top() == wxT( "zone_connection" ) ) )
343 {
344 sexprs.pop();
345 }
346
347 if( !sexprs.empty() )
348 {
349 // Ignore argument-less tokens
350 if( partial == wxT( "within_diff_pairs" ) )
351 {
352 partial = wxEmptyString;
353 }
354 else
355 {
356 if( sexprs.top() == wxT( "constraint" ) )
357 {
358 constraintType = wxEmptyString;
359 }
360
361 sexprs.pop();
362 }
363 }
364
365 context = NONE;
366 }
367 else if( c == ' ' )
368 {
369 if( context == SEXPR_OPEN && !partial.IsEmpty() )
370 {
371 m_textEditor->AutoCompCancel();
372 sexprs.push( partial );
373
374 if( partial == wxT( "constraint" )
375 || partial == wxT( "layer" )
376 || partial == wxT( "severity" ) )
377 {
378 context = SEXPR_TOKEN;
379 }
380 else if( partial == wxT( "rule" )
381 || partial == wxT( "condition" ) )
382 {
383 context = SEXPR_STRING;
384 }
385 else
386 {
387 context = NONE;
388 }
389
390 partial = wxEmptyString;
391 continue;
392 }
393 else if( partial == wxT( "disallow" )
394 || isDisallowToken( partial )
395 || partial == wxT( "min_resolved_spokes" )
396 || partial == wxT( "zone_connection" ) )
397 {
398 m_textEditor->AutoCompCancel();
399 sexprs.push( partial );
400
401 partial = wxEmptyString;
402 context = SEXPR_TOKEN;
403 continue;
404 }
405 else if( partial == wxT( "assertion" ) )
406 {
407 m_textEditor->AutoCompCancel();
408 sexprs.push( partial );
409
410 partial = wxEmptyString;
411 context = SEXPR_STRING;
412 continue;
413 }
414 else if( isConstraintTypeToken( partial ) )
415 {
416 constraintType = partial;
417 }
418
419 context = NONE;
420 }
421 else
422 {
423 partial += c;
424 }
425 }
426
427 wxString tokens;
428
429 if( context == SEXPR_OPEN )
430 {
431 if( sexprs.empty() )
432 {
433 tokens = wxT( "rule|"
434 "version" );
435 }
436 else if( sexprs.top() == wxT( "rule" ) )
437 {
438 tokens = wxT( "condition|"
439 "constraint|"
440 "layer|"
441 "severity" );
442 }
443 else if( sexprs.top() == wxT( "constraint" ) )
444 {
445 if( constraintType == wxT( "skew" ) )
446 tokens = wxT( "max|min|opt|within_diff_pairs" );
447 else
448 tokens = wxT( "max|min|opt" );
449 }
450 }
451 else if( context == SEXPR_TOKEN )
452 {
453 if( sexprs.empty() )
454 {
455 /* badly formed grammar */
456 }
457 else if( sexprs.top() == wxT( "constraint" ) )
458 {
459 tokens = wxT( "annular_width|"
460 "assertion|"
461 "clearance|"
462 "connection_width|"
463 "courtyard_clearance|"
464 "diff_pair_gap|"
465 "diff_pair_uncoupled|"
466 "disallow|"
467 "edge_clearance|"
468 "length|"
469 "hole_clearance|"
470 "hole_size|"
471 "hole_to_hole|"
472 "min_resolved_spokes|"
473 "physical_clearance|"
474 "physical_hole_clearance|"
475 "silk_clearance|"
476 "skew|"
477 "text_height|"
478 "text_thickness|"
479 "thermal_relief_gap|"
480 "thermal_spoke_width|"
481 "track_width|"
482 "via_count|"
483 "via_diameter|"
484 "zone_connection" );
485 }
486 else if( sexprs.top() == wxT( "disallow" ) || isDisallowToken( sexprs.top() ) )
487 {
488 tokens = wxT( "buried_via|"
489 "footprint|"
490 "graphic|"
491 "hole|"
492 "micro_via|"
493 "pad|"
494 "text|"
495 "track|"
496 "via|"
497 "zone" );
498 }
499 else if( sexprs.top() == wxT( "zone_connection" ) )
500 {
501 tokens = wxT( "none|solid|thermal_reliefs" );
502 }
503 else if( sexprs.top() == wxT( "min_resolved_spokes" ) )
504 {
505 tokens = wxT( "0|1|2|3|4" );
506 }
507 else if( sexprs.top() == wxT( "layer" ) )
508 {
509 tokens = wxT( "inner|outer|\"x\"" );
510 }
511 else if( sexprs.top() == wxT( "severity" ) )
512 {
513 tokens = wxT( "warning|error|ignore|exclusion" );
514 }
515 }
516 else if( context == SEXPR_STRING && !sexprs.empty()
517 && ( sexprs.top() == wxT( "condition" ) || sexprs.top() == wxT( "assertion" ) ) )
518 {
519 m_textEditor->AddText( wxT( "\"" ) );
520 }
521 else if( context == STRING && !sexprs.empty()
522 && ( sexprs.top() == wxT( "condition" ) || sexprs.top() == wxT( "assertion" ) ) )
523 {
524 if( expr_context == STRUCT_REF )
525 {
527 std::set<wxString> propNames;
528
529 for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
530 {
531 const PROPERTY_LIST& props = propMgr.GetProperties( cls.type );
532
533 for( PROPERTY_BASE* prop : props )
534 {
535 // TODO: It would be nice to replace IsHiddenFromRulesEditor with a nickname
536 // system, so that two different properies don't need to be created. This is
537 // a bigger change than I want to make right now, though.
538 if( prop->IsHiddenFromRulesEditor() )
539 continue;
540
541 wxString ref( prop->Name() );
542 ref.Replace( wxT( " " ), wxT( "_" ) );
543 propNames.insert( ref );
544 }
545 }
546
547 for( const wxString& propName : propNames )
548 tokens += wxT( "|" ) + propName;
549
551
552 for( const wxString& funcSig : functions.GetSignatures() )
553 {
554 if( !funcSig.Contains( "DEPRECATED" ) )
555 tokens += wxT( "|" ) + funcSig;
556 }
557 }
558 else if( expr_context == STRING )
559 {
560 if( m_netClassRegex.Matches( last ) )
561 {
563 std::shared_ptr<NET_SETTINGS>& netSettings = bds.m_NetSettings;
564
565 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
566 tokens += wxT( "|" ) + name;
567 }
568 else if( m_netNameRegex.Matches( last ) )
569 {
570 BOARD* board = m_frame->GetBoard();
571
572 for( const wxString& netnameCandidate : board->GetNetClassAssignmentCandidates() )
573 tokens += wxT( "|" ) + netnameCandidate;
574 }
575 else if( m_typeRegex.Matches( last ) )
576 {
577 tokens = wxT( "Bitmap|"
578 "Dimension|"
579 "Footprint|"
580 "Graphic|"
581 "Group|"
582 "Leader|"
583 "Pad|"
584 "Target|"
585 "Text|"
586 "Text Box|"
587 "Track|"
588 "Via|"
589 "Zone" );
590 }
591 else if( m_viaTypeRegex.Matches( last ) )
592 {
593 tokens = wxT( "Through|"
594 "Blind/buried|"
595 "Micro" );
596 }
597 else if( m_padTypeRegex.Matches( last ) )
598 {
599 tokens = wxT( "Through-hole|"
600 "SMD|"
601 "Edge connector|"
602 "NPTH, mechanical" );
603 }
604 else if( m_pinTypeRegex.Matches( last ) )
605 {
606 tokens = wxT( "Input|"
607 "Output|"
608 "Bidirectional|"
609 "Tri-state|"
610 "Passive|"
611 "Free|"
612 "Unspecified|"
613 "Power input|"
614 "Power output|"
615 "Open collector|"
616 "Open emitter|"
617 "Unconnected" );
618 }
619 else if( m_fabPropRegex.Matches( last ) )
620 {
621 tokens = wxT( "None|"
622 "BGA pad|"
623 "Fiducial, global to board|"
624 "Fiducial, local to footprint|"
625 "Test point pad|"
626 "Heatsink pad|"
627 "Castellated pad" );
628 }
629 else if( m_shapeRegex.Matches( last ) )
630 {
631 tokens = wxT( "Segment|"
632 "Rectangle|"
633 "Arc|"
634 "Circle|"
635 "Polygon|"
636 "Bezier" );
637 }
638 else if( m_padShapeRegex.Matches( last ) )
639 {
640 tokens = wxT( "Circle|"
641 "Rectangle|"
642 "Oval|"
643 "Trapezoid|"
644 "Rounded rectangle|"
645 "Chamfered rectangle|"
646 "Custom" );
647 }
648 else if( m_padConnectionsRegex.Matches( last ) )
649 {
650 tokens = wxT( "Inherited|"
651 "None|"
652 "Solid|"
653 "Thermal reliefs|"
654 "Thermal reliefs for PTH" );
655 }
656 else if( m_zoneConnStyleRegex.Matches( last ) )
657 {
658 tokens = wxT( "Inherited|"
659 "None|"
660 "Solid|"
661 "Thermal reliefs" );
662 }
663 else if( m_lineStyleRegex.Matches( last ) )
664 {
665 tokens = wxT( "Default|"
666 "Solid|"
667 "Dashed|"
668 "Dotted|"
669 "Dash-Dot|"
670 "Dash-Dot-Dot" );
671 }
672 else if( m_hJustRegex.Matches( last ) )
673 {
674 tokens = wxT( "Left|"
675 "Center|"
676 "Right" );
677 }
678 else if( m_vJustRegex.Matches( last ) )
679 {
680 tokens = wxT( "Top|"
681 "Center|"
682 "Bottom" );
683 }
684 }
685 }
686
687 if( !tokens.IsEmpty() )
688 m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, '|' ) );
689}
690
691
692void PANEL_SETUP_RULES::OnCompile( wxCommandEvent& event )
693{
695
696 try
697 {
698 std::vector<std::shared_ptr<DRC_RULE>> dummyRules;
699
700 DRC_RULES_PARSER parser( m_textEditor->GetText(), _( "DRC rules" ) );
701
702 parser.Parse( dummyRules, m_errorsReport );
703 }
704 catch( PARSE_ERROR& pe )
705 {
706 wxString msg = wxString::Format( wxT( "%s <a href='%d:%d'>%s</a>%s" ),
707 _( "ERROR:" ),
708 pe.lineNumber,
709 pe.byteIndex,
710 pe.ParseProblem(),
711 wxEmptyString );
712
714 }
715
717}
718
719
720void PANEL_SETUP_RULES::OnErrorLinkClicked( wxHtmlLinkEvent& event )
721{
722 wxString link = event.GetLinkInfo().GetHref();
723 wxArrayString parts;
724 long line = 0, offset = 0;
725
726 wxStringSplit( link, parts, ':' );
727
728 if( parts.size() > 1 )
729 {
730 parts[0].ToLong( &line );
731 parts[1].ToLong( &offset );
732 }
733
734 int pos = m_textEditor->PositionFromLine( line - 1 ) + ( offset - 1 );
735
736 m_textEditor->GotoPos( pos );
737
738 m_textEditor->SetFocus();
739}
740
741
743{
744 wxFileName rulesFile( m_frame->GetDesignRulesPath() );
745
746 if( rulesFile.FileExists() )
747 {
748 wxTextFile file( rulesFile.GetFullPath() );
749
750 if( file.Open() )
751 {
752 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
753 {
755 m_textEditor->AddText( str << '\n' );
756 }
757
758 m_textEditor->EmptyUndoBuffer();
759
760 wxCommandEvent dummy;
761 OnCompile( dummy );
762 }
763 }
764 else
765 {
766 m_textEditor->AddText( wxT( "(version 1)\n" ) );
767 }
768
769 m_originalText = m_textEditor->GetText();
770
771 if( m_frame->Prj().IsNullProject() )
772 {
773 m_textEditor->ClearAll();
774 m_textEditor->AddText( _( "Design rules cannot be added without a project" ) );
775 m_textEditor->Disable();
776 }
777
778 return true;
779}
780
781
783{
784 if( m_originalText == m_textEditor->GetText() )
785 return true;
786
787 if( m_frame->Prj().IsNullProject() )
788 return true;
789
790 wxString rulesFilepath = m_frame->GetDesignRulesPath();
791
792 try
793 {
794 if( m_textEditor->SaveFile( rulesFilepath ) )
795 {
796 m_frame->GetBoard()->GetDesignSettings().m_DRCEngine->InitEngine( rulesFilepath );
797 return true;
798 }
799 }
800 catch( PARSE_ERROR& )
801 {
802 // Don't lock them in to the Setup dialog if they have bad rules. They've already
803 // saved them so we can allow an exit.
804 return true;
805 }
806
807 return false;
808}
809
810
811void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
812{
813 if( m_helpWindow )
814 {
816 return;
817 }
818
819 wxString msg =
821 ;
822
823#ifdef __WXMAC__
824 msg.Replace( wxT( "Ctrl+" ), wxT( "Cmd+" ) );
825#endif
826
827 m_helpWindow = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
828 m_helpWindow->SetDialogSizeInDU( 420, 320 );
829
830 wxString html_txt;
831 ConvertMarkdown2Html( wxGetTranslation( msg ), html_txt );
832
833 html_txt.Replace( wxS( "<td" ), wxS( "<td valign=top" ) );
834 m_helpWindow->AddHTML_Text( html_txt );
835
837}
838
839
841{
842 if( !m_frame->Prj().IsNullProject() )
843 {
844 wxFileName relFile = aBoard->GetFileName();
845 relFile.SetExt( FILEEXT::DesignRulesFileExtension );
846
847 wxFileName absFile( aBoard->GetProject()->AbsolutePath( relFile.GetFullName() ) );
848
849 if( absFile.FileExists() )
850 {
851 wxTextFile file( absFile.GetFullPath() );
852
853 if( file.Open() )
854 {
855 m_textEditor->ClearAll();
856
857 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
858 {
860 m_textEditor->AddText( str << '\n' );
861 }
862
863 m_textEditor->EmptyUndoBuffer();
864
865 wxCommandEvent dummy;
866 OnCompile( dummy );
867 }
868 }
869 }
870}
const char * name
Definition: DXF_plotter.cpp:57
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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.
Definition: board.h:289
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition: board.cpp:2013
const wxString & GetFileName() const
Definition: board.h:326
PROJECT * GetProject() const
Definition: board.h:490
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:877
APPEARANCE m_Appearance
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.
void SetModified()
Definition: paged_dialog.h:43
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)
PCB_EDIT_FRAME * m_frame
void OnContextMenu(wxMouseEvent &event) override
~PANEL_SETUP_RULES() override
HTML_MESSAGE_BOX * m_helpWindow
void OnCompile(wxCommandEvent &event) override
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.
BOARD * GetBoard() const
The main frame for Pcbnew.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:678
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.
Definition: project.cpp:359
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:153
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
CLASSES_INFO GetAllClasses()
const PROPERTY_LIST & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
void SetBitmap(const wxBitmapBundle &aBmp)
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.
Definition: confirm.cpp:250
This file is part of the common library.
#define _(s)
static const std::string DesignRulesFileExtension
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
std::vector< PROPERTY_BASE * > PROPERTY_LIST
Definition: property_mgr.h:49
@ RPT_SEVERITY_ERROR
@ 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,...
Definition: ki_exception.h:120
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:121
const wxString ParseProblem()
Definition: ki_exception.h:151
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:122
Definition of file extensions used in Kicad.