BRL-CAD
wdb.h
Go to the documentation of this file.
1/* W D B . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2023 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 rt/wdb.h
21 *
22 */
23
24#ifndef RT_WDB_H
25#define RT_WDB_H
26
27#include "common.h"
28
29#include "vmath.h"
30#include "bu/magic.h"
31#include "bu/list.h"
32#include "bu/vls.h"
33#include "bu/observer.h"
34#include "rt/db_instance.h"
35#include "rt/tree.h"
36
37__BEGIN_DECLS
38
39struct resource; /* forward declaration */
40
41/* struct rt_wdb database types (for wdb_type struct entry).
42 * The "default" types will return the wdbp associated with
43 * the dbip - i.e., if the dbip is an inmem it will return
44 * the INMEM types, and if associated with a file it will
45 * return the DISK types. This is for calling code that
46 * just needs a wdbp and isn't concerned with the details
47 * of how objects are being written. */
48#define RT_WDB_TYPE_DB_DEFAULT 0
49#define RT_WDB_TYPE_DB_DEFAULT_APPEND_ONLY 1
50#define RT_WDB_TYPE_DB_DISK 2
51#define RT_WDB_TYPE_DB_DISK_APPEND_ONLY 3
52#define RT_WDB_TYPE_DB_INMEM 4
53#define RT_WDB_TYPE_DB_INMEM_APPEND_ONLY 5
54
55
56/**
57 * This data structure is at the core of the "LIBWDB" support for
58 * allowing application programs to read and write BRL-CAD databases.
59 * Many different access styles are supported.
60 */
61
62struct rt_wdb {
63 struct bu_list l;
64 int type; /** < @brief .g database type (RT_WDB_TYPE - disk or inmem, append-only) */
65 struct db_i * dbip;
67
71
72 /* variables for name prefixing */
76
77 /* default region ident codes for this particular database. */
78 int wdb_item_default;/**< @brief GIFT region ID */
80 int wdb_mat_default;/**< @brief GIFT material code */
81 int wdb_los_default;/**< @brief Line-of-sight estimate */
82
83 /* These members are marked for removal */
84 struct bu_vls wdb_name; /**< @brief database object name */
86 void * wdb_interp; /**< @brief Tcl_Interp */
87};
88
89#define RT_CHECK_WDB(_p) BU_CKMAG(_p, RT_WDB_MAGIC, "rt_wdb")
90#define RT_CK_WDB(_p) RT_CHECK_WDB(_p)
91#define RT_WDB_INIT_ZERO { {RT_WDB_MAGIC, BU_LIST_NULL, BU_LIST_NULL}, 0, NULL, RT_DBTS_INIT_ZERO, BG_TESS_TOL_INIT_ZERO, BN_TOL_INIT_ZERO, NULL, BU_VLS_INIT_ZERO, 0, 0, 0, 0, 0, 0, BU_VLS_INIT_ZERO, BU_OBSERVER_LIST_INIT_ZERO, NULL }
92#define RT_WDB_NULL ((struct rt_wdb *)NULL)
93
94/**
95 *
96 * Routines to allow libwdb to use librt's import/export interface,
97 * rather than having to know about the database formats directly.
98 *
99 */
100RT_EXPORT extern struct rt_wdb *wdb_fopen(const char *filename);
101
102
103/**
104 * Create a libwdb output stream destined for a disk file. This will
105 * destroy any existing file by this name, and start fresh. The file
106 * is then opened in the normal "update" mode and an in-memory
107 * directory is built along the way, allowing retrievals and object
108 * replacements as needed.
109 *
110 * The rt_wdb type returned is RT_WDB_TYPE_DB_DISK.
111 *
112 * Users can change the database title by calling: ???
113 */
114RT_EXPORT extern struct rt_wdb *wdb_fopen_v(const char *filename,
115 int version);
116
117
118/**
119 * Create a libwdb output stream destined for an existing BRL-CAD database,
120 * already opened via a db_open() call.
121 *
122 * Note: there can be only one rt_wdb container of each type per dbip - if an
123 * rt_wdb of the specified type is already associated with the database, the
124 * pre-existing stream will be returned.
125 *
126 * RT_WDB_TYPE_DB_DISK Add to on-disk database
127 * RT_WDB_TYPE_DB_DISK_APPEND_ONLY Add to on-disk database, don't clobber existing names, use prefix
128 * RT_WDB_TYPE_DB_INMEM Add to in-memory database only
129 * RT_WDB_TYPE_DB_INMEM_APPEND_ONLY Ditto, but give errors if name in use.
130 */
131RT_EXPORT extern struct rt_wdb *wdb_dbopen(struct db_i *dbip,
132 int mode);
133
134
135/**
136 * Returns -
137 * 0 and modified *internp;
138 * -1 ft_import failure (from rt_db_get_internal)
139 * -2 db_get_external failure (from rt_db_get_internal)
140 * -3 Attempt to import from write-only (stream) file.
141 * -4 Name not found in database TOC.
142 *
143 * NON-PARALLEL because of rt_uniresource
144 */
145RT_EXPORT extern int wdb_import(struct rt_wdb *wdbp,
146 struct rt_db_internal *internp,
147 const char *name,
148 const mat_t mat);
149
150
151/**
152 * The caller must free "ep".
153 *
154 * Returns -
155 * 0 OK
156 * <0 error
157 */
158RT_EXPORT extern int wdb_export_external(struct rt_wdb *wdbp,
159 struct bu_external *ep,
160 const char *name,
161 int flags,
162 unsigned char minor_type);
163
164/**
165 * Convert the internal representation of a solid to the external one,
166 * and write it into the database.
167 *
168 * The internal representation is always freed. This is the analog of
169 * rt_db_put_internal() for rt_wdb objects.
170 *
171 * Use this routine in preference to wdb_export() whenever the caller
172 * already has an rt_db_internal structure handy.
173 *
174 * NON-PARALLEL because of rt_uniresource
175 *
176 * Returns -
177 * 0 OK
178 * <0 error
179 */
180RT_EXPORT extern int wdb_put_internal(struct rt_wdb *wdbp,
181 const char *name,
182 struct rt_db_internal *ip,
183 double local2mm);
184
185
186/**
187 * Export an in-memory representation of an object, as described in
188 * the file h/rtgeom.h, into the indicated database.
189 *
190 * The internal representation (gp) is always freed.
191 *
192 * WARNING: The caller must be careful not to double-free gp,
193 * particularly if it's been extracted from an rt_db_internal, e.g. by
194 * passing intern.idb_ptr for gp.
195 *
196 * If the caller has an rt_db_internal structure handy already, they
197 * should call wdb_put_internal() directly -- this is a convenience
198 * routine intended primarily for internal use in LIBWDB.
199 *
200 * Returns -
201 * 0 OK
202 * <0 error
203 */
204RT_EXPORT extern int wdb_export(struct rt_wdb *wdbp,
205 const char *name,
206 void *gp,
207 int id,
208 double local2mm);
209RT_EXPORT extern void wdb_init(struct rt_wdb *wdbp,
210 struct db_i *dbip,
211 int mode);
212
213
214/**
215 * Close a database created with wdb_fopen or wdb_fopen_v.
216 */
217RT_EXPORT extern void wdb_close(struct rt_wdb *wdbp);
218
219/**
220 * Given the name of a database object or a full path to a leaf
221 * object, obtain the internal form of that leaf. Packaged separately
222 * mainly to make available nice Tcl error handling.
223 *
224 * Returns -
225 * BRLCAD_OK
226 * BRLCAD_ERROR
227 */
228RT_EXPORT extern int wdb_import_from_path(struct bu_vls *logstr,
229 struct rt_db_internal *ip,
230 const char *path,
231 struct rt_wdb *wdb);
232
233
234/**
235 * Given the name of a database object or a full path to a leaf
236 * object, obtain the internal form of that leaf. Packaged separately
237 * mainly to make available nice Tcl error handling. Additionally,
238 * copies ts.ts_mat to matp.
239 *
240 * Returns -
241 * BRLCAD_OK
242 * BRLCAD_ERROR
243 */
244RT_EXPORT extern int wdb_import_from_path2(struct bu_vls *logstr,
245 struct rt_db_internal *ip,
246 const char *path,
247 struct rt_wdb *wdb,
248 matp_t matp);
249
250
251__END_DECLS
252
253#endif /* RT_WDB_H */
254
255/*
256 * Local Variables:
257 * tab-width: 8
258 * mode: C
259 * indent-tabs-mode: t
260 * c-file-style: "stroustrup"
261 * End:
262 * ex: shiftwidth=4 tabstop=8
263 */
Header file for the BRL-CAD common definitions.
void int char * mode
Definition: tig.h:179
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition: vmath.h:366
fastf_t * matp_t
pointer to a 4x4 matrix
Definition: vmath.h:369
Global registry of recognized magic numbers.
struct rt_wdb * wdb_fopen_v(const char *filename, int version)
void wdb_init(struct rt_wdb *wdbp, struct db_i *dbip, int mode)
struct rt_wdb * wdb_fopen(const char *filename)
int wdb_import_from_path2(struct bu_vls *logstr, struct rt_db_internal *ip, const char *path, struct rt_wdb *wdb, matp_t matp)
void wdb_close(struct rt_wdb *wdbp)
struct rt_wdb * wdb_dbopen(struct db_i *dbip, int mode)
int wdb_export(struct rt_wdb *wdbp, const char *name, void *gp, int id, double local2mm)
int wdb_import(struct rt_wdb *wdbp, struct rt_db_internal *internp, const char *name, const mat_t mat)
int wdb_import_from_path(struct bu_vls *logstr, struct rt_db_internal *ip, const char *path, struct rt_wdb *wdb)
int wdb_export_external(struct rt_wdb *wdbp, struct bu_external *ep, const char *name, int flags, unsigned char minor_type)
int wdb_put_internal(struct rt_wdb *wdbp, const char *name, struct rt_db_internal *ip, double local2mm)
Definition: tol.h:72
Definition: list.h:131
Definition: vls.h:53
Definition: wdb.h:62
int wdb_mat_default
GIFT material code.
Definition: wdb.h:80
struct bu_vls wdb_name
database object name
Definition: wdb.h:84
struct resource * wdb_resp
Definition: wdb.h:70
int wdb_item_default
GIFT region ID.
Definition: wdb.h:78
struct bu_vls wdb_prestr
Definition: wdb.h:73
void * wdb_interp
Tcl_Interp.
Definition: wdb.h:86
int wdb_los_default
Line-of-sight estimate.
Definition: wdb.h:81
struct bn_tol wdb_tol
Definition: wdb.h:69
struct bu_observer_list wdb_observers
Definition: wdb.h:85
int wdb_num_dups
Definition: wdb.h:75
int wdb_air_default
Definition: wdb.h:79
struct db_i * dbip
.g database type (RT_WDB_TYPE - disk or inmem, append-only)
Definition: wdb.h:65
struct bu_list l
Definition: wdb.h:63
struct bg_tess_tol wdb_ttol
Definition: wdb.h:68
int type
Definition: wdb.h:64
int wdb_ncharadd
Definition: wdb.h:74
struct db_tree_state wdb_initial_tree_state
Definition: wdb.h:66
fundamental vector, matrix, quaternion math macros