LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI graph Cursor Issues

My issue is that I am using a graph control and I am trying to have the cursor that is snapped to the plotted line not move when I hit the UP/DOWN key.  Every keypress event that I do pertaining to a up or down keystroke will move the cursor to the next index accordingly - right for up and left for down.  What I am trying to accomplish is to keep the cursor in place after the up or down key is pressed while updating the y-data of the plotted line.  I can change the y-data successfully, then the cursor moves - don't want this to happen with the cursor.  Also when I move the cursor with the mouse, the GetGraphCursorIndex function returns a '-1' for the plotHandle and arrayIndex values.  There are many issues that I am having with something that should be simple and intuitive to use.  Please provide me with some insight how to avoid having the cursor move without forcing its position in software when using the up and down keystrokes. 

0 Kudos
Message 1 of 7
(4,643 Views)

Hi,

 

1) The cursors only move if they have the focus

2) There is the sample GraphCursorCtrl - did you have a look at it?

3) If you are having issues with your code, it's easier to assist you if you provide the code and the error messages you receive.

0 Kudos
Message 2 of 7
(4,642 Views)

Here's my code.  Whenever I have an event keypress and it is switched to the event under which the up or down arrow is pressed, the cursor moves and doesn't stay in place once the graph has been 'bumped' up at the x-indexed location.  What can I do to correct this issue? 

 

int CVICALLBACK graphTableCB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
   
    GetGraphCursor(tableGraphPanel,GRAPH_GRAPH,1,&xVal,&yVal);
    
    switch (event)
    {
        case EVENT_KEYPRESS:
            switch(eventData1)
            {
                case VAL_ENTER_VKEY:
                    GetPlotAttribute(tableGraphPanel,GRAPH_GRAPH,graphHandle,ATTR_PLOT_YDATA,yData);
                    for(i = 0;i < 16;i++)
                        tmpIntArray[i] = ((yData[i] - GUIStat.curTable->offset) / GUIStat.curTable->slope) + 0.5;
                    tableFWID = atoi(GUIStat.curTable->tblIndexName);
                    burstDataSwitch(0);
                    Delay(0.055);
                    for(i = 0;i < 16;i++)
                        tableWrite(tableFWID,i,0,&tmpIntArray[i]);
                    burstDataSwitch(1);
                    break;
                case VAL_UP_ARROW_VKEY:
                    GetPlotAttribute(tableGraphPanel,GRAPH_GRAPH,graphHandle,ATTR_PLOT_XDATA,xData);
                    deltaX = (xData[1] - xData[0]) / 2.0;
                    for(i = 0;i < 16;i++)
                    {
                        if((xVal + deltaX) >= xData[i])
                            xIndex = i;
                    }
                    GetPlotAttribute(tableGraphPanel,GRAPH_GRAPH,graphHandle,ATTR_PLOT_YDATA,yData);
// Increase data by percentage
                    yData[xIndex] += GUIStat.curTable->slope;
                    if(yData[xIndex] >= GUIStat.curTable->maxVal)
                        yData[xIndex] = GUIStat.curTable->maxVal;
                    
                    DeleteGraphPlot(tableGraphPanel,GRAPH_GRAPH,graphHandle,VAL_IMMEDIATE_DRAW);
                    graphHandle = PlotXY(tableGraphPanel,GRAPH_GRAPH,xData,yData,16,VAL_DOUBLE,VAL_DOUBLE,VAL_FAT_LINE,VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_GREEN);
                    
                    GetGraphCursorIndex(tableGraphPanel,GRAPH_GRAPH,1,&plotHandle,&arrayIndex);
                    
                    break;
                case VAL_DOWN_ARROW_VKEY:
                    GetPlotAttribute(tableGraphPanel,GRAPH_GRAPH,graphHandle,ATTR_PLOT_XDATA,xData);
                    deltaX = (xData[1] - xData[0]) / 2.0;
                    for(i = 0;i < 16;i++)
                    {
                        if((xVal + deltaX) >= xData[i])
                            xIndex = i;
                    }
                    GetPlotAttribute(tableGraphPanel,GRAPH_GRAPH,graphHandle,ATTR_PLOT_YDATA,yData);
// Decrease data by percentage
                    yData[xIndex] -= GUIStat.curTable->slope;
                    if(yData[xIndex] <= GUIStat.curTable->minVal)
                        yData[xIndex] = GUIStat.curTable->minVal;
                    
                    DeleteGraphPlot(tableGraphPanel,GRAPH_GRAPH,graphHandle,VAL_IMMEDIATE_DRAW);
                    graphHandle = PlotXY(tableGraphPanel,GRAPH_GRAPH,xData,yData,16,VAL_DOUBLE,VAL_DOUBLE,VAL_FAT_LINE,VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_GREEN);
                    break;
                case VAL_RIGHT_ARROW_VKEY:
                    arrayIndex++;
                    if(arrayIndex >= 16)
                        arrayIndex = 15;
                    break;
                case VAL_LEFT_ARROW_VKEY:
                    arrayIndex--;
                    if(arrayIndex < 0)
                        arrayIndex = 0;
                    break;
            }
            break;
    }
    return 0;
}

0 Kudos
Message 3 of 7
(4,637 Views)

Question:  Why when I make my graph call-back function return 1 - not a zero, what I had to change to figure this out - does the graph cursor not move after I have an EVENT_VAL_CHANGED???  What does this do when you make the call-back return a non-zero number?  are there any other values that I can return that have other effects???

0 Kudos
Message 4 of 7
(4,634 Views)

User callbacks must always return 0 unless they intend to swallow the event to which they are responding. To swallow the event, the callback should return 1.

0 Kudos
Message 5 of 7
(4,631 Views)

Actually I am not sure that I understand what you are trying to achieve: If you want to prevent cursors from snapping to a certain plot, set ATTR_PLOT_SNAPPABLE for the plot to FALSE. Do you want to move the cursor up or down without snapping, set the ATTR_CURSOR_MODE to VAL_FREE_FORM

0 Kudos
Message 6 of 7
(4,616 Views)

Problem has been solved.  What was happening was that after I had an event keypress, the cursor index would shift right or left for the up and down keys respectively.  I wanted to stop the shifting and the way to do that was to have the call-back swallow the events so to speak so the cursor index would not change, hence move the cursor after an event keypress.  Now I have a trace on a graph where I can change one single value of the y-data and update the graph without the cursor moving left or right. 

0 Kudos
Message 7 of 7
(4,613 Views)