From ec70f760db4cea65fce14a6ec109062e443d20c3 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 24 Mar 2022 09:41:08 +0100 Subject: [PATCH] Arch: fixed missing multicore IFC import of 2D annotations --- src/Mod/Arch/importIFC.py | 74 ++------------------------- src/Mod/Arch/importIFCHelper.py | 80 +++++++++++++++++++++++++++++- src/Mod/Arch/importIFCmulticore.py | 8 +++ 3 files changed, 89 insertions(+), 73 deletions(-) diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 718a43e5bf..461b3795ca 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -1166,76 +1166,8 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None): continue # user given id skip list if annotation.is_a() in preferences['SKIP']: continue # preferences-set type skip list - if annotation.is_a("IfcGrid"): - axes = [] - uvwaxes = () - if annotation.UAxes: - uvwaxes = annotation.UAxes - if annotation.VAxes: - uvwaxes = uvwaxes + annotation.VAxes - if annotation.WAxes: - uvwaxes = uvwaxes + annotation.WAxes - for axis in uvwaxes: - if axis.AxisCurve: - sh = importIFCHelper.get2DShape(axis.AxisCurve,ifcscale) - if sh and (len(sh[0].Vertexes) == 2): # currently only straight axes are supported - sh = sh[0] - l = sh.Length - pl = FreeCAD.Placement() - pl.Base = sh.Vertexes[0].Point - pl.Rotation = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),sh.Vertexes[-1].Point.sub(sh.Vertexes[0].Point)) - o = Arch.makeAxis(1,l) - o.Length = l - o.Placement = pl - o.CustomNumber = axis.AxisTag - axes.append(o) - if axes: - name = "Grid" - grid_placement = None - if annotation.Name: - name = annotation.Name - if six.PY2: - name = name.encode("utf8") - if annotation.ObjectPlacement: - # https://forum.freecadweb.org/viewtopic.php?f=39&t=40027 - grid_placement = importIFCHelper.getPlacement( - annotation.ObjectPlacement, - scaling=1 - ) - if preferences['PREFIX_NUMBERS']: - name = "ID" + str(aid) + " " + name - anno = Arch.makeAxisSystem(axes,name) - if grid_placement: - anno.Placement = grid_placement - print(" axis") - else: - name = "Annotation" - if annotation.Name: - name = annotation.Name - if six.PY2: - name = name.encode("utf8") - if "annotation" not in name.lower(): - name = "Annotation " + name - if preferences['PREFIX_NUMBERS']: name = "ID" + str(aid) + " " + name - shapes2d = [] - for rep in annotation.Representation.Representations: - if rep.RepresentationIdentifier in ["Annotation","FootPrint","Axis"]: - sh = importIFCHelper.get2DShape(rep,ifcscale) - if sh in doc.Objects: - # dirty hack: get2DShape might return an object directly if non-shape based (texts for ex) - anno = sh - else: - shapes2d.extend(sh) - if shapes2d: - sh = Part.makeCompound(shapes2d) - if preferences['DEBUG']: print(" shape") - anno = doc.addObject("Part::Feature",name) - anno.Shape = sh - p = importIFCHelper.getPlacement(annotation.ObjectPlacement,ifcscale) - if p: # and annotation.is_a("IfcAnnotation"): - anno.Placement = p - else: - if preferences['DEBUG']: print(" no shape") + + anno = importIFCHelper.createAnnotation(annotation,doc,ifcscale,preferences) # placing in container if needed @@ -1299,7 +1231,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None): for added_mat in added_mats: if ( "Description" in added_mat.Material - and "DiffuseColor" in added_mat.Material + and "DiffuseColor" in added_mat.Material and "DiffuseColor" in mdict # Description has been set thus it is in mdict and added_mat.Material["Description"] == mdict["Description"] and added_mat.Material["DiffuseColor"] == mdict["DiffuseColor"] diff --git a/src/Mod/Arch/importIFCHelper.py b/src/Mod/Arch/importIFCHelper.py index e71cccd60a..913b4beabf 100644 --- a/src/Mod/Arch/importIFCHelper.py +++ b/src/Mod/Arch/importIFCHelper.py @@ -860,8 +860,8 @@ def get2DShape(representation,scaling=1000): elif item.is_a("IfcTextLiteral"): pl = getPlacement(item.Placement, scaling) if pl: - t = Draft.makeText([item.Literal], point=pl.Base) - return [t] # dirty hack... Object creation should not be done here + t = Draft.make_text(item.Literal.split(";"), pl.Base) + return [] # TODO dirty hack... Object creation should not be done here elif representation.is_a() in ["IfcPolyline","IfcCircle","IfcTrimmedCurve","IfcRectangleProfileDef"]: result = getCurveSet(representation) return result @@ -1020,3 +1020,79 @@ def getParents(ifcobj): if rel.is_a("IfcRelAggregates"): parentlist.append(rel.RelatingObject) return parentlist + + +def createAnnotation(annotation,doc,ifcscale,preferences): + """creates an annotation object""" + + anno = None + if annotation.is_a("IfcGrid"): + axes = [] + uvwaxes = () + if annotation.UAxes: + uvwaxes = annotation.UAxes + if annotation.VAxes: + uvwaxes = uvwaxes + annotation.VAxes + if annotation.WAxes: + uvwaxes = uvwaxes + annotation.WAxes + for axis in uvwaxes: + if axis.AxisCurve: + sh = get2DShape(axis.AxisCurve,ifcscale) + if sh and (len(sh[0].Vertexes) == 2): # currently only straight axes are supported + sh = sh[0] + l = sh.Length + pl = FreeCAD.Placement() + pl.Base = sh.Vertexes[0].Point + pl.Rotation = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),sh.Vertexes[-1].Point.sub(sh.Vertexes[0].Point)) + o = Arch.makeAxis(1,l) + o.Length = l + o.Placement = pl + o.CustomNumber = axis.AxisTag + axes.append(o) + if axes: + name = "Grid" + grid_placement = None + if annotation.Name: + name = annotation.Name + if six.PY2: + name = name.encode("utf8") + if annotation.ObjectPlacement: + # https://forum.freecadweb.org/viewtopic.php?f=39&t=40027 + grid_placement = getPlacement(annotation.ObjectPlacement,scaling=1) + if preferences['PREFIX_NUMBERS']: + name = "ID" + str(aid) + " " + name + anno = Arch.makeAxisSystem(axes,name) + if grid_placement: + anno.Placement = grid_placement + print(" axis") + else: + name = "Annotation" + if annotation.Name: + name = annotation.Name + if six.PY2: + name = name.encode("utf8") + if "annotation" not in name.lower(): + name = "Annotation " + name + if preferences['PREFIX_NUMBERS']: name = "ID" + str(aid) + " " + name + shapes2d = [] + for rep in annotation.Representation.Representations: + if rep.RepresentationIdentifier in ["Annotation","FootPrint","Axis"]: + sh = get2DShape(rep,ifcscale) + if sh in doc.Objects: + # dirty hack: get2DShape might return an object directly if non-shape based (texts for ex) + anno = sh + else: + shapes2d.extend(sh) + if shapes2d: + import Part + sh = Part.makeCompound(shapes2d) + #if preferences['DEBUG']: print(" shape") + anno = doc.addObject("Part::Feature",name) + anno.Shape = sh + p = getPlacement(annotation.ObjectPlacement,ifcscale) + if p: # and annotation.is_a("IfcAnnotation"): + anno.Placement = p + #else: + #if preferences['DEBUG']: print(" no shape") + + return anno diff --git a/src/Mod/Arch/importIFCmulticore.py b/src/Mod/Arch/importIFCmulticore.py index cb4a8bd6ac..fc8427f74f 100644 --- a/src/Mod/Arch/importIFCmulticore.py +++ b/src/Mod/Arch/importIFCmulticore.py @@ -118,6 +118,14 @@ def insert(filename,docname=None,preferences=None): if not iterator.next(): break + # process 2D annotations + annotations = ifcfile.by_type("IfcAnnotation") + if annotations: + print("Processing",str(len(annotations)),"annotations...") + ifcscale = importIFCHelper.getScaling(ifcfile) + for annotation in annotations: + importIFCHelper.createAnnotation(annotation,FreeCAD.ActiveDocument,ifcscale,preferences) + # post-processing processRelationships() storeColorDict()