BRL-CAD
constraint.c
Go to the documentation of this file.
1 /* C O N S T R A I N T . 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 /** @addtogroup librt */
21 /** @{ */
22 /** @file librt/constraint.c
23  *
24  * Various functions associated with constraint object database I/O
25  *
26  * Todo: Remove * resp from the param list ?? by modification of
27  * table.c and rt_functab struct ?
28  *
29  */
30 
31 #include "common.h"
32 
33 #include <stdio.h>
34 
35 
36 #include "bn.h"
37 #include "db.h"
38 #include "pc.h"
39 #include "raytrace.h"
40 
41 
42 static const struct bu_structparse rt_constraint_parse[] = {
43  {"%d", 1, "ID", bu_offsetof(struct rt_constraint_internal, id), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL},
44  {"%d", 1, "N", bu_offsetof(struct rt_constraint_internal, type), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL},
45  {"%V", 1, "Ex", bu_offsetof(struct rt_constraint_internal, expression), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL},
46  {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
47 };
48 
49 
50 /**
51  * Free the storage associated with the rt_db_internal version of
52  * constraint object.
53  */
54 void
56 {
57  register struct rt_constraint_internal *constraint;
58 
60  constraint = (struct rt_constraint_internal *)ip->idb_ptr;
61 
62  if (constraint) {
63  constraint->magic = 0; /* sanity */
64  bu_vls_free(&constraint->expression);
65  bu_free((void *)constraint, "constraint ifree");
66  }
67  ip->idb_ptr = ((void *)0); /* sanity */
68 }
69 
70 
71 int
73  struct bu_external *ep,
74  const struct rt_db_internal *ip,
75  double UNUSED(local2mm),
76  const struct db_i *dbip,
77  struct resource *resp)
78 {
79  struct rt_constraint_internal *cip;
80  struct bu_vls str = BU_VLS_INIT_ZERO;
81 
83  if (dbip) RT_CK_DBI(dbip);
84  if (resp) RT_CK_RESOURCE(resp);
85 
86  if (ip->idb_type != ID_CONSTRAINT) bu_bomb("rt_constraint_export() type not ID_CONSTRAINT");
87  cip = (struct rt_constraint_internal *) ip->idb_ptr;
88 
89  BU_EXTERNAL_INIT(ep);
90 
91  bu_vls_struct_print(&str, rt_constraint_parse, (char *)cip);
92 
93  ep->ext_nbytes = bu_vls_strlen(&str);
94  ep->ext_buf = (uint8_t *)bu_calloc(1, ep->ext_nbytes, "constrnt external");
95  bu_strlcpy((char *)ep->ext_buf, bu_vls_addr(&str), ep->ext_nbytes);
96 
97  bu_vls_free(&str);
98 
99  return 0; /* OK */
100 }
101 
102 
103 int
104 rt_constraint_import5(struct rt_db_internal *ip, const struct bu_external *ep, const mat_t UNUSED(mat), const struct db_i *dbip, struct resource *resp)
105 {
106  RT_CK_DB_INTERNAL(ip);
107  BU_CK_EXTERNAL(ep);
108  RT_CK_DBI(dbip);
109  if (resp) RT_CK_RESOURCE(resp);
110 
111  return 0; /* OK */
112 }
113 
114 
115 /** @} */
116 /*
117  * Local Variables:
118  * mode: C
119  * tab-width: 8
120  * indent-tabs-mode: t
121  * c-file-style: "stroustrup"
122  * End:
123  * ex: shiftwidth=4 tabstop=8
124  */
Definition: raytrace.h:800
int rt_constraint_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip, struct resource *resp)
Definition: constraint.c:72
Header file for the BRL-CAD common definitions.
if(share_geom)
Definition: nmg_mod.c:3829
struct bu_vls expression
Definition: raytrace.h:1026
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
#define ID_CONSTRAINT
Constraint object.
Definition: raytrace.h:503
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
void rt_constraint_ifree(struct rt_db_internal *ip)
Definition: constraint.c:55
#define bu_strlcpy(dst, src, size)
Definition: str.h:60
uint8_t * ext_buf
Definition: parse.h:216
size_t bu_vls_strlen(const struct bu_vls *vp)
Definition: vls.c:189
#define UNUSED(parameter)
Definition: common.h:239
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
void bu_vls_struct_print(struct bu_vls *vls, const struct bu_structparse *sdp, const char *base)
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
#define bu_offsetof(_t, _m)
Definition: parse.h:64
#define RT_CK_DBI(_p)
Definition: raytrace.h:829
int rt_constraint_import5(struct rt_db_internal *ip, const struct bu_external *ep, const mat_t mat, const struct db_i *dbip, struct resource *resp)
Definition: constraint.c:104
void * idb_ptr
Definition: raytrace.h:195
#define RT_CK_RESOURCE(_p)
Definition: raytrace.h:1490
#define BU_EXTERNAL_INIT(_p)
Definition: parse.h:229
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define BU_CK_EXTERNAL(_p)
Definition: parse.h:224
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
size_t ext_nbytes
Definition: parse.h:210
Definition: vls.h:56
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91