BRL-CAD
arced.c
Go to the documentation of this file.
1 /* A R C E D . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libged/arced.c
21  *
22  * The arced command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "ged.h"
31 
32 
33 int
34 ged_arced(struct ged *gedp, int argc, const char *argv[])
35 {
36  struct animate *anp;
37  struct directory *dp;
38  mat_t stack;
39  struct rt_db_internal intern;
40  struct rt_comb_internal *comb;
41  union tree *tp;
42  static const char *usage = "a/b anim_cmd ...";
43 
46  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
47 
48  /* initialize result */
49  bu_vls_trunc(gedp->ged_result_str, 0);
50 
51  /* must be wanting help */
52  if (argc == 1) {
53  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
54  return GED_HELP;
55  }
56 
57  if (argc < 3) {
58  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
59  return GED_ERROR;
60  }
61 
62  if (!strchr(argv[1], '/')) {
63  bu_vls_printf(gedp->ged_result_str, "arced: bad path specification '%s'", argv[1]);
64  return GED_ERROR;
65  }
66  anp = db_parse_1anim(gedp->ged_wdbp->dbip, argc, (const char **)argv);
67  if (!anp) {
68  bu_vls_printf(gedp->ged_result_str, "arced: unable to parse command");
69  return GED_ERROR;
70  }
71  if (anp->an_path.fp_len < 2) {
72  db_free_1anim(anp);
73  bu_vls_printf(gedp->ged_result_str, "arced: path spec has insufficient elements\n");
74  return GED_ERROR;
75  }
76 
77  /* Only the matrix rarc, lmul, and rmul directives are useful here */
78  MAT_IDN(stack);
79 
80  /* Load the combination into memory */
81  dp = anp->an_path.fp_names[anp->an_path.fp_len-2];
82  RT_CK_DIR(dp);
83  if ((dp->d_flags & RT_DIR_COMB) == 0) {
84  db_free_1anim(anp);
85  bu_vls_printf(gedp->ged_result_str, "%s: not a combination", dp->d_namep);
86  return GED_ERROR;
87  }
88  /* GED_DB_GET_INTERNAL(gedp, &intern, (fastf_t *)NULL, &rt_uniresource, GED_ERROR); */
89  if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) {
90  db_free_1anim(anp);
91  bu_vls_printf(gedp->ged_result_str, "Database read error, aborting");
92  return GED_ERROR;
93  }
94  comb = (struct rt_comb_internal *)intern.idb_ptr;
95  RT_CK_COMB(comb);
96  if (!comb->tree) {
97  bu_vls_printf(gedp->ged_result_str, "%s: empty combination", dp->d_namep);
98  goto fail;
99  }
100 
101  /* Search for first mention of arc */
102  if ((tp = db_find_named_leaf(comb->tree, anp->an_path.fp_names[anp->an_path.fp_len-1]->d_namep)) == TREE_NULL) {
103  bu_vls_printf(gedp->ged_result_str, "Unable to find instance of '%s' in combination '%s', error",
104  anp->an_path.fp_names[anp->an_path.fp_len-1]->d_namep,
105  anp->an_path.fp_names[anp->an_path.fp_len-2]->d_namep);
106  goto fail;
107  }
108 
109  /* Found match. Update tl_mat in place. */
110  if (!tp->tr_l.tl_mat)
112 
113  if (db_do_anim(anp, stack, tp->tr_l.tl_mat, NULL) < 0) {
114  goto fail;
115  }
116 
117  if (bn_mat_is_identity(tp->tr_l.tl_mat)) {
118  bu_free((void *)tp->tr_l.tl_mat, "tl_mat");
119  tp->tr_l.tl_mat = (matp_t)NULL;
120  }
121 
122  if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) {
123  bu_vls_printf(gedp->ged_result_str, "Database write error, aborting");
124  goto fail;
125  }
126  db_free_1anim(anp);
127  return GED_OK;
128 
129 fail:
130  rt_db_free_internal(&intern);
131  db_free_1anim(anp);
132  return GED_ERROR;
133 }
134 
135 
136 /*
137  * Local Variables:
138  * tab-width: 8
139  * mode: C
140  * indent-tabs-mode: t
141  * c-file-style: "stroustrup"
142  * End:
143  * ex: shiftwidth=4 tabstop=8
144  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
char * d_namep
pointer to name string
Definition: raytrace.h:859
int rt_db_get_internal(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat, struct resource *resp)
Definition: dir.c:76
int bn_mat_is_identity(const mat_t m)
Definition: mat.c:980
int rt_db_put_internal(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip, struct resource *resp)
Definition: dir.c:136
union tree * db_find_named_leaf(union tree *tp, const char *cp)
Definition: db_tree.c:393
size_t fp_len
Definition: db_fullpath.h:44
Definition: ged.h:338
const mat_t bn_mat_identity
Matrix and vector functionality.
Definition: mat.c:46
struct db_i * dbip
Definition: raytrace.h:1266
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
#define RT_CK_COMB(_p)
Definition: raytrace.h:955
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
int ged_arced(struct ged *gedp, int argc, const char *argv[])
Definition: arced.c:34
char * strchr(const char *sp, int c)
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define RT_CK_DIR(_dp)
Definition: raytrace.h:876
#define TREE_NULL
Definition: raytrace.h:1181
matp_t tl_mat
xform matp, NULL ==> identity
Definition: raytrace.h:1173
matp_t bn_mat_dup(const mat_t in)
Definition: mat.c:1046
struct directory ** fp_names
array of dir pointers
Definition: db_fullpath.h:46
struct bu_vls * ged_result_str
Definition: ged.h:357
int db_do_anim(struct animate *anp, mat_t stack, mat_t arc, struct mater_info *materp)
struct animate * db_parse_1anim(struct db_i *dbip, int argc, const char **argv)
struct db_full_path an_path
(sub)-path pattern
Definition: raytrace.h:1339
struct tree::tree_db_leaf tr_l
void * idb_ptr
Definition: raytrace.h:195
#define RT_DIR_COMB
combination
Definition: raytrace.h:884
union tree * tree
Leading to tree_db_leaf leaves.
Definition: raytrace.h:938
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
void db_free_1anim(struct animate *anp)
Definition: db_anim.c:208
#define GED_CHECK_READ_ONLY(_gedp, _flags)
Definition: ged.h:181
int d_flags
flags
Definition: raytrace.h:869
double fastf_t
Definition: defines.h:300
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216