From 7d2d62bdea1319e398f9b2df7a80920ba4153bfc Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Thu, 6 Sep 2018 00:11:00 +0300 Subject: [PATCH] BaseFeature: add updateReadonlyness global method + make basic Lattice properties such as MarkerSize hidden on objects with shape results. --- lattice2BaseFeature.py | 24 ++++++++++++++++++++++-- lattice2LinearArray.py | 3 ++- lattice2ParaSeries.py | 6 +++++- lattice2PolarArray.py | 4 +++- lattice2PolarArray2.py | 6 ++++-- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lattice2BaseFeature.py b/lattice2BaseFeature.py index 3b747ab..278f3c3 100644 --- a/lattice2BaseFeature.py +++ b/lattice2BaseFeature.py @@ -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): diff --git a/lattice2LinearArray.py b/lattice2LinearArray.py index 020fc38..3948ed6 100644 --- a/lattice2LinearArray.py +++ b/lattice2LinearArray.py @@ -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): diff --git a/lattice2ParaSeries.py b/lattice2ParaSeries.py index b8206d2..dfb81dd 100644 --- a/lattice2ParaSeries.py +++ b/lattice2ParaSeries.py @@ -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": diff --git a/lattice2PolarArray.py b/lattice2PolarArray.py index cb2989a..104afa6 100644 --- a/lattice2PolarArray.py +++ b/lattice2PolarArray.py @@ -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): diff --git a/lattice2PolarArray2.py b/lattice2PolarArray2.py index 36fe2aa..9330467 100644 --- a/lattice2PolarArray2.py +++ b/lattice2PolarArray2.py @@ -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)