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( "track_angle" )
268 || token == wxT( "track_segment_length" )
269 || token == wxT( "via_count" )
270 || token == wxT( "via_diameter" )
271 || token == wxT( "zone_connection" );
272 };
273
274 std::stack<wxString> sexprs;
275 wxString partial;
276 wxString last;
277 wxString constraintType;
278 int context = NONE;
279 int expr_context = NONE;
280
281 for( int i = startPos; i < currentPos; ++i )
282 {
283 wxChar c = m_textEditor->GetCharAt( i );
284
285 if( c == '\\' )
286 {
287 i++; // skip escaped char
288 }
289 else if( context == STRING )
290 {
291 if( c == '"' )
292 {
293 context = NONE;
294 }
295 else
296 {
297 if( expr_context == STRING )
298 {
299 if( c == '\'' )
300 expr_context = NONE;
301 else
302 partial += c;
303 }
304 else if( c == '\'' )
305 {
306 last = partial;
307 partial = wxEmptyString;
308 expr_context = STRING;
309 }
310 else if( c == '.' )
311 {
312 partial = wxEmptyString;
313 expr_context = STRUCT_REF;
314 }
315 else
316 {
317 partial += c;
318 }
319 }
320 }
321 else if( c == '"' )
322 {
323 last = partial;
324 partial = wxEmptyString;
325 context = STRING;
326 }
327 else if( c == '(' )
328 {
329 if( context == SEXPR_OPEN && !partial.IsEmpty() )
330 {
331 m_textEditor->AutoCompCancel();
332 sexprs.push( partial );
333 }
334
335 partial = wxEmptyString;
336 context = SEXPR_OPEN;
337 }
338 else if( c == ')' )
339 {
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" ) ) )
345 {
346 sexprs.pop();
347 }
348
349 if( !sexprs.empty() )
350 {
351 // Ignore argument-less tokens
352 if( partial == wxT( "within_diff_pairs" ) )
353 {
354 partial = wxEmptyString;
355 }
356 else
357 {
358 if( sexprs.top() == wxT( "constraint" ) )
359 {
360 constraintType = wxEmptyString;
361 }
362
363 sexprs.pop();
364 }
365 }
366
367 context = NONE;
368 }
369 else if( c == ' ' )
370 {
371 if( context == SEXPR_OPEN && !partial.IsEmpty() )
372 {
373 m_textEditor->AutoCompCancel();
374 sexprs.push( partial );
375
376 if( partial == wxT( "constraint" )
377 || partial == wxT( "layer" )
378 || partial == wxT( "severity" ) )
379 {
380 context = SEXPR_TOKEN;
381 }
382 else if( partial == wxT( "rule" )
383 || partial == wxT( "condition" ) )
384 {
385 context = SEXPR_STRING;
386 }
387 else
388 {
389 context = NONE;
390 }
391
392 partial = wxEmptyString;
393 continue;
394 }
395 else if( partial == wxT( "disallow" )
396 || isDisallowToken( partial )
397 || partial == wxT( "min_resolved_spokes" )
398 || partial == wxT( "zone_connection" ) )
399 {
400 m_textEditor->AutoCompCancel();
401 sexprs.push( partial );
402
403 partial = wxEmptyString;
404 context = SEXPR_TOKEN;
405 continue;
406 }
407 else if( partial == wxT( "assertion" ) )
408 {
409 m_textEditor->AutoCompCancel();
410 sexprs.push( partial );
411
412 partial = wxEmptyString;
413 context = SEXPR_STRING;
414 continue;
415 }
416 else if( isConstraintTypeToken( partial ) )
417 {
418 constraintType = partial;
419 }
420
421 context = NONE;
422 }
423 else
424 {
425 partial += c;
426 }
427 }
428
429 wxString tokens;
430
431 if( context == SEXPR_OPEN )
432 {
433 if( sexprs.empty() )
434 {
435 tokens = wxT( "rule|"
436 "version" );
437 }
438 else if( sexprs.top() == wxT( "rule" ) )
439 {
440 tokens = wxT( "condition|"
441 "constraint|"
442 "layer|"
443 "severity" );
444 }
445 else if( sexprs.top() == wxT( "constraint" ) )
446 {
447 if( constraintType == wxT( "skew" ) )
448 tokens = wxT( "max|min|opt|within_diff_pairs" );
449 else
450 tokens = wxT( "max|min|opt" );
451 }
452 }
453 else if( context == SEXPR_TOKEN )
454 {
455 if( sexprs.empty() )
456 {
457 /* badly formed grammar */
458 }
459 else if( sexprs.top() == wxT( "constraint" ) )
460 {
461 tokens = wxT( "annular_width|"
462 "assertion|"
463 "clearance|"
464 "connection_width|"
465 "courtyard_clearance|"
466 "creepage|"
467 "diff_pair_gap|"
468 "diff_pair_uncoupled|"
469 "disallow|"
470 "edge_clearance|"
471 "length|"
472 "hole_clearance|"
473 "hole_size|"
474 "hole_to_hole|"
475 "min_resolved_spokes|"
476 "physical_clearance|"
477 "physical_hole_clearance|"
478 "silk_clearance|"
479 "skew|"
480 "text_height|"
481 "text_thickness|"
482 "thermal_relief_gap|"
483 "thermal_spoke_width|"
484 "track_width|"
485 "track_angle|"
486 "track_segment_length|"
487 "via_count|"
488 "via_diameter|"
489 "zone_connection" );
490 }
491 else if( sexprs.top() == wxT( "disallow" ) || isDisallowToken( sexprs.top() ) )
492 {
493 tokens = wxT( "buried_via|"
494 "footprint|"
495 "graphic|"
496 "hole|"
497 "micro_via|"
498 "pad|"
499 "text|"
500 "track|"
501 "via|"
502 "zone" );
503 }
504 else if( sexprs.top() == wxT( "zone_connection" ) )
505 {
506 tokens = wxT( "none|solid|thermal_reliefs" );
507 }
508 else if( sexprs.top() == wxT( "min_resolved_spokes" ) )
509 {
510 tokens = wxT( "0|1|2|3|4" );
511 }
512 else if( sexprs.top() == wxT( "layer" ) )
513 {
514 tokens = wxT( "inner|outer|\"x\"" );
515 }
516 else if( sexprs.top() == wxT( "severity" ) )
517 {
518 tokens = wxT( "warning|error|ignore|exclusion" );
519 }
520 }
521 else if( context == SEXPR_STRING && !sexprs.empty()
522 && ( sexprs.top() == wxT( "condition" ) || sexprs.top() == wxT( "assertion" ) ) )
523 {
524 m_textEditor->AddText( wxT( "\"" ) );
525 }
526 else if( context == STRING && !sexprs.empty()
527 && ( sexprs.top() == wxT( "condition" ) || sexprs.top() == wxT( "assertion" ) ) )
528 {
529 if( expr_context == STRUCT_REF )
530 {
532 std::set<wxString> propNames;
533
534 for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
535 {
536 const PROPERTY_LIST& props = propMgr.GetProperties( cls.type );
537
538 for( PROPERTY_BASE* prop : props )
539 {
540 // TODO: It would be nice to replace IsHiddenFromRulesEditor with a nickname
541 // system, so that two different properies don't need to be created. This is
542 // a bigger change than I want to make right now, though.
543 if( prop->IsHiddenFromRulesEditor() )
544 continue;
545
546 wxString ref( prop->Name() );
547 ref.Replace( wxT( " " ), wxT( "_" ) );
548 propNames.insert( ref );
549 }
550 }
551
552 for( const wxString& propName : propNames )
553 tokens += wxT( "|" ) + propName;
554
556
557 for( const wxString& funcSig : functions.GetSignatures() )
558 {
559 if( !funcSig.Contains( "DEPRECATED" ) )
560 tokens += wxT( "|" ) + funcSig;
561 }
562 }
563 else if( expr_context == STRING )
564 {
565 if( m_netClassRegex.Matches( last ) )
566 {
568 std::shared_ptr<NET_SETTINGS>& netSettings = bds.m_NetSettings;
569
570 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
571 tokens += wxT( "|" ) + name;
572 }
573 else if( m_netNameRegex.Matches( last ) )
574 {
575 BOARD* board = m_frame->GetBoard();
576
577 for( const wxString& netnameCandidate : board->GetNetClassAssignmentCandidates() )
578 tokens += wxT( "|" ) + netnameCandidate;
579 }
580 else if( m_typeRegex.Matches( last ) )
581 {
582 tokens = wxT( "Bitmap|"
583 "Dimension|"
584 "Footprint|"
585 "Graphic|"
586 "Group|"
587 "Leader|"
588 "Pad|"
589 "Target|"
590 "Text|"
591 "Text Box|"
592 "Track|"
593 "Via|"
594 "Zone" );
595 }
596 else if( m_viaTypeRegex.Matches( last ) )
597 {
598 tokens = wxT( "Through|"
599 "Blind/buried|"
600 "Micro" );
601 }
602 else if( m_padTypeRegex.Matches( last ) )
603 {
604 tokens = wxT( "Through-hole|"
605 "SMD|"
606 "Edge connector|"
607 "NPTH, mechanical" );
608 }
609 else if( m_pinTypeRegex.Matches( last ) )
610 {
611 tokens = wxT( "Input|"
612 "Output|"
613 "Bidirectional|"
614 "Tri-state|"
615 "Passive|"
616 "Free|"
617 "Unspecified|"
618 "Power input|"
619 "Power output|"
620 "Open collector|"
621 "Open emitter|"
622 "Unconnected" );
623 }
624 else if( m_fabPropRegex.Matches( last ) )
625 {
626 tokens = wxT( "None|"
627 "BGA pad|"
628 "Fiducial, global to board|"
629 "Fiducial, local to footprint|"
630 "Test point pad|"
631 "Heatsink pad|"
632 "Castellated pad" );
633 }
634 else if( m_shapeRegex.Matches( last ) )
635 {
636 tokens = wxT( "Segment|"
637 "Rectangle|"
638 "Arc|"
639 "Circle|"
640 "Polygon|"
641 "Bezier" );
642 }
643 else if( m_padShapeRegex.Matches( last ) )
644 {
645 tokens = wxT( "Circle|"
646 "Rectangle|"
647 "Oval|"
648 "Trapezoid|"
649 "Rounded rectangle|"
650 "Chamfered rectangle|"
651 "Custom" );
652 }
653 else if( m_padConnectionsRegex.Matches( last ) )
654 {
655 tokens = wxT( "Inherited|"
656 "None|"
657 "Solid|"
658 "Thermal reliefs|"
659 "Thermal reliefs for PTH" );
660 }
661 else if( m_zoneConnStyleRegex.Matches( last ) )
662 {
663 tokens = wxT( "Inherited|"
664 "None|"
665 "Solid|"
666 "Thermal reliefs" );
667 }
668 else if( m_lineStyleRegex.Matches( last ) )
669 {
670 tokens = wxT( "Default|"
671 "Solid|"
672 "Dashed|"
673 "Dotted|"
674 "Dash-Dot|"
675 "Dash-Dot-Dot" );
676 }
677 else if( m_hJustRegex.Matches( last ) )
678 {
679 tokens = wxT( "Left|"
680 "Center|"
681 "Right" );
682 }
683 else if( m_vJustRegex.Matches( last ) )
684 {
685 tokens = wxT( "Top|"
686 "Center|"
687 "Bottom" );
688 }
689 }
690 }
691
692 if( !tokens.IsEmpty() )
693 m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, '|' ) );
694}
695
696
697void PANEL_SETUP_RULES::OnCompile( wxCommandEvent& event )
698{
700
701 try
702 {
703 std::vector<std::shared_ptr<DRC_RULE>> dummyRules;
704
705 DRC_RULES_PARSER parser( m_textEditor->GetText(), _( "DRC rules" ) );
706
707 parser.Parse( dummyRules, m_errorsReport );
708 }
709 catch( PARSE_ERROR& pe )
710 {
711 wxString msg = wxString::Format( wxT( "%s <a href='%d:%d'>%s</a>%s" ),
712 _( "ERROR:" ),
713 pe.lineNumber,
714 pe.byteIndex,
715 pe.ParseProblem(),
716 wxEmptyString );
717
719 }
720
722}
723
724
725void PANEL_SETUP_RULES::OnErrorLinkClicked( wxHtmlLinkEvent& event )
726{
727 wxString link = event.GetLinkInfo().GetHref();
728 wxArrayString parts;
729 long line = 0, offset = 0;
730
731 wxStringSplit( link, parts, ':' );
732
733 if( parts.size() > 1 )
734 {
735 parts[0].ToLong( &line );
736 parts[1].ToLong( &offset );
737 }
738
739 int pos = m_textEditor->PositionFromLine( line - 1 ) + ( offset - 1 );
740
741 m_textEditor->GotoPos( pos );
742
743 m_textEditor->SetFocus();
744}
745
746
748{
749 wxFileName rulesFile( m_frame->GetDesignRulesPath() );
750
751 if( rulesFile.FileExists() )
752 {
753 wxTextFile file( rulesFile.GetFullPath() );
754
755 if( file.Open() )
756 {
757 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
758 {
760 m_textEditor->AddText( str << '\n' );
761 }
762
763 m_textEditor->EmptyUndoBuffer();
764
765 wxCommandEvent dummy;
766 OnCompile( dummy );
767 }
768 }
769 else
770 {
771 m_textEditor->AddText( wxT( "(version 1)\n" ) );
772 }
773
774 m_originalText = m_textEditor->GetText();
775
776 if( m_frame->Prj().IsNullProject() )
777 {
778 m_textEditor->ClearAll();
779 m_textEditor->AddText( _( "Design rules cannot be added without a project" ) );
780 m_textEditor->Disable();
781 }
782
783 return true;
784}
785
786
788{
789 if( m_originalText == m_textEditor->GetText() )
790 return true;
791
792 if( m_frame->Prj().IsNullProject() )
793 return true;
794
795 wxString rulesFilepath = m_frame->GetDesignRulesPath();
796
797 try
798 {
799 if( m_textEditor->SaveFile( rulesFilepath ) )
800 {
801 m_frame->GetBoard()->GetDesignSettings().m_DRCEngine->InitEngine( rulesFilepath );
802 return true;
803 }
804 }
805 catch( PARSE_ERROR& )
806 {
807 // Don't lock them in to the Setup dialog if they have bad rules. They've already
808 // saved them so we can allow an exit.
809 return true;
810 }
811
812 return false;
813}
814
815
816void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
817{
818 if( m_helpWindow )
819 {
821 return;
822 }
823 std::vector<wxString> msg;
824 msg.clear();
825
826 wxString t =
828 ;
829 msg.emplace_back( t );
830 t =
832 ;
833 msg.emplace_back( t );
834 t =
836 ;
837 msg.emplace_back( t );
838 t =
840 ;
841 msg.emplace_back( t );
842 t =
844 ;
845 msg.emplace_back( t );
846 t =
848 ;
849 msg.emplace_back( t );
850 t =
852 ;
853 msg.emplace_back( t );
854 t =
856 ;
857 msg.emplace_back( t );
858 t =
860 ;
861 msg.emplace_back( t );
862 t =
864 ;
865 msg.emplace_back( t );
866
867 wxString msg_txt = wxEmptyString;
868
869 for( wxString i : msg )
870 msg_txt << wxGetTranslation( i );
871
872#ifdef __WXMAC__
873 msg_txt.Replace( wxT( "Ctrl+" ), wxT( "Cmd+" ) );
874#endif
875 const wxString& msGg_txt = msg_txt;
876
877 m_helpWindow = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
878 m_helpWindow->SetDialogSizeInDU( 420, 320 );
879
880 wxString html_txt = wxEmptyString;
881 ConvertMarkdown2Html( msGg_txt, html_txt );
882
883 html_txt.Replace( wxS( "<td" ), wxS( "<td valign=top" ) );
884 m_helpWindow->AddHTML_Text( html_txt );
885
887}
888
889
891{
892 if( !m_frame->Prj().IsNullProject() )
893 {
894 wxFileName relFile = aBoard->GetFileName();
895 relFile.SetExt( FILEEXT::DesignRulesFileExtension );
896
897 wxFileName absFile( aBoard->GetProject()->AbsolutePath( relFile.GetFullName() ) );
898
899 if( absFile.FileExists() )
900 {
901 wxTextFile file( absFile.GetFullPath() );
902
903 if( file.Open() )
904 {
905 m_textEditor->ClearAll();
906
907 for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
908 {
910 m_textEditor->AddText( str << '\n' );
911 }
912
913 m_textEditor->EmptyUndoBuffer();
914
915 wxCommandEvent dummy;
916 OnCompile( dummy );
917 }
918 }
919 }
920}
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:290
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition: board.cpp:2028
const wxString & GetFileName() const
Definition: board.h:327
PROJECT * GetProject() const
Definition: board.h:491
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:892
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:679
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:1060
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.