BaseFeature: add assureProperties method

This commit is contained in:
DeepSOIC 2018-09-04 18:26:12 +03:00
parent c3bb345c3f
commit 22925c8187
6 changed files with 18 additions and 15 deletions

View File

@ -128,13 +128,19 @@ class LatticeFeature(object):
obj.addProperty("App::PropertyBool",prop,"Lattice","Makes the placement syncronized to Placement property. This will often make this object unmoveable. Not applicable to arrays.")
#ReferencePlacement: added/removed dynamically. Abscence = global origin. The placement
# value is treated "under Placement" if not exposing placement, else as "absolute".
# 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)
obj.Proxy = self
def assureProperties(self, selfobj):
"""#overrideme Method to reconstruct missing properties, that appeared as new functionality was introduced.
Auto called from __init__ (and before derivedInit), and from execute (before derivedExecute)."""
pass
def assureProperty(self, selfobj, proptype, propname, defvalue, group, tooltip, readonly = False, hidden = False):
"""assureProperty(selfobj, proptype, propname, defvalue, group, tooltip): adds
a property if one is missing, and sets its value to default. Does nothing if property
@ -178,6 +184,8 @@ class LatticeFeature(object):
def execute(self,obj):
# please, don't override. Override derivedExecute instead.
self.assureProperties(obj)
plms = self.derivedExecute(obj)
if plms is not None:

View File

@ -51,14 +51,11 @@ class LatticeInvert(lattice2BaseFeature.LatticeFeature):
obj.OrientMode = ['invert', 'keep', 'reset']
obj.OrientMode = 'invert'
self.assureProperties(obj)
def assureProperties(self, selfobj):
super(LatticeInvert, self).assureProperties(selfobj)
self.assureProperty(selfobj, 'App::PropertyEnumeration', 'Referencing', ['Origin', 'Array\'s reference'], "Lattice Invert", "Sets which placement to use as origin")
def derivedExecute(self,obj):
self.assureProperties(obj)
# cache stuff
placements = lattice2BaseFeature.getPlacementsList(obj.Base)

View File

@ -80,8 +80,6 @@ class LinearArray(lattice2BaseFeature.LatticeFeature):
obj.Step = 3.0
obj.Count = 5.0
self.assureProperties(obj)
def updateReadonlyness(self, obj):
link = screen(obj.Link)
obj.setEditorMode("Dir", 1 if (link and obj.DirIsDriven) else 0)
@ -104,6 +102,8 @@ class LinearArray(lattice2BaseFeature.LatticeFeature):
valuestype= "App::PropertyDistance")
def assureProperties(self, selfobj):
super(LinearArray, self).assureProperties(selfobj)
assureProperty(selfobj, "App::PropertyLinkSub", "SubLink", sublinkFromApart(screen(selfobj.Link), selfobj.LinkSubelement), "Lattice Array", "Mirror of Object+SubNames properties")
created = self.assureProperty(selfobj,
@ -119,7 +119,6 @@ class LinearArray(lattice2BaseFeature.LatticeFeature):
def derivedExecute(self,obj):
self.assureGenerator(obj)
self.assureProperties(obj)
self.updateReadonlyness(obj)
# Apply links

View File

@ -75,8 +75,6 @@ class PolarArray(lattice2BaseFeature.LatticeFeature):
obj.EndInclusive = False
obj.Count = 5
self.assureProperties(obj)
def assureGenerator(self, obj):
'''Adds an instance of value series generator, if one doesn't exist yet.'''
if hasattr(self,"generator"):
@ -97,12 +95,13 @@ class PolarArray(lattice2BaseFeature.LatticeFeature):
self.generator.updateReadonlyness()
def assureProperties(self, selfobj):
super(PolarArray, self).assureProperties(selfobj)
assureProperty(selfobj, "App::PropertyLinkSub", "AxisSubLink", sublinkFromApart(screen(selfobj.AxisLink), selfobj.AxisLinkSubelement), "Lattice Array", "Mirror of Object+SubNames properties")
def derivedExecute(self,obj):
self.assureGenerator(obj)
self.assureProperties(obj)
self.updateReadonlyness(obj)
# Apply links

View File

@ -77,7 +77,6 @@ class PolarArray(APlm.AttachableFeature):
selfobj.addProperty('App::PropertyBool', 'FlipX', "Polar Array", "Reverses x axis of every placement.")
selfobj.addProperty('App::PropertyBool', 'FlipZ', "Polar Array", "Reverses z axis of every placement.")
self.assureProperties(selfobj)
self.assureGenerator(selfobj)
selfobj.ValuesSource = 'Generator'
@ -88,6 +87,8 @@ class PolarArray(APlm.AttachableFeature):
selfobj.Count = 7
def assureProperties(self, selfobj):
super(PolarArray, self).assureProperties(selfobj)
# upgrades older versions of the feature
created = self.assureProperty(selfobj,
'App::PropertyEnumeration',

View File

@ -99,11 +99,12 @@ class LatticePopulateCopies(lattice2BaseFeature.LatticeFeature):
obj.addProperty("App::PropertyLink","PlacementsTo","Lattice PopulateCopies", "Placement or array of placements, containing target locations.")
obj.addProperty("App::PropertyLink","PlacementsFrom", "Lattice PopulateCopies","Placement or array of placements to be treated as origins for PlacementsTo.")
self.assureProperties(obj)
obj.OutputCompounding = "(autosettle)" # this is default value for new features.
def assureProperties(self, obj):
'''Adds properties that might be missing, because of loaded project made with older version. Handles version compatibility.'''
super(LatticePopulateCopies, self).assureProperties(obj)
propname = 'OutputCompounding'
if not hasattr(obj,propname):
obj.addProperty("App::PropertyEnumeration", propname, "Lattice PopulateCopies","In case single object copy is made, this property controls, if it's packed into compoud or not.")
@ -114,8 +115,6 @@ class LatticePopulateCopies(lattice2BaseFeature.LatticeFeature):
def derivedExecute(self,obj):
self.assureProperties(obj)
# cache stuff
objectShape = screen(obj.Object).Shape