/*------------------------------------------------------------------------*
  Filename....: frame_tool.c


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

#include "frame.h"
#include "fz_tool_api.h"
#include "fz_cmnd_model_ids.h"

frame_otyp_parms_td		*_frame_tool_opts;

/************************************************************************
	info callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_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(frame_otyp_parms_td), (fzrt_ptr*)&_frame_tool_opts);
	
	if ( _frame_tool_opts != NULL)
	{
		_frame_tool_opts->radius 		= 6.0;
		_frame_tool_opts->base_obj 		= NULL;
	
	}
	else rv = -1;
	
	return (rv);
}

/************************************************************************
	init callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_tool_init (
	void
	)
{
	plugin_stuff.syst_funcs.fz_syst_cmnd_set_status_of_objt(FRAME_TOOL_ID,TRUE,FALSE);
	return (FZRT_NOERR);
}


/************************************************************************
	name callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_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, FRAME_STR_ID, FRAME_STR_TOOL_NAME, str);
	strncpy(name, str, max_len);
	
	return (FZRT_NOERR);
}

/************************************************************************
	uuid callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_tool_uuid(fzrt_UUID_td uuid)
{

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

/************************************************************************
	icon file callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_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,"frame.bmp");
	return(err);
}

/************************************************************************
	prefs io callback function for the frame tool command
**************************************************************************/
static fzrt_error_td frame_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;
	frame_otyp_parms_td	*data;
	
	data = _frame_tool_opts;

	if ( dir == FZ_IOST_WRITE ) *version = 0;
	
	err = plugin_stuff.iost_funcs.fz_iost_double(iost, &data->radius, 1);

	return(err);
}

/************************************************************************
	units callback function for the frame tool command
**************************************************************************/
static fzrt_error_td frame_tool_syst_units(fz_unit_type_enum pref_units, fz_unit_scale_enum pref_scale)
{
	frame_otyp_parms_td	*data;

	data = (frame_otyp_parms_td*) _frame_tool_opts;

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

	return(FZRT_NOERR);
}
/************************************************************************
	preferences defaults callback function for the frame tool command
**************************************************************************/
static fzrt_error_td frame_tool_pref_default(fz_unit_type_enum pref_units, fz_unit_scale_enum pref_scale)
{
	frame_otyp_parms_td	*data;

	data = (frame_otyp_parms_td*) _frame_tool_opts;

	if(data != NULL)
	{	data->base_obj  = NULL;
		frame_tool_syst_units(pref_units, pref_scale);
	}

	return(FZRT_NOERR);
}

/************************************************************************
	icon adjacent callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_tool_tool_bar_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_DERV_PARL_PL, adjacent_id);
	*where = FZ_FUIM_ICON_ADJACENT_RIGHT;
	
	return(FZRT_NOERR);
}

typedef struct
{

	fz_objt_ptr			obj;
	frame_otyp_parms_td	*frame;
	fz_xyz_td			origin;
	short				clicks;
	
} frame_track_data_td;

frame_track_data_td		frame_track_data;

/************************************************************************
	click callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_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,radius_err;
	fz_objt_ptr				obj,pick_obj,line_obj,final_obj,olist[3];
	fz_model_pick_enum		pkind;
	fzrt_boolean			pre_pick;
	fzrt_int				i,npick,sindx,pindx,n,olist_knt=0;
	fz_xyz_td				p1,p2,p3,p4,p5,p6,p7,p8,p9,c1,c2,bisect_vec1,bisect_vec2,origin,arc_start_pt,arc_end_pt,norm;
	double					radius,arc_start,arc_end = 0.0;
	fz_xy_td				radius_xy;
	fz_enty_list_ptr		obj_list=NULL;
	
	err		 	= FZRT_NOERR;
	radius_err	= FZRT_NOERR;
	pre_pick 	= FALSE;
	
	/* CHECK FOR PRE PICKED OBJECTS */
	plugin_stuff.model_funcs.fz_model_pick_get_count(windex,&npick);
	plugin_stuff.model_funcs.fz_model_pick_sort(windex,FZ_MODEL_PICK_SORT_ORDER);
	
	if(npick == 3)
	{
		plugin_stuff.model_funcs.fz_model_pick_get_data(windex,0,&pkind,NULL,&pick_obj,&sindx);
		
		if(pkind == FZ_MODEL_PICK_SEGT)
		{
			err = plugin_stuff.model_funcs.fz_objt_segt_get_start_pindx(windex,pick_obj,sindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&pindx);
			err = plugin_stuff.model_funcs.fz_objt_point_get_xyz(windex,pick_obj,pindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&p1);
			err = plugin_stuff.model_funcs.fz_objt_segt_get_end_pindx(windex,pick_obj,sindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&pindx);
			err = plugin_stuff.model_funcs.fz_objt_point_get_xyz(windex,pick_obj,pindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&p2);
			
			olist[olist_knt++] = pick_obj;
		}
		else err = -1;
		
		plugin_stuff.model_funcs.fz_model_pick_get_data(windex,1,&pkind,NULL,&pick_obj,&sindx);
		
		if(pkind == FZ_MODEL_PICK_SEGT)
		{
			err = plugin_stuff.model_funcs.fz_objt_segt_get_start_pindx(windex,pick_obj,sindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&pindx);
			err = plugin_stuff.model_funcs.fz_objt_point_get_xyz(windex,pick_obj,pindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&p3);
			err = plugin_stuff.model_funcs.fz_objt_segt_get_end_pindx(windex,pick_obj,sindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&pindx);
			err = plugin_stuff.model_funcs.fz_objt_point_get_xyz(windex,pick_obj,pindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&p4);

			if(pick_obj != olist[0])olist[olist_knt++] = pick_obj;
		}
		else err = -1;
		
		plugin_stuff.model_funcs.fz_model_pick_get_data(windex,2,&pkind,NULL,&pick_obj,&sindx);

		if(pkind == FZ_MODEL_PICK_SEGT)
		{
			err = plugin_stuff.model_funcs.fz_objt_segt_get_start_pindx(windex,pick_obj,sindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&pindx);
			err = plugin_stuff.model_funcs.fz_objt_point_get_xyz(windex,pick_obj,pindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&p5);
			err = plugin_stuff.model_funcs.fz_objt_segt_get_end_pindx(windex,pick_obj,sindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&pindx);
			err = plugin_stuff.model_funcs.fz_objt_point_get_xyz(windex,pick_obj,pindx,FZ_OBJT_MODEL_TYPE_UNSPEC,&p6);
			
			if(pick_obj != olist[0] && (olist_knt < 2 || pick_obj != olist[1]))olist[olist_knt++] = pick_obj;
		}
		else err = -1;
		
		if(err == FZRT_NOERR)
		{
			if((err = plugin_stuff.math_funcs.fz_math_3d_isect_lines(&p1, &p2, &p3, &p4, &c1, NULL)) == FZRT_NOERR)
			{
				if((err = plugin_stuff.math_funcs.fz_math_3d_isect_lines(&p3, &p4, &p5, &p6, &c2, NULL)) == FZRT_NOERR)
				{
					if((err = plugin_stuff.math_funcs.fz_math_3d_bisect_angle(&p1, &c1, &p4, &bisect_vec1)) == FZRT_NOERR)
					{
						if((err = plugin_stuff.math_funcs.fz_math_3d_bisect_angle(&p3, &c2, &p6, &bisect_vec2)) == FZRT_NOERR)
						{
							p7.x = c1.x + (bisect_vec1.x * 100.0);
							p7.y = c1.y + (bisect_vec1.y * 100.0);
							p7.z = c1.z + (bisect_vec1.z * 100.0);
							
							p8.x = c2.x + (bisect_vec2.x * 100.0);
							p8.y = c2.y + (bisect_vec2.y * 100.0);
							p8.z = c2.z + (bisect_vec2.z * 100.0);
							
							if((err = plugin_stuff.math_funcs.fz_math_3d_isect_lines(&c1, &p7, &c2, &p8, &origin, NULL)) == FZRT_NOERR)
							{
								if((err = plugin_stuff.math_funcs.fz_math_3d_dist_pt_line(&p1,&p2,&origin,&radius)) == FZRT_NOERR)
								{
									if((err = plugin_stuff.model_funcs.fz_objt_cnstr_circle(windex, radius, FZ_OBJT_MODEL_TYPE_SMOD, &origin, NULL, NULL, &final_obj)) == FZRT_NOERR)
									{
										plugin_stuff.model_funcs.fz_objt_edit_uncover_surface(windex, final_obj);
									}

#if 0
									if(plugin_stuff.math_funcs.fz_math_3d_project_pt_on_line(&p1, &p2, &origin, FALSE, &p9, NULL, NULL) == FZRT_NOERR)
									{
										if(plugin_stuff.model_funcs.fz_objt_cnstr_point(windex, &p9, &obj) == FZRT_NOERR)
										{
											err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,obj);
										}
									}
									if(plugin_stuff.math_funcs.fz_math_3d_project_pt_on_line(&p3, &p4, &origin, FALSE, &p9, NULL, NULL) == FZRT_NOERR)
									{
										if(plugin_stuff.model_funcs.fz_objt_cnstr_point(windex, &p9, &obj) == FZRT_NOERR)
										{
											err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,obj);
										}
									}
									if(plugin_stuff.math_funcs.fz_math_3d_project_pt_on_line(&p5, &p6, &origin, FALSE, &p9, NULL, NULL) == FZRT_NOERR)
									{
										if(plugin_stuff.model_funcs.fz_objt_cnstr_point(windex, &p9, &obj) == FZRT_NOERR)
										{
											err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,obj);
										}
									}
#endif

									radius_xy.x = radius;
									radius_xy.y = radius;
									
									if((err = plugin_stuff.math_funcs.fz_math_3d_project_pt_on_line(&p1, &p2, &origin, FALSE, &arc_start_pt, &radius, NULL)) == FZRT_NOERR)
									{
										if((err = plugin_stuff.math_funcs.fz_math_3d_project_pt_on_line(&p5, &p6, &origin, FALSE, &arc_end_pt, &radius, NULL)) == FZRT_NOERR)
										{
										}
									}
									
									if(final_obj == NULL)
									{
										
										p9.x = origin.x + 100.0;
										p9.y = origin.y;
										p9.z = origin.z;
										
										if((err = plugin_stuff.math_funcs.fz_math_3d_angle_of_2_lines(&p9, &origin, &arc_start_pt, &arc_start)) == FZRT_NOERR)
										{
											if((err = plugin_stuff.math_funcs.fz_math_3d_angle_of_2_lines(&p9, &origin, &arc_end_pt, &arc_end)) == FZRT_NOERR)
											{
												
											}
										}
										
										if((err = plugin_stuff.model_funcs.fz_objt_cnstr_arc(windex,&radius_xy, arc_start, arc_end, TRUE, FZ_OBJT_MODEL_TYPE_SMOD, &origin, NULL, NULL, &final_obj)) == FZRT_NOERR)
										{
										}
									}
									
									if((err = plugin_stuff.model_funcs.fz_objt_cnstr_line(windex,&arc_start_pt,&arc_end_pt, &line_obj)) == FZRT_NOERR)
									{
										norm.x = 0.0;
										norm.y = 0.0;
										norm.z = 1.0;
										

										err = plugin_stuff.model_funcs.fz_objt_list_create(&obj_list);
										
										if((err = plugin_stuff.model_funcs.fz_objt_edit_split_with_line(windex,final_obj,line_obj,&norm, 0, obj_list )) == FZRT_NOERR)
										{
											plugin_stuff.model_funcs.fz_objt_list_count(obj_list, &n);
											for(i = 0; i < n; i++)
											{
												plugin_stuff.model_funcs.fz_objt_list_get_objt(obj_list, i, &obj);
												
												err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,obj);
												
												if(i == 0)final_obj = obj;
											}
											plugin_stuff.model_funcs.fz_objt_list_delete(&obj_list);
										}
										else err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,final_obj);
										
										while(olist_knt)
										{
											olist_knt--;
											pick_obj = olist[olist_knt];
											n = 0;
											
											err = plugin_stuff.model_funcs.fz_objt_list_create(&obj_list);
											if((err = plugin_stuff.model_funcs.fz_objt_edit_split_with_line(windex,pick_obj,line_obj,&norm, 0, obj_list )) == FZRT_NOERR)
											{
												plugin_stuff.model_funcs.fz_objt_list_count(obj_list, &n);
												for(i = 0; i < n; i++)
												{
													plugin_stuff.model_funcs.fz_objt_list_get_objt(obj_list, i, &obj);
													
													err = plugin_stuff.model_funcs.fz_objt_add_objt_to_project(windex,obj);
												}
												plugin_stuff.model_funcs.fz_objt_list_delete(&obj_list);
											}
										
											if(n)err = plugin_stuff.model_funcs.fz_objt_edit_handle_status_of_opnd(windex,pick_obj,final_obj,TRUE);
										}
										plugin_stuff.model_funcs.fz_objt_edit_delete_objt(windex, line_obj);

									}
								}
							}
						}
					}
				}
			}
		}
		*done = TRUE;
	}

	return (err);
}


/************************************************************************
	tool options name callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_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, FRAME_STR_ID, FRAME_STR_OPTS_TITLE, str);
	strncpy(name, str, max_len);
	
	return (FZRT_NOERR);
}

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

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

/*************************************************************************
	Fuim item callback to copy the tool globals into the
	paramtric object data
**************************************************************************/
static short frame_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;
	frame_otyp_parms_td	*frame;
	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*)&frame);
				
				if( frame_otyp_check_radius(windex,frame->base_obj,_frame_tool_opts->radius,NULL) == TRUE )
				{	frame->radius = _frame_tool_opts->radius;
				}
			}
			rv = TRUE;
		break;
		
		
	}
	return(rv);
}

/************************************************************************
	tool options dialog template callback function for the frame tool command
*************************************************************************/
static fzrt_error_td frame_tool_opts_fuim(fz_fuim_tmpl_ptr fuim_tmpl, fzrt_ptr fuim_data)
{
	short					g1,gindx;
	frame_otyp_parms_td		*frame;
	char					str[256];
	fzrt_error_td			err;
	
	frame = (frame_otyp_parms_td*)_frame_tool_opts;

	plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_OPTS_TITLE, str);
	if((err = plugin_stuff.fuim_funcs.fz_fuim_tmpl_init(fuim_tmpl, str, 0, FRAME_TOOL_OPTS_ID, 0)) == FZRT_NOERR)
	{

		plugin_stuff.fuim_funcs.fz_fuim_objt_parm_result_regen(
				fuim_tmpl,
				FZ_FUIM_ROOT,
				FRAME_OTYP_ID,
				frame_tool_fuim_parm_copy_func,
				NULL,
				&gindx
				);
			
		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_RADIUS, str);
		plugin_stuff.fuim_funcs.fz_fuim_new_text_static_edit(fuim_tmpl,gindx,FZ_FUIM_NONE,str,FZ_FUIM_NONE,FZ_FUIM_FLAG_NONE, NULL, NULL,&g1);			
		plugin_stuff.fuim_funcs.fz_fuim_item_range_double(fuim_tmpl, g1, &frame->radius, 0.0, 0.0, FZ_FUIM_FORMAT_FLOAT_DISTANCE,FZ_FUIM_RANGE_MIN);

		plugin_stuff.fuim_funcs.fz_fuim_disp_res_surf_group(fuim_tmpl,gindx,NULL);

//		tab_group = plugin_stuff.fuim_funcs.fz_fuim_new_tab_group(fuim_tmpl,FZ_FUIM_ROOT,FZ_FUIM_NONE,FZ_FUIM_FLAG_NONE,NULL,NULL);
//		
//		plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_OPTIONS, str);
//		gg = plugin_stuff.fuim_funcs.fz_fuim_new_text_static(fuim_tmpl,tab_group,FZ_FUIM_NONE,FZ_FUIM_FLAG_NONE,str, NULL, NULL);			
//
//			plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_RADIUS, str);
//			plugin_stuff.fuim_funcs.fz_fuim_new_text_static_edit(fuim_tmpl,gg,FZ_FUIM_NONE,str,FZ_FUIM_NONE,FZ_FUIM_FLAG_NONE, NULL, NULL,&g1);			
//			plugin_stuff.fuim_funcs.fz_fuim_item_range_double(fuim_tmpl, g1, &frame->radius, 0.0, 0.0, FZ_FUIM_FORMAT_FLOAT_DISTANCE,FZ_FUIM_RANGE_MIN);
//
//		plugin_stuff.fuim_funcs.fz_fuim_disp_res_surf_group(fuim_tmpl,tab_group,NULL);
//	
//		plugin_stuff.fuim_funcs.fz_fuim_status_of_objt_group(fuim_tmpl,tab_group);
    }
		
	return (err);
}

/*************************************************************************
 tool info2 callback
 *************************************************************************/
static fzrt_boolean frame_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 = 1;		/* PICKING ONE SET */
			plugin_stuff.type_funcs.fz_type_set_int(&value, data);
			break;
			
		default:
			rv = FALSE;
		break;
	}
	
	return(rv);
}

/************************************************************************
 pick set callback
 *************************************************************************/
static fzrt_error_td frame_tool_pick_set(fzrt_int windex, fzrt_int set_id, fzrt_int *set_count_min, fzrt_int *set_count_max, fzrt_int *set_topo_mask, fzrt_int *set_type_count, fzrt_UUID_td *set_type_list, fzrt_int *set_flags)
{
	fzrt_error_td		err = FZRT_NOERR;
	
	*set_type_count = 0;
	
	switch(set_id)
	{
		case 0 : 
			*set_count_min = 3;														/* AT LEAST ONE */
			*set_topo_mask = 0;
			FZ_SETBIT(*set_topo_mask, FZ_OBJT_PICK_LEVEL_SEGT);						/* OBJECTS ONLY */
			
			plugin_stuff.fzrt_base_funcs.fzrt_UUID_copy(FZ_OBJT_DATA_UUID, set_type_list[(*set_type_count)++]);	/* OBJECT CLASS */
		break;
			
	}
	return(err);
}

/*************************************************************************
 Pick valid callback
 *************************************************************************/
static fzrt_error_td frame_tool_pick_valid(
   fzrt_int				windex, 
   fzrt_int				set_id, 
   fzrt_UUID_td		type, 
   fz_tag_td		*item_tag,
   fzrt_UUID_td		part_class, 
   fzrt_int				part_id, 
   fzrt_UUID_td		sub_part_class, 
   fzrt_int				sub_part_id, 
   fzrt_boolean		*valid,
   fz_string_td 	nvalid_reason
   )
{
	fz_objt_ptr					obj;
	
	*valid = FALSE;
	
	/* SOURCE : ALLOW OBJECT TOPOLOGY */
	if( plugin_stuff.fzrt_base_funcs.fzrt_UUID_compare(type,FZ_OBJT_DATA_UUID) == 0 )
	{
		if( plugin_stuff.model_funcs.fz_objt_tag_to_ptr(windex, item_tag, &obj) == FZRT_NOERR)
		{
			*valid = TRUE;
#if 0
			if ( frame_otyp_check_radius(windex,obj,_frame_tool_opts->radius,NULL) == TRUE )
			{
				*valid = TRUE;
			}
			else
			{	/* "One or more segments are shorter than the frame radius" */
				plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_NVALID_PICK, nvalid_reason);
			}
#endif
		}
	}
	
	return(FZRT_NOERR);
}

/************************************************************************
 JSP 10/08/08 : New function
 JSP 11/06/08  : adjusting function
 *************************************************************************/
static fzrt_boolean frame_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 :
			plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_DESC, actn_string);
			rv = TRUE;
		break;
			
		case FZ_TOOL_ACTION_PICK :
			plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_PICK, actn_string);
			rv = TRUE;
		break;
			
		case FZ_TOOL_ACTION_CLICK :
			plugin_stuff.fzrt_base_funcs.fzrt_fzr_get_string(plugin_stuff.fz_rsrc_ref_func, FRAME_STR_ID, FRAME_STR_CLICK, actn_string);
			rv = TRUE;
		break;
		default:
		break;
	}
	return(rv);
}

/************************************************************************
	Fill the tool command function set with the star tool command callback
	functions.
*************************************************************************/
fzrt_error_td frame_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 				*cmds_func;

	err = plugin_stuff.fsf->fzpl_fset_def_check ( fset_def, FZ_TOOL_CBAK_FSET_VERSION, FZPL_TYPE_STRING(fz_tool_cbak_fset), sizeof ( cmds_func ), FZPL_VERSION_OP_NEWER );
	if ( err == FZRT_NOERR )
	{
		cmds_func = (fz_tool_cbak_fset *)fset;
		
		cmds_func->fz_tool_cbak_init					= frame_tool_init;
		cmds_func->fz_tool_cbak_info					= frame_tool_info;
		cmds_func->fz_tool_cbak_name					= frame_tool_name;
		cmds_func->fz_tool_cbak_uuid					= frame_tool_uuid;
		cmds_func->fz_tool_cbak_icon_file				= frame_tool_icon_file;
		cmds_func->fz_tool_cbak_icon_menu_adjacent		= frame_tool_tool_bar_adjacent;
		
		cmds_func->fz_tool_cbak_pref_io					= frame_tool_pref_io;

		cmds_func->fz_tool_cbak_opts_name				= frame_tool_opts_name;
		cmds_func->fz_tool_cbak_opts_uuid				= frame_tool_opts_uuid;
		cmds_func->fz_tool_cbak_opts_iface_tmpl			= frame_tool_opts_fuim;
		cmds_func->fz_tool_cbak_click					= frame_tool_click;
		
		cmds_func->fz_tool_cbak_info2					= frame_tool_info2;
		cmds_func->fz_tool_cbak_pick_set				= frame_tool_pick_set;
		cmds_func->fz_tool_cbak_pick_valid				= frame_tool_pick_valid;
		cmds_func->fz_tool_cbak_action					= frame_tool_action;
		
	}

	return err;
}

/************************************************************************
	Fill the notification function set with the star tool notification callback
	functions.
*************************************************************************/
fzrt_error_td frame_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;

	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		= frame_tool_syst_units;
		notf_func->fz_notf_cbak_pref_default	= frame_tool_pref_default;

	}

	return err;
}

