BaseFeature: add updateReadonlyness global method

+ make basic Lattice properties such as MarkerSize hidden on objects with shape results.
This commit is contained in:
DeepSOIC 2018-09-06 00:11:00 +03:00
parent 32e840a941
commit 7d2d62bdea
5 changed files with 36 additions and 7 deletions

View File

@ -131,8 +131,8 @@ class LatticeFeature(object):
# value is treated "under selfobj.Placement" if not exposing placement, else as "absolute".
# Use getReferencePlm/setReferencePlm methods to work with reference placement in a expose-placement-invariant method.
self.assureProperties(obj)
self.derivedInit(obj)
self.assureProperties(obj)
obj.Proxy = self
@ -141,6 +141,24 @@ class LatticeFeature(object):
Auto called from __init__ (and before derivedInit), and from execute (before derivedExecute)."""
self.assureProperty(selfobj, 'App::PropertyLink', 'ReferencePlacementLink', None, "Lattice", "Link to placement to use as reference placement")
self.assureProperty(selfobj, 'App::PropertyString', 'ReferencePlacementLinkIndex', None, "Lattice", "Index of placement to take from the link. Can also be 'self.0' for own placements.")
def updateReadonlyness(self, selfobj, bypass_set = set()):
is_lattice = isObjectLattice(selfobj)
extref = 0
if hasattr(selfobj, 'ReferencePlacementOption'):
extref = 0 if selfobj.ReferencePlacementOption == 'external' else 1
rodict = {
'NumElements': 1,
'MarkerSize': 0,
'MarkerShape': 0,
'ReferencePlacement': 1,
'ReferencePlacementLink': extref,
'ReferencePlacementLinkIndex': extref,
}
for prop in rodict:
if prop in bypass_set: continue
if hasattr(selfobj, prop):
selfobj.setEditorMode(prop, rodict[prop] if is_lattice else 2)
def assureProperty(self, selfobj, proptype, propname, defvalue, group, tooltip, readonly = False, hidden = False):
"""assureProperty(selfobj, proptype, propname, defvalue, group, tooltip): adds
@ -278,7 +296,7 @@ class LatticeFeature(object):
else:
#nothing to do - FreeCAD will take care to make obj.Placement and obj.Shape.Placement synchronized.
pass
return
self.updateReadonlyness(obj)
def derivedExecute(self,obj):
'''For overriding by derived class. If this returns a list of placements,
@ -341,6 +359,8 @@ class LatticeFeature(object):
def onDocumentRestored(self, selfobj):
#override to have attachment!
self.disableAttacher(selfobj)
self.assureProperties(selfobj)
self.updateReadonlyness(selfobj)
class ViewProviderLatticeFeature(object):

View File

@ -81,6 +81,7 @@ class LinearArray(lattice2BaseFeature.LatticeFeature):
obj.Count = 5.0
def updateReadonlyness(self, obj):
super(LinearArray,self).updateReadonlyness(obj)
link = screen(obj.Link)
obj.setEditorMode("Dir", 1 if (link and obj.DirIsDriven) else 0)
obj.setEditorMode("Point", 1 if (link and obj.PointIsDriven) else 0)
@ -89,6 +90,7 @@ class LinearArray(lattice2BaseFeature.LatticeFeature):
obj.setEditorMode("DrivenProperty", 0 if link else 1)
obj.setEditorMode('ReferenceValue', 0 if obj.ReferencePlacementOption == 'at custom value' else 2)
self.assureGenerator(obj)
self.generator.updateReadonlyness()
def assureGenerator(self, obj):
@ -124,7 +126,6 @@ class LinearArray(lattice2BaseFeature.LatticeFeature):
def derivedExecute(self,obj):
self.assureGenerator(obj)
self.updateReadonlyness(obj)
# Apply links
if screen(obj.Link):

View File

@ -123,12 +123,16 @@ class LatticeParaSeries(lattice2BaseFeature.LatticeFeature):
self.generator.addProperties(groupname= "Lattice ParaSeries",
groupname_gen= "Lattice ParaSeries Generator",
valuesdoc= "List of parameter values to compute object for.")
def updateReadonlyness(self, selfobj):
super(LatticeParaSeries, self).updateReadonlyness(selfobj)
self.assureGenerator(selfobj)
self.generator.updateReadonlyness()
def derivedExecute(self,selfobj):
# values generator should be functional even if recomputing is disabled, so do it first
self.assureGenerator(selfobj)
self.generator.updateReadonlyness()
self.generator.execute()
if selfobj.Recomputing == "Disabled":

View File

@ -87,11 +87,14 @@ class PolarArray(lattice2BaseFeature.LatticeFeature):
self.updateReadonlyness(obj)
def updateReadonlyness(self, obj):
super(PolarArray, self).updateReadonlyness(obj)
axislink = screen(obj.AxisLink)
obj.setEditorMode("AxisDir", 1 if (axislink and obj.AxisDirIsDriven) else 0)
obj.setEditorMode("AxisPoint", 1 if (axislink and obj.AxisPointIsDriven) else 0)
obj.setEditorMode("AxisDirIsDriven", 0 if axislink else 1)
obj.setEditorMode("AxisPointIsDriven", 0 if axislink else 1)
self.assureGenerator(obj)
self.generator.updateReadonlyness()
def assureProperties(self, selfobj):
@ -102,7 +105,6 @@ class PolarArray(lattice2BaseFeature.LatticeFeature):
def derivedExecute(self,obj):
self.assureGenerator(obj)
self.updateReadonlyness(obj)
# Apply links
if screen(obj.AxisLink):

View File

@ -45,7 +45,7 @@ V = App.Vector
def make():
'''make(): makes a PolarArray object.'''
obj = lattice2BaseFeature.makeLatticeFeature('PolarArray', PolarArray, ViewProviderPolarArray, no_disable_attacher= True)
obj = lattice2BaseFeature.makeLatticeFeature('PolarArray', PolarArray, ViewProviderPolarArray)
return obj
def fetchArc(obj, sub):
@ -110,9 +110,11 @@ class PolarArray(APlm.AttachableFeature):
groupname_gen= "Lattice Series Generator",
valuesdoc= "List of angles, in degrees.",
valuestype= 'App::PropertyFloat')
self.updateReadonlyness(selfobj)
def updateReadonlyness(self, selfobj):
super(PolarArray, self).updateReadonlyness(selfobj)
self.assureGenerator(selfobj)
self.generator.updateReadonlyness()
arc = self.fetchArc(selfobj)