BIM: Added NativeIFC support to Add/remove tools

This commit is contained in:
Yorik van Havre
2024-10-04 12:17:45 +02:00
committed by Yorik van Havre
parent 5d1cba326b
commit 48b5543cf6
4 changed files with 34 additions and 7 deletions

View File

@@ -54,6 +54,10 @@ class Arch_Add:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Add space boundary"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.addSpaceBoundaries( FreeCAD.ActiveDocument."+sel[-1].Name+", FreeCADGui.Selection.getSelectionEx() )")
elif Draft.getType(sel[-1]).startswith("Ifc"):
FreeCADGui.addModule("nativeifc.ifc_tools")
for s in sel[:-1]:
FreeCADGui.doCommand("nativeifc.ifc_tools.aggregate(FreeCAD.ActiveDocument."+s.Name+",FreeCAD.ActiveDocument."+sel[-1].Name+")")
else:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Grouping"))
if not Arch.mergeCells(sel):
@@ -89,6 +93,10 @@ class Arch_Remove:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Remove space boundary"))
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.removeSpaceBoundaries( FreeCAD.ActiveDocument."+sel[-1].Name+", FreeCADGui.Selection.getSelection() )")
elif Draft.getType(sel[-1]).startswith("Ifc"):
FreeCADGui.addModule("nativeifc.ifc_tools")
for s in sel[:-1]:
FreeCADGui.doCommand("nativeifc.ifc_tools.aggregate(FreeCAD.ActiveDocument."+s.Name+",FreeCAD.ActiveDocument."+sel[-1].Name+",mode='opening')")
else:
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Ungrouping"))
if len(sel) > 1:

View File

@@ -2362,6 +2362,10 @@ def getRepresentation(
# actual ifcmaterial)
shapecolor = obj.ViewObject.ShapeColor[:3]
transparency = obj.ViewObject.Transparency/100.0
if transparency == 1:
# fix buggy fully transparent materials
# TODO there is some problem somewhere in ShapeAppearance that needs solving.
transparency = 0.
if hasattr(obj.ViewObject,"DiffuseColor"):
diffusecolor = obj.ViewObject.DiffuseColor
if shapecolor and (shapetype != "clone"): # cloned objects are already colored

View File

@@ -26,6 +26,7 @@ import difflib
import FreeCAD
import FreeCADGui
import ifcopenshell
from nativeifc import ifc_tools
import Arch_rc
translate = FreeCAD.Qt.translate
@@ -41,7 +42,12 @@ def get_diff(proj):
# than ifcopenshell and diff does not work
f = ifcopenshell.open(proj.IfcFilePath)
old = f.wrapped_data.to_string().split("\n")
new = proj.Proxy.ifcfile.wrapped_data.to_string().split("\n")
if not old:
return ""
ifcfile = ifc_tools.get_ifcfile(proj)
if not ifcfile:
return ""
new = ifcfile.wrapped_data.to_string().split("\n")
# diff = difflib.HtmlDiff().make_file(old,new) # UGLY
res = [l for l in difflib.unified_diff(old, new, lineterm="")]
res = [l for l in res if l.startswith("+") or l.startswith("-")]

View File

@@ -414,6 +414,8 @@ def get_ifcfile(obj):
if getattr(project, "Proxy", None):
project.Proxy.ifcfile = ifcfile
return ifcfile
else:
FreeCAD.Console.PrintError("Error: No IFC file attached to this project")
return None
@@ -977,14 +979,17 @@ def save(obj, filepath=None):
obj.Modified = False
def aggregate(obj, parent):
"""Takes any FreeCAD object and aggregates it to an existing IFC object"""
def aggregate(obj, parent, mode=None):
"""Takes any FreeCAD object and aggregates it to an existing IFC object.
Mode can be 'opening' to force-create a subtraction"""
proj = get_project(parent)
if not proj:
FreeCAD.Console.PrintError("The parent object is not part of an IFC project\n")
return
ifcfile = get_ifcfile(proj)
if not ifcfile:
return
product = None
stepid = getattr(obj, "StepId", None)
if stepid:
@@ -1001,11 +1006,14 @@ def aggregate(obj, parent):
newobj = obj
new = False
else:
product = create_product(obj, parent, ifcfile)
ifcclass = None
if mode == "opening":
ifcclass = "IfcOpeningElement"
product = create_product(obj, parent, ifcfile, ifcclass)
shapemode = getattr(parent, "ShapeMode", DEFAULT_SHAPEMODE)
newobj = create_object(product, obj.Document, ifcfile, shapemode)
new = True
create_relationship(obj, newobj, parent, product, ifcfile)
create_relationship(obj, newobj, parent, product, ifcfile, mode)
base = getattr(obj, "Base", None)
if base:
# make sure the base is used only by this object before deleting
@@ -1179,7 +1187,7 @@ def get_subvolume(obj):
return tempface, tempobj
def create_relationship(old_obj, obj, parent, element, ifcfile):
def create_relationship(old_obj, obj, parent, element, ifcfile, mode=None):
"""Creates a relationship between an IFC object and a parent IFC object"""
if isinstance(parent, FreeCAD.DocumentObject):
@@ -1280,7 +1288,8 @@ def create_relationship(old_obj, obj, parent, element, ifcfile):
relating_object=container,
)
# case 4: void element
elif parent_element.is_a("IfcElement") and element.is_a("IfcOpeningElement"):
elif (parent_element.is_a("IfcElement") and element.is_a("IfcOpeningElement"))\
or (mode == "opening"):
uprel = api_run(
"void.add_opening", ifcfile, opening=element, element=parent_element
)