| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | """Document observer to act on documents containing NativeIFC objects""" |
| |
|
| | import FreeCAD |
| |
|
| |
|
| | params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/NativeIFC") |
| |
|
| |
|
| | def add_observer(): |
| | """Adds this observer to the running FreeCAD instance""" |
| |
|
| | FreeCAD.BIMobserver = ifc_observer() |
| | FreeCAD.addDocumentObserver(FreeCAD.BIMobserver) |
| |
|
| |
|
| | def remove_observer(): |
| | """Removes this observer if present""" |
| |
|
| | if hasattr(FreeCAD, "BIMobserver"): |
| | FreeCAD.removeDocumentObserver(FreeCAD.BIMobserver) |
| | del FreeCAD.BIMobserver |
| |
|
| |
|
| | class ifc_observer: |
| | """A general document observer that handles IFC objects""" |
| |
|
| | def __init__(self): |
| | |
| | |
| | if FreeCAD.ActiveDocument: |
| | self.slotActivateDocument(FreeCAD.ActiveDocument) |
| |
|
| | def slotStartSaveDocument(self, doc, value): |
| | """Save all IFC documents in this doc""" |
| |
|
| | from PySide import QtCore |
| |
|
| | self.docname = doc.Name |
| | |
| | |
| | |
| | QtCore.QTimer.singleShot(100, self.save) |
| |
|
| | def slotDeletedObject(self, obj): |
| | """Deletes the corresponding object in the IFC document""" |
| |
|
| | from . import ifc_tools |
| |
|
| | proj = ifc_tools.get_project(obj) |
| | if not proj: |
| | return |
| | if not hasattr(obj, "Proxy"): |
| | return |
| | if getattr(obj.Proxy, "nodelete", False): |
| | return |
| | ifc_tools.remove_ifc_element(obj) |
| |
|
| | def slotChangedDocument(self, doc, prop): |
| | """Watch document IFC properties""" |
| |
|
| | |
| | if "IfcFilePath" not in doc.PropertiesList: |
| | return |
| |
|
| | from . import ifc_tools |
| |
|
| | if prop == "Schema": |
| | schema = doc.Schema |
| | ifcfile = ifc_tools.get_ifcfile(doc) |
| | if ifcfile: |
| | if schema != ifcfile.wrapped_data.schema_name(): |
| | |
| | ifcfile, migration_table = ifc_tools.migrate_schema(ifcfile, schema) |
| | doc.Proxy.ifcfile = ifcfile |
| | |
| | for old_id, new_id in migration_table.items(): |
| | child = [o for o in doc.Objects if getattr(o, "StepId", None) == old_id] |
| | if len(child) == 1: |
| | child[0].StepId = new_id |
| | elif prop == "Label": |
| | ifcfile = ifc_tools.get_ifcfile(doc) |
| | project = ifc_tools.get_ifc_element(doc) |
| | ifc_tools.set_attribute(ifcfile, project, "Name", doc.Label) |
| |
|
| | def slotCreatedObject(self, obj): |
| | """If this is an IFC document, turn the object into IFC""" |
| |
|
| | doc = getattr(obj, "Document", None) |
| | if doc: |
| | if hasattr(doc, "IfcFilePath"): |
| | from PySide import QtCore |
| |
|
| | self.objname = obj.Name |
| | self.docname = obj.Document.Name |
| | |
| | QtCore.QTimer.singleShot(100, self.convert) |
| |
|
| | def slotActivateDocument(self, doc): |
| | """Check if we need to lock""" |
| |
|
| | from . import ifc_status |
| |
|
| | ifc_status.on_activate() |
| |
|
| | def slotRemoveDynamicProperty(self, obj, prop): |
| |
|
| | from . import ifc_psets |
| |
|
| | ifc_psets.remove_property(obj, prop) |
| |
|
| | |
| |
|
| | def fit_all(self): |
| | """Fits the view""" |
| |
|
| | if FreeCAD.GuiUp: |
| | import FreeCADGui |
| |
|
| | FreeCADGui.SendMsgToActiveView("ViewFit") |
| |
|
| | def save(self): |
| | """Saves all IFC documents contained in self.docname Document""" |
| |
|
| | if not hasattr(self, "docname"): |
| | return |
| | if self.docname not in FreeCAD.listDocuments(): |
| | return |
| | doc = FreeCAD.getDocument(self.docname) |
| | del self.docname |
| | projects = [] |
| | if hasattr(doc, "IfcFilePath") and hasattr(doc, "Modified"): |
| | if doc.Modified: |
| | projects.append(doc) |
| | else: |
| | for obj in doc.findObjects(Type="Part::FeaturePython"): |
| | if hasattr(obj, "IfcFilePath") and hasattr(obj, "Modified"): |
| | if obj.Modified: |
| | projects.append(obj) |
| | if projects: |
| | from . import ifc_tools |
| | from . import ifc_viewproviders |
| |
|
| | ask = params.GetBool("AskBeforeSaving", True) |
| | if ask and FreeCAD.GuiUp: |
| | import Arch_rc |
| | import FreeCADGui |
| |
|
| | dlg = FreeCADGui.PySideUic.loadUi(":/ui/dialogExport.ui") |
| | result = dlg.exec_() |
| | if not result: |
| | return |
| | ask = dlg.checkAskBeforeSaving.isChecked() |
| | params.SetBool("AskBeforeSaving", ask) |
| |
|
| | for project in projects: |
| | if getattr(project.Proxy, "ifcfile", None): |
| | if project.IfcFilePath: |
| | ifc_tools.save(project) |
| | else: |
| | ifc_viewproviders.get_filepath(project) |
| | ifc_tools.save(project) |
| |
|
| | def convert(self): |
| | """Converts an object to IFC""" |
| |
|
| | if not hasattr(self, "objname") or not hasattr(self, "docname"): |
| | return |
| | if self.docname not in FreeCAD.listDocuments(): |
| | return |
| | doc = FreeCAD.getDocument(self.docname) |
| | if not doc: |
| | return |
| | obj = doc.getObject(self.objname) |
| | if not obj: |
| | return |
| | if "StepId" in obj.PropertiesList: |
| | return |
| | del self.docname |
| | del self.objname |
| | if ( |
| | obj.isDerivedFrom("Part::Feature") |
| | or "IfcType" in obj.PropertiesList |
| | or "CreateSpreadsheet" in obj.PropertiesList |
| | ): |
| | FreeCAD.Console.PrintLog("Converting " + obj.Label + " to IFC\n") |
| | from . import ifc_geometry |
| | from . import ifc_tools |
| |
|
| | newobj = ifc_tools.aggregate(obj, doc) |
| | ifc_geometry.add_geom_properties(newobj) |
| | doc.recompute() |
| |
|