/*CLASS UFCUST */ /*============================================================================== Copyright (c) 1999 Unigraphics Solutions Inc. Unpublished - All rights reserved ================================================================================ File description: An example UG/Open program is contained in this file demonstrating usage of the following UG/Open interfaces: UF_CURVE_create_trim UF_CURVE_ask_trim UF_CURVE_edit_trim UF_CURVE_free_trim This example program: 1) Creates a part file named "curve_trim". 2) Creates two lines. One to be trimmed and one as the bounding string. It also creates a fixed datum plane for a second bounding object. 3) Creates a trim curve feature that trims the first line to the bounding string. 4) Retrieves the parameters of the trim curve feature. 5) Edits the trim curve feature so that the first line is now trimmed to the bounding string and the fixed datum plane. 6) Frees the information retrieved from the UF_CURVE_ask_trim call. ==============================================================================*/ #include #include #include #include #include #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) { int error,trim_string[1],trim_dir[1],bound_string[1],bound_dir[1]; tag_t lines[3],trim_curve_feat,datum,part_tag; double plane_origin[3],plane_norm[3]; UF_CURVE_line_t line_coords; UF_CURVE_trim_t trim_curve_info,out_trim_curve_info; UF_CURVE_trim_mult_t out_info; char *prtnam = "curve_trim"; UF_CALL( UF_PART_new(prtnam, METRIC, &part_tag) ); /* Create three lines and a datum plane. */ line_coords.start_point[0] = 0.0; line_coords.end_point[0] = 20.0; line_coords.start_point[1] = 0.0; line_coords.end_point[1] = 10.0; line_coords.start_point[2] = 0.0; line_coords.end_point[2] = 0.0; UF_CALL(UF_CURVE_create_line(&line_coords,&lines[0])); line_coords.start_point[0] = 20.0; line_coords.end_point[0] = 30.0; line_coords.start_point[1] = 10.0; line_coords.end_point[1] = 0.0; line_coords.start_point[2] = 0.0; line_coords.end_point[2] = 0.0; UF_CALL(UF_CURVE_create_line(&line_coords,&lines[1])); line_coords.start_point[0] = -5.0; line_coords.end_point[0] = 35.0; line_coords.start_point[1] = 5.0; line_coords.end_point[1] = 5.0; line_coords.start_point[2] = 0.0; line_coords.end_point[2] = 0.0; UF_CALL(UF_CURVE_create_line(&line_coords,&lines[2])); plane_origin[0] = 15.0; plane_origin[1] = 0.0; plane_origin[2] = 0.0; plane_norm[0] = 1.0; plane_norm[1] = 0.0; plane_norm[2] = 0.0; UF_CALL(UF_MODL_create_fixed_dplane(plane_origin,plane_norm,&datum)); /* Fill in arrays to be used in string definition. */ trim_string[0] = 2; trim_dir[0] = 1; /* Fill in trim curve structure information to trim the first line to the second line as a bounding string. */ trim_curve_info.string_to_trim.num = 1; trim_curve_info.string_to_trim.string = trim_string; trim_curve_info.string_to_trim.dir = trim_dir; trim_curve_info.string_to_trim.id = lines; trim_curve_info.spline_extend_opt = UF_CURVE_EXTEND_NATURAL; trim_curve_info.trim_type = UF_CURVE_TRIM_TO_ONE_BOUND; UF_MODL_ask_distance_tolerance(&trim_curve_info.tolerances[0]); UF_MODL_ask_angle_tolerance(&trim_curve_info.tolerances[1]); /* Fill in arrays to be used in bound definition. */ bound_string[0] = 1; bound_dir[0] = 1; /* Fill in bounding information. */ trim_curve_info.trim_to.one_bound.string_trim_extend_end = UF_CURVE_TRIM_EXTEND_START; trim_curve_info.trim_to.one_bound.bound.string.num = 1; trim_curve_info.trim_to.one_bound.bound.string.string = bound_string; trim_curve_info.trim_to.one_bound.bound.string.dir = bound_dir; trim_curve_info.trim_to.one_bound.bound.string.id = &lines[2]; trim_curve_info.trim_to.one_bound.bound.use_suggested = FALSE; trim_curve_info.trim_to.one_bound.view = (UF_MODL_vector_p_t)(void *)0; trim_curve_info.trim_to.one_bound.bound.object = NULL_TAG; trim_curve_info.trim_to.one_bound.trim_bound = TRUE; /* Create the trim curve feature. */ error = UF_CURVE_create_trim(&trim_curve_info, &out_info, &trim_curve_feat); if (error == UF_CURVE_TRIM_MULT_PTS) { printf("Multiple intersections found\n"); /* Use first intersection point as suggested point. */ trim_curve_info.trim_to.one_bound.bound.use_suggested = TRUE; trim_curve_info.trim_to.one_bound.bound.suggested_point[0] = out_info.bound1_pts[0]; trim_curve_info.trim_to.one_bound.bound.suggested_point[1] = out_info.bound1_pts[1]; trim_curve_info.trim_to.one_bound.bound.suggested_point[2] = out_info.bound1_pts[2]; if (out_info.bound1_pts) { UF_free(out_info.bound1_pts); } if (out_info.bound2_pts) { UF_free(out_info.bound2_pts); } UF_CALL(UF_CURVE_create_trim(&trim_curve_info, &out_info, &trim_curve_feat)); } printf("Trim curve feature created\n"); /* Ask the parameters of the trim curve feature just created. */ UF_CALL(UF_CURVE_ask_trim(trim_curve_feat, &out_trim_curve_info)); printf("Trim curve feature parameters retrieved\n"); /* Transfer some of the retrieved parameters to the trim curve information structure. Reset other information in the structure so that the first line will now be trimmed so that the portion of the line outside the bounding string and the datum plane will be trimmed away. */ trim_curve_info.string_to_trim = out_trim_curve_info.string_to_trim; trim_curve_info.trim_type = UF_CURVE_TRIM_TO_TWO_BOUND; trim_curve_info.trim_to.two_bound.string_extend_end = UF_CURVE_TRIM_EXTEND_START; trim_curve_info.trim_to.two_bound.string_trim_option = UF_CURVE_TRIM_OUTSIDE; trim_curve_info.trim_to.two_bound.bound1.string = out_trim_curve_info.trim_to.one_bound.bound.string; trim_curve_info.trim_to.two_bound.bound1.object = NULL_TAG; trim_curve_info.trim_to.two_bound.bound2.string.num = 0; trim_curve_info.trim_to.two_bound.bound2.object = datum; trim_curve_info.trim_to.two_bound.bound2.use_suggested = FALSE; trim_curve_info.trim_to.two_bound.view = (UF_MODL_vector_p_t)(void *)0; trim_curve_info.trim_to.two_bound.trim_bound = TRUE; /* Edit the trim curve feature. */ UF_CALL(UF_CURVE_edit_trim(trim_curve_feat, &trim_curve_info)); /* Update the model. */ UF_CALL(UF_MODL_update()); printf("Trim curve feature edited, and model updated\n"); /* Free the retrieved information. */ UF_CALL(UF_CURVE_free_trim(&out_trim_curve_info)); printf("Trim curve feature information freed, and example completed.\n"); } /*ARGSUSED*/ void ufusr(char *param, int *retcode, int param_len) { if (!UF_CALL(UF_initialize())) { do_ugopen_api(); UF_CALL(UF_terminate()); } } int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); }