Skip to content

Commit

Permalink
Merge branch 'av-parse' into 'master'
Browse files Browse the repository at this point in the history
AV parse

See merge request fun3d-developers/refine!753
  • Loading branch information
Mike Park committed Jun 2, 2021
2 parents 80f4398 + 14a5191 commit d91f6f3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/ref_egads.c
Expand Up @@ -3895,6 +3895,62 @@ REF_STATUS ref_egads_get_attribute(REF_GEOM ref_geom, REF_INT type, REF_INT id,
#endif
}

REF_STATUS ref_egads_get_real_attribute(REF_GEOM ref_geom, REF_INT type,
REF_INT id, const char *name,
const REF_DBL **value,
REF_INT *length) {
#ifdef HAVE_EGADS
ego object = NULL;
int attribute_type;
const int *ints;
const char *strings;
int egads_status;

*value = NULL;

switch (type) {
case (REF_GEOM_NODE):
if (NULL == ref_geom->nodes) return REF_INVALID;
if (id < 1 || id > ref_geom->nnode) return REF_INVALID;
object = ((ego *)(ref_geom->nodes))[id - 1];
break;
case (REF_GEOM_EDGE):
if (NULL == ref_geom->edges) return REF_INVALID;
if (id < 1 || id > ref_geom->nedge) return REF_INVALID;
object = ((ego *)(ref_geom->edges))[id - 1];
break;
case (REF_GEOM_FACE):
if (NULL == ref_geom->faces) return REF_INVALID;
if (id < 1 || id > ref_geom->nface) return REF_INVALID;
object = ((ego *)(ref_geom->faces))[id - 1];
break;
case (REF_GEOM_BODY):
if (NULL == ref_geom->body) return REF_INVALID;
object = (ego)(ref_geom->body);
break;
default:
RSS(REF_FAILURE, "unknown type");
}

egads_status = EG_attributeRet(object, name, &attribute_type, length, &ints,
value, &strings);
if (EGADS_NOTFOUND == egads_status) return REF_NOT_FOUND;
REIS(EGADS_SUCCESS, egads_status, "get/return attribute");
if (ATTRREAL != attribute_type) return REF_NOT_FOUND;

return REF_SUCCESS;
#else
*value = NULL;
*length = 0;
printf("no-op, EGADS not linked with HAVE_EGADS_EFFECTIVE %s\n", __func__);
SUPRESS_UNUSED_COMPILER_WARNING(ref_geom);
SUPRESS_UNUSED_COMPILER_WARNING(type);
SUPRESS_UNUSED_COMPILER_WARNING(id);
SUPRESS_UNUSED_COMPILER_WARNING(name);
return REF_SUCCESS;
#endif
}

REF_STATUS ref_egads_extract_mapbc(REF_GEOM ref_geom, const char *mapbc) {
FILE *file;
file = fopen(mapbc, "w");
Expand Down
3 changes: 3 additions & 0 deletions src/ref_egads.h
Expand Up @@ -97,6 +97,9 @@ REF_STATUS ref_egads_add_attribute(REF_GEOM ref_geom, REF_INT type, REF_INT id,
const char *name, const char *value);
REF_STATUS ref_egads_get_attribute(REF_GEOM ref_geom, REF_INT type, REF_INT id,
const char *name, const char **value);
REF_STATUS ref_egads_get_real_attribute(REF_GEOM ref_geom, REF_INT type,
REF_INT id, const char *name,
const REF_DBL **value, REF_INT *length);
REF_STATUS ref_egads_extract_mapbc(REF_GEOM ref_geom, const char *mapbc);

END_C_DECLORATION
Expand Down
31 changes: 31 additions & 0 deletions src/ref_gather.c
Expand Up @@ -2345,6 +2345,16 @@ static REF_STATUS ref_gather_avm(REF_GRID ref_grid, const char *filename) {
for (i = 0; i < length; i++) {
REIS(1, fwrite(&nul, sizeof(nul), 1, file), "nul");
}
if (ref_geom_model_loaded(ref_grid_geom(ref_grid))) {
const char *coord_system;
REF_STATUS ref_status;
ref_status = ref_egads_get_attribute(
ref_grid_geom(ref_grid), REF_GEOM_BODY, REF_EMPTY,
"av:coordinate_system", &coord_system);
if (REF_SUCCESS == ref_status)
RSS(ref_grid_parse_coordinate_system(ref_grid, coord_system),
"parse av coor sys");
}
switch (ref_grid_coordinate_system(ref_grid)) {
case REF_GRID_XBYRZU:
sprintf(coordinate_system, "xByRzU");
Expand All @@ -2367,6 +2377,15 @@ static REF_STATUS ref_gather_avm(REF_GRID ref_grid, const char *filename) {
REIS(1, fwrite(&nul, sizeof(nul), 1, file), "nul");
}
REIS(1, fwrite(&model_scale, sizeof(model_scale), 1, file), "model_scale");
if (ref_geom_model_loaded(ref_grid_geom(ref_grid))) {
const char *unit;
REF_STATUS ref_status;
ref_status =
ref_egads_get_attribute(ref_grid_geom(ref_grid), REF_GEOM_BODY,
REF_EMPTY, "av:mesh_units", &unit);
if (REF_SUCCESS == ref_status)
RSS(ref_grid_parse_unit(ref_grid, unit), "parse unit");
}
switch (ref_grid_unit(ref_grid)) {
case REF_GRID_IN:
sprintf(mesh_units, "in");
Expand All @@ -2390,6 +2409,18 @@ static REF_STATUS ref_gather_avm(REF_GRID ref_grid, const char *filename) {
for (i = 0; i < length; i++) {
REIS(1, fwrite(&nul, sizeof(nul), 1, file), "nul");
}
if (ref_geom_model_loaded(ref_grid_geom(ref_grid))) {
const REF_DBL *reference;
REF_STATUS ref_status;
ref_status = ref_egads_get_real_attribute(
ref_grid_geom(ref_grid), REF_GEOM_BODY, REF_EMPTY, "av:reference",
&reference, &length);
if (REF_SUCCESS == ref_status && 7 == length) {
for (i = 0; i < length; i++) {
ref_grid_reference(ref_grid, i) = reference[i];
}
}
}
REIS(7, fwrite(&ref_grid_reference(ref_grid, 0), sizeof(double), 7, file),
"reference");
length = (int)strlen(ref_point_desc);
Expand Down

0 comments on commit d91f6f3

Please sign in to comment.