Skip to content

Commit

Permalink
Allow to delete objects
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Apr 13, 2023
1 parent 75db008 commit cfe542d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -42,7 +42,8 @@ Check for updates on this project at https://yorik.uncreated.net/blog/nativeifc
* [x] Allow to create an IFC document without an existing IFC file
* [x] Allow to add building structure (building, storey...)
* [x] Allow to add a simple generic IFC product
* [ ] Allow to delete objects
* [x] Allow to delete objects
* [ ] Allow to hide children of an object
* [ ] Tie all of the above to BIM commands

#### 4. Allow advanced editing
Expand All @@ -54,6 +55,7 @@ Check for updates on this project at https://yorik.uncreated.net/blog/nativeifc
* [ ] Expand properties
* [ ] Allow to regroup elements
* [ ] Handle drag/drop
* [ ] Handle undo/redo
* [x] Allow to change the IFC schema

#### 5. Tie NativeIFC and BIM Workbenches
Expand Down
14 changes: 13 additions & 1 deletion ifc_observer.py
Expand Up @@ -35,7 +35,6 @@ def add_observer():


class ifc_observer:

"""A general document observer that handles IFC objects"""

def slotStartSaveDocument(self, doc, value):
Expand All @@ -50,6 +49,8 @@ def slotStartSaveDocument(self, doc, value):
QtCore.QTimer.singleShot(100, self.save)

def save(self):
"""Saves all IFC documents contained in self.docname Document"""

if not hasattr(self, "docname"):
return
if not self.docname in FreeCAD.listDocuments():
Expand Down Expand Up @@ -81,3 +82,14 @@ def save(self):
obj.ViewObject.Proxy.save()
else:
obj.ViewObject.Proxy.save_as()

def slotDeletedObject(self, obj):
"""Deletes the corresponding object in the IFC document"""

import ifc_tools # lazy loading

proj = ifc_tools.get_project(obj)
if not proj:
return
if ifc_tools.remove_ifc_element(obj):
proj.Modified = True
14 changes: 9 additions & 5 deletions ifc_tools.py
Expand Up @@ -325,7 +325,7 @@ def add_properties(
obj.addProperty("App::PropertyEnumeration", attr, "IFC")
items = ifcopenshell.util.attribute.get_enum_items(attr_def)
setattr(obj, attr, items)
if not value in items:
if value not in items:
for v in ("UNDEFINED", "NOTDEFINED", "USERDEFINED"):
if v in items:
value = v
Expand Down Expand Up @@ -370,7 +370,7 @@ def get_ifc_classes(obj, baseclass):
classes = [sub.name() for sub in declaration.supertype().subtypes()]
# also include subtypes of the current class (ex, StandardCases)
classes.extend([sub.name() for sub in declaration.subtypes()])
if not baseclass in classes:
if baseclass not in classes:
classes.append(baseclass)
return classes

Expand Down Expand Up @@ -635,7 +635,8 @@ def set_geometry(obj, elem, ifcfile, cached=False):
colors = None
if obj.ViewObject:
# getChild(2) is master on/off switch,
# getChild(0) is flatlines display mode (1 = shaded, 2 = wireframe, 3 = points)
# getChild(0) is flatlines display mode
# (1 = shaded, 2 = wireframe, 3 = points)
basenode = obj.ViewObject.RootNode.getChild(2).getChild(0)
if basenode.getNumChildren() == 5:
# Part VP has 4 nodes, we have added 1 more
Expand Down Expand Up @@ -1031,6 +1032,9 @@ def remove_ifc_element(obj):

# This function can become pure IFC

element = get_ifc_element(obj)
ifcfile = get_ifcfile(obj)
ifcopenshell.api.run("root.remove_product", ifcfile, product=element)
element = get_ifc_element(obj)
if ifcfile and element:
ifcopenshell.api.run("root.remove_product", ifcfile, product=element)
return True
return False

0 comments on commit cfe542d

Please sign in to comment.