2020-05-16 22:30:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-23 02:10:47 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-05-16 22:30:30 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <bitmaps.h>
|
2021-01-26 16:18:35 +00:00
|
|
|
#include <confirm.h>
|
2020-05-16 22:30:30 +00:00
|
|
|
#include <widgets/paged_dialog.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
2020-07-22 20:27:38 +00:00
|
|
|
#include <pcb_expr_evaluator.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-09-15 19:13:45 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-05-16 22:30:30 +00:00
|
|
|
#include <project.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-05-16 22:30:30 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <panel_setup_rules.h>
|
2022-09-03 18:29:02 +00:00
|
|
|
#include <widgets/wx_html_report_box.h>
|
2021-09-14 18:26:03 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
2020-05-27 22:28:36 +00:00
|
|
|
#include <scintilla_tricks.h>
|
2020-06-10 10:57:35 +00:00
|
|
|
#include <drc/drc_rule_parser.h>
|
2020-09-15 19:13:45 +00:00
|
|
|
#include <tools/drc_tool.h>
|
2022-01-23 23:04:19 +00:00
|
|
|
#include <pgm_base.h>
|
2020-07-22 20:27:38 +00:00
|
|
|
|
2023-05-10 17:13:52 +00:00
|
|
|
PANEL_SETUP_RULES::PANEL_SETUP_RULES( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) :
|
|
|
|
PANEL_SETUP_RULES_BASE( aParentWindow ),
|
2020-05-16 22:30:30 +00:00
|
|
|
m_frame( aFrame ),
|
2020-09-05 16:00:29 +00:00
|
|
|
m_scintillaTricks( nullptr ),
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow( nullptr )
|
2020-05-16 22:30:30 +00:00
|
|
|
{
|
2021-06-28 10:19:12 +00:00
|
|
|
m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ), false,
|
|
|
|
[this]()
|
|
|
|
{
|
2023-05-10 17:13:52 +00:00
|
|
|
wxPostEvent( PAGED_DIALOG::GetDialog( this ),
|
|
|
|
wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
2021-06-28 10:19:12 +00:00
|
|
|
} );
|
2020-05-16 22:30:30 +00:00
|
|
|
|
2021-09-23 11:30:43 +00:00
|
|
|
m_textEditor->AutoCompSetSeparator( '|' );
|
|
|
|
|
2022-04-20 15:26:05 +00:00
|
|
|
m_netClassRegex.Compile( "^NetClass\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
|
|
|
m_netNameRegex.Compile( "^NetName\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
|
|
|
m_typeRegex.Compile( "^Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
2023-01-23 02:10:47 +00:00
|
|
|
m_viaTypeRegex.Compile( "^Via_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
2022-04-20 15:26:05 +00:00
|
|
|
m_padTypeRegex.Compile( "^Pad_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
|
|
|
m_pinTypeRegex.Compile( "^Pin_Type\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
|
|
|
m_fabPropRegex.Compile( "^Fabrication_Property\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
2023-01-22 18:45:06 +00:00
|
|
|
m_shapeRegex.Compile( "^Shape\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
2020-09-01 17:35:22 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_compileButton->SetBitmap( KiBitmap( BITMAPS::drc ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
|
2022-01-23 23:04:19 +00:00
|
|
|
m_textEditor->SetZoom( Pgm().GetCommonSettings()->m_Appearance.text_editor_zoom );
|
|
|
|
|
|
|
|
m_textEditor->UsePopUp( 0 );
|
2020-05-24 23:43:19 +00:00
|
|
|
m_textEditor->Bind( wxEVT_STC_CHARADDED, &PANEL_SETUP_RULES::onScintillaCharAdded, this );
|
2020-07-22 20:27:38 +00:00
|
|
|
m_textEditor->Bind( wxEVT_STC_AUTOCOMP_CHAR_DELETED, &PANEL_SETUP_RULES::onScintillaCharAdded, this );
|
2021-01-26 16:18:35 +00:00
|
|
|
m_textEditor->Bind( wxEVT_CHAR_HOOK, &PANEL_SETUP_RULES::onCharHook, this );
|
2020-05-16 22:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
PANEL_SETUP_RULES::~PANEL_SETUP_RULES( )
|
|
|
|
{
|
2022-01-23 23:04:19 +00:00
|
|
|
Pgm().GetCommonSettings()->m_Appearance.text_editor_zoom = m_textEditor->GetZoom();
|
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
delete m_scintillaTricks;
|
2020-09-05 16:00:29 +00:00
|
|
|
|
2020-12-07 12:15:52 +00:00
|
|
|
if( m_helpWindow )
|
|
|
|
m_helpWindow->Destroy();
|
2020-05-27 22:28:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-26 16:18:35 +00:00
|
|
|
void PANEL_SETUP_RULES::onCharHook( wxKeyEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.GetKeyCode() == WXK_ESCAPE && !m_textEditor->AutoCompActive() )
|
|
|
|
{
|
|
|
|
if( m_originalText != m_textEditor->GetText() )
|
|
|
|
{
|
|
|
|
if( !IsOK( this, _( "Cancel Changes?" ) ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-23 23:04:19 +00:00
|
|
|
void PANEL_SETUP_RULES::OnContextMenu(wxMouseEvent &event)
|
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
|
|
|
|
menu.Append( wxID_UNDO, _( "Undo" ) );
|
|
|
|
menu.Append( wxID_REDO, _( "Redo" ) );
|
|
|
|
|
|
|
|
menu.AppendSeparator();
|
|
|
|
|
|
|
|
menu.Append( 1, _( "Cut" ) ); // Don't use wxID_CUT, wxID_COPY, etc. On Mac (at least),
|
|
|
|
menu.Append( 2, _( "Copy" ) ); // wxWidgets never delivers them to us.
|
|
|
|
menu.Append( 3, _( "Paste" ) );
|
|
|
|
menu.Append( 4, _( "Delete" ) );
|
|
|
|
|
|
|
|
menu.AppendSeparator();
|
|
|
|
|
|
|
|
menu.Append( 5, _( "Select All" ) );
|
|
|
|
|
|
|
|
menu.AppendSeparator();
|
|
|
|
|
|
|
|
menu.Append( wxID_ZOOM_IN, _( "Zoom In" ) );
|
|
|
|
menu.Append( wxID_ZOOM_OUT, _( "Zoom Out" ) );
|
|
|
|
|
|
|
|
|
|
|
|
switch( GetPopupMenuSelectionFromUser( menu ) )
|
|
|
|
{
|
|
|
|
case wxID_UNDO:
|
|
|
|
m_textEditor->Undo();
|
|
|
|
break;
|
|
|
|
case wxID_REDO:
|
|
|
|
m_textEditor->Redo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
m_textEditor->Cut();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
m_textEditor->Copy();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
m_textEditor->Paste();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
long from, to;
|
|
|
|
m_textEditor->GetSelection( &from, &to );
|
|
|
|
|
|
|
|
if( to > from )
|
|
|
|
m_textEditor->DeleteRange( from, to );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
m_textEditor->SelectAll();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxID_ZOOM_IN:
|
|
|
|
m_textEditor->ZoomIn();
|
|
|
|
break;
|
|
|
|
case wxID_ZOOM_OUT:
|
|
|
|
m_textEditor->ZoomOut();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 23:43:19 +00:00
|
|
|
void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
|
|
|
|
{
|
2023-05-10 17:13:52 +00:00
|
|
|
PAGED_DIALOG::GetDialog( this )->SetModified();
|
2020-05-24 23:43:19 +00:00
|
|
|
m_textEditor->SearchAnchor();
|
|
|
|
|
2020-08-11 20:14:57 +00:00
|
|
|
wxString rules = m_textEditor->GetText();
|
2020-05-24 23:43:19 +00:00
|
|
|
int currentPos = m_textEditor->GetCurrentPos();
|
2020-08-11 20:14:57 +00:00
|
|
|
int startPos = 0;
|
|
|
|
|
|
|
|
for( int line = m_textEditor->LineFromPosition( currentPos ); line > 0; line-- )
|
|
|
|
{
|
|
|
|
int lineStart = m_textEditor->PositionFromLine( line );
|
|
|
|
wxString beginning = m_textEditor->GetTextRange( lineStart, lineStart + 10 );
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
if( beginning.StartsWith( wxT( "(rule " ) ) )
|
2020-08-11 20:14:57 +00:00
|
|
|
{
|
|
|
|
startPos = lineStart;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
STRING,
|
|
|
|
SEXPR_OPEN,
|
|
|
|
SEXPR_TOKEN,
|
2021-09-23 11:30:43 +00:00
|
|
|
SEXPR_STRING,
|
2020-07-21 22:42:40 +00:00
|
|
|
STRUCT_REF
|
2020-05-24 23:43:19 +00:00
|
|
|
};
|
|
|
|
|
2021-09-23 11:30:43 +00:00
|
|
|
auto isDisallowToken =
|
|
|
|
[]( const wxString& token ) -> bool
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
return token == wxT( "buried_via" )
|
|
|
|
|| token == wxT( "graphic" )
|
|
|
|
|| token == wxT( "hole" )
|
|
|
|
|| token == wxT( "micro_via" )
|
|
|
|
|| token == wxT( "pad" )
|
|
|
|
|| token == wxT( "text" )
|
|
|
|
|| token == wxT( "track" )
|
|
|
|
|| token == wxT( "via" )
|
|
|
|
|| token == wxT( "zone" );
|
2021-09-23 11:30:43 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 23:43:19 +00:00
|
|
|
std::stack<wxString> sexprs;
|
|
|
|
wxString partial;
|
2020-09-01 17:35:22 +00:00
|
|
|
wxString last;
|
2020-05-24 23:43:19 +00:00
|
|
|
int context = NONE;
|
2020-07-21 22:42:40 +00:00
|
|
|
int expr_context = NONE;
|
2020-05-24 23:43:19 +00:00
|
|
|
|
2020-08-11 20:14:57 +00:00
|
|
|
for( int i = startPos; i < currentPos; ++i )
|
2020-05-24 23:43:19 +00:00
|
|
|
{
|
2020-05-27 23:18:28 +00:00
|
|
|
wxChar c = m_textEditor->GetCharAt( i );
|
2020-05-24 23:43:19 +00:00
|
|
|
|
|
|
|
if( c == '\\' )
|
|
|
|
{
|
|
|
|
i++; // skip escaped char
|
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
else if( context == STRING )
|
2020-05-24 23:43:19 +00:00
|
|
|
{
|
|
|
|
if( c == '"' )
|
2020-07-21 22:42:40 +00:00
|
|
|
{
|
2020-05-24 23:43:19 +00:00
|
|
|
context = NONE;
|
2020-07-21 22:42:40 +00:00
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
else
|
2020-07-21 22:42:40 +00:00
|
|
|
{
|
|
|
|
if( expr_context == STRING )
|
|
|
|
{
|
|
|
|
if( c == '\'' )
|
|
|
|
expr_context = NONE;
|
|
|
|
else
|
|
|
|
partial += c;
|
|
|
|
}
|
|
|
|
else if( c == '\'' )
|
|
|
|
{
|
2020-09-01 17:35:22 +00:00
|
|
|
last = partial;
|
2020-07-21 22:42:40 +00:00
|
|
|
partial = wxEmptyString;
|
|
|
|
expr_context = STRING;
|
|
|
|
}
|
|
|
|
else if( c == '.' )
|
|
|
|
{
|
|
|
|
partial = wxEmptyString;
|
|
|
|
expr_context = STRUCT_REF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partial += c;
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
else if( c == '"' )
|
2020-05-24 23:43:19 +00:00
|
|
|
{
|
2020-09-01 17:35:22 +00:00
|
|
|
last = partial;
|
2020-05-24 23:43:19 +00:00
|
|
|
partial = wxEmptyString;
|
|
|
|
context = STRING;
|
|
|
|
}
|
|
|
|
else if( c == '(' )
|
|
|
|
{
|
|
|
|
if( context == SEXPR_OPEN && !partial.IsEmpty() )
|
2020-05-25 20:44:49 +00:00
|
|
|
{
|
|
|
|
m_textEditor->AutoCompCancel();
|
2020-05-24 23:43:19 +00:00
|
|
|
sexprs.push( partial );
|
2020-05-25 20:44:49 +00:00
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
|
|
|
|
partial = wxEmptyString;
|
|
|
|
context = SEXPR_OPEN;
|
|
|
|
}
|
|
|
|
else if( c == ')' )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
while( !sexprs.empty() && ( sexprs.top() == wxT( "assertion" )
|
|
|
|
|| sexprs.top() == wxT( "disallow" )
|
2021-09-23 11:30:43 +00:00
|
|
|
|| isDisallowToken( sexprs.top() )
|
2022-02-04 22:44:59 +00:00
|
|
|
|| sexprs.top() == wxT( "min_resolved_spokes" )
|
|
|
|
|| sexprs.top() == wxT( "zone_connection" ) ) )
|
2021-09-23 11:30:43 +00:00
|
|
|
{
|
|
|
|
sexprs.pop();
|
|
|
|
}
|
|
|
|
|
2020-07-21 14:52:48 +00:00
|
|
|
if( !sexprs.empty() )
|
|
|
|
sexprs.pop();
|
|
|
|
|
2020-05-24 23:43:19 +00:00
|
|
|
context = NONE;
|
|
|
|
}
|
|
|
|
else if( c == ' ' )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
if( context == SEXPR_OPEN && ( partial == wxT( "constraint" )
|
|
|
|
|| partial == wxT( "disallow" )
|
|
|
|
|| partial == wxT( "layer" )
|
|
|
|
|| partial == wxT( "severity" ) ) )
|
2020-05-24 23:43:19 +00:00
|
|
|
{
|
2020-05-25 20:44:49 +00:00
|
|
|
m_textEditor->AutoCompCancel();
|
2020-05-24 23:43:19 +00:00
|
|
|
sexprs.push( partial );
|
|
|
|
|
2021-09-23 11:30:43 +00:00
|
|
|
partial = wxEmptyString;
|
|
|
|
context = SEXPR_TOKEN;
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( partial == wxT( "disallow" )
|
2021-09-23 11:30:43 +00:00
|
|
|
|| isDisallowToken( partial )
|
2022-02-04 22:44:59 +00:00
|
|
|
|| partial == wxT( "min_resolved_spokes" )
|
|
|
|
|| partial == wxT( "zone_connection" ) )
|
2021-09-23 11:30:43 +00:00
|
|
|
{
|
|
|
|
m_textEditor->AutoCompCancel();
|
|
|
|
sexprs.push( partial );
|
|
|
|
|
|
|
|
partial = wxEmptyString;
|
|
|
|
context = SEXPR_TOKEN;
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( partial == wxT( "rule" )
|
|
|
|
|| partial == wxT( "assertion" )
|
|
|
|
|| partial == wxT( "condition" ) )
|
2021-09-23 11:30:43 +00:00
|
|
|
{
|
|
|
|
m_textEditor->AutoCompCancel();
|
|
|
|
sexprs.push( partial );
|
|
|
|
|
|
|
|
partial = wxEmptyString;
|
|
|
|
context = SEXPR_STRING;
|
|
|
|
continue;
|
2020-05-24 23:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
context = NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partial += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString tokens;
|
|
|
|
|
|
|
|
if( context == SEXPR_OPEN )
|
|
|
|
{
|
|
|
|
if( sexprs.empty() )
|
2020-10-04 11:44:22 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "rule|"
|
|
|
|
"version" );
|
2020-10-04 11:44:22 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "rule" ) )
|
2020-10-04 11:44:22 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "condition|"
|
|
|
|
"constraint|"
|
|
|
|
"layer|"
|
|
|
|
"severity" );
|
2020-10-04 11:44:22 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "constraint" ) )
|
2020-10-04 11:44:22 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "max|min|opt" );
|
2020-10-04 11:44:22 +00:00
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
}
|
|
|
|
else if( context == SEXPR_TOKEN )
|
|
|
|
{
|
2020-07-21 22:42:40 +00:00
|
|
|
if( sexprs.empty() )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
|
|
|
/* badly formed grammar */
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "constraint" ) )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "annular_width|"
|
|
|
|
"assertion|"
|
|
|
|
"clearance|"
|
2022-07-31 15:02:04 +00:00
|
|
|
"connection_width|"
|
2022-02-04 22:44:59 +00:00
|
|
|
"courtyard_clearance|"
|
|
|
|
"diff_pair_gap|"
|
|
|
|
"diff_pair_uncoupled|"
|
|
|
|
"disallow|"
|
|
|
|
"edge_clearance|"
|
|
|
|
"length|"
|
|
|
|
"hole_clearance|"
|
|
|
|
"hole_size|"
|
|
|
|
"hole_to_hole|"
|
|
|
|
"min_resolved_spokes|"
|
2022-05-06 13:46:24 +00:00
|
|
|
"physical_clearance|"
|
|
|
|
"physical_hole_clearance|"
|
2022-02-04 22:44:59 +00:00
|
|
|
"silk_clearance|"
|
|
|
|
"skew|"
|
|
|
|
"text_height|"
|
|
|
|
"text_thickness|"
|
|
|
|
"thermal_relief_gap|"
|
|
|
|
"thermal_spoke_width|"
|
|
|
|
"track_width|"
|
|
|
|
"via_count|"
|
|
|
|
"via_diameter|"
|
|
|
|
"zone_connection" );
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "disallow" ) || isDisallowToken( sexprs.top() ) )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "buried_via|"
|
|
|
|
"graphic|"
|
|
|
|
"hole|"
|
|
|
|
"micro_via|"
|
|
|
|
"pad|"
|
|
|
|
"text|"
|
|
|
|
"track|"
|
|
|
|
"via|"
|
|
|
|
"zone" );
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "zone_connection" ) )
|
2021-08-08 13:37:14 +00:00
|
|
|
{
|
2022-11-26 10:44:42 +00:00
|
|
|
tokens = wxT( "none|solid|thermal_reliefs" );
|
2021-08-08 13:37:14 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "min_resolved_spokes" ) )
|
2021-08-09 10:10:09 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "0|1|2|3|4" );
|
2021-08-09 10:10:09 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "layer" ) )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "inner|outer|\"x\"" );
|
2021-09-23 11:30:43 +00:00
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( sexprs.top() == wxT( "severity" ) )
|
2021-09-23 11:30:43 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "warning|error|ignore|exclusion" );
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
}
|
2021-09-22 21:20:18 +00:00
|
|
|
else if( context == SEXPR_STRING && !sexprs.empty()
|
2022-02-04 22:44:59 +00:00
|
|
|
&& ( sexprs.top() == wxT( "condition" ) || sexprs.top() == wxT( "assertion" ) ) )
|
2021-09-22 21:20:18 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
m_textEditor->AddText( wxT( "\"" ) );
|
2021-09-22 21:20:18 +00:00
|
|
|
}
|
|
|
|
else if( context == STRING && !sexprs.empty()
|
2022-02-04 22:44:59 +00:00
|
|
|
&& ( sexprs.top() == wxT( "condition" ) || sexprs.top() == wxT( "assertion" ) ) )
|
2020-07-21 22:42:40 +00:00
|
|
|
{
|
2020-09-01 17:35:22 +00:00
|
|
|
if( expr_context == STRUCT_REF )
|
2020-07-21 22:42:40 +00:00
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
std::set<wxString> propNames;
|
2020-05-24 23:43:19 +00:00
|
|
|
|
2020-07-21 22:42:40 +00:00
|
|
|
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
|
|
|
|
{
|
|
|
|
const PROPERTY_LIST& props = propMgr.GetProperties( cls.type );
|
|
|
|
|
|
|
|
for( PROPERTY_BASE* prop : props )
|
|
|
|
{
|
2023-03-26 23:43:16 +00:00
|
|
|
// TODO: It would be nice to replace IsHiddenFromRulesEditor with a nickname
|
2023-01-12 03:14:52 +00:00
|
|
|
// system, so that two different properies don't need to be created. This is
|
|
|
|
// a bigger change than I want to make right now, though.
|
2023-03-26 23:43:16 +00:00
|
|
|
if( prop->IsHiddenFromRulesEditor() )
|
2023-01-12 03:14:52 +00:00
|
|
|
continue;
|
|
|
|
|
2020-07-21 22:42:40 +00:00
|
|
|
wxString ref( prop->Name() );
|
2022-02-04 22:44:59 +00:00
|
|
|
ref.Replace( wxT( " " ), wxT( "_" ) );
|
2020-07-21 22:42:40 +00:00
|
|
|
propNames.insert( ref );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const wxString& propName : propNames )
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens += wxT( "|" ) + propName;
|
2020-07-22 20:27:38 +00:00
|
|
|
|
|
|
|
PCB_EXPR_BUILTIN_FUNCTIONS& functions = PCB_EXPR_BUILTIN_FUNCTIONS::Instance();
|
|
|
|
|
|
|
|
for( const wxString& funcSig : functions.GetSignatures() )
|
2022-08-28 16:41:39 +00:00
|
|
|
{
|
|
|
|
if( !funcSig.Contains( "DEPRECATED" ) )
|
|
|
|
tokens += wxT( "|" ) + funcSig;
|
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
}
|
2020-09-01 17:35:22 +00:00
|
|
|
else if( expr_context == STRING )
|
|
|
|
{
|
|
|
|
if( m_netClassRegex.Matches( last ) )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
std::shared_ptr<NET_SETTINGS>& netSettings = bds.m_NetSettings;
|
2020-09-01 17:35:22 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ name, netclass ] : netSettings->m_NetClasses )
|
|
|
|
tokens += wxT( "|" ) + name;
|
2020-09-01 17:35:22 +00:00
|
|
|
}
|
|
|
|
else if( m_netNameRegex.Matches( last ) )
|
|
|
|
{
|
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
|
|
|
|
for( const wxString& netnameCandidate : board->GetNetClassAssignmentCandidates() )
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens += wxT( "|" ) + netnameCandidate;
|
2021-09-23 11:30:43 +00:00
|
|
|
}
|
|
|
|
else if( m_typeRegex.Matches( last ) )
|
|
|
|
{
|
2023-01-22 18:44:27 +00:00
|
|
|
tokens = wxT( "Bitmap|"
|
|
|
|
"Dimension|"
|
2022-02-04 22:44:59 +00:00
|
|
|
"Footprint|"
|
|
|
|
"Graphic|"
|
|
|
|
"Group|"
|
|
|
|
"Leader|"
|
|
|
|
"Pad|"
|
|
|
|
"Target|"
|
|
|
|
"Text|"
|
2023-01-22 18:44:27 +00:00
|
|
|
"Text Box|"
|
2022-02-04 22:44:59 +00:00
|
|
|
"Track|"
|
|
|
|
"Via|"
|
|
|
|
"Zone" );
|
2021-09-23 11:30:43 +00:00
|
|
|
}
|
2023-01-23 02:10:47 +00:00
|
|
|
else if( m_viaTypeRegex.Matches( last ) )
|
|
|
|
{
|
|
|
|
tokens = wxT( "Through|"
|
|
|
|
"Blind/buried|"
|
|
|
|
"Micro" );
|
|
|
|
}
|
2021-09-23 11:30:43 +00:00
|
|
|
else if( m_padTypeRegex.Matches( last ) )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "Through-hole|"
|
|
|
|
"SMD|"
|
|
|
|
"Edge connector|"
|
|
|
|
"NPTH, mechanical" );
|
2021-09-23 11:30:43 +00:00
|
|
|
}
|
2022-01-23 23:04:19 +00:00
|
|
|
else if( m_pinTypeRegex.Matches( last ) )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "Input|"
|
|
|
|
"Output|"
|
|
|
|
"Bidirectional|"
|
|
|
|
"Tri-state|"
|
|
|
|
"Passive|"
|
|
|
|
"Free|"
|
|
|
|
"Unspecified|"
|
|
|
|
"Power input|"
|
|
|
|
"Power output|"
|
|
|
|
"Open collector|"
|
|
|
|
"Open emitter|"
|
|
|
|
"Unconnected" );
|
2022-01-23 23:04:19 +00:00
|
|
|
}
|
2021-09-23 11:30:43 +00:00
|
|
|
else if( m_fabPropRegex.Matches( last ) )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tokens = wxT( "None|"
|
|
|
|
"BGA pad|"
|
|
|
|
"Fiducial, global to board|"
|
|
|
|
"Fiducial, local to footprint|"
|
|
|
|
"Test point pad|"
|
|
|
|
"Heatsink pad|"
|
|
|
|
"Castellated pad" );
|
2020-09-01 17:35:22 +00:00
|
|
|
}
|
2023-01-22 18:45:06 +00:00
|
|
|
else if( m_shapeRegex.Matches( last ) )
|
|
|
|
{
|
|
|
|
tokens = wxT( "Segment|"
|
|
|
|
"Rectangle|"
|
|
|
|
"Arc|"
|
|
|
|
"Circle|"
|
|
|
|
"Polygon|"
|
|
|
|
"Bezier" );
|
|
|
|
}
|
2020-09-01 17:35:22 +00:00
|
|
|
}
|
2020-05-16 22:30:30 +00:00
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
|
|
|
|
if( !tokens.IsEmpty() )
|
2021-09-23 11:30:43 +00:00
|
|
|
m_scintillaTricks->DoAutocomplete( partial, wxSplit( tokens, '|' ) );
|
2020-05-16 22:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
void PANEL_SETUP_RULES::OnCompile( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_errorsReport->Clear();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2022-01-10 21:05:14 +00:00
|
|
|
std::vector<std::shared_ptr<DRC_RULE>> dummyRules;
|
2020-07-30 11:24:29 +00:00
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
DRC_RULES_PARSER parser( m_textEditor->GetText(), _( "DRC rules" ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
|
|
|
|
parser.Parse( dummyRules, m_errorsReport );
|
|
|
|
}
|
|
|
|
catch( PARSE_ERROR& pe )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString msg = wxString::Format( wxT( "%s <a href='%d:%d'>%s</a>%s" ),
|
2020-10-30 19:51:24 +00:00
|
|
|
_( "ERROR:" ),
|
2020-10-15 23:38:33 +00:00
|
|
|
pe.lineNumber,
|
|
|
|
pe.byteIndex,
|
|
|
|
pe.ParseProblem(),
|
|
|
|
wxEmptyString );
|
|
|
|
|
|
|
|
m_errorsReport->Report( msg, RPT_SEVERITY_ERROR );
|
2020-07-30 11:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_errorsReport->Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_RULES::OnErrorLinkClicked( wxHtmlLinkEvent& event )
|
|
|
|
{
|
|
|
|
wxString link = event.GetLinkInfo().GetHref();
|
|
|
|
wxArrayString parts;
|
2020-07-31 17:37:24 +00:00
|
|
|
long line = 0, offset = 0;
|
2020-07-30 11:24:29 +00:00
|
|
|
|
|
|
|
wxStringSplit( link, parts, ':' );
|
|
|
|
|
|
|
|
if( parts.size() > 1 )
|
|
|
|
{
|
2020-07-31 17:37:24 +00:00
|
|
|
parts[0].ToLong( &line );
|
|
|
|
parts[1].ToLong( &offset );
|
2020-07-30 11:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pos = m_textEditor->PositionFromLine( line - 1 ) + ( offset - 1 );
|
|
|
|
|
|
|
|
m_textEditor->GotoPos( pos );
|
|
|
|
|
|
|
|
m_textEditor->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-16 22:30:30 +00:00
|
|
|
bool PANEL_SETUP_RULES::TransferDataToWindow()
|
|
|
|
{
|
2020-09-25 01:26:23 +00:00
|
|
|
wxFileName rulesFile( m_frame->GetDesignRulesPath() );
|
2020-05-16 22:30:30 +00:00
|
|
|
|
|
|
|
if( rulesFile.FileExists() )
|
2020-08-10 17:16:22 +00:00
|
|
|
{
|
|
|
|
wxTextFile file( rulesFile.GetFullPath() );
|
|
|
|
|
|
|
|
if( file.Open() )
|
|
|
|
{
|
|
|
|
for ( wxString str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine() )
|
|
|
|
{
|
|
|
|
ConvertSmartQuotesAndDashes( &str );
|
|
|
|
m_textEditor->AddText( str << '\n' );
|
|
|
|
}
|
2020-10-16 11:20:37 +00:00
|
|
|
|
2022-10-14 21:00:54 +00:00
|
|
|
m_textEditor->EmptyUndoBuffer();
|
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
OnCompile( dummy );
|
2020-08-10 17:16:22 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-16 22:30:30 +00:00
|
|
|
|
2020-06-10 10:57:35 +00:00
|
|
|
m_originalText = m_textEditor->GetText();
|
|
|
|
|
2020-09-30 23:04:31 +00:00
|
|
|
if( m_frame->Prj().IsNullProject() )
|
|
|
|
{
|
|
|
|
m_textEditor->ClearAll();
|
|
|
|
m_textEditor->AddText( _( "Design rules cannot be added without a project" ) );
|
|
|
|
m_textEditor->Disable();
|
|
|
|
}
|
|
|
|
|
2020-05-16 22:30:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_SETUP_RULES::TransferDataFromWindow()
|
|
|
|
{
|
2020-06-10 10:57:35 +00:00
|
|
|
if( m_originalText == m_textEditor->GetText() )
|
|
|
|
return true;
|
|
|
|
|
2020-09-30 23:04:31 +00:00
|
|
|
if( m_frame->Prj().IsNullProject() )
|
|
|
|
return true;
|
|
|
|
|
2020-09-25 01:26:23 +00:00
|
|
|
wxString rulesFilepath = m_frame->GetDesignRulesPath();
|
2020-09-15 19:13:45 +00:00
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if( m_textEditor->SaveFile( rulesFilepath ) )
|
|
|
|
{
|
2020-09-17 17:56:20 +00:00
|
|
|
m_frame->GetBoard()->GetDesignSettings().m_DRCEngine->InitEngine( rulesFilepath );
|
2020-09-16 20:38:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 16:58:12 +00:00
|
|
|
catch( PARSE_ERROR& )
|
2020-05-16 22:30:30 +00:00
|
|
|
{
|
2020-09-16 20:38:23 +00:00
|
|
|
// Don't lock them in to the Setup dialog if they have bad rules. They've already
|
|
|
|
// saved them so we can allow an exit.
|
2020-05-16 22:30:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-25 20:44:49 +00:00
|
|
|
void PANEL_SETUP_RULES::OnSyntaxHelp( wxHyperlinkEvent& aEvent )
|
|
|
|
{
|
2020-12-07 12:15:52 +00:00
|
|
|
if( m_helpWindow )
|
|
|
|
{
|
|
|
|
m_helpWindow->ShowModeless();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
wxString msg =
|
2020-10-04 11:25:59 +00:00
|
|
|
#include "dialogs/panel_setup_rules_help_md.h"
|
2020-09-05 16:00:29 +00:00
|
|
|
;
|
|
|
|
|
2020-09-03 19:33:33 +00:00
|
|
|
#ifdef __WXMAC__
|
2022-02-04 22:44:59 +00:00
|
|
|
msg.Replace( wxT( "Ctrl+" ), wxT( "Cmd+" ) );
|
2020-09-03 19:33:33 +00:00
|
|
|
#endif
|
2020-05-25 20:44:49 +00:00
|
|
|
|
2021-10-17 23:29:40 +00:00
|
|
|
m_helpWindow = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow->SetDialogSizeInDU( 320, 320 );
|
2020-05-25 20:44:49 +00:00
|
|
|
|
2020-10-04 11:25:59 +00:00
|
|
|
wxString html_txt;
|
|
|
|
ConvertMarkdown2Html( wxGetTranslation( msg ), html_txt );
|
2021-09-14 18:26:03 +00:00
|
|
|
m_helpWindow->AddHTML_Text( html_txt );
|
2020-10-04 11:25:59 +00:00
|
|
|
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow->ShowModeless();
|
2020-05-25 20:44:49 +00:00
|
|
|
}
|