Slider control for XY data does not work on waveform...how to do that ?
supra
My question is what changes I need to do to have applicable also on waveform data.
Function/DF GetSupraPackageDFR()
DFREF dfr = root:Packages:Supra
if (DataFolderRefStatus(dfr) != 1)
NewDataFolder /O root:Packages
NewDataFolder /O root:Packages:Supra
DFREF dfr = root:Packages:Supra
Variable/G dfr:gLastSliderValueAdded = 0
endif
return dfr
End
Function AddSliderValue(xWave, yWave, startX, endX, sliderValue)
Wave xWave, yWave
Variable startX, endX
Variable sliderValue
// Take the previously-added slider value, if any, into account
DFREF dfr = GetSupraPackageDFR()
NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded
// To avoid accumulation of roundoff error we do this in two steps
YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
gLastSliderValueAdded = sliderValue
End
DFREF dfr = root:Packages:Supra
if (DataFolderRefStatus(dfr) != 1)
NewDataFolder /O root:Packages
NewDataFolder /O root:Packages:Supra
DFREF dfr = root:Packages:Supra
Variable/G dfr:gLastSliderValueAdded = 0
endif
return dfr
End
Function AddSliderValue(xWave, yWave, startX, endX, sliderValue)
Wave xWave, yWave
Variable startX, endX
Variable sliderValue
// Take the previously-added slider value, if any, into account
DFREF dfr = GetSupraPackageDFR()
NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded
// To avoid accumulation of roundoff error we do this in two steps
YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
gLastSliderValueAdded = sliderValue
End
You might look in to the function x2pnt, leading I think to the following or its equivalent:
ps = x2pnt(ywave,startx)
pe = x2pnt(ywave,endx)
ywave[ps,pe] -= gLastSliderValueAdded
ywave[ps,pe] += slidervalue
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 11, 2012 at 05:04 am - Permalink
YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
else
YWave -= (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? gLastSliderValueAdded : 0
YWave += (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? sliderValue : 0
endif
JJWeimer's use of a variable to hold the result of pnt2x() would be a bit faster, but I don't think it will be noticeable in this application.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
July 11, 2012 at 09:19 am - Permalink
Somehow I still didnt able to make it work on wave data.
Function/DF GetSupraPackageDFR()
DFREF dfr = root:Packages:Supra
if (DataFolderRefStatus(dfr) != 1)
NewDataFolder /O root:Packages
NewDataFolder /O root:Packages:Supra
DFREF dfr = root:Packages:Supra
Variable/G dfr:gLastSliderValueAdded = 0
endif
return dfr
End
Function MoveSegment(SliderValue)
Variable SliderValue
// Take the previously-added slider value, if any, into account
DFREF dfr = GetSupraPackageDFR()
NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded
WAVE/Z yWave = CsrWaveRef(A)
if (!WaveExists(yWave)) // Cursor is not on any wave
return -1
endif
WAVE/Z xWave = CsrXWaveRef(A)
if (!WaveExists(xWave)) // Cursor is not on XY pair
return -1
endif
Variable startX = hcsr(A)
Variable endX = hcsr(B)
if (startX > endX)
return -1
endif
// To avoid accumulation of roundoff error we do this in two steps
if (WaveExists(xWave))
YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
else
YWave -= (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? gLastSliderValueAdded : 0
YWave += (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? sliderValue : 0
endif
gLastSliderValueAdded = sliderValue
return 0
End
but somehow still it does not work ?
July 11, 2012 at 07:56 pm - Permalink
Variable SliderValue
// Take the previously-added slider value, if any, into account
DFREF dfr = GetSupraPackageDFR()
NVAR gLastSliderValueAdded = dfr:gLastSliderValueAdded
WAVE/Z yWave = CsrWaveRef(A)
if (!WaveExists(yWave)) // Cursor is not on any wave
return -1
endif
WAVE/Z xWave = CsrXWaveRef(A)
// this will exit the function when xWave does not exist
// so no change will happen with scaled waves
// remove this segement of code
// if (!WaveExists(xWave)) // Cursor is not on XY pair
// return -1
// endif
// this assures that start and end are arranged right regardless of cursors
Variable startX = min(hcsr(A),hcsr(B))
Variable endX = max(hcsr(B),hcsr(A))
// no longer needed here
// if (startX > endX)
// return -1
// endif
// To avoid accumulation of roundoff error we do this in two steps
if (WaveExists(xWave))
YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
else
YWave -= (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? gLastSliderValueAdded : 0
YWave += (pnt2x(YWave, p)>=startX && pnt2x(YWave, p)<=endX) ? sliderValue : 0
endif
gLastSliderValueAdded = sliderValue
return 0
End
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 12, 2012 at 04:30 am - Permalink
July 12, 2012 at 05:46 pm - Permalink
YWave -= (XWave>=startX && XWave<=endX) ? gLastSliderValueAdded : 0
YWave += (XWave>=startX && XWave<=endX) ? sliderValue : 0
else
YWave(startX, endX) -= gLastSliderValueAdded
YWave(startX, endX) += sliderValue
endif
The downside is that it employs a different syntax than the first part, but, at least for me, it's much easier to follow.
But maybe I miss something.
July 13, 2012 at 06:05 am - Permalink
I agree with your coding, but I could also be missing something.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 13, 2012 at 11:06 am - Permalink