/****************************************************************
 * Filename  :	Counter.c
 * Functions :	
 *		Counter_Display
 *		Counter_SetValue
 * Purpose   : 	Functions for the Counter class
 * Comment   : 	This class inherit from Item
 $Revision: 1.1 $
 ***************************************************************/

#include "dmvideo.h"                    /* data manager definitions           */
#include "OVtypes.h"                    /* video overlay type definitions     */
#include "dy4std.h"                     /* DY4 standard definitions           */
#include "video.h"                      /* DY4 video definitions              */
#include "mygraphics.h"                 /* graphics alignment definitions     */
#include "dy4driver.h"                 	/* DY4 driver definitions             */
#include "Date.h" 			/* Date class definitions             */
#include "Time.h" 			/* Time class definitions             */
#include "Counter.h" 			/* Counter class definitions          */

/*---------------------------------------------------------------
 | Function  :	Counter_Display
 | Purpose   : 	Display the Counter on the screen
 | Inputs    :	none
 | Outputs   :	none
 | Side FX   :	none
 | comments  :
 | Author    :	sylvain.coudray MBARI-IFREMER/diti/dsi/ie
 | Modified  :  tarrant 8/29/96 removed erase, already done on refresh
 |           :  tarrant 7/10/97 replaced globals with alignment structure
 ---------------------------------------------------------------*/
    void
Counter_Display(OV_alignment *alignment, OV_Item *p_item)
{

    My_wri_text(alignment, p_item->x, p_item->y, p_item->value);

    return;

} /* Counter_Display */



/*---------------------------------------------------------------
 | Function  :	Counter_SetValue
 | Purpose   : 	
 | Inputs    :	none
 | Outputs   :	none
 | Side FX   :	none
 | comments  :  call by upper class method Item_SetValue
 | Author    :	sylvain.coudray MBARI-IFREMER/diti/dsi/ie
 ---------------------------------------------------------------*/
    void
Counter_SetValue(OV_Item *p_item, OV_char *value)
{
	OV_float	format;
	OV_float	tmp_float;	/* temporary storage */
	OV_float	number;		/* temporary storage */
	OV_int		nb_int;		/* integer part length */
	OV_int		nb_dec;		/* decimal part length */
	OV_int		nb_char;	/* total length */
	OV_char		string_format[10];

	/* ................................... */
	/* ... Simulate Method inheritance ... */
	/* ................................... */

	if ( strcmp ( p_item->type, "DATE") == 0)
	{
	   Date_SetValue ( p_item, value);
	   return;
	}
	if ( strcmp ( p_item->type, "TIME") == 0)
	{
	   Time_SetValue ( p_item, value);
	   return;
	}

	/* ................................. */
	/* ... Begin specific statements ... */
	/* ................................. */

	/* Initializations */
	format = p_item->p_context->value_format;

	/* calculate format */
	nb_int = (int) format;
	tmp_float = format * 10.0;
	nb_dec = (int) (tmp_float) - (nb_int * 10);
	nb_char = nb_int + 1 + nb_dec;
	sscanf ( value, "%f", &number);

	strncpy ( string_format, "%", 1);
	sprintf ( string_format+1, "%d.%df", nb_char, nb_dec);

	/* allocate string for current value */
   	p_item->value = (char *) malloc ( nb_char);

	/* write value according to format */
	sprintf ( p_item->value, string_format, number);

/*debug
printf ( "format,tmp_float = %f %f\n", format,tmp_float);	
printf ("nb_int, nb_dec = %d %d\n", nb_int, nb_dec);
printf ( "value = %s \n", value);	
printf ( "number = %f \n", number);	
printf ( "string_format = %s \n", string_format);	
printf ( "p_item->value = %s \n", p_item->value);
enddebug*/

	/* ............. */
	/* ...  End  ... */
	/* ............. */

        return;

} /* Counter_SetValue */

/*---------------------------------------------------------------
 | Function  :	Counter_cccccc
 | Purpose   : 	
 | Inputs    :	none
 | Outputs   :	none
 | Side FX   :	none
 | comments  :
 | Author    :	sylvain.coudray MBARI-IFREMER/diti/dsi/ie
 ---------------------------------------------------------------*/

	void
Counter_cccccc ( p_item)
OV_Item		*p_item;
{

	/* ... Local Variables */
	/* ... Initializations */
	/* ... Begin */


	/* ... End */

        return;

} /* Counter_cccccc */

