Exemple #1
0
HIDDEN int
convert_grid(int idx)
{
    struct coord_sys *cs;
    point_t tmp_pt;
    VSETALL(tmp_pt, 0.0);


    if (!g_pts[idx].cid)
	return 0;

    for (BU_LIST_FOR(cs, coord_sys, &coord_head.l)) {
	if (cs->cid != g_pts[idx].cid)
	    continue;
	break;
    }

    if (BU_LIST_IS_HEAD(&cs->l, &coord_head.l)) {
	bu_exit(1, "No coordinate system defined for grid point #%d!\n", g_pts[idx].gid);
    }

    if (convert_pt(g_pts[idx].pt, cs, tmp_pt))
	return 1;

    VMOVE(g_pts[idx].pt, tmp_pt);
    g_pts[idx].cid = 0;

    return 0;
}
Exemple #2
0
int
bu_cmdhist_next(void *clientData, int argc, const char **UNUSED(argv))
{
    struct bu_cmdhist_obj *chop = (struct bu_cmdhist_obj *)clientData;

    if (argc != 2) {
	bu_log("ERROR: expecting only two arguments\n");
	return BRLCAD_ERROR;
    }

    if (BU_LIST_IS_HEAD(chop->cho_curr, &chop->cho_head.l))
	return BRLCAD_ERROR;

    chop->cho_curr = BU_LIST_PNEXT(bu_cmdhist, chop->cho_curr);
    if (BU_LIST_IS_HEAD(chop->cho_curr, &chop->cho_head.l))
	return BRLCAD_ERROR;

    /* result is in chop->cho_curr */
    return BRLCAD_OK;
}
Exemple #3
0
HIDDEN void
get_cbar(void)
{
    int eid, pid;
    int g1, g2;
    point_t pt1, pt2;
    fastf_t radius;
    vect_t height;
    struct pbar *pb;
    char cbar_name[NAMESIZE+1];

    eid = atoi( curr_rec[1] );

    pid = atoi( curr_rec[2] );
    if ( !pid )
    {
	if ( bar_def_pid )
	    pid = bar_def_pid;
	else
	    pid = eid;
    }

    g1 = atoi( curr_rec[3] );

    g2 = atoi( curr_rec[4] );

    get_grid( g1, pt1 );
    get_grid( g2, pt2 );

    for ( BU_LIST_FOR( pb, pbar, &pbar_head.l ) )
    {
	if ( pb->pid == pid )
	    break;
    }

    if ( BU_LIST_IS_HEAD( &pb->l, &pbar_head.l ) )
    {
	log_line( "Non-existent PID referenced in CBAR" );
	return;
    }

    VSCALE( pt1, pt1, conv[units] );
    VSCALE( pt2, pt2, conv[units] );

    radius = sqrt( pb->area/bn_pi );
    radius = radius * conv[units];

    VSUB2( height, pt2, pt1 );

    sprintf( cbar_name, "cbar.%d", eid );
    mk_rcc( fpout, cbar_name, pt1, height, radius );

    mk_addmember( cbar_name, &pb->head.l, NULL, WMOP_UNION );
}
Exemple #4
0
/*
 * Usage:
 * write i|next c x y z
 */
static int
vdraw_write_tcl(void *clientData, int argc, const char *argv[])
{
    struct dg_obj *dgop = (struct dg_obj *)clientData;
    size_t idx;
    unsigned long uind = 0;
    struct bn_vlist *vp, *cp;

    if (!dgop->dgo_currVHead) {
	Tcl_AppendResult(dgop->interp, "vdraw write: no vlist is currently open.", (char *)NULL);
	return TCL_ERROR;
    }
    if (argc < 4) {
	Tcl_AppendResult(dgop->interp, "vdraw write: not enough args\n", (char *)NULL);
	return TCL_ERROR;
    }
    if (argv[1][0] == 'n') {
	/* next */
	for (REV_BU_LIST_FOR(vp, bn_vlist, &(dgop->dgo_currVHead->vdc_vhd))) {
	    if (vp->nused > 0) {
		break;
	    }
	}
	if (BU_LIST_IS_HEAD(vp, &(dgop->dgo_currVHead->vdc_vhd))) {
	    /* we went all the way through */
	    vp = BU_LIST_PNEXT(bn_vlist, vp);
	    if (BU_LIST_IS_HEAD(vp, &(dgop->dgo_currVHead->vdc_vhd))) {
		RT_GET_VLIST(vp);
		BU_LIST_INSERT(&(dgop->dgo_currVHead->vdc_vhd), &(vp->l));
	    }
	}
	if (vp->nused >= BN_VLIST_CHUNK) {
	    vp = BU_LIST_PNEXT(bn_vlist, vp);
	    if (BU_LIST_IS_HEAD(vp, &(dgop->dgo_currVHead->vdc_vhd))) {
		RT_GET_VLIST(vp);
		BU_LIST_INSERT(&(dgop->dgo_currVHead->vdc_vhd), &(vp->l));
	    }
	}
	cp = vp;
	idx = vp->nused;
    } else if (sscanf(argv[1], "%lu", &uind) < 1) {
Exemple #5
0
void
merge(void)
{
    struct frame *cur, *next;

    for (BU_LIST_FOR(cur, frame, &head)) {
	next = BU_LIST_NEXT(frame, &cur->l);
	if (BU_LIST_IS_HEAD(next, &head)) break;
	if (cur->number == next->number) {
	    if (next->text) addtext(cur, next->text);
	    cur->flags |= next->flags;
	    BU_LIST_DEQUEUE(&next->l);
	    if (next->text) bu_free(next->text, "text area");
	    next->text = NULL;
	    next->l.magic = -1;
	    bu_free(next, "struct frame");
	    cur = BU_LIST_PREV(frame, &cur->l);
	}
    }
}
Exemple #6
0
HIDDEN int
convert_cs(struct coord_sys *cs)
{
    struct coord_sys *cs2;
    point_t tmp_orig, tmp_pt1, tmp_pt2;
    VSETALL(tmp_orig, 0.0);
    VSETALL(tmp_pt1, 0.0);
    VSETALL(tmp_pt2, 0.0);

    if (!cs->rid)
	return 0;

    for (BU_LIST_FOR(cs2, coord_sys, &coord_head.l)) {
	if (cs2->cid != cs->rid)
	    continue;
	break;
    }

    if (BU_LIST_IS_HEAD(&cs2->l, &coord_head.l)) {
	bu_exit(1, "A coordinate system is defined in terms of a non-existent coordinate system!!!\n");
    }

    if (convert_pt(cs->origin, cs2, tmp_orig))
	return 1;

    if (convert_pt(cs->v1, cs2, tmp_pt1))
	return 1;

    if (convert_pt(cs->v2, cs2, tmp_pt2))
	return 1;

    VMOVE(cs->origin, tmp_orig);
    VSUB2(cs->v3, tmp_pt1, cs->origin);
    VUNITIZE(cs->v3);
    VSUB2(cs->v1, tmp_pt2, cs->origin);
    VCROSS(cs->v2, cs->v3, cs->v1);
    VUNITIZE(cs->v2);
    VCROSS(cs->v1, cs->v3, cs->v2);
    cs->rid = 0;
    return 0;
}
Exemple #7
0
int
ged_which(struct ged *gedp, int argc, const char *argv[])
{
    int i, j;
    struct directory *dp;
    struct rt_db_internal intern;
    struct rt_comb_internal *comb;
    struct _ged_id_to_names headIdName;
    struct _ged_id_to_names *itnp;
    struct _ged_id_names *inp;
    int isAir;
    int sflag;
    static const char *usageAir = "code(s)";
    static const char *usageIds = "region_id(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);

    if (BU_STR_EQUAL(argv[0], "whichair"))
	isAir = 1;
    else
	isAir = 0;

    /* must be wanting help */
    if (argc == 1) {
	if (isAir)
	    bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usageAir);
	else
	    bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usageIds);
	return GED_HELP;
    }

    if (BU_STR_EQUAL(argv[1], "-s")) {
	--argc;
	++argv;

	if (argc < 2) {
	    if (isAir)
		bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usageAir);
	    else
		bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usageIds);

	    return GED_ERROR;
	}

	sflag = 1;
    } else {
	sflag = 0;
    }

    BU_LIST_INIT(&headIdName.l);

    /* Build list of id_to_names */
    for (j = 1; j < argc; j++) {
	int n;
	int start, end;
	int range;
	int k;

	n = sscanf(argv[j], "%d%*[:-]%d", &start, &end);
	switch (n) {
	    case 1:
		for (BU_LIST_FOR(itnp, _ged_id_to_names, &headIdName.l))
		    if (itnp->id == start)
			break;

		/* id not found */
		if (BU_LIST_IS_HEAD(itnp, &headIdName.l)) {
		    BU_GET(itnp, struct _ged_id_to_names);
		    itnp->id = start;
		    BU_LIST_INSERT(&headIdName.l, &itnp->l);
		    BU_LIST_INIT(&itnp->headName.l);
		}

		break;
	    case 2:
		if (start < end)
		    range = end - start + 1;
		else if (end < start) {
		    range = start - end + 1;
		    start = end;
		} else
		    range = 1;

		for (k = 0; k < range; ++k) {
		    int id = start + k;

		    for (BU_LIST_FOR(itnp, _ged_id_to_names, &headIdName.l))
			if (itnp->id == id)
			    break;

		    /* id not found */
		    if (BU_LIST_IS_HEAD(itnp, &headIdName.l)) {
			BU_GET(itnp, struct _ged_id_to_names);
			itnp->id = id;
			BU_LIST_INSERT(&headIdName.l, &itnp->l);
			BU_LIST_INIT(&itnp->headName.l);
		    }
		}

		break;
	}
    }

    /* 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 (!(dp->d_flags & RT_DIR_REGION))
		continue;

	    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;
	    }
	    comb = (struct rt_comb_internal *)intern.idb_ptr;
	    /* check to see if the region id or air code matches one in our list */
	    for (BU_LIST_FOR(itnp, _ged_id_to_names, &headIdName.l)) {
		if ((!isAir && comb->region_id == itnp->id) ||
		    (isAir && comb->aircode == itnp->id)) {
		    /* add region name to our name list for this region */
		    BU_GET(inp, struct _ged_id_names);
		    bu_vls_init(&inp->name);
		    bu_vls_strcpy(&inp->name, dp->d_namep);
		    BU_LIST_INSERT(&itnp->headName.l, &inp->l);
		    break;
		}
	    }

	    rt_db_free_internal(&intern);
	}
    }

    /* place data in interp and free memory */
    while (BU_LIST_WHILE(itnp, _ged_id_to_names, &headIdName.l)) {
	if (!sflag) {
	    bu_vls_printf(gedp->ged_result_str, "Region[s] with %s %d:\n",
			  isAir ? "air code" : "ident", itnp->id);
	}

	while (BU_LIST_WHILE(inp, _ged_id_names, &itnp->headName.l)) {
	    if (sflag)
		bu_vls_printf(gedp->ged_result_str, " %V", &inp->name);
	    else
		bu_vls_printf(gedp->ged_result_str, "   %V\n", &inp->name);

	    BU_LIST_DEQUEUE(&inp->l);
	    bu_vls_free(&inp->name);
	    BU_PUT(inp, struct _ged_id_names);
	}

	BU_LIST_DEQUEUE(&itnp->l);
	BU_PUT(itnp, struct _ged_id_to_names);
    }

    return GED_OK;
}