From bd1edd292a7da351c6a92e2528197033a8ec1958 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 2 May 2024 11:42:00 +0200 Subject: [PATCH] BIM - moved importers to subdir --- src/Mod/Arch/importers/__init__.py | 0 src/Mod/Arch/{ => importers}/exportIFC.py | 5 ++++- src/Mod/Arch/{ => importers}/exportIFCHelper.py | 0 .../Arch/{ => importers}/exportIFCStructuralTools.py | 0 src/Mod/Arch/{ => importers}/import3DS.py | 0 src/Mod/Arch/{ => importers}/importDAE.py | 0 src/Mod/Arch/{ => importers}/importGBXML.py | 1 - src/Mod/Arch/{ => importers}/importIFC.py | 5 ++++- src/Mod/Arch/{ => importers}/importIFCHelper.py | 0 src/Mod/Arch/{ => importers}/importIFClegacy.py | 5 +++-- src/Mod/Arch/{ => importers}/importIFCmulticore.py | 0 src/Mod/Arch/{ => importers}/importJSON.py | 6 +++--- src/Mod/Arch/{ => importers}/importOBJ.py | 10 +++++----- src/Mod/Arch/{ => importers}/importSH3D.py | 4 ++-- src/Mod/Arch/{ => importers}/importSHP.py | 6 +++--- src/Mod/Arch/{ => importers}/importWebGL.py | 5 ++--- 16 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 src/Mod/Arch/importers/__init__.py rename src/Mod/Arch/{ => importers}/exportIFC.py (99%) rename src/Mod/Arch/{ => importers}/exportIFCHelper.py (100%) rename src/Mod/Arch/{ => importers}/exportIFCStructuralTools.py (100%) rename src/Mod/Arch/{ => importers}/import3DS.py (100%) rename src/Mod/Arch/{ => importers}/importDAE.py (100%) rename src/Mod/Arch/{ => importers}/importGBXML.py (99%) rename src/Mod/Arch/{ => importers}/importIFC.py (99%) rename src/Mod/Arch/{ => importers}/importIFCHelper.py (100%) rename src/Mod/Arch/{ => importers}/importIFClegacy.py (99%) rename src/Mod/Arch/{ => importers}/importIFCmulticore.py (100%) rename src/Mod/Arch/{ => importers}/importJSON.py (97%) rename src/Mod/Arch/{ => importers}/importOBJ.py (98%) rename src/Mod/Arch/{ => importers}/importSH3D.py (98%) rename src/Mod/Arch/{ => importers}/importSHP.py (98%) rename src/Mod/Arch/{ => importers}/importWebGL.py (99%) diff --git a/src/Mod/Arch/importers/__init__.py b/src/Mod/Arch/importers/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Mod/Arch/exportIFC.py b/src/Mod/Arch/importers/exportIFC.py similarity index 99% rename from src/Mod/Arch/exportIFC.py rename to src/Mod/Arch/importers/exportIFC.py index e30d30bd70..e168c3bf93 100644 --- a/src/Mod/Arch/exportIFC.py +++ b/src/Mod/Arch/importers/exportIFC.py @@ -46,7 +46,6 @@ from DraftGeomUtils import vec from importIFCHelper import dd2dms from draftutils import params from draftutils.messages import _msg, _err -from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -55,6 +54,10 @@ __title__ = "FreeCAD IFC export" __author__ = ("Yorik van Havre", "Jonathan Wiedemann", "Bernd Hahnebach") __url__ = "https://www.freecad.org" +# Save the Python open function because it will be redefined +if open.__module__ in ['__builtin__', 'io']: + pyopen = open + # Templates and other definitions **** # Specific FreeCAD <-> IFC slang translations translationtable = { diff --git a/src/Mod/Arch/exportIFCHelper.py b/src/Mod/Arch/importers/exportIFCHelper.py similarity index 100% rename from src/Mod/Arch/exportIFCHelper.py rename to src/Mod/Arch/importers/exportIFCHelper.py diff --git a/src/Mod/Arch/exportIFCStructuralTools.py b/src/Mod/Arch/importers/exportIFCStructuralTools.py similarity index 100% rename from src/Mod/Arch/exportIFCStructuralTools.py rename to src/Mod/Arch/importers/exportIFCStructuralTools.py diff --git a/src/Mod/Arch/import3DS.py b/src/Mod/Arch/importers/import3DS.py similarity index 100% rename from src/Mod/Arch/import3DS.py rename to src/Mod/Arch/importers/import3DS.py diff --git a/src/Mod/Arch/importDAE.py b/src/Mod/Arch/importers/importDAE.py similarity index 100% rename from src/Mod/Arch/importDAE.py rename to src/Mod/Arch/importers/importDAE.py diff --git a/src/Mod/Arch/importGBXML.py b/src/Mod/Arch/importers/importGBXML.py similarity index 99% rename from src/Mod/Arch/importGBXML.py rename to src/Mod/Arch/importers/importGBXML.py index ae0c6f1389..5cc0f5ea18 100644 --- a/src/Mod/Arch/importGBXML.py +++ b/src/Mod/Arch/importers/importGBXML.py @@ -25,7 +25,6 @@ __url__ = "https://www.freecad.org" import FreeCAD import Draft -from builtins import open as pyopen if FreeCAD.GuiUp: from draftutils.translate import translate diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importers/importIFC.py similarity index 99% rename from src/Mod/Arch/importIFC.py rename to src/Mod/Arch/importers/importIFC.py index 0ef3528459..6b9340243d 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importers/importIFC.py @@ -44,7 +44,6 @@ import importIFCmulticore from draftutils import params from draftutils.messages import _msg, _err -from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui as Gui @@ -56,6 +55,10 @@ __url__ = "https://www.freecad.org" DEBUG = False # Set to True to see debug messages. Otherwise, totally silent ZOOMOUT = True # Set to False to not zoom extents after import +# Save the Python open function because it will be redefined +if open.__module__ in ['__builtin__', 'io']: + pyopen = open + # Templates and other definitions **** # which IFC type must create which FreeCAD type diff --git a/src/Mod/Arch/importIFCHelper.py b/src/Mod/Arch/importers/importIFCHelper.py similarity index 100% rename from src/Mod/Arch/importIFCHelper.py rename to src/Mod/Arch/importers/importIFCHelper.py diff --git a/src/Mod/Arch/importIFClegacy.py b/src/Mod/Arch/importers/importIFClegacy.py similarity index 99% rename from src/Mod/Arch/importIFClegacy.py rename to src/Mod/Arch/importers/importIFClegacy.py index 872e339e40..037e889ce5 100644 --- a/src/Mod/Arch/importIFClegacy.py +++ b/src/Mod/Arch/importers/importIFClegacy.py @@ -29,7 +29,6 @@ import FreeCAD, Arch, Draft, os, sys, time, Part, DraftVecUtils, uuid, math, re from draftutils import params from draftutils.translate import translate -from builtins import open as pyopen __title__="FreeCAD IFC importer" __author__ = "Yorik van Havre" @@ -55,7 +54,8 @@ supportedIfcTypes = ["IfcSite", "IfcBuilding", "IfcBuildingStorey", "IfcBeam", " "IfcPile", "IfcFooting", "IfcReinforcingBar", "IfcTendon"] # TODO : shading device not supported? - +if open.__module__ in ['__builtin__','io']: + pyopen = open # because we'll redefine open below def open(filename,skip=None): "called when freecad opens a file" @@ -1795,6 +1795,7 @@ def explorer(filename,schema="IFC2X3_TC1.exp"): tree.headerItem().setText(1, "") tree.headerItem().setText(2, "Item and Properties") bold = QtGui.QFont() + bold.setWeight(75) bold.setBold(True) #print(ifc.Entities) diff --git a/src/Mod/Arch/importIFCmulticore.py b/src/Mod/Arch/importers/importIFCmulticore.py similarity index 100% rename from src/Mod/Arch/importIFCmulticore.py rename to src/Mod/Arch/importers/importIFCmulticore.py diff --git a/src/Mod/Arch/importJSON.py b/src/Mod/Arch/importers/importJSON.py similarity index 97% rename from src/Mod/Arch/importJSON.py rename to src/Mod/Arch/importers/importJSON.py index 83239da499..32133898f9 100644 --- a/src/Mod/Arch/importJSON.py +++ b/src/Mod/Arch/importers/importJSON.py @@ -27,7 +27,6 @@ import FreeCAD import Draft import Mesh import Part -from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -38,7 +37,8 @@ else: def translate(ctxt, txt): return txt - +if open.__module__ in ['__builtin__','io']: + pythonopen = open def export(exportList, filename): @@ -52,7 +52,7 @@ def export(exportList, filename): } # Write file - outfile = pyopen(filename, "w") + outfile = pythonopen(filename, "w") json.dump(data, outfile, separators = (',', ':')) outfile.close() diff --git a/src/Mod/Arch/importOBJ.py b/src/Mod/Arch/importers/importOBJ.py similarity index 98% rename from src/Mod/Arch/importOBJ.py rename to src/Mod/Arch/importers/importOBJ.py index 97ae8e9ceb..70f95f790b 100644 --- a/src/Mod/Arch/importOBJ.py +++ b/src/Mod/Arch/importers/importOBJ.py @@ -32,7 +32,6 @@ import Mesh import MeshPart import Part from draftutils import params -from builtins import open as pyopen if FreeCAD.GuiUp: from draftutils.translate import translate @@ -51,7 +50,8 @@ else: # and supports exporting faces with more than 3 vertices # and supports object colors / materials - +if open.__module__ in ['__builtin__','io']: + pythonopen = open def findVert(aVertex,aList): "finds aVertex in aList, returns index" @@ -260,7 +260,7 @@ def export(exportList,filename,colors=None): outfile.close() FreeCAD.Console.PrintMessage(translate("Arch","Successfully written") + " " + filename + "\n") if materials: - outfile = pyopen(filenamemtl,"w") + outfile = pythonopen(filenamemtl,"w") outfile.write("# FreeCAD v" + ver[0] + "." + ver[1] + " build" + ver[2] + " Arch module\n") outfile.write("# https://www.freecad.org\n") kinds = {"AmbientColor":"Ka ","DiffuseColor":"Kd ","SpecularColor":"Ks ","EmissiveColor":"Ke ","Transparency":"Tr ","Dissolve":"d "} @@ -306,7 +306,7 @@ def insert(filename,docname): doc = FreeCAD.newDocument(docname) FreeCAD.ActiveDocument = doc - with pyopen(filename,"r") as infile: + with pythonopen(filename,"r") as infile: verts = [] facets = [] activeobject = None @@ -327,7 +327,7 @@ def insert(filename,docname): if line[:7] == "mtllib ": matlib = os.path.join(os.path.dirname(filename),line[7:]) if os.path.exists(matlib): - with pyopen(matlib,"r") as matfile: + with pythonopen(matlib,"r") as matfile: mname = None color = None trans = None diff --git a/src/Mod/Arch/importSH3D.py b/src/Mod/Arch/importers/importSH3D.py similarity index 98% rename from src/Mod/Arch/importSH3D.py rename to src/Mod/Arch/importers/importSH3D.py index 20244470c1..6ae6f9c25e 100644 --- a/src/Mod/Arch/importSH3D.py +++ b/src/Mod/Arch/importers/importSH3D.py @@ -34,7 +34,6 @@ import Arch import Draft import Mesh import Part -from builtins import open as pyopen ## @package importSH3D # \ingroup ARCH @@ -44,7 +43,8 @@ from builtins import open as pyopen DEBUG = True - +if open.__module__ in ['__builtin__','io']: + pyopen = open # because we'll redefine open below def open(filename): diff --git a/src/Mod/Arch/importSHP.py b/src/Mod/Arch/importers/importSHP.py similarity index 98% rename from src/Mod/Arch/importSHP.py rename to src/Mod/Arch/importers/importSHP.py index 46f1687ce7..4fe6c88eb3 100644 --- a/src/Mod/Arch/importSHP.py +++ b/src/Mod/Arch/importers/importSHP.py @@ -22,10 +22,10 @@ import os import FreeCAD -from builtins import open as pyopen translate = FreeCAD.Qt.translate - +if open.__module__ in ['__builtin__','io']: + pythonopen = open def open(filename): @@ -142,7 +142,7 @@ def checkShapeFileLibrary(): return False b = u.read() fp = os.path.join(FreeCAD.getUserMacroDir(True),"shapefile.py") - f = pyopen(fp,"wb") + f = pythonopen(fp,"wb") f.write(b) f.close() try: diff --git a/src/Mod/Arch/importWebGL.py b/src/Mod/Arch/importers/importWebGL.py similarity index 99% rename from src/Mod/Arch/importWebGL.py rename to src/Mod/Arch/importers/importWebGL.py index aa57efb654..c0c0b2df3d 100644 --- a/src/Mod/Arch/importWebGL.py +++ b/src/Mod/Arch/importers/importWebGL.py @@ -44,7 +44,6 @@ import Part import OfflineRenderingUtils import json import textwrap -from builtins import open as pyopen if FreeCAD.GuiUp: import FreeCADGui @@ -53,7 +52,7 @@ else: FreeCADGui = None def translate(ctxt, txt): return txt - +if open.__module__ in ['__builtin__','io']: pythonopen = open ## @package importWebGL # \ingroup ARCH @@ -869,7 +868,7 @@ def export( exportList, filename, colors = None, camera = None ): html = html.replace('$data', json.dumps(data, separators=(',', ':')) ) # Shape Data - outfile = pyopen(filename, "w") + outfile = pythonopen(filename, "w") outfile.write( html ) outfile.close() FreeCAD.Console.PrintMessage( translate("Arch", "Successfully written") + ' ' + filename + "\n" )