From 0783669633167d5030afece1d81cc572d801b805 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 24 Sep 2020 21:26:23 -0400 Subject: [PATCH] CHANGED: Design rules files now use .kicad_dru extension Fixes https://gitlab.com/kicad/code/kicad/-/issues/5763 Fixes https://gitlab.com/kicad/code/kicad/-/issues/5444 --- common/project/project_archiver.cpp | 1 + common/wildcards_and_files_ext.cpp | 1 + include/wildcards_and_files_ext.h | 1 + kicad/tree_project_frame.cpp | 1 + pcbnew/dialogs/dialog_drc.cpp | 2 +- pcbnew/dialogs/panel_setup_rules.cpp | 5 ++- pcbnew/pcb_base_edit_frame.cpp | 40 ++++++++++++++++-------- pcbnew/pcb_base_edit_frame.h | 7 +++++ pcbnew/swig/pcbnew_scripting_helpers.cpp | 6 +++- pcbnew/tools/pcb_inspection_tool.cpp | 4 +-- 10 files changed, 48 insertions(+), 20 deletions(-) diff --git a/common/project/project_archiver.cpp b/common/project/project_archiver.cpp index 35fa3a144f..f055432c48 100644 --- a/common/project/project_archiver.cpp +++ b/common/project/project_archiver.cpp @@ -165,6 +165,7 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi wxT( "*.cmp" ), wxT( "*.brd" ), wxT( "*.kicad_pcb" ), // Brd files wxT( "*.mod" ), wxT( "*.kicad_mod" ), // fp files + wxT( "*.kicad_dru" ), wxT( "*.gb?" ), wxT( "*.gbrjob" ), // Gerber files wxT( "*.gko" ), wxT( "*.gm1" ), wxT( "*.gm2" ), wxT( "*.g?" ), diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index fa4fbd50b7..f791d9a8fc 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -140,6 +140,7 @@ const std::string ArchiveFileExtension( "zip" ); const std::string LegacyPcbFileExtension( "brd" ); const std::string KiCadPcbFileExtension( "kicad_pcb" ); const std::string PageLayoutDescrFileExtension( "kicad_wks" ); +const std::string DesignRulesFileExtension( "kicad_dru" ); const std::string PdfFileExtension( "pdf" ); const std::string MacrosFileExtension( "mcr" ); diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 6093d86b56..666fa12f52 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -132,6 +132,7 @@ extern const std::string KiCadPcbFileExtension; #define PcbFileExtension KiCadPcbFileExtension // symlink choice extern const std::string KiCadSymbolLibFileExtension; extern const std::string PageLayoutDescrFileExtension; +extern const std::string DesignRulesFileExtension; extern const std::string LegacyFootprintLibPathExtension; extern const std::string PdfFileExtension; diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 453252d21e..d14d4cacaf 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -70,6 +70,7 @@ static const wxChar* s_allowedExtensionsToList[] = { wxT( "^.*\\.kicad_sch$" ), // S-expr Eeschema files wxT( "^[^$].*\\.brd$" ), // Legacy Pcbnew files wxT( "^[^$].*\\.kicad_pcb$" ), // S format Pcbnew board files + wxT( "^[^$].*\\.kicad_dru$" ), // Design rule files wxT( "^[^$].*\\.kicad_wks$" ), // S format kicad page layout help_textr files wxT( "^[^$].*\\.kicad_mod$" ), // S format kicad footprint files, currently not listed wxT( "^.*\\.net$" ), // pcbnew netlist file diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index 0cc99bad66..293dc3d378 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -210,7 +210,7 @@ void DIALOG_DRC::OnRunDRCClick( wxCommandEvent& aEvent ) // and that they at least parse. try { - drcTool->GetDRCEngine()->InitEngine( m_parentFrame->Prj().AbsolutePath( "drc-rules" ) ); + drcTool->GetDRCEngine()->InitEngine( m_brdEditor->GetDesignRulesPath() ); } catch( PARSE_ERROR& pe ) { diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index a0e60c24f8..d630fd2274 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -331,8 +331,7 @@ void PANEL_SETUP_RULES::OnErrorLinkClicked( wxHtmlLinkEvent& event ) bool PANEL_SETUP_RULES::TransferDataToWindow() { - wxString rulesFilepath = m_frame->Prj().AbsolutePath( "drc-rules" ); - wxFileName rulesFile( rulesFilepath ); + wxFileName rulesFile( m_frame->GetDesignRulesPath() ); if( rulesFile.FileExists() ) { @@ -373,7 +372,7 @@ bool PANEL_SETUP_RULES::TransferDataFromWindow() return false; } - wxString rulesFilepath = m_frame->Prj().AbsolutePath( "drc-rules" ); + wxString rulesFilepath = m_frame->GetDesignRulesPath(); try { diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 134df5994c..209efaf1af 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -39,6 +39,8 @@ #include #include #include +#include + PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle, @@ -131,19 +133,6 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard ) if( new_board ) { - BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); - bds.m_DRCEngine = std::make_shared( aBoard, &bds ); - - try - { - bds.m_DRCEngine->InitEngine( Prj().AbsolutePath( "drc-rules" ) ); - } - catch( PARSE_ERROR& pe ) - { - // TODO: We could redirect to Board Setup here and report the error. Or we could - // wait till they run DRC or do an Inspect Clearance. Not sure which is better.... - } - if( m_toolManager ) m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); @@ -153,6 +142,22 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard ) PCB_BASE_FRAME::SetBoard( aBoard ); + if( new_board ) + { + BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); + bds.m_DRCEngine = std::make_shared( aBoard, &bds ); + + try + { + bds.m_DRCEngine->InitEngine( GetDesignRulesPath() ); + } + catch( PARSE_ERROR& pe ) + { + // TODO: We could redirect to Board Setup here and report the error. Or we could + // wait till they run DRC or do an Inspect Clearance. Not sure which is better.... + } + } + GetCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetDesignSettings().m_GridOrigin ) ); // update the tool manager with the new board and its view. @@ -217,3 +222,12 @@ COLOR_SETTINGS* PCB_BASE_EDIT_FRAME::GetColorSettings() } +wxString PCB_BASE_EDIT_FRAME::GetDesignRulesPath() +{ + if( !GetBoard() ) + return wxEmptyString; + + wxFileName fn = GetBoard()->GetFileName(); + fn.SetExt( DesignRulesFileExtension ); + return Prj().AbsolutePath( fn.GetFullName() ); +} diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 54ba2192da..1e17a94c32 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -212,6 +212,13 @@ public: */ void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override; + /** + * Returns the absolute path to the design rules file for the currently-loaded board. + * Note that there is no guarantee that this file actually exists and can be opened! + * NOTE: only really makes sense from PcbNew, but is needed in PCB_BASE_EDIT_FRAME::SetBoard + */ + wxString GetDesignRulesPath(); + protected: /// User defined rotation angle (in tenths of a degree). int m_rotationAngle; diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index a91836dc5c..91d4a17619 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -323,9 +323,13 @@ bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits, wxCHECK( engine, false ); + wxFileName fn = GetBoard()->GetFileName(); + fn.SetExt( DesignRulesFileExtension ); + wxString drcRulesPath = s_SettingsManager->Prj().AbsolutePath( fn.GetFullName() ); + try { - engine->InitEngine( s_SettingsManager->Prj().AbsolutePath( "drc-rules" ) ); + engine->InitEngine( drcRulesPath ); } catch( PARSE_ERROR& pe ) { diff --git a/pcbnew/tools/pcb_inspection_tool.cpp b/pcbnew/tools/pcb_inspection_tool.cpp index 34fddc6c3c..d88ddca955 100644 --- a/pcbnew/tools/pcb_inspection_tool.cpp +++ b/pcbnew/tools/pcb_inspection_tool.cpp @@ -191,7 +191,7 @@ void PCB_INSPECTION_TOOL::reportCopperClearance( PCB_LAYER_ID aLayer, BOARD_CONN try { - drcEngine.InitEngine( m_frame->Prj().AbsolutePath( "drc-rules" ) ); + drcEngine.InitEngine( m_frame->GetDesignRulesPath() ); } catch( PARSE_ERROR& pe ) { @@ -337,7 +337,7 @@ int PCB_INSPECTION_TOOL::InspectConstraints( const TOOL_EVENT& aEvent ) try { - drcEngine.InitEngine( m_frame->Prj().AbsolutePath( "drc-rules" ) ); + drcEngine.InitEngine( m_frame->GetDesignRulesPath() ); } catch( PARSE_ERROR& pe ) {