[cgma-dev] r2590 - cgm/trunk/itaps

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Wed Jan 28 15:31:45 CST 2009


Author: kraftche
Date: 2009-01-28 15:31:45 -0600 (Wed, 28 Jan 2009)
New Revision: 2590

Added:
   cgm/trunk/itaps/size.sat
Modified:
   cgm/trunk/itaps/CATag.cpp
   cgm/trunk/itaps/CATag.hpp
   cgm/trunk/itaps/testgeom.cc
Log:
o Fix bug where failure to access preset tag data is not propogated to caller
o Make initialization of preset tag data tabular so it is easier to understand
o Add new preset tags: MESH_INTERVAL, MESH_SIZE, & SIZE_FIRMNESS
o Add tests for new preset tags



Modified: cgm/trunk/itaps/CATag.cpp
===================================================================
--- cgm/trunk/itaps/CATag.cpp	2009-01-28 21:31:20 UTC (rev 2589)
+++ cgm/trunk/itaps/CATag.cpp	2009-01-28 21:31:45 UTC (rev 2590)
@@ -32,6 +32,7 @@
 #include "TDUniqueId.hpp"
 #include "CGMApp.hpp"
 #include "iGeomError.h"
+#include "TopologyEntity.hpp"
 
 #define CHECK_SIZE(array, type, this_size, retval)  \
   if (0 == array ## _allocated || array ## _allocated < this_size) {\
@@ -93,7 +94,22 @@
   CATag *this_ca = new CATag(&instance(), entity, p_csa);
   return this_ca;
 }
+ 
 
+static CGMTagManager::TagInfo preset_tag_list[] = {
+   // tag size      tag name           tag data type  default active
+ { 0,              "",                 iBase_BYTES,   NULL,  false },
+ { 32,             "NAME",             iBase_BYTES,   NULL,   true },
+ { sizeof(int),    "GLOBAL_ID",        iBase_INTEGER, NULL,   true },
+ { sizeof(int),    "UNIQUE_ID",        iBase_INTEGER, NULL,   true },
+ { sizeof(int),    "MESH_INTERVAL",    iBase_INTEGER, NULL,   true },
+ { sizeof(double), "MESH_SIZE",        iBase_DOUBLE,  NULL,   true },
+ { 4,              "SIZE_FIRMNESS",    iBase_BYTES,   NULL,   true } };
+ 
+
+CGMTagManager::TagInfo* const CGMTagManager::presetTagInfo = preset_tag_list;
+const int CGMTagManager::numPresetTag = sizeof(preset_tag_list)/sizeof(preset_tag_list[0]);
+
 CGMTagManager::CGMTagManager() 
     : interfaceGroup(NULL)
 {
@@ -119,32 +135,10 @@
   else
     CATag_att_type = max_type;
 
-    // create the 0th tag, since this index represents no tag
-  TagInfo tmp_info = {0, std::string("NULL tag"), iBase_BYTES, NULL, false};
-  tagInfo.push_back(tmp_info);
-  presetTagInfo.push_back(tmp_info);
-
     // create preset tags, for CGM attributes we want to be visible as tags
     // name - make same as in MBTagConventions
-  tmp_info.tagLength = 32;
-  tmp_info.tagName = std::string("NAME");
-  tmp_info.defaultValue = NULL;
-  tmp_info.tagType = iBase_BYTES;
-  tmp_info.isActive = true;
-  presetTagInfo.push_back(tmp_info);
-  tagNameMap[std::string("NAME")] = -1;
-    // id
-  tmp_info.tagLength = sizeof(int);
-  tmp_info.tagName = std::string("GLOBAL_ID");
-  tmp_info.tagType = iBase_INTEGER;
-  presetTagInfo.push_back(tmp_info);
-  tagNameMap[std::string("GLOBAL_ID")] = -2;
-    // uid
-  tmp_info.tagLength = sizeof(int);
-  tmp_info.tagName = std::string("UNIQUE_ID");
-  tmp_info.tagType = iBase_INTEGER;
-  presetTagInfo.push_back(tmp_info);
-  tagNameMap[std::string("UNIQUE_ID")] = -3;
+  for (int i = 1; i < numPresetTag; ++i)
+    tagNameMap[presetTagInfo[i].tagName] = -i; // neg handles beginning with -1
 }
 
 CGMTagManager::~CGMTagManager() 
@@ -335,14 +329,24 @@
   TagInfo *tinfo = (tag_handle >= 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
   int tag_size = tinfo->tagLength;
     // either way, we have to have that many bytes when we leave this function
+  const bool allocated_data_arr = (*tag_value_allocated == 0);
   TAG_CHECK_SIZE(*tag_value, *tag_value_allocated, entity_handles_size*tinfo->tagLength);
   char *val_ptr = *tag_value;
   if (tag_handle < 0) {
     for (int i = 0; i < entity_handles_size; i++) {
+      bool result;
       if (NULL == entity_handles[i])
-        getPresetTagData(interface_group(), tag_handle, val_ptr, tinfo->tagLength);
+        result = getPresetTagData(interface_group(), tag_handle, val_ptr, tinfo->tagLength);
       else
-        getPresetTagData(entity_handles[i], tag_handle, val_ptr, tinfo->tagLength);
+        result = getPresetTagData(entity_handles[i], tag_handle, val_ptr, tinfo->tagLength);
+      if (!result) {
+        if (allocated_data_arr) {
+          free(*tag_value);
+          *tag_value = 0;
+          *tag_value_allocated = 0;
+        }
+        RETURN(iBase_TAG_NOT_FOUND);
+      }
       val_ptr += tinfo->tagLength;
     }
     *tag_value_size = entity_handles_size*tinfo->tagLength;
@@ -508,6 +512,9 @@
         // unique id
       iGeom_setLastError( iBase_NOT_SUPPORTED, "Can't set unique id of entities with this implementation." );
       return iBase_NOT_SUPPORTED;
+    case 4: // mesh interval
+    case 5: // mesh size
+    case 6: // mesh interval firmness
     default:
       iGeom_setLastError( iBase_NOT_SUPPORTED, "Can't set this tag on entities with this implementation." );
       return iBase_NOT_SUPPORTED;
@@ -516,22 +523,61 @@
   iGeom_setLastError( iBase_TAG_NOT_FOUND );
   return iBase_TAG_NOT_FOUND;
 }
-        
+
+CubitSimpleAttrib* CGMTagManager::get_simple_attrib(RefEntity* entity,
+                                                    const char* name )
+{
+  TopologyEntity* te_ptr = dynamic_cast<TopologyEntity*>(entity);
+  TopologyBridge* tb_ptr = te_ptr ? te_ptr->bridge_manager()->topology_bridge() : 0;
+  if (!tb_ptr) {
+    iGeom_setLastError( iBase_INVALID_ENTITY_HANDLE, "Entity not topology" );
+    return 0;
+  }
+  DLIList<CubitSimpleAttrib*> attr_list;
+  tb_ptr->get_simple_attribute("MESH_INTERVAL", attr_list);
+  if (attr_list.size() == 0) {
+    iGeom_setLastError( iBase_TAG_NOT_FOUND, "No MESH_INTERVAL attribute" );
+    return 0;
+  }
+  CubitSimpleAttrib* result = attr_list.pop();
+  while (attr_list.size() != 0)
+    delete attr_list.pop();
+  return result;
+}
+
+
 bool CGMTagManager::getPresetTagData(const RefEntity *entity, 
                                      const long tag_handle, 
                                      char *tag_value, 
                                      int &tag_size) 
 {
-  std::string *this_name;
+  const char *this_name;
+  int name_len, val;
+  double dval;
   int *this_id;
   int *this_uid;
   
+  if (-tag_handle >= numPresetTag || tag_handle >= 0) {
+    iGeom_setLastError( iBase_INVALID_TAG_HANDLE, "Invalid tag handle" );
+    return false;
+  }
+  
+  const TagInfo& info = presetTagInfo[-tag_handle];
+  tag_size = info.tagLength;
+  CubitSimpleAttrib* csa;
+  CubitString* str;
+  
   switch (-tag_handle) {
     case 1:
         // entity name
-      tag_size = sizeof(std::string);
-      this_name = reinterpret_cast<std::string*>(tag_value);
-      *this_name = std::string(entity->entity_name().c_str());
+      this_name = entity->entity_name().c_str();
+      name_len = strlen(this_name);
+        // if name is too long, truncate
+      if (name_len > info.tagLength)
+        name_len = info.tagLength;
+      strncpy( tag_value, this_name, name_len );
+        // if name is too short, pad with zero bytes
+      memset( tag_value + name_len, 0, info.tagLength );
       return true;
     case 2:
         // entity id
@@ -546,6 +592,70 @@
         // const_cast because we're passing false for create_if_missing
       *this_uid = TDUniqueId::get_unique_id(const_cast<RefEntity*>(entity), false);
       return (*this_uid == 0 ? false : true);
+    case 4: // mesh interval
+      csa = get_simple_attrib( const_cast<RefEntity*>(entity), "MESH_INTERVAL" );
+      if (!csa)
+        return false;
+      csa->int_data_list()->reset();
+      val = *csa->int_data_list()->get_and_step();
+        // check if interval is set
+      csa->string_data_list()->reset();
+        // If a) the size is set and b) the firmness is LIMP, then
+        // the interval count has not been set.
+      if ( csa->string_data_list()->size() && 
+          *csa->string_data_list()->get() == "LIMP" && 
+           csa->int_data_list()->size() > 1 && 
+         !*csa->int_data_list()->get())
+        val = 0;
+      delete csa;
+      if (val == 0 || val == CUBIT_INT_MIN) {
+        if (info.defaultValue)
+          val = *(int*)info.defaultValue;
+        else {
+          iGeom_setLastError( iBase_TAG_NOT_FOUND, "Interval not set" );
+          return 0;
+        }
+      }
+      *(int*)tag_value = val;
+      return true;
+    case 5: // mesh size
+      csa = get_simple_attrib( const_cast<RefEntity*>(entity), "MESH_INTERVAL" );
+      if (!csa)
+        return false;
+      csa->int_data_list()->reset();
+      csa->int_data_list()->step();
+      csa->double_data_list()->reset();
+        // if size value is invalid or flag indicates size has not been set...
+      if (csa->double_data_list()->size() == 0 ||
+         *csa->double_data_list()->get() == CUBIT_DBL_MIN ||
+         (csa->int_data_list()->size() > 1 && !*csa->int_data_list()->get())) {
+        if (info.defaultValue)
+          dval = *(double*)info.defaultValue;
+        else {
+          delete csa;
+          iGeom_setLastError( iBase_TAG_NOT_FOUND, "Mesh size not set" );
+          return false;
+        }
+      }
+      else
+        dval = *csa->double_data_list()->get();
+      delete csa;
+      *(double*)tag_value = dval;
+      return true;
+    case 6: // interval firmness
+      csa = get_simple_attrib( const_cast<RefEntity*>(entity), "MESH_INTERVAL" );
+      if (!csa)
+        return false;
+      if (csa->string_data_list()->size() < 2) {
+        delete csa;
+        iGeom_setLastError( iBase_TAG_NOT_FOUND, "Interval firmness not set" );
+        return false;
+      }
+      csa->string_data_list()->reset();
+      str = csa->string_data_list()->step_and_get();
+      memcpy( tag_value, str->c_str(), 4 );
+      delete csa;
+      return true;
   }
 
   return false;

Modified: cgm/trunk/itaps/CATag.hpp
===================================================================
--- cgm/trunk/itaps/CATag.hpp	2009-01-28 21:31:20 UTC (rev 2589)
+++ cgm/trunk/itaps/CATag.hpp	2009-01-28 21:31:45 UTC (rev 2590)
@@ -122,7 +122,8 @@
   int CATag_att_type;
   long pcTag;
   std::vector<TagInfo> tagInfo;
-  std::vector<TagInfo> presetTagInfo;
+  static TagInfo* const presetTagInfo;
+  static const int numPresetTag;
   std::map<std::string, long> tagNameMap;
   static const char *CATag_NAME;
   static const char *CATag_NAME_INTERNAL;
@@ -141,6 +142,7 @@
   
   RefGroup *interface_group(const bool create_if_missing = true);
   
+  CubitSimpleAttrib* get_simple_attrib( RefEntity* entity, const char* name );  
 };
 
 class CATag: public CubitAttrib

Added: cgm/trunk/itaps/size.sat
===================================================================
--- cgm/trunk/itaps/size.sat	                        (rev 0)
+++ cgm/trunk/itaps/size.sat	2009-01-28 21:31:45 UTC (rev 2590)
@@ -0,0 +1,107 @@
+1600 0 1 0           
+10 Cubit 10.2 17 ACIS 16.0.1 Linux 24 Wed Jan 28 12:39:30 2009 
+1 9.9999999999999995e-07 1e-10 
+body $-1 -1 -1 $-1 $1 $-1 $-1 T -5 -5 -5 5 5 5 #
+lump $-1 -1 -1 $-1 $-1 $2 $0 T -5 -5 -5 5 5 5 #
+shell $-1 -1 -1 $-1 $-1 $-1 $3 $-1 $1 T -5 -5 -5 5 5 5 #
+face $4 -1 -1 $-1 $5 $6 $2 $-1 $7 forward single T -5 -5 5 5 5 5 F #
+simple-snl-attrib $-1 -1 $-1 $-1 $3 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 SOFT @4 LIMP 2 1 0 5 1 1 0 1 1 #
+face $8 -1 -1 $-1 $9 $10 $2 $-1 $11 reversed single T -5 -5 -5 5 5 -5 F #
+loop $-1 -1 -1 $-1 $-1 $12 $3 T -5 -5 5 5 5 5 unknown #
+plane-surface $-1 -1 -1 $-1 0 0 5 0 0 1 1 0 0 forward_v I I I I #
+simple-snl-attrib $-1 -1 $-1 $-1 $5 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 SOFT @4 LIMP 2 2 0 5 1 1 0 1 1 #
+face $13 -1 -1 $-1 $14 $15 $2 $-1 $16 reversed single T -5 -5 -5 5 -5 5 F #
+loop $-1 -1 -1 $-1 $-1 $17 $5 T -5 -5 -5 5 5 -5 unknown #
+plane-surface $-1 -1 -1 $-1 0 0 -5 0 0 1 1 0 0 forward_v I I I I #
+coedge $-1 -1 -1 $-1 $18 $19 $20 $21 forward $6 $-1 #
+simple-snl-attrib $-1 -1 $-1 $-1 $9 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 SOFT @4 LIMP 2 3 0 5 1 1 0 1 1 #
+face $22 -1 -1 $-1 $23 $24 $2 $-1 $25 reversed single T -5 -5 -5 -5 5 5 F #
+loop $-1 -1 -1 $-1 $-1 $26 $9 T -5 -5 -5 5 -5 5 unknown #
+plane-surface $-1 -1 -1 $-1 0 -5 0 0 1 -0 -0 0 1 forward_v I I I I #
+coedge $-1 -1 -1 $-1 $27 $28 $29 $30 forward $10 $-1 #
+coedge $-1 -1 -1 $-1 $31 $12 $32 $33 forward $6 $-1 #
+coedge $-1 -1 -1 $-1 $12 $31 $34 $35 forward $6 $-1 #
+coedge $-1 -1 -1 $-1 $36 $37 $12 $21 reversed $38 $-1 #
+edge $39 -1 -1 $-1 $40 -5 $41 5 $20 $42 forward @7 unknown T 5 -5 5 5 5 5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $14 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 SOFT @4 LIMP 2 4 0 5 1 1 0 1 1 #
+face $43 -1 -1 $-1 $44 $45 $2 $-1 $46 reversed single T -5 5 -5 5 5 5 F #
+loop $-1 -1 -1 $-1 $-1 $47 $14 T -5 -5 -5 -5 5 5 unknown #
+plane-surface $-1 -1 -1 $-1 -5 0 0 1 0 0 0 0 -1 forward_v I I I I #
+coedge $-1 -1 -1 $-1 $48 $34 $49 $50 forward $15 $-1 #
+coedge $-1 -1 -1 $-1 $51 $17 $48 $52 forward $10 $-1 #
+coedge $-1 -1 -1 $-1 $17 $51 $53 $54 forward $10 $-1 #
+coedge $-1 -1 -1 $-1 $37 $36 $17 $30 reversed $38 $-1 #
+edge $55 -1 -1 $-1 $56 -5 $57 5 $29 $58 forward @7 unknown T 5 -5 -5 5 5 -5 #
+coedge $-1 -1 -1 $-1 $19 $18 $59 $60 forward $6 $-1 #
+coedge $-1 -1 -1 $-1 $61 $62 $18 $33 reversed $45 $-1 #
+edge $63 -1 -1 $-1 $41 -5 $64 5 $32 $65 forward @7 unknown T -5 5 5 5 5 5 #
+coedge $-1 -1 -1 $-1 $26 $66 $19 $35 reversed $15 $-1 #
+edge $67 -1 -1 $-1 $68 -5 $40 5 $34 $69 forward @7 unknown T -5 -5 5 5 -5 5 #
+coedge $-1 -1 -1 $-1 $29 $20 $66 $70 forward $38 $-1 #
+coedge $-1 -1 -1 $-1 $20 $29 $61 $71 reversed $38 $-1 #
+loop $-1 -1 -1 $-1 $-1 $36 $44 T 5 -5 -5 5 5 5 unknown #
+simple-snl-attrib $-1 -1 $-1 $-1 $21 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 6 0 5 1 1 1 0 -2147483648 #
+vertex $-1 -1 -1 $-1 $21 $72 #
+vertex $-1 -1 -1 $-1 $21 $73 #
+straight-curve $-1 -1 -1 $-1 5 0 5 0 1 0 I I #
+simple-snl-attrib $-1 -1 $-1 $-1 $23 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 SOFT @4 LIMP 2 5 0 5 1 1 0 1 1 #
+face $74 -1 -1 $-1 $-1 $38 $2 $-1 $75 reversed single T 5 -5 -5 5 5 5 F #
+loop $-1 -1 -1 $-1 $-1 $61 $23 T -5 5 -5 5 5 5 unknown #
+plane-surface $-1 -1 -1 $-1 0 5 0 0 -1 0 0 0 -1 forward_v I I I I #
+coedge $-1 -1 -1 $-1 $76 $59 $62 $77 forward $24 $-1 #
+coedge $-1 -1 -1 $-1 $66 $26 $27 $52 reversed $15 $-1 #
+coedge $-1 -1 -1 $-1 $59 $76 $26 $50 reversed $24 $-1 #
+edge $78 -1 -1 $-1 $68 -5 $79 5 $49 $80 forward @7 unknown T -5 -5 -5 -5 -5 5 #
+coedge $-1 -1 -1 $-1 $28 $27 $76 $81 forward $10 $-1 #
+edge $82 -1 -1 $-1 $57 -5 $79 5 $48 $83 forward @7 unknown T -5 -5 -5 5 -5 -5 #
+coedge $-1 -1 -1 $-1 $62 $61 $28 $54 reversed $45 $-1 #
+edge $84 -1 -1 $-1 $85 -5 $56 5 $53 $86 forward @7 unknown T -5 5 -5 5 5 -5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $30 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 6 0 5 5 1 1 0 -2147483648 #
+vertex $-1 -1 -1 $-1 $30 $87 #
+vertex $-1 -1 -1 $-1 $70 $88 #
+straight-curve $-1 -1 -1 $-1 5 0 -5 0 -1 0 I I #
+coedge $-1 -1 -1 $-1 $47 $49 $31 $60 reversed $24 $-1 #
+edge $89 -1 -1 $-1 $64 -5 $68 5 $59 $90 forward @7 unknown T -5 -5 5 -5 5 5 #
+coedge $-1 -1 -1 $-1 $53 $32 $37 $71 forward $45 $-1 #
+coedge $-1 -1 -1 $-1 $32 $53 $47 $77 reversed $45 $-1 #
+simple-snl-attrib $-1 -1 $-1 $-1 $33 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 5 0 5 2 1 1 0 -2147483648 #
+vertex $-1 -1 -1 $-1 $33 $91 #
+straight-curve $-1 -1 -1 $-1 0 5 5 -1 0 0 I I #
+coedge $-1 -1 -1 $-1 $34 $48 $36 $70 reversed $15 $-1 #
+simple-snl-attrib $-1 -1 $-1 $-1 $35 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 3 0 5 4 1 1 0 -2147483648 #
+vertex $-1 -1 -1 $-1 $60 $92 #
+straight-curve $-1 -1 -1 $-1 0 -5 5 1 0 0 I I #
+edge $93 -1 -1 $-1 $40 -5 $57 5 $36 $94 forward @7 unknown T 5 -5 -5 5 -5 5 #
+edge $95 -1 -1 $-1 $41 -5 $56 5 $37 $96 forward @7 unknown T 5 5 -5 5 5 5 #
+point $-1 -1 -1 $-1 5 -5 5 #
+point $-1 -1 -1 $-1 5 5 5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $44 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 SOFT @4 LIMP 2 6 0 5 1 1 0 1 1 #
+plane-surface $-1 -1 -1 $-1 5 0 0 -1 0 0 0 -0 1 forward_v I I I I #
+coedge $-1 -1 -1 $-1 $49 $47 $51 $81 reversed $24 $-1 #
+edge $97 -1 -1 $-1 $64 -5 $85 5 $62 $98 forward @7 unknown T -5 5 -5 -5 5 5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $50 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 4 0 5 9 1 1 0 -2147483648 #
+vertex $-1 -1 -1 $-1 $81 $99 #
+straight-curve $-1 -1 -1 $-1 -5 -5 0 0 0 -1 I I #
+edge $100 -1 -1 $-1 $79 -5 $85 5 $76 $101 forward @7 unknown T -5 -5 -5 -5 5 -5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $52 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 3 0 5 6 1 1 0 -2147483648 #
+straight-curve $-1 -1 -1 $-1 0 -5 -5 -1 0 0 I I #
+simple-snl-attrib $-1 -1 $-1 $-1 $54 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 5 0 5 8 1 1 0 -2147483648 #
+vertex $-1 -1 -1 $-1 $54 $102 #
+straight-curve $-1 -1 -1 $-1 0 5 -5 1 0 0 I I #
+point $-1 -1 -1 $-1 5 5 -5 #
+point $-1 -1 -1 $-1 5 -5 -5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $60 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 4 0 5 3 1 1 0 -2147483648 #
+straight-curve $-1 -1 -1 $-1 -5 0 5 0 -1 0 I I #
+point $-1 -1 -1 $-1 -5 5 5 #
+point $-1 -1 -1 $-1 -5 -5 5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $70 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 6 0 5 10 1 1 0 -2147483648 #
+straight-curve $-1 -1 -1 $-1 5 -5 0 0 0 -1 I I #
+simple-snl-attrib $-1 -1 $-1 $-1 $71 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 6 0 5 12 1 1 0 -2147483648 #
+straight-curve $-1 -1 -1 $-1 5 5 0 0 0 -1 I I #
+simple-snl-attrib $-1 -1 $-1 $-1 $77 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 5 0 5 11 1 1 0 -2147483648 #
+straight-curve $-1 -1 -1 $-1 -5 5 0 0 0 -1 I I #
+point $-1 -1 -1 $-1 -5 -5 -5 #
+simple-snl-attrib $-1 -1 $-1 $-1 $81 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 @17 NEW_SIMPLE_ATTRIB 3 @13 MESH_INTERVAL @4 HARD @4 LIMP 2 4 0 5 7 1 1 0 -2147483648 #
+straight-curve $-1 -1 -1 $-1 -5 0 -5 0 1 0 I I #
+point $-1 -1 -1 $-1 -5 5 -5 #
+End-of-ACIS-data 
\ No newline at end of file

Modified: cgm/trunk/itaps/testgeom.cc
===================================================================
--- cgm/trunk/itaps/testgeom.cc	2009-01-28 21:31:20 UTC (rev 2589)
+++ cgm/trunk/itaps/testgeom.cc	2009-01-28 21:31:45 UTC (rev 2590)
@@ -22,6 +22,10 @@
 #include <vector>
 #include <iterator>
 #include <algorithm>
+#include <iomanip>
+#include <assert.h>
+#include <string.h>
+#include <math.h>
 #define CHECK( STR ) if (err != iBase_SUCCESS) return print_error( STR, err, geom, __FILE__, __LINE__ )
 
 #define STRINGIFY(S) XSTRINGIFY(S)
@@ -106,6 +110,7 @@
 bool transforms_test(iGeom_Instance geom);
 bool booleans_test(iGeom_Instance geom);
 bool shutdown_test(iGeom_Instance geom);
+bool mesh_size_test(iGeom_Instance geom);
 
 void handle_error_code(const bool result,
                        int &number_failed,
@@ -236,6 +241,16 @@
                     number_tests_successful);
   number_tests++;
   std::cout << "\n";
+  
+#if defined(HAVE_ACIS) && !defined(FORCE_OCC)
+  std::cout << "   mesh size: ";
+  result = mesh_size_test(geom);
+  handle_error_code(result, number_tests_failed,
+                    number_tests_not_implemented,
+                    number_tests_successful);
+  number_tests++;
+  std::cout << "\n";
+#endif  
 
     // shutdown test
   std::cout << "   shutdown: ";
@@ -246,6 +261,7 @@
   number_tests++;
   std::cout << "\n";
   
+
     // summary
 
   std::cout << "\nTSTT TEST SUMMARY: \n"
@@ -1152,6 +1168,199 @@
   return true;
 }
 
+static int get_entities( iGeom_Instance geom, int entity_type,
+                          std::vector<iBase_EntityHandle>& entities_out,
+                          iBase_TagHandle id_tag = 0,
+                          std::vector<int>* ids_out = 0 )
+{
+  int err, num;
+  iBase_EntitySetHandle root;
+  iGeom_getRootSet( geom, &root, &err ); 
+  if (iBase_SUCCESS != err)
+    return err;
+  iGeom_getNumOfType( geom, root, entity_type, &num, &err ); 
+  if (iBase_SUCCESS != err)
+    return err;
+  
+  entities_out.resize(num);
+  int junk1 = entities_out.size(), junk2;
+  iBase_EntityHandle* junk_ptr = &entities_out[0];;
+  iGeom_getEntities( geom, root, entity_type, &junk_ptr, &junk1, &junk2, &err );
+  if (iBase_SUCCESS != err)
+    return err;
+  assert( num == junk1 && num == junk2 );
+  
+  if (!ids_out)
+    return iBase_SUCCESS;
+  
+  ids_out->resize(num);
+  int* int_ptr = &(*ids_out)[0];
+  iGeom_getIntArrData( geom, &entities_out[0], num, id_tag, &int_ptr, &junk1, &junk2, &err );
+  if (iBase_SUCCESS != err)
+    return err;
+  assert( num == junk1 && num == junk2 );
+  
+  return iBase_SUCCESS;
+}
+
+static int check_firmness( iGeom_Instance geom,
+                           const std::vector<iBase_EntityHandle>& entities,
+                           const std::vector<int>& ids,
+                           iBase_TagHandle firmness_tag,
+                           const char* expected_value,
+                           const char* ent_type_str )
+{
+  const int firmness_size = 4;
+  std::vector<char> firmness(firmness_size * entities.size());
+
+  char* byte_ptr = &firmness[0];
+  int err, junk1, junk2 = entities.size()*firmness_size;
+  iGeom_getArrData( geom, &entities[0], entities.size(), firmness_tag, &byte_ptr, &junk1, &junk2, &err ); 
+  if (iBase_SUCCESS != err)
+    return err;
+  
+  bool all_correct = true;
+  for (unsigned i = 0; i < entities.size(); ++i)
+    if (std::string(&firmness[firmness_size*i],firmness_size) != expected_value)
+      all_correct = false;
+  if (!all_correct) {
+    std::cout << "ERROR: Expected \"" << expected_value << "\" firmness "
+              << "for all " << ent_type_str << "." << std::endl;
+    std::cout << "ID  Actual  " << std::endl;
+    for (unsigned i = 0; i < entities.size(); ++i)
+      std::cout << std::setw(2) << ids[i] << "  "
+                << std::string(&firmness[firmness_size*i],firmness_size)
+                << std::endl;
+    return iBase_FAILURE;
+  }
+  
+  return iBase_SUCCESS;
+}
+
+static int count_num_with_tag( iGeom_Instance geom,
+                               const std::vector<iBase_EntityHandle>& ents,
+                               iBase_TagHandle tag )
+{
+  int err, bytes;
+  iGeom_getTagSizeBytes( geom, tag, &bytes, &err );
+  if (iBase_SUCCESS != err)
+    return -1;
+  std::vector<char> data(bytes);
+  
+  int success_count = 0;
+  for (size_t i = 0; i < ents.size(); ++i) {
+    char* ptr = &data[0];
+    int junk1 = bytes, junk2;
+    iGeom_getData( geom, ents[i], tag, &ptr, &junk1, &junk2, &err );
+    if (iBase_TAG_NOT_FOUND == err)
+      continue;
+    if (iBase_SUCCESS != err)
+      return -1;
+    ++success_count;
+  }
+  
+  return success_count;
+}
+  
+
+bool mesh_size_test(iGeom_Instance geom)
+{
+  const char* filename = STRINGIFY(SRCDIR) "/size.sat";
+  int err, junk1, junk2;
+  bool result = true;
+  
+  iGeom_deleteAll( geom, &err ); CHECK("");
+  iGeom_load( geom, filename, 0, &err, strlen(filename), 0 );
+  CHECK( "Failed to load input file: 'size.sat'" );
+  
+    // get tag handles
+  iBase_TagHandle interval, size, firmness, id;
+  iGeom_getTagHandle( geom, "MESH_INTERVAL", &interval, &err, strlen("MESH_INTERVAL") );
+  CHECK( "iGeom_getTagHandle(\"MESH_INTERVAL\")" );
+  iGeom_getTagHandle( geom, "MESH_SIZE", &size, &err, strlen("MESH_SIZE") );
+  CHECK( "iGeom_getTagHandle(\"MESH_SIZE\")" );
+  iGeom_getTagHandle( geom, "SIZE_FIRMNESS", &firmness, &err, strlen("SIZE_FIRMNESS") );
+  CHECK( "iGeom_getTagHandle(\"SIZE_FIRMNESS\")" );
+  iGeom_getTagHandle( geom, "GLOBAL_ID", &id, &err, strlen("GLOBAL_ID") );
+  CHECK( "iGeom_getTagHandle(\"GLOBAL_ID\")" );
+  
+    // get entity lists
+  std::vector<iBase_EntityHandle> verts, curves, surfs, vols;
+  std::vector<int> vert_ids, curve_ids, surf_ids, vol_ids;
+  err = get_entities( geom, iBase_VERTEX, verts,  id, &vert_ids  ); CHECK("");
+  err = get_entities( geom, iBase_EDGE,   curves, id, &curve_ids ); CHECK("");
+  err = get_entities( geom, iBase_FACE,   surfs,  id, &surf_ids  ); CHECK("");
+  err = get_entities( geom, iBase_REGION, vols,   id, &vol_ids   ); CHECK("");
+  
+    // expect interval count to be the same as ID for every curve
+  std::vector<int> intervals(curves.size());
+  int *int_ptr = &intervals[0];
+  junk1 = junk2 = curves.size();
+  iGeom_getIntArrData( geom, &curves[0], curves.size(), interval, &int_ptr, &junk1, &junk2, &err ); 
+  CHECK("Failed to get intervals for curves");
+  if (intervals != curve_ids) {
+    std::cout << "ERROR: Incorrect curve intervals for one or more curves." << std::endl;
+    std::cout << "ID  Expected  Actual" << std::endl;
+    for (unsigned i = 0; i < curves.size(); ++i)
+      std::cout << std::setw(2) << curve_ids[i] << "  "
+                << std::setw(8) << curve_ids[i] << "  "
+                << std::setw(6) << intervals[i] << std::endl;
+    result = false;
+  }
+  
+    // expect size to be the same as ID for every surface
+  std::vector<double> sizes(surfs.size());
+  double* dbl_ptr = &sizes[0];
+  junk1 = junk2 = surfs.size();
+  iGeom_getDblArrData( geom, &surfs[0], surfs.size(), size, &dbl_ptr, &junk1, &junk2, &err ); 
+  CHECK("Failed to get sizes for surfaces");
+  bool all_correct = true;
+  for (unsigned i = 0; i < surfs.size(); ++i)
+    if (fabs(sizes[i] - (double)surf_ids[i] ) > 1e-8)
+      all_correct = false;
+  if (!all_correct) {
+    std::cout << "ERROR: Incorrect mesh size for one or more surfaces." << std::endl;
+    std::cout << "ID  Expected  Actual  " << std::endl;
+    for (unsigned i = 0; i < surfs.size(); ++i)
+      std::cout << std::setw(2) << surf_ids[i] << "  "
+                << std::setw(8) << (double)surf_ids[i] << "  "
+                << std::setw(8) << sizes[i] << std::endl;
+    result = false;
+  }
+  
+  
+  err = result ? iBase_SUCCESS : iBase_FAILURE;
+  CHECK("Invalid size or interval data");
+    
+    // expect "HARD" firmness on all curves
+  err = check_firmness( geom, curves, curve_ids, firmness, "HARD", "curves" );
+  CHECK("Invalid curve firmness");
+    // expect "SOFT" firmness on all surfaces
+  err = check_firmness( geom, surfs, surf_ids, firmness, "SOFT", "surfaces" );
+  CHECK("Invalid surface firmness");
+  
+    // expect no firmnes on other entities
+  err = count_num_with_tag( geom, verts, firmness ) ? iBase_FAILURE : iBase_SUCCESS;
+  CHECK("Got firmness for vertex.");
+  err = count_num_with_tag( geom, vols, firmness ) ? iBase_FAILURE : iBase_SUCCESS;
+  CHECK("Got firmness for volume.");
+
+    // expect no interval tag on any entities except curves
+  err = count_num_with_tag( geom, verts, interval ) ? iBase_FAILURE : iBase_SUCCESS;
+  CHECK("Got interval count for vertex.");
+  err = count_num_with_tag( geom, vols, interval ) ? iBase_FAILURE : iBase_SUCCESS;
+  CHECK("Got interval count for volume.");
+
+    // expect no size tag on any entities except surfaces
+    // curves should have size of one of their parent surfaces
+  err = count_num_with_tag( geom, verts, size ) ? iBase_FAILURE : iBase_SUCCESS;
+  CHECK("Got mesh size for vertex.");
+  err = count_num_with_tag( geom, vols, size ) ? iBase_FAILURE : iBase_SUCCESS;
+  CHECK("Got mesh size for volume.");
+
+  return true;
+}
+
 bool shutdown_test(iGeom_Instance geom) 
 {
   int err;



More information about the cgma-dev mailing list