From 5157657eba354919a773bfe71a457807aafab5ca Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Sun, 22 Apr 2012 13:14:58 +0200 Subject: [PATCH] merged to last testing, also added automatic file extension detection on save/load --- pcbnew/class_module.h | 2 -- pcbnew/class_netclass.h | 7 ------ pcbnew/scripting/board.i | 11 ++++++---- pcbnew/scripting/examples/createPcb.py | 4 ++-- pcbnew/scripting/pcbnew.i | 14 +++++------- pcbnew/scripting/pcbnew_scripting_helpers.cpp | 22 +++++++++---------- 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 135b0f8f1b..ae63b75799 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -235,8 +235,6 @@ public: */ bool Read_GPCB_Descr( const wxString& CmpFullFileName ); - int Read_3D_Descr( LINE_READER* aReader ); - /* drawing functions */ void Draw( EDA_DRAW_PANEL* aPanel, diff --git a/pcbnew/class_netclass.h b/pcbnew/class_netclass.h index 73fab5c8a1..be7d51f461 100644 --- a/pcbnew/class_netclass.h +++ b/pcbnew/class_netclass.h @@ -294,13 +294,6 @@ public: */ NETCLASS* Find( const wxString& aName ) const; - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; }; #endif // CLASS_NETCLASS_H diff --git a/pcbnew/scripting/board.i b/pcbnew/scripting/board.i index 0df6736fed..55426db705 100644 --- a/pcbnew/scripting/board.i +++ b/pcbnew/scripting/board.i @@ -45,9 +45,12 @@ def Save(self,filename,format = None): if format is None: - return SaveBoard(filename,self) - else: - return SaveBoard(filename,self,format) + str_filename = str(filename) + if str_filename.endswith(".brd"): + format = IO_MGR.LEGACY + if str_filename.endswith(".kicad_brd"): + format = IO_MGR.KICAD + return SaveBoard(filename,self,format) # # add function, clears the thisown to avoid python from deleting @@ -90,4 +93,4 @@ def GetShapeStr(self): return self.ShowShape(self.GetShape()) } -} \ No newline at end of file +} diff --git a/pcbnew/scripting/examples/createPcb.py b/pcbnew/scripting/examples/createPcb.py index 1c30d178c8..70cdef9da6 100755 --- a/pcbnew/scripting/examples/createPcb.py +++ b/pcbnew/scripting/examples/createPcb.py @@ -34,9 +34,9 @@ for y in range (0,10): # save the PCB to disk pcb.Save("/tmp/my2.kicad_brd") -pcb.Save("/tmp/my2.brd",IO_MGR.LEGACY) +pcb.Save("/tmp/my2.brd") -pcb = LoadBoard("/tmp/my2.brd",IO_MGR.LEGACY) +pcb = LoadBoard("/tmp/my2.brd") print map( lambda x: x.GetReference() , list(pcb.GetModules())) diff --git a/pcbnew/scripting/pcbnew.i b/pcbnew/scripting/pcbnew.i index 9851e518cd..4b0fb5d325 100644 --- a/pcbnew/scripting/pcbnew.i +++ b/pcbnew/scripting/pcbnew.i @@ -73,12 +73,11 @@ BOARD *GetBoard(); /* get current editor board */ %} -#ifdef BUILD_WITH_PLUGIN + %{ #include #include %} -#endif %include %include @@ -104,15 +103,14 @@ %include -#ifdef BUILD_WITH_PLUGIN - // ignore RELEASER as nested classes are still unsupported by swig - %ignore IO_MGR::RELEASER; - %include - %include -#endif +// ignore RELEASER as nested classes are still unsupported by swig +%ignore IO_MGR::RELEASER; +%include +%include %include "board.i" %include "module.i" %include "units.i" + diff --git a/pcbnew/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/scripting/pcbnew_scripting_helpers.cpp index 086238c2b8..1918a9d57b 100644 --- a/pcbnew/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/scripting/pcbnew_scripting_helpers.cpp @@ -54,13 +54,20 @@ void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame) BOARD* LoadBoard(wxString& aFileName) { - return LoadBoard(aFileName,IO_MGR::KICAD); + + if (aFileName.EndsWith(wxT(".kicad_brd"))) + return LoadBoard(aFileName,IO_MGR::KICAD); + else if (aFileName.EndsWith(wxT(".brd"))) + return LoadBoard(aFileName,IO_MGR::LEGACY); + + // as fall back for any other kind use the legacy format + return LoadBoard(aFileName,IO_MGR::LEGACY); + } BOARD* LoadBoard(wxString& aFileName,IO_MGR::PCB_FILE_T aFormat) { static char ExceptionError[256]; -#ifdef USE_NEW_PCBNEW_LOAD try{ return IO_MGR::Load(aFormat,aFileName); } catch (IO_ERROR e) @@ -69,10 +76,7 @@ BOARD* LoadBoard(wxString& aFileName,IO_MGR::PCB_FILE_T aFormat) PyErr_SetString(PyExc_IOError,ExceptionError); return NULL; } -#else - fprintf(stderr,"Warning, LoadBoard not implemented without USE_NEW_PCBNEW_LOAD\n"); - return NULL; -#endif + } bool SaveBoard(wxString& aFilename, BOARD* aBoard) @@ -84,7 +88,6 @@ bool SaveBoard(wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat) { static char ExceptionError[256]; -#ifdef USE_NEW_PCBNEW_LOAD aBoard->m_Status_Pcb &= ~CONNEXION_OK; aBoard->SynchronizeNetsAndNetClasses(); aBoard->SetCurrentNetClass( aBoard->m_NetClasses.GetDefault()->GetName() ); @@ -115,11 +118,6 @@ bool SaveBoard(wxString& aFileName, BOARD* aBoard, return false; } -#else - fprintf(stderr,"Warning, SaveBoard not implemented without USE_NEW_PCBNEW_LOAD\n"); - return false; -#endif - }