Placement link: expose placement as Placement property

This commit is contained in:
DeepSOIC 2015-11-01 00:16:28 +03:00
parent cec62e9015
commit c16d208648
3 changed files with 25 additions and 12 deletions

View File

@ -197,6 +197,7 @@ def CreateLatticeArrayFromShape(name, nonArray = False):
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName) FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
if nonArray: if nonArray:
FreeCADGui.doCommand("f.WholeObject = True") FreeCADGui.doCommand("f.WholeObject = True")
FreeCADGui.doCommand("f.SingleByDesign = True")
FreeCADGui.doCommand("f.Label = 'Placement of ' + f.Base.Label") FreeCADGui.doCommand("f.Label = 'Placement of ' + f.Base.Label")
else: else:
FreeCADGui.doCommand("f.Label = 'Array from ' + f.Base.Label") FreeCADGui.doCommand("f.Label = 'Array from ' + f.Base.Label")

View File

@ -31,6 +31,7 @@ import Part
from latticeCommon import * from latticeCommon import *
import latticeCompoundExplorer as LCE import latticeCompoundExplorer as LCE
import latticeMarkers import latticeMarkers
import latticeExecuter
def getDefLatticeFaceColor(): def getDefLatticeFaceColor():
return (1.0, 0.7019608020782471, 0.0, 0.0) #orange 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.addProperty("App::PropertyInteger",prop,"Lattice","Info: number of placements in the array")
obj.setEditorMode(prop, 1) # set read-only 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::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") obj.addProperty("App::PropertyEnumeration","isLattice","Lattice","Sets whether this object should be treated as a lattice by further operations")
@ -121,6 +126,12 @@ class LatticeFeature():
markerSize = getMarkerSizeEstimate(plms) markerSize = getMarkerSizeEstimate(plms)
marker = latticeMarkers.getPlacementMarker(scale=markerSize) marker = latticeMarkers.getPlacementMarker(scale=markerSize)
#FIXME: make hierarchy-aware #FIXME: make hierarchy-aware
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: for plm in plms:
sh = marker.copy() sh = marker.copy()
sh.Placement = plm sh.Placement = plm
@ -131,7 +142,6 @@ class LatticeFeature():
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') #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 = Part.makeCompound(shapes)
sh.Placement = obj.Placement #Fix single placement behaving badly
obj.Shape = sh obj.Shape = sh
if obj.isLattice == 'Auto-Off': if obj.isLattice == 'Auto-Off':

View File

@ -54,6 +54,8 @@ class LatticePlacement(latticeBaseFeature.LatticeFeature):
obj.addProperty("App::PropertyBool","Invert","Lattice Placement","Invert the placement") obj.addProperty("App::PropertyBool","Invert","Lattice Placement","Invert the placement")
obj.SingleByDesign = True
def updateReadOnlyness(self, obj): def updateReadOnlyness(self, obj):
m = obj.PlacementChoice m = obj.PlacementChoice
obj.setEditorMode("Placement", 0 if m == "Custom" else 1) obj.setEditorMode("Placement", 0 if m == "Custom" else 1)
@ -86,7 +88,7 @@ class LatticePlacement(latticeBaseFeature.LatticeFeature):
if obj.PlacementChoice == 'Custom': if obj.PlacementChoice == 'Custom':
obj.Invert = False 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): class ViewProviderLatticePlacement(latticeBaseFeature.ViewProviderLatticeFeature):