Invert: support for reference placement
This commit is contained in:
parent
9d2043f546
commit
65c6dad39f
|
@ -46,8 +46,6 @@ class LatticeInvert(lattice2BaseFeature.LatticeFeature):
|
||||||
"The Lattice Invert object"
|
"The Lattice Invert object"
|
||||||
|
|
||||||
def derivedInit(self,obj):
|
def derivedInit(self,obj):
|
||||||
self.Type = "LatticeInvert"
|
|
||||||
|
|
||||||
obj.addProperty("App::PropertyLink","Base","Lattice Invert","Lattice, all the placements of which are to be inverted.")
|
obj.addProperty("App::PropertyLink","Base","Lattice Invert","Lattice, all the placements of which are to be inverted.")
|
||||||
|
|
||||||
obj.addProperty("App::PropertyEnumeration","TranslateMode","Lattice Invert","What to do with translation part of placements")
|
obj.addProperty("App::PropertyEnumeration","TranslateMode","Lattice Invert","What to do with translation part of placements")
|
||||||
|
@ -58,12 +56,28 @@ class LatticeInvert(lattice2BaseFeature.LatticeFeature):
|
||||||
obj.OrientMode = ['invert', 'keep', 'reset']
|
obj.OrientMode = ['invert', 'keep', 'reset']
|
||||||
obj.OrientMode = 'invert'
|
obj.OrientMode = 'invert'
|
||||||
|
|
||||||
|
self.assureProperties(obj)
|
||||||
|
|
||||||
|
def assureProperties(self, selfobj):
|
||||||
|
self.assureProperty(selfobj, 'App::PropertyEnumeration', 'Referencing', ['Origin', 'Array\'s reference'], "Lattice Invert", "Sets which placement to use as origin")
|
||||||
|
|
||||||
def derivedExecute(self,obj):
|
def derivedExecute(self,obj):
|
||||||
|
self.assureProperties(obj)
|
||||||
|
|
||||||
# cache stuff
|
# cache stuff
|
||||||
base = screen(obj.Base).Shape
|
placements = lattice2BaseFeature.getPlacementsList(obj.Base)
|
||||||
if not lattice2BaseFeature.isObjectLattice(screen(obj.Base)):
|
|
||||||
lattice2Executer.warning(obj, "Base is not a lattice, but lattice is expected. Results may be unexpected.\n")
|
# dereference
|
||||||
baseChildren = LCE.AllLeaves(base)
|
refplm = App.Placement()
|
||||||
|
if obj.Referencing == 'Origin':
|
||||||
|
pass
|
||||||
|
elif obj.Referencing == 'Array\'s reference':
|
||||||
|
refplm = self.getReferencePlm(obj.Base)
|
||||||
|
self.setReferencePlm(obj, refplm)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(obj.Referencing)
|
||||||
|
inv_refplm = refplm.inverse()
|
||||||
|
locplms = [inv_refplm.multiply(plm) for plm in placements]
|
||||||
|
|
||||||
#cache mode comparisons, for speed
|
#cache mode comparisons, for speed
|
||||||
posIsInvert = obj.TranslateMode == 'invert'
|
posIsInvert = obj.TranslateMode == 'invert'
|
||||||
|
@ -78,26 +92,29 @@ class LatticeInvert(lattice2BaseFeature.LatticeFeature):
|
||||||
outputPlms = [] #list of placements
|
outputPlms = [] #list of placements
|
||||||
|
|
||||||
# the essence
|
# the essence
|
||||||
for child in baseChildren:
|
for plm in locplms:
|
||||||
pos = App.Vector()
|
pos = App.Vector()
|
||||||
ori = App.Rotation()
|
ori = App.Rotation()
|
||||||
inverted = child.Placement.inverse()
|
inverted = plm.inverse()
|
||||||
if posIsInvert:
|
if posIsInvert:
|
||||||
pos = inverted.Base
|
pos = inverted.Base
|
||||||
elif posIsKeep:
|
elif posIsKeep:
|
||||||
pos = child.Placement.Base
|
pos = plm.Base
|
||||||
elif posIsReset:
|
elif posIsReset:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if oriIsInvert:
|
if oriIsInvert:
|
||||||
ori = inverted.Rotation
|
ori = inverted.Rotation
|
||||||
elif oriIsKeep:
|
elif oriIsKeep:
|
||||||
ori = child.Placement.Rotation
|
ori = plm.Rotation
|
||||||
elif oriIsReset:
|
elif oriIsReset:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
plm = App.Placement(pos, ori)
|
outputPlms.append(App.Placement(pos, ori))
|
||||||
outputPlms.append(plm)
|
|
||||||
|
# re-reference
|
||||||
|
outputPlms = [refplm.multiply(plm) for plm in outputPlms]
|
||||||
|
|
||||||
return outputPlms
|
return outputPlms
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +138,8 @@ def CreateLatticeInvert(name):
|
||||||
FreeCADGui.addModule("lattice2Executer")
|
FreeCADGui.addModule("lattice2Executer")
|
||||||
FreeCADGui.doCommand("f = lattice2Invert.makeLatticeInvert(name='"+name+"')")
|
FreeCADGui.doCommand("f = lattice2Invert.makeLatticeInvert(name='"+name+"')")
|
||||||
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
|
FreeCADGui.doCommand("f.Base = App.ActiveDocument."+sel[0].ObjectName)
|
||||||
|
hasref = lattice2BaseFeature.getReferencePlm(sel[0].Object) is not None
|
||||||
|
FreeCADGui.doCommand("f.Referencing = {r}".format(r= repr('Array\'s reference' if hasref else 'Origin') ))
|
||||||
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
|
FreeCADGui.doCommand("for child in f.ViewObject.Proxy.claimChildren():\n"+
|
||||||
" child.ViewObject.hide()")
|
" child.ViewObject.hide()")
|
||||||
FreeCADGui.doCommand("lattice2Executer.executeFeature(f)")
|
FreeCADGui.doCommand("lattice2Executer.executeFeature(f)")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user