# Include <stdio. h>
# Include <uf. h>
# Include <uf_defs.h>
# Include <uf_modl.h>
# Include <uf_part.h>
# Include <uf_curve.h>
# Include <uf_csys.h>
# Include <uf_vec.h>
# Include <uf_ui.h>
# Define UF_CALL (X) (report (_ FILE __, _ LINE __, # X, (X )))
Static int report (char * file, int line, char * call, int irc)
{
If (irc)
{
Char messg [133];
Printf ("% s, line % d: % s \ n", file, line, call );
(UF_get_fail_message (irc, messg ))?
Printf ("returned a % d \ n", irc ):
Printf ("returned error % d: % s \ n", irc, messg );
}
Return (irc );
}
Static void do_ugopen_api (void)
{
Double tol [3] = {0.1, 0.1, 0.1 };
Double value [6], base_point [3];
Double direction_vector [3], draft_direction_vector [3], dot = 1;
Double x_direction [3] = {-1, 0 };
Double step = 1.0;
Char * part_name = "sample ";
Char distance_str [] = {"0.25 "};
Char neg_distance_str [] = {"-0.25 "};
Int units = UF_PART_ENGLISH, num_curves, I;
Int align = 1, end_point = 0, body_type = 0, edge_type;
Tag_t part_tag, arc1_tag, arc2_tag, face_tag,
Sheet_tag, offset_tag, * offset_curves;
Tag_t wcs;
UF_STRING_t guide, spine, input_string;
UF_CURVE_arc_t arc_coords;
Uf_list_p_t edge_list, face_list;
UF_CURVE_offset_data_t offset_data, ask_offset_data;
UF_CURVE_offset_distance_data_t offset_distance1;
/* Open a new part */
UF_CALL (UF_PART_new (part_name, units, & part_tag ));
/* Create 2 arcs for guide strings for ruled surface */
UF_CALL (UF_CSYS_ask_wcs (& wcs ));
UF_CALL (UF_CSYS_ask_matrix_of_object (wcs, & arc_coords.matrix_tag ));
Arc_coords.start_angle = 78.0*(PI/180 );
Arc_coords.end_angle = 101.0*(PI/180 );
Arc_coords.arc_center [0] = 0.5;
Arc_coords.arc_center [1] =-2.4750;
Arc_coords.arc_center [2] = 0.0;
Arc_coords.radius = 2.525;
UF_CALL (UF_CURVE_create_arc (& arc_coords, & arcw.tag ));
Arc_coords.arc_center [0] = 0.5;
Arc_coords.arc_center [1] =-1.9750;
Arc_coords.arc_center [2] = 0.0;
UF_CALL (UF_CURVE_create_arc (& arc_coords, & arc2_tag ));
UF_MODL_create_string_list (2, 2, & guide );
Guide. num = 2;
Guide. string [0] = 1;
Guide. dir [0] = 1;
Guide. id [0] = arcbench tag;
Guide. string [1] = 1;
Guide. dir [1] = 1;
Guide. id [1] = arc2_tag;
Spine. num = 0;
/* Create ruled surface */
UF_CALL (UF_MODL_create_ruled (& guide,
& Spine,
& Align,
Value,
& End_point,
& Body_type,
UF_NULLSIGN,
Tol,
& Sheet_tag ));
UF_MODL_free_string_list (& guide );
/* Get the tag to the face */
UF_CALL (UF_MODL_ask_body_faces (sheet_tag,
& Face_list ));
UF_CALL (UF_MODL_ask_list_item (face_list,
0,
& Face_tag ));
UF_CALL (UF_MODL_delete_list (& face_list ));
/* Get the edges of the face */
UF_CALL (UF_MODL_ask_face_edges (face_tag,
& Edge_list ));
/* Set up a string for the input curves. Find the two linear edges */
/* Opposite the guide strings of the ruled surface to use in the string .*/
UF_MODL_create_string_list (1,8, & input_string );
Input_string.num = 1;
Input_string.string [0] = 4;
Input_string.dir [0] = 1;
Input_string.id [0] = arcbench tag;
Input_string.id [1] = arc2_tag;
Num_curves = 2;
For (I = 0; I <4; I ++)
{
UF_MODL_ask_list_item (edge_list,
I,
& Input_string.id [num_curves]);
UF_MODL_ask_edge_type (input_string.id [num_curves],
& Edge_type );
If (edge_type = UF_MODL_LINEAR_EDGE)
Num_curves ++;
}
UF_MODL_delete_list (& edge_list );
/* Compute the direction vectors of the string */
UF_CALL (UF_CURVE_ask_offset_direction (& input_string,
Direction_vector,
Draft_direction_vector,
Base_point ));
/* Compute the dot product between the direction vector and the + X vector */
/* This will be used later to determine if we will use a positive or
Negative */
/* Offset distance .*/
UF_VEC3_dot (direction_vector,
X_direction,
& Dot );
/* Set up the structures to define a non-associative type of offset */
/* Curve. This will use a distance and have a trim method of fillet .*/
Offset_data.offset_type = UF_CURVE_OFFSET_DISTANCE_FILLET;
Offset_data.input_curves = & input_string;
Offset_data.approximation_tolerance = step;
UF_MODL_ask_distance_tolerance (& offset_data.string_tolerance );
Offset_data.offset_def.distance_type1 = & offset_distance1;
Offset_distance1.distance = distance_str;
If (dot> = 0)
{
Offset_distance1.distance = distance_str;
}
Else
{
Offset_distance1.distance = neg_distance_str;
}
/* Create the offset curves .*/
UF_CALL (UF_CURVE_create_offset_curve (& offset_data,
& Num_curves,
& Offset_curves ));
UF_free (offset_curves );
/* Set up the structures to define an associative type of offset */
/* Curve. This will use a distance and have a trim method */
/* Extended tangents. (Only need to change the type, all other */
/* Parameters were set up previusly .*/
Offset_data.offset_type = UF_CURVE_OFFSET_DISTANCE_TANGENT;
/* Create the offset curve object .*/
UF_CALL (UF_CURVE_create_offset_object (& offset_data,
& Offset_tag ));
/* Get the tags to the output offset curves. These will be used */
/* Input to create the next offset curve object .*/
UF_CALL (UF_CURVE_ask_offset_curves (offset_tag,
& Num_curves,
& Offset_curves ));
/* Modify the input string to pass in the offset curves as input .*/
Input_string.string [0] = num_curves;
For (I = 0; I <num_curves; I ++)
Input_string.id [I] = offset_curves [I];
UF_free (offset_curves );
/* Create the new offset curve object. (This is the way to do */
/* Multiple copies or multiple Applies interactively .)*/
UF_CALL (UF_CURVE_create_offset_object (& offset_data,
& Offset_tag ));
/* Retrieve the parameter information for the last object created .*/
UF_CALL (UF_CURVE_ask_offset_parms (offset_tag,
& Ask_offset_data ));
/* Change the offset type to have no extenstion/trim .*/
Ask_offset_data.offset_type = UF_CURVE_OFFSET_DISTANCE_NO_TRIM;
UF_CALL (UF_CURVE_edit_offset_object (& ask_offset_data,
Offset_tag ));
/* Free underlying structures .*/
UF_CALL (UF_CURVE_free_offset_parms (& ask_offset_data ));
UF_MODL_free_string_list (& input_string );
}
/* ARGSUSED */
Void ufusr (char * param, int * retcode, int paramLen)
{
If (! UF_CALL (UF_initialize ()))
{
Do_ugopen_api ();
UF_CALL (UF_terminate ());
}
}
Int ufusr_ask_unload (void)
{
Return (UF_UNLOAD_IMMEDIATELY );
}
Offset curve code