home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- SAGET.C
- ¬⌐┼v (C) 1988-1992 Autodesk ñ╜Ñq
-
- Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
- ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
- ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
-
- ( i) │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
- (ii) ╕ⁿª│íu¬⌐┼v (C) 1988-1992 Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
-
-
-
- AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
- Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
- ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
- íuº╣Ñ■╡L╗~ív¬║½O├╥íC
-
-
- Description: Library of extended ads_getxxx() functions. These functions
- behave exactly the same as their original ADS counterparts
- but provide:
-
- - AutoLISP input redirection
- - supporting 'CAL (Geometry Calculator) command
- - options 'CP and Baseplane
-
- The library also contains some new functions for entering
- an axis and a plane etc.
-
- Notes:
-
- See the AME R2 manual for the description of the AutoLISP support
- and the 'CP and Baseplane options. The 'CAL command (Geometry Calculator)
- is described in the "AutoCAD Extras" manual.
-
- You must call sa_init_input() at the beginning of each ADS command,
- before using any of the sa_getxxx() functions. This function initializes
- some variables and reads the list of result buffers passed to the ADS
- command via AutoLISP. It also reads the implied selection set.
-
- Global variable 'lisp_input' is set to TRUE if the input is read from
- AutoLISP and FALSE if the input is read from the keyboard.
-
- If an error occurs during the input from AutoLISP, global variable
- 'lisp_error' is set to TRUE and all subsequent calls to sa_getxx()
- functions will do nothing and just return RTERROR. This is to disable
- the input of other parameters from AutoLISP if something failed before.
-
- You must use sa_initget() and sa_getinput() with sa_getxxx()
- functions, not the standard ads_initget() and ads_getinput().
-
- All the functions return standard ADS return codes, i.e. RTNORM,
- RTNONE, RTERROR, RTCAN, RTKWORD, RTSTRING etc.
-
- *****************************************************************************/
-
- #ifdef __ZTC__
- #ifdef __INLINE_8087
- #undef __INLINE_8087
- #endif
- #endif /*__ZTC__*/
-
-
- /****************************************************************************/
- /* INCLUDES */
- /****************************************************************************/
-
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include "adslib.h"
- #include "ol_errno.h"
- #include "util.h"
- #include "saget.h"
-
-
- /****************************************************************************/
- /* DEFINES */
- /****************************************************************************/
-
- #define MAX_STR_LEN 501 /* Max string length */
- #define MAX_UCS_LEVEL 5 /* Maximum level of UCS nesting */
-
-
- /****************************************************************************/
- /* GLOBAL VARIABLES */
- /****************************************************************************/
-
- int lisp_input = FALSE; /* Input from AutoLISP list of resbufs*/
- int lisp_error = FALSE; /* Error occured during AutoLISP input*/
-
- struct resbuf *current_rb = NULL; /* Next resbuf to read from AutoLISP */
-
- int sa_get_returned_RTCAN = FALSE; /* Some sa_getxxx() returned RTCAN */
-
- ads_name implied_selset; /* The implied selection set name */
- int implied_selset_exists = FALSE; /* The implied selection set exists */
-
- /* The following global array of selection set names keeps the selection
- sets which were read by sa_ssget() function. no_of_ssget_ss keeps the
- number of selection sets read */
-
- ads_name ssget_ss[20]; /* Array of selsets from sa_ssget() */
- int no_of_ssget_ss = 0; /* Number of selsets read */
-
-
- /****************************************************************************/
- /* STATIC VARIABLES */
- /****************************************************************************/
-
- static struct igbuff
- {
- int val;
- char kwl[MAX_STR_LEN];
- char kw[MAX_STR_LEN];
- int cplast;
- } initget_buffer = {0, /* NT */"", /* NT */"", FALSE};
-
- static struct
- {
- ads_point p1, p2;
- } last_axis = {{ 0.0, 0.0, 0.0 },
- { 0.0, 0.0, 0.0 }};
-
- static struct
- {
- ads_point p1, p2, p3;
- } last_plane = {{ 0.0, 0.0, 0.0 },
- { 0.0, 0.0, 0.0 },
- { 0.0, 0.0, 0.0 }};
-
- static int setcp_level = 0; /* Level of SetCP nesting */
- static int ucs_level = 0; /* Level of UCS nesting */
- static int cp_used = FALSE; /* CP used in last sa_getxxx() */
- static struct resbuf ucsicon; /* Save area for UCSICON */
-
-
- /****************************************************************************/
- /* STATIC FUNCTIONSS */
- /****************************************************************************/
-
- static int invoke_calculator _((int required_expr_type,
- ads_point result));
- static void str_toupper _((char *str));
- static void check_if_string_is_keyword _((char *word, char *kw));
- static int is_null_argument _((int *success));
- static int get_from_ads _((int func, ads_point pt,
- char *prompt, ads_point res));
- static int get_from_lisp _((int func, ads_point res));
- static void convert_angle _((int func, double *angle));
- static int check_value _((int func, double value));
- static int match _((char *kw, char *pattern));
- static int get_it _((int func, ads_point pt,
- char *prompt, ads_point result));
-
-
- /****************************************************************************/
- /*.doc invoke_calculator(internal) */
- /*+
- Invokes the GEOMCAL application and returns the value of the
- evaluated expression in 'result'.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/invoke_calculator(required_expr_type, result)
-
- int required_expr_type; /* RTREAL, RTSHORT or RT3DPOINT */
- ads_point result; /* The returned value */
- {
- char expr_str[MAX_STR_LEN];
- struct resbuf *rb;
- int success;
- struct resbuf *res = NULL;
-
- result[X] = result[Y] = result[Z] = 0.0;
-
- /* Load the "geomcal" application */
-
- success = ads_xload("geomcal");
-
- if (success != RTNORM) {
- struct resbuf aerrno;
- ads_getvar("ERRNO", &aerrno);
- if (aerrno.resval.rint != OL_ELOADED) {
- ads_printf("\n╕ⁿñJíu┤Xª≤¡p║ΓívÑ\134»α¿τ╝╞Ñó▒╤íC\n");
- return(RTERROR);
- }
- }
-
- Prompt:
-
- sa_initget(1, NULL);
- success = sa_getstring(1, ">> ¡zÑy: ", expr_str);
-
- if ((success == RTERROR) || (success == RTCAN) || (success == RTREJ)) {
- return(success);
- } else if ((success != RTNORM) || (expr_str[0] == EOS)) {
- if (!lisp_input) {
- goto Prompt;
- } else {
- return(RTERROR);
- }
- }
-
- rb = ads_buildlist(RTSTR, /* NT */"CAL", RTSTR, expr_str, 0);
-
- success = ads_invoke(rb, &res);
- ads_relrb(rb);
-
- if (success != RTNORM) {
- ads_printf("\n░⌡ªµíu┤Xª≤¡p║ΓívÑ\134»αÑó▒╤íC\n");
- return(RTERROR);
- }
-
- if (res == NULL) {
- if (!lisp_input) {
- goto Prompt;
- } else {
- return(RTERROR);
- }
- }
-
- /* Calculator properly returned a list of resbufs,
- let's check their type */
-
- switch (required_expr_type) {
-
- case RTREAL:
- if ((res->rbnext != NULL) ||
- (res->restype != RTREAL) && (res->restype != RTSHORT)) {
-
- ads_printf("\n¡zÑyÑ▓╢╖└╦─╢¼░íu╣Ω╝╞¡╚ívíC\n\n");
- ads_relrb(res);
- if (!lisp_input)
- goto Prompt;
- else
- return(RTERROR);
- }
-
- if (res->restype == RTREAL)
- result[X] = res->resval.rreal;
- else
- result[X] = (double)res->resval.rint;
- break;
-
- case RTSHORT:
- if (res->restype != RTSHORT) {
- ads_printf("\n¡zÑyÑ▓╢╖└╦─╢¼░íu╛π╝╞¡╚ívíC\n\n");
- ads_relrb(res);
- if (!lisp_input)
- goto Prompt;
- else
- return(RTERROR);
- }
-
- result[X] = (double)res->resval.rint;
- break;
-
- case RT3DPOINT:
- if (res->rbnext == NULL) {
- ads_printf("\n¡zÑyÑ▓╢╖└╦─╢¼░íu┬Ií■ªV╢qívíC\n\n");
- ads_relrb(res);
- if (!lisp_input)
- goto Prompt;
- else
- return(RTERROR);
- }
-
- result[X] = res->resval.rreal;
- result[Y] = res->rbnext->resval.rreal;
- result[Z] = res->rbnext->rbnext->resval.rreal;
- break;
-
- default:
- ads_relrb(res);
- return(RTREJ);
- } /*switch*/
-
- ads_relrb(res);
- return(RTNORM);
- } /*invoke_calculator*/
-
-
- static void
- /*FCN*/str_toupper(str)
-
- char *str;
- {
- while ((*str = ads_toupper(*str)) != 0)
- str++;
- } /*str_toupper*/
-
-
- /****************************************************************************/
- /*.doc check_if_string_is_keyword(internal) */
- /*+
- Checks whether the given string 'word' is one of the keywords from
- initget_buffer.kwl. If yes, gives the keyword 'kw', otherwise
- gives "".
- -*/
- /****************************************************************************/
-
-
- static void
- /*FCN*/check_if_string_is_keyword(word, kw)
-
- char word[]; /* Input string */
- char kw[]; /* Output keyword or "" if no match */
- {
- char kwl[MAX_STR_LEN];
- char w[MAX_STR_LEN];
- char whole_kw[MAX_STR_LEN], short_kw[MAX_STR_LEN];
- char *ch, *space, *comma;
- int w_len, s_len;
- int word_underscored = FALSE;
- char *underscore_pos;
- int count = 0;
-
- /* Initialize 'kw', make local copy of input 'word', strip off
- the leading underscore, if present */
-
- kw[0] = EOS;
-
- if (word[0] == /* NT */'_') {
- strcpy(w, word + 1);
- word_underscored = TRUE;
- } else {
- strcpy(w, word);
- }
- str_toupper(w);
-
- if (word[0] == EOS)
- return;
-
- strcpy(kwl, initget_buffer.kwl);
-
- underscore_pos = strstr(kwl, /* NT */" _");
- if (underscore_pos != NULL) {
- underscore_pos++;
-
- if (word_underscored) {
- ch = underscore_pos + 1; /* Check only keywords following "_" */
- } else {
- ch = kwl;
- *underscore_pos = EOS; /* Check only keywords preceding "_" */
- }
- } else {
- ch = kwl;
- }
-
- /* Go through all the keywords in initget_buffer.kwl */
-
- for (;;) {
-
- /* Go to the beginning of the next kword */
-
- while (*ch == /* NT */' ') {
- ch++;
- }
- if (*ch == EOS)
- return; /*Not found*/
-
- /* Parse the keyword specification */
-
- count++;
-
- /* Find the position of the terminating space */
-
- space = strchr(ch, /* NT */' ');
- if (space == NULL)
- space = kwl + strlen(kwl);
-
- comma = strchr(ch, /* NT */',');
- if ((comma != NULL) && (comma > space))
- comma = NULL;
-
- /* Assign whole_kw and short_kw */
-
- if (comma == NULL) {
- char *c = short_kw;
-
- w_len = space - ch;
- strncpy(whole_kw, ch, w_len); whole_kw[w_len] = EOS;
-
- strcpy (short_kw, whole_kw);
- while (*c != EOS) {
- if (ads_islower(*c)) {
- if (c != short_kw) /*Not the first character*/
- *c = EOS;
- break;
- }
- c++;
- } /*while*/
- } else {
- w_len = comma - ch;
- s_len = space - (comma+1);
-
- strncpy(whole_kw, ch, w_len); whole_kw[w_len] = EOS;
- strncpy(short_kw, comma+1, s_len); short_kw[s_len] = EOS;
- } /*else*/
-
- str_toupper(whole_kw);
- str_toupper(short_kw);
-
- /*
- If 'w' is prefix of 'whole_kw' and
- 'short_kw' is prefix of 'w'
- then 'w' is a keyword.
- */
-
- if ((strstr(whole_kw, w ) == whole_kw) &&
- (strstr(w, short_kw) == w )) {
-
- int len;
-
- if (comma != NULL)
- len = comma - ch;
- else
- len = space - ch;
-
- strncpy(kw, ch, len); kw[len] = EOS;
- break; /*Found*/
- }
-
- /* Go to the space terminating the checked keyword */
-
- ch = space;
- } /*forever*/
-
- /* The keyword was found. But if the given word was underscored
- and the list of keywords contains both the orignal and language
- dependent keywords, then instead of returning the keyword found
- we return its language dependent equivalent */
-
- if (word_underscored && (underscore_pos != NULL)) {
- char *tok;
- int i;
-
- /* Go to the count's token in the list of keywords */
-
- tok = strtok(kwl, " ");
- for (i = 0; i < count - 1; i++) {
- tok = strtok(NULL, " ");
- }
- if (tok != NULL) {
- strcpy(kw, tok);
- } else {
- kw[0] = EOS;
- }
- }
-
- } /*check_if_string_is_keyword*/
-
-
- /****************************************************************************/
- /*.doc is_null_argument(internal)*/
- /*+
- Checks whether the next argument in the AutoLISP's list of resbufs
- is null, that is NIL or "".
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/is_null_argument(success)
-
- int *success;
- {
- if (current_rb == NULL) {
- if (initget_buffer.val & RSG_NONULL) {
- ads_printf("\n┐∙╗~:íuñ▐╝╞ív╣Lñ╓íC\n\n");
- *success = RTERROR;
- } else {
- *success = RTNONE;
- }
- return(TRUE);
- }
-
- if ((current_rb->restype == RTNIL) ||
- (current_rb->restype == RTSTR) &&
- (current_rb->resval.rstring[0] == EOS)) {
- if (initget_buffer.val & RSG_NONULL) {
- ads_printf("\n┐∙╗~: ñú▒╡¿ⁿíuNull ñ▐╝╞ívíC\n\n");
- *success = RTERROR;
- } else {
- *success = RTNONE;
- }
- return(TRUE);
- }
- return(FALSE);
- } /*is_null_argument*/
-
-
- /****************************************************************************/
- /*.doc get_from_ads(internal)*/
- /*+
- Function calls one of the standard ads_getxxx() functions.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/get_from_ads(func, pt, prompt, res)
-
- int func; /*'I' == int, 'P' == point, etc. */
- ads_point pt; /* Reference point */
- char *prompt;
- ads_point res;
- {
- int success;
-
- switch (func) {
-
- case /* NT */'I': {
- int i;
- success = ads_getint(prompt, &i); /*int*/
- res[X] = (double) i;
- break;
- }
- case /* NT */'R':
- success = ads_getreal(prompt, res); /*double*/
- break;
- case /* NT */'A':
- success = ads_getangle(pt, prompt, res); /*double*/
- break;
- case /* NT */'C':
- success = ads_getcorner(pt, prompt, res); /*point*/
- break;
- case /* NT */'D':
- success = ads_getdist(pt, prompt, res); /*double*/
- break;
- case /* NT */'O':
- success = ads_getorient(pt, prompt, res); /*double*/
- break;
- case /* NT */'P':
- success = ads_getpoint(pt, prompt, res); /*point*/
- break;
- default:
- success = RTREJ;
- break;
- } /*switch*/
-
- return(success);
- } /*get_from_ads*/
-
-
- /****************************************************************************/
- /*.doc get_from_lisp(internal)*/
- /*+
- Function gets one argument from the AutoLISP's list of result buffers.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/get_from_lisp(func, res)
-
- int func;
- ads_point res;
- {
- int type;
- int success;
- char kw[MAX_STR_LEN];
-
- if (lisp_error)
- return(RTERROR);
-
- if (is_null_argument(&success))
- goto End;
-
- type = current_rb->restype;
-
- /* Is it a keyword? */
-
- if (type == RTSTR) {
-
- check_if_string_is_keyword(current_rb->resval.rstring, kw);
-
- if (kw[0] != EOS) {
- strcpy(initget_buffer.kw, kw);
- success = RTKWORD;
-
- } else if (initget_buffer.val & RSG_OTHER) {
- strcpy(initget_buffer.kw, current_rb->resval.rstring);
- str_toupper(initget_buffer.kw);
- success = RTKWORD;
-
- } else {
- ads_printf("\n┐∙╗~: ├÷┴Σªríu%sívñúªX▓zíC\n\n",
- current_rb->resval.rstring);
- success = RTERROR;
- }
- goto End;
- } /*if*/
-
- /* Switch depending on the type of the sa_getxxx() function */
-
- switch (func) {
-
- case /* NT */'I': /*Integer*/
- switch (type) {
- case RTSHORT:
- res[X] = (double)current_rb->resval.rint;
- success = RTNORM;
- break;
- default:
- ads_printf("\n┐∙╗~:íu░╤╝╞ív└│¼░íu╛π╝╞ívíC\n\n");
- success = RTERROR;
- goto End;
- } /*switch*/
- break;
-
- case /* NT */'R': /*Real*/
- case /* NT */'D':
- case /* NT */'A':
- case /* NT */'O':
- switch (type) {
- case RTSHORT:
- res[X] = (double)current_rb->resval.rint;
- success = RTNORM;
- break;
- case RTLONG:
- res[X] = (double)current_rb->resval.rlong;
- success = RTNORM;
- break;
- case RTREAL:
- case RTANG:
- case RTORINT:
- res[X] = current_rb->resval.rreal;
- success = RTNORM;
- break;
- default:
- ads_printf("\n┐∙╗~:íu░╤╝╞ív└│¼░íu╣Ω╝╞ívíC\n\n");
- success = RTERROR;
- goto End;
- } /*switch*/
- break;
-
- case /* NT */'P':
- case /* NT */'C':
- switch (type) {
- case RTPOINT:
- case RT3DPOINT:
- CPY_PNT(res, current_rb->resval.rpoint);
- success = RTNORM;
- break;
- default:
- ads_printf("\n┐∙╗~:íu░╤╝╞ív└│¼░íu┬Ií■ªV╢qívíC\n\n");
- success = RTERROR;
- goto End;
- } /*switch*/
- func = /* NT */'P';
- break;
-
- default:
- success = RTREJ;
- goto End;
- } /*switch*/
-
- if (!check_value(func, res[X])) {
- success = RTERROR;
- goto End;
- }
-
- if ((func == /* NT */'A') || (func == /* NT */'O')) {
- convert_angle(func, &res[X]);
- }
-
- End:
- if (current_rb != NULL)
- current_rb = current_rb->rbnext;
- lisp_error = ((success != RTNORM) && (success != RTNONE) &&
- (success != RTKWORD));
- return(success);
- } /*get_from_lisp*/
-
-
- /****************************************************************************/
- /*.doc convert_angle(internal)*/
- /*+
- Converts the given angle from the current units and orientation to ccw
- measured radians. Takes into account the values of AutoCAD variables
- ANGDIR, AUNITS and ANGBASE.
- -*/
- /****************************************************************************/
-
-
- static void
- /*FCN*/convert_angle(func, angle)
-
- int func;
- double *angle;
- {
- struct resbuf angdir, aunits;
- double ang = *angle;
-
- ads_getvar("ANGDIR", &angdir);
- ads_getvar("AUNITS", &aunits);
-
- /* Orient the angle counterclockwise */
-
- if (angdir.resval.rint == 1) {
- ang = -ang;
- }
-
- /* Convert from the current units to radians */
-
- switch (aunits.resval.rint) {
- case 2:
- ang *= (0.9 * DEGRAD);
- break;
- case 3:
- /* Already in radians */
- break;
- default:
- ang *= DEGRAD;
- break;
- } /*switch*/
-
- /* If the function is sa_getorient(), add ANGBASE angle */
-
- if (func == /* NT */'O') {
- struct resbuf angbase;
- ads_getvar("ANGBASE", &angbase);
-
- ang += angbase.resval.rreal;
- }
-
- sa_normalize_angle(&ang);
- *angle = ang;
- } /*convert_angle*/
-
-
- /****************************************************************************/
- /*.doc check_value(internal)*/
- /*+
- Check the given real value whether it satisfies the initget bits
- RSG_NOZERO and RSG_NONEG. Returns TRUE if the value is OK, FALSE otherwise.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/check_value(func, value)
-
- int func;
- double value;
- {
- /* For reals and integers check flags RSG_NOZERO & RSG_NONEG */
-
- if ((func == /* NT */'I') ||
- (func == /* NT */'R') || (func == /* NT */'D') ||
- (func == /* NT */'A') || (func == /* NT */'O')) {
-
- if ((initget_buffer.val & RSG_NOZERO) && (value == 0.0)) {
- ads_printf("\n┐∙╗~: ╝╞¡╚ñúÑi¼░íu0ívíC\n\n");
- return(FALSE);
- }
- if ((initget_buffer.val & RSG_NONEG) && (value < 0.0)) {
- ads_printf("\n┐∙╗~: ╝╞Ñ╪ñúÑi¼░íu¡t¡╚ívíC\n\n");
- return(FALSE);
- }
- }
- return(TRUE);
- } /*check_value*/
-
-
- /****************************************************************************/
- /*.doc match(internal)*/
- /*+
- Check whether
- kw == pattern or
- kw == 'pattern or
- kw == (pattern) or
- kw == (C:pattern)
-
- This awkward code is necessary as the user input 'XXX is converted to
- either (XXX) or (C:XXX) or left unchanged as 'XXX.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/match(kw, pattern)
-
- char *kw;
- char *pattern;
- {
- char pat[MAX_STR_LEN];
-
- if (strcmp(kw, pattern) == 0)
- return(TRUE);
-
- if ((kw[0] != /* NT */'(') && (kw[0] != /*ASCII character ' */ 39))
- return(FALSE);
-
- if ((kw[0] == /*ASCII character ' */ 39) &&
- (strcmp(kw + 1, pattern) == 0))
- return(TRUE);
-
- pat[0] = EOS;
- strcat(pat, /* NT */"(C:");
- strcat(pat, pattern);
- strcat(pat, /* NT */")");
-
- if (strcmp(kw, pat) == 0)
- return(TRUE);
-
- pat[0] = EOS;
- strcat(pat, /* NT */"(");
- strcat(pat, pattern);
- strcat(pat, /* NT */")");
-
- if (strcmp(kw, pat) == 0)
- return(TRUE);
-
- return(FALSE);
- } /*match*/
-
-
- /****************************************************************************/
- /*.doc get_it(internal)*/
- /*+
- General sa_getxxx() routine. Is implemented to avoid writing similar
- code for individual sa_getpoint(), sa_getangle(), sa_getdist() etc.
- -*/
- /****************************************************************************/
-
-
- static int
- /*FCN*/get_it(func, pt, prompt, result)
-
- int func; /* 'P' == getpoint, 'D' == getdist... */
- ads_point pt; /* Reference point */
- char *prompt; /* Prompt (optional) */
- ads_point result; /* Returned result */
- {
- char kw[MAX_STR_LEN];
- int success;
- char cp_option[10];
- struct igbuff initget_save;
- struct resbuf ucsicon_save;
- int ucsicon_saved = FALSE;
- ads_point res;
- ads_point ref_pt;
- ads_point ref_pt_wcs;
- double *ref_pt_ptr;
-
- /* Save the reference point pt and initget_buffer */
-
- if (pt != NULL) {
- CPY_PNT(ref_pt, pt);
- sa_u2w(ref_pt, ref_pt_wcs);
- ref_pt_ptr = ref_pt;
- } else {
- ref_pt_ptr = NULL;
- }
-
- initget_save = initget_buffer;
- cp_used = FALSE;
-
- /* If sa_init_cplast() was used, go directly to CPL (Last) option */
-
- if (initget_save.cplast) {
- strcpy(kw, "CPL");
- goto Check_kword;
- }
-
- Prompt:
-
- /* Get the input from the user or from AutoLISP. Notice that
- we are explicitly setting the RSG_OTHER initget bit. This is
- necessary for supporting 'CAL, 'CP etc, which are returned
- as arbitrary keyboard input, not as keywords.
- */
-
- kw[0] = EOS;
- sa_initget(initget_save.val | RSG_OTHER, initget_save.kwl);
-
- if (lisp_input) {
- success = get_from_lisp(func, res);
- } else {
- success = get_from_ads(func, ref_pt_ptr, prompt, res);
- }
-
- if (success != RTKWORD)
- goto End;
-
- if (lisp_input) {
- sa_getinput(kw);
- } else {
- ads_getinput(kw);
- }
-
- Check_kword:
-
- /* Check whether the string 'kw' is one of the reserved keywords
- such as 'CAL, 'CP etc. Notice that these reserved keywords are
- returned as arbitrary keyboard input strings.
- */
-
- cp_option[0] = EOS;
-
- if (match(kw, "CAL")) {
- strcpy(kw, "CAL");
-
- } else if (match(kw, "CP")) {
- strcpy(kw, "CP");
-
- } else if (match(kw, "CPE")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "Entity");
-
- } else if (match(kw, "CPV")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "View");
-
- } else if (match(kw, "CPZ")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "Zaxis");
-
- } else if (match(kw, "CPXY")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "XY");
-
- } else if (match(kw, "CPYZ")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "YZ");
-
- } else if (match(kw, "CPZX")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "ZX");
-
- } else if (match(kw, "CPL")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "Last");
-
- } else if (match(kw, "CP3")) {
- strcpy(kw, "CP");
- strcpy(cp_option, "3points");
-
- } else if ((initget_save.val & RSG_OTHER) == 0) {
-
- /* As we forecfully added the RSG_OTHER bit to ads_initget(), this
- means that all wrong input will be returned as arbitrary
- keyboard input string. But if the user himself didn't set the
- RSG_OTHER flag, we want to print an error if the string is
- not any of the legal keywords.
- */
-
- char tmp[MAX_STR_LEN];
- check_if_string_is_keyword(kw, tmp);
-
- if (tmp[0] == EOS) {
- ads_printf("\n╡L«─¬║íu┐ΘñJívíC\n");
-
- if (!lisp_input) {
- goto Prompt;
- } else {
- goto End;
- }
- }
- }
-
- if (strcmp(kw, "CP") == 0) {
-
- ads_point origin, xaxis, yaxis;
- int i;
- struct resbuf ucsi;
-
- if (ucs_level >= MAX_UCS_LEVEL) {
- ads_printf("\nCPíu▒_▓╒╝h╢Ñív╣L▓`íC\n\n");
- if (!lisp_input)
- goto Prompt;
- else {
- success = RTERROR;
- goto End;
- }
- }
-
- if (!ucsicon_saved) {
- ads_getvar("UCSICON", &ucsicon_save);
- ucsicon_saved = TRUE;
- }
-
- /* Prompt for the construction plane */
-
- success = sa_getplane("\nCP", cp_option, origin, xaxis, yaxis);
- if (!lisp_input && (success == RTCAN)) {
- goto Prompt;
- } else if (success != RTNORM)
- goto End;
-
- /* Align UCS with the construction plane */
-
- sa_save_acad_vars();
-
- success = ads_command(RTSTR, /* NT */"_.UCS", RTSTR, /* NT */"_3",
- RT3DPOINT, origin,
- RT3DPOINT, xaxis,
- RT3DPOINT, yaxis, 0);
- sa_restore_acad_vars();
-
- if (success != RTNORM) {
- ads_printf("\n¼░íu½╪║cÑ¡¡▒ív│]⌐w UCS Ñó▒╤\n\n");
- success = RTERROR;
- goto End;
- }
- ucs_level++;
-
- /* Transform 'ref_pt_wcs' from WCS to CP */
-
- if (ref_pt_ptr != NULL)
- sa_w2u(ref_pt_wcs, ref_pt);
-
- /* Display ucs icon at the origin of the construction plane */
-
- ucsi.restype = RTSHORT;
- ucsi.resval.rint = 3;
- ads_setvar("UCSICON",&ucsi);
-
- /* Exclude keyword "Baseplane" after CP was used */
-
- if (strncmp(initget_save.kwl, "Baseplane", 9) == 0) {
- for (i = 0; i < 9; i++)
- initget_save.kwl[i] = /* NT */' ';
- }
-
- /* Get a value relative to the construction plane */
- /* Notice the recursiive call to get_it() */
-
- sa_initget(initget_save.val, initget_save.kwl);
- success = get_it(func, ref_pt_ptr, prompt, res);
-
- if ((success == RTKWORD) || (success == RTSTR))
- sa_getinput(kw);
-
- /* Transform result 'res' CP->UCS if it is a point */
-
- if (((func == /* NT */'C') || (func == /* NT */'P'))
- && (success == RTNORM)) {
- sa_u2w(res, res);
- }
-
- /* Return UCS back, hide UCSICON to avoid jumping of the icon */
-
- ucsi.restype = RTSHORT;
- ucsi.resval.rint = 0;
- ads_setvar("UCSICON", &ucsi);
-
- sa_cmdecho_off();
- ads_command(RTSTR, /* NT */"_.UCS", RTSTR, /* NT */"_PREV", 0);
- sa_cmdecho_back();
- ucs_level--;
-
- if (((func == /* NT */'C') || (func == /* NT */'P'))
- && (success == RTNORM)) {
- sa_w2u(res, res);
- }
-
- cp_used = TRUE;
-
- } else if (strcmp(kw, "Baseplane") == 0) {
-
- if (ucs_level >= MAX_UCS_LEVEL) {
- ads_printf("\n░≥╖╟¡▒íu▒_▓╒╝h╢Ñív╣L▓`íC\n\n");
- if (!lisp_input)
- goto Prompt;
- else {
- success = RTERROR;
- goto End;
- }
- }
-
- if (!ucsicon_saved) {
- ads_getvar("UCSICON", &ucsicon_save);
- ucsicon_saved = TRUE;
- }
-
- success = sa_set_cp("\n░≥╖╟¡▒");
- cp_used = FALSE;
-
- if (!lisp_input && (success == RTCAN)) {
- goto Prompt;
- } else if (success != RTNORM)
- goto End;
-
- ads_getvar("UCSICON", &ucsicon_save);
- if (ref_pt_ptr != NULL)
- sa_w2u(ref_pt_wcs, ref_pt);
- goto Prompt;
-
- } else if (strcmp(kw, /* NT */"CAL") == 0) {
-
- int required_expr_type;
-
- switch (func) {
-
- case /* NT */'P':
- case /* NT */'C':
- required_expr_type = RT3DPOINT;
- break;
- case /* NT */'D':
- case /* NT */'A':
- case /* NT */'O':
- case /* NT */'R':
- required_expr_type = RTREAL;
- break;
- case /* NT */'I':
- required_expr_type = RTSHORT;
- break;
- default:
- success = RTERROR;
- goto End;
- } /*switch*/
-
- success = invoke_calculator(required_expr_type, res);
-
- if (!lisp_input && (success == RTCAN))
- goto Prompt;
- else if (success != RTNORM)
- goto End;
-
- if (!check_value(func, res[X])) {
- if (!lisp_input) {
- goto Prompt;
- } else {
- success = RTERROR;
- goto End;
- }
- }
-
- if ((func == /* NT */'A') || (func == /* NT */'O')) {
- convert_angle(func, &res[X]);
- }
-
- } else {
- success = RTKWORD;
- }
-
- End:
- if (success == RTNORM)
- CPY_PNT(result, res);
-
- sa_initget(0, NULL);
- strcpy(initget_buffer.kw, kw);
-
- if (ucsicon_saved) {
- ads_setvar("UCSICON", &ucsicon_save);
- }
-
- sa_get_returned_RTCAN = (success == RTCAN);
-
- return(success);
- } /*get_it*/
-
-
- /****************************************************************************/
- /*.doc sa_init_input(external)*/
- /*+
- This function must be called before each ADS command. It initializes the
- system and reads the arguments (list of result buffers) which AutoLISP
- passes to the AME command being activated. It also reads the implied
- selection set and stores it in global variable implied_selset. The global
- integer variable implied_selset_exists is set to TRUE if there is an
- implied selection set.
-
- It is convenient to call sa_init_input() from main(), before processing the
- RQSUBR request from ads_link().
-
- The 'input_source' argument is used to determine whether the input of
- sa_getxxx() functions will go from the keyboard or from AutoLISP's list
- of result buffers.
-
- 0 ... input from AutoLISP if a resbuf list present, otherwise from keyboard.
- 1 ... input from AutoLISP even if no resbuf list present
- 2 ... input from keyboard even if a resbuf list present.
-
- Function always returns RTNORM.
-
- Note:
-
- Don't forget to explicitly free the stored and unused implied selection
- when you are leaving the ADS application. The number of currently open
- selection set names is limited. See the code 30 lines below how to do this.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_init_input(input_source)
-
- int input_source;
- {
- int success;
-
- switch (input_source) {
- case 0:
- current_rb = ads_getargs();
- lisp_input = (current_rb != NULL);
- break;
- case 1:
- current_rb = ads_getargs();
- lisp_input = TRUE;
- break;
- case 2:
- current_rb = NULL;
- lisp_input = FALSE;
- break;
- default:
- current_rb = NULL;
- lisp_input = FALSE;
- break;
- } /*switch*/
-
- /************************************************************************
- Free the stored and unused implied selection set. You should
- explicitly free the stored implied selection set when you are leaving
- the ADS application or any time when sa_init_input() is not called to
- free it for you.
- ************************************************************************/
-
- if (implied_selset_exists) {
- ads_ssfree(implied_selset);
- implied_selset_exists = FALSE;
- }
-
- /* Get the implied selection set, if there is any */
-
- success = ads_ssget(/* NT */"_I", NULL, NULL, NULL, implied_selset);
- implied_selset_exists = (success == RTNORM);
-
- if (lisp_input) {
- ads_retnil();
- } else {
- ads_retvoid();
- }
-
- lisp_error = FALSE;
- sa_get_returned_RTCAN = FALSE;
- no_of_ssget_ss = 0;
-
- return(RTNORM);
- } /*sa_init_input*/
-
-
- /****************************************************************************/
- /*.doc sa_initget(external)*/
- /*+
- Analogy to ads_initget() but must be used with sa_getxxx() functions.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_initget(val, kwl)
-
- int val;
- char *kwl;
- {
- int success;
-
- success = ads_initget(val, kwl);
- if (success != RTNORM)
- return(success);
-
- initget_buffer.val = val;
- if (kwl != NULL) {
- strcpy(initget_buffer.kwl, kwl);
- } else {
- initget_buffer.kwl[0] = EOS;
- }
-
- initget_buffer.kw[0] = EOS;
- initget_buffer.cplast = FALSE;
-
- return(RTNORM);
- } /*sa_initget*/
-
-
- /****************************************************************************/
- /*.doc sa_init_cplast(external)*/
- /*+
- The purpose of this function is similar to sa_initget(), that is modifying
- the behavior of the next sa_getxxx() call. It sets that the next sa_getxxx()
- function will automatically jump to the CP used in the last sa_getxxx()
- function. If no CP was used in the last sa_getxxx() then nothing happens.
-
- This function must be called AFTER sa_initget() and before the sa_getxxx()
- function.
-
- Function always returns RTNORM.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_init_cplast()
- {
- initget_buffer.cplast = (cp_used);
- return(RTNORM);
- } /*sa_init_cplast*/
-
-
- /****************************************************************************/
- /*.doc sa_getinput(external)*/
- /*+
- Analogy to ads_getinput() but must be used with sa_getxxx() functions.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getinput(str)
-
- char *str;
- {
- if (initget_buffer.kw[0] == EOS)
- return(RTERROR);
-
- strcpy(str, initget_buffer.kw);
- initget_buffer.kw[0] = EOS;
- return(RTNORM);
- } /*sa_getinput*/
-
-
- /****************************************************************************/
- /*.doc sa_getpoint(external)*/
- /*+
- Enhanced ads_getpoint() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getpoint(pt, prompt, result)
-
- ads_point pt;
- char *prompt;
- ads_point result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'P', pt, prompt, p);
- if (success == RTNORM)
- CPY_PNT(result, p);
- return(success);
- } /*sa_getpoint*/
-
-
- /****************************************************************************/
- /*.doc sa_getcorner(external)*/
- /*+
- Enhanced ads_getcorner() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getcorner(pt, prompt, result)
-
- ads_point pt;
- char *prompt;
- ads_point result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'C', pt, prompt, p);
- if (success == RTNORM)
- CPY_PNT(result, p);
- return(success);
- } /*sa_getcorner*/
-
-
- /****************************************************************************/
- /*.doc sa_getangle(external)*/
- /*+
- Enhanced ads_getangle() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getangle(pt, prompt, result)
-
- ads_point pt;
- char *prompt;
- double *result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'A', pt, prompt, p);
-
- if (success == RTNORM)
- *result = p[X];
- return(success);
- } /*sa_getangle*/
-
-
- /****************************************************************************/
- /*.doc sa_getorient(external)*/
- /*+
- Enhanced ads_getorient() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getorient(pt, prompt, result)
-
- ads_point pt;
- char *prompt;
- double *result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'O', pt, prompt, p);
- if (success == RTNORM)
- *result = p[X];
- return(success);
- } /*sa_getorient*/
-
-
- /****************************************************************************/
- /*.doc sa_getdist(external)*/
- /*+
- Enhanced ads_getdist() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getdist(pt, prompt, result)
-
- ads_point pt;
- char *prompt;
- double *result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'D', pt, prompt, p);
- if (success == RTNORM)
- *result = p[X];
- return(success);
- } /*sa_getdist*/
-
-
- /****************************************************************************/
- /*.doc sa_getreal(external)*/
- /*+
- Enhanced ads_getreal() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getreal(prompt, result)
-
- char *prompt;
- double *result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'R', NULL, prompt, p);
- if (success == RTNORM)
- *result = p[X];
- return(success);
- } /*sa_getreal*/
-
-
- /****************************************************************************/
- /*.doc sa_getint(external)*/
- /*+
- Enhanced ads_getint() function which supports keyboard/AutoLISP input
- redirection and 'CAL, 'CP and Baseplane options.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getint(prompt, result)
-
- char *prompt;
- int *result;
- {
- int success;
- ads_point p;
-
- success = get_it(/* NT */'I', NULL, prompt, p);
- *result = (int) p[X];
- return(success);
- } /*sa_getint*/
-
-
- /****************************************************************************/
- /*.doc sa_getstring(external)*/
- /*+
- Enhanced ads_getstring() function which supports keyboard/AutoLISP input
- redirection.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getstring(cronly, prompt, result)
-
- int cronly;
- char *prompt;
- char *result;
- {
- int success;
- int type;
-
- cp_used = FALSE;
-
- if (!lisp_input) {
- success = ads_getstring(cronly, prompt, result);
-
- } else {
- if (lisp_error)
- return(RTERROR);
-
- if ((current_rb == NULL) || (current_rb->restype == RTNIL)) {
- result[0] = EOS;
- success = RTNORM;
- goto End;
- }
-
- type = current_rb->restype;
-
- if (type == RTSTR) {
- if (!cronly && strchr(current_rb->resval.rstring, /* NT */' ')) {
- ads_printf("\n┐∙╗~: ªrªΩñññúñ╣│\134┬°ª│íu¬┼Ñ╒ívíC\n\n");
- success = RTERROR;
- goto End;
- }
-
- strcpy(result, current_rb->resval.rstring);
- success = RTNORM;
- } else {
- ads_printf("\n┐∙╗~:íu░╤╝╞ív└│¼░íuªrªΩívíC\n\n");
- success = RTERROR;
- }
- }
-
- End:
- if (lisp_input) {
- if (current_rb != NULL)
- current_rb = current_rb->rbnext;
- lisp_error = (success != RTNORM);
- }
-
- sa_get_returned_RTCAN = (success == RTCAN);
-
- sa_initget(0, NULL);
- return(success);
- } /*sa_getstring*/
-
-
- /****************************************************************************/
- /*.doc sa_getkword(external)*/
- /*+
- Enhanced ads_getkword() function which supports keyboard/AutoLISP input
- redirection.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getkword(prompt, result)
-
- char *prompt;
- char *result;
- {
- int success;
- int type;
- char kw[MAX_STR_LEN];
-
- cp_used = FALSE;
-
- if (!lisp_input) {
- success = ads_getkword(prompt, result);
-
- } else {
-
- if (lisp_error)
- return(RTERROR);
-
- if (is_null_argument(&success))
- goto End;
-
- type = current_rb->restype;
-
- if (type == RTSTR) {
-
- check_if_string_is_keyword(current_rb->resval.rstring, kw);
-
- if (kw[0] != EOS) { /*Keyword found*/
- strcpy(result, kw);
- success = RTNORM;
-
- } else if (initget_buffer.val & RSG_OTHER) {
- strcpy(result, current_rb->resval.rstring);
- str_toupper(result);
- success = RTSTR;
-
- } else {
- ads_printf("\n┐∙╗~: ╡L¬k┐δ├╤¬║íu├÷┴Σªr %sívíC\n\n",
- current_rb->resval.rstring);
- success = RTERROR;
- }
- } else {
- ads_printf("\n┐∙╗~:íu░╤╝╞ív└│¼░íu├÷┴ΣªrívíC\n\n");
- success = RTERROR;
- }
- }
-
- End:
- if (lisp_input) {
- if (current_rb != NULL)
- current_rb = current_rb->rbnext;
- lisp_error = ((success != RTNORM) && (success != RTNONE));
- }
-
- sa_get_returned_RTCAN = (success == RTCAN);
-
- sa_initget(0, NULL);
- return(success);
- } /*sa_getkword*/
-
-
- /****************************************************************************/
- /*.doc sa_getaxis(external)*/
- /*+
- Function prompts for entering arbitrary 3D axis and returns two points
- p1 and p2 on the axis. The axis is oriented from p1 to p2.
-
- Function returns one the standard ADS result codes.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getaxis(prompt, p1, p2)
-
- char *prompt; /* Prompt (optional) */
- ads_point p1, p2; /* Returned two points on the axis */
- {
- int success;
- char kw[10];
- ads_point origin, xaxis, yaxis, zaxis;
- char pro[201];
-
- /* Prepare the prompt */
-
- if (prompt != NULL)
- strcpy(pro, prompt);
- else
- strcpy(pro, "Axis");
-
- strcat(pro, " ¿╠╛┌ E╣╧ñ╕/L│╠½ß/V╡°┤║/X╢b/Y╢b/Z╢b/<2┬I>: ");
-
- /* Get the method of specifying the axis */
-
- Prompt:
-
- sa_initget(0, "Entity View Xaxis Yaxis Zaxis Last 2points");
- success = sa_getpoint(NULL, pro, origin);
-
- if (success == RTKWORD) {
- sa_getinput(kw);
- } else if (success == RTNONE) {
- strcpy(kw, "2points");
- } else if (success == RTNORM) {
- goto Second_point;
- } else {
- goto End;
- }
-
- /* Switch according to the method of specifying the axis */
-
- if (strcmp(kw, "2points") == 0) {
-
- sa_initget(1, NULL);
- success = sa_getpoint(NULL, "╢bñW▓─ 1 ┬I: ", origin);
- if (success != RTNORM)
- goto End;
-
- Second_point:
- sa_initget(1, NULL);
- success = sa_getpoint(origin, "╢bñW▓─ 2 ┬I: ", zaxis);
- if (success != RTNORM)
- goto End;
-
- if (DISTANCE(origin, zaxis) < EPS) {
- ads_printf("\n¿Γ┬Iíu¼█ªPívíC\n\n");
- if (!lisp_input) {
- goto Second_point;
- } else {
- success = RTERROR;
- goto End;
- }
- }
- success = RTNORM;
-
- } else if ((strcmp(kw, "Xaxis") == 0) ||
- (strcmp(kw, "Yaxis") == 0) ||
- (strcmp(kw, "Zaxis") == 0) ) {
-
- char ax[2];
- char prompt[35];
-
- ax[0] = kw[0];
- ax[1] = EOS;
-
- strcpy(prompt, "┬Iª∞⌐≤ ");
- strcat(prompt, ax);
- strcat(prompt, " ╢b <0,0,0>: ");
-
- sa_initget(0, NULL);
- success = sa_getpoint(NULL, prompt, origin);
- if ((success != RTNORM) && (success != RTNONE))
- goto End;
-
- if (success == RTNONE) {
- origin[X] = origin[Y] = origin[Z] = 0.0;
- sa_cp2ucs(origin);
- }
-
- CPY_PNT(zaxis, origin);
- zaxis[kw[0] - /* NT */'X'] += 1.0;
- success = RTNORM;
-
- } else if (strcmp(kw, "View") == 0) {
-
- struct resbuf viewdir;
-
- sa_initget(0, NULL);
- success = sa_getpoint(NULL, "┬IÑXíu╡°┤║ñΦªVív¬║╢b <0,0,0>: ",
- origin);
- if (success == RTNONE) {
- origin[X] = origin[Y] = origin[Z] = 0.0;
- sa_cp2ucs(origin);
- } else if (success != RTNORM)
- goto End;
-
- ads_getvar("VIEWDIR", &viewdir);
- ADD_PNT(zaxis, origin, viewdir.resval.rpoint);
- success = RTNORM;
-
- } else if (strcmp(kw, "Last") == 0) {
-
- if (DISTANCE(last_axis.p1, last_axis.p2) == 0.0) {
- ads_printf("\nѲ½e¿├Ñ╝½ⁿ⌐wíu╢bívíC\n\n");
- if (!lisp_input) {
- goto Prompt;
- } else {
- success = RTERROR;
- goto End;
- }
- }
-
- sa_w2u(last_axis.p1, origin);
- sa_w2u(last_axis.p2, zaxis);
-
- success = RTNORM;
-
- } else { /*Entity*/
-
- if (lisp_input) {
- ads_printf("\n┐∙╗~:íuE╣╧ñ╕ív┐∩╢╡ñúÑi╕gÑ╤ AutoLISP ÑsÑ╬íC\n");
- success = RTERROR;
- goto End;
- }
-
- success = sa_get_cs_of_picked_entity(NULL, TRUE,
- origin, xaxis, yaxis, zaxis);
- if (success != RTNORM) {
- success = RTERROR;
- goto End;
- }
-
- sa_orientate_cs_upwards(origin, xaxis, yaxis, zaxis);
- success = RTNORM;
- }
-
- if (success == RTNORM) {
-
- CPY_PNT(p1, origin);
- CPY_PNT(p2, zaxis);
-
- sa_u2w(p1, last_axis.p1);
- sa_u2w(p2, last_axis.p2);
- }
-
- End:
- if (lisp_input) {
- lisp_error = (success != RTNORM);
- }
- sa_get_returned_RTCAN = (success == RTCAN);
-
- return(success);
- } /*sa_getaxis*/
-
-
- /****************************************************************************/
- /*.doc sa_getplane(external)*/
- /*+
- Function prompts for entering an arbitrary plane and returns three points
- on the plane. These three points may also be considered as defining
- a coordinate system:
-
- p1 ... origin
- p2 ... point on positive portion of X-axis
- p3 ... point in the halfplane of positive Y-axis
-
- Function returns one of the standard ADS result codes.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_getplane(prompt, plane_option, p1, p2, p3)
-
- char *prompt; /* Prompt (optional) */
- char *plane_option; /* NULL or "Entity", "3points" ... */
- ads_point p1, p2, p3; /* Returned points on the plane */
- {
- int success;
- char kw[10];
- ads_point origin, xaxis, yaxis, zaxis;
-
- if ((plane_option != NULL) && (plane_option[0] != EOS)) {
-
- /* Use directly the provided plane option */
-
- strcpy(kw, plane_option);
-
- } else {
- char pro[201];
-
- /* Prepare the prompt */
-
- if (prompt != NULL)
- strcpy(pro, prompt);
- else
- strcpy(pro, "Plane");
-
- strcat(pro, " ¿╠╛┌ E╣╧ñ╕/L│╠½ß/Z╢b/V╡°┤║/XY/YZ/ZX/<3┬I>: ");
-
- /* Get the method of specifying the plane */
- Prompt:
- sa_initget(0, "Entity View Zaxis XY YZ ZX Last 3points");
-
- success = sa_getpoint(NULL, pro, origin);
-
- if (success == RTKWORD) {
- sa_getinput(kw);
- } else if (success == RTNONE) {
- strcpy(kw, "3points");
- } else if (success == RTNORM) {
- goto Second_point;
- } else {
- goto End;
- }
- }
-
- /* Switch according the method of specifying the plane */
-
- if (strcmp(kw, "3points") == 0) {
-
- sa_initget(1, NULL);
- success = sa_getpoint(NULL, "¡▒ñW▓─ 1 ┬I: ", origin);
- if (success != RTNORM)
- goto End;
-
- Second_point:
- sa_initget(1, NULL);
- success = sa_getpoint(origin, "¡▒ñW▓─ 2 ┬I: ", xaxis);
- if (success != RTNORM)
- goto End;
-
- if (DISTANCE(origin, xaxis) < EPS) {
- ads_printf("\n▓─ 1 ┬I╗P▓─ 2 ┬Iíu¼█ªPívíC\n\n");
- if (!lisp_input) {
- goto Second_point;
- } else {
- success = RTERROR;
- goto End;
- }
- }
-
- Third_point:
- sa_initget(1, NULL);
- success = sa_getpoint(origin, "¡▒ñW▓─ 3 ┬I: ", yaxis);
- if (success != RTNORM)
- goto End;
-
- if (DISTANCE(xaxis, yaxis) < EPS) {
- ads_printf("\n▓─ 2 ┬I╗P▓─ 3 ┬Iíu¼█ªPívíC\n\n");
- if (!lisp_input) {
- goto Third_point;
- } else {
- success = RTERROR;
- goto End;
- }
- }
- if (DISTANCE(origin, yaxis) < EPS) {
- ads_printf("\n▓─ 1 ┬I╗P▓─ 3 ┬Iíu¼█ªPívíC\n\n");
- if (!lisp_input) {
- goto Third_point;
- } else {
- success = RTERROR;
- goto End;
- }
- }
- if (sa_points_are_collinear(origin, xaxis, yaxis)) {
- ads_printf("\nñT┬Iª@╜uíC\n\n");
- if (!lisp_input) {
- goto Third_point;
- } else {
- success = RTERROR;
- goto End;
- }
- }
- success = RTNORM;
-
- } else if (strcmp(kw, "Zaxis") == 0) {
-
- sa_initget(1, NULL);
- success = sa_getpoint(NULL, "¡▒ñW¬║┬I: ", origin);
- if (success != RTNORM)
- goto End;
-
- Zaxis_point:
- sa_initget(1, NULL);
- success = sa_getpoint(origin,
- "┬IÑXÑ¡¡▒¬║íuZ ╢bív(¬k╜u): ",
- zaxis);
- if (success != RTNORM)
- goto End;
-
- if (DISTANCE(origin, zaxis) < EPS) {
- ads_printf("\n¿Γ┬Iíu¼█ªPívíC\n\n");
- if (!lisp_input) {
- goto Zaxis_point;
- } else {
- success = RTERROR;
- goto End;
- }
- }
- sa_plane_from_point_and_normal(origin, zaxis, xaxis, yaxis);
- success = RTNORM;
-
- } else if (strcmp(kw, "View") == 0) {
-
- struct resbuf viewdir;
-
- sa_initget(0, NULL);
- success = sa_getpoint(NULL, "┬IÑXíu╡°┤║Ñ¡¡▒ív<0,0,0>: ", origin);
- if (success == RTNONE) {
- origin[X] = origin[Y] = origin[Z] = 0.0;
- sa_cp2ucs(origin);
- } else if (success != RTNORM)
- goto End;
-
- ads_getvar("VIEWDIR", &viewdir);
- ADD_PNT(zaxis, origin, viewdir.resval.rpoint);
-
- /* Get the 'xaxis' and 'yaxis' aligned with x,y axes of the screen */
-
- {
- struct resbuf ucs, dcs;
- ads_point xv, yv;
-
- xv[X] = 1.0;
- xv[Y] = 0.0;
- xv[Z] = 0.0;
-
- yv[X] = 0.0;
- yv[Y] = 1.0;
- yv[Z] = 0.0;
-
- ucs.restype = RTSHORT;
- ucs.resval.rint = 1;
- dcs.restype = RTSHORT;
- dcs.resval.rint = 2;
-
- success = ads_trans(xv, &dcs, &ucs, TRUE, xv);
- if (success != RTNORM)
- goto End;
-
- success = ads_trans(yv, &dcs, &ucs, TRUE, yv);
- if (success != RTNORM)
- goto End;
-
- ADD_PNT(xaxis, origin, xv);
- ADD_PNT(yaxis, origin, yv);
- }
- success = RTNORM;
-
- } else if ((strcmp(kw, "XY") == 0) ||
- (strcmp(kw, "YZ") == 0) ||
- (strcmp(kw, "ZX") == 0) ) {
-
- int i;
- char pl[3];
- char prompt[35];
-
- pl[0] = kw[0];
- pl[1] = kw[1];
- pl[2] = EOS;
-
- strcpy(prompt, "┬IÑX ");
- strcat(prompt, pl);
- strcat(prompt, " Ñ¡¡▒ <0,0,0>: ");
-
- sa_initget(0, NULL);
- success = sa_getpoint(NULL, prompt, origin);
- if ((success != RTNORM) && (success != RTNONE))
- goto End;
-
- if (success == RTNONE) {
- origin[X] = origin[Y] = origin[Z] = 0.0;
- sa_cp2ucs(origin);
- }
-
- CPY_PNT(xaxis, origin);
- CPY_PNT(yaxis, origin);
-
- i = kw[0] - /* NT */'X';
-
- xaxis[i] += 1.0;
- yaxis[(i+1)%3] += 1.0;
- success = RTNORM;
-
- } else if (strcmp(kw, "Last") == 0) {
-
- if ((DISTANCE(last_plane.p1, last_plane.p2) == 0.0) &&
- (DISTANCE(last_plane.p1, last_plane.p3) == 0.0) ) {
-
- ads_printf("\nѲ½e¿├Ñ╝½ⁿ⌐wíuÑ¡¡▒ívíC\n\n");
- if (!lisp_input) {
- goto Prompt;
- } else {
- success = RTERROR;
- goto End;
- }
- }
-
- sa_w2u(last_plane.p1, origin);
- sa_w2u(last_plane.p2, xaxis );
- sa_w2u(last_plane.p3, yaxis );
-
- success = RTNORM;
-
- } else if (strcmp(kw, "Entity") == 0) {
-
- if (lisp_input) {
- ads_printf("┐∙╗~:íuE╣╧ñ╕ív┐∩╢╡ñúÑi╕gÑ╤ AutoLISP ÑsÑ╬íC\n");
- success = RTERROR;
- goto End;
- }
-
- success = sa_get_cs_of_picked_entity(NULL, FALSE,
- origin, xaxis, yaxis, zaxis);
- if (success != RTNORM)
- goto End;
- success = RTNORM;
-
- } else {
- success = RTERROR;
- goto End;
- }
-
- End:
- if (success == RTNORM) {
-
- CPY_PNT(p1,origin);
- CPY_PNT(p2,xaxis);
- CPY_PNT(p3,yaxis);
-
- sa_u2w(p1, last_plane.p1);
- sa_u2w(p2, last_plane.p2);
- sa_u2w(p3, last_plane.p3);
- }
-
- if (lisp_input) {
- lisp_error = (success != RTNORM);
- }
- sa_get_returned_RTCAN = (success == RTCAN);
-
- return(success);
- } /*sa_getplane*/
-
-
- /****************************************************************************/
- /*.doc sa_set_cp(external)*/
- /*+
- Function prompts the user to enter a CP (Construction Plane) and sets
- current UCS according to this CP. Function may be invoked consecutively
- several times.
-
- This function may also be called from any sa_getxxx() function to change
- the UCS. To do so, the keyword "Baseplane" must be provided as the first
- keyword in sa_initget's list of accepted keywords. Then, if the user
- types "Baseplane", sa_set_cp() function is called. Example:
-
- sa_initget(1 + 2, "Baseplane Aaa Bbb");
- sa_getpoint(...) <-- If the user types Baseplane, sa_set_cp() is called
-
- To return UCS back, that is to undo the effect of sa_set_cp(),
- call sa_return_cp().
-
- Note: See the AME R2 manual for examples of using the Baseplane option
- for creating the primitive solids.
-
- Function returns one of the standard ADS result codes.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_set_cp(prompt)
-
- char *prompt; /* Prompt (optional) */
- {
- int success;
- ads_point p1, p2, p3;
-
- success = sa_getplane(prompt, NULL, p1, p2, p3);
- if (success != RTNORM)
- goto End;
-
- sa_save_acad_vars();
- success = ads_command(RTSTR, /* NT */"_.UCS", RTSTR, /* NT */"_3",
- RT3DPOINT, p1, RT3DPOINT, p2, RT3DPOINT, p3, 0);
- sa_restore_acad_vars();
-
- if (success != RTNORM)
- goto End;
-
- setcp_level++;
- ucs_level ++;
-
- /* Set 'UCSICON' variable to "On" and "Origin" */
-
- if (setcp_level == 1) {
-
- struct resbuf ucsi;
-
- ads_getvar("UCSICON", &ucsicon);
- ucsi.restype = RTSHORT;
- ucsi.resval.rint = 3; /* "On" and "Origin" */
- ads_setvar("UCSICON",&ucsi);
- }
- success = RTNORM;
-
- End:
- if (lisp_input) {
- lisp_error = (success != RTNORM);
- }
- sa_get_returned_RTCAN = (success == RTCAN);
- return(success);
- } /*sa_set_cp*/
-
-
- /****************************************************************************/
- /*.doc sa_return_cp(external)*/
- /*+
- Inverts the efect of ALL sa_set_cp() calls, that it it returns UCS to its
- original position before the first sa_set_cp() was used.
-
- Function returns one of the standard ADS result codes.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_return_cp()
- {
- int success;
- int i;
- struct resbuf ucsi;
-
- if (setcp_level > 0) {
-
- /* Hide UCSICON to avoid jumping */
-
- ucsi.restype = RTSHORT;
- ucsi.resval.rint = 0;
- ads_setvar("UCSICON", &ucsi);
-
- sa_cmdecho_off();
- for (i = 0; i < setcp_level; i++) {
-
- success = ads_command(RTSTR, /* NT */"_.UCS", RTSTR,
- /* NT */"_PREV", 0);
- if (success != RTNORM)
- break;
- }
- sa_cmdecho_back();
-
- ads_setvar("UCSICON", &ucsicon);
- }
-
- setcp_level = 0;
- ucs_level = 0;
-
- return(success);
- } /*sa_return_cp*/
-
-
- /****************************************************************************/
- /*.doc sa_cp2ucs(external)*/
- /*+
- If CP was used in the last sa_getxxx() function, then this function
- converts point 'p' expressed in the coordinate sytem of the last CP to
- current UCS, otherwise leaves the point unchanged.
-
- This function can be used, for example, when sa_getpoint() function
- returns RTNONE and you want to use default point coordinates with
- respect to the CP used. Then the default coordinates must be transformed
- by the sa_cp2ucs() function.
-
- Function returns one of the standard ADS result codes.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_cp2ucs(p)
-
- ads_point p;
- {
- int success;
- ads_point pp1, pp2, pp3;
-
- if (!cp_used || (p == NULL) ||
- sa_points_are_collinear(last_plane.p1, last_plane.p2, last_plane.p3))
- {
- return(RTNORM);
- }
-
- /* Convert the last plane from WCS to UCS (because UCS command expects
- coordinates in current UCS).
- */
-
- sa_w2u(last_plane.p1, pp1);
- sa_w2u(last_plane.p2, pp2);
- sa_w2u(last_plane.p3, pp3);
-
- /* Set UCS to align with the last plane */
-
- sa_save_acad_vars();
- success = ads_command(RTSTR, /* NT */"_.UCS", RTSTR, /* NT */"_3P",
- RT3DPOINT, pp1, RT3DPOINT, pp2, RT3DPOINT, pp3,
- 0);
-
- /* Convert the given point 'p' from CP (now current UCS) to WCS */
-
- sa_u2w(p, p);
-
- /* Return UCS back */
-
- ads_command(RTSTR, /* NT */"_.UCS", RTSTR, /* NT */"_PREV", 0);
- sa_restore_acad_vars();
-
- if (success != RTNORM)
- return(RTERROR);
-
- /* Convert 'p' from WCS to current UCS */
-
- sa_w2u(p, p);
-
- return(RTNORM);
- } /*sa_cp2ucs*/
-
-
- /****************************************************************************/
- /*.doc sa_ssget(external)*/
- /*+
- Enhanced ads_ssget() function providing keyboard/AutoLISP input
- redirection.
-
- Note:
-
- The sa_ssget() function supports the Implied selection set better than
- the standard ads_ssget(). The sa_init_input() function reads the implied
- selection set and keeps it in the global variable implied_selset. The
- global integer variable implied_selset_exists is set to TRUE if there was
- an implied selection set. Then the first call to sa_ssget() uses this
- stored selection set and sets the global variable implied_selset_exists
- to FALSE.
-
- The advantage of this solution is that you may execute any number of
- ads_command() calls before actually calling sa_ssget() and still you
- can get the implied selection set. Using the standard ads_ssget() wouldn't
- work as any call to ads_command() clears the implied selection set and
- ads_ssget() wouldn't be able to get it.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_ssget(str, pt1, pt2, filter, ss)
-
- char *str;
- void *pt1;
- ads_point pt2;
- struct resbuf *filter;
- ads_name ss;
- {
- int success;
- int type;
- int NULL_params;
- int implied_required = FALSE;
- char kw[MAX_STR_LEN];
-
- NULL_params = ((str == NULL) && (pt1 == NULL) && (pt2 == NULL) &&
- (filter == NULL));
-
- /* Check whether the input 'str' is "IMPLIED" */
-
- if ((str != NULL) && (strlen(str) <= 7)) {
- int i;
- char imp[8];
-
- strcpy(imp, "IMPLIED");
- implied_required = TRUE;
- for (i = 0 ; i < strlen(str); i++)
- if (ads_toupper(str[i]) != imp[i]) {
- implied_required = FALSE;
- break;
- }
- }
-
- if (implied_required) {
- if (implied_selset_exists) {
- ads_name_set(implied_selset, ss);
- implied_selset_exists = FALSE;
- success = RTNORM;
- } else {
- success = RTERROR;
- }
-
- } else if (implied_selset_exists && NULL_params) {
- ads_name_set(implied_selset, ss);
- implied_selset_exists = FALSE;
- success = RTNORM;
-
- } else if (!lisp_input || !NULL_params) {
- success = ads_ssget(str, pt1, pt2, filter, ss);
-
- } else {
-
- if (lisp_error)
- return(RTERROR);
-
- initget_buffer.val = 0;
- if (is_null_argument(&success))
- goto End;
-
- type = current_rb->restype;
- switch (type) {
-
- case RTPICKS:
- ads_name_set(current_rb->resval.rlname, ss);
- success = RTNORM;
- break;
-
- case RTENAME:
- success = ads_ssadd(current_rb->resval.rlname, NULL, ss);
- if (success != RTNORM)
- success = RTERROR;
- break;
-
- case RTSTR:
- check_if_string_is_keyword(current_rb->resval.rstring, kw);
-
- if (kw[0] != EOS) {
- strcpy(initget_buffer.kw, kw);
- success = RTKWORD;
- } else {
- ads_printf("\n┐∙╗~: ╡L¬k┐δ├╤¬║íu├÷┴Σªr %sívíC\n\n",
- current_rb->resval.rstring);
- success = RTERROR;
- }
- break;
-
- default:
- ads_printf("\n┐∙╗~: └│¼░íu┐∩╢░ (selection set)ívíC\n\n");
- success = RTERROR;
- break;
- } /*switch*/
- }
-
- End:
- if (lisp_input) {
- if (current_rb != NULL)
- current_rb = current_rb->rbnext;
-
- if (!implied_required) {
- lisp_error = ((success != RTNORM) &&
- (success != RTNONE) &&
- (success != RTKWORD));
- }
- }
-
- if (success == RTNORM) {
- ads_name_set(ss, ssget_ss[no_of_ssget_ss]);
- no_of_ssget_ss++;
- }
-
- sa_get_returned_RTCAN = (success == RTCAN);
-
- return(success);
- } /*sa_ssget*/
-
-
- /****************************************************************************/
- /*.doc sa_entsel(external)*/
- /*+
- Enhanced ads_entsel() function supporting keyboard/AutoLISP input
- redirection.
-
- When reading input from AutoLISP, either an single entity name or
- a list (entity_name pickpt) is accepted. If only an entity name is
- provided, then the pickpoint 'ptres' is not assigned.
- -*/
- /****************************************************************************/
-
-
- int
- /*FCN*/sa_entsel(str, entres, ptres)
-
- char *str;
- ads_name entres;
- ads_point ptres;
- {
- int success;
- int type;
- int getpoint_called = FALSE;
- char kw[MAX_STR_LEN];
-
- if (!lisp_input) {
- success = ads_entsel(str, entres, ptres);
-
- } else {
-
- if (lisp_error)
- return(RTERROR);
-
- if (current_rb == NULL) {
- ads_printf("\n┐∙╗~:íuñ▐╝╞ív╣Lñ╓íC\n\n");
- success = RTERROR;
- goto End;
- }
-
- type = current_rb->restype;
- switch (type) {
-
- case RTENAME:
- /* Entity name provided */
-
- ads_name_set(current_rb->resval.rlname, entres);
-
- success = RTNORM;
- break;
-
- case RTLB:
- /* A list (entity_name point) provided */
-
- current_rb = current_rb->rbnext;
- if ((current_rb != NULL) && (current_rb->restype == RTENAME)) {
- ads_name_set(current_rb->resval.rlname, entres);
- } else {
- ads_printf("\n┐∙╗~: └│¼░ (entity_name pickpt) ªΩªCíC\n\n");
- success = RTERROR;
- break;
- }
-
- current_rb = current_rb->rbnext;
- if ((current_rb != NULL) &&
- ((current_rb->restype == RT3DPOINT) ||
- (current_rb->restype == RTPOINT))) {
- ads_point_set(ptres, current_rb->resval.rpoint);
- } else {
- ads_printf("\n┐∙╗~: └│¼░ (entity_name pickpt) ªΩªCíC\n\n");
- success = RTERROR;
- break;
- }
-
- current_rb = current_rb->rbnext;
- if ((current_rb == NULL) || (current_rb->restype != RTLE)) {
- ads_printf("\n┐∙╗~: └│¼░ (entity_name pickpt) ªΩªCíC\n\n");
- success = RTERROR;
- break;
- }
-
- success = RTNORM;
- break;
-
- case RTSTR:
- check_if_string_is_keyword(current_rb->resval.rstring, kw);
-
- if (kw[0] != EOS) {
- strcpy(initget_buffer.kw, kw);
- success = RTKWORD;
- } else {
- ads_printf("\n┐∙╗~: ╡L¬k┐δ├╤íu├÷┴Σªr %sívíC\n\n",
- current_rb->resval.rstring);
- success = RTERROR;
- }
- break;
-
- default:
- ads_printf("\n┐∙╗~: └│¼░íu╣╧ñ╕ívíC\n\n");
- success = RTERROR;
- goto End;
- } /*switch*/
- }
-
- End:
- if (lisp_input) {
- if ((current_rb != NULL) && !getpoint_called)
- current_rb = current_rb->rbnext;
- lisp_error = ((success != RTNORM) && (success != RTKWORD));
- }
-
- sa_get_returned_RTCAN = (success == RTCAN);
-
- return(success);
- } /*sa_entsel*/
-
-
- /****************************************************************************/
- /*.doc se_reset_last_axis_and_plane(external)*/
- /*+
- Resets the values of the last_axis and last_plane static variables to
- "no axis" and "no plane".
- -*/
- /****************************************************************************/
-
-
- void
- /*FCN*/sa_reset_last_axis_and_plane()
- {
- ads_point zero;
- zero[X] = zero[Y] = zero[Z] = 0.0;
-
- CPY_PNT(last_axis.p1, zero);
- CPY_PNT(last_axis.p2, zero);
-
- CPY_PNT(last_plane.p1, zero);
- CPY_PNT(last_plane.p2, zero);
- CPY_PNT(last_plane.p3, zero);
- } /*sa_reset_last_axis_and_plane*/
-