1 #include "DamselUtil.hpp"
2 #include "moab/Range.hpp"
3
4 #include "damsel.h"
5
6 namespace moab
7 {
8
9 damsel_entity_type DamselUtil::mtod_entity_type[] = {
10 DAMSEL_ENTITY_TYPE_VERTEX,
11 DAMSEL_ENTITY_TYPE_EDGE,
12 DAMSEL_ENTITY_TYPE_TRI,
13 DAMSEL_ENTITY_TYPE_QUAD,
14 DAMSEL_ENTITY_TYPE_POLYGON,
15 DAMSEL_ENTITY_TYPE_TET,
16 DAMSEL_ENTITY_TYPE_PYRAMID,
17 DAMSEL_ENTITY_TYPE_PRISM,
18 DAMSEL_ENTITY_TYPE_UNDEFINED,
19 DAMSEL_ENTITY_TYPE_HEX,
20 DAMSEL_ENTITY_TYPE_POLYHEDRON,
21 DAMSEL_ENTITY_TYPE_UNDEFINED
22 };
23
24 EntityType DamselUtil::dtom_entity_type[] = {
25 MBVERTEX,
26 MBEDGE,
27 MBTRI,
28 MBQUAD,
29 MBPOLYGON,
30 MBTET,
31 MBPRISM,
32 MBPYRAMID,
33 MBHEX,
34 MBPOLYHEDRON,
35 MBMAXTYPE,
36 MBMAXTYPE
37 };
38
39 damsel_data_type DamselUtil::mtod_data_type[] = {
40 DAMSEL_DATA_TYPE_BYTES,
41 DAMSEL_DATA_TYPE_INTEGER,
42 DAMSEL_DATA_TYPE_DOUBLE,
43 DAMSEL_DATA_TYPE_INVALID,
44 DAMSEL_DATA_TYPE_HANDLE
45 };
46
47 DataType DamselUtil::dtom_data_type[] = {
48 MB_TYPE_OPAQUE,
49 MB_TYPE_OPAQUE,
50 MB_TYPE_INTEGER,
51 MB_TYPE_OPAQUE,
52 MB_TYPE_OPAQUE,
53 MB_TYPE_DOUBLE,
54 MB_TYPE_HANDLE,
55 MB_TYPE_OPAQUE,
56 MB_TYPE_OPAQUE,
57 MB_TYPE_OPAQUE
58 };
59
60 DamselUtil::DamselUtil()
61 : dmslLib( DAMSEL_LIBRARY_INVALID ), dmslModel( DAMSEL_MODEL_INVALID ), moabHandleType( DAMSEL_HANDLE_TYPE_INVALID )
62 {
63 }
64
65
66
67 ErrorCode DamselUtil::container_to_range( damsel_model m, damsel_container& c, Range& r )
68 {
69 if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_SEQUENCE )
70 {
71 damsel_handle start;
72 size_t count, stride;
73 damsel_err_t err = DMSLcontainer_sequence_get_contents( m, c, &start, &count, &stride );
74 CHK_DMSL_ERR_NM( err );
75 for( damsel_handle i = start + ( count - 1 ) * stride; i >= start; i -= stride )
76 r.insert( i );
77 }
78 else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_VECTOR )
79 {
80 damsel_handle* handle_ptr;
81 size_t count;
82 damsel_err_t err = DMSLcontainer_vector_get_contents( m, c, &handle_ptr, &count );
83 CHK_DMSL_ERR_NM( err );
84 for( int i = count - 1; i >= 0; i-- )
85 r.insert( handle_ptr[i] );
86 }
87 else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_TREE )
88 {
89 damsel_handle_ptr node_ptr = NULL;
90 damsel_container cont = NULL;
91 damsel_err_t err = DMSLcontainer_tree_get_contents( m, c, &node_ptr, &cont );
92 while( err.id == DMSL_OK.id && cont )
93 {
94 ErrorCode rval = container_to_range( m, c, r );
95 if( MB_SUCCESS != rval ) return rval;
96 err = DMSLcontainer_tree_get_contents( m, c, &node_ptr, &cont );
97 }
98 }
99
100 return MB_SUCCESS;
101 }
102
103 }