diff --git a/src/Mod/Import/CMakeLists.txt b/src/Mod/Import/CMakeLists.txt index 8a606109ce..2a00dc1203 100644 --- a/src/Mod/Import/CMakeLists.txt +++ b/src/Mod/Import/CMakeLists.txt @@ -81,4 +81,3 @@ INSTALL( FILES_MATCHING PATTERN "*.rub*" ) - diff --git a/src/Mod/Import/ImportGlobal.h b/src/Mod/Import/ImportGlobal.h index 65dd3e5bd1..de12b39058 100644 --- a/src/Mod/Import/ImportGlobal.h +++ b/src/Mod/Import/ImportGlobal.h @@ -29,19 +29,19 @@ // Import #ifndef ImportExport #ifdef Import_EXPORTS -# define ImportExport FREECAD_DECL_EXPORT +#define ImportExport FREECAD_DECL_EXPORT #else -# define ImportExport FREECAD_DECL_IMPORT +#define ImportExport FREECAD_DECL_IMPORT #endif #endif // ImportGui #ifndef ImportGuiExport #ifdef ImportGui_EXPORTS -# define ImportGuiExport FREECAD_DECL_EXPORT +#define ImportGuiExport FREECAD_DECL_EXPORT #else -# define ImportGuiExport FREECAD_DECL_IMPORT +#define ImportGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //IMPORT_GLOBAL_H +#endif// IMPORT_GLOBAL_H diff --git a/src/Mod/Import/Init.py b/src/Mod/Import/Init.py index 730665c0b0..658ca17173 100644 --- a/src/Mod/Import/Init.py +++ b/src/Mod/Import/Init.py @@ -1,36 +1,35 @@ # FreeCAD init script of the Import module # (c) 2001 Juergen Riegel -#*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD 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 Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ - +# *************************************************************************** +# * Copyright (c) 2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD 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 Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # Append the open handler -#FreeCAD.addImportType("STEP 214 (*.step *.stp)","ImportGui") -#FreeCAD.addExportType("STEP 214 (*.step *.stp)","ImportGui") -#FreeCAD.addExportType("IGES files (*.iges *.igs)","ImportGui") -FreeCAD.addImportType("PLMXML files (*.plmxml)","PlmXmlParser") -FreeCAD.addImportType("STEPZ Zip File Type (*.stpZ *.stpz)","stepZ") -FreeCAD.addExportType("STEPZ zip File Type (*.stpZ *.stpz)","stepZ") -FreeCAD.addExportType("glTF (*.gltf *.glb)","ImportGui") +# FreeCAD.addImportType("STEP 214 (*.step *.stp)","ImportGui") +# FreeCAD.addExportType("STEP 214 (*.step *.stp)","ImportGui") +# FreeCAD.addExportType("IGES files (*.iges *.igs)","ImportGui") +FreeCAD.addImportType("PLMXML files (*.plmxml)", "PlmXmlParser") +FreeCAD.addImportType("STEPZ Zip File Type (*.stpZ *.stpz)", "stepZ") +FreeCAD.addExportType("STEPZ zip File Type (*.stpZ *.stpz)", "stepZ") +FreeCAD.addExportType("glTF (*.gltf *.glb)", "ImportGui") diff --git a/src/Mod/Import/InitGui.py b/src/Mod/Import/InitGui.py index 7b3d4e94ae..4ae974a1db 100644 --- a/src/Mod/Import/InitGui.py +++ b/src/Mod/Import/InitGui.py @@ -6,34 +6,34 @@ # This is the second one of three init scripts, the third one # runs when the gui is up -#*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD 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 Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD 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 Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # Registered in Part's Init.py file -FreeCAD.changeImportModule("STEP with colors (*.step *.stp)","Import","ImportGui") -FreeCAD.changeExportModule("STEP with colors (*.step *.stp)","Import","ImportGui") -FreeCAD.changeExportModule("glTF (*.gltf *.glb)","Import","ImportGui") +FreeCAD.changeImportModule("STEP with colors (*.step *.stp)", "Import", "ImportGui") +FreeCAD.changeExportModule("STEP with colors (*.step *.stp)", "Import", "ImportGui") +FreeCAD.changeExportModule("glTF (*.gltf *.glb)", "Import", "ImportGui") """ class ImportWorkbench ( Workbench ): @@ -74,5 +74,5 @@ class ImportWorkbench ( Workbench ): Gui.addWorkbench("Import",ImportWorkbench()) """ # See https://forum.freecad.org/viewtopic.php?f=3&t=26782 -#import Import_rc -#FreeCADGui.addPreferencePage(":/ui/preferences-import.ui","Import-Export") +# import Import_rc +# FreeCADGui.addPreferencePage(":/ui/preferences-import.ui","Import-Export") diff --git a/src/Mod/Import/import.dox b/src/Mod/Import/import.dox index ad8b67c776..446762d982 100644 --- a/src/Mod/Import/import.dox +++ b/src/Mod/Import/import.dox @@ -2,4 +2,3 @@ * \ingroup UTILITIES * brief Utilities to import various file formats using OpenCasCade OCAF */ - diff --git a/src/Mod/Import/stepZ.py b/src/Mod/Import/stepZ.py index c4116e0005..1e55c3a775 100644 --- a/src/Mod/Import/stepZ.py +++ b/src/Mod/Import/stepZ.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -#**************************************************************************** -#* Copyright (c) 2018 Maurice * -#* * -#* StepZ Import Export compressed STEP files for FreeCAD * -#* License: LGPLv2+ * -#* * -#**************************************************************************** +# **************************************************************************** +# * Copyright (c) 2018 Maurice * +# * * +# * StepZ Import Export compressed STEP files for FreeCAD * +# * License: LGPLv2+ * +# * * +# **************************************************************************** # workaround for unicode in gzipping filename # OCC7 doesn't support non-ASCII characters at the moment @@ -34,130 +34,149 @@ import builtins import importlib -import zipfile as zf +import zipfile as zf # import stepZ; import importlib; importlib.reload(stepZ); stepZ.open(u"C:/Temp/brick.stpz") + def mkz_string(input): if isinstance(input, str): return input else: - input = input.encode('utf-8') + input = input.encode("utf-8") return input + + #### def mkz_unicode(input): if isinstance(input, str): return input else: - input = input.decode('utf-8') + input = input.decode("utf-8") return input + #### def sayz(msg): FreeCAD.Console.PrintMessage(msg) - FreeCAD.Console.PrintMessage('\n') + FreeCAD.Console.PrintMessage("\n") + + #### def sayzw(msg): FreeCAD.Console.PrintWarning(msg) - FreeCAD.Console.PrintWarning('\n') + FreeCAD.Console.PrintWarning("\n") + + #### def sayzerr(msg): FreeCAD.Console.PrintError(msg) - FreeCAD.Console.PrintWarning('\n') + FreeCAD.Console.PrintWarning("\n") + + #### -def import_stpz(fn,fc,doc): + +def import_stpz(fn, fc, doc): # sayz(fn) ext = os.path.splitext(os.path.basename(fn))[1] - fname=os.path.splitext(os.path.basename(fn))[0] - basepath=os.path.split(fn)[0] - filepath = os.path.join(basepath,fname + u'.stp') + fname = os.path.splitext(os.path.basename(fn))[0] + basepath = os.path.split(fn)[0] + filepath = os.path.join(basepath, fname + ".stp") - tempdir = tempfile.gettempdir() # get the current temporary directory - tempfilepath = os.path.join(tempdir,fname + u'.stp') + tempdir = tempfile.gettempdir() # get the current temporary directory + tempfilepath = os.path.join(tempdir, fname + ".stp") - with builtins.open(tempfilepath, 'wb') as f: #py3 + with builtins.open(tempfilepath, "wb") as f: # py3 f.write(fc) - #ImportGui.insert(filepath) + # ImportGui.insert(filepath) if doc is None: ImportGui.open(tempfilepath) else: - ImportGui.open(tempfilepath,doc.Name) + ImportGui.open(tempfilepath, doc.Name) FreeCADGui.SendMsgToActiveView("ViewFit") try: os.remove(tempfilepath) except OSError: - sayzerr("error on removing "+tempfilepath+" file") + sayzerr("error on removing " + tempfilepath + " file") + + ### -def open(filename,doc=None): + +def open(filename, doc=None): if zf.is_zipfile(filename): - with zf.ZipFile(filename, 'r') as fz: + with zf.ZipFile(filename, "r") as fz: file_names = fz.namelist() for fn in file_names: sayz(fn) with fz.open(fn) as zfile: file_content = zfile.read() - import_stpz(filename,file_content,doc) + import_stpz(filename, file_content, doc) else: - with gz.open(filename, 'rb') as f: - fnm=os.path.splitext(os.path.basename(filename))[0] + with gz.open(filename, "rb") as f: + fnm = os.path.splitext(os.path.basename(filename))[0] sayz(fnm) file_content = f.read() - import_stpz(filename,file_content,doc) + import_stpz(filename, file_content, doc) + + #### -def insert(filename,doc): + +def insert(filename, doc): doc = FreeCAD.ActiveDocument open(filename, doc) + #### -def export(objs,filename): + +def export(objs, filename): """exporting to file folder""" - #sayz(filename) - sayz("stpZ version "+___stpZversion___) + # sayz(filename) + sayz("stpZ version " + ___stpZversion___) ext = os.path.splitext(os.path.basename(filename))[1] - fname=os.path.splitext(os.path.basename(filename))[0] - basepath=os.path.split(filename)[0] - tempdir = tempfile.gettempdir() # get the current temporary directory + fname = os.path.splitext(os.path.basename(filename))[0] + basepath = os.path.split(filename)[0] + tempdir = tempfile.gettempdir() # get the current temporary directory - filepath = os.path.join(basepath,fname) + u'.stp' - filepath_base = os.path.join(basepath,fname) + filepath = os.path.join(basepath, fname) + ".stp" + filepath_base = os.path.join(basepath, fname) - namefpath = os.path.join(basepath,fname) + namefpath = os.path.join(basepath, fname) - outfpath = os.path.join(basepath,fname)+u'.stpZ' - outfpathT = os.path.join(tempdir,fname)+u'.stpZ' - outfpath_stp = os.path.join(basepath,fname)+u'.stp' - outfpathT_stp = os.path.join(tempdir,fname)+u'.stp' + outfpath = os.path.join(basepath, fname) + ".stpZ" + outfpathT = os.path.join(tempdir, fname) + ".stpZ" + outfpath_stp = os.path.join(basepath, fname) + ".stp" + outfpathT_stp = os.path.join(tempdir, fname) + ".stp" outfpath_base = basepath - #outfpath_str = mkz_string(os.path.join(basepath,fname)) - outfpath_str = os.path.join(basepath,fname)+u'.stp' - outfpathT_str = os.path.join(tempdir,fname)+u'.stp' - + # outfpath_str = mkz_string(os.path.join(basepath,fname)) + outfpath_str = os.path.join(basepath, fname) + ".stp" + outfpathT_str = os.path.join(tempdir, fname) + ".stp" if os.path.exists(outfpathT_stp): os.remove(outfpathT_stp) - sayzw("Old temp file with the same name removed '"+ outfpathT_stp +"'") - ImportGui.export(objs,outfpathT_stp) - with builtins.open(outfpathT_stp, 'rb') as f_in: + sayzw("Old temp file with the same name removed '" + outfpathT_stp + "'") + ImportGui.export(objs, outfpathT_stp) + with builtins.open(outfpathT_stp, "rb") as f_in: file_content = f_in.read() new_f_content = file_content f_in.close() - with gz.open(outfpathT_str, 'wb') as f_out: + with gz.open(outfpathT_str, "wb") as f_out: f_out.write(new_f_content) f_out.close() if os.path.exists(outfpath): shutil.move(outfpathT_str, outfpath) - #os.remove(outfpathT_stp) + # os.remove(outfpathT_stp) else: shutil.move(outfpathT_str, outfpath) - #os.remove(outfpathT_stp) + # os.remove(outfpathT_stp) + ####