Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CNiGraph annotation event bug - or am I wrong?

Hello

Yesterday, I ran into problem (I'm using Measurement Studio 7.1 and MSVC 7.1/C++): My application uses CNiGraph to display various plots. This is already done and works just fine. Now I'm adding "events" to the plots. "Event" has time but no "value", only textual description. I wanted it to be clearly visible on all plots, since relation of values on various plots in time of event is important. So I decided to display "events" as vertical (perpendicular to time axis) lines that span whole Y axis. That way intersection of "event" and plot(s) is clearly visible. I also wanted my "events" to display textual information, but not all the time - only when user moves mouse pointer over them. Annotations seemed to be the very tool I needed.

I started creating (programmatically) new annotations, setting them for "Range" style, "MinMaxRegion" shape, apropriate fill color and all that. Since I wanted them to span whole Y axis, I have set coordinate vectors to ( t_0, t_0 + epsilon ) and ( ), where t_0 is "event time", epsilon "event width". My events appeared just as I wanted. So far so good, but then I switched to event handling part of task. My CNiGraph already has many event handlers installed and they worked just fine, so I thought that will be easy. Well, it wasn't. After half a day of experiments and test I found out that CNiGraph won't generate _any_ annotation events on shape (you can get caption events, arrow events, but not shape ones) when annotation is set to "Range", "MinMaxRegion" and that region has only x1 and x2 coordinates.

You can easily reproduce that error. Please take stock CNiGraph in dialog (f.e. one from examples in Measurement Studio install directory), add one annotation, set it to have "Range" style and "MinMaxRegion" shape. Now use "Edit points" button and set region to have only "X min" and "X max" coordinates. Then install handler for "OnAnnotationMouseMove" event.
Try to produce that event - you'll see it won't appear. Now change shape of annotation (add sensible Y min and Y max coordinates). Retry and bang - event handler gets called. Well, I think it's bug not to call it when Y coordinates are unspecified. Or am I wrong? What should I do?

I can think about one possible solution to this problem: always set both X and Y coordinates, later ones to min/max values of axis. Yes, this can work, but I do _lots_ of changes to axes' ranges (both automatically via autoscale and manually from many places) and I don't want to ugly my code up. Any other workarounds possible? Anybody has any idea?

Thank you for your time and best regards
Michal


0 Kudos
Message 1 of 4
(3,753 Views)

Hi Michael,

 

I wasn't able to reproduce the bug that you mentioned. Perhaps I did something different then you when I tested it out. I was modifying the events and region of interest examples located at C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\UI\3DGraph and also the Annotations example located at C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\UI\Graph\Annotations.  Perhaps you could post some short example code that demonstrates the behavior.

 

I know you mentioned that you were using the OnAnnotationMouseMove() event which is generated when you move the mouse over an annotation. One thing to note is that the graph you are using will ONLY generate that MouseMove event if CNiGraph::TrackMode is set to TrackAllEvents. If TrackMode is TrackDragAnnotation, the function generates the AnnotationChange event.  To set this option, you could say:

 

graph.SetTrackMode(CNiGraph3D::TrackModes::TrackAllEvents);

 

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 2 of 4
(3,737 Views)
Hi Jonathan

The problem is, I'm using CNiGraph, not CNiGraph3D. Of course I have CNiGraph::TrackAllEvents set - that's why I mentioned getting other (cursor, for example) events. Moreover, when I add vertical limits to my MinMaxRange, I get exactly the event I want. Look, if I have both horizonal _and_ vertical limits set (my MinMaxRange has coordinates x1, y1, x2, y2), I get these events. That is, control code does probably something like that
if( ( x1 <= mouse_x ) && ( y1 <= mouse_y ) && ( mouse_x <= x2 ) && ( mouse_y <= y2 ) ) SendEvent( );
But when I remove vertical limits (y1 and y2) _no event_ appears! And I think it should: when no vertical limits are set, code should look like that:
if( ( x1 <= mouse_x ) && ( mouse_x <= x2 ) ) SendEvent( );
That is, it should be independent from mouse_y position, since my MinMaxRange spans _whole_ vertical axis (because it has no vertical limits).

And my code goes here:

        annotation.SetBuiltinStyle( NI::CNiAnnotation::Range );
        annotation.SetEnabled( TRUE );
        annotation.SetVisible( TRUE );
        annotation.GetShape( ).SetType( NI::CNiShape::MinMaxRegion );
        annotation.GetShape( ).SetFillVisible( TRUE );
        annotation.GetShape( ).SetLineWidth( 1 );
        NI::CNiColor clr( 0xff, 0xff, 0 );    // yellow for now
        annotation.GetShape( ).SetLineColor( clr );
        annotation.GetShape( ).SetLineStyle( NI::CNiShape::LineSolid );
       // to Jonathan: here I use my own time functions but they work just fine
       // limits are set properly and annotation appears where I want it to be
        NI::CNiReal64Vector empty_vector( 0 ), time_coordinate_vector( 2 );
        time_coordinate_vector[ 0 ] = convertTime( t );
        tkt::system::Timestamp tt( t.getSeconds( ) + 10, t.getNanoseconds( ) );
        time_coordinate_vector[ 1 ] = convertTime( tt );
        annotation.GetShape( ).SetCoordinates( time_coordinate_vector, empty_vector );
        annotation.SetCoordinateType( NI::CNiAnnotation::AxesCoordinates );
        annotation.SetSnapMode( NI::CNiAnnotation::SnapFloating );

Please note that I got very same effect using example provided by NI and dialog boxes in Visual Studio, so I doubt that this is problem of my code. What I think is that vertical limits are needed for event checking. And that's plain wrong. Could you please check it out again?

Thanks in advance
Michal
0 Kudos
Message 3 of 4
(3,730 Views)

Hi Michal,

I was able to fully reproduce the behavior that you saw when you were using the MinMaxRegion shape and removing the vertical limits. This does appear to be a bug and I am notifying R&D about this issue. Thanks for the find. 

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 4 of 4
(3,709 Views)