BRL-CAD
trace.c
Go to the documentation of this file.
1 /* T R A C E . 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/trace.c
21  *
22  * The trace command.
23  *
24  */
25 
26 #include "ged.h"
27 
28 #include "./ged_private.h"
29 
30 
31 static void
32 trace_do(struct db_i *dbip,
33  struct rt_comb_internal *UNUSED(comb),
34  union tree *comb_leaf,
35  void *user_ptr1,
36  void *user_ptr2,
37  void *user_ptr3,
38  void *user_ptr4)
39 {
40  int *verbose;
41  int *pathpos;
42  matp_t old_xlate;
43  mat_t new_xlate;
44  struct directory *nextdp;
45  struct _ged_trace_data *gtdp;
46 
47  RT_CK_DBI(dbip);
48  RT_CK_TREE(comb_leaf);
49 
50  if ((nextdp = db_lookup(dbip, comb_leaf->tr_l.tl_name, LOOKUP_NOISY)) == RT_DIR_NULL)
51  return;
52 
53  pathpos = (int *)user_ptr1;
54  old_xlate = (matp_t)user_ptr2;
55  gtdp = (struct _ged_trace_data *)user_ptr3;
56  verbose = (int *)user_ptr4;
57 
58  /*
59  * In _GED_EVAL_ONLY mode we're collecting the matrices along
60  * the path in order to perform some type of edit where the object
61  * lives (i.e. after applying the accumulated transforms). So, if
62  * we're doing a matrix edit (i.e. the last object in the path is
63  * a combination), we skip its leaf matrices because those are the
64  * one's we'll be editing.
65  */
66  if (gtdp->gtd_flag != _GED_EVAL_ONLY ||
67  (*pathpos)+1 < gtdp->gtd_objpos) {
68  if (comb_leaf->tr_l.tl_mat) {
69  bn_mat_mul(new_xlate, old_xlate, comb_leaf->tr_l.tl_mat);
70  } else {
71  MAT_COPY(new_xlate, old_xlate);
72  }
73  } else {
74  MAT_COPY(new_xlate, old_xlate);
75  }
76 
77  ged_trace(nextdp, (*pathpos)+1, new_xlate, gtdp, *verbose);
78 }
79 
80 
81 void
82 ged_trace(struct directory *dp,
83  int pathpos,
84  const mat_t old_xlate,
85  struct _ged_trace_data *gtdp,
86  int verbose)
87 {
88  struct rt_db_internal intern;
89  struct rt_comb_internal *comb;
90  int i;
91  int id;
92 
93  if (pathpos >= _GED_MAX_LEVELS) {
94  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "nesting exceeds %d levels\n", _GED_MAX_LEVELS);
95 
96  for (i = 0; i < _GED_MAX_LEVELS; i++)
97  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "/%s", gtdp->gtd_path[i]->d_namep);
98 
100  return;
101  }
102 
103  if (dp->d_flags & RT_DIR_COMB) {
104  if (rt_db_get_internal(&intern, dp, gtdp->gtd_gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) {
105  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "Database read error, aborting");
106  return;
107  }
108 
109  gtdp->gtd_path[pathpos] = dp;
110  comb = (struct rt_comb_internal *)intern.idb_ptr;
111  if (comb->tree)
112  db_tree_funcleaf(gtdp->gtd_gedp->ged_wdbp->dbip, comb, comb->tree, trace_do,
113  (void *)&pathpos, (void *)old_xlate, (void *)gtdp, (void *)&verbose);
114 
115  rt_db_free_internal(&intern);
116 
117  return;
118  }
119 
120  /* not a combination - should have a solid */
121 
122  /* last (bottom) position */
123  gtdp->gtd_path[pathpos] = dp;
124 
125  /* check for desired path */
126  if (gtdp->gtd_flag == _GED_CPEVAL) {
127  for (i = 0; i <= pathpos; i++) {
128  if (gtdp->gtd_path[i]->d_addr != gtdp->gtd_obj[i]->d_addr) {
129  /* not the desired path */
130  return;
131  }
132  }
133  } else {
134  for (i = 0; i < gtdp->gtd_objpos; i++) {
135  if (gtdp->gtd_path[i]) {
136  if (gtdp->gtd_path[i]->d_addr != gtdp->gtd_obj[i]->d_addr) {
137  /* not the desired path */
138  return;
139  }
140  } else {
141  /* not the desired path */
142  return;
143  }
144  }
145  }
146 
147  /* have the desired path up to objpos */
148  MAT_COPY(gtdp->gtd_xform, old_xlate);
149  gtdp->gtd_prflag = 1;
150 
151  if (gtdp->gtd_flag == _GED_CPEVAL ||
152  gtdp->gtd_flag == _GED_EVAL_ONLY)
153  return;
154 
155  /* print the path */
156  for (i = 0; i < pathpos; i++)
157  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "/%s", gtdp->gtd_path[i]->d_namep);
158 
159  if (gtdp->gtd_flag == _GED_LISTPATH) {
160  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "/%s:\n", dp->d_namep);
161  return;
162  }
163 
164  /* NOTE - only reach here if gtd_flag == _GED_LISTEVAL */
166  if ((id=rt_db_get_internal(&intern, dp, gtdp->gtd_gedp->ged_wdbp->dbip, gtdp->gtd_xform, &rt_uniresource)) < 0) {
167  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "rt_db_get_internal(%s) failure", dp->d_namep);
168  return;
169  }
170  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "%s:\n", dp->d_namep);
171  if (!OBJ[id].ft_describe ||
172  OBJ[id].ft_describe(gtdp->gtd_gedp->ged_result_str,
173  &intern,
174  verbose,
177  gtdp->gtd_gedp->ged_wdbp->dbip) < 0)
178  bu_vls_printf(gtdp->gtd_gedp->ged_result_str, "%s: describe error\n", dp->d_namep);
179  rt_db_free_internal(&intern);
180 }
181 
182 
183 /*
184  * Local Variables:
185  * tab-width: 8
186  * mode: C
187  * indent-tabs-mode: t
188  * c-file-style: "stroustrup"
189  * End:
190  * ex: shiftwidth=4 tabstop=8
191  */
char * d_namep
pointer to name string
Definition: raytrace.h:859
Definition: raytrace.h:800
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
struct db_i * dbip
Definition: raytrace.h:1266
#define _GED_MAX_LEVELS
Definition: ged.h:1912
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
Definition: db_lookup.c:153
struct rt_wdb * ged_wdbp
Definition: ged.h:340
struct directory * gtd_path[_GED_MAX_LEVELS]
Definition: ged.h:1915
if(share_geom)
Definition: nmg_mod.c:3829
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define _GED_CPEVAL
Definition: ged_private.h:52
#define _GED_EVAL_ONLY
Definition: ged_private.h:55
matp_t tl_mat
xform matp, NULL ==> identity
Definition: raytrace.h:1173
char * tl_name
Name of this leaf (bu_strdup'ed)
Definition: raytrace.h:1174
#define UNUSED(parameter)
Definition: common.h:239
void bn_mat_mul(mat_t o, const mat_t a, const mat_t b)
struct ged * gtd_gedp
Definition: ged.h:1914
struct bu_vls * ged_result_str
Definition: ged.h:357
double dbi_base2local
unit conversion factors
Definition: raytrace.h:808
#define RT_CK_DBI(_p)
Definition: raytrace.h:829
struct tree::tree_db_leaf tr_l
void * idb_ptr
Definition: raytrace.h:195
mat_t gtd_xform
Definition: ged.h:1917
#define RT_DIR_COMB
combination
Definition: raytrace.h:884
const struct rt_functab OBJ[]
Definition: table.c:159
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 RT_DIR_NULL
Definition: raytrace.h:875
#define LOOKUP_NOISY
Definition: raytrace.h:892
void db_tree_funcleaf(struct db_i *dbip, struct rt_comb_internal *comb, union tree *comb_tree, void(*leaf_func)(struct db_i *, struct rt_comb_internal *, union tree *, void *, void *, void *, void *), void *user_ptr1, void *user_ptr2, void *user_ptr3, void *user_ptr4)
Definition: db_tree.c:640
#define RT_CK_TREE(_p)
Definition: raytrace.h:1182
#define _GED_LISTPATH
Definition: ged_private.h:53
int gtd_flag
Definition: ged.h:1920
HIDDEN void verbose(struct human_data_t *dude)
Definition: human.c:2008
int d_flags
flags
Definition: raytrace.h:869
int gtd_prflag
Definition: ged.h:1919
double fastf_t
Definition: defines.h:300
struct directory * gtd_obj[_GED_MAX_LEVELS]
Definition: ged.h:1916
void rt_db_free_internal(struct rt_db_internal *ip)
Definition: dir.c:216
void ged_trace(struct directory *dp, int pathpos, const mat_t old_xlate, struct _ged_trace_data *gtdp, int verbose)
Definition: trace.c:82
int gtd_objpos
Definition: ged.h:1918