diff --git a/lattice2BaseFeature.py b/lattice2BaseFeature.py index df257eb..f1c935f 100644 --- a/lattice2BaseFeature.py +++ b/lattice2BaseFeature.py @@ -141,17 +141,17 @@ class LatticeFeature(): obj.Placement = App.Placement() if bExposing: - obj.Shape = marker.copy() + obj.Shape = shallow_copy(marker) obj.Placement = plms[0] else: for plm in plms: - sh = marker.copy() + sh = shallow_copy(marker) sh.Placement = plm shapes.append(sh) if len(shapes) == 0: obj.Shape = lattice2Markers.getNullShapeShape(markerSize) - raise ValueError('Lattice object is null') #Feeding empty compounds to FreeCAD seems to cause rendering issues, otherwise it would have been a good idea to output nothing. + raise ValueError('Lattice object is null') sh = Part.makeCompound(shapes) obj.Shape = sh diff --git a/lattice2Common.py b/lattice2Common.py index ab4af1d..57ad837 100644 --- a/lattice2Common.py +++ b/lattice2Common.py @@ -80,6 +80,23 @@ def deselect(sel): '''deselect(sel): remove objects in sel from selection''' for selobj in sel: FreeCADGui.Selection.removeSelection(selobj.Object) + +def shallow_copy(shape): + copiers = { + "Vertex": lambda(sh): sh.Vertexes[0], + "Edge": lambda(sh): sh.Edges[0], + "Wire": lambda(sh): sh.Wires[0], + "Face": lambda(sh): sh.Faces[0], + "Shell": lambda(sh): sh.Shells[0], + "Solid": lambda(sh): sh.Solids[0], + "CompSolid": lambda(sh): sh.CompSolids[0], + "Compound": lambda(sh): sh.Compounds[0], + } + copier = copiers.get(shape.ShapeType) + if copier is None: + copier = lambda(sh): sh.copy() + FreeCAD.Console.PrintWarning("Lattice2: shallow_copy: unexpected shape type '{typ}'. Using deep copy instead.\n".format(typ= shape.ShapeType)) + return copier(shape) # OCC's Precision::Confusion; should have taken this from FreeCAD but haven't found; unlikely to ever change. DistConfusion = 1e-7 diff --git a/lattice2PopulateChildren.py b/lattice2PopulateChildren.py index 17475ac..c0f68eb 100644 --- a/lattice2PopulateChildren.py +++ b/lattice2PopulateChildren.py @@ -106,7 +106,7 @@ class LatticePopulateChildren(lattice2BaseFeature.LatticeFeature): objectPlm = objectPlms[iChild] outputPlms.append(plm.multiply(objectPlm)) else: - outputShape = objectShapes[iChild].copy() + outputShape = shallow_copy(objectShapes[iChild]) outputShape.Placement = plm.multiply(outputShape.Placement) outputShapes.append(outputShape) diff --git a/lattice2PopulateCopies.py b/lattice2PopulateCopies.py index 2bd0238..4697797 100644 --- a/lattice2PopulateCopies.py +++ b/lattice2PopulateCopies.py @@ -127,7 +127,7 @@ class LatticePopulateCopies(lattice2BaseFeature.LatticeFeature): for objectPlm in objectPlms: outputPlms.append(plm.multiply(objectPlm)) else: - outputShape = objectShape.copy() + outputShape = shallow_copy(objectShape) outputShape.Placement = plm.multiply(outputShape.Placement) outputShapes.append(outputShape)