home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-17 | 50.7 KB | 1,654 lines |
- /* Next available MSG number is 113 */
-
- /************************************************************************
- Name: design.c. AME2_APLIB_SAMP_design.c
-
- Description: AME/API sample program for basic machine elements modelling
-
- Author: AME Group
- Autodesk, Inc.
-
-
-
-
- Copyright (C) 1992 by Autodesk, Inc.
- **************************************************************************
- * *
- * Permission to use, copy, modify, and distribute this software *
- * for any purpose and without fee is hereby granted, provided *
- * that the above copyright notice appears in all copies and that *
- * both that copyright notice and this permission notice appear in *
- * all supporting documentation. *
- * *
- * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
- * WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR *
- * PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED. *
- * *
- * *
- * The objective of this sample program is to illustrate how to *
- * use AME/API as application programming interface for creation and *
- * manipulation of basic mechanical components. Six commands are *
- * available in this program for users to create the geometric *
- * model of basic machine elements such as shaft, wheel, gear, *
- * bearing, bolt and nut. Each part is characterized by design *
- * parameters which link to engineering applications. All components *
- * are created in the world coordinate system. *
- * *
- * "SOLSHAFT" command allows the user to create a standard shaft by *
- * specifying shaft's diameter, length and keyway. The shaft is *
- * positioned along positive Z axis with one end at insertion point. *
- * The keyway is cut from one end of the shaft (near the origin) along *
- * the intersection of XZ plane and cylindrical surface at the *
- * specified depth, width and length. The command syntax and design *
- * parameters associated with the "SOLSHAFT" are shown as follows: *
- * *
- * Command: solshaft *
- * Insertion base point <0,0,0>: *
- * Enter shaft diameter <1.0>: *
- * Enter shaft length <5.0>: *
- * Enter keyway depth <0.3>: *
- * Enter keyway width <0.4>: *
- * Enter keyway length <2.0>: *
- * *
- * *
- * "SOLWHEEL" command allows the user to create a standard flywheel *
- * by specifying flywheel's diameter, thickness, hub, hole and keyway. *
- * The flywheel is created symmetrically about the XY plane with its *
- * central axis along Z axis. The keyway is cut on the hole surface *
- * along XZ plane at the specified depth and width. *
- * *
- * Command: solwheel *
- * Insertion base point <0,0,0>: *
- * Enter wheel diameter <5.0>: *
- * Enter wheel thickness <1.0>: *
- * Enter hub diameter <3.0>: *
- * Enter hub extrusion thickness <0.25>: *
- * Enter shaft hole diameter <1.0>: *
- * Enter keyway depth <0.2>: *
- * Enter keyway width <0.4>: *
- * *
- * *
- * "SOLGEAR" command allows the user to create a standard spur gear *
- * by specifying gear's pitch diameter, number of teeth, thickness, *
- * and pressure angle. The gear is created by extrusion of a 2D *
- * polyline (defined on the XY plane) along positive Z axis. *
- * The involute profile of the teeth are represented by arcs. *
- * *
- * Command: solgear *
- * Insertion base point <0,0,0>: *
- * Enter pitch circle diameter <4.0>: *
- * Enter number of teeth <12>: *
- * Enter gear thickness <1.0>: *
- * Enter pressure angle <25 degrees>: *
- * *
- * *
- * "SOLBEAR" command allows the user to create a standard bearing by *
- * specifying bearing's outer diameter, thickness, height, hole and *
- * base. The bearing is created by extrusion of a 2D polyline *
- * (defined on the XY plane) along positive Z axis. *
- * *
- * Command: solbear *
- * Insertion base point <0,0,0>: *
- * Enter outer diameter <5.0>: *
- * Enter bearing thickness <3.0>: *
- * Enter hole diameter <2.0>: *
- * Enter distance from base to center of hole <5.0>: *
- * Enter base height <1.0>: *
- * Enter base width <6.0>: *
- * *
- * *
- * "SOLBOLT" command allows the user to create a standard bolt by *
- * specifying bolt's head diameter and height, screw diameter and *
- * length. The bolt is positioned along positive Z axis with one of *
- * its end located at insertion point. *
- * *
- * Command: solbolt *
- * Insertion base point <0,0,0>: *
- * Enter head diameter <2.0>: *
- * Enter head height <0.5>: *
- * Enter screw diameter <1.0>: *
- * Enter screw length <5.0>: *
- * *
- * "SOLNUT" command allows the user to create a standard nut by *
- * specifying nut's diameter, height and hole. The nut is positioned *
- * on the XY plane such that its central axis coincides with positive *
- * Z axis. *
- * *
- * Command: solnut *
- * Insertion base point <0,0,0>: *
- * Enter nut diameter <2.0>: *
- * Enter nut height <0.5>: *
- * Enter hole diameter <1.0>: *
- * *
- * *
- * To run the program, You have to xload the executable code "design" *
- * Then enter any of the following command at regular AutoCAD prompt *
- * *
- * command: solshaft *
- * command: solwheel *
- * command: solgear *
- * command: solbear *
- * command: solbolt *
- * command: solnut *
- * *
- **************************************************************************
-
-
- Modification history:
- Refer to the RCS section at the end of this file.
-
- Bugs and restrictions on use:
-
- Notes:
-
- **************************************************************************/
-
-
- /*************************************************************************/
- /* Includes */
- /*************************************************************************/
-
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <adslib.h>
- #include <aplib.h>
-
- /*************************************************************************/
- /* Defines */
- /*************************************************************************/
-
- #define PI 3.14159265358979
- #define EPSILON 1.0e-8
-
- #ifndef ELEMENTS
- #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
- #endif
-
- /*************************************************************************/
- /* Typedefs */
- /*************************************************************************/
-
- /*************************************************************************/
- /* Global variables */
- /*************************************************************************/
-
- /* Function type declaration */
-
- int funcload();
- void print_new_command_set();
- void create_shaft_func();
- ap_Bool get_shaft_data();
- void create_wheel_func();
- ap_Bool get_wheel_data();
- void create_gear_func();
- ap_Bool get_gear_data();
- ap_Bool define_gear_pline();
- void create_bearing_func();
- ap_Bool get_bearing_data();
- void create_bolt_func();
- ap_Bool get_bolt_data();
- ap_Bool define_hexagon_pline();
- void create_nut_func();
- ap_Bool get_nut_data();
- void trans_uc2wc();
-
- /* Command definition and dispatch table. */
-
- struct ads_comm {
- char *cmdname;
- void (*cmdfunc) ();
- };
-
- struct ads_comm cmdtab[] = {
-
- {/*MSG1*/"C:SOLSHAFT", create_shaft_func},
- {/*MSG2*/"C:SOLWHEEL", create_wheel_func},
- {/*MSG3*/"C:SOLGEAR", create_gear_func},
- {/*MSG4*/"C:SOLBEAR", create_bearing_func},
- {/*MSG5*/"C:SOLBOLT", create_bolt_func},
- {/*MSG6*/"C:SOLNUT", create_nut_func},
- };
-
-
- /*************************************************************************/
- /* .doc main() */
- /*+
- -*/
- /*************************************************************************/
-
- void
- /*FCN*/main(argc, argv)
- int argc;
- char *argv[];
- {
- int stat, cindex;
- short scode = 1;
-
- ads_init(argc, argv);
-
- while (TRUE) {
- if ((stat = ads_link(scode)) < 0) {
- printf(/*MSG7*/"DESIGN: bad status from ads_link() = %d\n",
- stat);
- fflush(stdout);
- ads_exit(1);
- }
- scode = -RSRSLT;
-
- switch (stat) {
-
- case RQXLOAD: /* Load & register functions */
- scode = -(funcload() ? RSRSLT : RSERR);
- scode = -RSRSLT;
- print_new_command_set();
- break;
-
- case RQSUBR: /* Evaluate external lisp function */
- cindex = ads_getfuncode();
- (*cmdtab[cindex].cmdfunc) ();
- break;
-
- case RQXUNLD: /* Unloading */
- ads_printf (/*MSG8*/"Unloading: ");
- break;
-
- case RQSAVE: /* AutoCAD SAVE notification */
- break;
-
- case RQQUIT: /* AutoCAD QUIT notification */
- break;
-
- case RQEND: /* AutoCAD END notification */
- break;
-
- default:
- break;
-
- }
-
- }
- }
-
- /*************************************************************************/
- /* .doc funcload() */
- /*+
- Load external functions into AutoCAD system
- -*/
- /*************************************************************************/
-
- static int
- /*FCN*/funcload()
-
- {
- int i;
-
- for (i = 0; i < ELEMENTS(cmdtab); i++) {
- if(! ads_defun (cmdtab[i].cmdname , i))
- return RTERROR;
- }
- return RTNORM;
- }
-
- /*************************************************************************/
- /* .doc print_new_command_set() */
- /*+
- Print new commands on the screen when the program is loaded
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/print_new_command_set()
- {
- ads_printf(/*MSG9*/"\nNew loaded commands:");
- ads_printf(/*MSG10*/"\nSOLSHAFT, SOLWHEEL, SOLGEAR, ");
- ads_printf(/*MSG11*/"SOLBEAR, SOLBOLT, SOLNUT\n");
- }
-
- /*************************************************************************/
- /* .doc create_shaft_func() */
- /*+
- This function executes SOLSHAFT command.
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/create_shaft_func ()
-
- {
- ap_Real shaft_d, shaft_l, key_d, key_w, key_l;
- ap_Real radius, block_l, block_w, block_h, tx, ty, tz;
- ap_Trans3d matrix, mat;
- ap_Objid Block, Cyl, Shaft;
- int stat;
-
- /* Initialize API */
-
- stat = ap_init();
- if (stat != AP_NORMAL)
- goto Error;
-
- /* Prompt user for shaft data */
-
- stat = get_shaft_data(&shaft_d, &shaft_l, &key_d, &key_w, &key_l, mat);
- if (stat == FALSE)
- goto Error;
-
- /* Create a cylindrical shaft with specified size */
-
- radius = shaft_d / 2.0;
- stat = ap_cylinder (radius, radius, shaft_l, &Cyl);
-
- /* Verify whether cylinder has been created successfully */
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG12*/"\nUnable to create cylinder.");
- goto Error;
- }
-
- /* Create a block of keyway size */
-
- block_l = 2.0 * key_d;
- block_w = key_w;
- block_h = 2.0 * key_l;
- stat = ap_box (block_l, block_w, block_h, &Block);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG13*/"\nUnable to create a box.");
- goto Error;
- }
-
- /* Setup translation matrix */
-
- tx = radius - key_d;
- ty = - key_w / 2.0;
- tz = - key_l;
- ap_translate (tx, ty, tz, matrix);
-
- /* Move Block to proper position */
-
- ap_move_obj (Block, matrix, TRUE);
-
- /* Subtract Block from Cylinder to create a keyway */
-
- stat = ap_subtract (Cyl, Block, &Shaft);
-
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG14*/"\nUnable to subtract solid.\n");
- goto Error;
- }
-
- /* Move shaft to UCS */
-
- ap_move_obj (Shaft, mat, FALSE);
-
- /* Display the shaft on the screen */
-
- ap_post_obj (Shaft, AP_POSTWIRE);
-
- Error:
- ads_retvoid();
- return;
- }
-
- /*************************************************************************/
- /* .doc get_shaft_data() */
- /*+
- This routine prompts the user to enter shaft data.
- -*/
- /*************************************************************************/
- static ap_Bool
- /*FCN*/get_shaft_data (dia, len, keyd, keyw, keyl, mat)
- ads_real *dia, *len, *keyd, *keyw, *keyl;
- ap_Trans3d mat;
- {
- int stat;
- ads_real temp, keyw_max;
- ads_point pt, pd;
- ap_Trans3d mat1, mat2;
-
- /* Initialization of shaft data for default input */
-
- pt[X] = 0.0;
- pt[Y] = 0.0;
- pt[Z] = 0.0;
- *dia = 1.0;
- *len = 5.0;
- *keyd = 0.3;
- *keyw = 0.4;
- *keyl = 2.0;
-
-
- /* Acquire values of design parameters associated with shaft
- from the user and verify the validity of input data */
-
- stat = ads_getpoint (NULL, /*MSG15*/"\nInsertion base point <0,0,0>: ", pt);
- if (stat == RTCAN) {
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG16*/"\nEnter shaft diameter <1.0>: ", dia);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*dia <= 0.0) {
- ads_printf(/*MSG17*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG18*/"\nEnter shaft length <5.0>: ", len);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*len <= 0.0) {
- ads_printf(/*MSG19*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG20*/"\nEnter keyway depth <0.3>: ", keyd);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*keyd <= 0.0) {
- ads_printf(/*MSG21*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*keyd >= *dia) {
- ads_printf(/*MSG22*/"\nValue must be less than shaft's diameter.");
- return FALSE;
- }
-
- temp = (*dia)*(*keyd) - (*keyd)*(*keyd);
- keyw_max = 2.0 * sqrt(temp);
- stat = ads_getreal (/*MSG23*/"\nEnter keyway width <0.4>: ", keyw);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*keyw <= 0.0) {
- ads_printf(/*MSG24*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*keyw >= keyw_max) {
- ads_printf(/*MSG25*/"\nValue must be less than %f.", keyw_max);
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG26*/"\nEnter keyway length <2.0>: ", keyl);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*keyl <= 0.0) {
- ads_printf(/*MSG27*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*keyl >= *len) {
- ads_printf(/*MSG28*/"\nValue must be less than shaft's length.");
- return FALSE;
- }
-
- stat = ap_get_ucsmat(mat1);
- if (stat != AP_NORMAL)
- return FALSE;
- trans_uc2wc(pt, TRUE, pd);
- stat = ap_translate (pd[X], pd[Y], pd[Z], mat2);
- if (stat != AP_NORMAL)
- return FALSE;
- stat = ap_compose(mat2, mat1, mat);
- if (stat != AP_NORMAL)
- return FALSE;
-
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc create_wheel_func() */
- /*+
- This function executes SOLWHEEL command.
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/create_wheel_func ()
- {
- ap_Real wheel_d, wheel_b, hub_d, hub_t, hole_d, key_d, key_w;
- ap_Real radius, block_l, block_w, block_b, tx, ty, tz;
- ap_Real hub_b, hole_b;
- ap_Trans3d matrix, mat;
- ap_Objid Block, Cyl[3], Temp1, Temp2, Hole, Wheel;
- int stat;
-
- /* Initialize API */
-
- stat = ap_init();
- if (stat != AP_NORMAL)
- goto Error;
-
- /* Prompt user for wheel data */
-
- stat = get_wheel_data(&wheel_d, &wheel_b, &hub_d, &hub_t,
- &hole_d, &key_d, &key_w, mat);
- if (stat == FALSE)
- goto Error;
-
- /* Create a cylindrical wheel of specified size */
-
- radius = wheel_d / 2.0;
- stat = ap_cylinder (radius, radius, wheel_b, &Cyl[0]);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG29*/"\nUnable to create solid.\n");
- goto Error;
- }
-
- /* Move the cylinder down along z-axis and
- make it symmetric with respect to xy-plane */
-
- tx = 0.0;
- ty = 0.0;
- tz = - wheel_b / 2.0;
- ap_translate (tx, ty, tz, matrix);
- ap_move_obj (Cyl[0], matrix, TRUE);
-
- /* Create a cylindrical hub of specified size */
-
- radius = hub_d / 2.0;
- hub_b = wheel_b + 2.0 * hub_t;
- stat = ap_cylinder (radius, radius, hub_b, &Cyl[1]);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG30*/"\nUnable to create cylinder.\n");
- goto Error;
- }
-
- /* Move the cylinder down along z-axis and
- make it symmetric with respect to xy-plane */
-
- tx = 0.0;
- ty = 0.0;
- tz = - hub_b / 2.0;
- ap_translate (tx, ty, tz, matrix);
- ap_move_obj (Cyl[1], matrix, TRUE);
-
- /* Define a NULL solid to terminate array Cyl[] */
-
- Cyl[2] = (ap_Objid) NULL;
-
- /* Join wheel stored in Cyl[0]) and hub stored in Cyl[1] together */
-
- stat = ap_union (Cyl, &Temp1);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG31*/"\nUnable to perform union on solids.\n");
- goto Error;
- }
-
- /* Create a cylinder of the same size as the hole */
-
- radius = hole_d / 2.0;
- hole_b = 2.0 * hub_b;
- stat = ap_cylinder (radius, radius, hole_b, &Hole);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG32*/"\nUnable to create cylinder.\n");
- goto Error;
- }
-
- /* Move the cylinder down along z-axis and
- make it symmetric with respect to xy-plane */
-
- tx = 0.0;
- ty = 0.0;
- tz = - hole_b / 2.0;
- ap_translate (tx, ty, tz, matrix);
- ap_move_obj (Hole, matrix, TRUE);
-
- /* Subtract cylinder from wheel to produce a hole */
-
- stat = ap_subtract (Temp1, Hole, &Temp2);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG33*/"\nUnable to subtract solids.\n");
- goto Error;
- }
-
- /* Create a block of keyway size */
-
- block_l = (hole_d/2.0) + key_d;
- block_w = key_w;
- block_b = 2.0 * hub_b;
- stat = ap_box (block_l, block_w, block_b, &Block);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG34*/"\nUnable to create solid.\n");
- goto Error;
- }
-
- /* Move the block to proper position */
-
- tx = 0.0;
- ty = - key_w / 2.0;
- tz = - hub_b;
- ap_translate (tx, ty, tz, matrix);
- ap_move_obj (Block, matrix, TRUE);
-
- /* Subtract block from wheel to produce a keyway */
-
- stat = ap_subtract (Temp2, Block, &Wheel);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG35*/"\nUnable to subtract solids.\n");
- goto Error;
- }
-
- /* Move wheel to UCS */
-
- ap_move_obj (Wheel, mat, FALSE);
-
- /* Display the wheel on the screen */
-
- ap_post_obj (Wheel, AP_POSTWIRE);
-
- Error:
- ads_retvoid();
- return;
- }
-
- /*************************************************************************/
- /* .doc get_wheel_data() */
- /*+
- This routine prompts the user to enter wheel data.
- -*/
- /*************************************************************************/
- static ap_Bool
- /*FCN*/get_wheel_data (wheeld, wheelb, hubd, hubt, holed, keyd, keyw, mat)
- ads_real *wheeld, *wheelb, *hubd, *hubt, *holed, *keyd, *keyw;
- ap_Trans3d mat;
- {
- int stat;
- ads_real keyw_max, temp1, temp2;
- ads_point pt, pd;
- ap_Trans3d mat1, mat2;
-
- /* Initialization of wheel data for default input */
-
- pt[X] = 0.0;
- pt[Y] = 0.0;
- pt[Z] = 0.0;
- *wheeld = 5.0;
- *wheelb = 1.0;
- *hubd = 3.0;
- *hubt = 0.25;
- *holed = 1.0;
- *keyd = 0.2;
- *keyw = 0.4;
-
- /* Acquire values of design parameters associated with wheel
- from the user and verify the validity of input data */
-
- stat = ads_getpoint (NULL, /*MSG36*/"\nInsertion base point <0,0,0>: ", pt);
- if (stat == RTCAN) {
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG37*/"\nEnter wheel diameter <5.0>: ", wheeld);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*wheeld <= 0.0) { /* verify positive value */
- ads_printf(/*MSG38*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG39*/"\nEnter wheel thickness <1.0>: ", wheelb);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*wheelb <= 0.0) {
- ads_printf(/*MSG40*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG41*/"\nEnter hub diameter <3.0>: ", hubd);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*hubd <= 0.0) {
- ads_printf(/*MSG42*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*hubd >= *wheeld) {
- ads_printf(/*MSG43*/"\nValue must be less than wheel's diameter.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG44*/"\nEnter hub extrusion thickness <0.25>: ", hubt);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*hubt <= 0.0) {
- ads_printf(/*MSG45*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*hubt >= *wheeld) {
- ads_printf(/*MSG46*/"\nValue must be less than wheel's diameter.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG47*/"\nEnter hole diameter <1.0>: ", holed);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*holed <= 0.0) {
- ads_printf(/*MSG48*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*holed >= *hubd) {
- ads_printf(/*MSG49*/"\nValue must be less than hub's diameter.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG50*/"\nEnter keyway depth <0.2>: ", keyd);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*keyd <= 0.0) {
- ads_printf(/*MSG51*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*keyd >= (*hubd-*holed)/2.0) {
- ads_printf
- (/*MSG52*/"\nValue must be less than hub's radius minus hole's radius.");
- return FALSE;
- }
-
- temp1 = (*holed/2.0) + (*keyd);
- temp2 = (*hubd/2.0)*(*hubd/2.0) - (temp1)*(temp1);
- keyw_max = 2.0 * sqrt(temp2);
- stat = ads_getreal (/*MSG53*/"\nEnter keyway width <0.4>: ", keyw);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*keyw <= 0.0) {
- ads_printf(/*MSG54*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*keyw > *holed) {
- ads_printf(/*MSG55*/"\nValue must be less than hole's diameter.");
- return FALSE;
- } else if (*keyw >= keyw_max) {
- ads_printf(/*MSG56*/"\nValue must be less than %f.", keyw_max);
- return FALSE;
- }
-
- stat = ap_get_ucsmat(mat1);
- if (stat != AP_NORMAL)
- return FALSE;
- trans_uc2wc(pt, TRUE, pd);
- stat = ap_translate (pd[X], pd[Y], pd[Z], mat2);
- if (stat != AP_NORMAL)
- return FALSE;
- stat = ap_compose(mat2, mat1, mat);
- if (stat != AP_NORMAL)
- return FALSE;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc create_gear_func() */
- /*+
- This function executes SOLGEAR command.
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/create_gear_func ()
- {
- ap_Real gear_d, gear_b, alpha;
- int number_t, np, stat;
- ap_Objid Gear;
- ap_Swp_pts pts[501];
- ap_Trans3d mat;
-
-
- /* Initialize API */
-
- stat = ap_init();
- if (stat != AP_NORMAL)
- goto Error;
-
- /* Prompt user for gear data */
-
- stat = get_gear_data(&gear_d, &gear_b, &number_t, &alpha, mat);
- if (stat == FALSE)
- goto Error;
-
- stat = define_gear_pline(gear_d, number_t, alpha, pts, &np);
- if (stat == FALSE)
- goto Error;
-
- ads_printf (/*MSG57*/"\n\nWorking...");
-
- /* Extrude gear profile to obtain 3D gear model */
-
- stat = ap_extrude_pline(np, pts, gear_b, 0.0, &Gear);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG58*/"\nUnable to generate extruded solids.\n");
- goto Error;
- }
-
- /* Move gear to UCS */
-
- ap_move_obj (Gear, mat, FALSE);
-
- /* Display gear on the screen */
-
- ap_post_obj (Gear, AP_POSTWIRE);
-
- Error:
- ads_retvoid();
- return;
- }
-
- /*************************************************************************/
- /* .doc get_gear_data() */
- /*+
- This routine prompts the user to enter gear data.
- -*/
- /*************************************************************************/
- static ap_Bool
- /*FCN*/get_gear_data (dia, thick, nteeth, pangle, mat)
- ads_real *dia, *thick, *pangle;
- int *nteeth;
- ap_Trans3d mat;
- {
- int stat;
- ads_point pt, pd;
- ap_Trans3d mat1, mat2;
-
- /* Initialization of gear data for default input */
-
- pt[X] = 0.0;
- pt[Y] = 0.0;
- pt[Z] = 0.0;
- *dia = 4.0;
- *thick = 1.0;
- *nteeth = 12;
- *pangle = 25.0;
-
- /* Acquire values of design parameters associated with gear
- from the user and verify the validity of input data */
-
- stat = ads_getpoint (NULL, /*MSG59*/"\nInsertion base point <0,0,0>: ", pt);
- if (stat == RTCAN) {
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG60*/"\nEnter pitch circle diameter <4.0>: ", dia);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*dia <= 0.0) {
- ads_printf(/*MSG61*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getint (/*MSG62*/"\nEnter number of teeth <12>: ", nteeth);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*nteeth <= 3) {
- ads_printf(/*MSG63*/"\nCan not handle less than 4 teeth.");
- return FALSE;
- } else if (*nteeth >= 37) {
- ads_printf(/*MSG64*/"\nCan not handle more than 36 teeth.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG65*/"\nEnter gear thickness <1.0>: ", thick);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*thick <= 0.0) {
- ads_printf(/*MSG66*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG67*/"\nEnter pressure angle <25 degrees>: ", pangle);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*pangle < 14.5) {
- ads_printf
- (/*MSG68*/"\nAngle must be greater or equal to 14.5 degrees.");
- return FALSE;
- } else if (*pangle > 25.0) {
- ads_printf(/*MSG69*/"\nAngle must be less or equal to 25 degrees.");
- return FALSE;
- }
-
- stat = ap_get_ucsmat(mat1);
- if (stat != AP_NORMAL)
- return FALSE;
- trans_uc2wc(pt, TRUE, pd);
- stat = ap_translate (pd[X], pd[Y], pd[Z], mat2);
- if (stat != AP_NORMAL)
- return FALSE;
- stat = ap_compose(mat2, mat1, mat);
- if (stat != AP_NORMAL)
- return FALSE;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc define_gear_pline() */
- /*+
- This routine computes the gear profile based on the input
- arguments gear_d (pitch diameter), number_t (number of teeth)
- and alpha (pressure angle). It returns a polyline vertex array pts
- and the total number of vertices npoint contained in the polyline.
- The routine first generates an involute tooth, then rotates and
- copies the tooth to obtain a complete gear profile. The gear
- profile is defined in the xy plane and centered at the origin.
- -*/
- /*************************************************************************/
-
- static ap_Bool
- /*FCN*/define_gear_pline (gear_d, number_t, alpha, pts, npoint)
- ap_Real gear_d, alpha;
- ap_Swp_pts pts[];
- int number_t, *npoint;
- {
- ap_Real angle_a, angle_b, angle_c, angle_d, angle_e, angle_f;
- ap_Real angle_h, angle_i, angle_j, angle_k;
- ap_Real angle_rot, cos_rot, sin_rot, omega, phi, temp;
- ap_Real rad_pitch, rad_base, rad_adden, rad_deden;
- int i, j, k, nt;
-
- if((gear_d <= 0.0) || (number_t <= 2))
- return FALSE;
-
- nt = 10 * number_t + 1;
- phi = alpha * PI / 180;
-
- /* Define radius for pitch circle */
-
- rad_pitch = gear_d / 2;
-
- /* Define radius for base circle */
-
- rad_base = rad_pitch * cos (phi);
-
- /* Define radius for addendum circle */
-
- rad_adden = rad_pitch + gear_d / number_t;
-
- /* Define radius for dedendum circle */
-
- rad_deden = rad_pitch - 1.25 * gear_d / number_t;
-
- if (rad_deden > rad_base)
- rad_deden = 0.99 * rad_base;
- temp = rad_adden * rad_adden / (rad_base * rad_base) - 1;
- omega = sqrt (temp);
-
- /* Define angles for construction of the tooth profile */
-
- angle_i = PI/ (2 * number_t);
- angle_j = angle_i + tan (phi) - phi;
- angle_k = angle_j;
- angle_h = angle_j - omega + atan (omega);
- angle_a = angle_j - 2 * PI / number_t;
- angle_b = (angle_a - angle_j) / 2;
- angle_c = - angle_k;
- angle_d = - angle_j;
- angle_e = - angle_i;
- angle_f = - angle_h;
-
- /* Define the coordinates of the polyline vertices
- for one tooth profile consisting of line
- and arc segments */
-
- pts[0].x = rad_deden * cos (angle_a);
- pts[0].y = rad_deden * sin (angle_a);
- pts[0].type = AP_PT_LINE;
-
- pts[1].x = rad_deden * cos (angle_b);
- pts[1].y = rad_deden * sin (angle_b);
- pts[1].type = AP_PT_LINE;
-
- pts[2].x = rad_deden * cos (angle_c);
- pts[2].y = rad_deden * sin (angle_c);
- pts[2].type = AP_PT_ARCEND;
-
- pts[3].x = rad_base * cos (angle_d);
- pts[3].y = rad_base * sin (angle_d);
- pts[3].type = AP_PT_LINE;
-
- pts[4].x = rad_pitch * cos (angle_e);
- pts[4].y = rad_pitch * sin (angle_e);
- pts[4].type = AP_PT_LINE;
-
- pts[5].x = rad_adden * cos (angle_f);
- pts[5].y = rad_adden * sin (angle_f);
- pts[5].type = AP_PT_ARCEND;
-
- pts[6].x = rad_adden;
- pts[6].y = 0.0;
- pts[6].type = AP_PT_LINE;
-
- pts[7].x = pts[5].x;
- pts[7].y = -pts[5].y;
- pts[7].type = AP_PT_ARCEND;
-
- pts[8].x = pts[4].x;
- pts[8].y = -pts[4].y;
- pts[8].type = AP_PT_LINE;
-
- pts[9].x = pts[3].x;
- pts[9].y = -pts[3].y;
- pts[9].type = AP_PT_ARCEND;
-
- pts[10].x = pts[2].x;
- pts[10].y = -pts[2].y;
- pts[10].type = AP_PT_LINE;
-
- /* Rotate and copy one tooth profile to obtain
- a complete gear profile */
-
- for (i=1; i<number_t; i++) {
- angle_rot = i * 2 * PI / number_t;
- cos_rot = cos (angle_rot);
- sin_rot = sin (angle_rot);
-
- for (j=1; j<11; j++) {
- k = 10 * i + j;
- pts[k].x = cos_rot * pts[j].x - sin_rot * pts[j].y;
- pts[k].y = sin_rot * pts[j].x + cos_rot * pts[j].y;
- pts[k].type = pts[j].type;
- }
- }
-
- pts[nt-1].x = pts[0].x;
- pts[nt-1].y = pts[0].y;
- pts[nt-1].type = pts[0].type;
-
- *npoint = nt;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc create_bearing_func() */
- /*+
- This function executes SOLBEAR command.
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/create_bearing_func ()
- {
- ap_Real bear_d, bear_b, hole_d, hole_h, base_h, base_w;
- ap_Real radius, tx, ty, tz;
- ap_Trans3d matrix, mat;
- ap_Objid Temp, Hole, Bear;
- ap_Swp_pts pts[10];
- int np, stat;
-
-
- /* Initialize API */
-
- stat = ap_init();
- if (stat != AP_NORMAL)
- goto Error;
-
- /* Prompt user for bearing data */
-
- stat = get_bearing_data(&bear_d, &bear_b, &hole_d, &hole_h,
- &base_h, &base_w, mat);
- if (stat == FALSE)
- goto Error;
-
- /* Define a 2D sectional profile for extrusion */
-
- np = 10;
- pts[0].x = base_w / 2.0;
- pts[0].y = 0.0;
- pts[0].type = AP_PT_LINE;
-
- pts[1].x = base_w / 2.0;
- pts[1].y = base_h;
- pts[1].type = AP_PT_LINE;
-
- radius = bear_d / 2.0;
- pts[3].x = radius * sin (PI/6.0);
- pts[3].y = hole_h - radius * cos (PI/6.0);
- pts[3].type = AP_PT_LINE;
-
- pts[2].x = pts[3].x;
- pts[2].y = pts[1].y;
- pts[2].type = AP_PT_LINE;
-
- pts[4].x = 0.0;
- pts[4].y = hole_h + radius;
- pts[4].type = AP_PT_LINE;
-
- pts[5].x = - pts[3].x;
- pts[5].y = pts[3].y;
- pts[5].type = AP_PT_ARCEND;
-
- pts[6].x = pts[5].x;
- pts[6].y = base_h;
- pts[6].type = AP_PT_LINE;
-
- pts[7].x = - base_w / 2.0;
- pts[7].y = base_h;
- pts[7].type = AP_PT_LINE;
-
- pts[8].x = - base_w / 2.0;
- pts[8].y = 0.0;
- pts[8].type = AP_PT_LINE;
-
- pts[9].x = pts[0].x;
- pts[9].y = pts[0].y;
- pts[9].type = AP_PT_LINE;
-
- /* Extrude 2D sectional profile to create 3D bearing */
-
- stat = ap_extrude_pline(np, pts, bear_b, 0.0, &Temp);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG70*/"\nUnable to generate extruded solid.\n");
- goto Error;
- }
-
- /* Create a cylinder tool to drill the hole */
-
- radius = hole_d / 2.0;
- stat = ap_cylinder (radius, radius, bear_b, &Hole);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG71*/"\nUnable to create a cylinder.\n");
- goto Error;
- }
-
- /* Move cylinder to proper position */
-
- tx = 0.0;
- ty = hole_h;
- tz = 0.0;
- ap_translate (tx, ty, tz, matrix);
- ap_move_obj (Hole, matrix, TRUE);
-
- /* Subtract cylinder from bearing to create a hole
- for houseing shaft */
-
- stat = ap_subtract (Temp, Hole, &Bear);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG72*/"\nUnable to subtract solids.\n");
- goto Error;
- }
-
- /* Move bearing to UCS */
-
- ap_move_obj (Bear, mat, FALSE);
-
- /* Display the bearing on the screen */
-
- ap_post_obj (Bear, AP_POSTWIRE);
-
- Error:
- ads_retvoid();
- return;
- }
-
- /*************************************************************************/
- /* .doc get_bearing_data() */
- /*+
- This routine prompts the user to enter bearing data.
- -*/
- /*************************************************************************/
- static ap_Bool
- /*FCN*/get_bearing_data (beard, bearb, holed, holeh, baseh, basew,mat)
- ads_real *beard, *bearb, *holed, *holeh, *baseh, *basew;
- ap_Trans3d mat;
- {
- int stat;
- ads_real baseh_max, basew_min;
- ads_point pt, pd;
- ap_Trans3d mat1, mat2;
-
- /* Initialization of bearing data for default input */
-
- pt[X] = 0.0;
- pt[Y] = 0.0;
- pt[Z] = 0.0;
- *beard = 5.0;
- *bearb = 3.0;
- *holed = 2.0;
- *holeh = 5.0;
- *baseh = 1.0;
- *basew = 6.0;
-
- /* Acquire values of design parameters associated with bearing
- from the user and verify the validity of input data */
-
- stat = ads_getpoint (NULL, /*MSG73*/"\nInsertion base point <0,0,0>: ", pt);
- if (stat == RTCAN) {
- return FALSE;
- }
- stat = ads_getreal (/*MSG74*/"\nEnter bearing diameter <5.0>: ", beard);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*beard <= 0.0) {
- ads_printf(/*MSG75*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG76*/"\nEnter bearing thickness <3.0>: ", bearb);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*bearb <= 0.0) {
- ads_printf(/*MSG77*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG78*/"\nEnter hole diameter <2.0>: ", holed);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*holed <= 0.0) {
- ads_printf(/*MSG79*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*holed >= *beard) {
- ads_printf(/*MSG80*/"\nHole diameter must be less than bearing diameter.");
- return FALSE;
- }
-
- stat = ads_getreal
- (/*MSG81*/"\nEnter distance from base to center of hole <5.0>: ", holeh);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*holeh <= (*beard/2.0)) {
- ads_printf(/*MSG82*/"\nValue must be greater than bearing's radius.");
- return FALSE;
- }
-
- baseh_max = *holeh - (*beard/2.0) * cos(PI/6.0);
- stat = ads_getreal (/*MSG83*/"\nEnter base height <1.0>: ", baseh);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*baseh <= 0.0) {
- ads_printf(/*MSG84*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*baseh >= baseh_max) {
- ads_printf(/*MSG85*/"\nValue must be less than %f.", baseh_max);
- return FALSE;
- }
-
- basew_min = (*beard) * sin(PI/6.0);
- stat = ads_getreal (/*MSG86*/"\nEnter base width <6.0>: ", basew);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*basew <= basew_min) {
- ads_printf(/*MSG87*/"\nValue must be greater than %f.", basew_min);
- return FALSE;
- }
-
- stat = ap_get_ucsmat(mat1);
- if (stat != AP_NORMAL)
- return FALSE;
- trans_uc2wc(pt, TRUE, pd);
- stat = ap_translate (pd[X], pd[Y], pd[Z], mat2);
- if (stat != AP_NORMAL)
- return FALSE;
- stat = ap_compose(mat2, mat1, mat);
- if (stat != AP_NORMAL)
- return FALSE;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc create_bolt_func() */
- /*+
- This function executes SOLBOLT command.
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/create_bolt_func ()
- {
- ap_Real head_d, head_h, screw_d, screw_h;
- ap_Real radius, length;
- ap_Objid Temp[3], Bolt;
- ap_Swp_pts pts[10];
- ap_Trans3d mat;
- int np, stat;
-
-
- /* Initialize API */
-
- stat = ap_init();
- if (stat != AP_NORMAL)
- goto Error;
-
- /* Prompt user for bolt data */
-
- stat = get_bolt_data(&head_d, &head_h, &screw_d, &screw_h, mat);
- if (stat == FALSE)
- goto Error;
-
- /* Define a 2D six-sided polygon profile */
-
- radius = head_d / 2;
- define_hexagon_pline(radius, pts, &np);
-
- /* Extrude the profile to create bolt's head */
-
- stat = ap_extrude_pline(np, pts, head_h, 0.0, &Temp[0]);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG88*/"\nUnable to generate extruded solid.\n");
- goto Error;
- }
-
- /* Create a cylinder of the same size as bolt's shank */
-
- radius = screw_d / 2.0;
- length = screw_h + head_h;
- stat = ap_cylinder (radius, radius, length, &Temp[1]);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG89*/"\nUnable to create cylinder.\n");
- goto Error;
- }
-
- /* Define a NULL solid to terminate Temp[] array */
-
- Temp[2] = (ap_Objid)NULL;
-
- stat = ap_union (Temp, &Bolt);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG90*/"\nUnable to perform union on solids.\n");
- goto Error;
- }
-
- /* Move bolt to UCS */
-
- ap_move_obj (Bolt, mat, FALSE);
-
- /* Display the bolt on the screen */
-
- ap_post_obj (Bolt, AP_POSTWIRE);
-
- Error:
- ads_retvoid();
- return;
- }
-
- /*************************************************************************/
- /* .doc get_bolt_data() */
- /*+
- This routine prompts the user to enter bolt data.
- -*/
- /*************************************************************************/
- static ap_Bool
- /*FCN*/get_bolt_data (headd, headh, screwd, screwh, mat)
- ads_real *headd, *headh, *screwd, *screwh;
- ap_Trans3d mat;
- {
- int stat;
- ads_real screwd_max;
- ads_point pt, pd;
- ap_Trans3d mat1, mat2;
-
- /* Initialization of wheel data for default input */
-
- pt[X] = 0.0;
- pt[Y] = 0.0;
- pt[Z] = 0.0;
- *headd = 2.0;
- *headh = 0.5;
- *screwd = 1.0;
- *screwh = 5.0;
-
- /* Acquire values of design parameters associated with bolt
- from the user and verify the validity of input data */
-
- stat = ads_getpoint (NULL, /*MSG91*/"\nInsertion base point <0,0,0>: ", pt);
- if (stat == RTCAN) {
- return FALSE;
- }
- stat = ads_getreal (/*MSG92*/"\nEnter head diameter <2.0>: ", headd);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*headd <= 0.0) {
- ads_printf(/*MSG93*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG94*/"\nEnter head height <0.5>: ", headh);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*headh <= 0.0) {
- ads_printf(/*MSG95*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- screwd_max = (*headd) * sin(60.0*PI/180.0);
- stat = ads_getreal (/*MSG96*/"\nEnter screw diameter <1.0>: ", screwd);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*screwd <= 0.0) {
- ads_printf(/*MSG97*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*screwd >= screwd_max) {
- ads_printf(/*MSG98*/"\nValue must be less than %f.", screwd_max);
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG99*/"\nEnter screw length <5.0>: ", screwh);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*screwh <= 0.0) {
- ads_printf(/*MSG100*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ap_get_ucsmat(mat1);
- if (stat != AP_NORMAL)
- return FALSE;
- trans_uc2wc(pt, TRUE, pd);
- stat = ap_translate (pd[X], pd[Y], pd[Z], mat2);
- if (stat != AP_NORMAL)
- return FALSE;
- stat = ap_compose(mat2, mat1, mat);
- if (stat != AP_NORMAL)
- return FALSE;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc define_hexagon_pline() */
- /*+
- This routine defines a regular six sides polygon.
- The polygon locates on xy plane and inscribes to a circle
- of specified radius and centered at the origin.
- -*/
- /*************************************************************************/
-
- static ap_Bool
- /*FCN*/define_hexagon_pline (rad, pts, np)
- ap_Swp_pts pts[];
- ads_real rad;
- int *np;
- {
- rad = fabs(rad);
- if (rad < EPSILON) {
- ads_printf(/*MSG101*/"\nThe radius is too small.");
- return FALSE;
- }
- pts[0].x = rad;
- pts[0].y = 0.0;
- pts[0].type = AP_PT_LINE;
-
- pts[1].x = rad * cos (PI/3);
- pts[1].y = rad * sin (PI/3);
- pts[1].type = AP_PT_LINE;
-
- pts[2].x = rad * cos (2*PI/3);
- pts[2].y = rad * sin (2*PI/3);
- pts[2].type = AP_PT_LINE;
-
- pts[3].x = rad * cos (PI);
- pts[3].y = rad * sin (PI);
- pts[3].type = AP_PT_LINE;
-
- pts[4].x = rad * cos (4*PI/3);
- pts[4].y = rad * sin (4*PI/3);
- pts[4].type = AP_PT_LINE;
-
- pts[5].x = rad * cos (5*PI/3);
- pts[5].y = rad * sin (5*PI/3);
- pts[5].type = AP_PT_LINE;
-
- pts[6].x = pts[0].x;
- pts[6].y = pts[0].y;
- pts[6].type = AP_PT_LINE;
-
- *np = 7;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc create_nut_func() */
- /*+
- This function executes SOLNUT command.
- -*/
- /*************************************************************************/
-
- static void
- /*FCN*/create_nut_func ()
- {
- ap_Real nut_d, nut_h, hole_d;
- ap_Real radius;
- ap_Objid Temp1, Temp2, Nut;
- ap_Swp_pts pts[10];
- ap_Trans3d mat;
- int np, stat;
-
-
- /* Initialize API */
-
- stat = ap_init();
- if (stat != AP_NORMAL)
- goto Error;
-
- /* Prompt user for nut data */
-
- stat = get_nut_data(&nut_d, &nut_h, &hole_d, mat);
- if (stat == FALSE)
- goto Error;
-
- /* Define a 2D six-sided polygon profile */
-
- radius = nut_d / 2;
- define_hexagon_pline(radius, pts, &np);
-
- /* Extrude the profile to create a nut */
-
- stat = ap_extrude_pline(np, pts, nut_h, 0.0, &Temp1);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG102*/"\nUnable to generate extruded solids.\n");
- goto Error;
- }
-
- /* Create a cylinder of the same size as the hole */
-
- radius = hole_d / 2.0;
- stat = ap_cylinder (radius, radius, nut_h, &Temp2);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG103*/"\nUnable to create solid.\n");
- goto Error;
- }
-
- /* Subtract cylinder from nut to produce a hole */
-
- stat = ap_subtract (Temp1, Temp2, &Nut);
- if (stat != AP_NORMAL) {
- ads_printf(/*MSG104*/"\nUnable to subtract solids.\n");
- goto Error;
- }
-
- /* Move nut to UCS */
-
- ap_move_obj (Nut, mat, FALSE);
-
- /* Display the solid */
-
- ap_post_obj (Nut, AP_POSTWIRE);
-
- Error:
- ads_retvoid();
- return;
- }
-
- /*************************************************************************/
- /* .doc get_nut_data() */
- /*+
- This routine prompts the user to enter nut data.
- -*/
- /*************************************************************************/
- static ap_Bool
- /*FCN*/get_nut_data (nutd, nuth, holed, mat)
- ads_real *nutd, *nuth, *holed;
- ap_Trans3d mat;
- {
- int stat;
- ads_real holed_max;
- ads_point pt, pd;
- ap_Trans3d mat1, mat2;
-
- /* Initialization of nut data for default input */
-
- pt[X] = 0.0;
- pt[Y] = 0.0;
- pt[Z] = 0.0;
- *nutd = 2.0;
- *nuth = 0.5;
- *holed = 1.0;
-
- /* Acquire values of design parameters associated with nut
- from the user and verify the validity of input data */
-
- stat = ads_getpoint (NULL, /*MSG105*/"\nInsertion base point <0,0,0>: ", pt);
- if (stat == RTCAN) {
- return FALSE;
- }
- stat = ads_getreal (/*MSG106*/"\nEnter nut diameter <2.0>: ", nutd);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*nutd <= 0.0) {
- ads_printf(/*MSG107*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- stat = ads_getreal (/*MSG108*/"\nEnter nut height <0.5>: ", nuth);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*nuth <= 0.0) {
- ads_printf(/*MSG109*/"\nValue must be positive and nonzero.");
- return FALSE;
- }
-
- holed_max = (*nutd) * sin(60.0*PI/180.0);
- stat = ads_getreal (/*MSG110*/"\nEnter hole diameter <1.0>: ", holed);
- if (stat == RTCAN) {
- return FALSE;
- } else if (*holed <= 0.0) {
- ads_printf(/*MSG111*/"\nValue must be positive and nonzero.");
- return FALSE;
- } else if (*holed >= holed_max) {
- ads_printf(/*MSG112*/"\nValue must be less than %f.", holed_max);
- return FALSE;
- }
-
- stat = ap_get_ucsmat(mat1);
- if (stat != AP_NORMAL)
- return FALSE;
- trans_uc2wc(pt, TRUE, pd);
- stat = ap_translate (pd[X], pd[Y], pd[Z], mat2);
- if (stat != AP_NORMAL)
- return FALSE;
- stat = ap_compose(mat2, mat1, mat);
- if (stat != AP_NORMAL)
- return FALSE;
- return TRUE;
- }
-
- /*************************************************************************/
- /* .doc trans_uc2wc() */
- /*+
- Transform a point p in ucs into point q in wcs
- If vec = TRUE, then p is a vector
- If vec = FALSE, then p is a point
- -*/
- /*************************************************************************/
-
- static void
- /* FCN */trans_uc2wc(p,vec,q)
- ads_point p, q;
- ap_Bool vec;
- {
- struct resbuf rbfrom, rbto;
-
- rbfrom.restype = RTSHORT;
- rbto.restype = RTSHORT;
- rbfrom.resval.rint = 1; /* from ucs */
- rbto.resval.rint = 0; /* to world */
- ads_trans(p, &rbfrom, &rbto, vec, q);
- }
-
-
- /* EOF */
-