LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

drawing waveforms and rectangular in one graph control

Hi,
 
i have a graph control which displays acquired waveforms from a DAQ card.
Now, i get the coordinates of the mouse cursor when EVENT_RIGHT_CLICK  and the coordinates when EVENT_RIGHT_MOUSE_UP.
So i get the coordinates of a rectangular. I want to draw this rectangle in the graph control.
I tried with PlotRectangle () but nothing happend ....
What is going wrong, any idea ?
 
Thanks
0 Kudos
Message 1 of 6
(3,904 Views)

When you get mouse coordinates in a callback, they are referred to the top left corner of the panel. ConvertMouseCoordinates function converts these coordinates with reference to top left corner of a given control.

After that, you will need to map these coordinates (which are in pixels) to actual graph axis scales: GetGraphCoordsFromPoint function is what you need for this.

In case you are using GetRelativeMouseState function to get mouse coordinates, the first step is unnecessary.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,898 Views)
ok, I thought plotRectangular plots the coordinates directly.
but i did not find the GetGraphCoordsFromPoint function. is it just for newer versions ? i am using 7.1
 
0 Kudos
Message 3 of 6
(3,896 Views)


@ichaus wrote:
ok, I thought plotRectangular plots the coordinates directly.
but i did not find the GetGraphCoordsFromPoint function. is it just for newer versions ? i am using 7.1
 



Yes, GetGraphCoordsFromPoint has been introduced in version 8: you will need to perform the conversion by yourself.
Basically, starting from coordinates relative to the top left corner of the control, you must remap them relative to plotting area (Use GetCtrlAttribute with ATTR_PLOT_AREA_xxx to determine position and size of the plot area).
After this, you must remap each coordinate considering min and max values on X and Y axis to obtain the correct value.
 
Alternatively, you could use hidden top and right axes mapped to the dimensions of the plot area in pixels and plot the rectangle activating these axes (ATTR_ACTIVE_X_AXIS and ATTR_ACTIVE_Y_AXIS) passing directly the pixels values to PlotRectangle. I never tried it but in my opinion it should work.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(3,896 Views)
I've been using the following function for a long time, which is a little like GetGraphCoordsFromPoint(). You put the mouse coordinates in xPixel (typically eventData2) and yPixel (typically eventData1) and get back the graph coordinates in xPos & yPos. Note that it uses GetAxisRange(), which is deprecated now. You may want to change this.
 
void GraphCalcBitPosn(int panel, int control, int xPixel, int yPixel, double *xPos, double *yPos)
{
 int top, left, tmp, tmp2;
 int width, height;
 double xmin, xmax, ymin, ymax;
 double alpha;
 GetCtrlAttribute(panel,control,ATTR_TOP,&top);
 GetCtrlAttribute(panel,control,ATTR_PLOT_AREA_TOP,&tmp);
 top += tmp;
 GetCtrlAttribute(panel,control,ATTR_LEFT,&left);
 GetCtrlAttribute(panel,control,ATTR_PLOT_AREA_LEFT,&tmp);
 left += tmp;
 GetCtrlAttribute(panel,control,ATTR_PLOT_AREA_WIDTH,&width);
 GetCtrlAttribute(panel,control,ATTR_PLOT_AREA_HEIGHT,&height);
 GetAxisRange(panel,control,&tmp,&xmin,&xmax,&tmp2,&ymin,&ymax);
 
 alpha = (xPixel-left)/(double)width;
 *xPos = xmin + (xmax-xmin)*alpha;
 alpha = (yPixel-top)/(double)height;
 *yPos = ymax + (ymin-ymax)*alpha;
}
 
--
Martin
Certified CVI Developer
0 Kudos
Message 5 of 6
(3,873 Views)
thank you fopr the help. I am using your function now. it is working fine.
0 Kudos
Message 6 of 6
(3,844 Views)