/* * Supports for the 'keep' method. * Write each node encountered exactly once. */ HIDDEN void node_write(struct db_i *dbip, struct directory *dp, void *ptr) { struct keep_node_data *kndp = (struct keep_node_data *)ptr; struct rt_db_internal intern; RT_CK_WDB(kndp->wdbp); if (dp->d_nref++ > 0) return; /* already written */ if (rt_db_get_internal(&intern, dp, dbip, NULL, &rt_uniresource) < 0) { bu_vls_printf(kndp->gedp->ged_result_str, "Database read error, aborting\n"); return; } if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_EXTRUDE) { /* if this is an extrusion, keep the referenced sketch */ struct rt_extrude_internal *extr; struct directory *dp2; extr = (struct rt_extrude_internal *)intern.idb_ptr; RT_EXTRUDE_CK_MAGIC(extr); if ((dp2 = db_lookup(dbip, extr->sketch_name, LOOKUP_QUIET)) != RT_DIR_NULL) { node_write(dbip, dp2, ptr); } } else if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_REVOLVE) { /* if this is a revolve, keep the referenced sketch */ struct rt_revolve_internal *rev; struct directory *dp2; rev = (struct rt_revolve_internal *)intern.idb_ptr; RT_REVOLVE_CK_MAGIC(rev); if ((dp2 = db_lookup(dbip, bu_vls_addr(&rev->sketch_name), LOOKUP_QUIET)) != RT_DIR_NULL) { node_write(dbip, dp2, ptr); } } else if (dp->d_major_type == DB5_MAJORTYPE_BRLCAD && dp->d_minor_type == DB5_MINORTYPE_BRLCAD_DSP) { /* if this is a DSP, keep the referenced binary object too */ struct rt_dsp_internal *dsp; struct directory *dp2; dsp = (struct rt_dsp_internal *)intern.idb_ptr; RT_DSP_CK_MAGIC(dsp); if (dsp->dsp_datasrc == RT_DSP_SRC_OBJ) { /* need to keep this object */ if ((dp2 = db_lookup(dbip, bu_vls_addr(&dsp->dsp_name), LOOKUP_QUIET)) != RT_DIR_NULL) { node_write(dbip, dp2, ptr); } } } if (wdb_put_internal(kndp->wdbp, dp->d_namep, &intern, 1.0) < 0) { bu_vls_printf(kndp->gedp->ged_result_str, "Database write error, aborting\n"); return; } }
int ged_cat(struct ged *gedp, int argc, const char *argv[]) { struct directory *dp; int arg; static const char *usage = "<objects>"; GED_CHECK_DATABASE_OPEN(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 (arg = 1; arg < argc; arg++) { if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[arg], LOOKUP_NOISY)) == RT_DIR_NULL) continue; _ged_do_list(gedp, dp, 0); /* non-verbose */ } return GED_OK; }
std::string BRLCADWrapper::GetBRLCADName(std::string &name) { std::ostringstream str; std::string strcnt; struct bu_vls obj_name = BU_VLS_INIT_ZERO; int len = 0; char *cp,*tp; static int start = 1; for (cp = (char *)name.c_str(), len = 0; *cp != '\0'; ++cp, ++len) { if (*cp == '@') { if (*(cp + 1) == '@') ++cp; else break; } bu_vls_putc(&obj_name, *cp); } bu_vls_putc(&obj_name, '\0'); tp = (char *)((*cp == '\0') ? "" : cp + 1); do { bu_vls_trunc(&obj_name, len); bu_vls_printf(&obj_name, "%d", start++); bu_vls_strcat(&obj_name, tp); } while (db_lookup(outfp->dbip, bu_vls_addr(&obj_name), LOOKUP_QUIET) != RT_DIR_NULL); return bu_vls_addr(&obj_name); }
HIDDEN void edcodes_traverse_node(struct db_i *dbip, struct rt_comb_internal *UNUSED(comb), union tree *comb_leaf, void *user_ptr1, void *user_ptr2, void *user_ptr3, void *UNUSED(user_ptr4)) { int ret; int *pathpos; struct directory *nextdp; struct ged *gedp; RT_CK_DBI(dbip); RT_CK_TREE(comb_leaf); if ((nextdp=db_lookup(dbip, comb_leaf->tr_l.tl_name, LOOKUP_NOISY)) == RT_DIR_NULL) return; pathpos = (int *)user_ptr1; gedp = (struct ged *)user_ptr2; /* recurse on combinations */ if (nextdp->d_flags & RT_DIR_COMB) { int *status = (int *)user_ptr3; ret = edcodes_collect_regnames(gedp, nextdp, (*pathpos)+1); if (status && ret == EDCODES_HALT) *status = EDCODES_HALT; } }
/*------------------------------------------------------------------------ * lsr_queue - generate Link State Request packets *------------------------------------------------------------------------ */ int lsr_queue(struct ospf_if *pif, struct ospf_nb *pnb, struct ep *pepin) { struct ep *pep = 0; struct ip *pipin = (struct ip *)pepin->ep_data; struct ospf *poin = (struct ospf *)pipin->ip_data; struct ospf_dd *pdd = (struct ospf_dd *)poin->ospf_data; struct ospf_lss *plss; struct ospf_db *pdb; int i, nlss; nlss = (poin->ospf_len - MINDDLEN) / LSSHDRLEN; plss = pdd->dd_lss; for (i=0; i<nlss; ++i, ++plss) { pdb = db_lookup(pif->if_area, plss->lss_type, plss->lss_lsid); if (pdb == 0) pep = lsr_add(pif, plss, pep); /* if plss newer, pep = lsr_add(pif, plss, pep); */ } if (pep && enq(pnb->nb_lsrl, pep, 0) < 0) freebuf(pep); lsr_xmit(pif, pnb); }
/* now look for objects in the other database that aren't here */ FOR_ALL_DIRECTORY_START(dp2, dbip2) { /* skip the _GLOBAL object */ if (dp2->d_major_type == DB5_MAJORTYPE_ATTRIBUTE_ONLY) continue; /* check if this object exists in the other database */ if (db_lookup(dbip1, dp2->d_namep, 0) == RT_DIR_NULL) { /* need to add this object */ has_diff += 1; argv[2] = dp2->d_namep; /* FIXME: use libtclcad's get interface or libged or librt * directly, just not wdb_obj */ if (wdb_get_tcl((void *)dbip2->dbi_wdbp, 3, (const char **)argv) == TCL_ERROR || !bu_strncmp(Tcl_GetStringResult(interp), "invalid", 7)) { /* could not get TCL version */ if (mode == HUMAN) printf("Import %s from %s\n", dp2->d_namep, dbip2->dbi_filename); else printf("# IMPORT %s from %s\n", dp2->d_namep, dbip2->dbi_filename); } else { if (mode == HUMAN) printf("%s does not exist in %s\n", dp2->d_namep, dbip1->dbi_filename); else printf("db put %s %s\n", dp2->d_namep, Tcl_GetStringResult(interp)); } Tcl_ResetResult(interp); } } FOR_ALL_DIRECTORY_END;
void buy() { char name[200]; key k; result res; read_until(STDIN, name, 200, '\n'); k.data.count = strlen(name) + 1; k.data.data = (opaque *)name; res = db_lookup(k); if (res.status == SUCCESS) { item_details *d = (item_details *)res.rec.data->data.data; if (d->count < 1) { printf("Not enought items\n"); } else { d->count--; if (d->count == 0) db_delete(k); else db_insert(*res.rec.data); } } else { printf("Item not found\n"); } }
void crregion(char *region, char *op, int *members, int number, char *solidname, int maxlen) { int i; struct bu_list head; if (dbip == DBI_NULL) return; BU_LIST_INIT(&head); for (i=0; i<number; i++) { solidname[8] = '\0'; crname(solidname, members[i], maxlen); if ( db_lookup( dbip, solidname, LOOKUP_QUIET) == DIR_NULL ) { Tcl_AppendResult(interp, "region: ", region, " will skip member: ", solidname, "\n", (char *)NULL); continue; } mk_addmember( solidname, &head, NULL, op[i] ); } (void)mk_comb( wdbp, region, &head, 1, NULL, NULL, NULL, 500+Trackpos+i, 0, mat_default, los_default, 0, 1, 1 ); }
int db_argv_to_path(struct db_full_path *pp, struct db_i *dbip, int argc, const char *const *argv) { struct directory *dp; int ret = 0; int i; RT_CK_DBI(dbip); /* Make a path structure just big enough */ pp->magic = DB_FULL_PATH_MAGIC; pp->fp_maxlen = pp->fp_len = argc; pp->fp_names = (struct directory **)bu_malloc( pp->fp_maxlen * sizeof(struct directory *), "db_argv_to_path path array"); pp->fp_bool = (int *)bu_calloc(pp->fp_maxlen, sizeof(int), "db_argv_to_path bool array"); pp->fp_mat = (matp_t *)bu_calloc(pp->fp_maxlen, sizeof(matp_t), "db_string_to_path mat array"); for (i = 0; i<argc; i++) { if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) { bu_log("db_argv_to_path() failed on element %d='%s'\n", i, argv[i]); ret = -1; /* FAILED */ /* Fall through, storing null dp in this location */ } pp->fp_names[i] = dp; } return ret; }
/* test functions */ int db_object_exists(struct exists_data *ed) { struct directory *dp = NULL; dp = db_lookup(ed->gedp->ged_wdbp->dbip, *(ed->t_wp), LOOKUP_QUIET); if (dp) return 1; return 0; }
int rt_db_lookup_internal ( struct db_i *dbip, const char *obj_name, struct directory **dpp, struct rt_db_internal *ip, int noisy, struct resource *resp) { struct directory *dp; if (obj_name == (char *) 0) { if (noisy == LOOKUP_NOISY) bu_log("rt_db_lookup_internal() No object specified\n"); return ID_NULL; } if ((dp = db_lookup(dbip, obj_name, noisy)) == RT_DIR_NULL) return ID_NULL; if (rt_db_get_internal(ip, dp, dbip, (matp_t) NULL, resp) < 0) { if (noisy == LOOKUP_NOISY) bu_log("rt_db_lookup_internal() Failed to get internal form of object '%s'\n", dp->d_namep); return ID_NULL; } *dpp = dp; return ip->idb_type; }
static void dup_dir_check5(struct db_i *input_dbip, const struct db5_raw_internal *rip, off_t addr, void *ptr) { char *name; struct directory *dupdp; struct bu_vls local = BU_VLS_INIT_ZERO; struct dir_check_stuff *dcsp = (struct dir_check_stuff *)ptr; if (dcsp->main_dbip == DBI_NULL) return; RT_CK_DBI(input_dbip); RT_CK_RIP(rip); if (rip->h_dli == DB5HDR_HFLAGS_DLI_HEADER_OBJECT) return; if (rip->h_dli == DB5HDR_HFLAGS_DLI_FREE_STORAGE) return; name = (char *)rip->name.ext_buf; if (name == (char *)NULL) return; if (addr == 0) return; /* do not compare _GLOBAL */ if (rip->major_type == DB5_MAJORTYPE_ATTRIBUTE_ONLY && rip->minor_type == 0) return; /* Add the prefix, if any */ if (db_version(dcsp->main_dbip) < 5) { if (dcsp->wdbp->wdb_ncharadd > 0) { bu_vls_strncpy(&local, bu_vls_addr(&dcsp->wdbp->wdb_prestr), dcsp->wdbp->wdb_ncharadd); bu_vls_strcat(&local, name); } else { bu_vls_strncpy(&local, name, _GED_V4_MAXNAME); } bu_vls_trunc(&local, _GED_V4_MAXNAME); } else { if (dcsp->wdbp->wdb_ncharadd > 0) { (void)bu_vls_vlscat(&local, &dcsp->wdbp->wdb_prestr); (void)bu_vls_strcat(&local, name); } else { (void)bu_vls_strcat(&local, name); } } /* Look up this new name in the existing (main) database */ if ((dupdp = db_lookup(dcsp->main_dbip, bu_vls_addr(&local), LOOKUP_QUIET)) != RT_DIR_NULL) { /* Duplicate found, add it to the list */ dcsp->wdbp->wdb_num_dups++; *dcsp->dup_dirp++ = dupdp; } bu_vls_free(&local); return; }
/* A "wrapping" combination is a combination that contains a single object * and does not apply a matrix to it */ int Comb_Is_Wrapper(struct directory *dp, struct rt_wdb *wdbp) { struct rt_db_internal comb_intern; struct rt_db_internal comb_child_intern; struct rt_comb_internal *comb; union tree *child; struct directory *child_dp; int node_count = 0; rt_db_get_internal(&comb_intern, dp, wdbp->dbip, bn_mat_identity, &rt_uniresource); RT_CK_DB_INTERNAL(&comb_intern); if (comb_intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_COMBINATION) { rt_db_free_internal(&comb_intern); return -1; } /* If this comb has more than one child, it isn't a wrapper */ comb = (struct rt_comb_internal *)comb_intern.idb_ptr; if (comb->tree) { node_count = db_count_tree_nodes(comb->tree, 0); if (node_count > 1) { rt_db_free_internal(&comb_intern); return 1; } } else { /* Empty comb */ return -2; } /* If the child doesn't exist, this isn't a wrapper */ child = _db_tree_get_child(comb->tree); child_dp = db_lookup(wdbp->dbip, child->tr_l.tl_name, LOOKUP_QUIET); if (child_dp == RT_DIR_NULL) { rt_db_free_internal(&comb_intern); return 1; } /* If the child is a comb, this isn't a wrapper */ rt_db_get_internal(&comb_child_intern, child_dp, wdbp->dbip, bn_mat_identity, &rt_uniresource); RT_CK_DB_INTERNAL(&comb_child_intern); if (comb_child_intern.idb_minor_type == DB5_MINORTYPE_BRLCAD_COMBINATION) { rt_db_free_internal(&comb_intern); rt_db_free_internal(&comb_child_intern); return 1; } /* If the child has a matrix over it, this isn't a wrapper */ if (child->tr_l.tl_mat) { rt_db_free_internal(&comb_intern); rt_db_free_internal(&comb_child_intern); return 1; } /* If we made it here, we have a wrapper */ rt_db_free_internal(&comb_intern); rt_db_free_internal(&comb_child_intern); return 0; }
/** * Creates one metaball object that includes all points from an * existing list (in 'av') of named metaballs. This routine creates * an rt_metaball_internal object directly via LIBRT given it requires * reading existing metaballs from the database. */ static void mix_balls(struct db_i *dbip, const char *name, int ac, const char *av[]) { int i; struct directory *dp; struct rt_metaball_internal *newmp; RT_CK_DBI(dbip); /* allocate a struct rt_metaball_internal object that we'll * manually fill in with points from the other metaballs being * joined together. */ BU_ALLOC(newmp, struct rt_metaball_internal); newmp->magic = RT_METABALL_INTERNAL_MAGIC; newmp->threshold = 1.0; newmp->method = 1; BU_LIST_INIT(&newmp->metaball_ctrl_head); bu_log("Combining together the following metaballs:\n"); for (i = 0; i < ac; i++) { struct rt_db_internal dir; struct rt_metaball_internal *mp; struct wdb_metaballpt *mpt; /* get a handle on the existing database object */ bu_log("\t%s\n", av[i]); dp = db_lookup(dbip, av[i], 1); if (!dp) { bu_log("Unable to find %s\n", av[i]); continue; } /* load the existing database object */ if (rt_db_get_internal(&dir, dp, dbip, NULL, &rt_uniresource) < 0) { bu_log("Unable to load %s\n", av[i]); continue; } /* access the metaball-specific internal structure */ mp = (struct rt_metaball_internal *)dir.idb_ptr; RT_METABALL_CK_MAGIC(mp); /* iterate over each point in that database object and add it * to our new metaball. */ for (BU_LIST_FOR(mpt, wdb_metaballpt, &mp->metaball_ctrl_head)) { bu_log("Adding point (%lf %lf %lf)\n", V3ARGS(mpt->coord)); rt_metaball_add_point(newmp, (const point_t *)&mpt->coord, mpt->fldstr, mpt->sweat); } } bu_log("Joining balls together and creating [%s] object\n", name); /* write out new "mega metaball" out to disk */ dbip->dbi_wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK); wdb_export(dbip->dbi_wdbp, name, newmp, ID_METABALL, 1.0); }
/* * Go poke the rgb values of a region, on the fly. * This does not update the inmemory database, * so any changes will vanish on next re-prep unless other measures * are taken. */ int sh_directchange_shader(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *argv[]) { long int rtip_val; struct rt_i *rtip; struct region *regp; struct directory *dp; struct bu_vls shader = BU_VLS_INIT_ZERO; if ( argc < 4 ) { Tcl_AppendResult(interp, "Usage: sh_directchange_shader $rtip comb shader_arg(s)\n", NULL); return TCL_ERROR; } rtip_val = atol(argv[1]); rtip = (struct rt_i *)rtip_val; RT_CK_RTI(rtip); if ( rtip->needprep ) { Tcl_AppendResult(interp, "rt_prep() hasn't been called yet, error.\n", NULL); return TCL_ERROR; } if ( (dp = db_lookup( rtip->rti_dbip, argv[2], LOOKUP_NOISY)) == RT_DIR_NULL ) { Tcl_AppendResult(interp, argv[2], ": not found\n", NULL); return TCL_ERROR; } bu_vls_from_argv(&shader, argc-3, argv+3); bu_vls_trimspace(&shader); /* Find all region names which match /comb/ pattern */ for ( BU_LIST_FOR( regp, region, &rtip->HeadRegion ) ) { /* if ( dp->d_flags & RT_DIR_REGION ) { */ /* name will occur at end of region string w/leading slash */ /* } else { */ /* name will occur anywhere, bracketed by slashes */ /* } */ /* XXX quick hack */ if ( strstr( regp->reg_name, argv[2] ) == NULL ) continue; /* Modify the region's shader string */ bu_log("sh_directchange_shader() changing %s\n", regp->reg_name); if ( regp->reg_mater.ma_shader ) bu_free( (void *)regp->reg_mater.ma_shader, "reg_mater.ma_shader"); regp->reg_mater.ma_shader = bu_vls_strdup(&shader); /* Update the shader */ mlib_free(regp); if ( mlib_setup( &mfHead, regp, rtip ) != 1 ) { Tcl_AppendResult(interp, regp->reg_name, ": mlib_setup() failure\n", NULL); } } bu_vls_free(&shader); return TCL_OK; }
int loadrep(char *inst_name) { char buf[BUFSIZE]; FILE *fp; extern XFORM *global_transform; XFORM *save_transform; DB_TAB *ed_rep; int retval=1; char *save_rep; BOUNDS bb; if ((ed_rep = db_lookup(inst_name)) == NULL) { /* not in memory */ snprintf(buf, MAXFILENAME, "./cells/%s.d", inst_name); if((fp = fopen(buf, "r")) == 0) { /* cannot find copy on disk */ retval=0; } else { /* found it on disk, read it in */ if (currep != NULL) { save_rep=strsave(currep->name); } else { save_rep=NULL; } currep = db_install(inst_name); /* create blank stub */ readin(buf, 1, EDI, NULL); currep->modified = 0; bb.init=0; save_transform = global_transform; db_render(currep, 0, &bb, D_READIN); /* set boundbox, etc */ global_transform = save_transform; if (save_rep != NULL) { currep=db_lookup(save_rep); free(save_rep); } else { currep=NULL; } } } return(retval); }
/* * Go poke the rgb values of a region, on the fly. * This does not update the inmemory database, * so any changes will vanish on next re-prep unless other measures * are taken. */ int sh_directchange_rgb(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *argv[]) { long int rtip_val; struct rt_i *rtip; struct region *regp; struct directory *dp; float r, g, b; if ( argc != 6 ) { Tcl_AppendResult(interp, "Usage: sh_directchange_rgb $rtip comb r g b\n", NULL); return TCL_ERROR; } r = atoi(argv[3+0]) / 255.0; g = atoi(argv[3+1]) / 255.0; b = atoi(argv[3+2]) / 255.0; rtip_val = atol(argv[1]); rtip = (struct rt_i *)rtip_val; RT_CK_RTI(rtip); if ( rtip->needprep ) { Tcl_AppendResult(interp, "rt_prep() hasn't been called yet, error.\n", NULL); return TCL_ERROR; } if ( (dp = db_lookup( rtip->rti_dbip, argv[2], LOOKUP_NOISY)) == RT_DIR_NULL ) { Tcl_AppendResult(interp, argv[2], ": not found\n", NULL); return TCL_ERROR; } /* Find all region names which match /comb/ pattern */ for ( BU_LIST_FOR( regp, region, &rtip->HeadRegion ) ) { /* if ( dp->d_flags & RT_DIR_REGION ) { */ /* name will occur at end of region string w/leading slash */ /* } else { */ /* name will occur anywhere, bracketed by slashes */ /* } */ /* XXX quick hack */ if ( strstr( regp->reg_name, argv[2] ) == NULL ) continue; /* Modify the region's color */ bu_log("sh_directchange_rgb() changing %s\n", regp->reg_name); VSET( regp->reg_mater.ma_color, r, g, b ); /* Update the shader */ mlib_free(regp); if ( mlib_setup( &mfHead, regp, rtip ) != 1 ) { Tcl_AppendResult(interp, regp->reg_name, ": mlib_setup() failure\n", NULL); } } return TCL_OK; }
HIDDEN void db_count_refs(struct db_i *dbip, struct rt_comb_internal *comb, union tree *comb_leaf, genptr_t dummy1, genptr_t dummy2, genptr_t dummy3) { struct directory *dp; RT_CK_TREE( comb_leaf ); if ( (dp=db_lookup(dbip, comb_leaf->tr_l.tl_name, LOOKUP_QUIET)) != DIR_NULL ) ++dp->d_nref; }
/*------------------------------------------------------------------------ * lsr_in - handle a received link state request packet *------------------------------------------------------------------------ */ void lsr_in(struct ep *pep) { struct ip *pipout, *pip = (struct ip *)pep->ep_data; struct ospf *poout, *po; struct ospf_if *pif = &ospf_if[pep->ep_ifn]; struct ospf_nb *pnb; struct ospf_lsr *plsr; struct ospf_lsu *plsu; struct ospf_db *pdb; struct ep *pepout, *ospflstmpl(struct ospf_if *); unsigned i, nlsr, maxlsapp; if (pif->if_state <= IFS_WAITING) return; pnb = &pif->if_nbtab[1]; po = (struct ospf *)((char *)pip+IP_HLEN(pip)); for (i=0; i<MAXNBR; ++i, ++pnb) if (pnb->nb_rid == po->ospf_rid) break; if (i == MAXNBR || pnb->nb_state < NBS_EXCHNG) return; maxlsapp = (nif[pep->ep_ifn].ni_mtu - IPMHLEN - MINLSULEN); maxlsapp /= (LSSHDRLEN + MAXLSDLEN); pepout = ospflstmpl(pif); if (pepout == 0) return; pipout = (struct ip *)pepout->ep_data; poout = (struct ospf *)pipout->ip_data; plsu = (struct ospf_lsu *)poout->ospf_data; nlsr = (po->ospf_len - MINHDRLEN) / sizeof (struct ospf_lsr); plsr = (struct ospf_lsr *)po->ospf_data; for (i=0; i<nlsr; ++i, ++plsr) { pdb = db_lookup(pif->if_area, plsr->lsr_type, plsr->lsr_lsid); if (pdb == 0) { freebuf(pepout); nb_mismatch(pif, pnb); return; } if (plsu->lsu_nads >= maxlsapp) { lsa_send(pif, pip->ip_src, pepout); if (!(pepout = ospflstmpl(pif))) return; pipout = (struct ip *)pepout->ep_data; poout = (struct ospf *)pipout->ip_data; plsu = (struct ospf_lsu *)poout->ospf_data; } lsa_add(pif, pepout, pdb); } lsa_send(pif, pip->ip_src, pepout); }
int ged_wcodes(struct ged *gedp, int argc, const char *argv[]) { int i; int status; FILE *fp; struct directory *dp; static const char *usage = "filename object(s)"; GED_CHECK_DATABASE_OPEN(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; } if (argc == 2) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } if ((fp = fopen(argv[1], "w")) == NULL) { bu_vls_printf(gedp->ged_result_str, "%s: Failed to open file - %s", argv[0], argv[1]); return GED_ERROR; } path = (struct directory **)bu_calloc(PATH_STEP, sizeof(struct directory *), "alloc initial path"); path_capacity = PATH_STEP; for (i = 2; i < argc; ++i) { if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) != RT_DIR_NULL) { status = wcodes_printcodes(gedp, fp, dp, 0); if (status == GED_ERROR) { (void)fclose(fp); return GED_ERROR; } } } (void)fclose(fp); bu_free(path, "dealloc path"); path = NULL; path_capacity = 0; return GED_OK; }
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; }
int get_de_pointers(union tree *tp, struct directory *dp, int de_len, int *de_pointers) { RT_CK_TREE(tp); RT_CK_DIR(dp); switch (tp->tr_op) { case OP_UNION: case OP_SUBTRACT: case OP_INTERSECT: get_de_pointers(tp->tr_b.tb_left, dp, de_len, de_pointers); get_de_pointers(tp->tr_b.tb_right, dp, de_len, de_pointers); break; case OP_DB_LEAF: { struct directory *dp_M; dp_M = db_lookup(DBIP, tp->tr_l.tl_name, LOOKUP_NOISY); if (dp_M == RT_DIR_NULL) return 1; if (dp_M->d_uses >= 0) { bu_log("g-iges: member (%s) in combination (%s) has not been written to iges file\n", dp_M->d_namep, dp->d_namep); de_pointers[de_pointer_number++] = 0; return 1; } if (tp->tr_l.tl_mat && !bn_mat_is_identity(tp->tr_l.tl_mat)) { /* write a solid instance entity for this member with a pointer to the new matrix */ if (!NEAR_ZERO(tp->tr_l.tl_mat[15] - 1.0, tol.dist)) { /* scale factor is not 1.0, IGES can't handle it. go ahead and write the solid instance anyway, but warn the user twice */ bu_log("g-iges WARNING: member (%s) of combination (%s) is scaled, IGES cannot handle this\n", dp_M->d_namep, dp->d_namep); scale_error++; } de_pointers[de_pointer_number++] = write_solid_instance(-dp_M->d_uses, tp->tr_l.tl_mat, fp_dir, fp_param); } else de_pointers[de_pointer_number++] = (-dp_M->d_uses); if (dp_M->d_nref) comb_form = 1; } break; default: bu_log("Unrecognized operator in combination!\n"); return 1; } return 0; }
void incr_refs(struct db_i *dbip, struct rt_comb_internal *comb, union tree *tp, void *UNUSED(user_ptr1), void *UNUSED(user_ptr2), void *UNUSED(user_ptr3), void *UNUSED(user_ptr4)) { struct directory *dp; RT_CK_COMB(comb); RT_CK_DBI(dbip); RT_CK_TREE(tp); if ((dp = db_lookup(dbip, tp->tr_l.tl_name, LOOKUP_NOISY)) == RT_DIR_NULL) return; dp->d_nref++; }
int db_dircheck(struct db_i *dbip, struct bu_vls *ret_name, int noisy, struct directory ***headp) { struct directory *dp; char *cp = bu_vls_addr(ret_name); char n0 = cp[0]; char n1 = cp[1]; /* Compute hash only once (almost always the case) */ *headp = &(dbip->dbi_Head[db_dirhash(cp)]); for (dp = **headp; dp != RT_DIR_NULL; dp=dp->d_forw) { char *this_obj; if (n0 == *(this_obj=dp->d_namep) && /* speed */ n1 == this_obj[1] && /* speed */ BU_STR_EQUAL(cp, this_obj)) { /* Name exists in directory already */ int c; bu_vls_strcpy(ret_name, "A_"); bu_vls_strcat(ret_name, this_obj); cp = bu_vls_addr(ret_name); for (c = 'A'; c <= 'Z'; c++) { *cp = c; if (db_lookup(dbip, cp, noisy) == RT_DIR_NULL) break; } if (c > 'Z') { bu_log("db_dircheck: Duplicate of name '%s', ignored\n", cp); return -1; /* fail */ } bu_log("db_dircheck: Duplicate of '%s', given temporary name '%s'\n", cp+2, cp); /* no need to recurse, simply recompute the hash and break */ *headp = &(dbip->dbi_Head[db_dirhash(cp)]); break; } } return 0; /* success */ }
int main(int argc, char** argv) { struct rt_wdb* outfp; ON_Brep* brep; ON_TextLog error_log; const char* id_name = "B-Rep Example"; const char* geom_name = "cube.s"; ON::Begin(); if (argc > 1) { printf("Writing a twisted cube b-rep...\n"); outfp = wdb_fopen("brep_cube1.g"); mk_id(outfp, id_name); brep = MakeTwistedCube(error_log); mk_brep(outfp, geom_name, brep); //mk_comb1(outfp, "cube.r", geom_name, 1); unsigned char rgb[] = {255,255,255}; mk_region1(outfp, "cube.r", geom_name, "plastic", "", rgb); wdb_close(outfp); delete brep; } printf("Reading a twisted cube b-rep...\n"); struct db_i* dbip = db_open("brep_cube1.g", "r"); db_dirbuild(dbip); struct directory* dirp; if ((dirp = db_lookup(dbip, "cube.s", 0)) != DIR_NULL) { printf("\tfound cube.s\n"); struct rt_db_internal ip; mat_t mat; MAT_IDN(mat); if (rt_db_get_internal(&ip, dirp, dbip, mat, &rt_uniresource) >= 0) { printPoints((struct rt_brep_internal*)ip.idb_ptr); } else { fprintf(stderr, "problem getting internal object rep\n"); } } db_close(dbip); ON::End(); return 0; }
int BRLFile::AddModel(char const *name) { if(dbip==DBI_NULL) return 1; struct directory *dp=db_lookup(dbip, name, 1); if(dp == NULL) return 1; rt_init_resource( &rt_uniresource, 0, NULL ); db_functree(dbip, dp, CsgCombine, CsgLeaf, &rt_uniresource, this); while(construction.size()>0) { Add(construction.front()); construction.pop_front(); } return 0; }
/*------------------------------------------------------------------------ * db_update - update/insert a link state advertisement *------------------------------------------------------------------------ */ int db_update(struct ospf_ar *par, struct ospf_lsa *plsa) { struct ospf_db *pdb; if (pdb = db_lookup(par, plsa->lsa_type, plsa->lsa_lsid)) { } else { int hv; pdb = db_new(par, plsa); pdb->db_lnext = par->ar_dblhead; par->ar_dblhead = pdb; hv = DBHASH(pdb->db_lsa.lsa_lsid); pdb->db_hnext = par->ar_htable[hv]; par->ar_htable[hv] = pdb; } }
/** * returns the next available/unused name, using a consistent naming * convention specific to combinations/regions and solids. * state->incr is used for each number level increase. */ static struct bu_vls * get_name(struct db_i *_dbip, struct directory *dp, struct clone_state *state, int iter) { struct bu_vls *newname; char prefix[CLONE_BUFSIZE] = {0}, suffix[CLONE_BUFSIZE] = {0}, buf[CLONE_BUFSIZE] = {0}, suffix2[CLONE_BUFSIZE] = {0}; int num = 0, i = 1, j = 0; newname = bu_vls_vlsinit(); /* Ugh. This needs much repair/cleanup. */ if (state->updpos == 0) { sscanf(dp->d_namep, "%[!-/,:-~]%d%[!-/,:-~]%512s", prefix, &num, suffix, suffix2); /* CLONE_BUFSIZE */ snprintf(suffix, CLONE_BUFSIZE, "%s", suffix2); } else if (state->updpos == 1) { int num2 = 0; sscanf(dp->d_namep, "%[!-/,:-~]%d%[!-/,:-~]%d%[!-/,:-~]", prefix, &num2, suffix2, &num, suffix); snprintf(prefix, CLONE_BUFSIZE, "%s%d%s", prefix, num2, suffix2); } else bu_exit(EXIT_FAILURE, "multiple -c options not supported yet."); do { /* choke the name back to the prefix */ bu_vls_trunc(newname, 0); bu_vls_strcpy(newname, prefix); if ((dp->d_flags & RT_DIR_SOLID) || (dp->d_flags & RT_DIR_REGION)) { /* primitives and regions */ if (suffix[0] != 0) if ((i == 1) && is_in_list(obj_list, buf)) { j = index_in_list(obj_list, buf); snprintf(buf, CLONE_BUFSIZE, "%s%d", prefix, num); /* save the name for the next pass */ /* clear and set the name */ bu_vls_trunc(newname, 0); bu_vls_printf(newname, "%V%s", obj_list.names[j].dest[iter], suffix); } else bu_vls_printf(newname, "%zu%s", num+i*state->incr, suffix); else bu_vls_printf(newname, "%zu", num + i*state->incr); } else /* non-region combinations */ bu_vls_printf(newname, "%d", (num==0)?i+1:i+num); i++; } while (db_lookup(_dbip, bu_vls_addr(newname), LOOKUP_QUIET) != NULL); return newname; }
int ged_whatid(struct ged *gedp, int argc, const char *argv[]) { struct directory *dp; struct rt_db_internal intern; struct rt_comb_internal *comb; static const char *usage = "region"; GED_CHECK_DATABASE_OPEN(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; } if (argc != 2) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } if ((dp=db_lookup(gedp->ged_wdbp->dbip, argv[1], LOOKUP_NOISY)) == RT_DIR_NULL) return GED_ERROR; if (!(dp->d_flags & RT_DIR_REGION)) { bu_vls_printf(gedp->ged_result_str, "%s is not a region", argv[1]); return GED_ERROR; } if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) return GED_ERROR; comb = (struct rt_comb_internal *)intern.idb_ptr; bu_vls_printf(gedp->ged_result_str, "%ld", comb->region_id); rt_db_free_internal(&intern); return GED_OK; }
HIDDEN int constraint_eval(void *datap, int argc, const char *argv[]) { size_t i, obj; struct directory *dp; struct bu_attribute_value_set avs; struct bu_attribute_value_pair *avpp; int ret = BRLCAD_OK; struct ged *gedp = (struct ged *)datap; if (!gedp || argc < 1 || !argv) return BRLCAD_ERROR; GED_CHECK_READ_ONLY(gedp, GED_ERROR); /* multiple arguments assumed to be multiple objects */ for (obj = 0; 2+obj < (size_t)argc; obj++) { /* load the constraint object */ dp = db_lookup(gedp->ged_wdbp->dbip, argv[2+obj], LOOKUP_QUIET); if (dp == RT_DIR_NULL) { bu_vls_printf(gedp->ged_result_str, "Unable to find %s in the database.\n", argv[2+obj]); ret = BRLCAD_ERROR; continue; } bu_avs_init_empty(&avs); if (db5_get_attributes(gedp->ged_wdbp->dbip, &avs, dp)) { bu_vls_printf(gedp->ged_result_str, "Cannot get constraints from %s\n", dp->d_namep); ret = BRLCAD_ERROR; } for (i=0, avpp = avs.avp; i < avs.count; i++, avpp++) { bu_vls_printf(gedp->ged_result_str, "Evaluating %s constraint: %s %s\n", argv[2+obj], avpp->name, avpp->value); bu_vls_printf(gedp->ged_result_str, "<<constraint eval here>>\n"); } bu_avs_free(&avs); } return ret; }