diff --git a/ifc_generator.py b/ifc_generator.py index 2c350c1..7c6a6bb 100644 --- a/ifc_generator.py +++ b/ifc_generator.py @@ -156,11 +156,18 @@ def generate_shape(ifcfile, elements, cached=False): for i in range(len(shape.Solids)): for j in range(len(shape.Solids[i].Faces)): scolors.append( - (sstyle[i * 4], sstyle[i * 4 + 1], sstyle[i * 4 + 2], 1.0 - sstyle[i * 4 + 3]) + ( + sstyle[i * 4], + sstyle[i * 4 + 1], + sstyle[i * 4 + 2], + 1.0 - sstyle[i * 4 + 3], + ) ) if len(colors) < len(shape.Faces): for i in range(len(shape.Faces) - len(colors)): - scolors.append((sstyle[0], sstyle[1], sstyle[2], 1.0 - sstyle[3])) + scolors.append( + (sstyle[0], sstyle[1], sstyle[2], 1.0 - sstyle[3]) + ) else: color = (sstyle[0], sstyle[1], sstyle[2], 1.0 - sstyle[3]) for f in shape.Faces: diff --git a/ifc_geometry.py b/ifc_geometry.py index 0885009..7958dc7 100644 --- a/ifc_geometry.py +++ b/ifc_geometry.py @@ -277,5 +277,13 @@ def set_geom_property(obj, prop): changed = set_attribute(ifcfile, elem, prop, value) if changed: - FreeCAD.Console.PrintLog("DEBUG: Changing prop" + obj.Label + ":" + str(prop) + "to" + str(getattr(obj, prop)) + "\n") + FreeCAD.Console.PrintLog( + "DEBUG: Changing prop" + + obj.Label + + ":" + + str(prop) + + "to" + + str(getattr(obj, prop)) + + "\n" + ) return changed diff --git a/ifc_import.py b/ifc_import.py index 7bf9969..7468b9d 100644 --- a/ifc_import.py +++ b/ifc_import.py @@ -109,9 +109,7 @@ def insert( return document -def get_options( - strategy=None, shapemode=None, switchwb=None, silent=False -): +def get_options(strategy=None, shapemode=None, switchwb=None, silent=False): """Shows a dialog to get import options shapemode: 0 = full shape diff --git a/ifc_status.py b/ifc_status.py index ec41183..e681a66 100644 --- a/ifc_status.py +++ b/ifc_status.py @@ -32,7 +32,7 @@ translate = FreeCAD.Qt.translate params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/NativeIFC") text_on = translate("BIM", "Strict IFC mode is ON (all objects are IFC)") -text_off = translate("BIM", "Strict IFC mode is OFF (IFC and non-IFC objects allowed)") +text_off = translate("BIM", "Strict IFC mode is OFF (IFC and non-IFC objects allowed)") def set_status_widget(statuswidget): @@ -43,8 +43,8 @@ def set_status_widget(statuswidget): # lock button lock_button = QtGui.QAction() path = os.path.dirname(os.path.dirname(__file__)) - icon = QtGui.QIcon(os.path.join(path, "icons", "IFC.svg")) - lock_button.setIcon(icon) + icon = QtGui.QIcon(os.path.join(path, "icons", "IFC.svg")) + lock_button.setIcon(icon) lock_button.setCheckable(True) doc = FreeCAD.ActiveDocument if doc and "IfcFilePath" in doc.PropertiesList: @@ -66,7 +66,7 @@ def set_status_widget(statuswidget): def toggle_lock(checked=False): """Sets the lock button on/off""" - + from PySide import QtGui # lazy loading mw = FreeCADGui.getMainWindow() @@ -80,7 +80,7 @@ def toggle_lock(checked=False): statuswidget.lock_button.setChecked(False) statuswidget.lock_button.setText(" ") statuswidget.lock_button.setToolTip(text_off) - + def do_lock(checked): """Locks or unlocks the document""" @@ -102,7 +102,9 @@ def unlock_document(): doc.openTransaction("Unlock document") children = [o for o in doc.Objects if not o.InList] if children: - project = ifc_tools.create_document_object(doc, filename = doc.IfcFilePath, silent = True) + project = ifc_tools.create_document_object( + doc, filename=doc.IfcFilePath, silent=True + ) project.Group = children props = ["IfcFilePath", "Modified", "Proxy", "Schema"] props += [p for p in doc.PropertiesList if doc.getGroupOfProperty(p) == "IFC"] @@ -115,7 +117,7 @@ def unlock_document(): def lock_document(): """Locks the active document""" - + import ifc_tools # lazy loading import exportIFC import ifc_geometry @@ -126,14 +128,16 @@ def lock_document(): spatial = [] if "IfcFilePath" not in doc.PropertiesList: # this is not a locked document - projects = [o for o in doc.Objects if getattr(o,"Class",None) == "IfcProject"] + projects = [o for o in doc.Objects if getattr(o, "Class", None) == "IfcProject"] if len(projects) == 1: # 1 there is a project already project = projects[0] children = project.OutListRecursive rest = [o for o in doc.Objects if o not in children and o != project] doc.openTransaction("Lock document") - ifc_tools.convert_document(doc, filename=project.IfcFilePath, strategy=3, silent=True) + ifc_tools.convert_document( + doc, filename=project.IfcFilePath, strategy=3, silent=True + ) ifcfile = doc.Proxy.ifcfile if rest: # 1b some objects are outside @@ -146,7 +150,9 @@ def lock_document(): if not getattr(product, "VoidsElements", None): if not getattr(product, "Decomposes", None): new = ifc_tools.create_object(product, doc, ifcfile) - children = ifc_tools.create_children(new, ifcfile, recursive=True) + children = ifc_tools.create_children( + new, ifcfile, recursive=True + ) for o in [new] + children: ifc_geometry.add_geom_properties(o) for n in [o.Name for o in rest]: @@ -163,7 +169,9 @@ def lock_document(): doc.recompute() elif len(projects) > 1: # 2 there is more than one project - FreeCAD.Console.PrintError("Unable to lock this document because it contains several IFC documents\n") + FreeCAD.Console.PrintError( + "Unable to lock this document because it contains several IFC documents\n" + ) QtCore.QTimer.singleShot(100, toggle_lock) elif doc.Objects: # 3 there is no project but objects @@ -186,7 +194,7 @@ def lock_document(): def find_toplevel(objs): """Finds the top-level objects from the list""" - + # filter out any object that depend on another from the list nobjs = [] for obj in objs: @@ -201,7 +209,7 @@ def find_toplevel(objs): for obj in objs: if obj.isDerivedFrom("Part::Feature"): if obj.Shape.Edges and not obj.Shape.Solids: - print("Excluding",obj.Label,"- 2D objects not supported yet") + print("Excluding", obj.Label, "- 2D objects not supported yet") else: nobjs.append(obj) else: diff --git a/ifc_tools.py b/ifc_tools.py index 787d68d..576f074 100644 --- a/ifc_tools.py +++ b/ifc_tools.py @@ -459,8 +459,9 @@ def add_object(document, otype=None, oname="IfcObject"): obj = document.addObject(ftype, oname, proxy, vp, False) if obj.ViewObject and otype == "layer": from draftviewproviders import view_layer # lazy import + view_layer.ViewProviderLayer(obj.ViewObject) - obj.ViewObject.addProperty("App::PropertyBool","HideChildren","Layer") + obj.ViewObject.addProperty("App::PropertyBool", "HideChildren", "Layer") obj.ViewObject.HideChildren = True return obj @@ -534,7 +535,7 @@ def add_properties( elif attr_def and "IfcLengthMeasure" in str(attr_def.type_of_attribute()): obj.addProperty("App::PropertyDistance", attr, "IFC") if value: - setattr(obj, attr, value*(1/get_scale(ifcfile))) + setattr(obj, attr, value * (1 / get_scale(ifcfile))) elif isinstance(value, int): if attr not in obj.PropertiesList: obj.addProperty("App::PropertyInteger", attr, "IFC") @@ -762,11 +763,11 @@ def set_colors(obj, colors): if isinstance(colors[0], (tuple, list)): obj.ViewObject.ShapeColor = colors[0][:3] if len(colors[0]) > 3: - obj.ViewObject.Transparency = int(colors[0][3]*100) + obj.ViewObject.Transparency = int(colors[0][3] * 100) else: obj.ViewObject.ShapeColor = colors[:3] if len(colors) > 3: - obj.ViewObject.Transparency = int(colors[3]*100) + obj.ViewObject.Transparency = int(colors[3] * 100) if hasattr(obj.ViewObject, "DiffuseColor"): # strip out transparency value because it currently gives ugly # results in FreeCAD when combining transparent and non-transparent objects @@ -1229,7 +1230,7 @@ def get_group(project, name): doc = project group = add_object(doc, otype="group", oname=name) group.Label = name.strip("Ifc").strip("Group") - #if FreeCAD.GuiUp: + # if FreeCAD.GuiUp: # group.ViewObject.ShowInTree = PARAMS.GetBool("ShowDataGroups", False) if hasattr(project.Proxy, "addObject"): project.Proxy.addObject(project, group) diff --git a/ifc_viewproviders.py b/ifc_viewproviders.py index c86ddac..85c8fba 100644 --- a/ifc_viewproviders.py +++ b/ifc_viewproviders.py @@ -188,8 +188,8 @@ def expandChildren(self, obj=None): # expand the item in the tree view mw = FreeCADGui.getMainWindow() - tree = mw.findChild(QtGui.QDockWidget,"Model") - model = tree.findChild(QtGui.QWidget,"Model") + tree = mw.findChild(QtGui.QDockWidget, "Model") + model = tree.findChild(QtGui.QWidget, "Model") splitter = model.findChild(QtGui.QSplitter) tree = splitter.children()[1].children()[0] it = tree.findItems(obj.Label, QtCore.Qt.MatchRecursive, 0)