From 72b904a97843a32ecca9f6231f16943b096c34ab Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sun, 27 Sep 2020 18:12:32 +0100 Subject: [PATCH] ADDED: CADSTAR Archive project importer --- common/wildcards_and_files_ext.cpp | 6 ++++ include/wildcards_and_files_ext.h | 1 + kicad/import_project.cpp | 44 +++++++++++++++++++++--------- kicad/kicad_id.h | 1 + kicad/kicad_manager_frame.cpp | 1 + kicad/kicad_manager_frame.h | 19 +++++++++++++ kicad/menubar.cpp | 21 +++++++++++--- pcbnew/files.cpp | 1 + 8 files changed, 77 insertions(+), 17 deletions(-) diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 83e434d798..a727d46f98 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -242,6 +242,12 @@ wxString CadstarSchematicArchiveFileWildcard() } +wxString CadstarArchiveFilesWildcard() +{ + return _( "CADSTAR Archive files" ) + AddFileExtListToFilter( { "csa", "cpa" } ); +} + + wxString EagleSchematicFileWildcard() { return _( "Eagle XML schematic files" ) + AddFileExtListToFilter( { "sch" } ); diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 3be9876f7b..b1d5346832 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -195,6 +195,7 @@ extern wxString PcbFileWildcard(); extern wxString EaglePcbFileWildcard(); extern wxString AltiumSchematicFileWildcard(); extern wxString CadstarSchematicArchiveFileWildcard(); +extern wxString CadstarArchiveFilesWildcard(); extern wxString EagleSchematicFileWildcard(); extern wxString EagleFilesWildcard(); extern wxString PCadPcbFileWildcard(); diff --git a/kicad/import_project.cpp b/kicad/import_project.cpp index 1e2e73b6b0..9ddcf24796 100644 --- a/kicad/import_project.cpp +++ b/kicad/import_project.cpp @@ -25,7 +25,7 @@ /** * @file import_project.cpp - * @brief routines for importing an eagle project + * @brief routines for importing a non-KiCad project */ @@ -46,16 +46,16 @@ #include "kicad_manager_frame.h" -void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) + +void KICAD_MANAGER_FRAME::ImportNonKiCadProject( wxString aWindowTitle, wxString aFilesWildcard, + wxString aSchFileExtension, wxString aPcbFileExtension, int aSchFileType, int aPcbFileType ) { - wxString title = _( "Import Eagle Project Files" ); - int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST; + int style = wxFD_OPEN | wxFD_FILE_MUST_EXIST; wxString default_dir = GetMruPath(); ClearMsg(); - wxFileDialog schdlg( this, title, default_dir, wxEmptyString, - EagleFilesWildcard(), style ); + wxFileDialog schdlg( this, aWindowTitle, default_dir, wxEmptyString, aFilesWildcard, style ); if( schdlg.ShowModal() == wxID_CANCEL ) return; @@ -63,7 +63,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) wxFileName sch( schdlg.GetPath() ); - sch.SetExt( LegacySchematicFileExtension ); + sch.SetExt( aSchFileExtension ); wxFileName pro = sch; @@ -85,9 +85,10 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) if( directory.HasFiles() ) { - wxString msg = _( "The selected directory is not empty. We recommend you " - "create projects in their own clean directory.\n\nDo you " - "want to create a new empty directory for the project?" ); + wxString msg = + _( "The selected directory is not empty. We recommend you " + "create projects in their own clean directory.\n\nDo you " + "want to create a new empty directory for the project?" ); KIDIALOG dlg( this, msg, _( "Confirmation" ), wxYES_NO | wxICON_WARNING ); dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); @@ -106,8 +107,9 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) wxFileName pcb( sch ); std::string packet; + pro.SetExt( ProjectFileExtension ); - pcb.SetExt( LegacyPcbFileExtension ); // enforce extension + pcb.SetExt( aPcbFileExtension ); // enforce extension if( !pro.IsAbsolute() ) pro.MakeAbsolute(); @@ -121,7 +123,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) { KIWAY_PLAYER* schframe = Kiway().Player( FRAME_SCH, true ); - packet = StrPrintf( "%d\n%s", SCH_IO_MGR::SCH_EAGLE, TO_UTF8( sch.GetFullPath() ) ); + packet = StrPrintf( "%d\n%s", aSchFileType, TO_UTF8( sch.GetFullPath() ) ); schframe->Kiway().ExpressMail( FRAME_SCH, MAIL_IMPORT_FILE, packet, this ); if( !schframe->IsShown() ) @@ -141,7 +143,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) if( !pcbframe->IsVisible() ) pcbframe->Show( true ); - packet = StrPrintf( "%d\n%s", IO_MGR::EAGLE, TO_UTF8( pcb.GetFullPath() ) ); + packet = StrPrintf( "%d\n%s", aPcbFileType, TO_UTF8( pcb.GetFullPath() ) ); pcbframe->Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_IMPORT_FILE, packet, this ); // On Windows, Raise() does not bring the window on screen, when iconized @@ -154,3 +156,19 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) ReCreateTreePrj(); m_active_project = true; } + + +void KICAD_MANAGER_FRAME::OnImportCadstarArchiveFiles( wxCommandEvent& event ) +{ + ImportNonKiCadProject( _( "Import CADSTAR Archive Project Files" ), + CadstarArchiveFilesWildcard(), "csa", "cpa", SCH_IO_MGR::SCH_CADSTAR_ARCHIVE, + IO_MGR::CADSTAR_PCB_ARCHIVE ); +} + + +void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event ) +{ + ImportNonKiCadProject( _( "Import Eagle Project Files" ), EagleFilesWildcard(), + LegacySchematicFileExtension, LegacyPcbFileExtension, + SCH_IO_MGR::SCH_EAGLE, IO_MGR::EAGLE ); +} diff --git a/kicad/kicad_id.h b/kicad/kicad_id.h index 84bf8eaa01..8f1df1bb42 100644 --- a/kicad/kicad_id.h +++ b/kicad/kicad_id.h @@ -70,6 +70,7 @@ enum id_kicad_frm { ID_READ_ZIP_ARCHIVE, ID_INIT_WATCHED_PATHS, ID_IMPORT_EAGLE_PROJECT, + ID_IMPORT_CADSTAR_ARCHIVE_PROJECT, // Please, verify: the number of items in this list should be // less than ROOM_FOR_KICADMANAGER (see id.h) diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index e115ee2d2e..9653105ab4 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -75,6 +75,7 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME ) EVT_MENU( ID_BROWSE_IN_FILE_EXPLORER, KICAD_MANAGER_FRAME::OnBrowseInFileExplorer ) EVT_MENU( ID_SAVE_AND_ZIP_FILES, KICAD_MANAGER_FRAME::OnArchiveFiles ) EVT_MENU( ID_READ_ZIP_ARCHIVE, KICAD_MANAGER_FRAME::OnUnarchiveFiles ) + EVT_MENU( ID_IMPORT_CADSTAR_ARCHIVE_PROJECT, KICAD_MANAGER_FRAME::OnImportCadstarArchiveFiles ) EVT_MENU( ID_IMPORT_EAGLE_PROJECT, KICAD_MANAGER_FRAME::OnImportEagleFiles ) // Range menu events diff --git a/kicad/kicad_manager_frame.h b/kicad/kicad_manager_frame.h index 6ab6533301..9230f0930b 100644 --- a/kicad/kicad_manager_frame.h +++ b/kicad/kicad_manager_frame.h @@ -108,6 +108,25 @@ public: return GetProjectFileName(); } + + /** + * @brief Creates a project and imports a non-KiCad Schematic and PCB + * @param aWindowTitle to display to the user when opening the files + * @param aFilesWildcard that includes both PCB and Schematic files (from wildcards_and_files_ext.h) + * @param aSchFileExtension e.g. "sch" or "csa" + * @param aPcbFileExtension e.g. "brd" or "cpa" + * @param aSchFileType Type of Schematic File to import (from SCH_IO_MGR::SCH_FILE_T) + * @param aPcbFileType Type of PCB File to import (from IO_MGR::PCB_FILE_T) + */ + void ImportNonKiCadProject( wxString aWindowTitle, wxString aFilesWildcard, + wxString aSchFileExtension, wxString aPcbFileExtension, int aSchFileType, + int aPcbFileType ); + + /** + * Open dialog to import CADSTAR Schematic and PCB Archive files. + */ + void OnImportCadstarArchiveFiles( wxCommandEvent& event ); + /** * Open dialog to import Eagle schematic and board files. */ diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index 1d6b5f3834..cdccbf7c7b 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -84,10 +84,23 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() fileMenu->Add( ACTIONS::saveAs ); fileMenu->AppendSeparator(); - fileMenu->Add( _( "Import EAGLE Project..." ), - _( "Import EAGLE CAD XML schematic and board" ), - ID_IMPORT_EAGLE_PROJECT, - import_project_xpm ); + + //Import Sub-menu + ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool ); + importMenu->SetTitle( _( "Import Non-KiCad Project..." ) ); + importMenu->SetIcon( import_project_xpm ); + + importMenu->Add( _( "Import CADSTAR Project..." ), + _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ), + ID_IMPORT_CADSTAR_ARCHIVE_PROJECT, + import_project_xpm ); + + importMenu->Add( _( "Import EAGLE Project..." ), + _( "Import EAGLE CAD XML schematic and board" ), + ID_IMPORT_EAGLE_PROJECT, + import_project_xpm ); + + fileMenu->Add( importMenu ); fileMenu->AppendSeparator(); fileMenu->Add( _( "&Archive Project..." ), diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 517eab5a09..b7dc8b523b 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -1013,6 +1013,7 @@ bool PCB_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) { switch( (IO_MGR::PCB_FILE_T) aFileType ) { + case IO_MGR::CADSTAR_PCB_ARCHIVE: case IO_MGR::EAGLE: if( OpenProjectFiles( std::vector( 1, aFileName ), KICTL_EAGLE_BRD ) ) {