ValueSeriesGenerator: improve Alignment - keep span

Keeps Span property from being auto-updated read-only when in StepN
mode.

Now, Alignment makes much more sense
This commit is contained in:
DeepSOIC 2016-08-21 17:28:39 +03:00
parent 28a7e4f88e
commit 04f5d9d64c

View File

@ -41,6 +41,14 @@ class ValueSeriesGenerator:
def addProperties(self, groupname, groupname_gen, valuesdoc, valuestype = 'App::PropertyFloat'): def addProperties(self, groupname, groupname_gen, valuesdoc, valuestype = 'App::PropertyFloat'):
# _addProperty(proptype , propname , defvalue, group, tooltip) # _addProperty(proptype , propname , defvalue, group, tooltip)
# first, try to guess interface version. If we are re-adding properties to old feature,
# it already has some other properties, but not Version. So we should default to 0
# in this case. Therwise the Version property already exists, so default desn't matter;
# or we are creating a new generator, so default to 1.
self._addProperty("App::PropertyInteger" ,"VSGVersion" , 0 if hasattr(self.documentObject, "Values") else 1 , groupname_gen, "Interface version")
self.documentObject.setEditorMode("VSGVersion", 2) #hide this property
self._addProperty("App::PropertyStringList" ,"Values" , None, groupname, valuesdoc) self._addProperty("App::PropertyStringList" ,"Values" , None, groupname, valuesdoc)
self._addProperty("App::PropertyEnumeration","ValuesSource" , self.source_modes, groupname, "Select where to take the value series from.") self._addProperty("App::PropertyEnumeration","ValuesSource" , self.source_modes, groupname, "Select where to take the value series from.")
self._addProperty("App::PropertyLink" ,"SpreadsheetLink", None, groupname, "Link to spreadsheet to take values from.") self._addProperty("App::PropertyLink" ,"SpreadsheetLink", None, groupname, "Link to spreadsheet to take values from.")
@ -99,7 +107,7 @@ class ValueSeriesGenerator:
if propname == "SpanStart": if propname == "SpanStart":
return False return False
elif propname == "SpanEnd": elif propname == "SpanEnd":
return m == "StepN" return False
elif propname == "Step": elif propname == "Step":
return m == "SpanN" return m == "SpanN"
elif propname == "Count": elif propname == "Count":
@ -148,16 +156,21 @@ class ValueSeriesGenerator:
vStep = (vEnd - vStart)/n vStep = (vEnd - vStart)/n
obj.Step = vStep obj.Step = vStep
elif obj.GeneratorMode == 'StepN': elif obj.GeneratorMode == 'StepN':
n = obj.Count if obj.VSGVersion < 1:
if obj.EndInclusive: #old behavior: update span to match the end of array
n -= 1 n = obj.Count
vEnd = vStart + float(vStep)*n if obj.EndInclusive:
if obj.DistributionLaw == 'Linear': n -= 1
obj.SpanEnd = vEnd vEnd = vStart + float(vStep)*n
elif obj.DistributionLaw == 'Exponential': if obj.DistributionLaw == 'Linear':
obj.SpanEnd = math.exp(vEnd)*vSign obj.SpanEnd = vEnd
elif obj.DistributionLaw == 'Exponential':
obj.SpanEnd = math.exp(vEnd)*vSign
else:
raise ValueError(obj.Name+": distribution law not implemented: "+obj.DistributionLaw)
else: else:
raise ValueError(obj.Name+": distribution law not implemented: "+obj.DistributionLaw) # new behavior: keep span intact, as it can be used for alignment
pass
elif obj.GeneratorMode == 'SpanStep': elif obj.GeneratorMode == 'SpanStep':
nfloat = float((vEnd - vStart) / vStep) nfloat = float((vEnd - vStart) / vStep)
n = math.trunc(nfloat - ParaConfusion) + 1 n = math.trunc(nfloat - ParaConfusion) + 1