Skip to content

Commit 9527359

Browse files
authored
Merge pull request #2 from treydinges/materials-hotfix
fixes for material branch code style/implementation
2 parents 8e422a8 + 3e220cc commit 9527359

File tree

4 files changed

+94
-97
lines changed

4 files changed

+94
-97
lines changed

include/bu/avs.h

-7
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,6 @@ BU_EXPORT extern void bu_avs_merge(struct bu_attribute_value_set *dest,
222222
BU_EXPORT extern const char *bu_avs_get(const struct bu_attribute_value_set *avp,
223223
const char *attribute);
224224

225-
/**
226-
* gets all attributes in an attribute set in "name = value" form,
227-
* using the provided title.
228-
*/
229-
BU_EXPORT extern const char *bu_avs_get_all(const struct bu_attribute_value_set *avp,
230-
const char *title);
231-
232225
/**
233226
* Remove all occurrences of an attribute from the provided attribute
234227
* set.

src/libbu/avs.c

-31
Original file line numberDiff line numberDiff line change
@@ -198,37 +198,6 @@ bu_avs_get(const struct bu_attribute_value_set *avsp, const char *name)
198198
return NULL;
199199
}
200200

201-
const char *
202-
bu_avs_get_all(const struct bu_attribute_value_set *avsp, const char *title) {
203-
BU_CK_AVS(avsp);
204-
205-
struct bu_attribute_value_pair *avpp;
206-
size_t i;
207-
struct bu_vls str = BU_VLS_INIT_ZERO;
208-
209-
if (title) {
210-
bu_vls_strcat(&str, title);
211-
bu_vls_strcat(&str, "=\"");
212-
}
213-
214-
avpp = avsp->avp;
215-
for (i = 0; i < avsp->count; i++, avpp++) {
216-
bu_vls_strcat(&str, "\t\t(");
217-
bu_vls_strcat(&str, avpp->name ? avpp->name : "NULL");
218-
bu_vls_strcat(&str, " : ");
219-
bu_vls_strcat(&str, avpp->value ? avpp->value : "NULL");
220-
bu_vls_strcat(&str, ")\n");
221-
}
222-
223-
if (title) {
224-
bu_vls_strcat(&str, "\"");
225-
}
226-
227-
const char * attributes = bu_vls_strgrab(&str);
228-
229-
return attributes;
230-
}
231-
232201

233202
int
234203
bu_avs_remove(struct bu_attribute_value_set *avsp, const char *name)

src/librt/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ set(LIBRT_SOURCES
4040
comb/comb_brep.cpp
4141
comb/comb_mirror.c
4242
comb/db_comb.c
43+
material/material.c
4344
constraint.c
44-
material.c
4545
cut.c
4646
cut_hlbvh.c
4747
db5_alloc.c

src/librt/material.c src/librt/material/material.c

+93-58
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,72 @@
3737
#include "pc.h"
3838
#include "raytrace.h"
3939

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+
}
4074

4175
/**
4276
* Free the storage associated with the rt_db_internal version of
4377
* material object.
4478
*/
45-
void
46-
rt_material_ifree(struct rt_db_internal *ip)
79+
void rt_material_ifree(struct rt_db_internal *ip)
4780
{
4881
register struct rt_material_internal *material;
4982

5083
RT_CK_DB_INTERNAL(ip);
5184
material = (struct rt_material_internal *)ip->idb_ptr;
5285

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");
6498
}
65-
ip->idb_ptr = ((void *)0); /* sanity */
99+
ip->idb_ptr = ((void *)0); /* sanity */
66100
}
67101

68-
69102
/**
70103
* Import a material from the database format to the internal format.
71104
*/
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))
74106
{
75107
struct rt_material_internal *material_ip;
76108

@@ -122,9 +154,12 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
122154

123155
physical_ep.ext_nbytes = size;
124156
physical_ep.ext_buf = cp;
125-
if (size > 0) {
157+
if (size > 0)
158+
{
126159
db5_import_attributes(&material_ip->physicalProperties, &physical_ep);
127-
} else {
160+
}
161+
else
162+
{
128163
bu_avs_init_empty(&material_ip->physicalProperties);
129164
}
130165
cp += size;
@@ -135,9 +170,12 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
135170

136171
mechanical_ep.ext_nbytes = size;
137172
mechanical_ep.ext_buf = cp;
138-
if (size > 0) {
173+
if (size > 0)
174+
{
139175
db5_import_attributes(&material_ip->mechanicalProperties, &mechanical_ep);
140-
} else {
176+
}
177+
else
178+
{
141179
bu_avs_init_empty(&material_ip->mechanicalProperties);
142180
}
143181
cp += size;
@@ -148,9 +186,12 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
148186

149187
optical_ep.ext_nbytes = size;
150188
optical_ep.ext_buf = cp;
151-
if (size > 0) {
189+
if (size > 0)
190+
{
152191
db5_import_attributes(&material_ip->opticalProperties, &optical_ep);
153-
} else {
192+
}
193+
else
194+
{
154195
bu_avs_init_empty(&material_ip->opticalProperties);
155196
}
156197
cp += size;
@@ -161,27 +202,29 @@ rt_material_import5(struct rt_db_internal *ip, const struct bu_external *ep, con
161202

162203
thermal_ep.ext_nbytes = size;
163204
thermal_ep.ext_buf = cp;
164-
if (size > 0) {
205+
if (size > 0)
206+
{
165207
db5_import_attributes(&material_ip->thermalProperties, &thermal_ep);
166-
} else {
208+
}
209+
else
210+
{
167211
bu_avs_init_empty(&material_ip->thermalProperties);
168212
}
169213
cp += size;
170214

171-
return 0; /* OK */
215+
return 0; /* OK */
172216
}
173217

174-
175218
/**
176219
* Export a material from the internal format to the database format.
177220
*/
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))
180222
{
181223
struct rt_material_internal *material_ip;
182224
RT_CK_DB_INTERNAL(ip);
183225

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");
185228
material_ip = (struct rt_material_internal *)ip->idb_ptr;
186229

187230
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
201244
db5_export_attributes(&thermal_ep, &material_ip->thermalProperties);
202245

203246
// 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;
212248
ep->ext_buf = (uint8_t *)bu_calloc(1, ep->ext_nbytes, "material external");
213249
unsigned char *cp = ep->ext_buf;
214250

@@ -234,40 +270,39 @@ rt_material_export5(struct bu_external *ep, const struct rt_db_internal *ip, dou
234270
*(uint32_t *)cp = htonl(physical_ep.ext_nbytes);
235271
cp += SIZEOF_NETWORK_LONG;
236272
memcpy(cp, physical_ep.ext_buf, physical_ep.ext_nbytes);
237-
cp += physical_ep.ext_nbytes;
273+
cp += physical_ep.ext_nbytes;
238274
bu_free_external(&physical_ep);
239275

240276
// copy mechanical properties
241277
*(uint32_t *)cp = htonl(mechanical_ep.ext_nbytes);
242278
cp += SIZEOF_NETWORK_LONG;
243279
memcpy(cp, mechanical_ep.ext_buf, mechanical_ep.ext_nbytes);
244-
cp += mechanical_ep.ext_nbytes;
280+
cp += mechanical_ep.ext_nbytes;
245281
bu_free_external(&mechanical_ep);
246282

247283
// copy optical properties
248284
*(uint32_t *)cp = htonl(optical_ep.ext_nbytes);
249285
cp += SIZEOF_NETWORK_LONG;
250286
memcpy(cp, optical_ep.ext_buf, optical_ep.ext_nbytes);
251-
cp += optical_ep.ext_nbytes;
287+
cp += optical_ep.ext_nbytes;
252288
bu_free_external(&optical_ep);
253289

254290
// copy thermal properties
255291
*(uint32_t *)cp = htonl(thermal_ep.ext_nbytes);
256292
cp += SIZEOF_NETWORK_LONG;
257293
memcpy(cp, thermal_ep.ext_buf, thermal_ep.ext_nbytes);
258-
cp += thermal_ep.ext_nbytes;
294+
cp += thermal_ep.ext_nbytes;
259295
bu_free_external(&thermal_ep);
260296

261-
return 0; /* OK */
297+
return 0; /* OK */
262298
}
263299

264300
/**
265301
* Make human-readable formatted presentation of this object. First
266302
* line describes type of object. Additional lines are indented one
267303
* tab, and give parameter values.
268304
*/
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))
271306
{
272307
register struct rt_material_internal *material_ip = (struct rt_material_internal *)ip->idb_ptr;
273308

@@ -276,33 +311,33 @@ rt_material_describe(struct bu_vls *str, const struct rt_db_internal *ip, int ve
276311
struct bu_vls buf = BU_VLS_INIT_ZERO;
277312
bu_vls_strcat(str, "material (MATERIAL)\n");
278313

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);
282317

283-
if (!verbose) {
318+
if (!verbose)
319+
{
284320
bu_vls_vlscat(str, &buf);
285321
bu_vls_free(&buf);
286322
return 0;
287323
}
288324

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);
293329

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);
298334

299335
bu_vls_vlscat(str, &buf);
300336
bu_vls_free(&buf);
301337

302338
return 0;
303339
}
304340

305-
306341
/** @} */
307342
/*
308343
* Local Variables:

0 commit comments

Comments
 (0)