BRL-CAD
brlcad.c
Go to the documentation of this file.
1 /* B R L C A D . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2015 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 brlcad.c
21  *
22  * BRL-CAD .g database plugin for libgcv.
23  *
24  */
25 
26 
27 #include "common.h"
28 
29 #include "../plugin.h"
30 
31 
32 HIDDEN int
33 gcv_brlcad_read(const char *path, struct rt_wdb *wdbp,
34  const struct gcv_opts *UNUSED(options))
35 {
36  int ret;
37  struct db_i *dbip = db_open(path, DB_OPEN_READONLY);
38 
39  if (!dbip) {
40  bu_log("db_open() failed for '%s'\n", path);
41  return 0;
42  }
43 
44  if (db_dirbuild(dbip)) {
45  bu_log("db_dirbuild() failed for '%s'\n", path);
46  db_close(dbip);
47  return 0;
48  }
49 
50  ret = db_dump(wdbp, dbip);
51  db_close(dbip);
52 
53  return ret == 0;
54 }
55 
56 
57 HIDDEN int
58 gcv_brlcad_write(const char *path, struct db_i *dbip,
59  const struct gcv_opts *UNUSED(options))
60 {
61  int ret;
62  struct rt_wdb *wdbp = wdb_fopen(path);
63 
64  if (!wdbp) {
65  bu_log("wdb_fopen() failed for '%s'\n", path);
66  return 0;
67  }
68 
69  ret = db_dump(wdbp, dbip);
70  wdb_close(wdbp);
71 
72  return ret == 0;
73 }
74 
75 
76 static const struct gcv_converter converters[] = {
78  {NULL, NULL, NULL}
79 };
80 
81 const struct gcv_plugin_info gcv_plugin_conv_brlcad = {converters};
82 
83 
84 /*
85  * Local Variables:
86  * tab-width: 8
87  * mode: C
88  * indent-tabs-mode: t
89  * c-file-style: "stroustrup"
90  * End:
91  * ex: shiftwidth=4 tabstop=8
92  */
Definition: raytrace.h:800
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
const struct gcv_plugin_info gcv_plugin_conv_brlcad
Definition: brlcad.c:81
Header file for the BRL-CAD common definitions.
Definition: gcv.c:8
#define HIDDEN
Definition: common.h:86
int db_dump(struct rt_wdb *wdbp, struct db_i *dbip)
Definition: db_open.c:384
char * options
Definition: gqa.c:56
void db_close(struct db_i *dbip)
#define UNUSED(parameter)
Definition: common.h:239
void wdb_close(struct rt_wdb *wdbp)
Definition: wdb.c:333
HIDDEN int gcv_brlcad_write(const char *path, struct db_i *dbip, const struct gcv_opts *options)
Definition: brlcad.c:58
#define DB_OPEN_READONLY
Definition: raytrace.h:3550
struct db_i * db_open(const char *name, const char *mode)
Definition: db_open.c:59
HIDDEN int gcv_brlcad_read(const char *path, struct rt_wdb *wdbp, const struct gcv_opts *options)
Definition: brlcad.c:33
int db_dirbuild(struct db_i *dbip)
Definition: db5_scan.c:301
struct rt_wdb * wdb_fopen(const char *filename)
Definition: wdb.c:56