From c16d208648ca35a758451ae118a5cc8bc4195039 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sun, 1 Nov 2015 00:16:28 +0300 Subject: [PATCH] Placement link: expose placement as Placement property --- latticeArrayFromShape.py | 1 + latticeBaseFeature.py | 32 +++++++++++++++++++++----------- latticePlacement.py | 4 +++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/latticeArrayFromShape.py b/latticeArrayFromShape.py index 3a51f82..028f117 100644 --- a/latticeArrayFromShape.py +++ b/latticeArrayFromShape.py @@ -197,6 +197,7 @@ def CreateLatticeArrayFromShape(name, nonArray = False): FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) if nonArray: FreeCADGui.doCommand("f.WholeObject = True") + FreeCADGui.doCommand("f.SingleByDesign = True") FreeCADGui.doCommand("f.Label = 'Placement of ' + f.Base.Label") else: FreeCADGui.doCommand("f.Label = 'Array from ' + f.Base.Label") diff --git a/latticeBaseFeature.py b/latticeBaseFeature.py index adcc44f..3753a58 100644 --- a/latticeBaseFeature.py +++ b/latticeBaseFeature.py @@ -31,6 +31,7 @@ import Part from latticeCommon import * import latticeCompoundExplorer as LCE import latticeMarkers +import latticeExecuter def getDefLatticeFaceColor(): return (1.0, 0.7019608020782471, 0.0, 0.0) #orange @@ -93,6 +94,10 @@ class LatticeFeature(): obj.addProperty("App::PropertyInteger",prop,"Lattice","Info: number of placements in the array") obj.setEditorMode(prop, 1) # set read-only + prop = "SingleByDesign" + obj.addProperty("App::PropertyBool",prop,"Lattice","Makes the element be populated into object's Placement property") + obj.setEditorMode(prop, 2) # set hidden + obj.addProperty("App::PropertyLength","MarkerSize","Lattice","Size of placement markers (set to zero for automatic).") obj.addProperty("App::PropertyEnumeration","isLattice","Lattice","Sets whether this object should be treated as a lattice by further operations") @@ -121,18 +126,23 @@ class LatticeFeature(): markerSize = getMarkerSizeEstimate(plms) marker = latticeMarkers.getPlacementMarker(scale=markerSize) #FIXME: make hierarchy-aware - for plm in plms: - sh = marker.copy() - sh.Placement = plm - shapes.append(sh) + if obj.SingleByDesign: + if len(plms) != 1: + latticeExecuter.warning(obj,"Multiple placements are being fed, but object is single by design. Only fisrt placement will be used...") + obj.Shape = marker.copy() + obj.Placement = plms[0] + else: + for plm in plms: + sh = marker.copy() + sh.Placement = plm + shapes.append(sh) + + if len(shapes) == 0: + obj.Shape = markers.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. - if len(shapes) == 0: - obj.Shape = markers.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. - - sh = Part.makeCompound(shapes) - sh.Placement = obj.Placement #Fix single placement behaving badly - obj.Shape = sh + sh = Part.makeCompound(shapes) + obj.Shape = sh if obj.isLattice == 'Auto-Off': obj.isLattice = 'Auto-On' diff --git a/latticePlacement.py b/latticePlacement.py index 3000ad1..6321fc1 100644 --- a/latticePlacement.py +++ b/latticePlacement.py @@ -54,6 +54,8 @@ class LatticePlacement(latticeBaseFeature.LatticeFeature): obj.addProperty("App::PropertyBool","Invert","Lattice Placement","Invert the placement") + obj.SingleByDesign = True + def updateReadOnlyness(self, obj): m = obj.PlacementChoice obj.setEditorMode("Placement", 0 if m == "Custom" else 1) @@ -86,7 +88,7 @@ class LatticePlacement(latticeBaseFeature.LatticeFeature): if obj.PlacementChoice == 'Custom': obj.Invert = False - return [App.Placement()] #always return default placement, because Placement property is automatically applied on top of it. + return [obj.Placement] class ViewProviderLatticePlacement(latticeBaseFeature.ViewProviderLatticeFeature):