37
37
#include "pc.h"
38
38
#include "raytrace.h"
39
39
40
+ const char *
41
+ get_all_avs_keys (const struct bu_attribute_value_set * avsp , const char * title )
42
+ {
43
+ BU_CK_AVS (avsp );
44
+
45
+ struct bu_attribute_value_pair * avpp ;
46
+ size_t i ;
47
+ struct bu_vls str = BU_VLS_INIT_ZERO ;
48
+
49
+ if (title )
50
+ {
51
+ bu_vls_strcat (& str , title );
52
+ bu_vls_strcat (& str , "=\"" );
53
+ }
54
+
55
+ avpp = avsp -> avp ;
56
+ for (i = 0 ; i < avsp -> count ; i ++ , avpp ++ )
57
+ {
58
+ bu_vls_strcat (& str , " " );
59
+ bu_vls_strcat (& str , avpp -> name ? avpp -> name : "NULL" );
60
+ bu_vls_strcat (& str , ":" );
61
+ bu_vls_strcat (& str , avpp -> value ? avpp -> value : "NULL" );
62
+ bu_vls_strcat (& str , "\n" );
63
+ }
64
+
65
+ if (title )
66
+ {
67
+ bu_vls_strcat (& str , "\"" );
68
+ }
69
+
70
+ const char * attributes = bu_vls_strgrab (& str );
71
+
72
+ return attributes ;
73
+ }
40
74
41
75
/**
42
76
* Free the storage associated with the rt_db_internal version of
43
77
* material object.
44
78
*/
45
- void
46
- rt_material_ifree (struct rt_db_internal * ip )
79
+ void rt_material_ifree (struct rt_db_internal * ip )
47
80
{
48
81
register struct rt_material_internal * material ;
49
82
50
83
RT_CK_DB_INTERNAL (ip );
51
84
material = (struct rt_material_internal * )ip -> idb_ptr ;
52
85
53
- if (material ) {
54
- material -> magic = 0 ; /* sanity */
55
- bu_vls_free (& material -> name );
56
- bu_vls_free (& material -> parent );
57
- bu_vls_free (& material -> source );
58
-
59
- bu_avs_free (& material -> physicalProperties );
60
- bu_avs_free (& material -> mechanicalProperties );
61
- bu_avs_free (& material -> opticalProperties );
62
- bu_avs_free (& material -> thermalProperties );
63
- bu_free ((void * )material , "material ifree" );
86
+ if (material )
87
+ {
88
+ material -> magic = 0 ; /* sanity */
89
+ bu_vls_free (& material -> name );
90
+ bu_vls_free (& material -> parent );
91
+ bu_vls_free (& material -> source );
92
+
93
+ bu_avs_free (& material -> physicalProperties );
94
+ bu_avs_free (& material -> mechanicalProperties );
95
+ bu_avs_free (& material -> opticalProperties );
96
+ bu_avs_free (& material -> thermalProperties );
97
+ bu_free ((void * )material , "material ifree" );
64
98
}
65
- ip -> idb_ptr = ((void * )0 ); /* sanity */
99
+ ip -> idb_ptr = ((void * )0 ); /* sanity */
66
100
}
67
101
68
-
69
102
/**
70
103
* Import a material from the database format to the internal format.
71
104
*/
72
- int
73
- rt_material_import5 (struct rt_db_internal * ip , const struct bu_external * ep , const fastf_t * UNUSED (mat ), const struct db_i * UNUSED (dbip ))
105
+ int rt_material_import5 (struct rt_db_internal * ip , const struct bu_external * ep , const fastf_t * UNUSED (mat ), const struct db_i * UNUSED (dbip ))
74
106
{
75
107
struct rt_material_internal * material_ip ;
76
108
@@ -122,9 +154,12 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
122
154
123
155
physical_ep .ext_nbytes = size ;
124
156
physical_ep .ext_buf = cp ;
125
- if (size > 0 ) {
157
+ if (size > 0 )
158
+ {
126
159
db5_import_attributes (& material_ip -> physicalProperties , & physical_ep );
127
- } else {
160
+ }
161
+ else
162
+ {
128
163
bu_avs_init_empty (& material_ip -> physicalProperties );
129
164
}
130
165
cp += size ;
@@ -135,9 +170,12 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
135
170
136
171
mechanical_ep .ext_nbytes = size ;
137
172
mechanical_ep .ext_buf = cp ;
138
- if (size > 0 ) {
173
+ if (size > 0 )
174
+ {
139
175
db5_import_attributes (& material_ip -> mechanicalProperties , & mechanical_ep );
140
- } else {
176
+ }
177
+ else
178
+ {
141
179
bu_avs_init_empty (& material_ip -> mechanicalProperties );
142
180
}
143
181
cp += size ;
@@ -148,9 +186,12 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
148
186
149
187
optical_ep .ext_nbytes = size ;
150
188
optical_ep .ext_buf = cp ;
151
- if (size > 0 ) {
189
+ if (size > 0 )
190
+ {
152
191
db5_import_attributes (& material_ip -> opticalProperties , & optical_ep );
153
- } else {
192
+ }
193
+ else
194
+ {
154
195
bu_avs_init_empty (& material_ip -> opticalProperties );
155
196
}
156
197
cp += size ;
@@ -161,27 +202,29 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
161
202
162
203
thermal_ep .ext_nbytes = size ;
163
204
thermal_ep .ext_buf = cp ;
164
- if (size > 0 ) {
205
+ if (size > 0 )
206
+ {
165
207
db5_import_attributes (& material_ip -> thermalProperties , & thermal_ep );
166
- } else {
208
+ }
209
+ else
210
+ {
167
211
bu_avs_init_empty (& material_ip -> thermalProperties );
168
212
}
169
213
cp += size ;
170
214
171
- return 0 ; /* OK */
215
+ return 0 ; /* OK */
172
216
}
173
217
174
-
175
218
/**
176
219
* Export a material from the internal format to the database format.
177
220
*/
178
- int
179
- rt_material_export5 (struct bu_external * ep , const struct rt_db_internal * ip , double UNUSED (local2mm ), const struct db_i * UNUSED (dbip ))
221
+ int rt_material_export5 (struct bu_external * ep , const struct rt_db_internal * ip , double UNUSED (local2mm ), const struct db_i * UNUSED (dbip ))
180
222
{
181
223
struct rt_material_internal * material_ip ;
182
224
RT_CK_DB_INTERNAL (ip );
183
225
184
- if (ip -> idb_type != ID_MATERIAL ) bu_bomb ("rt_material_export() type not ID_MATERIAL" );
226
+ if (ip -> idb_type != ID_MATERIAL )
227
+ bu_bomb ("rt_material_export() type not ID_MATERIAL" );
185
228
material_ip = (struct rt_material_internal * )ip -> idb_ptr ;
186
229
187
230
struct bu_vls name = BU_VLS_INIT_ZERO ;
@@ -201,14 +244,7 @@ rt_material_export5(struct bu_external *ep, const struct rt_db_internal *ip, dou
201
244
db5_export_attributes (& thermal_ep , & material_ip -> thermalProperties );
202
245
203
246
// initialize entire buffer
204
- ep -> ext_nbytes = bu_vls_strlen (& material_ip -> name ) + 1
205
- + bu_vls_strlen (& material_ip -> parent ) + 1
206
- + bu_vls_strlen (& material_ip -> source ) + 1
207
- + (4 * SIZEOF_NETWORK_LONG )
208
- + physical_ep .ext_nbytes
209
- + mechanical_ep .ext_nbytes
210
- + optical_ep .ext_nbytes
211
- + thermal_ep .ext_nbytes ;
247
+ ep -> ext_nbytes = bu_vls_strlen (& material_ip -> name ) + 1 + bu_vls_strlen (& material_ip -> parent ) + 1 + bu_vls_strlen (& material_ip -> source ) + 1 + (4 * SIZEOF_NETWORK_LONG ) + physical_ep .ext_nbytes + mechanical_ep .ext_nbytes + optical_ep .ext_nbytes + thermal_ep .ext_nbytes ;
212
248
ep -> ext_buf = (uint8_t * )bu_calloc (1 , ep -> ext_nbytes , "material external" );
213
249
unsigned char * cp = ep -> ext_buf ;
214
250
@@ -234,40 +270,39 @@ rt_material_export5(struct bu_external *ep, const struct rt_db_internal *ip, dou
234
270
* (uint32_t * )cp = htonl (physical_ep .ext_nbytes );
235
271
cp += SIZEOF_NETWORK_LONG ;
236
272
memcpy (cp , physical_ep .ext_buf , physical_ep .ext_nbytes );
237
- cp += physical_ep .ext_nbytes ;
273
+ cp += physical_ep .ext_nbytes ;
238
274
bu_free_external (& physical_ep );
239
275
240
276
// copy mechanical properties
241
277
* (uint32_t * )cp = htonl (mechanical_ep .ext_nbytes );
242
278
cp += SIZEOF_NETWORK_LONG ;
243
279
memcpy (cp , mechanical_ep .ext_buf , mechanical_ep .ext_nbytes );
244
- cp += mechanical_ep .ext_nbytes ;
280
+ cp += mechanical_ep .ext_nbytes ;
245
281
bu_free_external (& mechanical_ep );
246
282
247
283
// copy optical properties
248
284
* (uint32_t * )cp = htonl (optical_ep .ext_nbytes );
249
285
cp += SIZEOF_NETWORK_LONG ;
250
286
memcpy (cp , optical_ep .ext_buf , optical_ep .ext_nbytes );
251
- cp += optical_ep .ext_nbytes ;
287
+ cp += optical_ep .ext_nbytes ;
252
288
bu_free_external (& optical_ep );
253
289
254
290
// copy thermal properties
255
291
* (uint32_t * )cp = htonl (thermal_ep .ext_nbytes );
256
292
cp += SIZEOF_NETWORK_LONG ;
257
293
memcpy (cp , thermal_ep .ext_buf , thermal_ep .ext_nbytes );
258
- cp += thermal_ep .ext_nbytes ;
294
+ cp += thermal_ep .ext_nbytes ;
259
295
bu_free_external (& thermal_ep );
260
296
261
- return 0 ; /* OK */
297
+ return 0 ; /* OK */
262
298
}
263
299
264
300
/**
265
301
* Make human-readable formatted presentation of this object. First
266
302
* line describes type of object. Additional lines are indented one
267
303
* tab, and give parameter values.
268
304
*/
269
- int
270
- rt_material_describe (struct bu_vls * str , const struct rt_db_internal * ip , int verbose , double UNUSED (mm2local ))
305
+ int rt_material_describe (struct bu_vls * str , const struct rt_db_internal * ip , int verbose , double UNUSED (mm2local ))
271
306
{
272
307
register struct rt_material_internal * material_ip = (struct rt_material_internal * )ip -> idb_ptr ;
273
308
@@ -276,33 +311,33 @@ rt_material_describe(struct bu_vls *str, const struct rt_db_internal *ip, int ve
276
311
struct bu_vls buf = BU_VLS_INIT_ZERO ;
277
312
bu_vls_strcat (str , "material (MATERIAL)\n" );
278
313
279
- bu_vls_printf (& buf , "\tName : %s\n" , material_ip -> name .vls_str );
280
- bu_vls_printf (& buf , "\tParent : %s\n" , material_ip -> parent .vls_str );
281
- bu_vls_printf (& buf , "\tSource : %s\n" , material_ip -> source .vls_str );
314
+ bu_vls_printf (& buf , " name : %s\n" , material_ip -> name .vls_str );
315
+ bu_vls_printf (& buf , " parent : %s\n" , material_ip -> parent .vls_str );
316
+ bu_vls_printf (& buf , " source : %s\n" , material_ip -> source .vls_str );
282
317
283
- if (!verbose ) {
318
+ if (!verbose )
319
+ {
284
320
bu_vls_vlscat (str , & buf );
285
321
bu_vls_free (& buf );
286
322
return 0 ;
287
323
}
288
324
289
- const char * physicalProperties = bu_avs_get_all (& material_ip -> physicalProperties , NULL );
290
- const char * mechanicalProperties = bu_avs_get_all (& material_ip -> mechanicalProperties , NULL );
291
- const char * opticalProperties = bu_avs_get_all (& material_ip -> opticalProperties , NULL );
292
- const char * thermalProperties = bu_avs_get_all (& material_ip -> thermalProperties , NULL );
325
+ const char * physicalProperties = get_all_avs_keys (& material_ip -> physicalProperties , NULL );
326
+ const char * mechanicalProperties = get_all_avs_keys (& material_ip -> mechanicalProperties , NULL );
327
+ const char * opticalProperties = get_all_avs_keys (& material_ip -> opticalProperties , NULL );
328
+ const char * thermalProperties = get_all_avs_keys (& material_ip -> thermalProperties , NULL );
293
329
294
- bu_vls_printf (& buf , "\tphysicalProperties: \n%s" , physicalProperties );
295
- bu_vls_printf (& buf , "\tmechanicalProperties: \n%s" , mechanicalProperties );
296
- bu_vls_printf (& buf , "\topticalProperties: \n%s" , opticalProperties );
297
- bu_vls_printf (& buf , "\tthermalProperties: \n%s" , thermalProperties );
330
+ bu_vls_printf (& buf , " physical properties \n%s" , physicalProperties );
331
+ bu_vls_printf (& buf , " mechanical properties \n%s" , mechanicalProperties );
332
+ bu_vls_printf (& buf , " optical properties \n%s" , opticalProperties );
333
+ bu_vls_printf (& buf , " thermal properties \n%s" , thermalProperties );
298
334
299
335
bu_vls_vlscat (str , & buf );
300
336
bu_vls_free (& buf );
301
337
302
338
return 0 ;
303
339
}
304
340
305
-
306
341
/** @} */
307
342
/*
308
343
* Local Variables:
0 commit comments