How to use SliderValue of a SliderControl inside a function
supra
The function MoveSegment shift( along y) the part of the graph between two cursor. Can anybody give me some idea.
The example in Igor helpfiles are mainly based on structure based code...so didnt help me lot
NVAR SliderValue= root:SliderValue
Slider slider1,pos={700,50},size={50,200},proc=MySliderProc
Slider slider1,limits={-500,500,10},value= 0, vert= 1
//---------------------------
Function MySliderProc(ctrl, SliderValue, event) : SliderControl
String ctrl
// Slider $cntl
Variable event // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved
if (event %& 0x1) // bit 0, value set
MoveSegment()
endif
return 0
End
//---------------------------------------------
Function MoveSegment()
NVAR SliderValue= root:SliderValue
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
YWave = (XWave>=startX && XWave<=endX) ? YWave + SliderValue : YWave
return 0
End
Slider slider1,pos={700,50},size={50,200},proc=MySliderProc
Slider slider1,limits={-500,500,10},value= 0, vert= 1
//---------------------------
Function MySliderProc(ctrl, SliderValue, event) : SliderControl
String ctrl
// Slider $cntl
Variable event // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved
if (event %& 0x1) // bit 0, value set
MoveSegment()
endif
return 0
End
//---------------------------------------------
Function MoveSegment()
NVAR SliderValue= root:SliderValue
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
YWave = (XWave>=startX && XWave<=endX) ? YWave + SliderValue : YWave
return 0
End
Slider slider1,limits={-500,500,10},value= 0, vert= 1
//---------------------------
Function MySliderProc(ctrl, SliderValue, event) : SliderControl
String ctrl
Variable SliderValue
Variable event // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved
if (event & 0x1) // bit 0, value set
MoveSegment(SliderValue)
endif
return 0
End
//---------------------------------------------
Function MoveSegment(SliderValue)
Variable SliderValue
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
YWave = (XWave>=startX && XWave<=endX) ? YWave + SliderValue : YWave
return 0
End
NOTE: I haven't run this- there may still be problems.
It really isn't hard to use the structure-based version of the action procedure, and they are faster and future developments will go into the structure-based procedures. Like this:
STRUCT WMSliderAction &s
if (s.eventCode & 0x1) // bit 0, value set
MoveSegment(s.curval)
endif
return 0
End
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 7, 2012 at 05:09 pm - Permalink
in the current code of MoveSegment function when I move the silder the y wave changes..but it changes the y wave in every slider move ..I cant bring it back to its initial value of y ...
how can I do that...such that ..say if I change slider by 10 ..y wave will be y+10 ...and then next time if I change the slider by 50 it should be y+50 ...now in current sitaution it becomes cumulative like this two slider change makes y+10+50 and eventually its completley out of control ( as I apply it to graph...the motivation is to shift the graph along y by certain value)
June 7, 2012 at 06:13 pm - Permalink
I would recommend making a copy of yWave. say,
Then, your function could do ywave = ycopy + slidervalue.
This way, ywave on the graph will always move in reference to it's original values.
June 8, 2012 at 06:25 am - Permalink
Thank you so much for your reply. As you said I tried to duplicate Ywave in Ycopy..
YWave = (XWave>=startX && XWave<=endX) ? YCopy + SliderValue : YWave
but still it does not work. Can you think of any other way to do it ?
June 8, 2012 at 08:38 pm - Permalink
But you don't need to copy the entire wave. All you need to store is what you previously added to the wave. Here is code that does that:
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
June 9, 2012 at 10:31 am - Permalink
June 9, 2012 at 04:09 pm - Permalink