LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CanvasClear() seems like is not doing anything

When I call CanvasClear (panelGraph, GRAPH_CANVAS, VAL_ENTIRE_OBJECT); It doesn't clear the object. Any ideas why and what I can do to make it work?

Thanks.

0 Kudos
Message 1 of 9
(3,830 Views)
Howdy DLazarkski,

See if you can run some of our shipping examples that use that CanvasClear function such as canvas.prj and canvsbmk.prj located in the <CVI>\samples\userint\ directory.

Do you have the CanvasClear function in a loop perhaps? Perhaps try calling ProcessDrawEvents() to force an update to the GUI. You could also try playing around with the Draw Policy attribute (ATTR_DRAW_POLICY) for the canvas.

Also, what version of LabWindows/CVI are you using?

Best Regards,

Message Edited by Jonathan N on 01-22-2007 02:43 PM

Jonathan N.
National Instruments
0 Kudos
Message 2 of 9
(3,824 Views)
I'm using CVI 7.0.

I was trying to clear the canvas during a panel resize, so that I can redraw the graph. It's not being run in a loop. I will look through the examples to see if I'm missing something. I have draw policy set to update immediately.
0 Kudos
Message 3 of 9
(3,819 Views)
Howdy DLazarkski,

I just tested the canvas.prj in LabWindows/CVI 7.0 and it worked fine when the CanvasClear function was called.  Additionally, I created a callback function for panel events and I captured the EVENT_PANEL_SIZE event. In that event's case, I made a call to CanvasClear which also worked fine. 

Make sure that panelGraph is the correct reference to your panel you loaded into memory using the LoadPanel function. 

Hope this helps!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 9
(3,816 Views)
Are you using Batch Drawing? If you called the function CanvasStartBatchDraw on your canvas, then cleared it without using the function CanvasEndBatchDraw, you won't see anything changing on your Canvas.
If not, is it possible to post some part of your code? This would make it easier to help you out.
 
Success!
0 Kudos
Message 5 of 9
(3,807 Views)
I made some progress yestarday, but still having some wierd issues. Here's my code for EVENT_PANEL_SIZE

            GetPanelAttribute (panel, ATTR_HEIGHT, &y);
            GetPanelAttribute (panel, ATTR_WIDTH, &x);
            SetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_HEIGHT, y - 50);
            SetCtrlAttribute (panel, GRAPH_DECORATION, ATTR_HEIGHT, y - 50);
            SetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_WIDTH, x - 67);
            SetCtrlAttribute (panel, GRAPH_DECORATION, ATTR_WIDTH, x - 67);
            GetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_WIDTH, &x);
            GetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_HEIGHT, &y);
            //SetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_XCOORD_AT_ORIGIN, x*-0.5);
            //SetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_YCOORD_AT_ORIGIN, y*-0.5);
           
            CanvasClear (panel, GRAPH_CANVAS, VAL_ENTIRE_OBJECT);   
            SetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_PEN_COLOR, VAL_RED);
            CanvasStartBatchDraw (panel, GRAPH_CANVAS);
            CanvasSetPenPosition(panel, GRAPH_CANVAS, MakePoint(0, data1[0]*-2));
            for (i=0; i<100; i++)
            {
                CanvasDrawLineTo (panel, GRAPH_CANVAS, MakePoint(i*2, data1[i]*-2));
            }
            CanvasEndBatchDraw (panel, GRAPH_CANVAS);


Window initially is 800x600. When I maximize it, it works ok and redraws the graph, but when I restore the window size to previous, it draws the graph twice (or it doesn't clear the canvas). If I uncomment two lines of code where I set origin, I get the same thing but graphs are overlaying each other.

Also if I change Draw Policy to direct to screen, I get a blank graph after I resize the window. Update immediately or mark for update get me multiple graphs.

Message Edited by DLazarski on 01-23-2007 07:57 AM

0 Kudos
Message 6 of 9
(3,797 Views)
Ok, I was working on some other stuff today such as scrolling and I've noticed that when I set x and y coordinates at origin attributes, I get some funky stuff happening. I was trying to set point 0,0 to be in the center of the canvas, when I tried scrolling, only one quadrant moved (only positive x and y) rest of the canvas remained unchanged. Same thing with clearing.

Could some one clear up for me what's the purpose of those two attributes? I was hoping to I wouldn't have to offset the graph data.

Message Edited by DLazarski on 01-23-2007 09:19 AM

0 Kudos
Message 7 of 9
(3,785 Views)

Hello DLazarkski,

the attributes ATTR_XCOORD_AT_ORIGIN and ATTR_YCOORD_AT_ORIGIN allow you to change the (0, 0) point of the canvas. By default, the (0, 0) point is the left upper point of your canvas. If you use these attributes and then use the CanvasClear function with your area set to VAL_ENTIRE_OBJECT, you might indeed get weird results. VAL_ENTIRE_OBJECT is defined in the header file "userint.h":

#define VAL_ENTIRE_OBJECT                   MakeRect(0,0,VAL_TO_EDGE, VAL_TO_EDGE)

As you can see in this definition, the 'top' and 'left' members of the Rect structure are both set to 0. If you have changed this (0, 0)-point using the ATTR_XCOORD_AT_ORIGIN and ATTR_YCOORD_AT_ORIGIN attributes, only one quadrant of your canvas will be cleared. Instead of using VAL_ENTIRE_OBJECT to clear the canvas, you should use the MakeRect macro to define a rectangle that covers the entire canvas. I think the code below should work (not sure though):

GetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_XCOORD_AT_ORIGIN, &origin.x);
GetCtrlAttribute (panel, GRAPH_CANVAS, ATTR_YCOORD_AT_ORIGIN, &origin.y);

CanvasClear (panel, GRAPH_CANVAS, MakeRect (-origin.y, -origin.x, VAL_TO_EDGE, VAL_TO_EDGE));   

Hope this helps...

 


 

Message Edited by Wim S on 01-23-2007 04:54 PM

0 Kudos
Message 8 of 9
(3,776 Views)
Thank you for posting this. It makes sense now and everything seems to work. Right before you posted this, I cleared the canvas using a rectangle starting at (-1000, -1000). I'll just have to keep track how big the graph data is and pass it to clear canvas. Shouldn't be too hard since x will always be positive Smiley Happy

Thanks again!
0 Kudos
Message 9 of 9
(3,767 Views)