Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Mar 26, 2024
1 parent 1024d18 commit 0d49861
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 26 deletions.
11 changes: 9 additions & 2 deletions ifc_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion ifc_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions ifc_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 21 additions & 13 deletions ifc_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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()
Expand All @@ -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"""
Expand All @@ -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"]
Expand All @@ -115,7 +117,7 @@ def unlock_document():

def lock_document():
"""Locks the active document"""

import ifc_tools # lazy loading
import exportIFC
import ifc_geometry
Expand All @@ -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
Expand All @@ -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]:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions ifc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ifc_viewproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d49861

Please sign in to comment.