void attrib_add(char *a, int *prep) { char *p; if (!a) { bu_log("attrib_add null arg\n"); return; /* null char ptr */ } p = strtok(a, "\t "); while (p) { /* make sure we have space */ if (!a_tab.attrib || a_tab.attrib_use >= (a_tab.attrib_cnt-1)) { a_tab.attrib_cnt += 16; a_tab.attrib = (char **)bu_realloc(a_tab.attrib, a_tab.attrib_cnt * sizeof(char *), "attrib_tab"); } /* add the attribute name(s) */ a_tab.attrib[a_tab.attrib_use] = bu_strdup(db5_standard_attribute(db5_standardize_attribute(p))); /* bu_log("attrib[%d]=\"%s\"\n", attrib_use, attrib[attrib_use]); */ a_tab.attrib[++a_tab.attrib_use] = (char *)NULL; p = strtok((char *)NULL, "\t "); *prep = 1; } }
/* * update the v5 combination tree with the new names. * DESTRUCTIVE RECURSIVE */ int copy_v5_comb_tree(union tree *tree, int idx) { char *buf; switch (tree->tr_op) { case OP_UNION: case OP_INTERSECT: case OP_SUBTRACT: case OP_XOR: /* copy right */ copy_v5_comb_tree(tree->tr_b.tb_right, idx); case OP_NOT: case OP_GUARD: case OP_XNOP: /* copy left */ copy_v5_comb_tree(tree->tr_b.tb_left, idx); break; case OP_DB_LEAF: buf = tree->tr_l.tl_name; tree->tr_l.tl_name = bu_strdup(bu_vls_addr(&obj_list.names[index_in_list(obj_list, buf)].dest[idx])); bu_free(buf, "node name"); break; default: bu_log("clone v5 - OPCODE NOT IMPLEMENTED: %d\n", tree->tr_op); return -1; } return 0; }
HIDDEN int extract_path(struct bu_vls *path, const char *input) { int ret = 0; struct bu_vls wpath = BU_VLS_INIT_ZERO; char *colon_pos = NULL; char *inputcpy = NULL; if (UNLIKELY(!input)) return 0; inputcpy = bu_strdup(input); colon_pos = strchr(inputcpy, ':'); if (colon_pos) { bu_vls_sprintf(&wpath, "%s", input); bu_vls_nibble(&wpath, strlen(input) - strlen(colon_pos) + 1); if (path && bu_vls_strlen(&wpath) > 0) { ret = 1; bu_vls_sprintf(path, "%s", bu_vls_addr(&wpath)); } bu_vls_free(&wpath); } else { if (path) bu_vls_sprintf(path, "%s", input); ret = 1; } if (inputcpy) bu_free(inputcpy, "input copy"); if (path && !(bu_vls_strlen(path) > 0)) return 0; return ret; }
/* restore a combination that was created during save_comb() */ static void restore_comb(struct ged *gedp, struct directory *dp, const char *oldname) { const char *av[4]; char *name; if (!gedp || !dp || !oldname) return; /* get rid of previous comb */ name = bu_strdup(dp->d_namep); av[0] = "kill"; av[1] = name; av[2] = NULL; av[3] = NULL; (void)ged_kill(gedp, 2, (const char **)av); av[0] = "mv"; av[1] = oldname; av[2] = name; (void)ged_move(gedp, 3, (const char **)av); bu_free(name, "bu_strdup'd name"); }
void diff_init_result(struct diff_result *result, const struct bn_tol *curr_diff_tol, const char *obj_name) { if (!result) return; if (obj_name) { result->obj_name = bu_strdup(obj_name); } else { result->obj_name = NULL; } result->dp_left = RT_DIR_NULL; result->dp_ancestor = RT_DIR_NULL; result->dp_right = RT_DIR_NULL; result->param_state = DIFF_EMPTY; result->attr_state = DIFF_EMPTY; BU_GET(result->diff_tol, struct bn_tol); if (curr_diff_tol) { (result)->diff_tol->magic = BN_TOL_MAGIC; (result)->diff_tol->dist = curr_diff_tol->dist; (result)->diff_tol->dist_sq = curr_diff_tol->dist_sq; (result)->diff_tol->perp = curr_diff_tol->perp; (result)->diff_tol->para = curr_diff_tol->para; } else { BN_TOL_INIT(result->diff_tol); } BU_GET(result->param_diffs, struct bu_ptbl); BU_GET(result->attr_diffs, struct bu_ptbl); BU_PTBL_INIT(result->param_diffs); BU_PTBL_INIT(result->attr_diffs); }
int mk_extrusion( struct rt_wdb *fp, const char *name, const char *sketch_name, const point_t V, const vect_t h, const vect_t u_vec, const vect_t v_vec, int keypoint) { struct rt_extrude_internal *extr; BU_ALLOC(extr, struct rt_extrude_internal); extr->magic = RT_EXTRUDE_INTERNAL_MAGIC; extr->sketch_name = bu_strdup(sketch_name); VMOVE(extr->V, V); VMOVE(extr->h, h); VMOVE(extr->u_vec, u_vec); VMOVE(extr->v_vec, v_vec); extr->keypoint = keypoint; extr->skt = (struct rt_sketch_internal *)NULL; return wdb_export(fp, name, (void *)extr, ID_EXTRUDE, mk_conv2mm); }
/* i n s e r t ( ) Insert each member of the table of contents 'toc_list' which matches one of the arguments into the current list 'curr_list'. */ int insert( char *args[], int ct ) { register int i, j, nomatch; /* For each argument (does not include args[0]). */ for ( i = 1; i < ct; i++ ) { /* If object is in table of contents, insert in current list. */ nomatch = YES; for ( j = 0; j < ndir; j++ ) { if ( match( args[i], toc_list[j] ) ) { nomatch = NO; /* Allocate storage for string. */ curr_list[curr_ct++] = bu_strdup(toc_list[j]); } } if ( nomatch ) (void) fprintf( stderr, "Object \"%s\" not found.\n", args[i] ); } return curr_ct; }
void namecvt(int n, char **cp, int c) { char str[16]; sprintf(str, "%c%d%.13s", (char)c, n, name_it); *cp = bu_strdup(str); }
int ged_bot_flip(struct ged *gedp, int argc, const char *argv[]) { int i; struct directory *dp; struct rt_db_internal intern; struct rt_bot_internal *bot; static const char *usage = "bot [bot2 bot3 ...]"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_READ_ONLY(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } for (i = 1; i < argc; ++i) { /* Skip past any path elements */ char *obj = (char *)bu_calloc(strlen(argv[i]), sizeof(char), "ged_bot_flip obj"); bu_basename(obj, argv[i]); if (BU_STR_EQUAL(obj, ".")) { /* malformed path, lookup using exactly what was provided */ bu_free(obj, "free bu_basename"); obj = bu_strdup(argv[i]); } if ((dp = db_lookup(gedp->ged_wdbp->dbip, obj, LOOKUP_QUIET)) == RT_DIR_NULL) { bu_vls_printf(gedp->ged_result_str, "%s: db_lookup(%s) error\n", argv[0], obj); } else { GED_DB_GET_INTERNAL(gedp, &intern, dp, bn_mat_identity, &rt_uniresource, GED_ERROR); if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_BOT) { bu_vls_printf(gedp->ged_result_str, "%s: %s is not a BOT solid!\n", argv[0], obj); } else { bot = (struct rt_bot_internal *)intern.idb_ptr; rt_bot_flip(bot); GED_DB_PUT_INTERNAL(gedp, dp, &intern, gedp->ged_wdbp->wdb_resp, GED_ERROR); } } bu_free(obj, "free obj"); } return GED_OK; }
/* * The only argument is the name of the database file. */ void ph_dirbuild(struct pkg_conn *UNUSED(pc), char *buf) { long max_argc = 0; char **argv = NULL; struct rt_i *rtip = NULL; size_t n = 0; if (debug) fprintf(stderr, "ph_dirbuild: %s\n", buf); for (n = 0; n < strlen(buf); n++) { if (isspace((int)buf[n])) max_argc++; } argv = (char **)bu_calloc(max_argc+1, sizeof(char *), "alloc argv"); if ((bu_argv_from_string(argv, max_argc, buf)) <= 0) { /* No words in input */ (void)free(buf); bu_free(argv, "free argv"); return; } if (seen_dirbuild) { bu_log("ph_dirbuild: MSG_DIRBUILD already seen, ignored\n"); (void)free(buf); bu_free(argv, "free argv"); return; } title_file = bu_strdup(argv[0]); bu_free(argv, "free argv"); /* Build directory of GED database */ if ((rtip=rt_dirbuild(title_file, idbuf, sizeof(idbuf))) == RTI_NULL) bu_exit(2, "ph_dirbuild: rt_dirbuild(%s) failure\n", title_file); APP.a_rt_i = rtip; seen_dirbuild = 1; /* * Initialize all the per-CPU memory resources. * Go for the max, as TCL interface may change npsw as we run. */ for (n=0; n < MAX_PSW; n++) { rt_init_resource(&resource[n], n, rtip); bn_rand_init(resource[n].re_randptr, n); } if (pkg_send(MSG_DIRBUILD_REPLY, idbuf, strlen(idbuf)+1, pcsrv) < 0) fprintf(stderr, "MSG_DIRBUILD_REPLY error\n"); }
/** * B U _ D I R N A M E * * Given a filesystem pathname, return a pointer to a dynamic string * which is the parent directory of that file/directory. * * /usr/dir/file /usr/dir * @n /usr/dir/ /usr * @n /usr/file /usr * @n /usr/ / * @n /usr / * @n / / * @n . . * @n .. . * @n usr . * @n a/b a * @n a/ . * @n ../a/b ../a */ char * bu_dirname(const char *cp) { char *ret; char *slash; int len; /* Special cases */ if ( cp == NULL ) return bu_strdup("."); if ( strcmp( cp, "/" ) == 0 ) return bu_strdup("/"); if ( strcmp( cp, "." ) == 0 || strcmp( cp, ".." ) == 0 || strrchr(cp, '/') == NULL ) return bu_strdup("."); /* Make a duplicate copy of the string, and shorten it in place */ ret = bu_strdup(cp); /* A trailing slash doesn't count */ len = strlen(ret); if ( ret[len-1] == '/' ) ret[len-1] = '\0'; /* If no slashes remain, return "." */ if ( (slash = strrchr(ret, '/')) == NULL ) { bu_free( ret, "bu_dirname" ); return bu_strdup("."); } /* Remove trailing slash, unless it's at front */ if ( slash == ret ) ret[1] = '\0'; /* ret == "/" */ else *slash = '\0'; return ret; }
void fast4_arg_process(const char *args) { if (!args) return; char *input = bu_strdup(args); char **argv = (char **)bu_calloc(strlen(args) + 1, sizeof(char *), "argv array"); int argc = bu_argv_from_string(argv, strlen(args), input); option::Stats stats(Fast4Usage, argc, argv); option::Option *options = (option::Option *)bu_calloc(stats.options_max, sizeof(option::Option), "options"); option::Option *buffer= (option::Option *)bu_calloc(stats.buffer_max, sizeof(option::Option), "options"); option::Parser parse(Fast4Usage, argc, argv, options, buffer); if (options[FAST4_WARN_DEFAULT_NAMES]) { bu_log("FASTGEN 4 opt: %s:%s\n", options[FAST4_WARN_DEFAULT_NAMES].name, options[FAST4_WARN_DEFAULT_NAMES].arg); } bu_free(input, "input"); bu_free(options, "free options"); bu_free(buffer, "free buffer"); }
HIDDEN void reassemble_argstr(struct bu_vls *instr, struct bu_vls *outstr, option::Option *unknowns) { for (option::Option* opt = unknowns; opt; opt = opt->next()) { int input_only = 0; int output_only = 0; char *inputcpy = NULL; if (!instr || !outstr) return; inputcpy = bu_strdup(opt->name); if (!bu_strncmp(inputcpy, "--in-", 5)) input_only = 1; if (!bu_strncmp(inputcpy, "--out-", 5)) output_only = 1; char *equal_pos = strchr(inputcpy, '='); if (equal_pos) { struct bu_vls vopt = BU_VLS_INIT_ZERO; struct bu_vls varg = BU_VLS_INIT_ZERO; bu_vls_sprintf(&vopt, "%s", inputcpy); bu_vls_trunc(&vopt, -1 * strlen(equal_pos)); bu_vls_sprintf(&varg, "%s", inputcpy); bu_vls_nibble(&varg, strlen(inputcpy) - strlen(equal_pos) + 1); if (!output_only) { (bu_vls_strlen(&vopt) == 1) ? bu_vls_printf(instr, "-%s ", bu_vls_addr(&vopt)) : bu_vls_printf(instr, "%s ", bu_vls_addr(&vopt)); if (bu_vls_strlen(&varg)) bu_vls_printf(instr, "%s ", bu_vls_addr(&varg)); } if (!input_only) { (bu_vls_strlen(&vopt) == 1) ? bu_vls_printf(outstr, "-%s ", bu_vls_addr(&vopt)) : bu_vls_printf(outstr, "%s ", bu_vls_addr(&vopt)); if (bu_vls_strlen(&varg)) bu_vls_printf(outstr, "%s ", bu_vls_addr(&varg)); } bu_vls_free(&vopt); bu_vls_free(&varg); } else { if (!output_only) { (strlen(opt->name) == 1) ? bu_vls_printf(instr, "-%s ", opt->name) : bu_vls_printf(instr, "%s ", opt->name); if (opt->arg) bu_vls_printf(instr, "%s ", opt->arg); } if (!input_only) { (strlen(opt->name) == 1) ? bu_vls_printf(outstr, "-%s ", opt->name) : bu_vls_printf(outstr, "%s ", opt->name); if (opt->arg) bu_vls_printf(outstr, "%s ", opt->arg); } } bu_free(inputcpy, "input cpy"); } }
static void adjust_names(union tree *trp, struct db_i *dbip, Tcl_HashTable *name_tbl, Tcl_HashTable *used_names_tbl, struct ged_concat_data *cc_data) { char *new_name; if (trp == NULL) { return; } switch (trp->tr_op) { case OP_DB_LEAF: new_name = get_new_name(trp->tr_l.tl_name, dbip, name_tbl, used_names_tbl, cc_data); if (new_name) { bu_free(trp->tr_l.tl_name, "leaf name"); trp->tr_l.tl_name = bu_strdup(new_name); } break; case OP_UNION: case OP_INTERSECT: case OP_SUBTRACT: case OP_XOR: adjust_names(trp->tr_b.tb_left, dbip, name_tbl, used_names_tbl, cc_data); adjust_names(trp->tr_b.tb_right, dbip, name_tbl, used_names_tbl, cc_data); break; case OP_NOT: case OP_GUARD: case OP_XNOP: adjust_names(trp->tr_b.tb_left, dbip, name_tbl, used_names_tbl, cc_data); break; } }
/* * Each word in the command buffer is the name of a treetop. */ void ph_gettrees(struct pkg_conn *UNUSED(pc), char *buf) { size_t n = 0; long max_argc = 0; char **argv = NULL; int argc = 0; struct rt_i *rtip = APP.a_rt_i; RT_CK_RTI(rtip); if (debug) fprintf(stderr, "ph_gettrees: %s\n", buf); /* Copy values from command line options into rtip */ rtip->useair = use_air; if (rt_dist_tol > 0) { rtip->rti_tol.dist = rt_dist_tol; rtip->rti_tol.dist_sq = rt_dist_tol * rt_dist_tol; } if (rt_perp_tol > 0) { rtip->rti_tol.perp = rt_perp_tol; rtip->rti_tol.para = 1 - rt_perp_tol; } for (n = 0; n < strlen(buf); n++) { if (isspace((int)buf[n])) max_argc++; } argv = (char **)bu_calloc(max_argc+1, sizeof(char *), "alloc argv"); if ((argc = bu_argv_from_string(argv, max_argc, buf)) <= 0) { /* No words in input */ (void)free(buf); bu_free(argv, "free argv"); return; } title_obj = bu_strdup(argv[0]); if (rtip->needprep == 0) { /* First clean up after the end of the previous frame */ if (debug)bu_log("Cleaning previous model\n"); view_end(&APP); view_cleanup(rtip); rt_clean(rtip); if (rdebug&RDEBUG_RTMEM_END) bu_prmem("After rt_clean"); } /* Load the desired portion of the model */ if (rt_gettrees(rtip, argc, (const char **)argv, npsw) < 0) fprintf(stderr, "rt_gettrees(%s) FAILED\n", argv[0]); bu_free(argv, "free argv"); /* In case it changed from startup time via an OPT command */ if (npsw > 1) { RTG.rtg_parallel = 1; } else RTG.rtg_parallel = 0; seen_gettrees = 1; (void)free(buf); prepare(); /* Acknowledge that we are ready */ if (pkg_send(MSG_GETTREES_REPLY, title_obj, strlen(title_obj)+1, pcsrv) < 0) fprintf(stderr, "MSG_START error\n"); }
struct db_i * db_open(const char *name, const char *mode) { register struct db_i *dbip = DBI_NULL; register int i; char **argv; if (name == NULL) return DBI_NULL; if (RT_G_DEBUG & DEBUG_DB) { bu_log("db_open(%s, %s)\n", name, mode); } if (mode && mode[0] == 'r' && mode[1] == '\0') { /* Read-only mode */ struct bu_mapped_file *mfp; mfp = bu_open_mapped_file(name, "db_i"); if (mfp == NULL) { if (RT_G_DEBUG & DEBUG_DB) { bu_log("db_open(%s) FAILED, unable to open as a mapped file\n", name); } return DBI_NULL; } /* Is this a re-use of a previously mapped file? */ if (mfp->apbuf) { dbip = (struct db_i *)mfp->apbuf; RT_CK_DBI(dbip); dbip->dbi_uses++; /* * decrement the mapped file reference counter by 1, * references are already counted in dbip->dbi_uses */ bu_close_mapped_file(mfp); if (RT_G_DEBUG & DEBUG_DB) { bu_log("db_open(%s) dbip=%p: reused previously mapped file\n", name, (void *)dbip); } return dbip; } BU_ALLOC(dbip, struct db_i); dbip->dbi_mf = mfp; dbip->dbi_eof = (off_t)mfp->buflen; dbip->dbi_inmem = mfp->buf; dbip->dbi_mf->apbuf = (void *)dbip; /* Do this too, so we can seek around on the file */ if ((dbip->dbi_fp = fopen(name, "rb")) == NULL) { if (RT_G_DEBUG & DEBUG_DB) { bu_log("db_open(%s) FAILED, unable to open file for reading\n", name); } bu_free((char *)dbip, "struct db_i"); return DBI_NULL; } dbip->dbi_read_only = 1; } else { /* Read-write mode */ BU_ALLOC(dbip, struct db_i); dbip->dbi_eof = (off_t)-1L; if ((dbip->dbi_fp = fopen(name, "r+b")) == NULL) { if (RT_G_DEBUG & DEBUG_DB) { bu_log("db_open(%s) FAILED, unable to open file for reading/writing\n", name); } bu_free((char *)dbip, "struct db_i"); return DBI_NULL; } dbip->dbi_read_only = 0; } /* Initialize fields */ for (i = 0; i < RT_DBNHASH; i++) dbip->dbi_Head[i] = RT_DIR_NULL; dbip->dbi_local2base = 1.0; /* mm */ dbip->dbi_base2local = 1.0; dbip->dbi_title = (char *)0; dbip->dbi_uses = 1; /* FIXME: At some point, expand argv search paths with * getenv("BRLCAD_FILE_PATH") paths */ /* intentionally acquiring dynamic memory here since we set * dbip->dbi_filepath to argv. arg values and array memory are * released during db_close. */ argv = (char **)bu_malloc(3 * sizeof(char *), "dbi_filepath[3]"); argv[0] = bu_strdup("."); argv[1] = bu_dirname(name); argv[2] = NULL; dbip->dbi_filepath = argv; #if !defined(_WIN32) || defined(__CYGWIN__) /* If not a full path */ if (argv[1][0] != '/') { struct bu_vls fullpath = BU_VLS_INIT_ZERO; bu_free((void *)argv[1], "db_open: argv[1]"); argv[1] = getcwd((char *)NULL, (size_t)MAXPATHLEN); /* Something went wrong and we didn't get the CWD. So, * free up any memory allocated here and return DBI_NULL */ if (argv[1] == NULL) { if (dbip->dbi_mf) { bu_close_mapped_file(dbip->dbi_mf); bu_free_mapped_files(0); dbip->dbi_mf = (struct bu_mapped_file *)NULL; } if (dbip->dbi_fp) { fclose(dbip->dbi_fp); } bu_free((void *)argv[0], "db_open: argv[0]"); bu_free((void *)argv, "db_open: argv"); bu_free((char *)dbip, "struct db_i"); return DBI_NULL; } bu_vls_printf(&fullpath, "%s/%s", argv[1], name); dbip->dbi_filename = bu_strdup(bu_vls_addr(&fullpath)); bu_vls_free(&fullpath); } else { /* Record the filename and file path */ dbip->dbi_filename = bu_strdup(name); } #else /* Record the filename and file path */ dbip->dbi_filename = bu_strdup(name); #endif bu_ptbl_init(&dbip->dbi_clients, 128, "dbi_clients[]"); dbip->dbi_magic = DBI_MAGIC; /* Now it's valid */ /* determine version */ dbip->dbi_version = 0; /* make db_version() calculate */ dbip->dbi_version = db_version(dbip); if (dbip->dbi_version < 5) { if (rt_db_flip_endian(dbip)) { if (dbip->dbi_version > 0) dbip->dbi_version *= -1; dbip->dbi_read_only = 1; bu_log("WARNING: Binary-incompatible v4 geometry database detected.\n"); bu_log(" Endianness flipped. Converting to READ ONLY.\n"); } } if (RT_G_DEBUG & DEBUG_DB) { bu_log("db_open(%s) dbip=%p version=%d\n", dbip->dbi_filename, (void *)dbip, dbip->dbi_version); } return dbip; }
HIDDEN void killtree_callback(struct db_i *dbip, struct directory *dp, void *ptr) { struct killtree_data *gktdp = (struct killtree_data *)ptr; int ref_exists = 0; if (dbip == DBI_NULL) return; /* don't bother checking for references if the -f or -a flags are * presented to force a full kill and all references respectively. */ if (!gktdp->force && !gktdp->killrefs) ref_exists = find_reference(dbip, gktdp->top, dp->d_namep); /* if a reference exists outside of the subtree we're killing, we * don't kill this object or it'll create invalid reference * elsewhere in the database. do nothing. */ if (ref_exists) return; if (gktdp->print) { if (!gktdp->killrefs) bu_vls_printf(gktdp->gedp->ged_result_str, "%s ", dp->d_namep); else { if ((size_t)(gktdp->ac + 2) >= gktdp->av_capacity) { gktdp->av = (char **)bu_realloc(gktdp->av, sizeof(char *) * (gktdp->av_capacity + AV_STEP), "realloc av"); gktdp->av_capacity += AV_STEP; } gktdp->av[gktdp->ac++] = bu_strdup(dp->d_namep); gktdp->av[gktdp->ac] = (char *)0; bu_vls_printf(gktdp->gedp->ged_result_str, "%s ", dp->d_namep); } } else { _dl_eraseAllNamesFromDisplay(gktdp->gedp->ged_gdp->gd_headDisplay, gktdp->gedp->ged_wdbp->dbip, gktdp->gedp->ged_free_vlist_callback, dp->d_namep, 0, gktdp->gedp->freesolid); bu_vls_printf(gktdp->gedp->ged_result_str, "KILL %s: %s\n", (dp->d_flags & RT_DIR_COMB) ? "COMB" : "Solid", dp->d_namep); if (!gktdp->killrefs) { if (db_delete(dbip, dp) != 0 || db_dirdelete(dbip, dp) != 0) { bu_vls_printf(gktdp->gedp->ged_result_str, "an error occurred while deleting %s\n", dp->d_namep); } } else { if ((size_t)(gktdp->ac + 2) >= gktdp->av_capacity) { gktdp->av = (char **)bu_realloc(gktdp->av, sizeof(char *) * (gktdp->av_capacity + AV_STEP), "realloc av"); gktdp->av_capacity += AV_STEP; } gktdp->av[gktdp->ac++] = bu_strdup(dp->d_namep); gktdp->av[gktdp->ac] = (char *)0; if (db_delete(dbip, dp) != 0 || db_dirdelete(dbip, dp) != 0) { bu_vls_printf(gktdp->gedp->ged_result_str, "an error occurred while deleting %s\n", dp->d_namep); /* Remove from list */ bu_free((void *)gktdp->av[--gktdp->ac], "killtree_callback"); gktdp->av[gktdp->ac] = (char *)0; } } } }
int ged_killtree(struct ged *gedp, int argc, const char *argv[]) { struct directory *dp; int i; int c; struct killtree_data gktd; static const char *usage = "[-a|-f|-n] object(s)"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_READ_ONLY(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } gktd.gedp = gedp; gktd.killrefs = 0; gktd.print = 0; gktd.force = 0; gktd.ac = 1; gktd.top = NULL; gktd.av = (char **)bu_calloc(1, sizeof(char *) * AV_STEP, "alloc av"); gktd.av_capacity = AV_STEP; BU_ASSERT(gktd.ac + argc + 2 < AV_STEP); /* potential -n opts */ gktd.av[0] = "killrefs"; gktd.av[1] = (char *)0; bu_optind = 1; while ((c = bu_getopt(argc, (char * const *)argv, "afn")) != -1) { switch (c) { case 'a': gktd.killrefs = 1; break; case 'n': gktd.print = 1; gktd.av[gktd.ac++] = bu_strdup("-n"); gktd.av[gktd.ac] = (char *)0; break; case 'f': gktd.force = 1; break; default: bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); bu_free(gktd.av, "free av (error)"); gktd.av = NULL; return GED_ERROR; } } argc -= (bu_optind - 1); argv += (bu_optind - 1); /* Objects that would be killed are in the first sublist */ if (gktd.print) bu_vls_printf(gedp->ged_result_str, "{"); for (i = 1; i < argc; i++) { if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) continue; /* ignore phony objects */ if (dp->d_addr == RT_DIR_PHONY_ADDR) continue; /* stash the what's killed so we can find refs elsewhere */ gktd.top = argv[i]; db_functree(gedp->ged_wdbp->dbip, dp, killtree_callback, killtree_callback, gedp->ged_wdbp->wdb_resp, (void *)&gktd); } /* Close the sublist of would-be killed objects. Also open the * sublist of objects that reference the would-be killed objects. */ if (gktd.print) bu_vls_printf(gedp->ged_result_str, "} {"); if (gktd.killrefs && gktd.ac > 1) { gedp->ged_internal_call = 1; (void)ged_killrefs(gedp, gktd.ac, (const char **)gktd.av); gedp->ged_internal_call = 0; for (i = 1; i < gktd.ac; i++) { if (!gktd.print) bu_vls_printf(gedp->ged_result_str, "Freeing %s\n", gktd.av[i]); bu_free((void *)gktd.av[i], "killtree_data"); gktd.av[i] = NULL; } } if (gktd.print) bu_vls_printf(gedp->ged_result_str, "}"); bu_free(gktd.av, "free av"); gktd.av = NULL; return GED_OK; }
/** * Add the list of regions in the model to the rigid bodies list in * simulation parameters. This function will duplicate the existing * regions prefixing "sim_" to the new region and putting them all * under a new comb "sim.c". It will skip over any existing regions * with "sim_" in the name */ int add_regions(struct ged *gedp, struct simulation_params *sim_params) { struct directory *dp, *ndp; char *prefix = "sim_"; int i; struct rigid_body *prev_node = NULL, *current_node; struct bu_vls dp_name_vls = BU_VLS_INIT_ZERO; /* Kill the existing sim comb */ sim_kill(gedp, sim_params->sim_comb_name); sim_params->num_bodies = 0; /* Walk the directory list duplicating all regions only, skip some regions */ for (i = 0; i < RT_DBNHASH; i++) for (dp = gedp->ged_wdbp->dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) { if ((dp->d_flags & RT_DIR_HIDDEN) || /* check for hidden comb/prim */ !(dp->d_flags & RT_DIR_REGION) /* check if region */ ) { continue; } if (strstr(dp->d_namep, prefix)) { bu_vls_printf(gedp->ged_result_str, "add_regions: Skipping \"%s\" due to \"%s\" in name\n", dp->d_namep, prefix); continue; } if (BU_STR_EMPTY(dp->d_namep)) { bu_vls_printf(gedp->ged_result_str, "add_regions: Skipping \"%s\" due to empty name\n", dp->d_namep); continue; } /* Duplicate the region */ bu_vls_sprintf(&dp_name_vls, "%s%s", prefix, dp->d_namep); sim_kill_copy(gedp, dp, bu_vls_addr(&dp_name_vls)); bu_vls_printf(gedp->ged_result_str, "add_regions: Copied \"%s\" to \"%s\"\n", dp->d_namep, bu_vls_addr(&dp_name_vls)); /* Get the directory pointer for the object just added */ if ((ndp=db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&dp_name_vls), LOOKUP_QUIET)) == RT_DIR_NULL) { bu_vls_printf(gedp->ged_result_str, "add_regions: db_lookup(%s) failed", bu_vls_addr(&dp_name_vls)); return GED_ERROR; } /* Add to simulation list */ BU_ALLOC(current_node, struct rigid_body); current_node->index = sim_params->num_bodies; current_node->rb_namep = bu_strdup(bu_vls_addr(&dp_name_vls)); current_node->dp = ndp; current_node->next = NULL; /* Save the internal format as well */ if (!rt_db_lookup_internal(sim_params->gedp->ged_wdbp->dbip, ndp->d_namep, &ndp, &(current_node->intern), LOOKUP_NOISY, &rt_uniresource)) { bu_exit(1, "add_regions: ERROR rt_db_lookup_internal(%s) failed to get the internal form", ndp->d_namep); return GED_ERROR; } /* Add physics attribs : one shot get from user */ add_physics_attribs(current_node); /* Setup the linked list */ if (prev_node == NULL) { /* first node */ prev_node = current_node; sim_params->head_node = current_node; } else { /* past 1st node now */ prev_node->next = current_node; prev_node = prev_node->next; } /* Add the new region to the simulation result */ add_to_comb(gedp, sim_params->sim_comb_name, bu_vls_addr(&dp_name_vls)); sim_params->num_bodies++; } bu_vls_free(&dp_name_vls); if(sim_params->num_bodies == 0){ bu_vls_printf(gedp->ged_result_str, "add_regions: ERROR No objects were added\n"); return GED_ERROR; } /* Show list of objects to be added to the sim : keep for debugging as of now */ /* bu_log("add_regions: The following %d regions will participate in the sim : \n", sim_params->num_bodies); for (current_node = sim_params->head_node; current_node != NULL; current_node = current_node->next) { print_rigid_body(current_node); }*/ return GED_OK; }
static struct name_conv_list * Add_new_name(char *name, unsigned int obj, int type) { struct name_conv_list *ptr; if ( debug ) bu_log( "Add_new_name( %s, x%x, %d )\n", name, obj, type ); if ( type != ASSEMBLY_TYPE && type != PART_TYPE && type != CUT_SOLID_TYPE ) { bu_exit(EXIT_FAILURE, "Bad type for name (%s) in Add_new_name\n", name ); } /* Add a new name */ ptr = (struct name_conv_list *)bu_calloc( 1, sizeof( struct name_conv_list ), "Add_new_name: prev->next" ); ptr->next = (struct name_conv_list *)NULL; ptr->brlcad_name = bu_strdup( name ); ptr->obj = obj; if ( do_regex && type != CUT_SOLID_TYPE ) { regmatch_t pmatch; if ( regexec( ®_cmp, ptr->brlcad_name, 1, &pmatch, 0 ) == 0 ) { /* got a match */ bu_strlcpy( &ptr->brlcad_name[pmatch.rm_so], &ptr->brlcad_name[pmatch.rm_eo], MAX_LINE_SIZE ); } if ( debug ) bu_log( "\tafter reg_ex, name is %s\n", ptr->brlcad_name ); } else if ( type == CUT_SOLID_TYPE ) { bu_free( (char *)ptr->brlcad_name, "brlcad_name" ); ptr->brlcad_name = NULL; } ptr->solid_use_no = 0; ptr->comb_use_no = 0; if ( type != CUT_SOLID_TYPE ) { /* make sure brlcad_name is unique */ char *tmp; tmp = ptr->brlcad_name; ptr->brlcad_name = bu_strdup( Build_unique_name( ptr->brlcad_name ) ); bu_free( (char *)tmp, "brlcad_name" ); } if ( type == ASSEMBLY_TYPE ) { ptr->solid_name = NULL; return( ptr ); } else if ( type == PART_TYPE ) { struct bu_vls vls; bu_vls_init( &vls ); bu_vls_strcpy( &vls, "s." ); bu_vls_strcat( &vls, ptr->brlcad_name ); ptr->solid_name = bu_vls_strgrab( &vls ); } else { struct bu_vls vls; bu_vls_init( &vls ); bu_vls_strcpy( &vls, "s." ); bu_vls_strcat( &vls, ptr->brlcad_name ); ptr->solid_name = bu_vls_strgrab( &vls ); } /* make sure solid name is unique */ ptr->solid_name = bu_strdup( Build_unique_name( ptr->solid_name ) ); return( ptr ); }
struct obj_info * Part_import( int id_start ) { char line[MAX_LINE_SIZE]; struct obj_info *part; struct wmember reg_head; unsigned char rgb[3]; int surf_count=0; int id_end; int last_surf=0; int i; int tri[3]; int corner_index=-1; clean_vert_tree( tree_root ); VSETALL( rgb, 128 ); BU_ALLOC(part, struct obj_info); part->obj_type = PART_TYPE; part->obj_id = id_start; while ( bu_fgets( line, MAX_LINE_SIZE, fd_in ) ) { if ( !bu_strncmp( line, "PartName", 8 ) ) { line[strlen( line ) - 1] = '\0'; part->obj_name = bu_strdup( &line[9] ); lower_case( part->obj_name ); Make_brlcad_names( part ); } else if ( !bu_strncmp( line, "FaceCount", 9 ) ) { surf_count = atoi( &line[10] ); if ( surf_count == 0 ) { last_surf = 1; } } else if ( !bu_strncmp( line, "EndPartId", 9 ) ) { /* found end of part, check id */ id_end = atoi( &line[10] ); if ( id_end != id_start ) bu_exit( 1, "%s: ERROR: found end of part id %d while processing part %d\n", progname,id_end, id_start ); if ( last_surf ) { break; } } else if ( !bu_strncmp( line, "FaceRGB", 7 ) ) { /* get face color */ char *ptr; i = 8; ptr = strtok( &line[i], " \t" ); for ( i=0; i<3 && ptr; i++ ) { rgb[i] = atof( ptr ); ptr = strtok( (char *)NULL, " \t" ); } } else if ( !bu_strncmp( line, "Facet", 5 ) ) { /* read a triangle */ VSETALL( tri, -1 ); corner_index = -1; } else if ( !bu_strncmp( line, "Face", 4 ) ) { /* start of a surface */ int surf_no; surf_no = atoi( &line[5] ); if ( surf_no == surf_count ) { last_surf = 1; } } else if ( !bu_strncmp( line, "TriangleCount", 13 ) ) { /* get number of triangles for this surface */ } else if ( !bu_strncmp( line, "Vertices", 9 ) ) { /* get vertex list for this triangle */ } else if ( !bu_strncmp( line, "Vertex", 6 ) ) { /* get a vertex */ char *ptr = NULL; vect_t v = VINIT_ZERO; i = 7; while ( !isspace( (int)line[i] ) && line[i] != '\0' ) i++; ptr = strtok( &line[i], " \t" ); for ( i=0; i<3 && ptr; i++ ) { v[i] = atof( ptr ); ptr = strtok( (char *)NULL, " \t" ); } tri[++corner_index] = Add_vert( V3ARGS( v ), tree_root, local_tol_sq ); if ( corner_index == 2 ) { if ( !bad_triangle( tri, tree_root->the_array ) ) { add_triangle( tri ); } } } else if ( !bu_strncmp( line, "Normal", 6 ) ) { /* get a vertex normal */ } else if ( !bu_strncmp( line, "PointCount", 10 ) ) { /* get number of vertices for this surface */ } else bu_exit( 1, "%s: ERROR: unrecognized line encountered while processing part id %d:\n%s\n", progname,id_start, line ); } if ( curr_tri == 0 ) { /* no facets in this part, so ignore it */ bu_free( (char *)part, "part" ); part = (struct obj_info *)NULL; } else { /* write this part to database, first make a primitive solid */ if ( mk_bot( fd_out, part->brlcad_solid, RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, tree_root->curr_vert, curr_tri, tree_root->the_array, part_tris, NULL, NULL ) ) bu_exit( 1, "%s: Failed to write primitive %s (%s) to database\n", progname,part->brlcad_solid, part->obj_name ); if ( verbose ) { DO_INDENT; bu_log( "Wrote BOT %s\n", part->brlcad_solid ); } /* then a region */ BU_LIST_INIT( ®_head.l ); if ( mk_addmember( part->brlcad_solid, ®_head.l, NULL, WMOP_UNION ) == WMEMBER_NULL ) bu_exit( 1, "%s: ERROR: Failed to add solid (%s), to region (%s)\n", progname,part->brlcad_solid, part->brlcad_comb ); if ( mk_comb( fd_out, part->brlcad_comb, ®_head.l, 1, NULL, NULL, rgb, ident++, 0, 1, 100, 0, 0, 0 ) ) bu_exit( 1, "%s: Failed to write region %s (%s) to database\n", progname,part->brlcad_comb, part->obj_name ); if ( verbose ) { DO_INDENT; bu_log( "Wrote region %s\n", part->brlcad_comb ); } if ( use_part_name_hash ) { if ( db5_update_attribute( part->brlcad_comb, "Part_No", part->obj_name, fd_out->dbip ) ) { bu_log( "Failed to assign Part_no attribute to %s\n", part->brlcad_comb ); } } } /* free some memory */ if ( part_tris ) { bu_free( (char *)part_tris, "part_tris" ); } max_tri = 0; curr_tri = 0; part_tris = NULL; return part; }
void Make_brlcad_names( struct obj_info *part ) { struct bu_vls vls = BU_VLS_INIT_ZERO; int count=0; char *tmp_name, *ptr; Tcl_HashEntry *hash_entry=NULL; if ( use_part_name_hash ) { hash_entry = Tcl_FindHashEntry( &htbl, part->obj_name ); if ( !hash_entry ) { /* try without any name extension */ if ( (ptr=strrchr( part->obj_name, '_' )) != NULL ) { bu_vls_strncpy( &vls, part->obj_name, (ptr - part->obj_name) ); hash_entry = Tcl_FindHashEntry( &htbl, bu_vls_addr( &vls ) ); } } if ( !hash_entry ) { /* try without any name extension */ if ( (ptr=strchr( part->obj_name, '_' )) != NULL ) { bu_vls_strncpy( &vls, part->obj_name, (ptr - part->obj_name) ); hash_entry = Tcl_FindHashEntry( &htbl, bu_vls_addr( &vls ) ); } } if ( !hash_entry ) { /* try adding "-011" */ if ( (ptr=strchr( part->obj_name, '-' )) != NULL ) { bu_vls_strncpy( &vls, part->obj_name, (ptr - part->obj_name) ); bu_vls_strcat( &vls, "-011" ); hash_entry = Tcl_FindHashEntry( &htbl, bu_vls_addr( &vls ) ); } } if ( !hash_entry ) { name_not_converted++; } } bu_vls_free( &vls ); if ( hash_entry ) { tmp_name = bu_strdup( (char *)Tcl_GetHashValue( hash_entry ) ); } else { if ( use_part_name_hash ) { bu_log( "\tWarning: no name found for part %s\n", part->obj_name ); } /* make a copy of object name, then make it a legal BRL-CAD name */ if ( strlen( part->obj_name ) < 1 ) { tmp_name = bu_strdup( "s.1" ); } else { tmp_name = bu_strdup( part->obj_name ); ptr = tmp_name; while ( *ptr != '\0' ) { if ( !(isalnum( (int)*ptr ) || *ptr == '-')) { *ptr = '_'; } ptr++; } } } if ( part->obj_type == PART_TYPE ) { /* find a unique solid name */ bu_vls_printf( &vls, "s.%s", tmp_name ); if ( max_name_len ) { bu_vls_trunc( &vls, max_name_len ); } while ( db_lookup( fd_out->dbip, bu_vls_addr( &vls ), LOOKUP_QUIET ) != RT_DIR_NULL) { count++; if ( max_name_len ) { int digits = 1; int val = 10; while ( count >= val ) { digits++; val *= 10; } bu_vls_trunc( &vls, 0 ); bu_vls_printf( &vls, "s.%s", tmp_name ); bu_vls_trunc( &vls, max_name_len - digits - 1 ); bu_vls_printf( &vls, ".%d", count ); } else { bu_vls_trunc( &vls, 0 ); bu_vls_printf( &vls, "s.%s.%d", tmp_name, count ); } } part->brlcad_solid = bu_vls_strgrab( &vls ); } else { part->brlcad_solid = NULL; } /* find a unique non-primitive name */ bu_vls_printf( &vls, "%s", tmp_name ); if ( max_name_len ) { bu_vls_trunc( &vls, max_name_len ); } while ( db_lookup( fd_out->dbip, bu_vls_addr( &vls ), LOOKUP_QUIET) != RT_DIR_NULL ) { count++; if ( max_name_len ) { int digits = 1; int val = 10; while ( count >= val ) { digits++; val *= 10; } bu_vls_trunc( &vls, 0 ); bu_vls_printf( &vls, "%s", tmp_name ); bu_vls_trunc( &vls, max_name_len - digits - 1 ); bu_vls_printf( &vls, ".%d", count ); } else { bu_vls_trunc( &vls, 0 ); bu_vls_printf( &vls, "%s.%d", tmp_name, count ); } } part->brlcad_comb = bu_vls_strgrab( &vls ); switch ( part->obj_type ) { case UNKNOWN_TYPE: bu_log( "ERROR: Unknown object type for %s\n", part->obj_name ); break; case PART_TYPE: if ( use_part_name_hash ) { DO_INDENT bu_log( "part %s changed name to (%s)\n", part->obj_name, part->brlcad_comb ); } else { DO_INDENT bu_log( "part %s\n", part->brlcad_comb ); } break; case ASSEMBLY_TYPE: if ( use_part_name_hash ) { DO_INDENT bu_log( "assembly %s changed name to (%s)\n", part->obj_name, part->brlcad_comb ); } else { DO_INDENT bu_log( "assembly %s\n", part->brlcad_comb ); } break; } bu_free( tmp_name, "tmp_name" ); }
int make_hole(struct rt_wdb *wdbp, /* database to be modified */ point_t hole_start, /* center of start of hole */ vect_t hole_depth, /* depth and direction of hole */ fastf_t hole_radius, /* radius of hole */ int num_objs, /* number of objects that this hole affects */ struct directory **dp) /* array of directory pointers * [num_objs] of objects to * get this hole applied */ { struct bu_vls tmp_name = BU_VLS_INIT_ZERO; int i, base_len, count=0; RT_CHECK_WDB(wdbp); /* make sure we are only making holes in combinations, they do not * have to be regions */ for (i=0; i<num_objs; i++) { RT_CK_DIR(dp[i]); if (!(dp[i]->d_flags & RT_DIR_COMB)) { bu_log("make_hole(): can only make holes in combinations\n"); bu_log("\t%s is not a combination\n", dp[i]->d_namep); return 4; } } /* make a unique name for the RCC we will use (of the form * "make_hole_%d") */ bu_vls_strcat(&tmp_name, "make_hole_"); base_len = bu_vls_strlen(&tmp_name); bu_vls_strcat(&tmp_name, "0"); while ((db_lookup(wdbp->dbip, bu_vls_addr(&tmp_name), LOOKUP_QUIET)) != RT_DIR_NULL) { count++; bu_vls_trunc(&tmp_name, base_len); bu_vls_printf(&tmp_name, "%d", count); } /* build the RCC based on parameters passed in */ if (mk_rcc(wdbp, bu_vls_addr(&tmp_name), hole_start, hole_depth, hole_radius)) { bu_log("Failed to create hole cylinder!!!\n"); bu_vls_free(&tmp_name); return 2; } /* subtract this RCC from each combination in the list passed in */ for (i=0; i<num_objs; i++) { struct rt_db_internal intern; struct rt_comb_internal *comb; union tree *tree; /* get the internal form of the combination */ if (rt_db_get_internal(&intern, dp[i], wdbp->dbip, NULL, wdbp->wdb_resp) < 0) { bu_log("Failed to get %s\n", dp[i]->d_namep); bu_vls_free(&tmp_name); return 3; } comb = (struct rt_comb_internal *)intern.idb_ptr; /* Build a new "subtract" node (will be the root of the new tree) */ BU_ALLOC(tree, union tree); RT_TREE_INIT(tree); tree->tr_b.tb_op = OP_SUBTRACT; tree->tr_b.tb_left = comb->tree; /* subtract from the original tree */ comb->tree = tree; /* Build a node for the RCC to be subtracted */ BU_ALLOC(tree, union tree); RT_TREE_INIT(tree); tree->tr_l.tl_op = OP_DB_LEAF; tree->tr_l.tl_mat = NULL; tree->tr_l.tl_name = bu_strdup(bu_vls_addr(&tmp_name)); /* copy name of RCC */ /* Put the RCC node to the right of the root */ comb->tree->tr_b.tb_right = tree; /* Save the modified combination. This will overwrite the * original combination if wdbp was opened with the * RT_WDB_TYPE_DB_DISK flag. If wdbp was opened with the * RT_WDB_TYPE_DB_INMEM flag, then the combination will be * temporarily over-written in memory only and the disk file * will not be modified. */ wdb_put_internal(wdbp, dp[i]->d_namep, &intern, 1.0); } return 0; }
int main(int argc, char **argv) { FBIO *fbp; unsigned char *scan_buf; int y; int cm_save_needed; outrle.rle_file = stdout; if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit(1, NULL); } /* If screen size = default & file size is given, track file size */ if (screen_width == 0 && file_width > 0) screen_width = file_width; if (screen_height == 0 && file_height > 0) screen_height = file_height; if ((fbp = fb_open(framebuffer, screen_width, screen_height)) == FBIO_NULL) bu_exit(12, NULL); /* Honor original screen size desires, if set, unless they shrank */ if (screen_width == 0 || fb_getwidth(fbp) < screen_width) screen_width = fb_getwidth(fbp); if (screen_height == 0 || fb_getheight(fbp) < screen_height) screen_height = fb_getheight(fbp); /* If not specified, output file size tracks screen size */ if (file_width == 0) file_width = screen_width; if (file_height == 0) file_height = screen_height; /* Clip below and to left of (0, 0) */ if (screen_xoff < 0) { file_width += screen_xoff; screen_xoff = 0; } if (screen_yoff < 0) { file_height += screen_yoff; screen_yoff = 0; } /* Clip up and to the right */ if (screen_xoff + file_width > screen_width) file_width = screen_width - screen_xoff; if (screen_yoff + file_height > screen_height) file_height = screen_height - screen_yoff; if (file_width <= 0 || file_height <= 0) { fprintf(stderr, "fb-rle: Error: image rectangle entirely off screen\n"); bu_exit(1, NULL); } /* Read color map, see if it is linear */ cm_save_needed = 1; if (fb_rmap(fbp, &cmap) == -1) cm_save_needed = 0; if (cm_save_needed && fb_is_linear_cmap(&cmap)) cm_save_needed = 0; if (crunch && (cm_save_needed == 0)) crunch = 0; /* Convert to Utah format */ if (cm_save_needed) for (y=0; y<256; y++) { rlemap[y+0*256] = cmap.cm_red[y]; rlemap[y+1*256] = cmap.cm_green[y]; rlemap[y+2*256] = cmap.cm_blue[y]; } scan_buf = (unsigned char *)malloc(sizeof(RGBpixel) * screen_width); /* Build RLE header */ outrle.ncolors = 3; RLE_SET_BIT(outrle, RLE_RED); RLE_SET_BIT(outrle, RLE_GREEN); RLE_SET_BIT(outrle, RLE_BLUE); outrle.background = 2; /* use background */ outrle.bg_color = background; outrle.alpha = 0; /* no alpha channel */ if (cm_save_needed && !crunch) { outrle.ncmap = 3; outrle.cmaplen = 8; /* 1<<8 = 256 */ outrle.cmap = rlemap; } else { outrle.ncmap = 0; /* no color map */ outrle.cmaplen = 0; outrle.cmap = (rle_map *)0; } outrle.xmin = screen_xoff; outrle.ymin = screen_yoff; outrle.xmax = screen_xoff + file_width - 1; outrle.ymax = screen_yoff + file_height - 1; outrle.comments = (const char **)0; /* Add comments to the header file, since we have one */ if (framebuffer == (char *)0) framebuffer = fbp->if_name; snprintf(comment, COMMENT_SIZE, "encoded_from=%s", framebuffer); rle_putcom(bu_strdup(comment), &outrle); now = time(0); snprintf(comment, COMMENT_SIZE, "encoded_date=%24.24s", ctime(&now)); rle_putcom(bu_strdup(comment), &outrle); if ((who = getenv("USER")) != (char *)0) { snprintf(comment, COMMENT_SIZE, "encoded_by=%s", who); rle_putcom(bu_strdup(comment), &outrle); } # if HAVE_GETHOSTNAME gethostname(host, sizeof(host)); snprintf(comment, COMMENT_SIZE, "encoded_host=%s", host); rle_putcom(bu_strdup(comment), &outrle); # endif rle_put_setup(&outrle); rle_row_alloc(&outrle, &rows); /* Read the image a scanline at a time, and encode it */ for (y = 0; y < file_height; y++) { if (fb_read(fbp, screen_xoff, y+screen_yoff, scan_buf, file_width) == -1) { (void) fprintf(stderr, "fb-rle: read of %d pixels on line %d failed!\n", file_width, y+screen_yoff); bu_exit(1, NULL); } if (crunch) cmap_crunch((RGBpixel *)scan_buf, file_width, &cmap); /* Grumble, convert to Utah layout */ { unsigned char *pp = (unsigned char *)scan_buf; rle_pixel *rp = rows[0]; rle_pixel *gp = rows[1]; rle_pixel *bp = rows[2]; int i; for (i=0; i<file_width; i++) { *rp++ = *pp++; *gp++ = *pp++; *bp++ = *pp++; } } rle_putrow(rows, file_width, &outrle); } rle_puteof(&outrle); fb_close(fbp); fclose(outrle.rle_file); return 0; }
/* * M A I N */ int main(int argc, char **argv) { struct application ap; static struct rt_i *rtip; char *title_file; char idbuf[RT_BUFSIZE] = {0}; /* First ID record info */ char *ptr; int attr_count=0, i; char **attrs = (char **)NULL; if ( argc < 3 ) { bu_exit(1, usage); } RT_APPLICATION_INIT(&ap); argc--; argv++; while ( argv[0][0] == '-' ) switch ( argv[0][1] ) { case 'R': bundle_radius = atof( argv[1] ); argc -= 2; argv += 2; break; case 'n': num_rings = atoi( argv[1] ); argc -= 2; argv += 2; break; case 'c': rays_per_ring = atoi( argv[1] ); argc -= 2; argv += 2; break; case 'v': /* count the number of attribute names provided */ ptr = argv[1]; while ( *ptr ) { while ( *ptr && isspace( *ptr ) ) ptr++; if ( *ptr ) attr_count++; while ( *ptr && !isspace( *ptr ) ) ptr++; } if ( attr_count == 0 ) { bu_log( "missing list of attribute names!\n" ); bu_exit( 1, usage ); } /* allocate enough for a null terminated list */ attrs = (char **)bu_calloc( attr_count + 1, sizeof( char *), "attrs" ); /* use strtok to actually grab the names */ i = 0; ptr = strtok( argv[1], "\t " ); while ( ptr && i < attr_count ) { attrs[i] = bu_strdup( ptr ); ptr = strtok( (char *)NULL, "\t " ); i++; } argc -= 2; argv += 2; break; case 't': rt_bot_tri_per_piece = atoi( argv[1] ); argc -= 2; argv += 2; break; case 'b': rt_bot_minpieces = atoi( argv[1] ); argc -= 2; argv += 2; break; case 'o': sscanf( argv[1], "%d", &set_onehit ); argc -= 2; argv += 2; break; case 'r': { float ray_len; sscanf( argv[1], "%f", &ray_len ); set_ray_length = ray_len; } argc -= 2; argv += 2; break; case 'U': sscanf( argv[1], "%d", &use_air ); argc -= 2; argv += 2; break; case 'u': sscanf( argv[1], "%x", (unsigned int *)&bu_debug ); fprintf(stderr, "librt bu_debug=x%x\n", bu_debug); argc -= 2; argv += 2; break; case 'x': sscanf( argv[1], "%x", (unsigned int *)&rt_g.debug ); fprintf(stderr, "librt rt_g.debug=x%x\n", rt_g.debug); argc -= 2; argv += 2; break; case 'X': sscanf( argv[1], "%x", (unsigned int *)&rdebug ); fprintf(stderr, "rdebug=x%x\n", rdebug); argc -= 2; argv += 2; break; case 'N': sscanf( argv[1], "%x", (unsigned int *)&rt_g.NMG_debug); fprintf(stderr, "librt rt_g.NMG_debug=x%x\n", rt_g.NMG_debug); argc -= 2; argv += 2; break; case 'd': if ( argc < 4 ) goto err; ap.a_ray.r_dir[X] = atof( argv[1] ); ap.a_ray.r_dir[Y] = atof( argv[2] ); ap.a_ray.r_dir[Z] = atof( argv[3] ); set_dir = 1; argc -= 4; argv += 4; continue; case 'p': if ( argc < 4 ) goto err; ap.a_ray.r_pt[X] = atof( argv[1] ); ap.a_ray.r_pt[Y] = atof( argv[2] ); ap.a_ray.r_pt[Z] = atof( argv[3] ); set_pt = 1; argc -= 4; argv += 4; continue; case 'a': if ( argc < 4 ) goto err; at_vect[X] = atof( argv[1] ); at_vect[Y] = atof( argv[2] ); at_vect[Z] = atof( argv[3] ); set_at = 1; argc -= 4; argv += 4; continue; case 'O': { if ( !strcmp( argv[1], "resolve" ) || !strcmp( argv[1], "0") ) overlap_claimant_handling = 0; else if ( !strcmp( argv[1], "rebuild_fastgen" ) || !strcmp( argv[1], "1") ) overlap_claimant_handling = 1; else if ( !strcmp( argv[1], "rebuild_all" ) || !strcmp( argv[1], "2") ) overlap_claimant_handling = 2; else if ( !strcmp( argv[1], "retain" ) || !strcmp( argv[1], "3") ) overlap_claimant_handling = 3; else { bu_log( "Illegal argument (%s) to '-O' option. Must be:\n", argv[1] ); bu_log( "\t'resolve' or '0'\n"); bu_log( "\t'rebuild_fastgen' or '1'\n"); bu_log( "\t'rebuild_all' or '2'\n"); bu_log( "\t'retain' or '3'\n"); bu_exit(1, NULL); } argc -= 2; argv += 2; } continue; default: err: bu_exit(1, usage); } if ( argc < 2 ) { (void)fputs(usage, stderr); bu_exit(1, "rtshot: MGED database not specified\n"); } if ( set_dir + set_pt + set_at != 2 ) goto err; if ( num_rings != 0 || rays_per_ring != 0 || bundle_radius != 0.0 ) { if ( num_rings <= 0 || rays_per_ring <= 0 || bundle_radius <= 0.0 ) { fprintf( stderr, "Must have all of \"-R\", \"-n\", and \"-c\" set\n" ); goto err; } } /* Load database */ title_file = argv[0]; argv++; argc--; if ( (rtip=rt_dirbuild(title_file, idbuf, sizeof(idbuf))) == RTI_NULL ) { bu_exit(2, "rtshot: rt_dirbuild failure\n"); } if ( overlap_claimant_handling ) rtip->rti_save_overlaps = 1; ap.a_rt_i = rtip; fprintf(stderr, "db title: %s\n", idbuf); rtip->useair = use_air; /* Walk trees */ if ( rt_gettrees_and_attrs( rtip, (const char **)attrs, argc, (const char **)argv, 1 ) ) { bu_exit(1, "rt_gettrees FAILED\n"); } ap.attrs = attrs; rt_prep(rtip); if ( R_DEBUG&RDEBUG_RAYPLOT ) { if ( (plotfp = fopen("rtshot.plot", "w")) == NULL ) { perror("rtshot.plot"); bu_exit(1, NULL); } pdv_3space( plotfp, rtip->rti_pmin, rtip->rti_pmax ); } /* Compute r_dir and r_pt from the inputs */ if ( set_at ) { if ( set_dir ) { vect_t diag; fastf_t viewsize; VSUB2( diag, rtip->mdl_max, rtip->mdl_min ); viewsize = MAGNITUDE( diag ); VJOIN1( ap.a_ray.r_pt, at_vect, -viewsize/2.0, ap.a_ray.r_dir ); } else { /* set_pt */ VSUB2( ap.a_ray.r_dir, at_vect, ap.a_ray.r_pt ); } } VUNITIZE( ap.a_ray.r_dir ); if ( rays_per_ring ) { bu_log( "Central Ray:\n" ); } VPRINT( "Pnt", ap.a_ray.r_pt ); VPRINT( "Dir", ap.a_ray.r_dir ); if ( set_onehit ) ap.a_onehit = set_onehit; else ap.a_onehit = 0; if ( set_ray_length > 0.0 ) ap.a_ray_length = set_ray_length; else ap.a_ray_length = 0.0; /* Shoot Ray */ ap.a_purpose = "main ray"; ap.a_hit = hit; ap.a_miss = miss; if ( rays_per_ring ) { vect_t avec, bvec; struct xray *rp; /* create orthogonal rays for basis of bundle */ bn_vec_ortho( avec, ap.a_ray.r_dir ); VCROSS( bvec, ap.a_ray.r_dir, avec ); VUNITIZE( bvec ); rp = (struct xray *)bu_calloc( sizeof( struct xray ), (rays_per_ring * num_rings) + 1, "ray bundle" ); rp[0] = ap.a_ray; /* struct copy */ rp[0].magic = RT_RAY_MAGIC; rt_raybundle_maker( rp, bundle_radius, avec, bvec, rays_per_ring, num_rings ); (void)rt_shootray_bundle( &ap, rp, (rays_per_ring * num_rings) + 1 ); } else { (void)rt_shootray( &ap ); } return(0); }
int db_string_to_path(struct db_full_path *pp, const struct db_i *dbip, const char *str) { char *cp; char *slashp; struct directory *dp; char *copy; size_t nslash = 0; int ret = 0; size_t len; RT_CK_DBI(dbip); /* assume NULL str is '/' */ if (!str) { db_full_path_init(pp); return 0; } while (*str == '/') str++; /* strip off leading slashes */ if (*str == '\0') { /* Path of a lone slash */ db_full_path_init(pp); return 0; } copy = bu_strdup(str); /* eliminate all trailing slashes */ len = strlen(copy); while (copy[len - 1] == '/') { copy[len - 1] = '\0'; --len; } cp = copy; while (*cp) { if ((slashp = strchr(cp, '/')) == NULL) break; nslash++; cp = slashp+1; } /* Make a path structure just big enough */ pp->magic = DB_FULL_PATH_MAGIC; pp->fp_maxlen = pp->fp_len = nslash+1; pp->fp_names = (struct directory **)bu_malloc( pp->fp_maxlen * sizeof(struct directory *), "db_string_to_path path array"); pp->fp_bool = (int *)bu_calloc(pp->fp_maxlen, sizeof(int), "db_string_to_path bool array"); pp->fp_mat = (matp_t *)bu_calloc(pp->fp_maxlen, sizeof(matp_t), "db_string_to_path mat array"); /* Build up path array */ cp = copy; nslash = 0; while (*cp) { if ((slashp = strchr(cp, '/')) == NULL) { /* Last element of string, has no trailing slash */ slashp = cp + strlen(cp) - 1; } else { *slashp = '\0'; } if ((dp = db_lookup(dbip, cp, LOOKUP_NOISY)) == RT_DIR_NULL) { bu_log("db_string_to_path() of '%s' failed on '%s'\n", str, cp); ret = -1; /* FAILED */ /* Fall through, storing null dp in this location */ } pp->fp_names[nslash++] = dp; cp = slashp+1; } BU_ASSERT_SIZE_T(nslash, ==, pp->fp_len); bu_free(copy, "db_string_to_path() duplicate string"); return ret; }
struct obj_info * Assembly_import( int id_start ) { char line[MAX_LINE_SIZE]; struct obj_info *this_assem, *member; struct wmember assem_head; int id_end, member_id; size_t i; BU_ALLOC(this_assem, struct obj_info); this_assem->obj_type = ASSEMBLY_TYPE; this_assem->obj_id = id_start; this_assem->part_count = 0; this_assem->members = NULL; while ( bu_fgets( line, MAX_LINE_SIZE, fd_in ) ) { if ( !bu_strncmp( line, "AssemblyName", 12 ) ) { line[strlen( line ) - 1] = '\0'; this_assem->obj_name = bu_strdup( &line[13] ); lower_case( this_assem->obj_name ); DO_INDENT; bu_log( "Start of assembly %s (id = %d)\n", this_assem->obj_name, id_start ); indent_level += indent_delta; } else if ( !bu_strncmp( line, "PartId", 6 ) ) { /* found a member part */ member_id = atoi( &line[7] ); member = Part_import( member_id ); if ( !member ) continue; this_assem->part_count++; this_assem->members = (struct obj_info **)bu_realloc( this_assem->members, this_assem->part_count * sizeof( struct obj_info *), "this_assem->members" ); this_assem->members[this_assem->part_count-1] = member; } else if ( !bu_strncmp( line, "AssemblyId", 10 ) ) { /* found a member assembly */ member_id = atoi( &line[11] ); member = Assembly_import( member_id ); this_assem->part_count++; this_assem->members = (struct obj_info **)bu_realloc( this_assem->members, this_assem->part_count * sizeof( struct obj_info *), "this_assem->members" ); this_assem->members[this_assem->part_count-1] = member; } else if ( !bu_strncmp( line, "EndAssemblyId", 13 ) ) { /* found end of assembly, make sure it is this one */ id_end = atoi( &line[14] ); if ( id_end != id_start ) bu_exit( 1, "%s: ERROR: found end of assembly id %d while processing id %d\n", progname,id_end, id_start ); indent_level -= indent_delta; DO_INDENT; bu_log( "Found end of assembly %s (id = %d)\n", this_assem->obj_name, id_start ); break; } else { bu_log( "%s: Unrecognized line encountered while processing assembly id %d:\n", progname,id_start ); bu_exit( 1, "%s\n", line ); } } Make_brlcad_names( this_assem ); /* write this assembly to the database */ BU_LIST_INIT( &assem_head.l ); for ( i=0; i<this_assem->part_count; i++ ) if ( mk_addmember( this_assem->members[i]->brlcad_comb, &assem_head.l, NULL, WMOP_UNION ) == WMEMBER_NULL ) bu_exit( 1, "%s: ERROR: Failed to add region %s to assembly %s\n", progname,this_assem->members[i]->brlcad_comb, this_assem->brlcad_comb ); if ( mk_comb( fd_out, this_assem->brlcad_comb, &assem_head.l, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0 ) ) bu_exit( 1, "%s: ERROR: Failed to write combination (%s) to database\n", progname,this_assem->brlcad_comb ); if ( use_part_name_hash ) { if ( db5_update_attribute( this_assem->brlcad_comb, "Part_No", this_assem->obj_name, fd_out->dbip ) ) { bu_log( "Failed to assign Part_no attribute to %s\n", this_assem->brlcad_comb ); } } return this_assem; }
int main( int argc, char *argv[] ) { char line[MAX_LINE_SIZE]; char *input_file, *output_file; FILE *fd_parts; struct obj_info **top_level_assems = NULL; int top_level_assem_count = 0; int curr_top_level = -1; fastf_t tmp; int id; int c; bu_setprogname(argv[0]); local_tol = 0.0005; local_tol_sq = local_tol * local_tol; ident = 1000; while ( (c=bu_getopt( argc, argv, "vi:t:n:l:h?" ) ) != -1 ) { switch ( c ) { case 'v': /* verbose */ verbose = 1; break; case 'i': /* starting ident number */ ident = atoi( bu_optarg ); break; case 't': /* tolerance */ tmp = atof( bu_optarg ); if ( tmp <= 0.0 ) bu_exit( 1, "%s: Illegal tolerance (%g), must be > 0.0\n", progname,tmp ); break; case 'n': /* part name list */ part_name_file = bu_optarg; use_part_name_hash = 1; break; case 'l': /* max name length */ max_name_len = atoi( bu_optarg ); if ( max_name_len < 5 ) bu_exit( 1, "%s: Unreasonable name length limitation\n",progname ); break; default: Usage(); bu_exit( 1, NULL ); } } if ( argc - bu_optind != 2 ) { bu_log( "Not enough arguments!! (need at least input & output file names)\n" ); Usage(); bu_exit( 1, NULL ); } input_file = bu_strdup( argv[bu_optind] ); if ((fd_in=fopen(input_file, "rb")) == NULL) { bu_log( "%s: Cannot open %s for reading\n", progname,input_file ); perror( argv[0] ); bu_exit( 1, NULL ); } output_file = bu_strdup( argv[bu_optind+1] ); if ( (fd_out=wdb_fopen( output_file )) == NULL ) { bu_log( "%s: Cannot open %s for writing\n", progname,output_file ); perror( argv[0] ); bu_exit( 1, NULL ); } if ( use_part_name_hash ) { if ( (fd_parts=fopen( part_name_file, "rb" )) == NULL ) { bu_log( "%s,Cannot open part name file (%s)\n", progname,part_name_file ); perror( argv[0] ); bu_exit( 1, NULL ); } create_name_hash( fd_parts ); } tree_root = create_vert_tree(); /* finally, start processing the input */ while ( bu_fgets( line, MAX_LINE_SIZE, fd_in ) ) { if ( !bu_strncmp( line, "FileName", 8 ) ) { bu_log( "Converting facets originally from %s", &line[9] ); } else if ( !bu_strncmp( line, "TopAssemblies", 13 ) ) { bu_log( "Top level assemblies: %s", &line[14] ); top_level_assem_count = atoi( &line[14] ); if ( top_level_assem_count < 1 ) { top_level_assems = (struct obj_info **)NULL; } else { top_level_assems = (struct obj_info **)bu_calloc( top_level_assem_count, sizeof( struct obj_info * ), "top_level_assems" ); } } else if ( !bu_strncmp( line, "PartCount", 9 ) ) { bu_log( "Part count: %s", &line[10] ); } else if ( !bu_strncmp( line, "AssemblyId", 10 ) ) { id = atoi( &line[11] ); curr_top_level++; if ( curr_top_level >= top_level_assem_count ) { bu_log( "Warning: too many top level assemblies\n" ); bu_log( "\texpected %d, this os number %d\n", top_level_assem_count, curr_top_level+1 ); top_level_assem_count = curr_top_level+1; top_level_assems = (struct obj_info **)bu_realloc( top_level_assems, top_level_assem_count * sizeof( struct obj_info * ), "top_level_assems" ); } top_level_assems[curr_top_level] = Assembly_import( id ); } else if ( !bu_strncmp( line, "PartId", 6 ) ) { /* found a top-level part */ id = atoi( &line[7] ); (void)Part_import( id ); } } if ( name_not_converted ) { bu_log( "Warning %d objects were not found in the part number to name mapping,\n", name_not_converted ); bu_log( "\ttheir names remain as part numbers.\n" ); } return 0; }
HIDDEN int move_all_func(struct ged *gedp, int nflag, const char *old_name, const char *new_name) { int i; struct ged_display_list *gdlp; struct directory *dp; struct rt_db_internal intern; struct rt_comb_internal *comb; struct bu_ptbl stack; /* rename the record itself */ if ((dp = db_lookup(gedp->ged_wdbp->dbip, old_name, LOOKUP_NOISY)) == RT_DIR_NULL) return GED_ERROR; if (db_lookup(gedp->ged_wdbp->dbip, new_name, LOOKUP_QUIET) != RT_DIR_NULL) { bu_vls_printf(gedp->ged_result_str, "%s: already exists", new_name); return GED_ERROR; } /* if this was a sketch, we need to look for all the extrude * objects that might use it. * * This has to be done here, before we rename the (possible) sketch object * because the extrude will do a rt_db_get on the sketch when we call * rt_db_get_internal on it. */ if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && \ dp->d_minor_type == DB5_MINORTYPE_BRLCAD_SKETCH) { struct directory *dirp; for (i = 0; i < RT_DBNHASH; i++) { for (dirp = gedp->ged_wdbp->dbip->dbi_Head[i]; dirp != RT_DIR_NULL; dirp = dirp->d_forw) { if (dirp->d_major_type == DB5_MAJORTYPE_BRLCAD && \ dirp->d_minor_type == DB5_MINORTYPE_BRLCAD_EXTRUDE) { struct rt_extrude_internal *extrude; if (rt_db_get_internal(&intern, dirp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { bu_log("Can't get extrude %s?\n", dirp->d_namep); continue; } extrude = (struct rt_extrude_internal *)intern.idb_ptr; RT_EXTRUDE_CK_MAGIC(extrude); if (BU_STR_EQUAL(extrude->sketch_name, old_name)) { if (nflag) { bu_vls_printf(gedp->ged_result_str, "%s ", dirp->d_namep); rt_db_free_internal(&intern); } else { bu_free(extrude->sketch_name, "sketch name"); extrude->sketch_name = bu_strdup(new_name); if (rt_db_put_internal(dirp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { bu_log("oops\n"); } } } else rt_db_free_internal(&intern); } } } } if (!nflag) { /* Change object name in the directory. */ if (db_rename(gedp->ged_wdbp->dbip, dp, new_name) < 0) { bu_vls_printf(gedp->ged_result_str, "error in rename to %s, aborting", new_name); return GED_ERROR; } /* Change name in the file */ if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { bu_vls_printf(gedp->ged_result_str, "Database read error, aborting"); return GED_ERROR; } if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { bu_vls_printf(gedp->ged_result_str, "Database write error, aborting"); return GED_ERROR; } } bu_ptbl_init(&stack, 64, "combination stack for wdb_mvall_cmd"); /* Examine all COMB nodes */ for (i = 0; i < RT_DBNHASH; i++) { for (dp = gedp->ged_wdbp->dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) { if (nflag) { union tree *comb_leaf; int done=0; if (!(dp->d_flags & RT_DIR_COMB)) continue; if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) continue; comb = (struct rt_comb_internal *)intern.idb_ptr; bu_ptbl_reset(&stack); /* visit each leaf in the combination */ comb_leaf = comb->tree; if (comb_leaf) { while (!done) { while (comb_leaf->tr_op != OP_DB_LEAF) { bu_ptbl_ins(&stack, (long *)comb_leaf); comb_leaf = comb_leaf->tr_b.tb_left; } if (BU_STR_EQUAL(comb_leaf->tr_l.tl_name, old_name)) { bu_vls_printf(gedp->ged_result_str, "%s ", dp->d_namep); } if (BU_PTBL_END(&stack) < 1) { done = 1; break; } comb_leaf = (union tree *)BU_PTBL_GET(&stack, BU_PTBL_END(&stack)-1); if (comb_leaf->tr_op != OP_DB_LEAF) { bu_ptbl_rm(&stack, (long *)comb_leaf); comb_leaf = comb_leaf->tr_b.tb_right; } } } rt_db_free_internal(&intern); } else { int comb_mvall_status = db_comb_mvall(dp, gedp->ged_wdbp->dbip, old_name, new_name, &stack); if (!comb_mvall_status) continue; if (comb_mvall_status == 2) { bu_ptbl_free(&stack); bu_vls_printf(gedp->ged_result_str, "Database write error, aborting"); return GED_ERROR; } } } } bu_ptbl_free(&stack); if (!nflag) { /* Change object name anywhere in the display list path. */ for (BU_LIST_FOR(gdlp, ged_display_list, gedp->ged_gdp->gd_headDisplay)) { int first = 1; int found = 0; struct bu_vls new_path = BU_VLS_INIT_ZERO; char *dupstr = strdup(bu_vls_addr(&gdlp->gdl_path)); char *tok = strtok(dupstr, "/"); while (tok) { if (BU_STR_EQUAL(tok, old_name)) { found = 1; if (first) { first = 0; bu_vls_printf(&new_path, "%s", new_name); } else bu_vls_printf(&new_path, "/%s", new_name); } else { if (first) { first = 0; bu_vls_printf(&new_path, "%s", tok); } else bu_vls_printf(&new_path, "/%s", tok); } tok = strtok((char *)NULL, "/"); } if (found) { bu_vls_free(&gdlp->gdl_path); bu_vls_printf(&gdlp->gdl_path, "%s", bu_vls_addr(&new_path)); } free((void *)dupstr); bu_vls_free(&new_path); } } return GED_OK; }
int main(int argc, char **argv) { int i; int c; struct plate_mode pm; bu_setprogname(argv[0]); bu_setlinebuf( stderr ); the_model = nmg_mm(); tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; tree_state.ts_m = &the_model; ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; ttol.rel = 0.01; ttol.norm = 0.0; /* FIXME: These need to be improved */ tol.magic = BN_TOL_MAGIC; tol.dist = BN_TOL_DIST; tol.dist_sq = tol.dist * tol.dist; tol.perp = 1e-6; tol.para = 1 - tol.perp; /* NOTE: For visualization purposes, in the debug plot files */ { /* WTF: This value is specific to the Bradley */ nmg_eue_dist = 2.0; } BU_LIST_INIT( &RTG.rtg_vlfree ); /* for vlist macros */ BARRIER_CHECK; /* Get command line arguments. */ while ((c = bu_getopt(argc, argv, "d:a:n:o:r:vx:P:X:u:h?")) != -1) { switch (c) { case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'd': /* calculational tolerance */ tol.dist = atof( bu_optarg ); tol.dist_sq = tol.dist * tol.dist; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg)*DEG2RAD; ttol.rel = 0.0; break; case 'o': /* Output file name */ out_file = bu_optarg; break; case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'v': verbose++; break; case 'P': ncpu = atoi(bu_optarg); break; case 'x': sscanf( bu_optarg, "%x", (unsigned int *)&RTG.debug ); break; case 'X': sscanf( bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug ); NMG_debug = RTG.NMG_debug; break; case 'u': units = bu_strdup( bu_optarg ); scale_factor = bu_units_conversion( units ); if ( ZERO(scale_factor) ) bu_exit(1, "Unrecognized units (%s)\n", units ); scale_factor = 1.0 / scale_factor; break; default: print_usage(argv[0]); } } if (bu_optind+1 >= argc) print_usage(argv[0]); /* Open BRL-CAD database */ if ((dbip = db_open( argv[bu_optind], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[0]); bu_exit(1, "Cannot open geometry database file %s\n", argv[bu_optind] ); } if ( db_dirbuild( dbip ) ) bu_exit(1, "db_dirbuild() failed!\n" ); if (out_file == NULL) { outfp = stdout; setmode(fileno(outfp), O_BINARY); } else { if ((outfp = fopen( out_file, "wb")) == NULL) { perror( argv[0] ); bu_exit(2, "Cannot open %s\n", out_file ); } } writeX3dHeader(outfp, out_file); bu_optind++; BARRIER_CHECK; pm.num_bots = 0; pm.num_nonbots = 0; pm.array_size = 5; pm.bots = (struct rt_bot_internal **)bu_calloc( pm.array_size, sizeof( struct rt_bot_internal *), "pm.bots" ); for ( i=bu_optind; i<argc; i++ ) { struct directory *dp; dp = db_lookup( dbip, argv[i], LOOKUP_QUIET ); if ( dp == RT_DIR_NULL ) { bu_log( "Cannot find %s\n", argv[i] ); continue; } /* light source must be a combination */ if ( !(dp->d_flags & RT_DIR_COMB) ) continue; /* walk trees selecting only light source regions */ (void)db_walk_tree(dbip, 1, (const char **)(&argv[i]), ncpu, &tree_state, select_lights, do_region_end, leaf_tess, (void *)&pm); /* in librt/nmg_bool.c */ } BARRIER_CHECK; /* Walk indicated tree(s). Each non-light-source region will be output separately */ (void)db_walk_tree(dbip, argc-bu_optind, (const char **)(&argv[bu_optind]), ncpu, &tree_state, select_non_lights, do_region_end, leaf_tess, (void *)&pm); /* in librt/nmg_bool.c */ BARRIER_CHECK; /* Release dynamic storage */ nmg_km(the_model); db_close(dbip); /* Now we need to close each group set */ writeX3dEnd(outfp); if ( verbose ) bu_log( "Total of %d regions converted of %d regions attempted\n", regions_converted, regions_tried ); return 0; }