2020-05-16 22:30:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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>
|
2020-10-15 22:39:33 +00:00
|
|
|
#include <kicad_string.h>
|
2020-05-16 22:30:30 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <panel_setup_rules.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <wx_html_report_box.h>
|
2020-10-25 13:14:52 +00:00
|
|
|
#include <dialogs/html_messagebox.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>
|
2020-10-04 11:25:59 +00:00
|
|
|
#include <dialog_helpers.h>
|
2020-07-22 20:27:38 +00:00
|
|
|
|
2020-05-16 22:30:30 +00:00
|
|
|
PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ) :
|
|
|
|
PANEL_SETUP_RULES_BASE( aParent->GetTreebook() ),
|
2020-06-10 10:57:35 +00:00
|
|
|
m_Parent( aParent ),
|
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
|
|
|
{
|
2020-07-21 00:14:56 +00:00
|
|
|
m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ) );
|
2020-05-16 22:30:30 +00:00
|
|
|
|
2020-05-25 20:44:49 +00:00
|
|
|
int size = wxNORMAL_FONT->GetPointSize();
|
2020-05-26 15:17:29 +00:00
|
|
|
wxFont fixedFont( size, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
|
2020-05-25 20:44:49 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
|
|
|
|
m_textEditor->StyleSetFont( i, fixedFont );
|
|
|
|
|
2020-09-01 17:35:22 +00:00
|
|
|
m_netClassRegex.Compile( "NetClass\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
|
|
|
m_netNameRegex.Compile( "NetName\\s*[!=]=\\s*$", wxRE_ADVANCED );
|
|
|
|
|
2020-07-31 20:45:55 +00:00
|
|
|
m_compileButton->SetBitmap( KiBitmap( drc_xpm ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
|
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( )
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 23:43:19 +00:00
|
|
|
void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
|
|
|
|
{
|
2020-08-10 20:48:26 +00:00
|
|
|
m_Parent->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 );
|
|
|
|
|
|
|
|
if( beginning.StartsWith( "(rule " ) )
|
|
|
|
{
|
|
|
|
startPos = lineStart;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
STRING,
|
|
|
|
SEXPR_OPEN,
|
|
|
|
SEXPR_TOKEN,
|
2020-07-21 22:42:40 +00:00
|
|
|
STRUCT_REF
|
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 == ')' )
|
|
|
|
{
|
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 == ' ' )
|
|
|
|
{
|
|
|
|
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-07-29 11:26:27 +00:00
|
|
|
if( sexprs.size() && ( sexprs.top() == "constraint"
|
|
|
|
|| sexprs.top() == "disallow"
|
|
|
|
|| sexprs.top() == "layer" ) )
|
2020-05-24 23:43:19 +00:00
|
|
|
{
|
|
|
|
partial = wxEmptyString;
|
|
|
|
context = SEXPR_TOKEN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context = NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partial += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString tokens;
|
|
|
|
|
|
|
|
if( context == SEXPR_OPEN )
|
|
|
|
{
|
|
|
|
if( sexprs.empty() )
|
2020-10-04 11:44:22 +00:00
|
|
|
{
|
|
|
|
tokens = "rule "
|
|
|
|
"version";
|
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
else if( sexprs.top() == "rule" )
|
2020-10-04 11:44:22 +00:00
|
|
|
{
|
|
|
|
tokens = "condition "
|
|
|
|
"constraint "
|
|
|
|
"layer";
|
|
|
|
}
|
2020-05-24 23:43:19 +00:00
|
|
|
else if( sexprs.top() == "constraint" )
|
2020-10-04 11:44:22 +00:00
|
|
|
{
|
|
|
|
tokens = "max "
|
|
|
|
"min "
|
|
|
|
"opt";
|
|
|
|
}
|
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 */
|
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
else if( sexprs.top() == "constraint" )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2020-10-04 11:44:22 +00:00
|
|
|
tokens = "annulus_width "
|
|
|
|
"clearance "
|
|
|
|
"courtyard_clearance "
|
|
|
|
"diff_pair_gap "
|
|
|
|
"diff_pair_uncoupled "
|
|
|
|
"disallow "
|
|
|
|
"edge_clearance "
|
|
|
|
"length "
|
|
|
|
"hole "
|
|
|
|
"hole_clearance "
|
2020-11-29 22:01:40 +00:00
|
|
|
"hole_to_hole "
|
2020-10-11 10:51:23 +00:00
|
|
|
"silk_clearance "
|
|
|
|
"skew "
|
2020-10-04 11:44:22 +00:00
|
|
|
"track_width "
|
|
|
|
"via_count ";
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
|
|
|
else if( sexprs.top() == "disallow"
|
|
|
|
|| sexprs.top() == "buried_via"
|
|
|
|
|| sexprs.top() == "graphic"
|
|
|
|
|| sexprs.top() == "hole"
|
|
|
|
|| sexprs.top() == "micro_via"
|
|
|
|
|| sexprs.top() == "pad"
|
|
|
|
|| sexprs.top() == "text"
|
|
|
|
|| sexprs.top() == "track"
|
|
|
|
|| sexprs.top() == "via"
|
|
|
|
|| sexprs.top() == "zone" )
|
|
|
|
{
|
2020-10-04 11:44:22 +00:00
|
|
|
tokens = "buried_via "
|
|
|
|
"graphic "
|
|
|
|
"hole "
|
|
|
|
"micro_via "
|
|
|
|
"pad "
|
|
|
|
"text "
|
|
|
|
"track "
|
|
|
|
"via "
|
|
|
|
"zone";
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
2020-07-29 11:26:27 +00:00
|
|
|
else if( sexprs.top() == "layer" )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2020-10-04 11:44:22 +00:00
|
|
|
tokens = "inner "
|
|
|
|
"outer "
|
|
|
|
"\"x\"";
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
}
|
2020-09-01 17:35:22 +00:00
|
|
|
else if( context == STRING && !sexprs.empty() && sexprs.top() == "condition" )
|
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 )
|
|
|
|
{
|
|
|
|
wxString ref( prop->Name() );
|
|
|
|
ref.Replace( " ", "_" );
|
|
|
|
propNames.insert( ref );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const wxString& propName : propNames )
|
|
|
|
tokens += " " + 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() )
|
|
|
|
tokens += " " + 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 ) )
|
|
|
|
{
|
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
|
|
|
|
|
|
|
|
for( const std::pair<const wxString, NETCLASSPTR>& entry : bds.GetNetClasses() )
|
|
|
|
tokens += " " + entry.first;
|
|
|
|
}
|
|
|
|
else if( m_netNameRegex.Matches( last ) )
|
|
|
|
{
|
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
|
|
|
|
for( const wxString& netnameCandidate : board->GetNetClassAssignmentCandidates() )
|
|
|
|
tokens += " " + netnameCandidate;
|
|
|
|
}
|
|
|
|
}
|
2020-05-16 22:30:30 +00:00
|
|
|
}
|
2020-07-21 22:42:40 +00:00
|
|
|
|
|
|
|
if( !tokens.IsEmpty() )
|
2021-01-23 22:12:25 +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
|
|
|
|
{
|
|
|
|
std::vector<DRC_RULE*> dummyRules;
|
|
|
|
|
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 )
|
|
|
|
{
|
2020-10-30 19:51:24 +00:00
|
|
|
wxString msg = wxString::Format( "%s <a href='%d:%d'>%s</a>%s",
|
|
|
|
_( "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
|
|
|
|
|
|
|
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__
|
2020-09-05 16:00:29 +00:00
|
|
|
msg.Replace( "Ctrl+", "Cmd+" );
|
2020-09-03 19:33:33 +00:00
|
|
|
#endif
|
2020-05-25 20:44:49 +00:00
|
|
|
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow = new HTML_MESSAGE_BOX( nullptr, _( "Syntax Help" ) );
|
|
|
|
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 );
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow->m_htmlWindow->AppendToPage( 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
|
|
|
}
|