Skip to content

Commit

Permalink
Orphans group is now always created and by default hidden in the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed May 26, 2023
1 parent 701d6f9 commit 8a46c35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ifc_objects.py
Expand Up @@ -71,7 +71,7 @@ def onDocumentRestored(self, obj):
if hasattr(obj, "FilePath"):
# once we have loaded the project, recalculate child coin nodes
for child in obj.OutListRecursive:
if child.ShapeMode == "Coin":
if getattr(child, "ShapeMode", None) == "Coin":
child.Proxy.cached = True
child.touch()

Expand Down
12 changes: 6 additions & 6 deletions ifc_selftest.py
Expand Up @@ -103,7 +103,7 @@ def test01_ImportCoinSingle(self):
fp, "IfcTest", strategy=0, shapemode=1, switchwb=0, silent=True
)
fco = len(FreeCAD.getDocument("IfcTest").Objects)
self.failUnless(fco == 1, "ImportCoinSingle failed")
self.failUnless(fco == 2, "ImportCoinSingle failed")

def test02_ImportCoinStructure(self):
FreeCAD.Console.PrintMessage(
Expand All @@ -115,7 +115,7 @@ def test02_ImportCoinStructure(self):
fp, "IfcTest", strategy=1, shapemode=1, switchwb=0, silent=True
)
fco = len(FreeCAD.getDocument("IfcTest").Objects)
self.failUnless(fco == 4, "ImportCoinStructure failed")
self.failUnless(fco == 5, "ImportCoinStructure failed")

def test03_ImportCoinFull(self):
global FCSTD_FILE_PATH
Expand All @@ -129,7 +129,7 @@ def test03_ImportCoinFull(self):
d.saveAs(path)
FCSTD_FILE_PATH = path
fco = len(FreeCAD.getDocument("IfcTest").Objects)
self.failUnless(fco > 4, "ImportCoinFull failed")
self.failUnless(fco > 5, "ImportCoinFull failed")

def test04_ImportShapeFull(self):
FreeCAD.Console.PrintMessage("4. NativeIFC import: Full model, shape mode...")
Expand All @@ -139,7 +139,7 @@ def test04_ImportShapeFull(self):
fp, "IfcTest", strategy=2, shapemode=0, switchwb=0, silent=True
)
fco = len(FreeCAD.getDocument("IfcTest").Objects)
self.failUnless(fco > 4, "ImportShapeFull failed")
self.failUnless(fco > 5, "ImportShapeFull failed")

def test05_ImportFreeCAD(self):
FreeCAD.Console.PrintMessage("5. FreeCAD import: NativeIFC coin file...")
Expand Down Expand Up @@ -172,7 +172,7 @@ def test07_CreateDocument(self):
ifc_tools.create_document(doc, silent=True)
fco = len(FreeCAD.getDocument("IfcTest").Objects)
print(FreeCAD.getDocument("IfcTest").Objects[0])
self.failUnless(fco == 1, "CreateDocument failed")
self.failUnless(fco == 2, "CreateDocument failed")

def test08_ChangeIFCSchema(self):
FreeCAD.Console.PrintMessage("8. Changing IFC schema...")
Expand Down Expand Up @@ -215,7 +215,7 @@ def test09_CreateBIMObjects(self):
fco = len(FreeCAD.getDocument("IfcTest").Objects)
ifco = len(proj.Proxy.ifcfile.by_type("IfcRoot"))
print(ifco, "IFC objects created")
self.failUnless(fco == 8 and ifco == 12, "CreateDocument failed")
self.failUnless(fco == 9 and ifco == 12, "CreateDocument failed")


# test changing placement
Expand Down
25 changes: 20 additions & 5 deletions ifc_tools.py
Expand Up @@ -50,6 +50,7 @@
SCALE = 1000.0 # IfcOpenShell works in meters, FreeCAD works in mm
SHORT = False # If True, only Step ID attribute is created
ROUND = 8 # rounding value for placements
SHOW_GROUPS = False # to see special groups by default or not in the tree


def create_document(document, filename=None, shapemode=0, strategy=0, silent=False):
Expand Down Expand Up @@ -81,6 +82,7 @@ def create_document(document, filename=None, shapemode=0, strategy=0, silent=Fal
obj.Proxy.ifcfile = ifcfile
add_properties(obj, ifcfile, project, shapemode=shapemode)
obj.addProperty("App::PropertyEnumeration", "Schema", "Base")
get_group(obj, "IfcOrphansGroup")
obj.Schema = ifcopenshell.ifcopenshell_wrapper.schema_names()
obj.Schema = ifcfile.wrapped_data.schema_name()
# populate according to strategy
Expand Down Expand Up @@ -278,7 +280,7 @@ def can_expand(obj, ifcfile=None):
return False


def add_object(document, otype=None):
def add_object(document, otype=None, oname="IfcObject"):
"""adds a new object to a FreeCAD document.
otype can be 'project', 'group' or None (normal object)"""

Expand All @@ -294,7 +296,7 @@ def add_object(document, otype=None):
vp = ifc_viewproviders.ifc_vp_group()
else:
vp = ifc_viewproviders.ifc_vp_object()
obj = document.addObject(ftype, "IfcObject", proxy, vp, False)
obj = document.addObject(ftype, oname, proxy, vp, False)
return obj


Expand Down Expand Up @@ -1265,6 +1267,21 @@ def get_orphan_elements(ifcfile):
return products


def get_group(project, name):
"""returns a group of the given type under the given IFC project. Creates it if needed"""

for c in project.Group:
if c.isDerivedFrom("App::DocumentObjectGroupPython"):
if c.Name == name:
return c
group = add_object(project.Document, otype="group", oname=name)
group.Label = "Orphan objects"
if FreeCAD.GuiUp:
group.ViewObject.ShowInTree = SHOW_GROUPS
project.Proxy.addObject(project, group)
return group


def load_orphans(obj):
"""loads orphan objects from the given project object"""

Expand All @@ -1273,9 +1290,7 @@ def load_orphans(obj):
shapemode = obj.ShapeMode
elements = get_orphan_elements(ifcfile)
if elements:
group = add_object(doc, otype="group")
group.Label = "Orphans"
obj.Proxy.addObject(obj, group)
group = get_group(obj, "IfcOrphansGroup")
for element in elements:
child = create_object(element, doc, ifcfile, shapemode)
group.addObject(child)
Expand Down

0 comments on commit 8a46c35

Please sign in to comment.