From 3e4913adce86ea3955b7dac39703425d9cb2c41e Mon Sep 17 00:00:00 2001 From: Andrei Pozolotin Date: Mon, 15 Apr 2019 17:54:47 -0500 Subject: [PATCH] Pcbnew export/import scripting functions. Discussion can be found at https://forum.kicad.info/t/pcbnew-export-import-scripting-functions/16343 Fixes lp:1824668 https://bugs.launchpad.net/kicad/+bug/1824668 --- pcbnew/pcb_edit_frame.h | 9 ++++ .../specctra_import.cpp | 11 ++++- pcbnew/swig/pcbnew_scripting_helpers.cpp | 41 +++++++++++++++++++ pcbnew/swig/pcbnew_scripting_helpers.h | 33 +++++++++++++++ pcbnew/swig/tests/test_archive_modules.py | 15 +++++++ pcbnew/swig/tests/test_specctra_export.py | 13 ++++++ pcbnew/swig/tests/test_specctra_import.py | 13 ++++++ 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 pcbnew/swig/tests/test_archive_modules.py create mode 100644 pcbnew/swig/tests/test_specctra_export.py create mode 100644 pcbnew/swig/tests/test_specctra_import.py diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index c8b22871a9..80cbc33480 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -1102,6 +1102,15 @@ public: */ void ImportSpecctraSession( wxCommandEvent& event ); + /** + * Function ImportSpecctraSession + * will import a specctra *.ses file and use it to relocate MODULEs and + * to replace all vias and tracks in an existing and loaded BOARD. + * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the + * specification. + */ + bool ImportSpecctraSession( const wxString& aFullFilename ); + /** * Function ImportSpecctraDesign * will import a specctra *.dsn file and use it to replace an entire BOARD. diff --git a/pcbnew/specctra_import_export/specctra_import.cpp b/pcbnew/specctra_import_export/specctra_import.cpp index 02b9280b5c..24619b6f4a 100644 --- a/pcbnew/specctra_import_export/specctra_import.cpp +++ b/pcbnew/specctra_import_export/specctra_import.cpp @@ -89,6 +89,13 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) return; } + ImportSpecctraSession( fullFileName ); +} + + +bool PCB_EDIT_FRAME::ImportSpecctraSession( const wxString& fullFileName ) +{ + SetCurItem( NULL ); // To avoid issues with undo/redo lists (dangling pointers) @@ -114,7 +121,7 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) wxString extra = ioe.What(); DisplayErrorMessage( this, msg, extra); - return; + return false; } OnModify(); @@ -140,6 +147,8 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) SetStatusText( wxString( _( "Session file imported and merged OK." ) ) ); Refresh(); + + return true; } diff --git a/pcbnew/swig/pcbnew_scripting_helpers.cpp b/pcbnew/swig/pcbnew_scripting_helpers.cpp index 9255e33c89..8109823e2a 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.cpp +++ b/pcbnew/swig/pcbnew_scripting_helpers.cpp @@ -107,6 +107,47 @@ bool SaveBoard( wxString& aFileName, BOARD* aBoard ) } +bool ExportSpecctraDSN( wxString& aFullFilename ) +{ + if( s_PcbEditFrame ) + { + bool ok = s_PcbEditFrame->ExportSpecctraFile( aFullFilename ); + return ok; + } + else + { + return false; + } +} + + +bool ImportSpecctraSES( wxString& aFullFilename ) +{ + if( s_PcbEditFrame ) + { + bool ok = s_PcbEditFrame->ImportSpecctraSession( aFullFilename ); + return ok; + } + else + { + return false; + } +} + + +bool ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath ) +{ + if( s_PcbEditFrame ) + { + s_PcbEditFrame->ArchiveModulesOnBoard( aStoreInNewLib, aLibName, aLibPath ); + return true; + } + else + { + return false; + } +} + void Refresh() { if( s_PcbEditFrame ) diff --git a/pcbnew/swig/pcbnew_scripting_helpers.h b/pcbnew/swig/pcbnew_scripting_helpers.h index 123b26a2a7..f8090d2862 100644 --- a/pcbnew/swig/pcbnew_scripting_helpers.h +++ b/pcbnew/swig/pcbnew_scripting_helpers.h @@ -49,6 +49,39 @@ BOARD* LoadBoard( wxString& aFileName ); // so no option to choose the file format. bool SaveBoard( wxString& aFileName, BOARD* aBoard ); +/** + * will export the current BOARD to a specctra dsn file. + * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the + * specification. + * @return true if OK + */ +bool ExportSpecctraDSN( wxString& aFullFilename ); + +/** + * will import a specctra *.ses file and use it to relocate MODULEs and + * to replace all vias and tracks in an existing and loaded BOARD. + * See http://www.autotraxeda.com/docs/SPECCTRA/SPECCTRA.pdf for the + * specification. + * @return true if OK + */ +bool ImportSpecctraSES( wxString& aFullFilename ); + +/** + * Function ArchiveModulesOnBoard + * Save modules in a library: + * @param aStoreInNewLib: + * true : save modules in a existing lib. Existing footprints will be kept + * or updated. + * This lib should be in fp lib table, and is type is .pretty + * false: save modules in a new lib. It it is an existing lib, + * previous footprints will be removed + * + * @param aLibName: + * optional library name to create, stops dialog call. + * must be called with aStoreInNewLib as true + */ +bool ArchiveModulesOnBoard( + bool aStoreInNewLib, const wxString& aLibName = wxEmptyString, wxString* aLibPath = NULL ); /** * Update the board display after modifying it by a python script * (note: it is automatically called by action plugins, after running the plugin, diff --git a/pcbnew/swig/tests/test_archive_modules.py b/pcbnew/swig/tests/test_archive_modules.py new file mode 100644 index 0000000000..9531442af1 --- /dev/null +++ b/pcbnew/swig/tests/test_archive_modules.py @@ -0,0 +1,15 @@ +# +# manual test session for "Tools -> Scripting Console" +# verify that "board-archive.pretty" folder is present +# result should be identical to "File -> Archive -> ..." +# +import os +import pcbnew +board = pcbnew.GetBoard() +board_path = board.GetFileName() +path_tuple = os.path.splitext(board_path) +board_prefix = path_tuple[0] +aStoreInNewLib = True +aLibName = "footprint-export" +aLibPath = board_prefix + "-archive.pretty" +pcbnew.ArchiveModulesOnBoard(aStoreInNewLib,aLibName,aLibPath) diff --git a/pcbnew/swig/tests/test_specctra_export.py b/pcbnew/swig/tests/test_specctra_export.py new file mode 100644 index 0000000000..6c2df11615 --- /dev/null +++ b/pcbnew/swig/tests/test_specctra_export.py @@ -0,0 +1,13 @@ +# +# manual test session for "Tools -> Scripting Console" +# verify that "board.dsn" file is created after this session +# result should be identical to "File -> Export -> Specctra DSN" +# +import os +import pcbnew +board = pcbnew.GetBoard() +board_path = board.GetFileName() +path_tuple = os.path.splitext(board_path) +board_prefix = path_tuple[0] +export_path = board_prefix + ".dsn" +pcbnew.ExportSpecctraDSN(export_path) diff --git a/pcbnew/swig/tests/test_specctra_import.py b/pcbnew/swig/tests/test_specctra_import.py new file mode 100644 index 0000000000..a136e8b4da --- /dev/null +++ b/pcbnew/swig/tests/test_specctra_import.py @@ -0,0 +1,13 @@ +# +# manual test session for "Tools -> Scripting Console" +# verify that "board.ses" file is applied after this session +# result should be identical to "File -> Import -> Specctra Session" +# +import os +import pcbnew +board = pcbnew.GetBoard() +board_path = board.GetFileName() +path_tuple = os.path.splitext(board_path) +board_prefix = path_tuple[0] +import_path = board_prefix + ".ses" +pcbnew.ImportSpecctraSES(import_path)