Detecting Redraw Events

The simulation window (SimView) will be redrawn whenever you: Any objects you have drawn by your models during a simulation, such as an XY-graph, will be erased by a redraw event. You can restore them by detecting the redraw events and re-initialing or redrawing your dynamic objects.

You can detect redraw events by monitoring the value of the following pre-defined global integer:

resizedraw_no
The resizedraw_no is changed (incremented) everytime there is a redraw event.

For example:

Suppose your model displays an XY-graph gadget. You might do the following:
	DEFINE_THREAD: start_up
	 {
	  int old_redraw_number;

	  plot_init( MY_NAME, "x-axis", "y-axis" );
	  plot_axis_x( MY_NAME, 0.0, 105.0, 0, Gold, Blue );
	  plot_axis_y( MY_NAME, 50.0, 250.0, 0, Gold, Blue );

	  /* Record the initial redraw-number. */
	  old_redraw_number = resizedraw_no;

	  while (1)
	   {
	    DELAY(10.0);  /* Periodically check for redraws. */
	    if (old_redraw_number != resizedraw_no)
	     {
		/* Detected a redraw event.  Restore graph. */
		plot_init( MY_NAME, "x-axis", "y-axis" );
		plot_axis_x( MY_NAME, 0.0, 105.0, 0, Gold, Blue );
		plot_axis_y( MY_NAME, 50.0, 250.0, 0, Gold, Blue );
		/* Update the redraw-number. */
		old_redraw_number = resizedraw_no;
	     }
	   }
         }
	END_DEFINE_THREAD.