/** * B U _ P T B L * * This version maintained for source compatibility with existing NMG code. */ int bu_ptbl(struct bu_ptbl *b, int func, long int *p) { if (func == BU_PTBL_INIT) { bu_ptbl_init(b, 64, "bu_ptbl() buffer[]"); return 0; } else if (func == BU_PTBL_RST) { bu_ptbl_reset(b); return 0; } else if (func == BU_PTBL_INS) { return bu_ptbl_ins(b, p); } else if (func == BU_PTBL_LOC) { return bu_ptbl_locate(b, p); } else if ( func == BU_PTBL_ZERO ) { bu_ptbl_zero(b, p); return( 0 ); } else if (func == BU_PTBL_INS_UNIQUE) { return bu_ptbl_ins_unique(b, p); } else if (func == BU_PTBL_RM) { return bu_ptbl_rm(b, p); } else if (func == BU_PTBL_CAT) { bu_ptbl_cat( b, (const struct bu_ptbl *)p ); return(0); } else if (func == BU_PTBL_FREE) { bu_ptbl_free(b); return (0); } else { BU_CK_PTBL(b); bu_log("bu_ptbl(%8x) Unknown table function %d\n", b, func); bu_bomb("bu_ptbl"); } return(-1);/* this is here to keep lint happy */ }
void db_close_client(struct db_i *dbip, long int *client) { if (!dbip) return; RT_CK_DBI(dbip); if (client) { (void)bu_ptbl_rm(&dbip->dbi_clients, client); } db_close(dbip); }
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; }
static int selection_command( struct ged *gedp, struct rt_db_internal *ip, int argc, const char *argv[]) { int i; struct rt_selection_set *selection_set; struct bu_ptbl *selections; struct rt_selection *new_selection; struct rt_selection_query query; const char *cmd, *solid_name, *selection_name; /* 0 1 2 3 * brep <solid_name> selection subcommand */ if (argc < 4) { return -1; } solid_name = argv[1]; cmd = argv[3]; if (BU_STR_EQUAL(cmd, "append")) { /* append to named selection - selection is created if it doesn't exist */ void (*free_selection)(struct rt_selection *); /* 4 5 6 7 8 9 10 * selection_name startx starty startz dirx diry dirz */ if (argc != 11) { bu_log("wrong args for selection append"); return -1; } selection_name = argv[4]; /* find matching selections */ query.start[X] = atof(argv[5]); query.start[Y] = atof(argv[6]); query.start[Z] = atof(argv[7]); query.dir[X] = atof(argv[8]); query.dir[Y] = atof(argv[9]); query.dir[Z] = atof(argv[10]); query.sorting = RT_SORT_CLOSEST_TO_START; selection_set = ip->idb_meth->ft_find_selections(ip, &query); if (!selection_set) { bu_log("no matching selections"); return -1; } /* could be multiple options, just grabbing the first and * freeing the rest */ selections = &selection_set->selections; new_selection = (struct rt_selection *)BU_PTBL_GET(selections, 0); free_selection = selection_set->free_selection; for (i = BU_PTBL_LEN(selections) - 1; i > 0; --i) { long *s = BU_PTBL_GET(selections, i); free_selection((struct rt_selection *)s); bu_ptbl_rm(selections, s); } bu_ptbl_free(selections); BU_FREE(selection_set, struct rt_selection_set); /* get existing/new selections set in gedp */ selection_set = ged_get_selection_set(gedp, solid_name, selection_name); selection_set->free_selection = free_selection; selections = &selection_set->selections; /* TODO: Need to implement append by passing new and * existing selection to an rt_brep_evaluate_selection. * For now, new selection simply replaces old one. */ for (i = BU_PTBL_LEN(selections) - 1; i >= 0; --i) { long *s = BU_PTBL_GET(selections, i); free_selection((struct rt_selection *)s); bu_ptbl_rm(selections, s); } bu_ptbl_ins(selections, (long *)new_selection); } else if (BU_STR_EQUAL(cmd, "translate")) { struct rt_selection_operation operation; /* 4 5 6 7 * selection_name dx dy dz */ if (argc != 8) { return -1; } selection_name = argv[4]; selection_set = ged_get_selection_set(gedp, solid_name, selection_name); selections = &selection_set->selections; if (BU_PTBL_LEN(selections) < 1) { return -1; } for (i = 0; i < (int)BU_PTBL_LEN(selections); ++i) { int ret; operation.type = RT_SELECTION_TRANSLATION; operation.parameters.tran.dx = atof(argv[5]); operation.parameters.tran.dy = atof(argv[6]); operation.parameters.tran.dz = atof(argv[7]); ret = ip->idb_meth->ft_process_selection(ip, gedp->ged_wdbp->dbip, (struct rt_selection *)BU_PTBL_GET(selections, i), &operation); if (ret != 0) { return ret; } } } return 0; }