Draft: Independence from BIM (#17444)

* Draft: Independence from BIM - follow-up of #17390

* Draft: More info in DXF importer if BIM not present
This commit is contained in:
Yorik van Havre
2024-11-16 17:48:28 +01:00
committed by GitHub
parent 7183de92a4
commit ee2f384b2f
3 changed files with 51 additions and 34 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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"))