diff --git a/lattice2BaseFeature.py b/lattice2BaseFeature.py index 82150e9..f1aa30f 100644 --- a/lattice2BaseFeature.py +++ b/lattice2BaseFeature.py @@ -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 @@ -177,6 +183,8 @@ class LatticeFeature(object): def execute(self,obj): # please, don't override. Override derivedExecute instead. + + self.assureProperties(obj) plms = self.derivedExecute(obj) diff --git a/lattice2Invert.py b/lattice2Invert.py index adcf53f..fc40116 100644 --- a/lattice2Invert.py +++ b/lattice2Invert.py @@ -50,15 +50,12 @@ class LatticeInvert(lattice2BaseFeature.LatticeFeature): obj.addProperty("App::PropertyEnumeration","OrientMode","Lattice Invert","what to do with orientation part of placements") 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) diff --git a/lattice2LinearArray.py b/lattice2LinearArray.py index 745d327..56258cd 100644 --- a/lattice2LinearArray.py +++ b/lattice2LinearArray.py @@ -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 diff --git a/lattice2PolarArray.py b/lattice2PolarArray.py index dc119a4..cb2989a 100644 --- a/lattice2PolarArray.py +++ b/lattice2PolarArray.py @@ -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 diff --git a/lattice2PolarArray2.py b/lattice2PolarArray2.py index 008bcf6..cecd199 100644 --- a/lattice2PolarArray2.py +++ b/lattice2PolarArray2.py @@ -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', diff --git a/lattice2PopulateCopies.py b/lattice2PopulateCopies.py index 44df1b5..d3b6295 100644 --- a/lattice2PopulateCopies.py +++ b/lattice2PopulateCopies.py @@ -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