KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_drc_rule_editor.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) 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, see <https://www.gnu.org/licenses/>.
18 */
19
23#include <wx/log.h>
24#include <wx/regex.h>
25
26#include <pgm_base.h>
29#include <template_fieldnames.h>
30#include <grid_tricks.h>
31#include <eda_text.h>
33#include <bitmaps.h>
34#include <confirm.h>
35#include <kidialog.h>
36#include <layer_ids.h>
37#include <layer_range.h>
38#include <board.h>
40#include <scintilla_tricks.h>
41#include <wx/stc/stc.h>
43#include <wx/scrolwin.h>
44#include <wx/toplevel.h>
45#include <tools/drc_tool.h>
46#include <pcbexpr_evaluator.h>
47#include <string_utils.h>
48#include <drc_rules_lexer.h>
49
50#include <drc/drc_rule_parser.h>
65
66#include <eda_units.h>
80#include <properties/property.h>
82
83static constexpr const wxChar* KI_TRACE_DRC_RULE_EDITOR = wxT( "KI_TRACE_DRC_RULE_EDITOR" );
84
86{
87 switch( aConstraintType )
88 {
93 case HOLE_TO_HOLE_DISTANCE: return true;
94 default: return false;
95 }
96}
97
99 DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType,
100 std::shared_ptr<DRC_RE_BASE_CONSTRAINT_DATA> aConstraintData ) :
102 m_board( aBoard ),
103 m_validationSucceeded( false ),
104 m_modified( false ),
105 m_constraintData( aConstraintData ),
106 m_helpWindow( nullptr )
107{
108 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "[PANEL_DRC_RULE_EDITOR] ctor START" ) );
109
110 SetBorders( true, false, false, false );
111
112 m_constraintType = aConstraintType;
113 m_constraintPanel = getConstraintPanel( this, aConstraintType );
114 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "[PANEL_DRC_RULE_EDITOR] adding constraint panel to sizer" ) );
115 m_constraintContentSizer->Add( dynamic_cast<wxPanel*>( m_constraintPanel ), 0, wxEXPAND | wxTOP, 5 );
116 m_layerList = m_board->GetEnabledLayers().UIOrder();
118 m_staticline3->Hide();
119
120 m_nameCtrl->SetToolTip( _( "Name of this rule, must be unique" ) );
121 m_commentCtrl->SetToolTip( _( "Optional comment stored with the rule" ) );
122
123 m_layerListChoiceCtrl = new wxChoice( this, wxID_ANY );
124 m_layerListChoiceCtrl->SetToolTip( _( "Layers this rule applies to" ) );
127 m_LayersComboBoxSizer->Add( m_layerListChoiceCtrl, 0, wxALL | wxEXPAND, 5 );
128 // Hide layer selector for constraints where it doesn't apply
130 {
131 m_LayersComboBoxSizer->Show( false );
132 m_staticText711->Show( false );
133 m_staticline111->Show( false );
134 }
135
136 wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
138 new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END );
139 m_btnShowMatches = new wxButton( this, wxID_ANY, _( "Show Matches" ) );
140 buttonSizer->Add( m_matchReport, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5 );
141 buttonSizer->Add( m_btnShowMatches, 0, wxALL, 5 );
142
143 bContentSizer->Add( buttonSizer, 0, wxEXPAND | wxALL, 2 );
144
146
147 Bind( wxEVT_TEXT, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
148 Bind( wxEVT_CHOICE, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
149 Bind( wxEVT_COMBOBOX, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
150 Bind( wxEVT_CHECKBOX, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
151 Bind( wxEVT_CHECKLISTBOX, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
152 Bind( wxEVT_RADIOBUTTON, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
153 Bind( wxEVT_STC_CHANGE, &PANEL_DRC_RULE_EDITOR::onFieldChanged, this );
154
155 // Enter in any of the illustration's fields applies the rule. The fields carry
156 // wxTE_PROCESS_ENTER, so the event reaches this panel on its way up.
157 Bind( wxEVT_TEXT_ENTER, &PANEL_DRC_RULE_EDITOR::OnEnterKey, this );
158
159 m_btnShowMatches->Enable( true );
160
162
163 m_scintillaTricks = std::make_unique<SCINTILLA_TRICKS>(
164 m_textConditionCtrl, wxT( "()" ), false,
165 // onAcceptFn
166 [this]( wxKeyEvent& aEvent )
167 {
168 wxPostEvent( PAGED_DIALOG::GetDialog( this ), wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
169 },
170 // onCharFn
171 [this]( wxStyledTextEvent& aEvent )
172 {
173 onScintillaCharAdded( aEvent );
174 } );
175
176 m_textConditionCtrl->AutoCompSetSeparator( '|' );
177
178 // Hide the base class text control since we use the condition group panel
179 m_textConditionCtrl->Hide();
180
181 bool twoObjects = constraintNeedsTwoObjects( aConstraintType );
182
183 // Create condition group panel (multi-condition UI)
184 // Each condition row has its own custom query text control
185 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "[PANEL_DRC_RULE_EDITOR] creating conditionGroupPanel" ) );
187 m_conditionGroupPanel->SetChangeCallback(
188 [this]()
189 {
190 m_modified = true;
192 RelayoutHost();
193
196 } );
197
198 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "[PANEL_DRC_RULE_EDITOR] inserting conditionGroupPanel" ) );
199 m_conditionControlsSizer->Insert( 0, m_conditionGroupPanel, 0, wxEXPAND | wxBOTTOM, 5 );
200
201 if( aConstraintType == CUSTOM_RULE )
202 {
203 m_conditionGroupPanel->Hide();
205 m_syntaxHelp->Hide();
206 m_staticline8->Hide();
207 m_LayersComboBoxSizer->Show( false );
208 m_staticText711->Hide();
209 m_staticline111->Hide();
210
212 }
213
214 // Hide the base class syntax check controls since we use inline validation
215 m_checkSyntaxBtnCtrl->Hide();
216 m_syntaxErrorReport->Hide();
217
218 m_nameCtrl->Bind( wxEVT_TEXT,
219 [this]( wxCommandEvent& aEvent )
220 {
222 {
223 auto* customPanel = dynamic_cast<DRC_RE_CUSTOM_RULE_PANEL*>( m_constraintPanel );
224
225 if( customPanel )
226 customPanel->UpdateRuleName( m_nameCtrl->GetValue() );
227 }
228
229 aEvent.Skip();
230 } );
231
232 // Regex patterns are compiled as function-local statics in onScintillaCharAdded()
233 // to avoid recompilation on every panel creation.
234}
235
236
243
244
246{
247 if( m_constraintData )
248 {
249 m_nameCtrl->ChangeValue( m_constraintData->GetRuleName() );
250 m_commentCtrl->ChangeValue( m_constraintData->GetComment() );
251 setSelectedLayers( m_constraintData->GetLayers(), m_constraintData->GetLayerSource() );
252 wxString cond = m_constraintData->GetRuleCondition();
253
254 // Use the new condition group panel
255 // Each row manages its own custom query text control visibility
256 m_conditionGroupPanel->ParseCondition( cond );
257 }
258
259 bool transferred = true;
260
262 transferred = m_constraintPanel->TransferDataToWindow();
263
264 m_modified = false;
265
266 return transferred;
267}
268
269
271{
272 m_modified = true;
274
277
278 aEvent.Skip();
279}
280
281
283{
284 return m_conditionGroupPanel ? m_conditionGroupPanel->BuildCondition() : wxString();
285}
286
287
289{
291 return wxEmptyString;
292
293 int sel = m_layerListChoiceCtrl->GetSelection();
294 if( sel <= 0 )
295 return wxEmptyString;
296
297 int layerValue = m_layerIDs[sel - 1];
298
299 switch( layerValue )
300 {
301 case LAYER_SEL_OUTER: return DRC_RULES_LEXER::TokenName( DRCRULE_T::T_outer );
302 case LAYER_SEL_INNER: return DRC_RULES_LEXER::TokenName( DRCRULE_T::T_inner );
303 case LAYER_SEL_TOP:
304 case LAYER_SEL_BOTTOM:
306 default:
307 if( layerValue >= 0 )
308 return LSET::Name( static_cast<PCB_LAYER_ID>( layerValue ) );
309
310 return wxEmptyString;
311 }
312}
313
314
316{
318 m_constraintPanel->TransferDataFromWindow();
319
320 m_constraintData->SetRuleName( m_nameCtrl->GetValue() );
321 m_constraintData->SetComment( m_commentCtrl->GetValue() );
322 m_constraintData->SetLayers( getSelectedLayers() );
323 m_constraintData->SetLayerSource( getSelectedLayerSource() );
324
325 // Use the new condition group panel
326 wxString combined = m_conditionGroupPanel->BuildCondition();
327 m_constraintData->SetRuleCondition( combined );
328
330 context.ruleName = m_nameCtrl->GetValue();
331 context.comment = m_commentCtrl->GetValue();
333 context.layerClause = buildLayerClause();
334 context.constraintCode = m_constraintData->GetConstraintCode();
335
336 wxString generatedRule = m_constraintPanel->GenerateRule( context );
337 m_constraintData->SetGeneratedRule( generatedRule );
338
339 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "Generated rule '%s':\n%s" ),
340 context.ruleName, generatedRule );
341
342 return true;
343}
344
345
348{
349 EDA_UNITS units = EDA_UNITS::MM;
350
351 for( wxWindow* win = GetParent(); win; win = win->GetParent() )
352 {
353 if( auto* frame = dynamic_cast<EDA_BASE_FRAME*>( win ) )
354 {
355 units = frame->GetUserUnits();
356 break;
357 }
358 }
359
360 switch( aConstraintType )
361 {
362 case VIA_STYLE:
364 aParent,
365 dynamic_pointer_cast<DRC_RE_VIA_STYLE_CONSTRAINT_DATA>( m_constraintData ).get(),
366 units );
367
370 aParent,
371 dynamic_pointer_cast<DRC_RE_MINIMUM_TEXT_HEIGHT_THICKNESS_CONSTRAINT_DATA>( m_constraintData ).get(),
372 units );
373
376 aParent,
377 dynamic_pointer_cast<DRC_RE_ROUTING_DIFF_PAIR_CONSTRAINT_DATA>( m_constraintData ).get(),
378 units );
379
380 case ROUTING_WIDTH:
382 aParent,
383 dynamic_pointer_cast<DRC_RE_ROUTING_WIDTH_CONSTRAINT_DATA>( m_constraintData ).get(),
384 units );
385
386 case PERMITTED_LAYERS:
388 aParent,
389 dynamic_pointer_cast<DRC_RE_PERMITTED_LAYERS_CONSTRAINT_DATA>( m_constraintData ).get() );
390
393 aParent,
394 dynamic_pointer_cast<DRC_RE_ALLOWED_ORIENTATION_CONSTRAINT_DATA>( m_constraintData ).get() );
395
396 case VIAS_UNDER_SMD:
398 aParent, dynamic_pointer_cast<DRC_RE_VIAS_UNDER_SMD_CONSTRAINT_DATA>( m_constraintData ).get() );
399
400 case CUSTOM_RULE:
401 return new DRC_RE_CUSTOM_RULE_PANEL(
402 aParent, dynamic_pointer_cast<DRC_RE_CUSTOM_RULE_CONSTRAINT_DATA>( m_constraintData ) );
403
406 aParent,
407 dynamic_pointer_cast<DRC_RE_MATCHED_LENGTH_DIFF_PAIR_CONSTRAINT_DATA>( m_constraintData ).get(),
408 units );
409
410 case ABSOLUTE_LENGTH:
412 aParent,
413 dynamic_pointer_cast<DRC_RE_ABSOLUTE_LENGTH_TWO_CONSTRAINT_DATA>( m_constraintData ).get(),
414 units );
415
416 default:
417 if( DRC_RULE_EDITOR_UTILS::IsNumericInputType( aConstraintType ) )
418 {
420 aParent,
421 dynamic_pointer_cast<DRC_RE_NUMERIC_INPUT_CONSTRAINT_DATA>( m_constraintData ).get(),
422 units );
423 }
424 else if( DRC_RULE_EDITOR_UTILS::IsBoolInputType( aConstraintType ) )
425 {
427 aParent,
428 dynamic_pointer_cast<DRC_RE_BOOL_INPUT_CONSTRAINT_DATA>( m_constraintData ).get() );
429 }
430 else
431 {
432 return nullptr;
433 };
434 }
435}
436
437
438bool PANEL_DRC_RULE_EDITOR::ValidateInputs( int* aErrorCount, wxString* aValidationMessage )
439{
440 if( !m_callBackRuleNameValidation( m_constraintData->GetId(), m_nameCtrl->GetValue() ) )
441 {
442 m_validationSucceeded = false;
443 ( *aErrorCount )++;
445 DRC_RULE_EDITOR_UTILS::FormatErrorMessage( *aErrorCount, _( "Rule name must be unique." ) );
446 }
447
448 if( m_layerListChoiceCtrl->GetSelection() == wxNOT_FOUND )
449 {
450 m_validationSucceeded = false;
451 ( *aErrorCount )++;
453 DRC_RULE_EDITOR_UTILS::FormatErrorMessage( *aErrorCount, _( "Layer selection is required." ) );
454 }
455
457}
458
459
461{
462 return m_constraintPanel->GenerateRule( aContext );
463}
464
465
467{
469 int errorCount = 0;
470 m_validationMessage.Clear();
471
472 ValidateInputs( &errorCount, &m_validationMessage );
473
474 if( !m_constraintPanel->ValidateInputs( &errorCount, &m_validationMessage ) )
475 {
476 m_validationSucceeded = false;
477 }
478
480}
481
482
483void PANEL_DRC_RULE_EDITOR::onSaveButtonClicked( wxCommandEvent& aEvent )
484{
485 ValidateRule();
486
487 if( m_callBackSave )
488 {
490 }
491
493 m_btnShowMatches->Enable( true );
494}
495
496
497void PANEL_DRC_RULE_EDITOR::OnEnterKey( wxCommandEvent& aEvent )
498{
499 onSaveButtonClicked( aEvent );
500}
501
502
503void PANEL_DRC_RULE_EDITOR::Save( wxCommandEvent& aEvent )
504{
505 onSaveButtonClicked( aEvent );
506}
507
508
509void PANEL_DRC_RULE_EDITOR::onScintillaCharAdded( wxStyledTextEvent& aEvent )
510{
511 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKey() == ' ' )
512 {
513 // This is just a short-cut for do-auto-complete
514 }
515
516 m_textConditionCtrl->SearchAnchor();
517
518 int currentPos = m_textConditionCtrl->GetCurrentPos();
519 int startPos = 0;
520
521 for( int line = m_textConditionCtrl->LineFromPosition( currentPos ); line > 0; line-- )
522 {
523 int lineStart = m_textConditionCtrl->PositionFromLine( line );
524 wxString beginning = m_textConditionCtrl->GetTextRange( lineStart, lineStart + 10 );
525
526 if( beginning.StartsWith( wxT( "(condition " ) ) )
527 {
528 startPos = lineStart;
529 break;
530 }
531 }
532
533 enum class EXPR_CONTEXT_T : int
534 {
535 NONE,
536 STRING,
537 SEXPR_OPEN,
538 SEXPR_TOKEN,
539 SEXPR_STRING,
540 STRUCT_REF
541 };
542
543 std::stack<wxString> sexprs;
544 wxString partial;
545 wxString last;
546 EXPR_CONTEXT_T context = EXPR_CONTEXT_T::NONE;
547 EXPR_CONTEXT_T expr_context = EXPR_CONTEXT_T::NONE;
548
549 for( int i = startPos; i < currentPos; ++i )
550 {
551 wxChar c = m_textConditionCtrl->GetCharAt( i );
552
553 if( c == '\\' )
554 {
555 i++; // skip escaped char
556 }
557 else if( context == EXPR_CONTEXT_T::STRING )
558 {
559 if( c == '"' )
560 {
561 context = EXPR_CONTEXT_T::NONE;
562 }
563 else
564 {
565 if( expr_context == EXPR_CONTEXT_T::STRING )
566 {
567 if( c == '\'' )
568 expr_context = EXPR_CONTEXT_T::NONE;
569 else
570 partial += c;
571 }
572 else if( c == '\'' )
573 {
574 last = partial;
575 partial = wxEmptyString;
576 expr_context = EXPR_CONTEXT_T::STRING;
577 }
578 else if( c == '.' )
579 {
580 partial = wxEmptyString;
581 expr_context = EXPR_CONTEXT_T::STRUCT_REF;
582 }
583 else
584 {
585 partial += c;
586 }
587 }
588 }
589 else if( c == '"' )
590 {
591 last = partial;
592 partial = wxEmptyString;
593 context = EXPR_CONTEXT_T::STRING;
594 }
595 else if( c == '(' )
596 {
597 if( context == EXPR_CONTEXT_T::SEXPR_OPEN && !partial.IsEmpty() )
598 {
599 m_textConditionCtrl->AutoCompCancel();
600 sexprs.push( partial );
601 }
602
603 partial = wxEmptyString;
604 context = EXPR_CONTEXT_T::SEXPR_OPEN;
605 }
606 else if( c == ')' )
607 {
608 context = EXPR_CONTEXT_T::NONE;
609 }
610 else if( c == ' ' )
611 {
612 if( context == EXPR_CONTEXT_T::SEXPR_OPEN && !partial.IsEmpty() )
613 {
614 m_textConditionCtrl->AutoCompCancel();
615 sexprs.push( partial );
616
617 if( partial == wxT( "condition" ) )
618 {
619 context = EXPR_CONTEXT_T::SEXPR_STRING;
620 }
621 else
622 {
623 context = EXPR_CONTEXT_T::NONE;
624 }
625
626 partial = wxEmptyString;
627 continue;
628 }
629
630 context = EXPR_CONTEXT_T::NONE;
631 }
632 else
633 {
634 partial += c;
635 }
636 }
637
638 wxString tokens;
639
640 if( context == EXPR_CONTEXT_T::SEXPR_OPEN )
641 {
642 if( sexprs.empty() )
643 {
644 tokens = wxT( "condition" );
645 }
646 }
647 else if( context == EXPR_CONTEXT_T::SEXPR_TOKEN )
648 {
649 if( sexprs.empty() )
650 {
651 /* badly formed grammar */
652 }
653 }
654 else if( context == EXPR_CONTEXT_T::SEXPR_STRING && !sexprs.empty() && sexprs.top() == wxT( "condition" ) )
655 {
656 m_textConditionCtrl->AddText( wxT( "\"" ) );
657 }
658 else if( context == EXPR_CONTEXT_T::STRING && !sexprs.empty() && sexprs.top() == wxT( "condition" ) )
659 {
660 if( expr_context == EXPR_CONTEXT_T::STRUCT_REF )
661 {
663 std::set<wxString> propNames;
664
665 for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
666 {
667 const std::vector<PROPERTY_BASE*>& props = propMgr.GetProperties( cls.type );
668
669 for( PROPERTY_BASE* prop : props )
670 {
671 // TODO: It would be nice to replace IsHiddenFromRulesEditor with a nickname
672 // system, so that two different properies don't need to be created. This is
673 // a bigger change than I want to make right now, though.
674 if( prop->IsHiddenFromRulesEditor() )
675 continue;
676
677 wxString ref( prop->Name() );
678 ref.Replace( wxT( " " ), wxT( "_" ) );
679 propNames.insert( ref );
680 }
681 }
682
683 for( const wxString& propName : propNames )
684 tokens += wxT( "|" ) + propName;
685
687
688 for( const wxString& funcSig : functions.GetSignatures() )
689 {
690 if( !funcSig.Contains( "DEPRECATED" ) )
691 tokens += wxT( "|" ) + funcSig;
692 }
693 }
694 else if( expr_context == EXPR_CONTEXT_T::STRING )
695 {
696 static wxRegEx netClassRegex( wxS( "^NetClass\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
697 static wxRegEx netNameRegex( wxS( "^NetName\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
698 static wxRegEx typeRegex( wxS( "^Type\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
699 static wxRegEx viaTypeRegex( wxS( "^Via_Type\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
700 static wxRegEx padTypeRegex( wxS( "^Pad_Type\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
701 static wxRegEx pinTypeRegex( wxS( "^Pin_Type\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
702 static wxRegEx fabPropRegex( wxS( "^Fabrication_Property\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
703 static wxRegEx shapeRegex( wxS( "^Shape\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
704 static wxRegEx padShapeRegex( wxS( "^Pad_Shape\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
705 static wxRegEx padConnectionsRegex( wxS( "^Pad_Connections\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
706 static wxRegEx zoneConnStyleRegex( wxS( "^Zone_Connection_Style\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
707 static wxRegEx lineStyleRegex( wxS( "^Line_Style\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
708 static wxRegEx hJustRegex( wxS( "^Horizontal_Justification\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
709 static wxRegEx vJustRegex( wxS( "^Vertical_Justification\\s*[!=]=\\s*$" ), wxRE_ADVANCED );
710
711 if( netClassRegex.Matches( last ) )
712 {
713 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
714 std::shared_ptr<NET_SETTINGS>& netSettings = bds.m_NetSettings;
715
716 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
717 tokens += wxT( "|" ) + name;
718 }
719 else if( netNameRegex.Matches( last ) )
720 {
721 for( const wxString& netnameCandidate : m_board->GetNetClassAssignmentCandidates() )
722 tokens += wxT( "|" ) + netnameCandidate;
723 }
724 else if( typeRegex.Matches( last ) )
725 {
726 tokens = wxT( "Bitmap|"
727 "Dimension|"
728 "Footprint|"
729 "Graphic|"
730 "Group|"
731 "Leader|"
732 "Pad|"
733 "Target|"
734 "Text|"
735 "Text Box|"
736 "Track|"
737 "Via|"
738 "Zone" );
739 }
740 else if( viaTypeRegex.Matches( last ) )
741 {
742 tokens = wxT( "Through|"
743 "Blind/buried|"
744 "Micro" );
745 }
746 else if( padTypeRegex.Matches( last ) )
747 {
748 tokens = wxT( "Through-hole|"
749 "SMD|"
750 "Edge connector|"
751 "NPTH, mechanical" );
752 }
753 else if( pinTypeRegex.Matches( last ) )
754 {
755 tokens = wxT( "Input|"
756 "Output|"
757 "Bidirectional|"
758 "Tri-state|"
759 "Passive|"
760 "Free|"
761 "Unspecified|"
762 "Power input|"
763 "Power output|"
764 "Open collector|"
765 "Open emitter|"
766 "Unconnected" );
767 }
768 else if( fabPropRegex.Matches( last ) )
769 {
770 tokens = wxT( "None|"
771 "BGA pad|"
772 "Fiducial, global to board|"
773 "Fiducial, local to footprint|"
774 "Test point pad|"
775 "Heatsink pad|"
776 "Castellated pad" );
777 }
778 else if( shapeRegex.Matches( last ) )
779 {
780 tokens = wxT( "Segment|"
781 "Rectangle|"
782 "Arc|"
783 "Circle|"
784 "Polygon|"
785 "Bezier" );
786 }
787 else if( padShapeRegex.Matches( last ) )
788 {
789 tokens = wxT( "Circle|"
790 "Rectangle|"
791 "Oval|"
792 "Trapezoid|"
793 "Rounded rectangle|"
794 "Chamfered rectangle|"
795 "Custom" );
796 }
797 else if( padConnectionsRegex.Matches( last ) )
798 {
799 tokens = wxT( "Inherited|"
800 "None|"
801 "Solid|"
802 "Thermal reliefs|"
803 "Thermal reliefs for PTH" );
804 }
805 else if( zoneConnStyleRegex.Matches( last ) )
806 {
807 tokens = wxT( "Inherited|"
808 "None|"
809 "Solid|"
810 "Thermal reliefs" );
811 }
812 else if( lineStyleRegex.Matches( last ) )
813 {
814 tokens = wxT( "Default|"
815 "Solid|"
816 "Dashed|"
817 "Dotted|"
818 "Dash-Dot|"
819 "Dash-Dot-Dot" );
820 }
821 else if( hJustRegex.Matches( last ) )
822 {
823 tokens = wxT( "Left|"
824 "Center|"
825 "Right" );
826 }
827 else if( vJustRegex.Matches( last ) )
828 {
829 tokens = wxT( "Top|"
830 "Center|"
831 "Bottom" );
832 }
833 }
834 }
835
836 if( !tokens.IsEmpty() )
837 m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, '|' ) );
838}
839
840
841void PANEL_DRC_RULE_EDITOR::onSyntaxHelp( wxHyperlinkEvent& aEvent )
842{
843 if( m_helpWindow )
844 {
845 m_helpWindow->ShowModeless();
846 return;
847 }
848
849 std::vector<wxString> msg;
850 msg.clear();
851
852 wxString t =
854 ;
855 msg.emplace_back( t );
856
857 t =
859 ;
860 msg.emplace_back( t );
861
862 t =
864 ;
865 msg.emplace_back( t );
866
867 t =
869 ;
870 msg.emplace_back( t );
871
872 t =
874 ;
875 msg.emplace_back( t );
876
877 t =
879 ;
880 msg.emplace_back( t );
881
882 t =
884 ;
885 msg.emplace_back( t );
886
887 t =
889 ;
890 msg.emplace_back( t );
891
892
893 wxString msg_txt = wxEmptyString;
894
895 for( wxString i : msg )
896 msg_txt << wxGetTranslation( i );
897
898#ifdef __WXMAC__
899 msg_txt.Replace( wxT( "Ctrl+" ), wxT( "Cmd+" ) );
900#endif
901 const wxString& msGg_txt = msg_txt;
902
903 m_helpWindow = new HTML_MESSAGE_BOX( this, _( "Syntax Help" ) );
904 m_helpWindow->SetDialogSizeInDU( 420, 320 );
905
906 wxString html_txt = wxEmptyString;
907 ConvertMarkdown2Html( msGg_txt, html_txt );
908
909 html_txt.Replace( wxS( "<td" ), wxS( "<td valign=top" ) );
910 m_helpWindow->AddHTML_Text( html_txt );
911
912 m_helpWindow->ShowModeless();
913}
914
915
916void PANEL_DRC_RULE_EDITOR::onCheckSyntax( wxCommandEvent& event )
917{
918 m_syntaxErrorReport->Clear();
919
920 // Get the complete condition from the condition group panel
921 wxString condition = m_conditionGroupPanel->BuildCondition();
922
923 if( condition.IsEmpty() )
924 {
925 wxString msg = _( "ERROR: No condition text provided for validation." );
927 m_syntaxErrorReport->Flush();
928 return;
929 }
930
931 try
932 {
933 std::vector<std::shared_ptr<DRC_RULE>> dummyRules;
934 wxString ruleTemplate = L"(version 2)\n(rule default\n (condition \"%s\")\n)";
935 wxString formattedRule = wxString::Format( ruleTemplate, condition );
936 DRC_RULES_PARSER ruleParser( formattedRule, _( "DRC rule" ) );
937 ruleParser.Parse( dummyRules, m_syntaxErrorReport );
938 }
939 catch( PARSE_ERROR& pe )
940 {
941 wxString msg = wxString::Format( wxT( "%s <a href='%d:%d'>%s</a>" ),
942 _( "ERROR:" ),
943 pe.lineNumber, pe.byteIndex, pe.ParseProblem() );
944
946 }
947
948 m_syntaxErrorReport->Flush();
949}
950
951
952void PANEL_DRC_RULE_EDITOR::onErrorLinkClicked( wxHtmlLinkEvent& event )
953{
954 wxString link = event.GetLinkInfo().GetHref();
955 wxArrayString parts;
956 long line = 0, offset = 0;
957
958 wxStringSplit( link, parts, ':' );
959
960 if( parts.size() > 1 )
961 {
962 parts[0].ToLong( &line );
963 parts[1].ToLong( &offset );
964 }
965
966 int pos = m_textConditionCtrl->PositionFromLine( line - 1 ) + ( offset - 1 );
967
968 m_textConditionCtrl->GotoPos( pos );
969
970 m_textConditionCtrl->SetFocus();
971}
972
973
974void PANEL_DRC_RULE_EDITOR::onContextMenu( wxMouseEvent& event )
975{
976 wxMenu menu;
977
978 menu.Append( wxID_UNDO, _( "Undo" ) );
979 menu.Append( wxID_REDO, _( "Redo" ) );
980
981 menu.AppendSeparator();
982
983 menu.Append( 1, _( "Cut" ) ); // Don't use wxID_CUT, wxID_COPY, etc. On Mac (at least),
984 menu.Append( 2, _( "Copy" ) ); // wxWidgets never delivers them to us.
985 menu.Append( 3, _( "Paste" ) );
986 menu.Append( 4, _( "Delete" ) );
987
988 menu.AppendSeparator();
989
990 menu.Append( 5, _( "Select All" ) );
991
992 menu.AppendSeparator();
993
994 menu.Append( wxID_ZOOM_IN, _( "Zoom In" ) );
995 menu.Append( wxID_ZOOM_OUT, _( "Zoom Out" ) );
996
997
998 switch( GetPopupMenuSelectionFromUser( menu ) )
999 {
1000 case wxID_UNDO: m_textConditionCtrl->Undo(); break;
1001 case wxID_REDO: m_textConditionCtrl->Redo(); break;
1002
1003 case 1: m_textConditionCtrl->Cut(); break;
1004 case 2: m_textConditionCtrl->Copy(); break;
1005 case 3: m_textConditionCtrl->Paste(); break;
1006 case 4:
1007 {
1008 long from, to;
1009 m_textConditionCtrl->GetSelection( &from, &to );
1010
1011 if( to > from )
1012 m_textConditionCtrl->DeleteRange( from, to );
1013
1014 break;
1015 }
1016
1017 case 5: m_textConditionCtrl->SelectAll(); break;
1018
1019 case wxID_ZOOM_IN: m_textConditionCtrl->ZoomIn(); break;
1020 case wxID_ZOOM_OUT: m_textConditionCtrl->ZoomOut(); break;
1021 }
1022}
1023
1024
1026{
1027 if( !m_constraintData )
1028 {
1029 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "Show Matches clicked: no constraint data" ) );
1030 return;
1031 }
1032
1033 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR,
1034 wxS( "Show Matches clicked: nodeId=%d, rule='%s', code='%s'" ),
1035 m_constraintData->GetId(), m_constraintData->GetRuleName(),
1036 m_constraintData->GetConstraintCode() );
1037
1039 {
1040 int matchCount = m_callBackShowMatches( m_constraintData->GetId() );
1041
1042 if( matchCount < 0 )
1043 m_matchReport->SetLabel( _( "The rule does not compile." ) );
1044 else if( matchCount == 0 )
1045 m_matchReport->SetLabel( _( "No board items match." ) );
1046 else
1047 m_matchReport->SetLabel( wxString::Format(
1048 wxPLURAL( "%d board item matches.", "%d board items match.", matchCount ), matchCount ) );
1049
1050 m_matchReport->SetToolTip( m_matchReport->GetLabel() );
1051 Layout();
1052 }
1053}
1054
1055
1057{
1058 if( m_matchReport->GetLabel().IsEmpty() )
1059 return;
1060
1061 m_matchReport->SetLabel( wxEmptyString );
1062 m_matchReport->SetToolTip( wxEmptyString );
1063 Layout();
1064}
1065
1066
1068{
1069 m_layerListChoiceCtrl->Clear();
1070 m_layerIDs.clear();
1071
1072 m_layerListChoiceCtrl->Append( _( "Any" ) );
1073
1074 switch( aCategory )
1075 {
1077 m_layerListChoiceCtrl->Append( DRC_RULES_LEXER::TokenName( DRCRULE_T::T_outer ) );
1078 m_layerIDs.push_back( LAYER_SEL_OUTER );
1079 m_layerListChoiceCtrl->Append( DRC_RULES_LEXER::TokenName( DRCRULE_T::T_inner ) );
1080 m_layerIDs.push_back( LAYER_SEL_INNER );
1081
1082 for( PCB_LAYER_ID id : m_board->GetEnabledLayers().CuStack() )
1083 {
1084 m_layerListChoiceCtrl->Append( m_board->GetLayerName( id ) );
1085 m_layerIDs.push_back( static_cast<int>( id ) );
1086 }
1087
1088 break;
1089
1091 m_layerListChoiceCtrl->Append( m_board->GetLayerName( F_SilkS ) );
1092 m_layerIDs.push_back( static_cast<int>( F_SilkS ) );
1093 m_layerListChoiceCtrl->Append( m_board->GetLayerName( B_SilkS ) );
1094 m_layerIDs.push_back( static_cast<int>( B_SilkS ) );
1095 break;
1096
1098 m_layerListChoiceCtrl->Append( m_board->GetLayerName( F_Mask ) );
1099 m_layerIDs.push_back( static_cast<int>( F_Mask ) );
1100 m_layerListChoiceCtrl->Append( m_board->GetLayerName( B_Mask ) );
1101 m_layerIDs.push_back( static_cast<int>( B_Mask ) );
1102 break;
1103
1105 m_layerListChoiceCtrl->Append( m_board->GetLayerName( F_Paste ) );
1106 m_layerIDs.push_back( static_cast<int>( F_Paste ) );
1107 m_layerListChoiceCtrl->Append( m_board->GetLayerName( B_Paste ) );
1108 m_layerIDs.push_back( static_cast<int>( B_Paste ) );
1109 break;
1110
1112 m_layerListChoiceCtrl->Append( _( "Top" ) );
1113 m_layerIDs.push_back( LAYER_SEL_TOP );
1114 m_layerListChoiceCtrl->Append( _( "Bottom" ) );
1115 m_layerIDs.push_back( LAYER_SEL_BOTTOM );
1116 break;
1117
1119 m_layerListChoiceCtrl->Append( _( "outer" ) );
1120 m_layerIDs.push_back( LAYER_SEL_OUTER );
1121 m_layerListChoiceCtrl->Append( _( "inner" ) );
1122 m_layerIDs.push_back( LAYER_SEL_INNER );
1123
1124 for( PCB_LAYER_ID id : m_board->GetEnabledLayers().UIOrder() )
1125 {
1126 m_layerListChoiceCtrl->Append( m_board->GetLayerName( id ) );
1127 m_layerIDs.push_back( static_cast<int>( id ) );
1128 }
1129
1130 break;
1131
1133 // No layers to add - selector will be hidden
1134 break;
1135 }
1136
1137 m_layerListChoiceCtrl->SetSelection( 0 );
1138}
1139
1140
1142{
1144 return wxEmptyString;
1145
1146 int selection = m_layerListChoiceCtrl->GetSelection();
1147
1148 if( selection <= 0 )
1149 return wxEmptyString;
1150
1151 size_t index = static_cast<size_t>( selection - 1 );
1152
1153 if( index >= m_layerIDs.size() )
1154 return wxEmptyString;
1155
1156 int layerValue = m_layerIDs[index];
1157
1158 // Handle synthetic layers
1159 if( layerValue < 0 )
1160 {
1161 switch( layerValue )
1162 {
1163 case LAYER_SEL_OUTER:
1164 return wxString::Format( wxS( "(layer %s)" ), DRC_RULES_LEXER::TokenName( DRCRULE_T::T_outer ) );
1165
1166 case LAYER_SEL_INNER:
1167 return wxString::Format( wxS( "(layer %s)" ), DRC_RULES_LEXER::TokenName( DRCRULE_T::T_inner ) );
1168
1169 case LAYER_SEL_TOP:
1171
1172 case LAYER_SEL_BOTTOM:
1174
1175 default:
1176 return wxEmptyString;
1177 }
1178 }
1179
1180 // Real layer ID
1181 PCB_LAYER_ID layerId = static_cast<PCB_LAYER_ID>( layerValue );
1182 wxString clause = wxString::Format( wxS( "(layer \"%s\")" ), LSET::Name( layerId ) );
1183 wxLogTrace( KI_TRACE_DRC_RULE_EDITOR, wxS( "Layer clause: %s" ), clause );
1184 return clause;
1185}
1186
1188{
1189 int sel = m_layerListChoiceCtrl->GetSelection();
1190
1191 if( sel <= 0 )
1192 {
1194 return { F_SilkS, B_SilkS };
1195
1196 return {};
1197 }
1198
1199 int layerValue = m_layerIDs[sel - 1];
1200
1201 // Translate pseudo-IDs to real layer IDs
1202 if( layerValue < 0 )
1203 {
1204 switch( layerValue )
1205 {
1206 case LAYER_SEL_OUTER: return { F_Cu, B_Cu };
1207 case LAYER_SEL_INNER: return { In1_Cu };
1208
1209 case LAYER_SEL_TOP:
1210 case LAYER_SEL_BOTTOM:
1212
1213 default: return {};
1214 }
1215 }
1216
1217 return { static_cast<PCB_LAYER_ID>( layerValue ) };
1218}
1219
1220
1221void PANEL_DRC_RULE_EDITOR::setSelectedLayers( const std::vector<PCB_LAYER_ID>& aLayers,
1222 const wxString& aLayerSource )
1223{
1224 // Check for synthetic layer keywords first (for round-trip preservation)
1225 if( aLayerSource == DRC_RULES_LEXER::TokenName( DRCRULE_T::T_outer ) )
1226 {
1227 for( size_t i = 0; i < m_layerIDs.size(); ++i )
1228 {
1229 if( m_layerIDs[i] == LAYER_SEL_OUTER )
1230 {
1231 m_layerListChoiceCtrl->SetSelection( static_cast<int>( i ) + 1 );
1232 return;
1233 }
1234 }
1235 }
1236
1237 if( aLayerSource == DRC_RULES_LEXER::TokenName( DRCRULE_T::T_inner ) )
1238 {
1239 for( size_t i = 0; i < m_layerIDs.size(); ++i )
1240 {
1241 if( m_layerIDs[i] == LAYER_SEL_INNER )
1242 {
1243 m_layerListChoiceCtrl->SetSelection( static_cast<int>( i ) + 1 );
1244 return;
1245 }
1246 }
1247 }
1248
1249 // Map real layer IDs to Top/Bottom pseudo-entries (for TOP_BOTTOM_ANY dropdowns)
1250 if( !aLayers.empty() )
1251 {
1252 PCB_LAYER_ID target = aLayers.front();
1253 bool isFront = IsFrontLayer( target );
1254 bool isBack = IsBackLayer( target );
1255
1256 if( isFront || isBack )
1257 {
1258 int pseudoId = isFront ? LAYER_SEL_TOP : LAYER_SEL_BOTTOM;
1259
1260 for( size_t i = 0; i < m_layerIDs.size(); ++i )
1261 {
1262 if( m_layerIDs[i] == pseudoId )
1263 {
1264 m_layerListChoiceCtrl->SetSelection( static_cast<int>( i ) + 1 );
1265 return;
1266 }
1267 }
1268 }
1269 }
1270
1271 // Handle empty layers (default to "Any")
1272 if( aLayers.empty() )
1273 {
1274 m_layerListChoiceCtrl->SetSelection( 0 );
1275 return;
1276 }
1277
1278 // Find and select the matching layer
1279 int target = static_cast<int>( aLayers.front() );
1280
1281 for( size_t i = 0; i < m_layerIDs.size(); ++i )
1282 {
1283 if( m_layerIDs[i] == target )
1284 {
1285 m_layerListChoiceCtrl->SetSelection( static_cast<int>( i ) + 1 );
1286 return;
1287 }
1288 }
1289
1290 m_layerListChoiceCtrl->SetSelection( 0 );
1291}
1292
1293
1295{
1296 for( wxWindow* window = aChild; window; window = window->GetParent() )
1297 {
1298 if( PANEL_DRC_RULE_EDITOR* editor = dynamic_cast<PANEL_DRC_RULE_EDITOR*>( window ) )
1299 return editor;
1300 }
1301
1302 return nullptr;
1303}
1304
1305
1306void PANEL_DRC_RULE_EDITOR::SetOverrideNote( const wxString& aText )
1307{
1308 if( aText.IsEmpty() )
1309 {
1310 if( m_overrideNote )
1311 m_overrideNote->Hide();
1312
1313 return;
1314 }
1315
1316 if( !m_overrideNote )
1317 {
1319 new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END );
1320 m_overrideNote->SetFont( KIUI::GetInfoFont( this ).Italic() );
1321
1322 // A long condition would otherwise widen this column at the expense of the one beside it,
1323 // so the line shortens to the room it is given and keeps its text on hover.
1324 m_overrideNote->SetMinSize( wxSize( 1, -1 ) );
1325
1326 // Above the constraint, so the value being displaced is read before the one replacing it
1327 size_t at = m_constraintSizer->GetItemCount();
1328
1329 for( size_t i = 0; i < m_constraintSizer->GetItemCount(); ++i )
1330 {
1331 if( m_constraintSizer->GetItem( i )->GetSizer() == m_constraintContentSizer )
1332 {
1333 at = i;
1334 break;
1335 }
1336 }
1337
1338 m_constraintSizer->Insert( at, m_overrideNote, 0, wxEXPAND | wxTOP | wxRIGHT | wxLEFT, 5 );
1339 }
1340
1341 // Reached on every keystroke, so an unchanged note costs nothing.
1342 if( m_overrideNote->IsShown() && m_overrideNote->GetLabel() == aText )
1343 return;
1344
1345 m_overrideNote->SetLabel( aText );
1346 m_overrideNote->SetToolTip( aText );
1347 m_overrideNote->Show();
1348 Layout();
1349}
1350
1351
1353{
1354 // A custom rule is written in the constraint column and the column beside it is hidden,
1355 // so move the stretch across or the rule text stays at its smallest.
1356 for( wxSizerItem* item : bContentSizer->GetChildren() )
1357 {
1358 wxSizer* columns = item->GetSizer();
1359
1360 if( !columns || !columns->GetItem( m_constraintSizer ) )
1361 continue;
1362
1363 for( wxSizerItem* column : columns->GetChildren() )
1364 column->SetProportion( column->GetSizer() == m_constraintSizer ? 1 : 0 );
1365
1366 return;
1367 }
1368
1369 wxFAIL_MSG( wxS( "Constraint column not found; the generated layout has changed." ) );
1370}
1371
1372
1374{
1375 for( wxWindow* window = aWindow->GetParent(); window; window = window->GetParent() )
1376 {
1377 window->Layout();
1378
1379 if( wxScrolledWindow* scrolled = dynamic_cast<wxScrolledWindow*>( window ) )
1380 {
1381 scrolled->FitInside();
1382
1383 // Only the height scrolls. Pinning the virtual width to the client width keeps
1384 // the editor's buttons out from under the scrollbar.
1385 wxSize virtualSize = scrolled->GetVirtualSize();
1386 virtualSize.x = scrolled->GetClientSize().x;
1387 scrolled->SetVirtualSize( virtualSize );
1388 scrolled->Layout();
1389 break;
1390 }
1391
1392 if( dynamic_cast<wxTopLevelWindow*>( window ) )
1393 break;
1394 }
1395}
int index
const char * name
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
Overlay panel for absolute length constraints showing min, opt, and max length fields positioned over...
Overlay panel for allowed orientation constraints showing checkboxes for each orientation angle posit...
Overlay panel for boolean input constraints showing a single checkbox positioned over a diagram.
Container panel that manages multiple condition rows with boolean operators.
Simple panel used for editing custom rule text.
void UpdateRuleName(const wxString &aName)
Overlay panel for minimum text height and thickness constraints showing text dimension fields positio...
Overlay panel for numeric input constraints showing a single numeric value field positioned over a di...
Overlay panel for permitted layers constraints showing checkboxes for top and bottom layer selection ...
Overlay panel for differential pair routing constraints showing gap, width, and uncoupled length fiel...
Overlay panel for routing width constraints showing min/preferred/max width fields positioned over a ...
Overlay panel for via style constraints showing via diameter and hole size fields positioned over a d...
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
static bool IsNumericInputType(const DRC_RULE_EDITOR_CONSTRAINT_NAME &aConstraintType)
static wxString FormatErrorMessage(int aErrorCount, const wxString &aErrorMessage)
static wxString TranslateTopBottomLayer(DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType, bool aIsTop)
Translate a top/bottom selection to the appropriate layer clause or condition.
static DRC_LAYER_CATEGORY GetLayerCategoryForConstraint(DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType)
Get the layer category for a constraint type.
static PCB_LAYER_ID TopBottomLayerId(DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType, bool aIsTop)
The layer a side of the board means for a constraint, which is not copper for every one.
static bool IsBoolInputType(const DRC_RULE_EDITOR_CONSTRAINT_NAME &aConstraintType)
The base frame for deriving all KiCad main window classes.
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
PANEL_DRC_RULE_EDITOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxBORDER_NONE|wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > m_constraintData
wxString GenerateRule(const RULE_GENERATION_CONTEXT &aContext) override
void onScintillaCharAdded(wxStyledTextEvent &aEvent)
Handles character addition in the Scintilla text control, performing auto-complete and context-sensit...
static void LayoutAncestors(wxWindow *aWindow)
Lays out aWindow's parents, out to the page it scrolls in.
void onShowMatchesButtonClicked(wxCommandEvent &aEvent)
void onFieldChanged(wxEvent &aEvent)
void onCheckSyntax(wxCommandEvent &aEvent) override
Checks the syntax of the DRC rule condition and reports any errors.
std::function< void(int aNodeId)> m_callBackSave
HTML_MESSAGE_BOX * m_helpWindow
static PANEL_DRC_RULE_EDITOR * FindEditor(wxWindow *aChild)
The rule editor that hosts aChild, or nullptr when it is not inside one.
wxString getSelectedLayerSource() const
void onContextMenu(wxMouseEvent &aEvent) override
Handles right-click context menu actions for text editing (undo, redo, cut, copy, paste,...
PANEL_DRC_RULE_EDITOR(wxWindow *aParent, BOARD *aBoard, DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType, std::shared_ptr< DRC_RE_BASE_CONSTRAINT_DATA > aConstraintData)
wxString GetCondition() const
The condition the form currently describes, which is not yet the one the rule applies.
std::function< void()> m_callBackFieldChanged
void setSelectedLayers(const std::vector< PCB_LAYER_ID > &aLayers, const wxString &aLayerSource=wxEmptyString)
DRC_LAYER_CATEGORY m_layerCategory
void onSyntaxHelp(wxHyperlinkEvent &aEvent) override
Displays a modeless help window with syntax and rule documentation.
std::vector< int > m_layerIDs
void populateLayerSelector(DRC_LAYER_CATEGORY aCategory)
DRC_RULE_EDITOR_CONSTRAINT_NAME m_constraintType
void SetOverrideNote(const wxString &aText)
Shows a line above the constraint saying what this rule displaces, or clears it when empty.
void RelayoutHost()
Lays out the editor's parents, out to the page it scrolls in.
void onErrorLinkClicked(wxHtmlLinkEvent &aEvent) override
Handles clicks on error links in the syntax error report and navigates to the error location.
void OnEnterKey(wxCommandEvent &aEvent) override
std::function< int(int aNodeId)> m_callBackShowMatches
std::function< bool(int aNodeId, const wxString &aRuleName)> m_callBackRuleNameValidation
DRC_RE_CONDITION_GROUP_PANEL * m_conditionGroupPanel
std::unique_ptr< SCINTILLA_TRICKS > m_scintillaTricks
void Save(wxCommandEvent &aEvent)
void onSaveButtonClicked(wxCommandEvent &aEvent)
Handles the save button click event, validating inputs and invoking the save callback if valid.
DRC_RULE_EDITOR_CONTENT_PANEL_BASE * getConstraintPanel(wxWindow *aParent, const DRC_RULE_EDITOR_CONSTRAINT_NAME &aConstraintType)
std::vector< PCB_LAYER_ID > getSelectedLayers()
bool ValidateRule()
Runs the rule's validators and keeps the outcome, without applying anything.
bool ValidateInputs(int *aErrorCount, wxString *aValidationMessage) override
DRC_RULE_EDITOR_CONTENT_PANEL_BASE * m_constraintPanel
const wxArrayString GetSignatures() const
static PCBEXPR_BUILTIN_FUNCTIONS & Instance()
Provide class metadata.
const std::vector< PROPERTY_BASE * > & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
static PROPERTY_MANAGER & Instance()
std::vector< CLASS_INFO > GetAllClasses()
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition wx_panel.h:35
This file is part of the common library.
DRC_RULE_EDITOR_CONSTRAINT_NAME
@ ALLOWED_ORIENTATION
@ ROUTING_DIFF_PAIR
@ VIAS_UNDER_SMD
@ PHYSICAL_CLEARANCE
@ CREEPAGE_DISTANCE
@ ABSOLUTE_LENGTH
@ MINIMUM_CLEARANCE
@ PERMITTED_LAYERS
@ MINIMUM_TEXT_HEIGHT_AND_THICKNESS
@ COPPER_TO_HOLE_CLEARANCE
@ HOLE_TO_HOLE_DISTANCE
@ ROUTING_WIDTH
@ MATCHED_LENGTH_DIFF_PAIR
DRC_LAYER_CATEGORY
Layer categories for filtering the layer selector dropdown.
@ NO_LAYER_SELECTOR
Hide layer selector entirely.
@ TOP_BOTTOM_ANY
Simplified top/bottom/any selector with custom translation.
@ SOLDERMASK_ONLY
F_Mask, B_Mask.
@ GENERAL_ANY_LAYER
All layers + inner/outer synthetic.
@ SOLDERPASTE_ONLY
F_Paste, B_Paste.
@ COPPER_ONLY
Copper layers + inner/outer synthetic.
@ SILKSCREEN_ONLY
F_SilkS, B_SilkS.
@ LAYER_SEL_BOTTOM
Context-dependent back/bottom layer.
@ LAYER_SEL_OUTER
External copper layers (F_Cu + B_Cu)
@ LAYER_SEL_TOP
Context-dependent front/top layer.
@ LAYER_SEL_INNER
Internal copper layers (In1_Cu through In30_Cu)
#define _(s)
@ NONE
Definition eda_fill.h:42
EDA_UNITS
Definition eda_units.h:45
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_Paste
Definition layer_ids.h:100
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ F_SilkS
Definition layer_ids.h:96
@ In1_Cu
Definition layer_ids.h:62
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
static bool constraintNeedsTwoObjects(DRC_RULE_EDITOR_CONSTRAINT_NAME aConstraintType)
static constexpr const wxChar * KI_TRACE_DRC_RULE_EDITOR
see class PGM_BASE
@ RPT_SEVERITY_ERROR
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