Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material parse hotfix #8

Merged
merged 3 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/librt/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,27 @@ db5_update_attributes(struct directory *dp, struct bu_attribute_value_set *avsp,
}
}

const char *material_name = bu_avs_get(avsp, "material_name");
const char *material_id = bu_avs_get(&old_avs, "material_id");
if (material_name != NULL && !BU_STR_EQUAL(material_name, "(null)") && !BU_STR_EQUAL(material_name, "del")) {
struct directory *material_dp = db_lookup(dbip, material_name, LOOKUP_QUIET);
if (material_dp != RT_DIR_NULL) {
struct rt_db_internal intern;
struct rt_material_internal *material_ip;
if (rt_db_get_internal(&intern, material_dp, dbip, NULL, NULL) >= 0) {
if (intern.idb_minor_type == DB5_MINORTYPE_BRLCAD_MATERIAL) {
material_ip = (struct rt_material_internal *) intern.idb_ptr;
const char *id_string = bu_avs_get(&material_ip->physicalProperties, "id");
if (id_string == NULL) {
bu_log("WARNING: [%s] has invalid material_name value [%s]\nmaterial_id remains at %s\n", dp->d_namep, material_name, material_id);
} else {
bu_avs_add(avsp, "material_id", id_string);
}
}
}
}
}

bu_avs_merge(&old_avs, avsp);

db5_export_attributes(&attr, &old_avs);
Expand Down
6 changes: 0 additions & 6 deletions src/librt/db5_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,8 @@ db5_sync_attr_to_comb(struct rt_comb_internal *comb, const struct bu_attribute_v
bu_vls_sprintf(&newval, "%s", bu_avs_get(avs, db5_standard_attribute(ATTR_MATERIAL_NAME)));
bu_vls_trimspace(&newval);
if (bu_vls_strlen(&newval) != 0 && !BU_STR_EQUAL(bu_vls_addr(&newval), "(null)") && !BU_STR_EQUAL(bu_vls_addr(&newval), "del")) {
if (endptr == bu_vls_addr(&newval) + strlen(bu_vls_addr(&newval))) {
attr_char_val = bu_vls_strdup(&newval);
bu_vls_strcpy(&comb->material, attr_char_val);
// set the material_id using this material_name
} else {
bu_log("WARNING: [%s] has invalid material_name value [%s]\nmaterial_name remains at %s\n", name, bu_vls_addr(&newval), bu_vls_strdup(&comb->material));
}
} else {
/* empty - set to zero */
bu_vls_trunc(&comb->material, 0);
Expand Down Expand Up @@ -504,7 +499,6 @@ db5_sync_comb_to_attr(struct bu_attribute_value_set *avs, const struct rt_comb_i
if (bu_vls_strlen(&comb->material) != 0) {
bu_vls_sprintf(&newval, "%s", bu_vls_strdup(&comb->material));
(void)bu_avs_add_vls(avs, db5_standard_attribute(ATTR_MATERIAL_NAME), &newval);
// add the material_id using this material_name
} else {
bu_avs_remove(avs, db5_standard_attribute(ATTR_MATERIAL_NAME));
}
Expand Down