BRL-CAD
Loading...
Searching...
No Matches
db_fullpath.h
Go to the documentation of this file.
1/* D B _ F U L L P A T H . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2014-2026 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
21#ifndef RT_DB_FULLPATH_H
22#define RT_DB_FULLPATH_H
23
24#include "common.h"
25
26#include "vmath.h"
27
28#include "bu/color.h"
29#include "bu/vls.h"
30#include "rt/defines.h"
31
33
34struct db_i; /* forward declaration */
35struct directory; /* forward declaration */
36
37/** @addtogroup db_fullpath
38 *
39 * @brief
40 * Structures and routines for collecting and manipulating paths through the database tree.
41 *
42 */
43/** @{ */
44/** @file rt/db_fullpath.h */
45
46/**
47 * The fp_bool array can optionally hold a boolean flag
48 * associated with each corresponding dp in fp_names. This
49 * array must be manually maintained by the client code in
50 * order for it to have valid data - many functions using
51 * full paths (for example, conversion from strings) don't
52 * have knowledge of a specific boolean tree.
53 */
56 size_t fp_len;
57 size_t fp_maxlen;
58 struct directory ** fp_names; /**< @brief array of dir pointers */
59 int * fp_bool; /**< @brief array of boolean flags */
60 int * fp_cinst; /**< @brief array of comb tree instance specifiers */
61};
62
63#define DB_FULL_PATH_INIT_ZERO {DB_FULL_PATH_MAGIC, 0, 0, NULL, NULL, NULL}
64
65#define RT_CK_FULL_PATH(_p) BU_CKMAG(_p, DB_FULL_PATH_MAGIC, "db_full_path")
66
67#define DB_FULL_PATH_CUR_DIR(_pp) (((_pp)->fp_len > 0) ? (_pp)->fp_names[(_pp)->fp_len-1] : NULL)
68#define DB_FULL_PATH_CUR_BOOL(_pp) ((_pp)->fp_bool[(_pp)->fp_len-1])
69#define DB_FULL_PATH_SET_CUR_BOOL(_pp, _i) ((_pp)->fp_bool[(_pp)->fp_len-1]) = _i
70
71#define DB_FULL_PATH_CUR_COMB_INST(_pp) ((_pp)->fp_cinst[(_pp)->fp_len-1])
72#define DB_FULL_PATH_SET_CUR_COMB_INST(_pp, _i) ((_pp)->fp_cinst[(_pp)->fp_len-1]) = _i
73
74#define DB_FULL_PATH_LEN(_pp) ((_pp)->fp_len)
75#define DB_FULL_PATH_POP(_pp) ((_pp)->fp_len > 0) ? (_pp)->fp_len-- : (_pp)->fp_len
76
77#define DB_FULL_PATH_GET(_pp, _i) ((_pp)->fp_names[(_i)])
78#define DB_FULL_PATH_GET_BOOL(_pp, _i) ((_pp)->fp_bool[(_i)])
79#define DB_FULL_PATH_SET_BOOL(_pp, _i, _j) ((_pp)->fp_bool[(_i)] = _j)
80#define DB_FULL_PATH_GET_COMB_INST(_pp, _i) ((_pp)->fp_cinst[(_i)])
81#define DB_FULL_PATH_SET_COMB_INST(_pp, _i, _j) ((_pp)->fp_cinst[(_i)] = _j)
82
83#define DB_FULL_PATH_ROOT_DIR(_pp) ((_pp)->fp_names[0])
84
85
86
87/* db_fullpath.c */
89
91 struct directory *dp);
92
94 const struct db_full_path *oldp);
95
96/**
97 * Extend "pathp" so that it can grow from current fp_len by incr more names.
98 *
99 * This is intended primarily as an internal method.
100 */
102 size_t incr);
103
105 const struct db_full_path *src);
106
107/**
108 * Dup old path from starting index to end.
109 */
111 const struct db_full_path *oldp,
112 b_off_t start);
113
114
115/**
116 * Unlike rt_path_str(), this version can be used in parallel.
117 * Caller is responsible for freeing the returned buffer.
118 */
119RT_EXPORT extern char *db_path_to_string(const struct db_full_path *pp);
120
121/**
122 * Append a string representation of the path onto the vls. Must have
123 * exactly the same formatting conventions as db_path_to_string().
124 */
125RT_EXPORT extern void db_path_to_vls(struct bu_vls *str,
126 const struct db_full_path *pp);
127
128/**
129 * Append a string representation of the path onto the vls, with
130 * options to decorate nodes with additional information.
131 */
132#define DB_FP_PRINT_BOOL 0x1 /* print boolean operations */
133#define DB_FP_PRINT_TYPE 0x2 /* print object types */
134#define DB_FP_PRINT_MATRIX 0x4 /* print notice that a matrix is present */
135#define DB_FP_PRINT_COMB_INDEX 0x8 /* print non-zero comb tree instance specifiers */
137 const struct db_full_path *full_path,
138 const struct db_i *dbip, /* needed for type determination */
139 int fp_flags);
140
141
142RT_EXPORT extern void db_pr_full_path(const char *msg,
143 const struct db_full_path *pathp);
144
145
146/**
147 * Reverse the effects of db_path_to_string().
148 *
149 * The db_full_path structure will be initialized. If it was already
150 * in use, user should call db_free_full_path() first.
151 *
152 * Returns -
153 * -1 One or more components of path did not exist in the directory.
154 * 0 OK
155 */
157 const struct db_i *dbip,
158 const char *str);
159
160
161/**
162 * Treat elements from argv[0] to argv[argc-1] as a path specification.
163 *
164 * The path structure will be fully initialized. If it was already in
165 * use, user should call db_free_full_path() first.
166 *
167 * Returns -
168 * -1 One or more components of path did not exist in the directory.
169 * 0 OK
170 */
172 struct db_i *dbip,
173 int argc,
174 const char *const*argv);
175
176
177/**
178 * Free the contents of the db_full_path structure, but not the
179 * structure itself, which might be automatic.
180 */
182
183
184/**
185 * Returns -
186 * 1 match
187 * 0 different
188 */
190 const struct db_full_path *b);
191
192
193/**
194 * Returns -
195 * 1 if 'b' is a proper subset of 'a'
196 * 0 if not.
197 */
198RT_EXPORT extern int db_full_path_subset(const struct db_full_path *a,
199 const struct db_full_path *b,
200 const int skip_first);
201
202/**
203 * Returns -
204 * 1 if 'a' matches the top part of 'b'
205 * 0 if not.
206 *
207 * For example, /a/b matches both the top part of /a/b/c and /a/b.
208 */
210 const struct db_full_path *b);
211
212
213/**
214 * Returns -
215 * 1 'dp' is found on this path
216 * 0 not found
217 */
218RT_EXPORT extern int db_full_path_search(const struct db_full_path *a,
219 const struct directory *dp);
220
221
222/**
223 * Function to test whether a path has a cyclic entry in it.
224 *
225 * @param fp [i] Full path to test
226 * @param lname [i] String to use when checking path (optional). If NULL, use the name of the current directory pointer in fp.
227 * @param full_check [i] Flag to instruct the cyclic test to check using all directory pointers in fp, not just the lname/current dp test.
228 * @return 1 if the path is cyclic, 0 if it is not.
229 *
230 * By default, only the leaf (or test_name if supplied) will be used to test if
231 * the path is cyclic. If full_check is set, all object names in the path will
232 * be checked, as well as lname if set. This more expensive check is not
233 * necessary if calling code is checking for cyclic paths as paths are being
234 * built, but is necessary to fully "clear" a db_full_path from an arbitrary
235 * source. Calling code must use its knowledge of the origins of the full path
236 * (or lack thereof) to determine how much validation work is needed.
237 */
238RT_EXPORT extern int db_full_path_cyclic(const struct db_full_path *fp, const char *lname, int full_check);
239
240/**
241 * Build the transformation matrix obtained when traversing the path
242 * to the specified depth.
243 *
244 * Returns -
245 * 1 OK, path matrix written into 'mat'.
246 * 0 FAIL
247 *
248 * Called in librt/db_tree.c, mged/dodraw.c, and mged/animedit.c
249 */
250RT_EXPORT extern int db_path_to_mat(struct db_i *dbip, struct db_full_path *pathp, mat_t mat, int depth); /* number of arcs */
251
252/**
253 * For a given path, return the "net" boolean operation of the
254 * path. If a subtraction is found along the path, overall path
255 * is regarded as a subtraction. Else, if an intersection is found
256 * op is reported as an intersection. Else, union is reported.
257 */
258RT_EXPORT extern int
259db_fp_op(const struct db_full_path *pathp, struct db_i *dbip, int depth); /* number of arcs - 0 == all */
260
261/**
262 * Determine the color operative at the current directory pointer (the leaf
263 * node) of the path according to available information and rules.
264 *
265 * If nothing can be determined default color is set.
266 */
267RT_EXPORT extern void db_full_path_color(struct bu_color *c, struct db_full_path *pathp, struct db_i *dbip);
268
269
270/** @} */
271
273
274#endif /*RT_DB_FULLPATH_H*/
275
276/*
277 * Local Variables:
278 * tab-width: 8
279 * mode: C
280 * indent-tabs-mode: t
281 * c-file-style: "stroustrup"
282 * End:
283 * ex: shiftwidth=4 tabstop=8
284 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
#define b_off_t
Definition common.h:255
int db_path_to_mat(struct db_i *dbip, struct db_full_path *pathp, mat_t mat, int depth)
void db_pr_full_path(const char *msg, const struct db_full_path *pathp)
void db_add_node_to_full_path(struct db_full_path *pp, struct directory *dp)
void db_extend_full_path(struct db_full_path *pathp, size_t incr)
int db_full_path_subset(const struct db_full_path *a, const struct db_full_path *b, const int skip_first)
int db_full_path_cyclic(const struct db_full_path *fp, const char *lname, int full_check)
void db_fullpath_to_vls(struct bu_vls *vls, const struct db_full_path *full_path, const struct db_i *dbip, int fp_flags)
void db_dup_full_path(struct db_full_path *newp, const struct db_full_path *oldp)
int db_fp_op(const struct db_full_path *pathp, struct db_i *dbip, int depth)
void db_dup_path_tail(struct db_full_path *newp, const struct db_full_path *oldp, b_off_t start)
int db_string_to_path(struct db_full_path *pp, const struct db_i *dbip, const char *str)
void db_path_to_vls(struct bu_vls *str, const struct db_full_path *pp)
int db_full_path_search(const struct db_full_path *a, const struct directory *dp)
int db_argv_to_path(struct db_full_path *pp, struct db_i *dbip, int argc, const char *const *argv)
void db_full_path_init(struct db_full_path *pathp)
char * db_path_to_string(const struct db_full_path *pp)
int db_identical_full_paths(const struct db_full_path *a, const struct db_full_path *b)
void db_full_path_color(struct bu_color *c, struct db_full_path *pathp, struct db_i *dbip)
void db_free_full_path(struct db_full_path *pp)
int db_full_path_match_top(const struct db_full_path *a, const struct db_full_path *b)
void db_append_full_path(struct db_full_path *dest, const struct db_full_path *src)
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:369
Definition vls.h:53
size_t fp_len
Definition db_fullpath.h:56
int * fp_cinst
array of comb tree instance specifiers
Definition db_fullpath.h:60
int * fp_bool
array of boolean flags
Definition db_fullpath.h:59
uint32_t magic
Definition db_fullpath.h:55
size_t fp_maxlen
Definition db_fullpath.h:57
struct directory ** fp_names
array of dir pointers
Definition db_fullpath.h:58
fundamental vector, matrix, quaternion math macros