/*------------------------------------------------------------------------*
  Filename....: star_tool.c


		 COPYRIGHT (C) 2001.  All Rights Reserved.
		 auto*des*sys, Inc., Columbus, Ohio, USA.
 *------------------------------------------------------------------------*/

#include "star.h"
#include "fz_tool_api.h"
#include "fz_cmnd_model_ids.h"

star_otyp_parms_td		*_star_tool_opts;


enum
{
	STAR_ITEM_ID_RADIUS = 0,
	STAR_ITEM_ID_RATIO_SLIDER,
	STAR_ITEM_ID_RATIO_TEXT,
	STAR_ITEM_ID_BASE_TYPE,
	
	STAR_ITEM_ID_MAX
};

/************************************************************************
	info callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_info(fz_tool_kind_enum *kind, fz_proj_level_enum *level)
{
	fzrt_error_td			rv = FZRT_NOERR;

	*kind = FZ_TOOL_KIND_OPERATOR;
	*level = FZ_PROJ_LEVEL_MODEL;

	rv = plugin_stuff.fzrt_mem_funcs.fzrt_new_ptr(sizeof(star_otyp_parms_td), (fzrt_ptr*)&_star_tool_opts);
	
	if ( _star_tool_opts != NULL)
	{
		_star_tool_opts->base_type = 2;
		_star_tool_opts->origin.x = 0.0;
		_star_tool_opts->origin.y = 0.0;
		_star_tool_opts->origin.z = 0.0;
		_star_tool_opts->xaxis.x = 1.0;
		_star_tool_opts->xaxis.y = 0.0;
		_star_tool_opts->xaxis.z = 0.0;
		_star_tool_opts->yaxis.x = 0.0;
		_star_tool_opts->yaxis.y = 1.0;
		_star_tool_opts->yaxis.z = 0.0;
		_star_tool_opts->radius = 96.0;
		_star_tool_opts->rad_ratio = 0.5;
		_star_tool_opts->fixed = FALSE;
		
	}
	else rv = -1;
	
	return (rv);
}

/************************************************************************
	name callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_name(char *name, fzrt_int max_len)
{
	char	str[256];
	
	plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_TOOL_NAME, str);
	strncpy(name, str, max_len);
	
	return (FZRT_NOERR);
}

/************************************************************************
	uuid callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_uuid(fzrt_UUID_td uuid)
{

	plugin_stuff.fzrt_base_funcs.fzrt_UUID_copy( STAR_TOOL_ID, uuid );
	
	return (FZRT_NOERR);
}

/************************************************************************
	icon file callback function for the star tool command
	DEK 09/19/06 : Fixed unit var
	SPG 01/19/11 : Use new icon file function.
*************************************************************************/
static fzrt_error_td star_tool_icon_file(fzrt_floc_ptr floc)
{
fzrt_error_td	err=FZRT_NOERR;			/** DEK 09/19/06 ***/

	err = plugin_stuff.fzrt_file_funcs.fzrt_file_floc_copy(plugin_stuff.floc,floc);
	err = plugin_stuff.fzrt_file_funcs.fzrt_file_floc_set_name(floc,"star.bmp");
	return(err);
}

/************************************************************************
	prefs io callback function for the star tool command
**************************************************************************/
static fzrt_error_td star_tool_pref_io(fz_iost_ptr iost, fz_iost_dir_td_enum dir, fzpl_vers_td * const version, fzrt_unsigned_int size)
{
	fzrt_error_td		err = FZRT_NOERR;
	star_otyp_parms_td	*data;
	
	data = (star_otyp_parms_td*) _star_tool_opts;

	if ( dir == FZ_IOST_WRITE ) *version = 0;
	
	if((err = plugin_stuff.iost_funcs.fz_iost_int(iost,   &data->base_type, 1)) == FZRT_NOERR &&
	   (err = plugin_stuff.iost_funcs.fz_iost_double(iost, &data->radius, 1)) == FZRT_NOERR )
	{	if((err = plugin_stuff.iost_funcs.fz_iost_double(iost, &data->rad_ratio, 1)) == FZRT_NOERR)
		{	if((err = plugin_stuff.iost_funcs.fz_iost_short(iost, &data->fixed, 1)) == FZRT_NOERR)
			{
			}
		}
	}

	return(err);
}

/************************************************************************
	units callback function for the star tool command
**************************************************************************/
static fzrt_error_td star_tool_syst_units(fz_unit_type_enum pref_units, fz_unit_scale_enum pref_scale)
{
	star_otyp_parms_td	*data;

	data = (star_otyp_parms_td*) _star_tool_opts;

	if(data != NULL)
	{	
		plugin_stuff.fuim_funcs.fz_fuim_unit_convert(96.0, 200.0, FZ_UNIT_SCAL_MEDIUM, pref_units, pref_scale, &data->radius);
		
	}

	return(FZRT_NOERR);
}

/************************************************************************
	preferences defaults callback function for the star tool command
**************************************************************************/
static fzrt_error_td star_tool_pref_default(fz_unit_type_enum pref_units, fz_unit_scale_enum pref_scale)
{
	star_otyp_parms_td	*data;

	data = (star_otyp_parms_td*) _star_tool_opts;

	if(data != NULL)
	{			
		_star_tool_opts->base_type = 2;
		_star_tool_opts->origin.x = 0.0;
		_star_tool_opts->origin.y = 0.0;
		_star_tool_opts->origin.z = 0.0;
		_star_tool_opts->xaxis.x = 1.0;
		_star_tool_opts->xaxis.y = 0.0;
		_star_tool_opts->xaxis.z = 0.0;
		_star_tool_opts->yaxis.x = 0.0;
		_star_tool_opts->yaxis.y = 1.0;
		_star_tool_opts->yaxis.z = 0.0;
		_star_tool_opts->rad_ratio = 0.5;
		_star_tool_opts->fixed = FALSE;

		star_tool_syst_units(pref_units, pref_scale);
	}

	return(FZRT_NOERR);
}


/************************************************************************
	icon adjacent callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_icon_adjacent(const fzrt_UUID_td tool_bar_id, fzrt_UUID_td adjacent_id, fz_fuim_icon_adjacent_enum *where)
{		

	
	plugin_stuff.fzrt_base_funcs.fzrt_UUID_copy(FZ_CMND_MODEL_PRIM_SPHERE, adjacent_id);
	*where = FZ_FUIM_ICON_ADJACENT_RIGHT;
	
	return(FZRT_NOERR);
}


typedef struct
{
	fz_objt_ptr			obj;
	star_otyp_parms_td	*star;
	fz_xyz_td			origin;
	short				clicks;
	
} star_track_data_td;

star_track_data_td		star_track_data;

#define STAR_RADIUS_MIN	0.001


/************************************************************************
	handles the first click when creating a star object
*************************************************************************/
static fzrt_error_td star_tool_click_first(fzrt_int windex, fz_xyz_td *origin, fzrt_boolean *done)		
{
	fzrt_error_td		err;
	fz_objt_ptr			obj;
	star_otyp_parms_td	*star;		
	char				prompt_str[256];

	if((err = plugin_stuff.model_funcs.fz_objt_cnstr_objt_new(windex,&obj)) == FZRT_NOERR )
	{
		
		if( (err = plugin_stuff.model_funcs.fz_objt_parm_init_data(windex,obj,STAR_OTYP_ID,(fzrt_ptr*)&star)) == FZRT_NOERR )
		{
			star->origin 	= *origin;
			star->base_type = _star_tool_opts->base_type;
			if(_star_tool_opts->fixed)	star->radius 	= _star_tool_opts->radius;
			else						star->radius 	= STAR_RADIUS_MIN;
			star->rad_ratio = _star_tool_opts->rad_ratio;
			
			star->xaxis.x = star->radius;
			star->xaxis.y = 0.0;
			star->xaxis.z = 0.0;
			star->yaxis.x = 0.0;
			star->yaxis.y = star->radius;
			star->yaxis.z = 0.0;
			
			if((err = plugin_stuff.model_funcs.fz_objt_edit_parm_regen(windex,obj)) == FZRT_NOERR )
			{
				err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,obj);
			}
			
			if(_star_tool_opts->fixed)
			{
				plugin_stuff.model_funcs.fz_model_result_add_objt(windex,obj);
				*done = TRUE;
			}
			else
			{
				star_track_data.obj  	= obj;
				star_track_data.star 	= star;
				star_track_data.origin	= *origin;
				star_track_data.clicks	= 1;
				
				plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_RADIUS_PROMPT, prompt_str);
				plugin_stuff.fuim_funcs.fz_fuim_prompt_line(prompt_str, FZ_FUIM_PROMPT_LINE_NEXT, FZ_FUIM_PROMPT_EDIT_LINEAR_X);

				*done = FALSE;
			}
		}

		if ( err != FZRT_NOERR )
		{	plugin_stuff.model_funcs.fz_objt_edit_delete_objt(windex,obj);
		}
	}


	return FZRT_NOERR;
}

/************************************************************************
	handles the second click when creating a star object
*************************************************************************/
static fzrt_error_td star_tool_click_second(fzrt_int windex, fz_xyz_td *xaxis, fz_xyz_td *yaxis, double radius)
{	
	fzrt_error_td			err = FZRT_NOERR;
	star_otyp_parms_td		*star;
	fz_type_td				type;
	short					item_ids[5];
	
	star 		 = star_track_data.star;
	star->radius = radius;

	if(star->radius < STAR_RADIUS_MIN)star->radius = STAR_RADIUS_MIN;
	
	plugin_stuff.type_funcs.fz_type_set_double(&star->radius, &type);			
	plugin_stuff.fuim_funcs.fz_fuim_prompt_refresh_data(&type);

	if(xaxis)star->xaxis = *xaxis;
	if(yaxis)star->yaxis = *yaxis;
			
	plugin_stuff.model_funcs.fz_objt_edit_parm_regen(windex,star_track_data.obj);
	
	_star_tool_opts->radius = radius;	/* ALSO UPDATE GLOBAL */
	item_ids[0] = STAR_ITEM_ID_RADIUS;
	plugin_stuff.fuim_funcs.fz_fuim_tool_opts_update_items(1,item_ids);
	
	return (err);
}

/************************************************************************
	Calculates the rotation of a star object during dynaimc creation
	 JSP 02/25/08  PZ_09905 & PZ_09638  fixed the star not forming
			on planes other than XY plane. 
*************************************************************************/
static void star_tool_calc_axis(fz_xyz_td *where_3d, fz_map_plane_td *map_plane, double radius, fz_xyz_td *xaxis, fz_xyz_td *yaxis)		
{
	fz_xyz_td				start3d,end3d;	
	fz_xy_td				start2d,end2d;	
	double					angle;
	fz_mat4x4_td			mat;

	xaxis->x = radius;
	xaxis->y = 0.0;
	xaxis->z = 0.0;
	yaxis->x = 0.0;
	yaxis->y = radius;
	yaxis->z = 0.0;
			
	start3d = star_track_data.origin;
	end3d = *where_3d;
	plugin_stuff.math_funcs.fz_math_3d_map_plane_to_plane/*world*/(map_plane, &start3d);  /*  JSP 02/25/08  */
	plugin_stuff.math_funcs.fz_math_3d_map_plane_to_plane/*world*/(map_plane, &end3d);  /*  JSP 02/25/08  */

	start2d.x = start3d.x;
	start2d.y = start3d.y;

	end2d.x = end3d.x;
	end2d.y = end3d.y;
	
	plugin_stuff.math_funcs.fz_math_2d_angle_of_line_seg(&start2d, &end2d, &angle);
	
	plugin_stuff.math_funcs.fz_math_4x4_set_identity(&mat);
	plugin_stuff.math_funcs.fz_math_4x4_set_rot_mat(&mat, angle, FZ_AXIS_Z);
	plugin_stuff.math_funcs.fz_math_4x4_multiply_mat_xyz(&mat, xaxis);
	plugin_stuff.math_funcs.fz_math_4x4_multiply_mat_xyz(&mat, yaxis);
	
	plugin_stuff.math_funcs.fz_math_3d_map_plane_to_world(map_plane, xaxis);	/*  JSP 02/25/08  */
	plugin_stuff.math_funcs.fz_math_3d_map_plane_to_world(map_plane, yaxis);   /*  JSP 02/25/08  */
}


/************************************************************************
	click callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_click(
		fzrt_int 						windex, 
		fzrt_point 					*where, 
		fz_xyz_td 					*where_3d, 
		fz_map_plane_td 			*map_plane,
		fz_fuim_click_enum 			clicks, 
		fzrt_int 						click_count,  
		fzrt_boolean 				*click_handled,
		fz_fuim_click_wait_enum 	*click_next, 
		fzrt_boolean 				*done)		
{
	fzrt_error_td			err;
	fz_xyz_td				xaxis,yaxis;
	double					radius;
	
	if(click_count == 1)
	{	err = star_tool_click_first(windex, where_3d, done);	
	}
	else				
	{	
		radius = FZ_MATH_3D_DIST_PT_PT(&star_track_data.origin,where_3d);

		star_tool_calc_axis(where_3d, map_plane, radius, &xaxis, &yaxis);		
	
		err = star_tool_click_second(windex, &xaxis, &yaxis, radius);
		star_track_data.clicks = 0;
		
		plugin_stuff.model_funcs.fz_model_result_add_objt(windex,star_track_data.obj);

		*done = TRUE;	
	}

	return (err);
}

/************************************************************************
	track callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_track(
	fzrt_int				windex,				
	fzrt_point 			*where, 			
	fz_xyz_td	 		*where_3d, 			
	fz_map_plane_td 	*map_plane,
	fzrt_int			 	click_count 		
	)
{	
	fzrt_error_td			err = FZRT_NOERR;
	fz_xyz_td				xaxis,yaxis;
	double					radius;

	if(click_count == 1)
	{
		radius = FZ_MATH_3D_DIST_PT_PT(&star_track_data.origin,where_3d);

		star_tool_calc_axis(where_3d, map_plane, radius, &xaxis, &yaxis);		
	
		err = star_tool_click_second(windex, &xaxis, &yaxis, radius);
	}
	return (err);
}

/************************************************************************
	cancel callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_cancel(
	fzrt_int				windex,				
	fzrt_int			 	click_count 		
	)
{	
	fzrt_error_td			err = FZRT_NOERR;

	if(click_count == 1)
	{
		plugin_stuff.model_funcs.fz_objt_edit_delete_objt(windex,star_track_data.obj);
		star_track_data.clicks = 0;
		star_track_data.obj = NULL;
	}
	return (err);
}

/************************************************************************
	tool options name callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_opts_name(char *name, fzrt_int max_len)
{
	char	str[256];
	
	plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_OPTS_TITLE, str);
	strncpy(name, str, max_len);
	
	return (FZRT_NOERR);
}

/************************************************************************
	tool options uuid callback function for the star tool command
*************************************************************************/
static fzrt_error_td star_tool_opts_uuid(fzrt_UUID_td uuid)
{

	plugin_stuff.fzrt_base_funcs.fzrt_UUID_copy(STAR_TOOL_OPTS_ID, uuid);
	
	return (FZRT_NOERR);
}

/*************************************************************************
	Fuim item callback to copy the tool globals into the
	paramtric object data
**************************************************************************/
static short star_tool_fuim_parm_copy_func(
	fz_fuim_tmpl_ptr	fuim_tmpl, 
	fzrt_int				action, 
	short				item_id, 
	void				*func_data, 
	fz_fuim_type_td		*rv_data
	)
{
	fz_objt_ptr			obj;
	fzrt_int 				i,n,windex;
	star_otyp_parms_td	*star;
	short				rv = FALSE;
	

	switch(action)
	{
		case FZ_FUIM_ACTN_NEW_CHILD_VALUE :
			plugin_stuff.fuim_funcs.fz_fuim_get_active_windex(&windex);
			
			plugin_stuff.model_funcs.fz_model_result_get_count(windex,&n);
			for(i = 0; i < n; i++)
			{
				plugin_stuff.model_funcs.fz_model_result_get_objt(windex,i,&obj);
				plugin_stuff.model_funcs.fz_objt_parm_get_data(windex,obj,(fzrt_ptr*)&star);
				
				star->radius	= _star_tool_opts->radius;
				star->rad_ratio = _star_tool_opts->rad_ratio;
				star->base_type = _star_tool_opts->base_type;
			}
			rv = TRUE;
		break;
		
		
	}
	return(rv);
}

/************************************************************************
	tool options dialog template callback function for the star tool command
	JSP 2/15/08 : fixed minor fuim issue.  No bug number.  Sorry.  Its been bugging me.
*************************************************************************/
static fzrt_error_td star_tool_opts_fuim(fz_fuim_tmpl_ptr fuim_tmpl, fzrt_ptr fuim_data)
{
	short					g1, g2, gindx;
	star_otyp_parms_td		*star;
	fzrt_menu_ptr			menu;
	char					str[256];
	fzrt_error_td			err;
	
	star = (star_otyp_parms_td*)_star_tool_opts;

	plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_OPTS_TITLE, str);
	if((err = plugin_stuff.fuim_funcs.fz_fuim_tmpl_init(fuim_tmpl, str, 0, STAR_TOOL_OPTS_ID, 0)) == FZRT_NOERR)
	{
		plugin_stuff.fuim_funcs.fz_fuim_objt_parm_result_regen(
				fuim_tmpl,
				FZ_FUIM_ROOT,
				STAR_OTYP_ID,
				star_tool_fuim_parm_copy_func,
				NULL,
				&gindx
				);


		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_menu(plugin_stuff.fz_rsrc_ref_func, STAR_BASE_MENU_ID,&menu);
		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_BASE_TYPE, str);
		g1 = plugin_stuff.fuim_funcs.fz_fuim_new_menu(fuim_tmpl,gindx, STAR_ITEM_ID_BASE_TYPE, FZ_FUIM_FLAG_HORZ, str, menu, FALSE, NULL, NULL);
			plugin_stuff.fuim_funcs.fz_fuim_item_range_int(fuim_tmpl,g1, &star->base_type, 0, 7, FZ_FUIM_FORMAT_INT_DEFAULT,
								  FZ_FUIM_RANGE_MIN | FZ_FUIM_RANGE_MAX | FZ_FUIM_RANGE_MIN_INCL | FZ_FUIM_RANGE_MAX_INCL);
		
		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_DYNAMIC, str);
		g1 = plugin_stuff.fuim_funcs.fz_fuim_new_radio(fuim_tmpl,gindx,FZ_FUIM_NONE,FZ_FUIM_FLAG_NONE,str, NULL, NULL);			
		plugin_stuff.fuim_funcs.fz_fuim_item_unary_short(fuim_tmpl, g1, &star->fixed, 0);

		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_PRESET, str);
		g1 = plugin_stuff.fuim_funcs.fz_fuim_new_radio(fuim_tmpl,gindx,FZ_FUIM_NONE,FZ_FUIM_FLAG_NONE, str, NULL, NULL);			
		plugin_stuff.fuim_funcs.fz_fuim_item_unary_short(fuim_tmpl, g1, &star->fixed, 1);
		

			plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_RADIUS, str);
			plugin_stuff.fuim_funcs.fz_fuim_new_text_static_edit(fuim_tmpl,g1,FZ_FUIM_NONE,str,STAR_ITEM_ID_RADIUS,FZ_FUIM_FLAG_NONE /*FZ_FUIM_FLAG_BRDR*/, NULL, NULL,&g2);			
			plugin_stuff.fuim_funcs.fz_fuim_item_range_double(fuim_tmpl, g2, &star->radius, 0.0, 0.0, FZ_FUIM_FORMAT_FLOAT_DISTANCE, FZ_FUIM_RANGE_MIN);
			
		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, STAR_STR_ID, STAR_STR_RAY_RATIO, str);
		plugin_stuff.fuim_funcs.fz_fuim_new_slid_edit_pcent_double(
				fuim_tmpl, 
				gindx,
				str,
				STAR_ITEM_ID_RATIO_SLIDER,
				STAR_ITEM_ID_RATIO_TEXT,
				0.0,
				1.0,
				0.0,
				100.0,
				FZ_FUIM_RANGE_MIN | FZ_FUIM_RANGE_MIN_INCL | FZ_FUIM_RANGE_MAX | FZ_FUIM_RANGE_MAX_INCL,
				NULL,
				&star->rad_ratio, 
				NULL,
				NULL);
    }
		
	return (err);
}

/*************************************************************************
	info2 callback
*************************************************************************/
static fzrt_boolean star_tool_info2(
	fzrt_int				windex,
	fz_tool_info_enum	which,
	fz_type_td			*info_data,
	fz_type_td			*data
	)
{
	fzrt_boolean		rv = TRUE;
	fzrt_int				value;

	switch(which)
	{
		case FZ_TOOL_INFO_PICK_STATE :
			value = 0;
			plugin_stuff.type_funcs.fz_type_set_int(&value, data);
		break;

		case FZ_TOOL_INFO_DRAW_STATE:
			/* AUTOPLANE ONLY FOR FIRST CLICK POINT */
			value = 0;
			if( star_track_data.clicks == 0 ) value = 1;
			plugin_stuff.type_funcs.fz_type_set_int(&value, data);
		break;
		
		/* SNAP ALL THE TIME. NECESSARY BECAUSE PICK AND DRAW ARE BOTH OFF	*/
		/* AFTER FIRST CLICK, WHICH MEANS NO SNAPPING BY DEFAULT			*/
		case FZ_TOOL_INFO_YES_SNAP :
			value = 1;
			plugin_stuff.type_funcs.fz_type_set_int(&value, data);
		break;

		default:
			rv = FALSE;
		break;
	}
	return(rv);
}

/************************************************************************
	Activate tool callback
*************************************************************************/
static fzrt_error_td star_tool_activate(fzrt_int windex)
{
	star_track_data.clicks = 0;
	return(FZRT_NOERR);
}

/************************************************************************
	Deactivate tool callback
*************************************************************************/
static fzrt_error_td star_tool_deactivate(fzrt_int windex)
{
	star_track_data.clicks = 0;
	return(FZRT_NOERR);
}

/************************************************************************
	JSP 10/08/08 : New function
	JSP 11/06/08  : adjusting function
*************************************************************************/
static fzrt_boolean star_tool_action(
	fzrt_int				windex,
	fz_tool_action_enum	which,
	fzrt_int				set_id,
	fzrt_int				click_count, 
	char				*actn_string, 
	fzrt_int				actn_string_len
	)
{
	fzrt_boolean		rv = FALSE;
	
	switch(which)
	{
		case FZ_TOOL_ACTION_DESCRIPTION :
//			fzrt_fzr_get_string(_tools_rsrc_ref, list_id, TOOL_STR_CONE_DESC, actn_string);
			strcpy(actn_string,"Creates a star shaped object from clicked points.");
			rv = TRUE;
		break;
		
		case FZ_TOOL_ACTION_CLICK :
			if ( star_track_data.clicks == 0 )
			{
				strcpy(actn_string,"Define origin point.");
			}
			else
			{
				strcpy(actn_string,"Define radius point.");
			}

			rv = TRUE;
		break;
		default:
		break;
	}
	
	return(rv);
}

/************************************************************************
	Fill the tool command function set with the star tool command callback
	functions.
*************************************************************************/
fzrt_error_td star_tool_get_callback_fset ( const fzpl_fset_def_ptr fset_def, fzpl_fset_td * const fset )
{
	fzrt_error_td							err = FZRT_NOERR;
	fz_tool_cbak_fset 				*tool_func;

	err = plugin_stuff.fsf->fzpl_fset_def_check ( fset_def, FZ_TOOL_CBAK_FSET_VERSION, FZPL_TYPE_STRING(fz_tool_cbak_fset), sizeof ( tool_func ), FZPL_VERSION_OP_NEWER );
	if ( err == FZRT_NOERR )
	{
		tool_func = (fz_tool_cbak_fset *)fset;
		
		tool_func->fz_tool_cbak_info					= star_tool_info;
		tool_func->fz_tool_cbak_name					= star_tool_name;
		tool_func->fz_tool_cbak_uuid					= star_tool_uuid;
		tool_func->fz_tool_cbak_icon_file				= star_tool_icon_file;
		tool_func->fz_tool_cbak_icon_menu_adjacent		= star_tool_icon_adjacent;
		
		tool_func->fz_tool_cbak_pref_io					= star_tool_pref_io;

		tool_func->fz_tool_cbak_opts_name 				= star_tool_opts_name;
		tool_func->fz_tool_cbak_opts_uuid 				= star_tool_opts_uuid;
		tool_func->fz_tool_cbak_opts_iface_tmpl			= star_tool_opts_fuim;
		tool_func->fz_tool_cbak_click					= star_tool_click;
		tool_func->fz_tool_cbak_track					= star_tool_track;
		tool_func->fz_tool_cbak_cancel					= star_tool_cancel;
		tool_func->fz_tool_cbak_info2					= star_tool_info2;
		tool_func->fz_tool_cbak_activate				= star_tool_activate;
		tool_func->fz_tool_cbak_deactivate				= star_tool_deactivate;
		tool_func->fz_tool_cbak_action					= star_tool_action;
	}

	return err;
}

/************************************************************************
	Fill the notification function set with the star tool notification callback
	functions.
*************************************************************************/
fzrt_error_td star_notf_get_callback_fset ( const fzpl_fset_def_ptr fset_def, fzpl_fset_td * const fset )
{
	fzrt_error_td						err = FZRT_NOERR;
	fz_notf_cbak_fset 				*notf_func;

	err = plugin_stuff.fsf->fzpl_fset_def_check ( fset_def, 
					FZ_NOTF_CBAK_FSET_VERSION, 
					FZPL_TYPE_STRING(fz_notf_cbak_fset), 
					sizeof ( notf_func ), FZPL_VERSION_OP_NEWER );
	if ( err == FZRT_NOERR )
	{
		notf_func = (fz_notf_cbak_fset *)fset;
		
		notf_func->fz_notf_cbak_syst_units		= star_tool_syst_units;
		notf_func->fz_notf_cbak_pref_default	= star_tool_pref_default;

	}

	return err;
}
