From ee2f384b2fdfb5a3201b2d619fde8f45950da9f8 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sat, 16 Nov 2024 17:48:28 +0100 Subject: [PATCH] Draft: Independence from BIM (#17444) * Draft: Independence from BIM - follow-up of #17390 * Draft: More info in DXF importer if BIM not present --- src/Mod/Draft/draftmake/make_clone.py | 53 +++++++++++++---------- src/Mod/Draft/draftobjects/shape2dview.py | 6 ++- src/Mod/Draft/importDXF.py | 26 +++++++---- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/Mod/Draft/draftmake/make_clone.py b/src/Mod/Draft/draftmake/make_clone.py index 0af48100db..8fe82ee1df 100644 --- a/src/Mod/Draft/draftmake/make_clone.py +++ b/src/Mod/Draft/draftmake/make_clone.py @@ -72,32 +72,37 @@ def make_clone(obj, delta=None, forcedraft=False): cl.Label = prefix + obj[0].Label + " (2D)" elif (len(obj) == 1) and (hasattr(obj[0],"CloneOf") or (utils.get_type(obj[0]) == "BuildingPart")) and (not forcedraft): # arch objects can be clones - import Arch - if utils.get_type(obj[0]) == "BuildingPart": - cl = Arch.makeComponent() + try: + import Arch + except: + # BIM not present + pass else: - try: # new-style make function - cl = getattr(Arch, "make_" + obj[0].Proxy.Type.lower())() - except Exception: - try: # old-style make function - cl = getattr(Arch, "make" + obj[0].Proxy.Type)() + if utils.get_type(obj[0]) == "BuildingPart": + cl = Arch.makeComponent() + else: + try: # new-style make function + cl = getattr(Arch, "make_" + obj[0].Proxy.Type.lower())() except Exception: - pass # not a standard Arch object... Fall back to Draft mode - if cl: - base = utils.get_clone_base(obj[0]) - cl.Label = prefix + base.Label - cl.CloneOf = base - if utils.get_type(obj[0]) != "BuildingPart": - cl.Placement = obj[0].Placement - for prop in ("Description", "IfcType", "Material", "Subvolume", "Tag"): - try: - setattr(cl, prop, getattr(base, prop)) - except Exception: - pass - if App.GuiUp: - gui_utils.format_object(cl, base) - gui_utils.select(cl) - return cl + try: # old-style make function + cl = getattr(Arch, "make" + obj[0].Proxy.Type)() + except Exception: + pass # not a standard Arch object... Fall back to Draft mode + if cl: + base = utils.get_clone_base(obj[0]) + cl.Label = prefix + base.Label + cl.CloneOf = base + if utils.get_type(obj[0]) != "BuildingPart": + cl.Placement = obj[0].Placement + for prop in ("Description", "IfcType", "Material", "Subvolume", "Tag"): + try: + setattr(cl, prop, getattr(base, prop)) + except Exception: + pass + if App.GuiUp: + gui_utils.format_object(cl, base) + gui_utils.select(cl) + return cl # fall back to Draft clone mode if not cl: diff --git a/src/Mod/Draft/draftobjects/shape2dview.py b/src/Mod/Draft/draftobjects/shape2dview.py index 1a9e49ec57..8cfbf10a16 100644 --- a/src/Mod/Draft/draftobjects/shape2dview.py +++ b/src/Mod/Draft/draftobjects/shape2dview.py @@ -230,7 +230,11 @@ class Shape2DView(DraftObject): onlysolids = obj.Base.OnlySolids if hasattr(obj,"OnlySolids"): # override base object onlysolids = obj.OnlySolids - import Arch + try: + import Arch + except: + print("Shape2DView: BIM not present, unable to recompute") + return objs = groups.get_group_contents(objs, walls=True) if getattr(obj,"VisibleOnly",True): objs = gui_utils.remove_hidden(objs) diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index d908465c54..324212d2b0 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -104,6 +104,22 @@ def errorDXFLib(gui): ----- Use local variables, not global variables. """ + + def show_addon_message(gui): + if gui: + message = translate("Draft", """Download of dxf libraries failed. +Please install the dxf Library addon manually +from menu Tools -> Addon Manager""") + QtWidgets.QMessageBox.information(None, "", message) + else: + FCC.PrintWarning("The DXF import/export libraries needed by FreeCAD to handle the DXF format are not installed.\n") + FCC.PrintWarning("Please install the dxf Library addon from Tools -> Addon Manager\n") + try: + import ArchCommands + except: + # BIM not present + show_addon_message(gui) + return dxfAllowDownload = params.get_param("dxfAllowDownload") if dxfAllowDownload: files = ['dxfColorMap.py', 'dxfImportObjects.py', @@ -111,7 +127,6 @@ def errorDXFLib(gui): baseurl = 'https://raw.githubusercontent.com/yorikvanhavre/' baseurl += 'Draft-dxf-importer/master/' - import ArchCommands from FreeCAD import Base progressbar = Base.ProgressIndicator() progressbar.start("Downloading files...", 4) @@ -120,14 +135,7 @@ def errorDXFLib(gui): p = None p = ArchCommands.download(baseurl + f, force=True) if not p: - if gui: - message = translate("Draft", """Download of dxf libraries failed. -Please install the dxf Library addon manually -from menu Tools -> Addon Manager""") - QtWidgets.QMessageBox.information(None, "", message) - else: - FCC.PrintWarning("The DXF import/export libraries needed by FreeCAD to handle the DXF format are not installed.\n") - FCC.PrintWarning("Please install the dxf Library addon from Tools -> Addon Manager\n") + show_addon_message(gui) break progressbar.stop() sys.path.append(FreeCAD.ConfigGet("UserAppData"))