LCOV - code coverage report
Current view: top level - disks2/fathom/slaves/sigma2/cgm-occ-cov/build/itaps - iGeom_CGMA.cc (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 795 3073 25.9 %
Date: 2020-06-30 00:58:45 Functions: 84 235 35.7 %
Branches: 830 4676 17.8 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * Copyright 2006 Sandia Corporation.  Under the terms of Contract
       3                 :            :  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
       4                 :            :  * retains certain rights in this software.
       5                 :            :  * 
       6                 :            :  * This library is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU Lesser General Public
       8                 :            :  * License as published by the Free Software Foundation; either
       9                 :            :  * version 2.1 of the License, or (at your option) any later version.
      10                 :            :  * 
      11                 :            :  */
      12                 :            :  
      13                 :            : /**\file iGeom_CGMA.cc
      14                 :            :  *
      15                 :            :  *\author Tim Tautges
      16                 :            :  *\author Jason Kraftcheck
      17                 :            :  *
      18                 :            :  * Original file from SNL TSTT repository was named TSTTG_CGM.cpp.
      19                 :            :  *
      20                 :            :  * Renamed iGeom_CGMA.cc and added to ANL ITAPS repository by J.Kraftcheck,
      21                 :            :  * 2007-6-15
      22                 :            :  */
      23                 :            : #include "InitCGMA.hpp"
      24                 :            : #include "GMem.hpp"
      25                 :            : #include <iostream>
      26                 :            : #include <limits>
      27                 :            : #include <math.h>
      28                 :            : #include "GeometryQueryTool.hpp"
      29                 :            : #include "CubitCompat.hpp"
      30                 :            : #include "CCubitFile.hpp"
      31                 :            : 
      32                 :            : #include "cgm/CGMConfig.h"
      33                 :            : 
      34                 :            : 
      35                 :            : #ifdef ITAPS_SHIM
      36                 :            : # include "iGeom_private.h"
      37                 :            : # include "iGeom_binding.h"
      38                 :            : # include "CGM_iGeom.h"
      39                 :            : # define ITAPS_API static
      40                 :            : #else
      41                 :            : # include "iGeom.h"
      42                 :            : # define ITAPS_API
      43                 :            : #endif
      44                 :            : 
      45                 :            : const bool debug = false;
      46                 :            : 
      47                 :            : #define RETURN(a) do {CGM_iGeom_setLastError((*err = a)); return; } while(false)
      48                 :            : #define ERROR(a, b) do {CGM_iGeom_setLastError((*err = a), b); return; } while(false)
      49                 :            : 
      50                 :            : #define ARRAY_IN(b) \
      51                 :            :   b, b ## _size  
      52                 :            : 
      53                 :            : #define ARRAY_INOUT(b) \
      54                 :            :   b, b ## _allocated, b ## _size  
      55                 :            : 
      56                 :            : // Check the array size, and allocate the array if necessary.
      57                 :            : // Free the array upon leaving scope unless KEEP_ARRAY
      58                 :            : // is invoked.
      59                 :            : #define ALLOC_CHECK_ARRAY(array, this_size) \
      60                 :            :   iGeomArrayManager array ## _manager ( reinterpret_cast<void**>(array), *(array ## _allocated), *(array ## _size), this_size, sizeof(**array), err ); \
      61                 :            :   if (iBase_SUCCESS != *err) return
      62                 :            : 
      63                 :            : #define KEEP_ARRAY(array) \
      64                 :            :   array ## _manager .keep_array()
      65                 :            : 
      66                 :            : // Check the array size, and allocate the array if necessary.
      67                 :            : // Do NOT free the array upon leaving scope.
      68                 :            : #define ALLOC_CHECK_ARRAY_NOFAIL(array, this_size) \
      69                 :            :   ALLOC_CHECK_ARRAY(array, this_size); KEEP_ARRAY(array)
      70                 :            : 
      71                 :            : #define TAG_HANDLE(handle) reinterpret_cast<long>(handle)
      72                 :            : 
      73                 :            : #define ENTITY_HANDLE(handle) reinterpret_cast<RefEntity*>(handle)
      74                 :            : #define SET_HANDLE(handle) reinterpret_cast<RefGroup*>(handle)
      75                 :            : 
      76                 :            : #define ENTITY_HANDLE_ARRAY(array) reinterpret_cast<RefEntity**>(array)
      77                 :            : #define SET_HANDLE_ARRAY(array) reinterpret_cast<RefGroup**>(array)
      78                 :            : 
      79                 :            : #define ENTITY_HANDLE_CONST_ARRAY(array) reinterpret_cast<RefEntity* const*>(array)
      80                 :            : #define SET_HANDLE_CONST_ARRAY(array) reinterpret_cast<RefGroup* const*>(array)
      81                 :            : 
      82                 :            : #define ENTITY_HANDLE_ARRAY_PTR(array) reinterpret_cast<RefEntity***>(array)
      83                 :            : #define SET_HANDLE_ARRAY_PTR(array) reinterpret_cast<RefGroup***>(array)
      84                 :            : 
      85                 :            : #define CAST_TO_VOID(ptr) reinterpret_cast<void*>(ptr)
      86                 :            : #define TAG_HANDLE_ARRAY_INOUT(a) reinterpret_cast<long**>(a), a ## _allocated, a ## _size
      87                 :            : 
      88                 :            : #define TM reinterpret_cast<CGMTagManager*>(instance)
      89                 :            : 
      90                 :            : const double RAD_TO_DEG = 180.0 / acos(-1.0);
      91                 :            : const double DEG_TO_RAD = 1.0 / RAD_TO_DEG;
      92                 :            : 
      93                 :            : #include "CATag.hpp"
      94                 :            : #include "CGMAIterator.hpp"
      95                 :            : #include "iGeomError.h"
      96                 :            : 
      97                 :            : #include "RefEntityFactory.hpp"
      98                 :            : #include "BasicTopologyEntity.hpp"
      99                 :            : #include "RefGroup.hpp"
     100                 :            : #include "Body.hpp"
     101                 :            : #include "RefVertex.hpp"
     102                 :            : #include "RefEdge.hpp"
     103                 :            : #include "RefFace.hpp"
     104                 :            : #include "RefVolume.hpp"
     105                 :            : #include "CubitVector.hpp"
     106                 :            : 
     107                 :            : #ifdef USE_MPI
     108                 :            : #include "CGMReadParallel.hpp"
     109                 :            : #endif
     110                 :            : 
     111                 :            : #include "CGMApp.hpp"
     112                 :            : #include "GeometryModifyTool.hpp"
     113                 :            : #include "Surface.hpp"
     114                 :            : #include "BasicTopologyEntity.hpp"
     115                 :            : #include "CubitFile.hpp"
     116                 :            : #include "CubitDefines.h"
     117                 :            : #include "MergeTool.hpp"
     118                 :            : #include "GeometryDefines.h"
     119                 :            : 
     120                 :            : #define gqt GeometryQueryTool::instance()
     121                 :            : #define gmt GeometryModifyTool::instance()
     122                 :            : 
     123                 :            : const char *iGeom_entity_type_names[] = {"vertex", "curve", "surface", "body"};
     124                 :            : const char *cgm_type_names[] = {"vertex", "curve", "surface", "volume", "body"};
     125                 :            : 
     126                 :            : // Implement RAII pattern for allocated arrays
     127                 :            : class iGeomArrayManager
     128                 :            : {
     129                 :            :   void** arrayPtr;
     130                 :            : 
     131                 :            : public:
     132                 :            : 
     133                 :            : 
     134                 :       1959 :   iGeomArrayManager( void** array_ptr,
     135                 :            :                      int& array_allocated_space,
     136                 :            :                      int& array_size,
     137                 :            :                      int count,
     138                 :            :                      int val_size,
     139                 :       1959 :                      int* err ) : arrayPtr(0)
     140                 :            :   {
     141         [ +  + ]:       1959 :     if (!*array_ptr) {
     142                 :       1932 :       *array_ptr = malloc(val_size * count);
     143                 :       1932 :       array_allocated_space = array_size = count;
     144         [ -  + ]:       1932 :       if (!*array_ptr) {
     145                 :          0 :         ERROR(iBase_MEMORY_ALLOCATION_FAILED, "Couldn't allocate array.");
     146                 :            :       }
     147                 :       1932 :       arrayPtr = array_ptr;
     148                 :            :     }
     149                 :            :     else {
     150                 :         27 :       array_size = count;
     151         [ +  + ]:         27 :       if (array_allocated_space < count) {
     152                 :          1 :         ERROR(iBase_BAD_ARRAY_DIMENSION, 
     153                 :            :           "Allocated array not large enough to hold returned contents.");
     154                 :            :       }
     155                 :            :     }
     156                 :       1958 :     RETURN(iBase_SUCCESS);
     157                 :            :   }
     158                 :            :   
     159                 :       1959 :   ~iGeomArrayManager() 
     160                 :            :   {
     161         [ -  + ]:       1959 :     if (arrayPtr) {
     162                 :          0 :       free(*arrayPtr);
     163                 :          0 :       *arrayPtr = 0;
     164                 :            :     }
     165                 :       1959 :   }
     166                 :            :   
     167                 :       1958 :   void keep_array()
     168                 :       1958 :     { arrayPtr = 0; }
     169                 :            : };
     170                 :            : 
     171                 :            : 
     172                 :            : // declare private-type functions here, so they aren't visible outside
     173                 :            : // this implementation file
     174                 :            : 
     175                 :            : /* Helper functions 
     176                 :            :  * Declare these outside the 'extern "C"' block because they are not
     177                 :            :  * extern.
     178                 :            :  */
     179                 :            : static void
     180                 :            : iGeom_get_adjacent_entities( const RefEntity *from, 
     181                 :            :                              const int to_dim,
     182                 :            :                              DLIList<RefEntity*> &adj_ents,
     183                 :            :                              int* err);
     184                 :            : 
     185                 :            : static void tokenize( const std::string& str, 
     186                 :            :                       std::vector<std::string>& tokens );
     187                 :            : 
     188                 :            : // Expect option of the form "NAME=VALUE".
     189                 :            : // If NAME portion matches, pass back VALUE and return true.
     190                 :            : // Otherwise, leave 'value' unchanged and return false.
     191                 :            : static bool match_option( const std::string& opt,
     192                 :            :                           const char* name,
     193                 :            :                           std::string& value );
     194                 :            :                           
     195                 :            : static void
     196                 :            : iGeom_load_cub_geometry(const char *name, int* err) ;
     197                 :            : 
     198                 :            : static iBase_ErrorType 
     199                 :            : process_attribs(iGeom_Instance instance, DLIList<RefEntity*> &ref_list) ;
     200                 :            : 
     201                 :            : static void
     202                 :            : iGeom_get_adjacent_entities( const RefEntity *from, 
     203                 :            :                              const int to_dim,
     204                 :            :                              DLIList<RefEntity*> &adj_ents,
     205                 :            :                              int* err ) ;
     206                 :            : /* Common implementation for both single-entity and array functions. */
     207                 :            : static CubitStatus iGeom_closest_point( RefEntity* this_entity,
     208                 :            :                                         const CubitVector& near,
     209                 :            :                                         CubitVector& on );
     210                 :            : 
     211                 :            : static CubitStatus iGeom_closest_point_trimmed( RefEntity* this_entity,
     212                 :            :                                         const CubitVector& near,
     213                 :            :                                         CubitVector& on );
     214                 :            : 
     215                 :            : static CubitStatus
     216                 :            : iGeom_closest_point_and_normal( RefEntity* this_entity, 
     217                 :            :                                 const CubitVector& near,
     218                 :            :                                 CubitVector& on,
     219                 :            :                                 CubitVector& normal );
     220                 :            : static CubitStatus
     221                 :            : iGeom_bounding_box( RefEntity* entity, CubitVector& minc, CubitVector& maxc );
     222                 :            : 
     223                 :            : /** Smits' algorithm */
     224                 :            : /*
     225                 :            : static inline void box_min_max( double dir,
     226                 :            :                                 double min,
     227                 :            :                                 double max,
     228                 :            :                                 double pt,
     229                 :            :                                 double& tmin,
     230                 :            :                                 double& tmax );
     231                 :            : */
     232                 :            : /*
     233                 :            : static bool
     234                 :            : iBase_intersect_ray_box( const CubitBox& box,
     235                 :            :                          const CubitVector& point,
     236                 :            :                          const CubitVector& direction );
     237                 :            : */
     238                 :            : 
     239                 :            : static CubitStatus
     240                 :            : iGeom_fire_ray( const CubitVector& point,
     241                 :            :                 const CubitVector& direction,
     242                 :            :                 DLIList<RefEntity*>& entities,
     243                 :            :                 DLIList<double>& ray_params );
     244                 :            : 
     245                 :            : static RefEntity*
     246                 :            : iGeom_get_point_containment( const CubitVector& pt );
     247                 :            : 
     248                 :            : static int iGeom_get_nonmanifold_sense( const BasicTopologyEntity* child,
     249                 :            :                                         const BasicTopologyEntity* parent,
     250                 :            :                                         int* err );
     251                 :            : 
     252                 :            : static
     253                 :            : int iGeom_edge_vertex_sense( const RefEdge* cedge,
     254                 :            :                              const RefVertex* vtx1,
     255                 :            :                              const RefVertex* vtx2,
     256                 :            :                              int* err );
     257                 :            : 
     258                 :            : static int iGeom_is_parametric( RefEntity* entity );
     259                 :            : 
     260                 :            : static iBase_ErrorType
     261                 :            : iGeom_get_vtx_to_u(RefVertex* vertex, RefEdge* edge, double& u);
     262                 :            : 
     263                 :            : static iBase_ErrorType
     264                 :            : iGeom_get_vtx_to_uv(RefVertex* vertex, RefFace* face, double& u, double& uv);
     265                 :            : 
     266                 :            : 
     267                 :            : static CubitStatus
     268                 :            : iGeom_normal_from_uv( RefFace* face, double u, double v, CubitVector& normal );
     269                 :            : 
     270                 :            : static CubitStatus iGeom_is_periodic( RefEntity* entity, int& u, int& v );
     271                 :            : 
     272                 :            : static bool iGeom_is_face_degenerate( RefFace* face );
     273                 :            : 
     274                 :            : static
     275                 :            : int count_ibase_type( int ibase_type, 
     276                 :            :                       const DLIList<CubitEntity*>& list, 
     277                 :            :                       int* err );
     278                 :            : 
     279                 :            : static 
     280                 :            : void copy_ibase_type( int ibase_type, 
     281                 :            :                       const DLIList<CubitEntity*>& list,
     282                 :            :                       iBase_EntityHandle** entity_handles,
     283                 :            :                       int* entity_handles_alloc,
     284                 :            :                       int* entity_handles_size,
     285                 :            :                       int* err );
     286                 :            : 
     287                 :            : static 
     288                 :            : void append_ibase_type( int ibase_type, 
     289                 :            :                         const DLIList<CubitEntity*>& source_list,
     290                 :            :                         DLIList<RefEntity*>& target_list,
     291                 :            :                         int* err );
     292                 :            : static 
     293                 :            : void append_all_ibase_type( int ibase_type, 
     294                 :            :                             DLIList<RefEntity*>& target_list,
     295                 :            :                             int* err );
     296                 :            : 
     297                 :            : /*
     298                 :            : static
     299                 :            : CubitStatus iGeom_get_graphics(RefFace* face, 
     300                 :            :                                DLIList<CubitVector*>& point_list,
     301                 :            :                                DLIList<int>& facet_list,
     302                 :            :                                double normal_tolerance = 15.0,
     303                 :            :                                double distance_tolerance = 0.0,
     304                 :            :                                double longest_edge = 0.0) ;
     305                 :            : 
     306                 :            : static
     307                 :            : CubitStatus iGeom_get_graphics(RefEdge* edge,
     308                 :            :                                DLIList<CubitVector*>& point_list,
     309                 :            :                                DLIList<int>& facet_list,
     310                 :            :                                double angle_tolerance = 0.0,
     311                 :            :                                double distance_tolerance=0.0 ) ;
     312                 :            : 
     313                 :            : static CubitStatus iGeom_get_graphics(RefFace* face,
     314                 :            :                                DLIList<CubitVector*>& point_list,
     315                 :            :                                DLIList<int>& facet_list,
     316                 :            :                                double normal_tolerance, 
     317                 :            :                                double distance_tolerance,
     318                 :            :                                double longest_edge)
     319                 :            : {
     320                 :            :   CubitStatus status = CUBIT_SUCCESS;
     321                 :            :   GMem facets;
     322                 :            :   face->get_graphics(facets, normal_tolerance, distance_tolerance, longest_edge);
     323                 :            :   int num_points = 0, num_facets = 0;
     324                 :            :   num_points = facets.point_list_size();
     325                 :            :   num_facets = facets.facet_list_size();
     326                 :            :   GPoint* points = facets.point_list();
     327                 :            :   int*  facet_array = facets.facet_list();
     328                 :            :   for(int i = 0; i < num_points; i++)
     329                 :            :   {
     330                 :            :     CubitVector point(points[i].x, points[i].y, points[i].z);
     331                 :            :     point_list.append(&point);
     332                 :            :   }
     333                 :            :   for(int i = 0; i < num_facets; i++)
     334                 :            :     facet_list.append(facet_array[i]);
     335                 :            :   return status;
     336                 :            : }
     337                 :            : 
     338                 :            : static CubitStatus iGeom_get_graphics(RefEdge* edge,
     339                 :            :                                DLIList<CubitVector*>& point_list,
     340                 :            :                                DLIList<int>& facet_list,
     341                 :            :                                double angle_tolerance,
     342                 :            :                                double distance_tolerance )
     343                 :            : {
     344                 :            :   CubitStatus status = CUBIT_SUCCESS;
     345                 :            :   GMem facets;
     346                 :            :   edge->get_graphics(facets, angle_tolerance, distance_tolerance);
     347                 :            :   int num_points = 0, num_facets = 0;
     348                 :            :   num_points = facets.point_list_size();
     349                 :            :   num_facets = facets.facet_list_size();
     350                 :            :   GPoint* points = facets.point_list();
     351                 :            :   int*  facet_array = facets.facet_list();
     352                 :            :   for(int i = 0; i < num_points; i++)
     353                 :            :   {
     354                 :            :     CubitVector point(points[i].x, points[i].y, points[i].z);
     355                 :            :     point_list.append(&point);
     356                 :            :   }
     357                 :            :   for(int i = 0; i < num_facets; i++)
     358                 :            :     facet_list.append(facet_array[i]);
     359                 :            :   return status;
     360                 :            : }
     361                 :            : */
     362                 :            : 
     363                 :          4 : static CubitStatus init_cgm( const std::string& engine )
     364                 :            : {
     365                 :          4 :   CubitStatus status = CUBIT_SUCCESS;
     366         [ +  + ]:          4 :   if (engine.empty())
     367                 :          1 :     status = InitCGMA::initialize_cgma();
     368                 :            :   else
     369                 :          3 :     status = InitCGMA::initialize_cgma( engine.c_str() );
     370                 :            :  
     371                 :            : // sometimes can't have following, depending on CGM version
     372                 :            :   // CGMApp::instance()->attrib_manager()->silent_flag(true);
     373                 :            : 
     374                 :          4 :   CGMApp::instance()->attrib_manager()->auto_flag(true);
     375                 :            :   
     376                 :          4 :   return status;
     377                 :            : }
     378                 :            : 
     379                 :            : extern "C" {
     380                 :            : 
     381                 :            : #ifdef ITAPS_SHIM
     382                 :            : static struct iGeom_vtable CGM_iGeom_vtable = {
     383                 :            :   iGeom_getDescription,
     384                 :            :   iGeom_getErrorType,
     385                 :            :   iGeom_dtor,
     386                 :            :   iGeom_load,
     387                 :            :   iGeom_save,
     388                 :            :   iGeom_getRootSet,
     389                 :            :   iGeom_getBoundBox,
     390                 :            :   iGeom_getEntities,
     391                 :            :   iGeom_getNumOfType,
     392                 :            :   iGeom_getEntType,
     393                 :            :   iGeom_getArrType,
     394                 :            :   iGeom_getEntAdj,
     395                 :            :   iGeom_getArrAdj,
     396                 :            :   iGeom_getEnt2ndAdj,
     397                 :            :   iGeom_getArr2ndAdj,
     398                 :            :   iGeom_isEntAdj,
     399                 :            :   iGeom_isArrAdj,
     400                 :            :   iGeom_getTopoLevel,
     401                 :            :   iGeom_getEntClosestPt,
     402                 :            :   iGeom_getEntClosestPtTrimmed,
     403                 :            :   iGeom_getArrClosestPt,
     404                 :            :   iGeom_getEntNrmlXYZ,
     405                 :            :   iGeom_getArrNrmlXYZ,
     406                 :            :   iGeom_getEntNrmlPlXYZ,
     407                 :            :   iGeom_getArrNrmlPlXYZ,
     408                 :            :   iGeom_getEntTgntXYZ,
     409                 :            :   iGeom_getArrTgntXYZ,
     410                 :            :   iGeom_getFcCvtrXYZ,
     411                 :            :   iGeom_getEgCvtrXYZ,
     412                 :            :   iGeom_getEntArrCvtrXYZ,
     413                 :            :   iGeom_getEgEvalXYZ,
     414                 :            :   iGeom_getFcEvalXYZ,
     415                 :            :   iGeom_getArrEgEvalXYZ,
     416                 :            :   iGeom_getArrFcEvalXYZ,
     417                 :            :   iGeom_getEntBoundBox,
     418                 :            :   iGeom_getArrBoundBox,
     419                 :            :   iGeom_getVtxCoord,
     420                 :            :   iGeom_getVtxArrCoords,
     421                 :            :   iGeom_getPntRayIntsct,
     422                 :            :   iGeom_getPntArrRayIntsct,
     423                 :            :   iGeom_getPntClsf,
     424                 :            :   iGeom_getPntArrClsf,
     425                 :            :   iGeom_getEntNrmlSense,
     426                 :            :   iGeom_getArrNrmlSense,
     427                 :            :   iGeom_getEgFcSense,
     428                 :            :   iGeom_getEgFcArrSense,
     429                 :            :   iGeom_getEgVtxSense,
     430                 :            :   iGeom_getEgVtxArrSense,
     431                 :            :   iGeom_measure,
     432                 :            :   iGeom_getFaceType,
     433                 :            :   iGeom_getParametric,
     434                 :            :   iGeom_isEntParametric,
     435                 :            :   iGeom_isArrParametric,
     436                 :            :   iGeom_getEntUVtoXYZ,
     437                 :            :   iGeom_getArrUVtoXYZ,
     438                 :            :   iGeom_getEntUtoXYZ,
     439                 :            :   iGeom_getArrUtoXYZ,
     440                 :            :   iGeom_getEntXYZtoUV,
     441                 :            :   iGeom_getEntXYZtoU,
     442                 :            :   iGeom_getArrXYZtoUV,
     443                 :            :   iGeom_getArrXYZtoU,
     444                 :            :   iGeom_getEntXYZtoUVHint,
     445                 :            :   iGeom_getArrXYZtoUVHint,
     446                 :            :   iGeom_getEntUVRange,
     447                 :            :   iGeom_getEntURange,
     448                 :            :   iGeom_getArrUVRange,
     449                 :            :   iGeom_getArrURange,
     450                 :            :   iGeom_getEntUtoUV,
     451                 :            :   iGeom_getVtxToUV,
     452                 :            :   iGeom_getVtxToU,
     453                 :            :   iGeom_getArrUtoUV,
     454                 :            :   iGeom_getVtxArrToUV,
     455                 :            :   iGeom_getVtxArrToU,
     456                 :            :   iGeom_getEntNrmlUV,
     457                 :            :   iGeom_getArrNrmlUV,
     458                 :            :   iGeom_getEntTgntU,
     459                 :            :   iGeom_getArrTgntU,
     460                 :            :   iGeom_getEnt1stDrvt,
     461                 :            :   iGeom_getArr1stDrvt,
     462                 :            :   iGeom_getEnt2ndDrvt,
     463                 :            :   iGeom_getArr2ndDrvt,
     464                 :            :   iGeom_getFcCvtrUV,
     465                 :            :   iGeom_getFcArrCvtrUV,
     466                 :            :   iGeom_isEntPeriodic,
     467                 :            :   iGeom_isArrPeriodic,
     468                 :            :   iGeom_isFcDegenerate,
     469                 :            :   iGeom_isFcArrDegenerate,
     470                 :            :   iGeom_getTolerance,
     471                 :            :   iGeom_getEntTolerance,
     472                 :            :   iGeom_getArrTolerance,
     473                 :            :   iGeom_initEntIter,
     474                 :            :   iGeom_initEntArrIter,
     475                 :            :   iGeom_getNextEntIter,
     476                 :            :   iGeom_getNextEntArrIter,
     477                 :            :   iGeom_resetEntIter,
     478                 :            :   iGeom_resetEntArrIter,
     479                 :            :   iGeom_endEntIter,
     480                 :            :   iGeom_endEntArrIter,
     481                 :            :   iGeom_copyEnt,
     482                 :            :   iGeom_sweepEntAboutAxis,
     483                 :            :   iGeom_deleteAll,
     484                 :            :   iGeom_deleteEnt,
     485                 :            :   iGeom_createSphere,
     486                 :            :   iGeom_createPrism,
     487                 :            :   iGeom_createBrick,
     488                 :            :   iGeom_createCylinder,
     489                 :            :   iGeom_createCone,
     490                 :            :   iGeom_createTorus,
     491                 :            :   iGeom_moveEnt,
     492                 :            :   iGeom_rotateEnt,
     493                 :            :   iGeom_reflectEnt,
     494                 :            :   iGeom_scaleEnt,
     495                 :            :   iGeom_uniteEnts,
     496                 :            :   iGeom_subtractEnts,
     497                 :            :   iGeom_intersectEnts,
     498                 :            :   iGeom_sectionEnt,
     499                 :            :   iGeom_imprintEnts,
     500                 :            :   iGeom_mergeEnts,
     501                 :            :   iGeom_createEntSet,
     502                 :            :   iGeom_destroyEntSet,
     503                 :            :   iGeom_isList,
     504                 :            :   iGeom_getNumEntSets,
     505                 :            :   iGeom_getEntSets,
     506                 :            :   iGeom_addEntToSet,
     507                 :            :   iGeom_rmvEntFromSet,
     508                 :            :   iGeom_addEntArrToSet,
     509                 :            :   iGeom_rmvEntArrFromSet,
     510                 :            :   iGeom_addEntSet,
     511                 :            :   iGeom_rmvEntSet,
     512                 :            :   iGeom_isEntContained,
     513                 :            :   iGeom_isEntArrContained,
     514                 :            :   iGeom_isEntSetContained,
     515                 :            :   iGeom_addPrntChld,
     516                 :            :   iGeom_rmvPrntChld,
     517                 :            :   iGeom_isChildOf,
     518                 :            :   iGeom_getNumChld,
     519                 :            :   iGeom_getNumPrnt,
     520                 :            :   iGeom_getChldn,
     521                 :            :   iGeom_getPrnts,
     522                 :            :   iGeom_createTag,
     523                 :            :   iGeom_destroyTag,
     524                 :            :   iGeom_getTagName,
     525                 :            :   iGeom_getTagSizeValues,
     526                 :            :   iGeom_getTagSizeBytes,
     527                 :            :   iGeom_getTagHandle,
     528                 :            :   iGeom_getTagType,
     529                 :            :   iGeom_setEntSetData,
     530                 :            :   iGeom_setEntSetIntData,
     531                 :            :   iGeom_setEntSetDblData,
     532                 :            :   iGeom_setEntSetEHData,
     533                 :            :   iGeom_setEntSetESHData,
     534                 :            :   iGeom_getEntSetData,
     535                 :            :   iGeom_getEntSetIntData,
     536                 :            :   iGeom_getEntSetDblData,
     537                 :            :   iGeom_getEntSetEHData,
     538                 :            :   iGeom_getEntSetESHData,
     539                 :            :   iGeom_getAllEntSetTags,
     540                 :            :   iGeom_rmvEntSetTag,
     541                 :            :   iGeom_getArrData,
     542                 :            :   iGeom_getIntArrData,
     543                 :            :   iGeom_getDblArrData,
     544                 :            :   iGeom_getEHArrData,
     545                 :            :   iGeom_getESHArrData,
     546                 :            :   iGeom_setArrData,
     547                 :            :   iGeom_setIntArrData,
     548                 :            :   iGeom_setDblArrData,
     549                 :            :   iGeom_setEHArrData,
     550                 :            :   iGeom_setESHArrData,
     551                 :            :   iGeom_rmvArrTag,
     552                 :            :   iGeom_getData,
     553                 :            :   iGeom_getIntData,
     554                 :            :   iGeom_getDblData,
     555                 :            :   iGeom_getEHData,
     556                 :            :   iGeom_getESHData,
     557                 :            :   iGeom_setData,
     558                 :            :   iGeom_setIntData,
     559                 :            :   iGeom_setDblData,
     560                 :            :   iGeom_setEHData,
     561                 :            :   iGeom_setESHData,
     562                 :            :   iGeom_getAllTags,
     563                 :            :   iGeom_rmvTag,
     564                 :            :   iGeom_subtract,
     565                 :            :   iGeom_intersect,
     566                 :            :   iGeom_unite,
     567                 :            :   iGeom_getFacets
     568                 :            : };
     569                 :            : 
     570                 :            : void CGM_iGeom_register()
     571                 :            : {
     572                 :            :   iGeom_register("cgm", iGeom_newGeom);
     573                 :            : }
     574                 :            : #endif
     575                 :            : 
     576                 :            : 
     577                 :            : ITAPS_API void
     578                 :         12 : iGeom_getErrorType( iGeom_Instance geom,
     579                 :            :                     int *error_type )
     580                 :            : {
     581                 :         12 :   *error_type = CGM_iGeom_getLastErrorType();
     582                 :         12 : }
     583                 :            : 
     584                 :            : ITAPS_API void
     585                 :          2 : iGeom_getDescription( iGeom_Instance geom,
     586                 :            :                       char* description_buffer,
     587                 :            :                       int description_buffer_length )
     588                 :            : {
     589                 :          2 :   CGM_iGeom_getLastErrorDesc(description_buffer, description_buffer_length);
     590                 :          2 : }
     591                 :            : 
     592                 :            : ITAPS_API void
     593                 :          5 : iGeom_newGeom( const char* options,
     594                 :            :                iGeom_Instance* instance_out,
     595                 :            :                int* err,
     596                 :            :                const int options_size ) 
     597                 :            : {
     598                 :            :     // scan options for default engine option
     599         [ +  - ]:          5 :   std::string engine;
     600 [ +  + ][ +  - ]:          5 :   if (options && options_size) {
     601         [ +  - ]:          4 :     std::string tmp(options, options_size);
     602         [ +  - ]:          4 :     char f[] = ";engine="; f[0]=tmp[0]; // correct delimiter
     603         [ +  - ]:          4 :     size_t p = tmp.find( f );
     604         [ +  - ]:          4 :     if (p != std::string::npos) { // if we found engine option
     605                 :          4 :       p += strlen(f); // advance to value (past '=')
     606 [ +  - ][ +  - ]:          4 :       size_t e = tmp.find( tmp[0], p ); // find end delimiter
     607         [ +  - ]:          4 :       if (e == std::string::npos) // if no end delim, then must be last option
     608 [ +  - ][ +  - ]:          4 :         engine = tmp.substr( p, std::string::npos );
                 [ +  - ]
     609                 :            :       else
     610 [ #  # ][ #  # ]:          4 :         engine = tmp.substr( p, e-p );
                 [ #  # ]
     611         [ +  - ]:          4 :     }
     612                 :            :   }
     613                 :            :   
     614                 :            :     // initialize static var with result so that call happens only once
     615 [ +  + ][ +  - ]:          5 :   static const CubitStatus status = init_cgm( engine );
         [ +  - ][ #  # ]
     616                 :            :     // but check the result for every call
     617         [ -  + ]:          5 :   if (CUBIT_SUCCESS != status)
     618         [ #  # ]:          0 :     RETURN (iBase_FAILURE);
     619                 :            : 
     620                 :            :     // return the tagmanager as the instance
     621                 :            : #ifdef ITAPS_SHIM
     622                 :            :   CGMTagManager::instance().vtable = &CGM_iGeom_vtable;
     623                 :            : #endif
     624         [ +  - ]:          5 :   *instance_out = reinterpret_cast<iGeom_Instance>(&CGMTagManager::instance());
     625 [ +  - ][ +  - ]:          5 :   RETURN(iBase_SUCCESS);
     626                 :            : }
     627                 :            : 
     628                 :            : 
     629                 :            : ITAPS_API void
     630                 :          2 : iGeom_dtor( iGeom_Instance instance,
     631                 :            :             int* err ) 
     632                 :            : {
     633         [ -  + ]:          2 :   if (NULL == TM) 
     634                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "NUll Instance");
     635                 :            :   
     636                 :            :     // delete TM;
     637                 :            :   
     638                 :            :     // shut down CGM
     639                 :          2 :   CGMApp::instance()->shutdown();
     640                 :            : 
     641                 :          2 :   RETURN(iBase_SUCCESS);
     642                 :            : }
     643                 :            :   
     644                 :            : // user defined non-static methods:
     645                 :            : /**
     646                 :            :  * Load a model specified by name. Which formats are supported and the
     647                 :            :  * specific meaning of this name string (e.g. file name, model name,
     648                 :            :  * etc.) are implementation-dependent.  Options are also implementation-
     649                 :            :  * dependent.
     650                 :            :  * @param name Name of the model
     651                 :            :  * @param options String options 
     652                 :            :  */
     653                 :            : ITAPS_API void
     654                 :          7 : iGeom_load( iGeom_Instance instance,
     655                 :            :             /*in*/ const char *name,
     656                 :            :             /*in*/ const char *options,
     657                 :            :             int* err,
     658                 :            :             int name_len,
     659                 :            :             int options_size )
     660                 :            : {
     661                 :            :   // pre-get all entities, so we can filter them out later; use cubit list
     662                 :            :   // 'cuz we need to get both volumes and bodies
     663 [ +  - ][ +  - ]:         14 :   DLIList<RefEntity*> ref_list, tmp_ref_list;
                 [ +  - ]
     664         [ +  + ]:         42 :   for (int dim = 0; dim < 5; dim++) {
     665                 :            :     // Using a temporary since GeometryQueryTool::ref_entity_list cleans out
     666                 :            :     // the list before appending to it
     667 [ +  - ][ +  - ]:         35 :     gqt->ref_entity_list(cgm_type_names[dim], tmp_ref_list, false);
     668         [ +  - ]:         35 :     ref_list += tmp_ref_list;
     669                 :            :   }
     670                 :            : 
     671                 :            :    // make sure we have a null-terminated string for file name
     672 [ +  - ][ +  - ]:         14 :   std::string file_name( name, name_len );
     673         [ +  - ]:          7 :   name = file_name.c_str();
     674                 :            : 
     675                 :            :   // check if work in parallel
     676                 :          7 :   bool parallel = false;
     677 [ +  - ][ +  - ]:         14 :   std::string parallel_opt;
     678 [ +  - ][ +  - ]:         14 :   std::vector<std::string> opts;
     679 [ +  - ][ +  - ]:         14 :   std::string tmp_options(options, options_size);
     680         [ +  - ]:          7 :   tmp_options.insert(0, ";");
     681         [ +  - ]:          7 :   tokenize(tmp_options, opts );
     682 [ +  - ][ #  # ]:          7 :   for (std::vector<std::string>::iterator i = opts.begin(); i != opts.end(); ++i)
         [ +  - ][ +  - ]
                 [ -  + ]
     683                 :            :   {
     684 [ #  # ][ #  # ]:          0 :     if (match_option( *i, "PARALLEL", parallel_opt )) parallel = true;
                 [ #  # ]
     685                 :            :   }
     686                 :            :   
     687                 :            :   // parallel
     688         [ +  - ]:          7 :   if (parallel) {
     689                 :            : #ifdef USE_MPI
     690                 :            :     CGMParallelComm* p_comm = new CGMParallelComm();
     691                 :            :     CGMReadParallel* p_reader = new CGMReadParallel(GeometryQueryTool::instance(), p_comm);
     692                 :            :     CubitStatus status = p_reader->load_file(name, options);
     693                 :            :     if (CUBIT_SUCCESS != status) {
     694                 :            :       ERROR(iBase_FAILURE, "Trouble loading geometry file in parallel.");
     695                 :            :     }
     696                 :            : #endif
     697                 :            :   }
     698                 :            :   else {
     699                 :          7 :     CubitStatus status = CUBIT_SUCCESS;
     700                 :            :     
     701                 :            : 
     702         [ +  - ]:          7 :       std::string file_type;
     703   [ +  +  +  - ]:         13 :       if (strstr(name, ".brep") != NULL ||
     704         [ +  - ]:         12 :           strstr(name, ".BREP") != NULL ||
     705         [ -  + ]:         12 :           strstr(name, ".occ") != NULL ||
     706                 :          6 :           strstr(name, ".OCC") != NULL)
     707         [ +  - ]:          1 :         file_type = "OCC";
     708   [ +  +  +  - ]:          7 :       else if (strstr(name, ".stp") != NULL ||
     709         [ -  + ]:          2 :                strstr(name, ".STP") != NULL ||
     710         [ #  # ]:          1 :                strstr(name, ".step") != NULL ||
     711                 :          0 :                strstr(name, ".STEP") != NULL)
     712         [ +  - ]:          6 :         file_type = "STEP";
     713   [ #  #  #  # ]:          0 :       else if (strstr(name, ".igs") != NULL ||
     714         [ #  # ]:          0 :                strstr(name, ".IGS") != NULL ||
     715         [ #  # ]:          0 :                strstr(name, ".iges") != NULL ||
     716                 :          0 :                strstr(name, ".IGES") != NULL)
     717         [ #  # ]:          0 :         file_type = "IGES";
     718                 :            :       
     719                 :            : 
     720 [ +  - ][ +  - ]:          7 :       status = CubitCompat_import_solid_model(name, file_type.c_str());
     721                 :            : 
     722         [ -  + ]:          7 :       if (CUBIT_SUCCESS != status) {
     723 [ #  # ][ +  - ]:          7 :         ERROR(iBase_FILE_NOT_FOUND, "Trouble loading geometry file.");
                 [ +  - ]
     724                 :            : 
     725                 :          7 :     }
     726                 :            :   }
     727                 :            : 
     728 [ +  - ][ +  - ]:         14 :   DLIList<RefEntity*> ref_list_2;
     729         [ +  + ]:         42 :   for (int dim = 0; dim < 5; dim++) {
     730                 :            :     // Using a temporary since GeometryQueryTool::ref_entity_list cleans out
     731                 :            :     // the list before appending to it
     732 [ +  - ][ +  - ]:         35 :     gqt->ref_entity_list(cgm_type_names[dim], tmp_ref_list, false);
     733         [ +  - ]:         35 :     ref_list_2 += tmp_ref_list;
     734                 :            :   }
     735                 :            : 
     736         [ +  - ]:          7 :   ref_list_2 -= ref_list;
     737                 :            :   
     738                 :            :     // now process uncaught/unregistered attributes
     739         [ +  - ]:          7 :   iBase_ErrorType result = process_attribs(instance, ref_list_2);
     740                 :            : 
     741 [ +  - ][ +  - ]:         14 :   RETURN(result);
     742                 :            : }
     743                 :            : 
     744                 :            : // user defined non-static methods:
     745                 :            : /**
     746                 :            :  * Save a model to file specified by name. Which formats are supported and the
     747                 :            :  * specific meaning of this name string (e.g. file name, model name,
     748                 :            :  * etc.) are implementation-dependent.  Options are also implementation-
     749                 :            :  * dependent.
     750                 :            :  * @param name Name of the model
     751                 :            :  * @param options String options 
     752                 :            :  */
     753                 :            : ITAPS_API void
     754                 :          2 : iGeom_save( iGeom_Instance instance,
     755                 :            :             /*in*/ const char *name,
     756                 :            :             /*in*/ const char* options,
     757                 :            :             int* err,
     758                 :            :             int name_len,
     759                 :            :             int options_len )
     760                 :            : {
     761                 :            :     // make sure strings are null terminated
     762         [ +  - ]:          2 :   std::string name_buf(name, name_len);
     763         [ +  - ]:          2 :   name = name_buf.c_str();
     764                 :            :   
     765                 :            :     // parse options
     766 [ +  - ][ +  - ]:          4 :   std::string file_type;
     767 [ +  - ][ +  - ]:          4 :   std::vector<std::string> opts;
     768 [ +  - ][ +  - ]:          2 :   tokenize( std::string(options, options_len), opts );
                 [ +  - ]
     769 [ +  - ][ #  # ]:          2 :   for (std::vector<std::string>::iterator i = opts.begin(); i != opts.end(); ++i)
         [ +  - ][ +  - ]
                 [ -  + ]
     770                 :            :   {
     771 [ #  # ][ #  # ]:          0 :     if (!match_option( *i, "TYPE", file_type )) //
                 [ #  # ]
     772 [ #  # ][ #  # ]:          0 :       ERROR( iBase_INVALID_ARGUMENT, i->c_str() );
                 [ #  # ]
     773                 :            :   }
     774                 :            : 
     775                 :            :     // if no type, check file type for known extensions
     776 [ +  - ][ +  - ]:          2 :   if (file_type.empty()) {
     777         [ +  - ]:          2 :     size_t name_len = name_buf.length();
     778 [ +  - ][ +  - ]:          6 :     if (name_buf.find(".igs") < name_len ||
                 [ -  + ]
     779 [ +  - ][ +  - ]:          4 :         name_buf.find(".IGS") < name_len ||
     780 [ +  - ][ +  - ]:          6 :         name_buf.find(".iges") < name_len ||
                 [ -  + ]
     781         [ +  - ]:          2 :         name_buf.find(".IGES") < name_len)
     782         [ #  # ]:          0 :       file_type = "IGES";
     783 [ +  - ][ +  - ]:          6 :     else if (name_buf.find(".stp") < name_len ||
                 [ -  + ]
     784 [ +  - ][ +  - ]:          4 :              name_buf.find(".STP") < name_len ||
     785 [ +  - ][ +  - ]:          6 :              name_buf.find(".step") < name_len ||
                 [ -  + ]
     786         [ +  - ]:          2 :              name_buf.find(".STEP") < name_len)
     787         [ #  # ]:          0 :       file_type = "STEP";
     788 [ +  - ][ #  # ]:          4 :     else if (name_buf.find(".occ") < name_len ||
                 [ +  - ]
     789 [ #  # ][ #  # ]:          0 :              name_buf.find(".brep") < name_len ||
     790 [ -  + ][ #  # ]:          2 :              name_buf.find(".OCC") < name_len ||
                 [ #  # ]
     791         [ #  # ]:          0 :              name_buf.find(".BREP") < name_len)
     792         [ +  - ]:          2 :       file_type = "OCC";
     793                 :            :     else
     794         [ #  # ]:          2 :       ERROR(iBase_FAILURE, "Unknown geometry file extension and no file type.");
     795                 :            :   }
     796                 :            :   
     797                 :            :   /** 
     798                 :            :    * Work around QueryEngine log file handling bug:
     799                 :            :    * If the export format is iges or step, be sure the log file name is not null
     800                 :            :    */
     801                 :          2 :   const char* logfile_name = NULL;
     802 [ +  - ][ -  + ]:          2 :   if( file_type == "IGES" ){
     803                 :          0 :     logfile_name = "igeom_iges_export.log";
     804                 :            :   }
     805 [ +  - ][ -  + ]:          2 :   else if( file_type == "STEP" ){
     806                 :          0 :     logfile_name = "igeom_step_export.log";
     807                 :            :   }
     808                 :            : 
     809                 :            :     // process options (none right now...)
     810 [ +  - ][ +  - ]:          4 :   DLIList<RefEntity*> bodies;
     811                 :            :   int num_ents_exported;
     812 [ +  - ][ +  - ]:          4 :   CubitString cubit_version(" (iGeom)");
     813                 :            :   CubitStatus status = CubitCompat_export_solid_model(bodies, name, file_type.c_str(),
     814 [ +  - ][ +  - ]:          2 :                                                num_ents_exported, cubit_version, logfile_name );
     815         [ -  + ]:          2 :   if (CUBIT_SUCCESS != status) 
     816         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Trouble saving geometry file.");
     817                 :            : 
     818 [ +  - ][ +  - ]:          4 :   RETURN(iBase_SUCCESS);
     819                 :            : }
     820                 :            : 
     821                 :            : ITAPS_API void
     822                 :         14 : iGeom_getRootSet( iGeom_Instance,
     823                 :            :                   iBase_EntitySetHandle* root,
     824                 :            :                   int* err )
     825                 :            : {
     826                 :         14 :   *root = NULL;
     827                 :         14 :   RETURN(iBase_SUCCESS);
     828                 :            : }
     829                 :            : 
     830                 :            : 
     831                 :            : ITAPS_API void
     832                 :          0 : iGeom_getBoundBox( iGeom_Instance,
     833                 :            :                    double* min_x,
     834                 :            :                    double* min_y,
     835                 :            :                    double* min_z,
     836                 :            :                    double* max_x,
     837                 :            :                    double* max_y,
     838                 :            :                    double* max_z,
     839                 :            :                    int* err ) 
     840                 :            : {
     841 [ #  # ][ #  # ]:          0 :   CubitBox box = GeometryQueryTool::instance()->model_bounding_box();
     842         [ #  # ]:          0 :   *min_x = box.min_x();
     843         [ #  # ]:          0 :   *min_y = box.min_y();
     844         [ #  # ]:          0 :   *min_z = box.min_z();
     845         [ #  # ]:          0 :   *max_x = box.max_x();
     846         [ #  # ]:          0 :   *max_y = box.max_y();
     847         [ #  # ]:          0 :   *max_z = box.max_z();
     848 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
     849                 :            : }
     850                 :            : 
     851                 :            : 
     852                 :            : /**
     853                 :            :  * Initialize an iterator over gentities of a specified dimension.
     854                 :            :  * @param gentity_dimension Dimension of gentities to be iterated over
     855                 :            :  * @param gentity_iterator Iterator initialized by this function
     856                 :            :  */
     857                 :            : 
     858                 :            : ITAPS_API void
     859                 :          0 : iGeom_initEntIter( iGeom_Instance instance,
     860                 :            :                    iBase_EntitySetHandle entity_set_handle,
     861                 :            :                    const int dimension,
     862                 :            :                    iBase_EntityIterator *iterator,
     863                 :            :                    int* err )
     864                 :            : {
     865                 :            :   iGeom_initEntArrIter( instance, entity_set_handle, dimension, 1, 
     866                 :            :                         reinterpret_cast<iBase_EntityArrIterator*>(iterator), 
     867                 :          0 :                         err );
     868                 :          0 : }
     869                 :            : 
     870                 :            : ITAPS_API void
     871                 :          0 : iGeom_initEntArrIter( iGeom_Instance instance,
     872                 :            :                       /*in*/ iBase_EntitySetHandle entity_set_handle,
     873                 :            :                       /*in*/ int type,
     874                 :            :                       /*in*/ int requested_array_size,
     875                 :            :                       /*out*/ iBase_EntityArrIterator* entArr_iterator,
     876                 :            :                       int* err )
     877                 :            : {
     878         [ #  # ]:          0 :   DLIList<RefEntity*> entities;
     879         [ #  # ]:          0 :   if (RefGroup* group = reinterpret_cast<RefGroup*>(entity_set_handle)) {
     880         [ #  # ]:          0 :     DLIList<CubitEntity*> centities;
     881         [ #  # ]:          0 :     group->get_child_entities( centities );
     882 [ #  # ][ #  # ]:          0 :     append_ibase_type( type, centities, entities, err );
     883                 :            :   }
     884                 :            :   else {
     885         [ #  # ]:          0 :     append_all_ibase_type( type, entities, err );
     886                 :            :   }
     887                 :            :   
     888         [ #  # ]:          0 :   if (*err == iBase_SUCCESS) {
     889 [ #  # ][ #  # ]:          0 :     CGMAIterator* iter = new CGMAIterator(entities, requested_array_size);
     890                 :          0 :     *entArr_iterator = reinterpret_cast<iBase_EntityArrIterator>(iter);
     891         [ #  # ]:          0 :   }
     892                 :          0 : }
     893                 :            : 
     894                 :            : 
     895                 :            : 
     896                 :            : /**
     897                 :            :  * Get the next entity for this iterator.
     898                 :            :  * @param gentity_iterator Iterator being iterated over
     899                 :            :  * @param gentity_handle Next gentity
     900                 :            :  * @return If true, there were more gentities, if false, the iterator was
     901                 :            :  *         already at the end.
     902                 :            :  */
     903                 :            : ITAPS_API void
     904                 :          0 : iGeom_getNextEntIter( iGeom_Instance instance,
     905                 :            :                       /*in*/ iBase_EntityIterator gentity_iterator,
     906                 :            :                       /*out*/ iBase_EntityHandle *gentity_handle,
     907                 :            :                       int* has_data,
     908                 :            :                       int* err )
     909                 :            : {
     910                 :          0 :   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator);
     911                 :          0 :   RefEntity** out_handle = reinterpret_cast<RefEntity**>(gentity_handle);
     912                 :          0 :   *has_data = !iterator->at_end();
     913         [ #  # ]:          0 :   if (*has_data) {
     914                 :          0 :     int count = 1;
     915         [ #  # ]:          0 :     iterator->next( out_handle, count );
     916                 :            :   }
     917                 :          0 :   RETURN(iBase_SUCCESS);
     918                 :            : }
     919                 :            : 
     920                 :            : 
     921                 :            : ITAPS_API void
     922                 :          0 : iGeom_getNextEntArrIter( iGeom_Instance instance,
     923                 :            :                          /*in*/ iBase_EntityArrIterator entArr_iterator,
     924                 :            :                          /*inout*/ iBase_EntityHandle **entity_handles,
     925                 :            :                          int *entity_handles_allocated,
     926                 :            :                          int *entity_handles_size,
     927                 :            :                          int* has_data,
     928                 :            :                          int* err )
     929                 :            : {
     930                 :          0 :   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(entArr_iterator);
     931                 :          0 :   *has_data = !iterator->at_end();
     932         [ #  # ]:          0 :   if (has_data) {
     933 [ #  # ][ #  # ]:          0 :     ALLOC_CHECK_ARRAY_NOFAIL(entity_handles, iterator->size());
         [ #  # ][ #  # ]
     934 [ #  # ][ #  # ]:          0 :     iterator->next( (RefEntity**)*entity_handles, *entity_handles_size );
                 [ #  # ]
     935                 :            :   }
     936                 :          0 :   RETURN(iBase_SUCCESS);
     937                 :            : }
     938                 :            : 
     939                 :            : 
     940                 :            : /**
     941                 :            :  * Reset an iterator back to the first gentity
     942                 :            :  * @param gentity_iterator Iterator reset by this function
     943                 :            :  */
     944                 :            : ITAPS_API void
     945                 :          0 : iGeom_resetEntIter( iGeom_Instance instance,
     946                 :            :                     /*in*/ iBase_EntityIterator gentity_iterator,
     947                 :            :                     int* err )
     948                 :            : {
     949                 :          0 :   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator);
     950                 :          0 :   iterator->reset();
     951                 :          0 :   RETURN(iBase_SUCCESS);
     952                 :            : }
     953                 :            : 
     954                 :            : ITAPS_API void
     955                 :          0 : iGeom_resetEntArrIter( iGeom_Instance instance,
     956                 :            :                        /*in*/ iBase_EntityArrIterator gentity_iterator,
     957                 :            :                        int* err )
     958                 :            : {
     959                 :          0 :   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator);
     960                 :          0 :   iterator->reset();
     961                 :          0 :   RETURN(iBase_SUCCESS);
     962                 :            : }
     963                 :            : 
     964                 :            : /**
     965                 :            :  * Delete an iterator
     966                 :            :  * @param gentity_iterator Iterator deleted by this function
     967                 :            :  */
     968                 :            : ITAPS_API void
     969                 :          0 : iGeom_endEntIter( iGeom_Instance instance,
     970                 :            :                   /*in*/ iBase_EntityIterator gentity_iterator,
     971                 :            :                   int* err )
     972                 :            : {
     973                 :          0 :   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator);
     974         [ #  # ]:          0 :   delete iterator;
     975                 :          0 :   RETURN(iBase_SUCCESS);
     976                 :            : }
     977                 :            : 
     978                 :            : ITAPS_API void
     979                 :          0 : iGeom_endEntArrIter( iGeom_Instance instance,
     980                 :            :                      /*in*/ iBase_EntityArrIterator gentity_iterator,
     981                 :            :                      int* err )
     982                 :            : {
     983                 :          0 :   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator);
     984         [ #  # ]:          0 :   delete iterator;
     985                 :          0 :   RETURN(iBase_SUCCESS);
     986                 :            : }
     987                 :            : 
     988                 :            : /**
     989                 :            :  *   Returns true if the gentity_sets are related through a parent/child
     990                 :            :  *   relationship.
     991                 :            :  */
     992                 :            : ITAPS_API void
     993                 :          2 : iGeom_isChildOf( iGeom_Instance instance,
     994                 :            :                  /*in*/ iBase_EntitySetHandle parent_entity_set,
     995                 :            :                  /*in*/ iBase_EntitySetHandle child_entity_set,
     996                 :            :                  int* is_child,
     997                 :            :                  int* err )
     998                 :            : {
     999                 :            :   std::vector<RefGroup*> *par1, *ch1, *par2, *ch2;
    1000         [ +  - ]:          2 :   TM->pc_list(const_cast<RefGroup*>(SET_HANDLE(parent_entity_set)), par1, ch1, false);
    1001 [ +  + ][ +  - ]:          2 :   if (NULL == ch1 || ch1->empty()) {
         [ -  + ][ +  + ]
    1002                 :          1 :     *is_child = false;
    1003         [ +  - ]:          1 :     RETURN (iBase_SUCCESS);
    1004                 :            :   }
    1005         [ +  - ]:          1 :   TM->pc_list(const_cast<RefGroup*>(SET_HANDLE(child_entity_set)), par2, ch2, false);
    1006 [ +  - ][ +  - ]:          1 :   if (NULL == par2 || par2->empty()) {
         [ -  + ][ -  + ]
    1007                 :          0 :     *is_child = false;
    1008         [ #  # ]:          0 :     RETURN (iBase_SUCCESS);
    1009                 :            :   }
    1010                 :            :   
    1011                 :          1 :   const RefGroup *group1 = SET_HANDLE(parent_entity_set);
    1012                 :          1 :   const RefGroup *group2 = SET_HANDLE(child_entity_set);
    1013 [ +  - ][ +  - ]:          2 :   if ((std::find(ch1->begin(), ch1->end(), group2) != ch1->end())
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  -  
             #  #  #  # ]
    1014 [ -  + ][ #  # ]:          1 :       || (std::find(par2->begin(), par2->end(), group1) != par2->end()))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
                 [ -  + ]
           [ #  #  #  # ]
    1015                 :          1 :     *is_child = true;
    1016                 :            :   
    1017                 :          0 :   else *is_child = false;
    1018         [ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    1019                 :            : }
    1020                 :            : 
    1021                 :            : /**
    1022                 :            :  *   Recursively gets the children of this gentity_set up to num_hops
    1023                 :            :  *   levels; if num_hops is set to -1 all children are returned
    1024                 :            :  */
    1025                 :            : ITAPS_API void
    1026                 :          1 : iGeom_getChldn( iGeom_Instance instance,
    1027                 :            :                 /*in*/ iBase_EntitySetHandle from_entity_set,
    1028                 :            :                 /*in*/ const int num_hops,
    1029                 :            :                 /*inout*/ iBase_EntitySetHandle** entity_set_handles,
    1030                 :            :                 int* entity_set_handles_allocated,
    1031                 :            :                 int* entity_set_handles_size,
    1032                 :            :                 int* err )
    1033                 :            : {
    1034         [ +  - ]:          1 :   std::vector<RefGroup*> group_ptrs;
    1035                 :          1 :   const RefGroup *this_grp = SET_HANDLE(from_entity_set);
    1036         [ +  - ]:          1 :   TM->get_pc_groups(const_cast<RefGroup*>(this_grp), 1, num_hops, group_ptrs);
    1037 [ +  - ][ +  - ]:          2 :   ALLOC_CHECK_ARRAY_NOFAIL(entity_set_handles, group_ptrs.size());
         [ -  + ][ +  - ]
                 [ +  - ]
    1038                 :            : 
    1039         [ +  - ]:          1 :   iBase_EntitySetHandle* ent_arr = reinterpret_cast<iBase_EntitySetHandle*>(&group_ptrs[0]);
    1040 [ +  - ][ +  - ]:          1 :   std::copy( ent_arr, ent_arr + group_ptrs.size(), *entity_set_handles);
    1041                 :            :   
    1042 [ +  - ][ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    1043                 :            : }
    1044                 :            : 
    1045                 :            : /**
    1046                 :            :  *   Recursively gets the parents of this gentity_set up to num_hops
    1047                 :            :  *   levels; if num_hops is set to -1 all parents are returned
    1048                 :            :  */
    1049                 :            : ITAPS_API void
    1050                 :          1 : iGeom_getPrnts( iGeom_Instance instance,
    1051                 :            :                 /*in*/ iBase_EntitySetHandle from_entity_set,
    1052                 :            :                 /*in*/ const int num_hops,
    1053                 :            :                 /*inout*/ iBase_EntitySetHandle **entity_set_handles,
    1054                 :            :                 int *entity_set_handles_allocated,
    1055                 :            :                 int *entity_set_handles_size,
    1056                 :            :                 int* err )
    1057                 :            : {
    1058         [ +  - ]:          1 :   std::vector<RefGroup*> group_ptrs;
    1059                 :          1 :   const RefGroup *this_grp = SET_HANDLE(from_entity_set);
    1060         [ +  - ]:          1 :   TM->get_pc_groups(const_cast<RefGroup*>(this_grp), 0, num_hops, group_ptrs);
    1061 [ +  - ][ +  - ]:          2 :   ALLOC_CHECK_ARRAY_NOFAIL(entity_set_handles, group_ptrs.size());
         [ -  + ][ +  - ]
                 [ +  - ]
    1062                 :            : 
    1063         [ +  - ]:          1 :   iBase_EntitySetHandle* ent_arr = reinterpret_cast<iBase_EntitySetHandle*>(&group_ptrs[0]);
    1064 [ +  - ][ +  - ]:          1 :   std::copy( ent_arr, ent_arr + group_ptrs.size(), *entity_set_handles);
    1065 [ +  - ][ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    1066                 :            : }
    1067                 :            : 
    1068                 :            : /**
    1069                 :            :  *   Returns the number of immediate children in the gentity_set (one
    1070                 :            :  *   level down only)
    1071                 :            :  */
    1072                 :            : ITAPS_API void
    1073                 :          2 : iGeom_getNumChld( iGeom_Instance instance,
    1074                 :            :                   /*in*/ iBase_EntitySetHandle entity_set,
    1075                 :            :                   /*in*/ const int num_hops,
    1076                 :            :                   int* num_child, 
    1077                 :            :                   int* err )
    1078                 :            : {
    1079                 :            :     // HJK: num_hops has to be handled
    1080         [ -  + ]:          2 :   if (0 < num_hops) {
    1081                 :          0 :     ERROR(iBase_NOT_SUPPORTED, "Num_hops argument not yet supported.");
    1082                 :            :   }
    1083                 :            : 
    1084                 :          2 :   std::vector<RefGroup*> *my_children = TM->pc_list(const_cast<RefGroup*>(SET_HANDLE(entity_set)), 1, false);
    1085         [ +  - ]:          2 :   *num_child = my_children == NULL ? 0 : my_children->size();
    1086                 :          2 :   RETURN (iBase_SUCCESS);
    1087                 :            : }
    1088                 :            : 
    1089                 :            : /**
    1090                 :            :  *   Returns the number of immediate parents to the gentity_set (one
    1091                 :            :  *   level up only)
    1092                 :            :  */
    1093                 :            : ITAPS_API void
    1094                 :          1 : iGeom_getNumPrnt( iGeom_Instance instance,
    1095                 :            :                   /*in*/ iBase_EntitySetHandle entity_set,
    1096                 :            :                   /*in*/ const int num_hops,
    1097                 :            :                   int* num_parent,
    1098                 :            :                   int* err )
    1099                 :            : {
    1100                 :            :     // HJK: num_hops has to be handled
    1101         [ -  + ]:          1 :   if (0 < num_hops) {
    1102                 :          0 :     ERROR(iBase_NOT_SUPPORTED, "Num_hops argument not yet supported.");
    1103                 :            :   }
    1104                 :            : 
    1105                 :          1 :   std::vector<RefGroup*> *my_parents = TM->pc_list(const_cast<RefGroup*>(SET_HANDLE(entity_set)), 0, false);
    1106         [ +  - ]:          1 :   *num_parent = my_parents == NULL ? 0 : my_parents->size();
    1107                 :          1 :   RETURN (iBase_SUCCESS);
    1108                 :            : }
    1109                 :            : 
    1110                 :            : /**
    1111                 :            :  *   Add a parent to the gentity_set 
    1112                 :            :  */
    1113                 :            : ITAPS_API void
    1114                 :          4 : iGeom_addPrntChld( iGeom_Instance instance,
    1115                 :            :                    /*inout*/ iBase_EntitySetHandle parent_entity_set,
    1116                 :            :                    /*inout*/ iBase_EntitySetHandle child_entity_set,
    1117                 :            :                    int* err )
    1118                 :            : {
    1119                 :            :   std::vector<RefGroup*> *my_parents = 
    1120         [ +  - ]:          4 :     TM->pc_list(SET_HANDLE(child_entity_set), 0, true);
    1121                 :            :   std::vector<RefGroup*> *my_children = 
    1122         [ +  - ]:          4 :     TM->pc_list(SET_HANDLE(parent_entity_set), 1, true);
    1123                 :          4 :   RefGroup *par_group = SET_HANDLE(parent_entity_set);
    1124                 :          4 :   RefGroup *child_group = SET_HANDLE(child_entity_set);
    1125         [ +  - ]:          4 :   my_parents->push_back(par_group);
    1126         [ +  - ]:          4 :   my_children->push_back(child_group);
    1127         [ +  - ]:          4 :   RETURN(iBase_SUCCESS);
    1128                 :            : }
    1129                 :            : 
    1130                 :            : /**
    1131                 :            :  *   Remove a parent/child link between gentity_sets
    1132                 :            :  */
    1133                 :            : ITAPS_API void
    1134                 :          1 : iGeom_rmvPrntChld( iGeom_Instance instance,
    1135                 :            :                    /*inout*/ iBase_EntitySetHandle parent_entity_set,
    1136                 :            :                    /*inout*/ iBase_EntitySetHandle child_entity_set,
    1137                 :            :                    int* err )
    1138                 :            : {
    1139                 :          1 :   RefGroup *parent = reinterpret_cast<RefGroup *>(parent_entity_set);
    1140                 :          1 :   RefGroup *child = reinterpret_cast<RefGroup *>(child_entity_set);
    1141         [ +  - ]:          1 :   std::vector<RefGroup*> *children = TM->pc_list(parent, 1, false),
    1142         [ +  - ]:          1 :     *parents = TM->pc_list(child, 0, false);
    1143 [ +  - ][ -  + ]:          1 :   if (NULL == children || NULL == parents) {
    1144         [ #  # ]:          0 :     RETURN(iBase_INVALID_ARGUMENT);
    1145                 :            :   }
    1146                 :            :   
    1147 [ +  - ][ +  - ]:          1 :   children->erase(std::remove(children->begin(), children->end(), child), children->end());
         [ +  - ][ +  - ]
                 [ +  - ]
    1148 [ +  - ][ +  - ]:          1 :   parents->erase(std::remove(parents->begin(), parents->end(), parent), parents->end());
         [ +  - ][ +  - ]
                 [ +  - ]
    1149         [ +  - ]:          1 :   RETURN(iBase_SUCCESS);
    1150                 :            : }
    1151                 :            : 
    1152                 :            : /**
    1153                 :            :  * Return gentities of specified dimension in this set, or in whole model.
    1154                 :            :  * @param set_handle Entity set being queried (if 0, whole model)
    1155                 :            :  * @param gentity_dimension Dimension of entities being queried
    1156                 :            :  * @param gentity_handles Entity handles
    1157                 :            :  */
    1158                 :            : ITAPS_API void
    1159                 :         30 : iGeom_getEntities( iGeom_Instance instance,
    1160                 :            :                    /*in*/ iBase_EntitySetHandle set_handle,
    1161                 :            :                    /*in*/ int gentity_type,
    1162                 :            :                    /*out*/ iBase_EntityHandle **gentity_handles,
    1163                 :            :                    int *gentity_handles_allocated,
    1164                 :            :                    int *gentity_handles_size,
    1165                 :            :                    int* err )
    1166                 :            : {
    1167         [ +  + ]:         30 :   if (RefGroup *this_set = SET_HANDLE(set_handle)) {
    1168 [ +  + ][ +  - ]:          4 :     static DLIList<CubitEntity*> centities;
         [ +  - ][ #  # ]
    1169                 :          4 :     centities.clean_out();
    1170                 :          4 :     this_set->get_child_entities(centities);
    1171                 :            :     copy_ibase_type( gentity_type, centities, 
    1172                 :            :                      gentity_handles,
    1173                 :            :                      gentity_handles_allocated,
    1174                 :            :                      gentity_handles_size,
    1175                 :          4 :                      err );
    1176                 :            :   }
    1177                 :            :   else {
    1178 [ +  + ][ +  - ]:         26 :     static DLIList<RefEntity*> dim_entities;
         [ +  - ][ #  # ]
    1179         [ +  - ]:         26 :     dim_entities.clean_out();
    1180         [ +  - ]:         26 :     append_all_ibase_type( gentity_type, dim_entities, err );
    1181         [ -  + ]:         26 :     if (iBase_SUCCESS != *err)
    1182                 :          0 :       return;
    1183                 :            :     
    1184 [ +  - ][ +  - ]:         26 :     ALLOC_CHECK_ARRAY_NOFAIL(gentity_handles, dim_entities.size());
         [ -  + ][ +  - ]
    1185         [ +  - ]:         26 :     dim_entities.copy_to((RefEntity**)*gentity_handles);
    1186 [ +  - ][ +  - ]:         30 :     RETURN(iBase_SUCCESS);
    1187                 :            :   }  
    1188                 :            : }
    1189                 :            : 
    1190                 :            : /**
    1191                 :            :  * Return number of gentities of specified dimension in this set, or in
    1192                 :            :  * whole model.
    1193                 :            :  * @param set_handle Entity set being queried (if 0, whole model)
    1194                 :            :  * @param gentity_dimension Dimension of entities being queried
    1195                 :            :  * @return Number of entities
    1196                 :            :  */
    1197                 :            : ITAPS_API void
    1198                 :         25 : iGeom_getNumOfType( iGeom_Instance instance,
    1199                 :            :                     /*in*/ iBase_EntitySetHandle set_handle,
    1200                 :            :                     /*in*/ int gentity_type,
    1201                 :            :                     int* count,
    1202                 :            :                     int* err )
    1203                 :            : {
    1204                 :         25 :   const RefGroup *this_set = SET_HANDLE(set_handle);
    1205         [ +  + ]:         25 :   if (0 == this_set) {
    1206   [ -  +  +  +  :         17 :     switch (gentity_type) {
                   +  - ]
    1207                 :            :       case iBase_ALL_TYPES:
    1208                 :          0 :         *count  = GeometryQueryTool::instance()->num_bodies();
    1209                 :          0 :         *count += GeometryQueryTool::instance()->num_ref_faces();
    1210                 :          0 :         *count += GeometryQueryTool::instance()->num_ref_edges();
    1211                 :          0 :         *count += GeometryQueryTool::instance()->num_ref_vertices();
    1212                 :          0 :         break;
    1213                 :            :       case iBase_REGION:
    1214                 :          5 :         *count = GeometryQueryTool::instance()->num_bodies();
    1215                 :          5 :         break;
    1216                 :            :       case iBase_FACE:
    1217                 :          4 :         *count = GeometryQueryTool::instance()->num_ref_faces();
    1218                 :          4 :         break;
    1219                 :            :       case iBase_EDGE:
    1220                 :          4 :         *count = GeometryQueryTool::instance()->num_ref_edges();
    1221                 :          4 :         break;
    1222                 :            :       case iBase_VERTEX:
    1223                 :          4 :         *count = GeometryQueryTool::instance()->num_ref_vertices();
    1224                 :          4 :         break;
    1225                 :            :       default:
    1226                 :          0 :         RETURN(iBase_BAD_TYPE_AND_TOPO);
    1227                 :            :         break;
    1228                 :            :     }
    1229                 :         17 :     RETURN (iBase_SUCCESS);
    1230                 :            :   }
    1231                 :            :   else {
    1232 [ +  + ][ +  - ]:          8 :     static DLIList<CubitEntity*> centities;
         [ +  - ][ #  # ]
    1233                 :          8 :     centities.clean_out();
    1234                 :          8 :     const_cast<RefGroup*>(this_set)->get_child_entities(centities);
    1235                 :         25 :     *count = count_ibase_type( gentity_type, centities, err );
    1236                 :            :   }
    1237                 :            : }
    1238                 :            : 
    1239                 :            : ITAPS_API void
    1240                 :          0 : iGeom_getEntType( iGeom_Instance instance, 
    1241                 :            :                   iBase_EntityHandle handle,
    1242                 :            :                   int* gtype,
    1243                 :            :                   int* err )
    1244                 :            : {
    1245                 :          0 :   RefEntity* entity = reinterpret_cast<RefEntity*>(handle);
    1246 [ #  # ][ #  # ]:          0 :   if (dynamic_cast<Body*>(entity))
                 [ #  # ]
    1247                 :          0 :     *gtype = iBase_REGION;
    1248                 :            :   else
    1249                 :          0 :     *gtype = static_cast<int>(entity->dimension());
    1250                 :          0 :   RETURN(iBase_SUCCESS);
    1251                 :            : }
    1252                 :            : 
    1253                 :            : /**
    1254                 :            :  *    Returns an integer array of topological dimensions for an input
    1255                 :            :  *    array of entity handles.
    1256                 :            :  */
    1257                 :            : ITAPS_API void
    1258                 :          0 : iGeom_getArrType( iGeom_Instance instance,
    1259                 :            :                   /*in*/ iBase_EntityHandle const *gentity_handles,
    1260                 :            :                   int gentity_handles_size,
    1261                 :            :                   /*inout*/ int **gtype,
    1262                 :            :                   int *gtype_allocated,
    1263                 :            :                   int *gtype_size, 
    1264                 :            :                   int* err )
    1265                 :            : {
    1266                 :            :     // go through each entity and look up its dimension
    1267 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(gtype, gentity_handles_size);
                 [ #  # ]
    1268                 :            : 
    1269                 :          0 :   const RefEntity **tmp_handles = (const RefEntity**)(gentity_handles);
    1270                 :            :   
    1271         [ #  # ]:          0 :   for (int i = 0; i < gentity_handles_size; i++) {
    1272 [ #  # ][ #  # ]:          0 :     if (dynamic_cast<const Body*>(tmp_handles[i]))
                 [ #  # ]
    1273                 :          0 :       (*gtype)[i] = iBase_REGION;
    1274                 :            :     else
    1275         [ #  # ]:          0 :       (*gtype)[i] = tmp_handles[i]->dimension();
    1276                 :            :   }
    1277                 :            : 
    1278 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    1279                 :            : }
    1280                 :            : 
    1281                 :            : /**
    1282                 :            :  * Get the adjacent entities of a given dimension.
    1283                 :            :  * @param gentity_handle Entity for which adjacencies are requested
    1284                 :            :  * @param to_dimension Target dimension of adjacent entities
    1285                 :            :  * @param adj_gentities List returned with adjacent entities
    1286                 :            :  */
    1287                 :            : ITAPS_API void
    1288                 :       1899 : iGeom_getEntAdj( iGeom_Instance instance,
    1289                 :            :                  /*in*/ iBase_EntityHandle gentity_handle,
    1290                 :            :                  /*in*/int to_dimension,
    1291                 :            :                  /*inout*/ iBase_EntityHandle **adj_gentities,
    1292                 :            :                  int *adj_gentities_allocated,
    1293                 :            :                  int *adj_gentities_size,
    1294                 :            :                  int* err )
    1295                 :            : {
    1296                 :       1899 :   const RefEntity *tmp_hndl = ENTITY_HANDLE(gentity_handle);
    1297                 :            : 
    1298 [ +  - ][ -  + ]:       1899 :   if (tmp_hndl->dimension() == to_dimension) {
    1299         [ #  # ]:          0 :     ERROR(iBase_INVALID_ARGUMENT, "Can't get adjacencies to entities of same dimension.");
    1300                 :            :   }
    1301                 :            : 
    1302 [ +  + ][ +  - ]:       1899 :   static DLIList<RefEntity*> tmp_ents;
         [ +  - ][ #  # ]
    1303         [ +  - ]:       1899 :   iGeom_get_adjacent_entities(tmp_hndl, to_dimension, tmp_ents, err);
    1304         [ -  + ]:       1899 :   if (iBase_SUCCESS != *err) return;
    1305                 :            : 
    1306 [ +  - ][ +  - ]:       1899 :   ALLOC_CHECK_ARRAY_NOFAIL(adj_gentities, tmp_ents.size());
         [ -  + ][ +  - ]
    1307         [ +  - ]:       1899 :   tmp_ents.copy_to((RefEntity**)*adj_gentities);
    1308 [ +  - ][ +  - ]:       1899 :   RETURN(iBase_SUCCESS);
    1309                 :            : }
    1310                 :            : 
    1311                 :            : ITAPS_API void
    1312                 :          0 : iGeom_getArrAdj( iGeom_Instance instance,
    1313                 :            :                  /*in*/ iBase_EntityHandle const *entity_handles,
    1314                 :            :                  const int entity_handles_size,
    1315                 :            :                  /*in*/ int requested_entity_type,
    1316                 :            :                  /*inout*/ iBase_EntityHandle **adj_entity_handles,
    1317                 :            :                  int *adj_entity_handles_allocated,
    1318                 :            :                  int *adj_entity_handles_size,
    1319                 :            :                  /*inout*/ int **offset,
    1320                 :            :                  int *offset_allocated,
    1321                 :            :                  int *offset_size,
    1322                 :            :                  int* err )
    1323                 :            : {
    1324 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(offset, entity_handles_size+1);
    1325 [ #  # ][ #  # ]:          0 :   DLIList<RefEntity*> temp_list, total_list;
         [ #  # ][ #  # ]
    1326         [ #  # ]:          0 :   for (int i = 0; i < entity_handles_size; ++i) {
    1327         [ #  # ]:          0 :     (*offset)[i] = total_list.size();
    1328         [ #  # ]:          0 :     temp_list.clean_out();
    1329         [ #  # ]:          0 :     iGeom_get_adjacent_entities( (RefEntity*)(entity_handles[i]), requested_entity_type, temp_list, err );
    1330         [ #  # ]:          0 :     if (iBase_SUCCESS != *err) return;
    1331         [ #  # ]:          0 :     total_list += temp_list;
    1332                 :            :   }
    1333         [ #  # ]:          0 :   (*offset)[entity_handles_size] = total_list.size();
    1334                 :            : 
    1335 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(adj_entity_handles, total_list.size());
         [ #  # ][ #  # ]
                 [ #  # ]
    1336         [ #  # ]:          0 :   total_list.copy_to((RefEntity**)*adj_entity_handles);
    1337         [ #  # ]:          0 :   KEEP_ARRAY(offset);
    1338 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    1339                 :            : }
    1340                 :            :   
    1341                 :            : /**
    1342                 :            :  * Get the "2nd order" adjacent entities, through a specified "bridge"
    1343                 :            :  * dimension, of a target dimension.  For example, given a region, return
    1344                 :            :  * the regions (to_dimension=3) sharing an edge (bridge_dimension=1)
    1345                 :            :  * with that region.  bridge_dimension must be less than dimension of 
    1346                 :            :  * gentity_handle, and to_dimension must be greater than bridge dimension.
    1347                 :            :  * 
    1348                 :            :  * @param gentity_handle Entity for which 2nd order adjacencies are requested
    1349                 :            :  * @param to_dimension Target dimension of 2nd order adjacent entities
    1350                 :            :  * @param bridge_dimension Dimension of "bridge" entities
    1351                 :            :  * @param adj_gentities List returned with 2nd order adjacent entities
    1352                 :            :  */
    1353                 :            : ITAPS_API void
    1354                 :          0 : iGeom_getEnt2ndAdj( iGeom_Instance instance,
    1355                 :            :                     /*in*/ iBase_EntityHandle gentity_handle,
    1356                 :            :                     /*in*/ int bridge_dimension,
    1357                 :            :                     /*in*/ int to_dimension,
    1358                 :            :                     /*out*/ iBase_EntityHandle **adjacent_gentities,
    1359                 :            :                     int *adjacent_gentities_allocated,
    1360                 :            :                     int *adjacent_gentities_size,
    1361                 :            :                     int* err )
    1362                 :            : {
    1363                 :            :     // for better or worse, go to cgm as quickly as possible, to avoid working with
    1364                 :            :     // sidl arrays
    1365                 :          0 :   const RefEntity *gentity = ENTITY_HANDLE(gentity_handle);
    1366 [ #  # ][ #  # ]:          0 :   DLIList<RefEntity*> to_ents, bridge_ents, tmp_ents;
         [ #  # ][ #  # ]
                 [ #  # ]
    1367                 :            : 
    1368         [ #  # ]:          0 :   iGeom_get_adjacent_entities(gentity, bridge_dimension, bridge_ents, err);
    1369         [ #  # ]:          0 :   if (iBase_SUCCESS != *err) return;
    1370                 :            :   
    1371 [ #  # ][ #  # ]:          0 :   for (int i = bridge_ents.size(); i > 0; i--) {
    1372 [ #  # ][ #  # ]:          0 :     iGeom_get_adjacent_entities(bridge_ents.get_and_step(), to_dimension, tmp_ents, err);
    1373         [ #  # ]:          0 :     if (iBase_SUCCESS != *err) return;
    1374                 :            : 
    1375         [ #  # ]:          0 :     to_ents += tmp_ents;
    1376         [ #  # ]:          0 :     tmp_ents.clean_out();
    1377                 :            :   }
    1378                 :            : 
    1379         [ #  # ]:          0 :   to_ents.uniquify_unordered();
    1380                 :            : 
    1381 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(adjacent_gentities, to_ents.size());
         [ #  # ][ #  # ]
                 [ #  # ]
    1382         [ #  # ]:          0 :   to_ents.copy_to((RefEntity**)*adjacent_gentities);
    1383                 :            : 
    1384 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    1385                 :            : }
    1386                 :            : 
    1387                 :            : ITAPS_API void
    1388                 :          0 : iGeom_getArr2ndAdj( iGeom_Instance instance,
    1389                 :            :                     /*in*/ iBase_EntityHandle const *entity_handles,
    1390                 :            :                     int entity_handles_size,
    1391                 :            :                     /*in*/ int order_adjacent_key,
    1392                 :            :                     /*in*/ int requested_entity_type,
    1393                 :            :                     /*inout*/ iBase_EntityHandle **adj_entity_handles,
    1394                 :            :                     int *adj_entity_handles_allocated,
    1395                 :            :                     int *adj_entity_handles_size,
    1396                 :            :                     /*inout*/ int **offset,
    1397                 :            :                     int *offset_allocated,
    1398                 :            :                     int *offset_size,
    1399                 :            :                     int *err )
    1400                 :            : {
    1401 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(offset, entity_handles_size+1);
    1402 [ #  # ][ #  # ]:          0 :   DLIList<RefEntity*> bridge_list, temp_list, entity_list, total_list;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1403                 :            :    
    1404         [ #  # ]:          0 :   for (int i = 0; i < entity_handles_size; ++i) {
    1405         [ #  # ]:          0 :     bridge_list.clean_out();
    1406         [ #  # ]:          0 :     entity_list.clean_out();
    1407         [ #  # ]:          0 :     iGeom_get_adjacent_entities( (RefEntity*)(entity_handles[i]), order_adjacent_key, bridge_list, err );
    1408         [ #  # ]:          0 :     if (iBase_SUCCESS != *err) return;
    1409         [ #  # ]:          0 :     bridge_list.reset();
    1410 [ #  # ][ #  # ]:          0 :     for (int j = bridge_list.size(); j > 0; --j) {
    1411         [ #  # ]:          0 :       temp_list.clean_out();
    1412 [ #  # ][ #  # ]:          0 :       iGeom_get_adjacent_entities( bridge_list.get_and_step(), requested_entity_type, temp_list, err );
    1413         [ #  # ]:          0 :       if (iBase_SUCCESS != *err) return;
    1414         [ #  # ]:          0 :       entity_list += temp_list;
    1415                 :            :     }
    1416         [ #  # ]:          0 :     entity_list.uniquify_unordered();
    1417         [ #  # ]:          0 :     (*offset)[i] = total_list.size();
    1418         [ #  # ]:          0 :     total_list += entity_list;
    1419                 :            :   }
    1420         [ #  # ]:          0 :   (*offset)[entity_handles_size] = total_list.size();
    1421                 :            : 
    1422 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(adj_entity_handles, total_list.size());
         [ #  # ][ #  # ]
                 [ #  # ]
    1423         [ #  # ]:          0 :   total_list.copy_to((RefEntity**)*adj_entity_handles);
    1424         [ #  # ]:          0 :   KEEP_ARRAY(offset);
    1425 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    1426                 :            : }
    1427                 :            : 
    1428                 :            : /**
    1429                 :            :  * Return whether or not entities are adjacent.
    1430                 :            :  * @param gentity_handle1 1st entity
    1431                 :            :  * @param gentity_handle2 2nd entity
    1432                 :            :  * @param are_adjacent If true, entities are adjacent
    1433                 :            :  */
    1434                 :            : ITAPS_API void
    1435                 :          0 : iGeom_isEntAdj( iGeom_Instance instance,
    1436                 :            :                 /*in*/ iBase_EntityHandle gentity_handle1,
    1437                 :            :                 /*in*/ iBase_EntityHandle gentity_handle2,
    1438                 :            :                 /*out*/ int *are_adjacent,
    1439                 :            :                 int* err )
    1440                 :            : {
    1441         [ #  # ]:          0 :   const TopologyEntity *ent1 = dynamic_cast<const TopologyEntity*>(ENTITY_HANDLE(gentity_handle1));
    1442         [ #  # ]:          0 :   const TopologyEntity *ent2 = dynamic_cast<const TopologyEntity*>(ENTITY_HANDLE(gentity_handle2));
    1443 [ #  # ][ #  # ]:          0 :   if (ent1 != NULL && ent2 != NULL)
    1444                 :          0 :     *are_adjacent = const_cast<TopologyEntity*>(ent1)->is_directly_related(const_cast<TopologyEntity*>(ent2));
    1445                 :          0 :   else *are_adjacent = false;
    1446                 :          0 :   RETURN(iBase_SUCCESS);
    1447                 :            : }
    1448                 :            : 
    1449                 :            : ITAPS_API void
    1450                 :          0 : iGeom_isArrAdj( iGeom_Instance instance,
    1451                 :            :                 /*in*/ iBase_EntityHandle const *entity_handles_1,
    1452                 :            :                 int entity_handles_1_size,
    1453                 :            :                 /*in*/ iBase_EntityHandle const *entity_handles_2,
    1454                 :            :                 int entity_handles_2_size,
    1455                 :            :                 /*inout*/ int **is_adjacent_info,
    1456                 :            :                 int *is_adjacent_info_allocated,
    1457                 :            :                 int *is_adjacent_info_size,
    1458                 :            :                 int* err )
    1459                 :            : {
    1460                 :          0 :   RefEntity **list_1_iter = (RefEntity**)entity_handles_1, 
    1461                 :          0 :     **list_2_iter = (RefEntity**)entity_handles_2;
    1462                 :            :   size_t list_1_step, list_2_step;
    1463                 :            :   int count;
    1464                 :            :     // If either list contains only 1 entry, compare that entry with
    1465                 :            :     // every entry in the other list.
    1466         [ #  # ]:          0 :   if (entity_handles_1_size == entity_handles_2_size) {
    1467                 :          0 :     list_1_step = list_2_step = 1;
    1468                 :          0 :     count = entity_handles_1_size;
    1469                 :            :   }
    1470         [ #  # ]:          0 :   else if (entity_handles_1_size == 1) {
    1471                 :          0 :     list_1_step = 0;
    1472                 :          0 :     list_2_step = 1;
    1473                 :          0 :     count = entity_handles_2_size;
    1474                 :            :   }
    1475         [ #  # ]:          0 :   else if (entity_handles_2_size == 1) {
    1476                 :          0 :     list_1_step = 1;
    1477                 :          0 :     list_2_step = 0;
    1478                 :          0 :     count = entity_handles_1_size;
    1479                 :            :   }
    1480                 :            :   else {
    1481         [ #  # ]:          0 :     RETURN(iBase_INVALID_ENTITY_COUNT);
    1482                 :            :   }
    1483                 :            :   
    1484 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(is_adjacent_info, count);
                 [ #  # ]
    1485         [ #  # ]:          0 :   for (int i = 0; i < count; ++i)
    1486                 :            :   {
    1487         [ #  # ]:          0 :     TopologyEntity* ent1 = dynamic_cast<TopologyEntity*>(*list_1_iter);
    1488         [ #  # ]:          0 :     TopologyEntity* ent2 = dynamic_cast<TopologyEntity*>(*list_2_iter);
    1489         [ #  # ]:          0 :     (*is_adjacent_info)[i] = ent1->is_directly_related(ent2);
    1490                 :          0 :     list_1_iter += list_1_step;
    1491                 :          0 :     list_2_iter += list_2_step;
    1492                 :            :   }
    1493 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    1494                 :            : }
    1495                 :            : 
    1496                 :            : ITAPS_API void
    1497                 :          0 : iGeom_getTopoLevel( iGeom_Instance instance,
    1498                 :            :                     /*out*/ int* level,
    1499                 :            :                     int* err )
    1500                 :            : {
    1501                 :          0 :   *level = 2; // 0->basic entities only, 1->manifold, 2->non-manifold
    1502                 :          0 :   RETURN(iBase_SUCCESS);
    1503                 :            : }
    1504                 :            : 
    1505                 :            : /**
    1506                 :            :  * 
    1507                 :            :  *   Create a tag handle with a given name, size (in bytes), and
    1508                 :            :  *   default value.  The tag name is a unique string; if it duplicates
    1509                 :            :  *   an existing tag name, an error is returned.  The tag_handle is
    1510                 :            :  *   returned as an opaque value which is not associated with any mesh
    1511                 :            :  *   gentities until explicitly done so through one of the 'AddTag'
    1512                 :            :  *   functions defined later.  The implementation is assumed to
    1513                 :            :  *   allocate memory as needed to store the tag data.
    1514                 :            :  */
    1515                 :            : ITAPS_API void
    1516                 :          3 : iGeom_createTag( iGeom_Instance instance,
    1517                 :            :                  /*in*/ const char *tag_name,
    1518                 :            :                  /*in*/ int tag_size,
    1519                 :            :                  /*in*/ int tag_type,
    1520                 :            :                  /*out*/ iBase_TagHandle *tag_handle,
    1521                 :            :                  int* err,
    1522                 :            :                  int tag_name_len )
    1523                 :            : {
    1524                 :            :   long new_tag;
    1525                 :          3 :   int this_size = tag_size;
    1526   [ +  -  -  -  :          3 :   switch (tag_type) {
                   +  - ]
    1527                 :            :     case iBase_INTEGER:
    1528                 :          1 :       this_size *= sizeof(int);
    1529                 :          1 :       break;
    1530                 :            :     case iBase_DOUBLE:
    1531                 :          0 :       this_size *= sizeof(double);
    1532                 :          0 :       break;
    1533                 :            :     case iBase_ENTITY_HANDLE:
    1534                 :          0 :       this_size *= sizeof(iBase_EntityHandle);
    1535                 :          0 :       break;
    1536                 :            :     case iBase_ENTITY_SET_HANDLE:
    1537                 :          0 :       this_size *= sizeof(iBase_EntitySetHandle);
    1538                 :          0 :       break;
    1539                 :            :     case iBase_BYTES:
    1540                 :          2 :       break;
    1541                 :            :   }
    1542                 :            :   
    1543                 :            :     // make sure string is null terminated
    1544         [ +  - ]:          3 :   std::string name_buf( tag_name, tag_name_len );
    1545         [ +  - ]:          3 :   tag_name = name_buf.c_str();
    1546                 :            :   
    1547         [ +  - ]:          3 :   iBase_ErrorType retval = TM->createTag(tag_name, this_size, tag_type, NULL, &new_tag);
    1548                 :          3 :   *tag_handle = (iBase_TagHandle) new_tag;
    1549 [ +  - ][ +  - ]:          3 :   RETURN(retval);
    1550                 :            : }
    1551                 :            : 
    1552                 :            : /**
    1553                 :            :  *   Delete a tag handle and the data associated with that tag.  The
    1554                 :            :  *   deletion can be forced or not forced.  If the deletion is forced,
    1555                 :            :  *   the tag and all of its associated data are deleted from the
    1556                 :            :  *   implementation even if the tag is still associated with mesh
    1557                 :            :  *   gentities.  If the deletion is not forced, the tag will not be
    1558                 :            :  *   deleted if it is still associated with one or more mesh gentities.
    1559                 :            :  *   In this case an error is returned asking the user to remove the
    1560                 :            :  *   tag from that gentity before deleting it.  If the underlying
    1561                 :            :  *   implementation does not support the requested deletion mechanism,
    1562                 :            :  *   an error will be returned.
    1563                 :            :  */
    1564                 :            : ITAPS_API void
    1565                 :          2 : iGeom_destroyTag( iGeom_Instance instance,
    1566                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    1567                 :            :                   /*in*/ int forced,
    1568                 :            :                   int* err )
    1569                 :            : {
    1570                 :          2 :   iBase_ErrorType retval = TM->destroyTag(TAG_HANDLE(tag_handle), forced);
    1571                 :          2 :   RETURN(retval);
    1572                 :            : }
    1573                 :            : 
    1574                 :            : /**
    1575                 :            :  *   Get the tag name associated with a given tag handle.
    1576                 :            :  */
    1577                 :            : ITAPS_API void
    1578                 :          3 : iGeom_getTagName( iGeom_Instance instance,
    1579                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    1580                 :            :                   char* name,
    1581                 :            :                   int* err,
    1582                 :            :                   int name_len )
    1583                 :            : {
    1584                 :          3 :   const char* name_ptr = TM->getTagName(TAG_HANDLE(tag_handle));
    1585                 :          3 :   int len = strlen(name_ptr) + 1;
    1586         [ -  + ]:          3 :   if (len > name_len)
    1587                 :          0 :     len = name_len;
    1588                 :          3 :   memcpy( name, name_ptr, len );
    1589                 :          3 :   RETURN(iBase_SUCCESS);
    1590                 :            : }
    1591                 :            : 
    1592                 :            : /**
    1593                 :            :  *   Get the size of the data associated with a given tag handle.
    1594                 :            :  */
    1595                 :            : ITAPS_API void
    1596                 :          1 : iGeom_getTagSizeValues( iGeom_Instance instance,
    1597                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    1598                 :            :                         int* tag_size,
    1599                 :            :                         int* err )
    1600                 :            : {
    1601         [ +  - ]:          1 :   *tag_size = TM->getTagSize(TAG_HANDLE(tag_handle));
    1602                 :            :   int type;
    1603         [ +  - ]:          1 :   iGeom_getTagType( instance, tag_handle, &type, err );
    1604         [ -  + ]:          1 :   if (iBase_SUCCESS != *err) return;
    1605                 :            :   
    1606   [ -  -  -  +  :          1 :   switch (type) {
                      - ]
    1607                 :            :     case iBase_INTEGER:
    1608                 :          0 :       *tag_size /= sizeof(int);
    1609                 :          0 :       break;
    1610                 :            :     case iBase_DOUBLE:
    1611                 :          0 :       *tag_size /= sizeof(double);
    1612                 :          0 :       break;
    1613                 :            :     case iBase_ENTITY_HANDLE:
    1614                 :            :     case iBase_ENTITY_SET_HANDLE:
    1615                 :          0 :       *tag_size /= sizeof(iBase_EntityHandle);
    1616                 :          0 :       break;
    1617                 :            :     case iBase_BYTES:
    1618                 :          1 :       break;
    1619                 :            :   }
    1620         [ +  - ]:          1 :   RETURN(iBase_SUCCESS);
    1621                 :            : }
    1622                 :            : 
    1623                 :            : /**
    1624                 :            :  *   Get the size of the data associated with a given tag handle.
    1625                 :            :  */
    1626                 :            : ITAPS_API void
    1627                 :          9 : iGeom_getTagSizeBytes( iGeom_Instance instance,
    1628                 :            :                        /*in*/ iBase_TagHandle tag_handle,
    1629                 :            :                        int* tag_size,
    1630                 :            :                        int* err )
    1631                 :            : {
    1632                 :          9 :   *tag_size = TM->getTagSize(TAG_HANDLE(tag_handle));
    1633                 :          9 :   RETURN(iBase_SUCCESS);
    1634                 :            : }
    1635                 :            : 
    1636                 :            : ITAPS_API void
    1637                 :          2 : iGeom_getTagType( iGeom_Instance instance,
    1638                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    1639                 :            :                   int* type,
    1640                 :            :                   int* err )
    1641                 :            : {
    1642                 :          2 :   *type = TM->getTagType(TAG_HANDLE(tag_handle));
    1643                 :          2 :   RETURN(iBase_SUCCESS);
    1644                 :            : }
    1645                 :            : 
    1646                 :            : /**
    1647                 :            :  *     Get the tag handle associated with a given string name.
    1648                 :            :  */
    1649                 :            : ITAPS_API void
    1650                 :         12 : iGeom_getTagHandle( iGeom_Instance instance,
    1651                 :            :                     /*in*/ const char *tag_name,
    1652                 :            :                     iBase_TagHandle* tag_handle,
    1653                 :            :                     int* err,
    1654                 :            :                     int tag_name_len )
    1655                 :            : {
    1656                 :            :     // make sure string is null-terminated
    1657         [ +  - ]:         12 :   std::string tag_name_buf( tag_name, tag_name_len );
    1658         [ +  - ]:         12 :   tag_name = tag_name_buf.c_str();
    1659         [ +  - ]:         12 :   *tag_handle = reinterpret_cast<iBase_TagHandle>(static_cast<size_t>(TM->getTagHandle( tag_name )));
    1660                 :            : 
    1661                 :            :     // XXX: this seems really wrong...
    1662 [ +  - ][ +  - ]:         12 :   iGeom_getErrorType(instance, err);
    1663                 :         12 : }
    1664                 :            : 
    1665                 :            : ITAPS_API void
    1666                 :          0 : iGeom_rmvArrTag( iGeom_Instance instance,
    1667                 :            :                  const iBase_EntityHandle *entity_handles,
    1668                 :            :                  int entity_handles_size,
    1669                 :            :                  iBase_TagHandle tag_handle,
    1670                 :            :                  int* err )
    1671                 :            : {
    1672                 :          0 :   RefEntity *const *tmp_entity_handles = reinterpret_cast<RefEntity*const *>(entity_handles);  
    1673                 :          0 :   iBase_ErrorType retval = TM->rmvArrTag(tmp_entity_handles, entity_handles_size, TAG_HANDLE(tag_handle));
    1674                 :          0 :   RETURN(retval);
    1675                 :            : }
    1676                 :            : 
    1677                 :            : /**
    1678                 :            :  *   Allows the user to disassociate the tag referenced by the tag
    1679                 :            :  *   handle from the specified gentities. The tag data is not deleted in
    1680                 :            :  *   this call, but can be deleted later using the deleteTag function
    1681                 :            :  *   defined above.
    1682                 :            :  */
    1683                 :            : ITAPS_API void
    1684                 :          0 : iGeom_rmvTag( iGeom_Instance instance,
    1685                 :            :               /*in*/ iBase_EntityHandle entity_handle,
    1686                 :            :               /*in*/ iBase_TagHandle tag_handle,
    1687                 :            :               int* err )
    1688                 :            : {
    1689                 :          0 :   RefEntity *tmp_entity = ENTITY_HANDLE(entity_handle);
    1690         [ #  # ]:          0 :   iBase_ErrorType retval = TM->rmvArrTag(&tmp_entity, 1, TAG_HANDLE(tag_handle));
    1691         [ #  # ]:          0 :   RETURN(retval);
    1692                 :            : }
    1693                 :            : 
    1694                 :            : /**
    1695                 :            :  *   Get all tag handles associated with a given gentity.
    1696                 :            :  */
    1697                 :            : ITAPS_API void
    1698                 :        322 : iGeom_getAllTags( iGeom_Instance instance,
    1699                 :            :                   /*in*/ iBase_EntityHandle entity_handle,
    1700                 :            :                   /*inout*/ iBase_TagHandle **tag_handles,
    1701                 :            :                   int *tag_handles_allocated,
    1702                 :            :                   int *tag_handles_size,
    1703                 :            :                   int* err )
    1704                 :            : {
    1705                 :            :   iBase_ErrorType retval = TM->getAllTags(SET_HANDLE(entity_handle), 
    1706                 :        322 :                                           TAG_HANDLE_ARRAY_INOUT(tag_handles));
    1707                 :        322 :   RETURN(retval);
    1708                 :            : }
    1709                 :            : 
    1710                 :            : ITAPS_API void
    1711                 :          8 : iGeom_getArrData( iGeom_Instance instance,
    1712                 :            :                   /*in*/ iBase_EntityHandle const *entity_handles,
    1713                 :            :                   int entity_handles_size,
    1714                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    1715                 :            :                   /*inout*/ void **tag_value_tmp,
    1716                 :            :                   int *tag_value_allocated,
    1717                 :            :                   int *tag_value_size,
    1718                 :            :                   int* err )
    1719                 :            : {
    1720                 :          8 :   char **tag_value = reinterpret_cast<char**>(tag_value_tmp);
    1721                 :            :   iBase_ErrorType retval = TM->getArrData(reinterpret_cast<RefEntity*const*>(entity_handles),
    1722                 :            :                                           entity_handles_size,
    1723                 :            :                                           TAG_HANDLE(tag_handle), 
    1724                 :          8 :                                           ARRAY_INOUT(tag_value));
    1725                 :          8 :   RETURN(retval);
    1726                 :            : }
    1727                 :            : 
    1728                 :            : 
    1729                 :            : ITAPS_API void
    1730                 :          4 : iGeom_getIntArrData( iGeom_Instance instance,
    1731                 :            :                      /*in*/ iBase_EntityHandle const *entity_handles,
    1732                 :            :                      int entity_handles_size,
    1733                 :            :                      /*in*/ iBase_TagHandle tag_handle,
    1734                 :            :                      /*inout*/ int **tag_value,
    1735                 :            :                      int *tag_value_allocated,
    1736                 :            :                      int *tag_value_size,
    1737                 :            :                      int* err )
    1738                 :            : {
    1739                 :          4 :   int tag_value_allocated_tmp = *tag_value_allocated * sizeof(int);
    1740                 :          4 :   int tag_value_size_tmp = *tag_value_size * sizeof(int);
    1741                 :            :   iGeom_getArrData(instance, entity_handles, 
    1742                 :            :                    entity_handles_size, tag_handle,
    1743                 :            :                    reinterpret_cast<void**>(tag_value),
    1744                 :            :                    &tag_value_allocated_tmp, 
    1745                 :            :                    &tag_value_size_tmp,
    1746         [ +  - ]:          4 :                    err);
    1747                 :          4 :   *tag_value_allocated = tag_value_allocated_tmp / sizeof(int);
    1748                 :          4 :   *tag_value_size = tag_value_size_tmp / sizeof(int);
    1749                 :          4 : }
    1750                 :            : 
    1751                 :            : 
    1752                 :            : ITAPS_API void
    1753                 :          0 : iGeom_getDblArrData( iGeom_Instance instance,
    1754                 :            :                      /*in*/ iBase_EntityHandle const *entity_handles,
    1755                 :            :                      int entity_handles_size,
    1756                 :            :                      /*in*/ iBase_TagHandle tag_handle,
    1757                 :            :                      /*inout*/ double **tag_value,
    1758                 :            :                      int *tag_value_allocated,
    1759                 :            :                      int *tag_value_size,
    1760                 :            :                      int* err )
    1761                 :            : {
    1762                 :          0 :   int tag_value_allocated_tmp = *tag_value_allocated * sizeof(double);
    1763                 :          0 :   int tag_value_size_tmp = *tag_value_size * sizeof(double);
    1764                 :            :   iGeom_getArrData(instance, entity_handles, 
    1765                 :            :                    entity_handles_size, tag_handle,
    1766                 :            :                    reinterpret_cast<void**>(tag_value),
    1767                 :            :                    &tag_value_allocated_tmp, 
    1768                 :            :                    &tag_value_size_tmp,
    1769         [ #  # ]:          0 :                    err);
    1770                 :          0 :   *tag_value_allocated = tag_value_allocated_tmp / sizeof(double);
    1771                 :          0 :   *tag_value_size = tag_value_size_tmp / sizeof(double);
    1772                 :          0 : }
    1773                 :            : 
    1774                 :            : ITAPS_API void
    1775                 :          0 : iGeom_getEHArrData( iGeom_Instance instance,
    1776                 :            :                     /*in*/ iBase_EntityHandle const *entity_handles,
    1777                 :            :                     int entity_handles_size,
    1778                 :            :                     /*in*/ iBase_TagHandle tag_handle,
    1779                 :            :                     /*inout*/ iBase_EntityHandle **tag_value,
    1780                 :            :                     int *tag_value_allocated,
    1781                 :            :                     int *tag_value_size,
    1782                 :            :                     int* err )
    1783                 :            : {
    1784                 :          0 :   int tag_value_allocated_tmp = *tag_value_allocated * sizeof(iBase_EntityHandle);
    1785                 :          0 :   int tag_value_size_tmp = *tag_value_size * sizeof(iBase_EntityHandle);
    1786                 :            :   iGeom_getArrData(instance, entity_handles, 
    1787                 :            :                    entity_handles_size, tag_handle,
    1788                 :            :                    reinterpret_cast<void**>(tag_value),
    1789                 :            :                    &tag_value_allocated_tmp, 
    1790                 :            :                    &tag_value_size_tmp,
    1791         [ #  # ]:          0 :                    err);
    1792                 :          0 :   *tag_value_allocated = tag_value_allocated_tmp / sizeof(iBase_EntityHandle);
    1793                 :          0 :   *tag_value_size = tag_value_size_tmp / sizeof(iBase_EntityHandle);
    1794                 :          0 : }
    1795                 :            : 
    1796                 :            : ITAPS_API void
    1797                 :          0 : iGeom_getESHArrData( iGeom_Instance instance,
    1798                 :            :                      /*in*/ iBase_EntityHandle const *entity_handles,
    1799                 :            :                      int entity_handles_size,
    1800                 :            :                      /*in*/ iBase_TagHandle tag_handle,
    1801                 :            :                      /*inout*/ iBase_EntitySetHandle **tag_value,
    1802                 :            :                      int *tag_value_allocated,
    1803                 :            :                      int *tag_value_size,
    1804                 :            :                      int* err )
    1805                 :            : {
    1806                 :          0 :   int tag_value_allocated_tmp = *tag_value_allocated * sizeof(iBase_EntitySetHandle);
    1807                 :          0 :   int tag_value_size_tmp = *tag_value_size * sizeof(iBase_EntitySetHandle);
    1808                 :            :   iGeom_getArrData(instance, entity_handles,
    1809                 :            :                    entity_handles_size, tag_handle,
    1810                 :            :                    reinterpret_cast<void**>(tag_value),
    1811                 :            :                    &tag_value_allocated_tmp,
    1812                 :            :                    &tag_value_size_tmp,
    1813         [ #  # ]:          0 :                    err);
    1814                 :          0 :   *tag_value_allocated = tag_value_allocated_tmp / sizeof(iBase_EntitySetHandle);
    1815                 :          0 :   *tag_value_size = tag_value_size_tmp / sizeof(iBase_EntitySetHandle);
    1816                 :          0 : }
    1817                 :            : 
    1818                 :            : ITAPS_API void
    1819                 :          4 : iGeom_setArrData( iGeom_Instance instance,
    1820                 :            :                   const iBase_EntityHandle *entity_handles,
    1821                 :            :                   int entity_handles_size,
    1822                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    1823                 :            :                   /*in*/ const void *tag_value_tmp,
    1824                 :            :                   const int tag_value_size,
    1825                 :            :                   int* err )
    1826                 :            : {
    1827                 :          4 :   const char *tag_value = reinterpret_cast<const char*>(tag_value_tmp);
    1828                 :            :   iBase_ErrorType retval = TM->setArrData(ENTITY_HANDLE_CONST_ARRAY(entity_handles),
    1829                 :            :                                           entity_handles_size,
    1830                 :            :                                           TAG_HANDLE(tag_handle), 
    1831                 :          4 :                                           ARRAY_IN(tag_value));
    1832                 :          4 :   RETURN(retval);
    1833                 :            : }
    1834                 :            : 
    1835                 :            : ITAPS_API void
    1836                 :          0 : iGeom_setIntArrData( iGeom_Instance instance,
    1837                 :            :                      const iBase_EntityHandle *entity_handles,
    1838                 :            :                      int entity_handles_size,
    1839                 :            :                      iBase_TagHandle tag_handle,
    1840                 :            :                      const int *tag_value,
    1841                 :            :                      int tag_value_size,
    1842                 :            :                      int* err )
    1843                 :            : {
    1844                 :            :   iGeom_setArrData(instance, entity_handles, 
    1845                 :            :                    entity_handles_size, tag_handle, 
    1846                 :          0 :                    tag_value, sizeof(int)*tag_value_size, err);
    1847                 :          0 : }
    1848                 :            : 
    1849                 :            : ITAPS_API void
    1850                 :          0 : iGeom_setDblArrData( iGeom_Instance instance,
    1851                 :            :                      const iBase_EntityHandle *entity_handles,
    1852                 :            :                      int entity_handles_size,
    1853                 :            :                      iBase_TagHandle tag_handle,
    1854                 :            :                      const double *tag_value,
    1855                 :            :                      int tag_value_size,
    1856                 :            :                      int* err )
    1857                 :            : {
    1858                 :            :   iGeom_setArrData(instance, entity_handles, 
    1859                 :            :                    entity_handles_size, tag_handle, 
    1860                 :          0 :                    tag_value, sizeof(double)*tag_value_size, err);
    1861                 :          0 : }
    1862                 :            : 
    1863                 :            : ITAPS_API void
    1864                 :          0 : iGeom_setEHArrData( iGeom_Instance instance,
    1865                 :            :                     const iBase_EntityHandle *entity_handles,
    1866                 :            :                     int entity_handles_size,
    1867                 :            :                     iBase_TagHandle tag_handle,
    1868                 :            :                     iBase_EntityHandle const *tag_values,
    1869                 :            :                     int tag_values_size,
    1870                 :            :                     int* err )
    1871                 :            : {
    1872                 :            :   iGeom_setArrData(instance, entity_handles, 
    1873                 :            :                    entity_handles_size, tag_handle, 
    1874                 :            :                    tag_values, sizeof(iBase_EntityHandle)*tag_values_size,
    1875                 :          0 :                    err);
    1876                 :          0 : }
    1877                 :            : 
    1878                 :            : ITAPS_API void
    1879                 :          0 : iGeom_setESHArrData( iGeom_Instance instance,
    1880                 :            :                      const iBase_EntityHandle *entity_handles,
    1881                 :            :                      int entity_handles_size,
    1882                 :            :                      iBase_TagHandle tag_handle,
    1883                 :            :                      iBase_EntitySetHandle const *tag_values,
    1884                 :            :                      int tag_values_size,
    1885                 :            :                      int* err )
    1886                 :            : {
    1887                 :            :   iGeom_setArrData(instance, entity_handles,
    1888                 :            :                    entity_handles_size, tag_handle,
    1889                 :            :                    tag_values, sizeof(iBase_EntitySetHandle)*tag_values_size,
    1890                 :          0 :                    err);
    1891                 :          0 : }
    1892                 :            : 
    1893                 :            : /**
    1894                 :            :  *   Allows the user to retrieve an array of tag values associated with
    1895                 :            :  *   a tag handle from an input array of gentity handles
    1896                 :            :  */
    1897                 :            : ITAPS_API void
    1898                 :          8 : iGeom_getData( iGeom_Instance instance,
    1899                 :            :                /*in*/ iBase_EntityHandle entity_handle,
    1900                 :            :                /*in*/ iBase_TagHandle tag_handle,
    1901                 :            :                /*inout*/ void **tag_value_tmp,
    1902                 :            :                int *tag_value_allocated,
    1903                 :            :                int *tag_value_size,
    1904                 :            :                int* err )
    1905                 :            : {
    1906                 :          8 :   char **tag_value = reinterpret_cast<char **>(tag_value_tmp);
    1907                 :          8 :   RefEntity *tmp_entity = ENTITY_HANDLE(entity_handle);
    1908                 :            :   iBase_ErrorType retval = TM->getArrData(&tmp_entity, 1, TAG_HANDLE(tag_handle), 
    1909         [ +  - ]:          8 :                                           ARRAY_INOUT(tag_value));
    1910         [ +  - ]:          8 :   RETURN(retval);
    1911                 :            : }
    1912                 :            : 
    1913                 :            : ITAPS_API void
    1914                 :          0 : iGeom_getIntData( iGeom_Instance instance,
    1915                 :            :                   iBase_EntityHandle entity_handle,
    1916                 :            :                   iBase_TagHandle tag_handle,
    1917                 :            :                   int* data_out,
    1918                 :            :                   int* err ) 
    1919                 :            : {
    1920                 :          0 :   void *val_ptr = data_out;
    1921                 :          0 :   int val_size = sizeof(int);
    1922                 :            :   iGeom_getArrData(instance, &entity_handle, 1, 
    1923         [ #  # ]:          0 :                    tag_handle, &val_ptr, &val_size, &val_size, err);
    1924                 :          0 : }
    1925                 :            : 
    1926                 :            : ITAPS_API void
    1927                 :          0 : iGeom_getDblData( iGeom_Instance instance,
    1928                 :            :                   iBase_EntityHandle entity_handle,
    1929                 :            :                   iBase_TagHandle tag_handle,
    1930                 :            :                   double* data_out,
    1931                 :            :                   int* err ) 
    1932                 :            : {
    1933                 :          0 :   void *val_ptr = data_out;
    1934                 :          0 :   int val_size = sizeof(double);
    1935                 :            :   iGeom_getArrData(instance, &entity_handle, 1, 
    1936         [ #  # ]:          0 :                    tag_handle, &val_ptr, &val_size, &val_size, err);
    1937                 :          0 : }
    1938                 :            : 
    1939                 :            : ITAPS_API void
    1940                 :          0 : iGeom_getEHData( iGeom_Instance instance,
    1941                 :            :                  iBase_EntityHandle entity_handle,
    1942                 :            :                  iBase_TagHandle tag_handle,
    1943                 :            :                  iBase_EntityHandle* data_out,
    1944                 :            :                  int* err ) 
    1945                 :            : {
    1946                 :          0 :   void *val_ptr = data_out;
    1947                 :          0 :   int val_size = sizeof(iBase_EntityHandle);
    1948                 :            :   iGeom_getArrData(instance, &entity_handle, 1, 
    1949         [ #  # ]:          0 :                    tag_handle, &val_ptr, &val_size, &val_size, err);
    1950                 :          0 : }
    1951                 :            : 
    1952                 :            : ITAPS_API void
    1953                 :          0 : iGeom_getESHData( iGeom_Instance instance,
    1954                 :            :                   iBase_EntityHandle entity_handle,
    1955                 :            :                   iBase_TagHandle tag_handle,
    1956                 :            :                   iBase_EntitySetHandle* data_out,
    1957                 :            :                   int* err )
    1958                 :            : {
    1959                 :          0 :   void *val_ptr = data_out;
    1960                 :          0 :   int val_size = sizeof(iBase_EntitySetHandle);
    1961                 :            :   iGeom_getArrData(instance, &entity_handle, 1,
    1962         [ #  # ]:          0 :                    tag_handle, &val_ptr, &val_size, &val_size, err);
    1963                 :          0 : }
    1964                 :            : 
    1965                 :            : /**
    1966                 :            :  *   Allows the user to set the tag data values on an array of gentity
    1967                 :            :  *   handles
    1968                 :            :  */
    1969                 :            : ITAPS_API void
    1970                 :          4 : iGeom_setData( iGeom_Instance instance,
    1971                 :            :                /*in*/ iBase_EntityHandle entity_handle,
    1972                 :            :                /*in*/ iBase_TagHandle tag_handle,
    1973                 :            :                /*in*/ const void *tag_value_tmp,
    1974                 :            :                int tag_value_size,
    1975                 :            :                int* err )
    1976                 :            : {
    1977                 :          4 :   const char *tag_value = reinterpret_cast<const char *>(tag_value_tmp);
    1978                 :          4 :   RefEntity *tmp_entity = ENTITY_HANDLE(entity_handle);
    1979                 :            :   iBase_ErrorType retval = TM->setArrData(&tmp_entity, 1, 
    1980                 :            :                                           TAG_HANDLE(tag_handle), 
    1981         [ +  - ]:          4 :                                           ARRAY_IN(tag_value));
    1982         [ +  - ]:          4 :   RETURN(retval);
    1983                 :            : }
    1984                 :            : 
    1985                 :            : ITAPS_API void
    1986                 :          0 : iGeom_setIntData( iGeom_Instance instance,
    1987                 :            :                   /*in*/ iBase_EntityHandle entity_handle,
    1988                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    1989                 :            :                   /*in*/ int tag_value,
    1990                 :            :                   int* err ) 
    1991                 :            : {
    1992                 :            :   iGeom_setArrData(instance, &entity_handle, 1, 
    1993                 :          0 :                    tag_handle, &tag_value, sizeof(int), err);
    1994                 :          0 : }
    1995                 :            : 
    1996                 :            : ITAPS_API void
    1997                 :          0 : iGeom_setDblData( iGeom_Instance instance,
    1998                 :            :                   /*in*/ iBase_EntityHandle entity_handle,
    1999                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    2000                 :            :                   /*in*/ double tag_value,
    2001                 :            :                   int* err ) 
    2002                 :            : {
    2003                 :            :   iGeom_setArrData(instance, &entity_handle, 1, 
    2004                 :          0 :                    tag_handle, &tag_value, sizeof(double), err);
    2005                 :          0 : }
    2006                 :            : 
    2007                 :            : ITAPS_API void
    2008                 :          0 : iGeom_setEHData( iGeom_Instance instance,
    2009                 :            :                  /*in*/ iBase_EntityHandle entity_handle,
    2010                 :            :                  /*in*/ iBase_TagHandle tag_handle,
    2011                 :            :                  /*in*/ iBase_EntityHandle tag_value,
    2012                 :            :                  int* err ) 
    2013                 :            : {
    2014                 :            :   iGeom_setArrData(instance, &entity_handle, 1, 
    2015                 :          0 :                    tag_handle, &tag_value, sizeof(iBase_EntityHandle), err);
    2016                 :          0 : }
    2017                 :            : 
    2018                 :            : ITAPS_API void
    2019                 :          0 : iGeom_setESHData( iGeom_Instance instance,
    2020                 :            :                   /*in*/ iBase_EntityHandle entity_handle,
    2021                 :            :                   /*in*/ iBase_TagHandle tag_handle,
    2022                 :            :                   /*in*/ iBase_EntitySetHandle tag_value,
    2023                 :            :                   int* err )
    2024                 :            : {
    2025                 :            :   iGeom_setArrData(instance, &entity_handle, 1,
    2026                 :          0 :                    tag_handle, &tag_value, sizeof(iBase_EntitySetHandle), err);
    2027                 :          0 : }
    2028                 :            : 
    2029                 :            : /**
    2030                 :            :  *   Remove the tag associated with the tag_handle from the mesh or
    2031                 :            :  *   gentity_set.  The tag data is not destroyed in this function, but
    2032                 :            :  *   can be destroyed using the deleteTag function.
    2033                 :            :  */
    2034                 :            : ITAPS_API void
    2035                 :          0 : iGeom_rmvEntSetTag( iGeom_Instance instance,
    2036                 :            :                     /*in*/ iBase_EntitySetHandle entity_set,
    2037                 :            :                     /*in*/ iBase_TagHandle tag_handle,
    2038                 :            :                     int* err )
    2039                 :            : {
    2040                 :            :     // have to go through RefEntity* so that RefEntity** gets set right
    2041                 :          0 :   RefEntity *tmp_entity = SET_HANDLE(entity_set);
    2042         [ #  # ]:          0 :   iBase_ErrorType retval = TM->rmvArrTag(&tmp_entity, 1, TAG_HANDLE(tag_handle));
    2043         [ #  # ]:          0 :   RETURN(retval);
    2044                 :            : }
    2045                 :            : 
    2046                 :            : /**
    2047                 :            :  *   Get all tag handles associated with a given mesh or gentity_set.
    2048                 :            :  */
    2049                 :            : ITAPS_API void
    2050                 :          0 : iGeom_getAllEntSetTags( iGeom_Instance instance,
    2051                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2052                 :            :                         /*inout*/ iBase_TagHandle **tag_handles,
    2053                 :            :                         int *tag_handles_allocated,
    2054                 :            :                         int *tag_handles_size,
    2055                 :            :                         int* err )
    2056                 :            : {
    2057                 :            :     // have to go through RefEntity* so that RefEntity** gets set right
    2058                 :          0 :   const RefEntity *tmp_entity = SET_HANDLE(entity_set);
    2059                 :          0 :   iBase_ErrorType retval = TM->getAllTags(tmp_entity,TAG_HANDLE_ARRAY_INOUT(tag_handles));
    2060                 :          0 :   RETURN(retval);
    2061                 :            : }
    2062                 :            : 
    2063                 :            : /**
    2064                 :            :  *   Get the tag data associated with a tag handle from the mesh or
    2065                 :            :  *   gentity_set.  It is assumed that the tag_value argument is
    2066                 :            :  *   allocated by the application before being passed into the getTag
    2067                 :            :  *   function.
    2068                 :            :  */
    2069                 :            : ITAPS_API void
    2070                 :          0 : iGeom_getEntSetData( iGeom_Instance instance,
    2071                 :            :                      /*in*/ iBase_EntitySetHandle entity_set,
    2072                 :            :                      /*in*/ iBase_TagHandle tag_handle,
    2073                 :            :                      /*inout*/ void **tag_value_tmp,
    2074                 :            :                      int *tag_value_allocated,
    2075                 :            :                      int *tag_value_size,
    2076                 :            :                      int* err )
    2077                 :            : {
    2078                 :          0 :   char **tag_value = reinterpret_cast<char **>(tag_value_tmp);
    2079                 :            :     // have to go through RefEntity* so that RefEntity** gets set right
    2080                 :          0 :   RefEntity *tmp_entity = SET_HANDLE(entity_set);
    2081                 :            :   iBase_ErrorType retval = TM->getArrData(&tmp_entity, 1, TAG_HANDLE(tag_handle), 
    2082         [ #  # ]:          0 :                                           ARRAY_INOUT(tag_value));
    2083         [ #  # ]:          0 :   RETURN(retval);
    2084                 :            : }
    2085                 :            : 
    2086                 :            : ITAPS_API void
    2087                 :          0 : iGeom_getEntSetIntData( iGeom_Instance instance,
    2088                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2089                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    2090                 :            :                         int* tag_ptr,
    2091                 :            :                         int* err ) 
    2092                 :            : {
    2093                 :          0 :   int tag_size = sizeof(int);
    2094                 :          0 :   void* data_ptr = tag_ptr;
    2095                 :            :   iGeom_getEntSetData(instance, entity_set, tag_handle, &data_ptr, 
    2096         [ #  # ]:          0 :                       &tag_size, &tag_size, err);
    2097                 :          0 : }
    2098                 :            : 
    2099                 :            : ITAPS_API void
    2100                 :          0 : iGeom_getEntSetDblData( iGeom_Instance instance,
    2101                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2102                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    2103                 :            :                         double* tag_ptr,
    2104                 :            :                         int* err ) 
    2105                 :            : {
    2106                 :          0 :   int tag_size = sizeof(double);
    2107                 :          0 :   void* data_ptr = tag_ptr;
    2108                 :            :   iGeom_getEntSetData(instance, entity_set, tag_handle, &data_ptr, 
    2109         [ #  # ]:          0 :                       &tag_size, &tag_size, err);
    2110                 :          0 : }
    2111                 :            : 
    2112                 :            : ITAPS_API void
    2113                 :          0 : iGeom_getEntSetEHData( iGeom_Instance instance,
    2114                 :            :                        /*in*/ iBase_EntitySetHandle entity_set,
    2115                 :            :                        /*in*/ iBase_TagHandle tag_handle,
    2116                 :            :                        iBase_EntityHandle* tag_ptr,
    2117                 :            :                        int* err ) 
    2118                 :            : {
    2119                 :          0 :   int tag_size = sizeof(iBase_EntityHandle);
    2120                 :          0 :   void* data_ptr = tag_ptr;
    2121                 :            :   iGeom_getEntSetData(instance, entity_set, tag_handle, &data_ptr, 
    2122         [ #  # ]:          0 :                       &tag_size, &tag_size, err);
    2123                 :          0 : }
    2124                 :            : 
    2125                 :            : ITAPS_API void
    2126                 :          0 : iGeom_getEntSetESHData( iGeom_Instance instance,
    2127                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2128                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    2129                 :            :                         iBase_EntitySetHandle* tag_ptr,
    2130                 :            :                         int* err )
    2131                 :            : {
    2132                 :          0 :   int tag_size = sizeof(iBase_EntitySetHandle);
    2133                 :          0 :   void* data_ptr = tag_ptr;
    2134                 :            :   iGeom_getEntSetData(instance, entity_set, tag_handle, &data_ptr,
    2135         [ #  # ]:          0 :                       &tag_size, &tag_size, err);
    2136                 :          0 : }
    2137                 :            : 
    2138                 :            : /**
    2139                 :            :  *   Set the tag data associated with a given tag handle on the mesh or
    2140                 :            :  *   gentity_set
    2141                 :            :  */
    2142                 :            : ITAPS_API void
    2143                 :          0 : iGeom_setEntSetData( iGeom_Instance instance,
    2144                 :            :                      /*in*/ iBase_EntitySetHandle entity_set,
    2145                 :            :                      /*in*/ iBase_TagHandle tag_handle,
    2146                 :            :                      /*in*/ const void *tag_value_tmp,
    2147                 :            :                      int tag_value_size,
    2148                 :            :                      int* err )
    2149                 :            : {
    2150                 :          0 :   const char *tag_value = reinterpret_cast<const char *>(tag_value_tmp);
    2151                 :            :     // have to go through RefEntity* so that RefEntity** gets set right
    2152                 :          0 :   RefEntity *tmp_entity = SET_HANDLE(entity_set);
    2153                 :            :   iBase_ErrorType retval = TM->setArrData(&tmp_entity, 1, TAG_HANDLE(tag_handle), 
    2154         [ #  # ]:          0 :                                           ARRAY_IN(tag_value));
    2155         [ #  # ]:          0 :   RETURN(retval);
    2156                 :            : }
    2157                 :            : 
    2158                 :            : ITAPS_API void
    2159                 :          0 : iGeom_setEntSetIntData( iGeom_Instance instance,
    2160                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2161                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    2162                 :            :                         /*in*/ int tag_value,
    2163                 :            :                         int* err )
    2164                 :            : {
    2165                 :            :   iGeom_setEntSetData(instance, entity_set, tag_handle, 
    2166                 :          0 :                       &tag_value, sizeof(int), err);
    2167                 :          0 : }
    2168                 :            : 
    2169                 :            : ITAPS_API void
    2170                 :          0 : iGeom_setEntSetDblData( iGeom_Instance instance,
    2171                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2172                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    2173                 :            :                         /*in*/ double tag_value,
    2174                 :            :                         int* err )
    2175                 :            : {
    2176                 :            :   iGeom_setEntSetData(instance, entity_set, tag_handle, 
    2177                 :          0 :                       &tag_value, sizeof(double), err);
    2178                 :          0 : }
    2179                 :            : 
    2180                 :            : ITAPS_API void
    2181                 :          0 : iGeom_setEntSetEHData( iGeom_Instance instance,
    2182                 :            :                        /*in*/ iBase_EntitySetHandle entity_set,
    2183                 :            :                        /*in*/ iBase_TagHandle tag_handle,
    2184                 :            :                        /*in*/ iBase_EntityHandle tag_value,
    2185                 :            :                        int* err )
    2186                 :            : {
    2187                 :            :   iGeom_setEntSetData(instance, entity_set, tag_handle, 
    2188                 :            :                       &tag_value,
    2189                 :          0 :                       sizeof(iBase_EntityHandle), err);
    2190                 :          0 : }
    2191                 :            : 
    2192                 :            : ITAPS_API void
    2193                 :          0 : iGeom_setEntSetESHData( iGeom_Instance instance,
    2194                 :            :                         /*in*/ iBase_EntitySetHandle entity_set,
    2195                 :            :                         /*in*/ iBase_TagHandle tag_handle,
    2196                 :            :                         /*in*/ iBase_EntitySetHandle tag_value,
    2197                 :            :                         int* err )
    2198                 :            : {
    2199                 :            :   iGeom_setEntSetData(instance, entity_set, tag_handle,
    2200                 :          0 :                       &tag_value, sizeof(iBase_EntitySetHandle), err);
    2201                 :          0 : }
    2202                 :            : 
    2203                 :            : ITAPS_API void
    2204                 :          0 : iGeom_getEntClosestPt( iGeom_Instance instance,
    2205                 :            :                        /*in*/ iBase_EntityHandle entity_handle,
    2206                 :            :                        /*in*/ double near_x,
    2207                 :            :                        /*in*/ double near_y,
    2208                 :            :                        /*in*/ double near_z,
    2209                 :            :                        /*out*/ double* on_x,
    2210                 :            :                        /*out*/ double* on_y, 
    2211                 :            :                        /*out*/ double* on_z,
    2212                 :            :                        int* err )
    2213                 :            : {
    2214                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    2215 [ #  # ][ #  # ]:          0 :   CubitVector on, near(near_x, near_y, near_z);
    2216         [ #  # ]:          0 :   CubitStatus status = iGeom_closest_point( entity, near, on );
    2217         [ #  # ]:          0 :   if (status == CUBIT_FAILURE) {
    2218         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Problems getting closest point for some entity.");
    2219                 :            :   }
    2220         [ #  # ]:          0 :   on.get_xyz( *on_x, *on_y, *on_z );
    2221         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2222                 :            : }
    2223                 :            : 
    2224                 :            : ITAPS_API void
    2225                 :          0 : iGeom_getEntClosestPtTrimmed( iGeom_Instance instance,
    2226                 :            :                               iBase_EntityHandle entity_handle,
    2227                 :            :                               double near_x,
    2228                 :            :                               double near_y,
    2229                 :            :                               double near_z,
    2230                 :            :                               double* on_x,
    2231                 :            :                               double* on_y,
    2232                 :            :                               double* on_z,
    2233                 :            :                               int* err )
    2234                 :            : {
    2235                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    2236 [ #  # ][ #  # ]:          0 :   CubitVector on, near(near_x, near_y, near_z);
    2237         [ #  # ]:          0 :   CubitStatus status = iGeom_closest_point_trimmed( entity, near, on );
    2238         [ #  # ]:          0 :   if (status == CUBIT_FAILURE) {
    2239         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Problems getting closest point for some entity.");
    2240                 :            :   }
    2241         [ #  # ]:          0 :   on.get_xyz( *on_x, *on_y, *on_z );
    2242         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2243                 :            : }
    2244                 :            :  
    2245                 :            : /**
    2246                 :            :  * Return a points on specified entities closest to specified points
    2247                 :            :  * in space.  Input coordinates and output points are interleaved in 
    2248                 :            :  * the arrays.
    2249                 :            :  * @param gentity_handles The gentities being queried
    2250                 :            :  * @param near_coordinates Input coordinates
    2251                 :            :  * @param on_coordinates Closest point on gentity
    2252                 :            :  */
    2253                 :            : ITAPS_API void
    2254                 :          0 : iGeom_getArrClosestPt( iGeom_Instance instance,
    2255                 :            :                        /*in*/ iBase_EntityHandle const *gentity_handles,
    2256                 :            :                        int gentity_handles_size,
    2257                 :            :                        /*in*/ int storage_order,
    2258                 :            :                        /*in*/ const double *near_coordinates,
    2259                 :            :                        int near_coordinates_size,
    2260                 :            :                        /*out*/ double **on_coordinates,
    2261                 :            :                        int *on_coordinates_allocated,
    2262                 :            :                        int *on_coordinates_size,
    2263                 :            :                        int* err )
    2264                 :            : {
    2265                 :            :     /* set up iteration according to storage order.
    2266                 :            :        allow either gentity_handles or near_coordinates to contain
    2267                 :            :        only one value, where that single value is applied for every
    2268                 :            :        entry in the other list.
    2269                 :            :     */
    2270                 :          0 :   size_t near_step, on_step = 1, ent_step;
    2271                 :            :   int count;
    2272         [ #  # ]:          0 :   if (3*gentity_handles_size == near_coordinates_size) {
    2273                 :          0 :     near_step = ent_step = 1;
    2274                 :          0 :     count = gentity_handles_size;
    2275                 :            :   }
    2276         [ #  # ]:          0 :   else if (near_coordinates_size == 3) {
    2277                 :          0 :     near_step = 0;
    2278                 :          0 :     ent_step = 1;
    2279                 :          0 :     count = gentity_handles_size;
    2280                 :            :   }
    2281         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    2282                 :          0 :     near_step = 1;
    2283                 :          0 :     ent_step = 0;
    2284                 :          0 :     count = near_coordinates_size / 3;
    2285                 :            :   }
    2286                 :            :   else {
    2287         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    2288                 :            :   }
    2289 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( on_coordinates, 3*count );
    2290                 :            :   
    2291                 :            :   const double *near_x, *near_y, *near_z;
    2292                 :            :   double *on_x, *on_y, *on_z;
    2293         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    2294                 :          0 :     near_x = near_coordinates;
    2295                 :          0 :     near_y = near_x + near_coordinates_size/3;
    2296                 :          0 :     near_z = near_y + near_coordinates_size/3;
    2297                 :          0 :     on_x = *on_coordinates;
    2298                 :          0 :     on_y = on_x + count;
    2299                 :          0 :     on_z = on_y + count;
    2300                 :          0 :     on_step = 1;
    2301                 :            :   }
    2302                 :            :   else {
    2303                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    2304                 :          0 :     near_x = near_coordinates;
    2305                 :          0 :     near_y = near_x+1;
    2306                 :          0 :     near_z = near_x+2;
    2307                 :          0 :     on_x = *on_coordinates;
    2308                 :          0 :     on_y = on_x+1;
    2309                 :          0 :     on_z = on_x+2;
    2310                 :          0 :     near_step *= 3;
    2311                 :          0 :     on_step = 3;
    2312                 :            :   }
    2313                 :            :   
    2314                 :          0 :   RefEntity** ent_iter = (RefEntity**)(gentity_handles);
    2315                 :          0 :   CubitStatus final_result = CUBIT_SUCCESS;
    2316         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    2317 [ #  # ][ #  # ]:          0 :     CubitVector on, near( *near_x, *near_y, *near_z );
    2318         [ #  # ]:          0 :     CubitStatus status = iGeom_closest_point( *ent_iter, near, on );
    2319         [ #  # ]:          0 :     if (status != CUBIT_SUCCESS)
    2320                 :          0 :       final_result = status;
    2321         [ #  # ]:          0 :     on.get_xyz( *on_x, *on_y, *on_z );
    2322                 :            :     
    2323                 :          0 :     ent_iter += ent_step;
    2324                 :          0 :     near_x += near_step;
    2325                 :          0 :     near_y += near_step;
    2326                 :          0 :     near_z += near_step;
    2327                 :          0 :     on_x += on_step;
    2328                 :          0 :     on_y += on_step;
    2329                 :          0 :     on_z += on_step;
    2330                 :            :   }
    2331                 :            :   
    2332         [ #  # ]:          0 :   if (final_result == CUBIT_FAILURE) {
    2333         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Problems getting closest point for some entity.");
    2334                 :            :   }
    2335                 :            : 
    2336         [ #  # ]:          0 :   KEEP_ARRAY(on_coordinates);
    2337 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2338                 :            : }
    2339                 :            : 
    2340                 :            : 
    2341                 :            : ITAPS_API void
    2342                 :          6 : iGeom_getEntNrmlPlXYZ( iGeom_Instance instance,
    2343                 :            :                        /*in*/ iBase_EntityHandle entity_handle,
    2344                 :            :                        /*in*/ double x,
    2345                 :            :                        /*in*/ double y,
    2346                 :            :                        /*in*/ double z,
    2347                 :            :                        /*out*/ double* pt_x,
    2348                 :            :                        /*out*/ double* pt_y, 
    2349                 :            :                        /*out*/ double* pt_z,
    2350                 :            :                        /*out*/ double* nmrl_i,
    2351                 :            :                        /*out*/ double* nmrl_j, 
    2352                 :            :                        /*out*/ double* nmrl_k,
    2353                 :            :                        int* err )
    2354                 :            : {
    2355                 :          6 :   RefEntity* entity = (RefEntity*)entity_handle;
    2356 [ +  - ][ +  - ]:          6 :   CubitVector pt, nmrl, near(x, y, z);
                 [ +  - ]
    2357         [ +  - ]:          6 :   CubitStatus status = iGeom_closest_point_and_normal( entity, near, pt, nmrl );
    2358         [ -  + ]:          6 :   if (status == CUBIT_FAILURE) {
    2359         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Problems getting closest point for some entity.");
    2360                 :            :   }
    2361         [ +  - ]:          6 :   pt.get_xyz( *pt_x, *pt_y, *pt_z );
    2362         [ +  - ]:          6 :   nmrl.get_xyz( *nmrl_i, *nmrl_j, *nmrl_k );
    2363         [ +  - ]:          6 :   RETURN(iBase_SUCCESS);
    2364                 :            : }
    2365                 :            : 
    2366                 :            : /**
    2367                 :            :  * Return a points on specified entities closest to specified points
    2368                 :            :  * in space, and normals at that point.  Input coordinates and output points are 
    2369                 :            :  * interleaved in 
    2370                 :            :  * the arrays.
    2371                 :            :  * @param gentity_handles The gentities being queried
    2372                 :            :  * @param near_coordinates Input coordinates
    2373                 :            :  * @param on_coordinates Closest point on gentity
    2374                 :            :  */
    2375                 :            : ITAPS_API void
    2376                 :          0 : iGeom_getArrNrmlPlXYZ( iGeom_Instance instance,
    2377                 :            :                        /*in*/ iBase_EntityHandle const *gentity_handles,
    2378                 :            :                        const int gentity_handles_size,
    2379                 :            :                        /*in*/ int storage_order,
    2380                 :            :                        /*in*/ const double *near_coordinates,
    2381                 :            :                        const int near_coordinates_size,
    2382                 :            :                        /*out*/ double **on_coordinates,
    2383                 :            :                        int *on_coordinates_allocated,
    2384                 :            :                        int *on_coordinates_size,
    2385                 :            :                        /*out*/ double **normals,
    2386                 :            :                        int *normals_allocated,
    2387                 :            :                        int *normals_size,
    2388                 :            :                        int* err )
    2389                 :            : {
    2390                 :            :     /* set up iteration according to storage order.
    2391                 :            :        allow either gentity_handles or near_coordinates to contain
    2392                 :            :        only one value, where that single value is applied for every
    2393                 :            :        entry in the other list.
    2394                 :            :     */
    2395                 :          0 :   size_t near_step, on_step = 1, ent_step;
    2396                 :            :   int count;
    2397         [ #  # ]:          0 :   if (3*gentity_handles_size == near_coordinates_size) {
    2398                 :          0 :     near_step = ent_step = 1;
    2399                 :          0 :     count = gentity_handles_size;
    2400                 :            :   }
    2401         [ #  # ]:          0 :   else if (near_coordinates_size == 3) {
    2402                 :          0 :     near_step = 0;
    2403                 :          0 :     ent_step = 1;
    2404                 :          0 :     count = gentity_handles_size;
    2405                 :            :   }
    2406         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    2407                 :          0 :     near_step = 1;
    2408                 :          0 :     ent_step = 0;
    2409                 :          0 :     count = near_coordinates_size / 3;
    2410                 :            :   }
    2411                 :            :   else {
    2412         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    2413                 :            :   }
    2414 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( on_coordinates, 3*count );
    2415 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( normals, 3*count );
                 [ #  # ]
    2416                 :            :   
    2417                 :            :   const double *near_x, *near_y, *near_z;
    2418                 :            :   double *on_x, *on_y, *on_z;
    2419                 :            :   double *norm_x, *norm_y, *norm_z;
    2420         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    2421                 :          0 :     near_x = near_coordinates;
    2422                 :          0 :     near_y = near_x + near_coordinates_size/3;
    2423                 :          0 :     near_z = near_y + near_coordinates_size/3;
    2424                 :          0 :     on_x = *on_coordinates;
    2425                 :          0 :     on_y = on_x + count;
    2426                 :          0 :     on_z = on_y + count;
    2427                 :          0 :     norm_x = *normals;
    2428                 :          0 :     norm_y = norm_x + count;
    2429                 :          0 :     norm_z = norm_y + count;
    2430                 :          0 :     on_step = 1;
    2431                 :            :   }
    2432                 :            :   else {
    2433                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    2434                 :          0 :     near_x = near_coordinates;
    2435                 :          0 :     near_y = near_x+1;
    2436                 :          0 :     near_z = near_x+2;
    2437                 :          0 :     on_x = *on_coordinates;
    2438                 :          0 :     on_y = on_x+1;
    2439                 :          0 :     on_z = on_x+2;
    2440                 :          0 :     norm_x = *normals;
    2441                 :          0 :     norm_y = norm_x+1;
    2442                 :          0 :     norm_z = norm_x+2;
    2443                 :          0 :     near_step *= 3;
    2444                 :          0 :     on_step = 3;
    2445                 :            :   }
    2446                 :            :   
    2447                 :          0 :   RefEntity** ent_iter = (RefEntity**)(gentity_handles);
    2448                 :          0 :   CubitStatus final_result = CUBIT_SUCCESS;
    2449         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    2450 [ #  # ][ #  # ]:          0 :     CubitVector on, norm, near( *near_x, *near_y, *near_z );
                 [ #  # ]
    2451         [ #  # ]:          0 :     CubitStatus status = iGeom_closest_point_and_normal( *ent_iter, near, on, norm );
    2452         [ #  # ]:          0 :     if (status != CUBIT_SUCCESS)
    2453                 :          0 :       final_result = status;
    2454         [ #  # ]:          0 :     on.get_xyz( *on_x, *on_y, *on_z );
    2455         [ #  # ]:          0 :     norm.get_xyz( *norm_x, *norm_y, *norm_z );
    2456                 :            :     
    2457                 :          0 :     ent_iter += ent_step;
    2458                 :          0 :     near_x += near_step;
    2459                 :          0 :     near_y += near_step;
    2460                 :          0 :     near_z += near_step;
    2461                 :          0 :     on_x += on_step;
    2462                 :          0 :     on_y += on_step;
    2463                 :          0 :     on_z += on_step;
    2464                 :          0 :     norm_x += on_step;
    2465                 :          0 :     norm_y += on_step;
    2466                 :          0 :     norm_z += on_step;
    2467                 :            :   }
    2468                 :            :   
    2469         [ #  # ]:          0 :   if (final_result == CUBIT_FAILURE) {
    2470         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Problems getting closest point for some entity.");
    2471                 :            :   }
    2472                 :            : 
    2473         [ #  # ]:          0 :   KEEP_ARRAY(on_coordinates);
    2474         [ #  # ]:          0 :   KEEP_ARRAY(normals);
    2475 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2476                 :            : }
    2477                 :            : 
    2478                 :            : ITAPS_API void
    2479                 :          0 : iGeom_getEntNrmlXYZ( iGeom_Instance instance,
    2480                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    2481                 :            :                      /*in*/ double near_x,
    2482                 :            :                      /*in*/ double near_y,
    2483                 :            :                      /*in*/ double near_z,
    2484                 :            :                      /*out*/ double* nmrl_i,
    2485                 :            :                      /*out*/ double* nmrl_j, 
    2486                 :            :                      /*out*/ double* nmrl_k,
    2487                 :            :                      int* err )
    2488                 :            : {
    2489                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    2490         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    2491         [ #  # ]:          0 :   if (NULL == face) {
    2492         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Entities passed into gentityNormal must be faces.");
    2493                 :            :   }
    2494                 :            :   
    2495 [ #  # ][ #  # ]:          0 :   CubitVector normal, near( near_x, near_y, near_z );
    2496 [ #  # ][ #  # ]:          0 :   normal = face->normal_at( near );
    2497         [ #  # ]:          0 :   normal.get_xyz( *nmrl_i, *nmrl_j, *nmrl_k );
    2498         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2499                 :            : } 
    2500                 :            : 
    2501                 :            : /**
    2502                 :            :  * Return the normals at point on specified entities.  Returns error
    2503                 :            :  * if any input entity is not a gface.  Input coordinates and normals
    2504                 :            :  * are interleaved in the arrays.
    2505                 :            :  * @param gentity_handles The gentities being queried
    2506                 :            :  * @param coordinates Input coordinates, interleaved
    2507                 :            :  * @param normals The normals at the specified points, interleaved
    2508                 :            :  */
    2509                 :            : ITAPS_API void
    2510                 :          0 : iGeom_getArrNrmlXYZ( iGeom_Instance instance,
    2511                 :            :                      /*in*/ iBase_EntityHandle const *gentity_handles,
    2512                 :            :                      int gentity_handles_size,
    2513                 :            :                      int storage_order,
    2514                 :            :                      /*in*/ const double *coordinates,
    2515                 :            :                      int coordinates_size,
    2516                 :            :                      /*out*/ double **normals,
    2517                 :            :                      int *normals_allocated,
    2518                 :            :                      int *normals_size,
    2519                 :            :                      int* err )
    2520                 :            : {
    2521                 :            :     /* set up iteration according to storage order.
    2522                 :            :        allow either gentity_handles or near_coordinates to contain
    2523                 :            :        only one value, where that single value is applied for every
    2524                 :            :        entry in the other list.
    2525                 :            :     */
    2526                 :          0 :   size_t coord_step, norm_step = 1, ent_step;
    2527                 :            :   int count;
    2528         [ #  # ]:          0 :   if (3*gentity_handles_size == coordinates_size) {
    2529                 :          0 :     coord_step = ent_step = 1;
    2530                 :          0 :     count = gentity_handles_size;
    2531                 :            :   }
    2532         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    2533                 :          0 :     coord_step = 0;
    2534                 :          0 :     ent_step = 1;
    2535                 :          0 :     count = gentity_handles_size;
    2536                 :            :   }
    2537         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    2538                 :          0 :     coord_step = 1;
    2539                 :          0 :     ent_step = 0;
    2540                 :          0 :     count = coordinates_size / 3;
    2541                 :            :   }
    2542                 :            :   else {
    2543         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    2544                 :            :   }
    2545                 :            : 
    2546                 :            :     // check or pre-allocate the coordinate arrays
    2547 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( normals, 3*count );
    2548                 :            :   
    2549                 :            :   const double *coord_x, *coord_y, *coord_z;
    2550                 :            :   double *norm_x, *norm_y, *norm_z;
    2551         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    2552                 :          0 :     coord_x = coordinates;
    2553                 :          0 :     coord_y = coord_x + coordinates_size/3;
    2554                 :          0 :     coord_z = coord_y + coordinates_size/3;
    2555                 :          0 :     norm_x = *normals;
    2556                 :          0 :     norm_y = norm_x + count;
    2557                 :          0 :     norm_z = norm_y + count;
    2558                 :          0 :     norm_step = 1;
    2559                 :            :   }
    2560                 :            :   else {
    2561                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    2562                 :          0 :     coord_x = coordinates;
    2563                 :          0 :     coord_y = coord_x+1;
    2564                 :          0 :     coord_z = coord_x+2;
    2565                 :          0 :     norm_x = *normals;
    2566                 :          0 :     norm_y = norm_x+1;
    2567                 :          0 :     norm_z = norm_x+2;
    2568                 :          0 :     coord_step *= 3;
    2569                 :          0 :     norm_step = 3;
    2570                 :            :   }
    2571                 :            :   
    2572                 :          0 :   RefEntity** entities = (RefEntity**)(gentity_handles);
    2573         [ #  # ]:          0 :   for (int i = 0; i < count; ++i)
    2574                 :            :   {
    2575         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*entities);
    2576         [ #  # ]:          0 :     if (NULL == face) {
    2577         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Entities passed into gentityNormal must be faces.");
    2578                 :            :     }
    2579                 :            :     else {
    2580 [ #  # ][ #  # ]:          0 :       CubitVector normal, coords( *coord_x, *coord_y, *coord_z );
    2581 [ #  # ][ #  # ]:          0 :       normal = face->normal_at( coords );
    2582         [ #  # ]:          0 :       normal.get_xyz( *norm_x, *norm_y, *norm_z );
    2583                 :            :     }
    2584                 :          0 :     entities += ent_step;
    2585                 :          0 :     coord_x += coord_step;
    2586                 :          0 :     coord_y += coord_step;
    2587                 :          0 :     coord_z += coord_step;
    2588                 :          0 :     norm_x += norm_step;
    2589                 :          0 :     norm_y += norm_step;
    2590                 :          0 :     norm_z += norm_step;
    2591                 :            :   }
    2592                 :            : 
    2593         [ #  # ]:          0 :   KEEP_ARRAY(normals);
    2594 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2595                 :            : }
    2596                 :            : 
    2597                 :            : 
    2598                 :            : ITAPS_API void
    2599                 :          0 : iGeom_getEntTgntXYZ( iGeom_Instance instance,
    2600                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    2601                 :            :                      /*in*/ double x,
    2602                 :            :                      /*in*/ double y,
    2603                 :            :                      /*in*/ double z,
    2604                 :            :                      /*out*/ double* tgnt_i,
    2605                 :            :                      /*out*/ double* tgnt_j, 
    2606                 :            :                      /*out*/ double* tgnt_k,
    2607                 :            :                      int* err )
    2608                 :            : {
    2609                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    2610         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>(entity);
    2611         [ #  # ]:          0 :   if (NULL == edge) {
    2612         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Entities passed into gentityTangent must be edges.");
    2613                 :            :   }
    2614                 :            :   
    2615 [ #  # ][ #  # ]:          0 :   CubitVector tangent, near( x, y, x );
    2616         [ #  # ]:          0 :   edge->tangent( near, tangent );
    2617         [ #  # ]:          0 :   tangent.get_xyz( *tgnt_i, *tgnt_j, *tgnt_k );
    2618         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2619                 :            : } 
    2620                 :            : 
    2621                 :            : /**
    2622                 :            :  * Return the tangent at point on specified entities.  Returns error
    2623                 :            :  * if any input entity is not a gedge.  Input coordinates and tangents
    2624                 :            :  * are interleaved in the arrays.
    2625                 :            :  * @param gentity_handles The gentities being queried
    2626                 :            :  * @param coordinates Input coordinates, interleaved
    2627                 :            :  * @param tangents The tangents at the specified points, interleaved
    2628                 :            :  */
    2629                 :            : ITAPS_API void
    2630                 :          0 : iGeom_getArrTgntXYZ( iGeom_Instance instance,
    2631                 :            :                      /*in*/ iBase_EntityHandle const *gentity_handles,
    2632                 :            :                      int gentity_handles_size,
    2633                 :            :                      /*in*/ int storage_order,
    2634                 :            :                      /*in*/ const double *coordinates,
    2635                 :            :                      int coordinates_size,
    2636                 :            :                      /*out*/ double **tangents,
    2637                 :            :                      int *tangents_allocated,
    2638                 :            :                      int *tangents_size,
    2639                 :            :                      int* err )
    2640                 :            : {
    2641                 :            :     /* set up iteration according to storage order.
    2642                 :            :        allow either gentity_handles or near_coordinates to contain
    2643                 :            :        only one value, where that single value is applied for every
    2644                 :            :        entry in the other list.
    2645                 :            :     */
    2646                 :          0 :   size_t coord_step, tan_step = 1, ent_step;
    2647                 :            :   int count;
    2648         [ #  # ]:          0 :   if (3*gentity_handles_size == coordinates_size) {
    2649                 :          0 :     coord_step = ent_step = 1;
    2650                 :          0 :     count = gentity_handles_size;
    2651                 :            :   }
    2652         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    2653                 :          0 :     coord_step = 0;
    2654                 :          0 :     ent_step = 1;
    2655                 :          0 :     count = gentity_handles_size;
    2656                 :            :   }
    2657         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    2658                 :          0 :     coord_step = 1;
    2659                 :          0 :     ent_step = 0;
    2660                 :          0 :     count = coordinates_size / 3;
    2661                 :            :   }
    2662                 :            :   else {
    2663         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    2664                 :            :   }
    2665                 :            : 
    2666                 :            :     // check or pre-allocate the coordinate arrays
    2667 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( tangents, 3*count );
    2668                 :            :   
    2669                 :            :   const double *coord_x, *coord_y, *coord_z;
    2670                 :            :   double *tan_x, *tan_y, *tan_z;
    2671         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    2672                 :          0 :     coord_x = coordinates;
    2673                 :          0 :     coord_y = coord_x + coordinates_size/3;
    2674                 :          0 :     coord_z = coord_y + coordinates_size/3;
    2675                 :          0 :     tan_x = *tangents;
    2676                 :          0 :     tan_y = tan_x + count;
    2677                 :          0 :     tan_z = tan_y + count;
    2678                 :          0 :     tan_step = 1;
    2679                 :            :   }
    2680                 :            :   else {
    2681                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    2682                 :          0 :     coord_x = coordinates;
    2683                 :          0 :     coord_y = coord_x+1;
    2684                 :          0 :     coord_z = coord_x+2;
    2685                 :          0 :     tan_x = *tangents;
    2686                 :          0 :     tan_y = tan_x+1;
    2687                 :          0 :     tan_z = tan_x+2;
    2688                 :          0 :     coord_step *= 3;
    2689                 :          0 :     tan_step = 3;
    2690                 :            :   }
    2691                 :            :   
    2692                 :          0 :   RefEntity** entities = (RefEntity**)(gentity_handles);
    2693         [ #  # ]:          0 :   for (int i = 0; i < count; ++i)
    2694                 :            :   {
    2695         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*entities);
    2696         [ #  # ]:          0 :     if (NULL == edge) {
    2697         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Entities passed into gentityTangent must be edges.");
    2698                 :            :     }
    2699                 :            :     else {
    2700 [ #  # ][ #  # ]:          0 :       CubitVector tangent, coords( *coord_x, *coord_y, *coord_z );
    2701         [ #  # ]:          0 :       edge->tangent( coords, tangent );
    2702         [ #  # ]:          0 :       tangent.get_xyz( *tan_x, *tan_y, *tan_z );
    2703                 :            :     }
    2704                 :            :     
    2705                 :          0 :     entities += ent_step;
    2706                 :          0 :     coord_x += coord_step;
    2707                 :          0 :     coord_y += coord_step;
    2708                 :          0 :     coord_z += coord_step;
    2709                 :          0 :     tan_x += tan_step;
    2710                 :          0 :     tan_y += tan_step;
    2711                 :          0 :     tan_z += tan_step;
    2712                 :            :   }
    2713                 :            : 
    2714         [ #  # ]:          0 :   KEEP_ARRAY(tangents);
    2715 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    2716                 :            : }
    2717                 :            : 
    2718                 :            : 
    2719                 :            : ITAPS_API void
    2720                 :          0 : iGeom_getFcCvtrXYZ( iGeom_Instance instance,
    2721                 :            :                     /*in*/ iBase_EntityHandle face_handle,
    2722                 :            :                     /*in*/ double x,
    2723                 :            :                     /*in*/ double y,
    2724                 :            :                     /*in*/ double z,
    2725                 :            :                     /*out*/ double* cvtr1_i,
    2726                 :            :                     /*out*/ double* cvtr1_j,
    2727                 :            :                     /*out*/ double* cvtr1_k,
    2728                 :            :                     /*out*/ double* cvtr2_i,
    2729                 :            :                     /*out*/ double* cvtr2_j,
    2730                 :            :                     /*out*/ double* cvtr2_k,
    2731                 :            :                     int* err )
    2732                 :            : {
    2733                 :          0 :   RefEntity* entity = (RefEntity*)face_handle;
    2734         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    2735         [ #  # ]:          0 :   if (!face)
    2736         [ #  # ]:          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    2737                 :            :   
    2738         [ #  # ]:          0 :   Surface* surf = face->get_surface_ptr();
    2739 [ #  # ][ #  # ]:          0 :   CubitVector loc(x,y,z), curv1, curv2;
                 [ #  # ]
    2740         [ #  # ]:          0 :   CubitStatus status = surf->closest_point( loc, 0, 0, &curv1, &curv2 );
    2741 [ #  # ][ #  # ]:          0 :   if (surf->bridge_sense() == CUBIT_REVERSED) {
    2742 [ #  # ][ #  # ]:          0 :     curv1 = -curv1;
    2743 [ #  # ][ #  # ]:          0 :     curv2 = -curv2;
    2744                 :            :   }
    2745         [ #  # ]:          0 :   curv1.get_xyz( *cvtr1_i, *cvtr1_j, *cvtr1_k );
    2746         [ #  # ]:          0 :   curv2.get_xyz( *cvtr2_i, *cvtr2_j, *cvtr2_k );
    2747 [ #  # ][ #  # ]:          0 :   RETURN( (status == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    2748                 :            : }
    2749                 :            : 
    2750                 :            : ITAPS_API void
    2751                 :          0 : iGeom_getEgCvtrXYZ( iGeom_Instance instance,
    2752                 :            :                     /*in*/ iBase_EntityHandle edge_handle,
    2753                 :            :                     /*in*/ double x,
    2754                 :            :                     /*in*/ double y,
    2755                 :            :                     /*in*/ double z,
    2756                 :            :                     /*out*/ double* cvtr_i,
    2757                 :            :                     /*out*/ double* cvtr_j,
    2758                 :            :                     /*out*/ double* cvtr_k,
    2759                 :            :                     int* err )
    2760                 :            : {
    2761                 :          0 :   RefEntity* entity = (RefEntity*)edge_handle;
    2762         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>(entity);
    2763         [ #  # ]:          0 :   if (!edge)
    2764         [ #  # ]:          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    2765                 :            :   
    2766 [ #  # ][ #  # ]:          0 :   CubitVector loc(x,y,z), junk, curv;
                 [ #  # ]
    2767         [ #  # ]:          0 :   CubitStatus status = edge->closest_point( loc, junk, 0, &curv );
    2768         [ #  # ]:          0 :   curv.get_xyz( *cvtr_i, *cvtr_j, *cvtr_k );
    2769 [ #  # ][ #  # ]:          0 :   RETURN( (status == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    2770                 :            : }
    2771                 :            : 
    2772                 :            : ITAPS_API void
    2773                 :          0 : iGeom_getEntArrCvtrXYZ( iGeom_Instance instance,
    2774                 :            :                         /*in*/ const iBase_EntityHandle *entity_handles,
    2775                 :            :                         int entity_handles_size,
    2776                 :            :                         /*in*/ int storage_order,
    2777                 :            :                         /*in*/ const double *coordinates,
    2778                 :            :                         int coordinates_size,
    2779                 :            :                         /*inout*/ double **cvtr_1,
    2780                 :            :                         int *cvtr_1_allocated,
    2781                 :            :                         int *cvtr_1_size,
    2782                 :            :                         /*inout*/ double **cvtr_2,
    2783                 :            :                         int *cvtr_2_allocated,
    2784                 :            :                         int *cvtr_2_size,
    2785                 :            :                         int* err )
    2786                 :            : {
    2787                 :          0 :   RefEntity** entities = (RefEntity**)(entity_handles);
    2788                 :            :   
    2789                 :            :     /* set up iteration according to storage order.
    2790                 :            :        allow either gentity_handles or near_coordinates to contain
    2791                 :            :        only one value, where that single value is applied for every
    2792                 :            :        entry in the other list.
    2793                 :            :     */
    2794                 :          0 :   size_t coord_step, cvtr_step = 1, ent_step;
    2795                 :            :   int count;
    2796         [ #  # ]:          0 :   if (3*entity_handles_size == coordinates_size) {
    2797                 :          0 :     coord_step = ent_step = 1;
    2798                 :          0 :     count = entity_handles_size;
    2799                 :            :   }
    2800         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    2801                 :          0 :     coord_step = 0;
    2802                 :          0 :     ent_step = 1;
    2803                 :          0 :     count = entity_handles_size;
    2804                 :            :   }
    2805         [ #  # ]:          0 :   else if (entity_handles_size == 1) {
    2806                 :          0 :     coord_step = 1;
    2807                 :          0 :     ent_step = 0;
    2808                 :          0 :     count = coordinates_size / 3;
    2809                 :            :   }
    2810                 :            :   else {
    2811         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    2812                 :            :   }
    2813                 :            :   
    2814                 :            :     /* check if input list contains any surfaces. */
    2815                 :          0 :   bool have_surfs = false;
    2816         [ #  # ]:          0 :   for (int s = 0; s < entity_handles_size; ++s)
    2817 [ #  # ][ #  # ]:          0 :     if (dynamic_cast<RefFace*>(entities[s])) {
                 [ #  # ]
    2818                 :          0 :       have_surfs = true;
    2819                 :          0 :       break;
    2820                 :            :     }
    2821                 :            : 
    2822                 :            :     // check or pre-allocate the coordinate arrays
    2823 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( cvtr_1, 3*count );
    2824 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( cvtr_2, have_surfs ? 3*count : 0 );
         [ #  # ][ #  # ]
    2825                 :            :   
    2826                 :            :   const double *coord_x, *coord_y, *coord_z;
    2827                 :            :   double *c1x, *c1y, *c1z, *c2x, *c2y, *c2z;
    2828         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    2829                 :          0 :     coord_x = coordinates;
    2830                 :          0 :     coord_y = coord_x + coordinates_size/3;
    2831                 :          0 :     coord_z = coord_y + coordinates_size/3;
    2832                 :          0 :     c1x = *cvtr_1;
    2833                 :          0 :     c1y = c1x + count;
    2834                 :          0 :     c1z = c1y + count;
    2835                 :          0 :     c2x = *cvtr_2;
    2836                 :          0 :     c2y = c2x + count;
    2837                 :          0 :     c2z = c2y + count;
    2838                 :          0 :     cvtr_step = 1;
    2839                 :            :   }
    2840                 :            :   else {
    2841                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    2842                 :          0 :     coord_x = coordinates;
    2843                 :          0 :     coord_y = coord_x+1;
    2844                 :          0 :     coord_z = coord_x+2;
    2845                 :          0 :     c1x = *cvtr_1;
    2846                 :          0 :     c1y = c1x+1;
    2847                 :          0 :     c1z = c1x+2;
    2848                 :          0 :     c2x = *cvtr_2;
    2849                 :          0 :     c2y = c2x+1;
    2850                 :          0 :     c2z = c2x+2;
    2851                 :          0 :     coord_step *= 3;
    2852                 :          0 :     cvtr_step = 3;
    2853                 :            :   }
    2854                 :            :   
    2855                 :            :   RefFace *face;
    2856                 :            :   RefEdge *edge;
    2857                 :          0 :   CubitStatus result = CUBIT_SUCCESS;
    2858         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    2859                 :            :     CubitStatus status;
    2860         [ #  # ]:          0 :     const CubitVector coords( *coord_x, *coord_y, *coord_z );
    2861 [ #  # ][ #  # ]:          0 :     if ((face = dynamic_cast<RefFace*>(*entities))) {
    2862         [ #  # ]:          0 :       Surface* surf = face->get_surface_ptr();
    2863 [ #  # ][ #  # ]:          0 :       CubitVector curv1, curv2;
    2864         [ #  # ]:          0 :       status = surf->closest_point( coords, 0, 0, &curv1, &curv2 );
    2865         [ #  # ]:          0 :       curv1.get_xyz( *c1x, *c1y, *c1z );
    2866         [ #  # ]:          0 :       curv2.get_xyz( *c2x, *c2y, *c2z );
    2867                 :            :     }
    2868 [ #  # ][ #  # ]:          0 :     else if ((edge = dynamic_cast<RefEdge*>(*entities))) {
    2869 [ #  # ][ #  # ]:          0 :       CubitVector junk, curv;
    2870         [ #  # ]:          0 :       status = edge->closest_point( coords, junk, 0, &curv );
    2871         [ #  # ]:          0 :       curv.get_xyz( *c1x, *c1y, *c1z );
    2872                 :            :     }
    2873                 :            :     else {
    2874                 :          0 :       status = CUBIT_FAILURE;
    2875                 :            :     }
    2876                 :            : 
    2877         [ #  # ]:          0 :     if (CUBIT_SUCCESS != status)
    2878                 :          0 :       result = status;
    2879                 :            :     
    2880                 :          0 :     entities += ent_step;
    2881                 :          0 :     coord_x += coord_step;
    2882                 :          0 :     coord_y += coord_step;
    2883                 :          0 :     coord_z += coord_step;
    2884                 :          0 :     c1x += cvtr_step;
    2885                 :          0 :     c1y += cvtr_step;
    2886                 :          0 :     c1z += cvtr_step;
    2887                 :          0 :     c2x += cvtr_step;
    2888                 :          0 :     c2y += cvtr_step;
    2889                 :          0 :     c2z += cvtr_step;
    2890                 :            :   }
    2891                 :            :   
    2892         [ #  # ]:          0 :   if (result == CUBIT_FAILURE)
    2893         [ #  # ]:          0 :     RETURN(iBase_FAILURE);
    2894                 :            :   
    2895         [ #  # ]:          0 :   KEEP_ARRAY( cvtr_1 );
    2896         [ #  # ]:          0 :   KEEP_ARRAY( cvtr_2 );
    2897 [ #  # ][ #  # ]:          0 :   RETURN( iBase_SUCCESS );
    2898                 :            : }
    2899                 :            : 
    2900                 :            : 
    2901                 :            : ITAPS_API void
    2902                 :          0 : iGeom_getEgEvalXYZ( iGeom_Instance instance,
    2903                 :            :                     /*in*/ iBase_EntityHandle edge_handle,
    2904                 :            :                     /*in*/ double x,
    2905                 :            :                     /*in*/ double y,
    2906                 :            :                     /*in*/ double z,
    2907                 :            :                     /*out*/ double* on_x,
    2908                 :            :                     /*out*/ double* on_y,
    2909                 :            :                     /*out*/ double* on_z,
    2910                 :            :                     /*out*/ double* tan_i,
    2911                 :            :                     /*out*/ double* tan_j,
    2912                 :            :                     /*out*/ double* tan_k,
    2913                 :            :                     /*out*/ double* cvtr_i,
    2914                 :            :                     /*out*/ double* cvtr_j,
    2915                 :            :                     /*out*/ double* cvtr_k,
    2916                 :            :                     int* err )
    2917                 :            : {
    2918                 :          0 :   RefEntity* entity = (RefEntity*)edge_handle;
    2919         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>(entity);
    2920         [ #  # ]:          0 :   if (!edge)
    2921         [ #  # ]:          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    2922                 :            :   
    2923 [ #  # ][ #  # ]:          0 :   CubitVector loc(x,y,z), on, tan, curv;
         [ #  # ][ #  # ]
    2924         [ #  # ]:          0 :   CubitStatus status = edge->closest_point( loc, on, &tan, &curv );
    2925         [ #  # ]:          0 :   on.get_xyz( *on_x, *on_y, *on_z );
    2926         [ #  # ]:          0 :   tan.get_xyz( *tan_i, *tan_j, *tan_k );
    2927         [ #  # ]:          0 :   curv.get_xyz( *cvtr_i, *cvtr_j, *cvtr_k );
    2928 [ #  # ][ #  # ]:          0 :   RETURN( (status == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    2929                 :            : }
    2930                 :            : 
    2931                 :            : ITAPS_API void
    2932                 :          0 : iGeom_getFcEvalXYZ( iGeom_Instance instance,
    2933                 :            :                     /*in*/ iBase_EntityHandle face_handle,
    2934                 :            :                     /*in*/ double x,
    2935                 :            :                     /*in*/ double y,
    2936                 :            :                     /*in*/ double z,
    2937                 :            :                     /*out*/ double* on_x,
    2938                 :            :                     /*out*/ double* on_y,
    2939                 :            :                     /*out*/ double* on_z,
    2940                 :            :                     /*out*/ double* norm_i,
    2941                 :            :                     /*out*/ double* norm_j,
    2942                 :            :                     /*out*/ double* norm_k,
    2943                 :            :                     /*out*/ double* cvtr1_i,
    2944                 :            :                     /*out*/ double* cvtr1_j,
    2945                 :            :                     /*out*/ double* cvtr1_k,
    2946                 :            :                     /*out*/ double* cvtr2_i,
    2947                 :            :                     /*out*/ double* cvtr2_j,
    2948                 :            :                     /*out*/ double* cvtr2_k,
    2949                 :            :                     int* err )
    2950                 :            : {
    2951                 :          0 :   RefEntity* entity = (RefEntity*)face_handle;
    2952         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    2953         [ #  # ]:          0 :   if (!face)
    2954         [ #  # ]:          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    2955                 :            :   
    2956         [ #  # ]:          0 :   Surface* surf = face->get_surface_ptr();
    2957 [ #  # ][ #  # ]:          0 :   CubitVector loc(x,y,z), on, norm, curv1, curv2;
         [ #  # ][ #  # ]
                 [ #  # ]
    2958                 :            : #ifdef CGM_HAVE_FACET_ENGINE_ONLY
    2959                 :            :   CubitStatus status = surf->closest_point( loc, &on, &norm);
    2960                 :            : #else
    2961         [ #  # ]:          0 :   CubitStatus status = surf->closest_point( loc, &on, &norm, &curv1, &curv2 );
    2962                 :            : #endif
    2963                 :            : 
    2964 [ #  # ][ #  # ]:          0 :   if (surf->bridge_sense() == CUBIT_REVERSED) {
    2965 [ #  # ][ #  # ]:          0 :     norm = -norm;
    2966 [ #  # ][ #  # ]:          0 :     curv1 = -curv1;
    2967 [ #  # ][ #  # ]:          0 :     curv2 = -curv2;
    2968                 :            :   }
    2969         [ #  # ]:          0 :   on.get_xyz( *on_x, *on_y, *on_z );
    2970         [ #  # ]:          0 :   norm.get_xyz( *norm_i, *norm_j, *norm_k );
    2971         [ #  # ]:          0 :   curv1.get_xyz( *cvtr1_i, *cvtr1_j, *cvtr1_k );
    2972         [ #  # ]:          0 :   curv2.get_xyz( *cvtr2_i, *cvtr2_j, *cvtr2_k );
    2973 [ #  # ][ #  # ]:          0 :   RETURN( (status == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    2974                 :            : }
    2975                 :            :                        
    2976                 :            : ITAPS_API void
    2977                 :          0 : iGeom_getArrEgEvalXYZ( iGeom_Instance instance,
    2978                 :            :                        /*in*/ const iBase_EntityHandle *edge_handles,
    2979                 :            :                        int edge_handles_size,
    2980                 :            :                        /*in*/ int storage_order,
    2981                 :            :                        /*in*/ const double *coordinates,
    2982                 :            :                        int coordinates_size,
    2983                 :            :                        /*inout*/ double **on_coords,
    2984                 :            :                        int *on_coords_allocated,
    2985                 :            :                        int *on_coords_size,
    2986                 :            :                        /*inout*/ double **tangents,
    2987                 :            :                        int *tangents_allocated,
    2988                 :            :                        int *tangents_size,
    2989                 :            :                        /*inout*/ double **curvatures,
    2990                 :            :                        int *curvatures_allocated,
    2991                 :            :                        int *curvatures_size,
    2992                 :            :                        int* err )
    2993                 :            : {
    2994                 :            :     /* set up iteration according to storage order.
    2995                 :            :        allow either gentity_handles or near_coordinates to contain
    2996                 :            :        only one value, where that single value is applied for every
    2997                 :            :        entry in the other list.
    2998                 :            :     */
    2999                 :          0 :   size_t coord_step, on_step = 1, ent_step;
    3000                 :            :   int count;
    3001         [ #  # ]:          0 :   if (3*edge_handles_size == coordinates_size) {
    3002                 :          0 :     coord_step = ent_step = 1;
    3003                 :          0 :     count = edge_handles_size;
    3004                 :            :   }
    3005         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    3006                 :          0 :     coord_step = 0;
    3007                 :          0 :     ent_step = 1;
    3008                 :          0 :     count = edge_handles_size;
    3009                 :            :   }
    3010         [ #  # ]:          0 :   else if (edge_handles_size == 1) {
    3011                 :          0 :     coord_step = 1;
    3012                 :          0 :     ent_step = 0;
    3013                 :          0 :     count = coordinates_size / 3;
    3014                 :            :   }
    3015                 :            :   else {
    3016         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    3017                 :            :   }
    3018                 :            : 
    3019                 :            :     // check or pre-allocate the coordinate arrays
    3020 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( on_coords, 3*count );
    3021 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( tangents, 3*count );
                 [ #  # ]
    3022 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( curvatures, 3*count );
                 [ #  # ]
    3023                 :            :   
    3024                 :            :   const double *coord_x, *coord_y, *coord_z;
    3025                 :            :   double *on_x, *on_y, *on_z;
    3026                 :            :   double *tan_x, *tan_y, *tan_z;
    3027                 :            :   double *curv_x, *curv_y, *curv_z;
    3028         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    3029                 :          0 :     coord_x = coordinates;
    3030                 :          0 :     coord_y = coord_x + coordinates_size/3;
    3031                 :          0 :     coord_z = coord_y + coordinates_size/3;
    3032                 :          0 :     on_x = *on_coords;
    3033                 :          0 :     on_y = on_x + count;
    3034                 :          0 :     on_z = on_y + count;
    3035                 :          0 :     tan_x = *tangents;
    3036                 :          0 :     tan_y = tan_x + count;
    3037                 :          0 :     tan_z = tan_y + count;
    3038                 :          0 :     curv_x = *curvatures;
    3039                 :          0 :     curv_y = curv_x + count;
    3040                 :          0 :     curv_z = curv_y + count;
    3041                 :          0 :     on_step = 1;
    3042                 :            :   }
    3043                 :            :   else {
    3044                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    3045                 :          0 :     coord_x = coordinates;
    3046                 :          0 :     coord_y = coord_x+1;
    3047                 :          0 :     coord_z = coord_x+2;
    3048                 :          0 :     on_x = *on_coords;
    3049                 :          0 :     on_y = on_x + 1;
    3050                 :          0 :     on_z = on_x + 2;
    3051                 :          0 :     tan_x = *tangents;
    3052                 :          0 :     tan_y = tan_x+1;
    3053                 :          0 :     tan_z = tan_x+2;
    3054                 :          0 :     curv_x = *curvatures;
    3055                 :          0 :     curv_y = curv_x + 1;
    3056                 :          0 :     curv_z = curv_x + 2;
    3057                 :          0 :     coord_step *= 3;
    3058                 :          0 :     on_step = 3;
    3059                 :            :   }
    3060                 :            :   
    3061                 :          0 :   RefEntity** ent_iter = (RefEntity**)edge_handles;
    3062                 :          0 :   iBase_ErrorType result = iBase_SUCCESS;
    3063         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    3064         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*ent_iter);
    3065         [ #  # ]:          0 :     if (!edge) {
    3066         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Non-edge input handle.");
    3067                 :            :     }
    3068                 :            :     else {
    3069         [ #  # ]:          0 :       const CubitVector coords( *coord_x, *coord_y, *coord_z );
    3070 [ #  # ][ #  # ]:          0 :       CubitVector on, tan, curv;
                 [ #  # ]
    3071         [ #  # ]:          0 :       CubitStatus s = edge->closest_point( coords, on, &tan, &curv );
    3072         [ #  # ]:          0 :       if (s == CUBIT_FAILURE)
    3073                 :          0 :         result = iBase_FAILURE;
    3074         [ #  # ]:          0 :       on.get_xyz( *on_x, *on_y, *on_z );
    3075         [ #  # ]:          0 :       tan.get_xyz( *tan_x, *tan_y, *tan_z );
    3076         [ #  # ]:          0 :       curv.get_xyz( *curv_x, *curv_y, *curv_z );
    3077                 :            :     }
    3078                 :            :     
    3079                 :          0 :     ent_iter += ent_step;
    3080                 :          0 :     coord_x += coord_step;
    3081                 :          0 :     coord_y += coord_step;
    3082                 :          0 :     coord_z += coord_step;
    3083                 :          0 :     on_x += on_step;
    3084                 :          0 :     on_y += on_step;
    3085                 :          0 :     on_z += on_step;
    3086                 :          0 :     tan_x += on_step;
    3087                 :          0 :     tan_y += on_step;
    3088                 :          0 :     tan_z += on_step;
    3089                 :          0 :     curv_x += on_step;
    3090                 :          0 :     curv_y += on_step;
    3091                 :          0 :     curv_z += on_step;
    3092                 :            :   }
    3093                 :            :   
    3094         [ #  # ]:          0 :   KEEP_ARRAY( on_coords );
    3095         [ #  # ]:          0 :   KEEP_ARRAY( tangents );
    3096         [ #  # ]:          0 :   KEEP_ARRAY( curvatures );
    3097 [ #  # ][ #  # ]:          0 :   RETURN(result);
    3098                 :            : }
    3099                 :            :                        
    3100                 :            : ITAPS_API void
    3101                 :          0 : iGeom_getArrFcEvalXYZ( iGeom_Instance instance,
    3102                 :            :                        /*in*/ const iBase_EntityHandle *face_handles,
    3103                 :            :                        int face_handles_size,
    3104                 :            :                        /*in*/ int storage_order,
    3105                 :            :                        /*in*/ const double *coordinates,
    3106                 :            :                        int coordinates_size,
    3107                 :            :                        /*inout*/ double **on_coords,
    3108                 :            :                        int *on_coords_allocated,
    3109                 :            :                        int *on_coords_size,
    3110                 :            :                        /*inout*/ double **normals,
    3111                 :            :                        int *normals_allocated,
    3112                 :            :                        int *normals_size,
    3113                 :            :                        /*inout*/ double **curvatures_1,
    3114                 :            :                        int *curvatures_1_allocated,
    3115                 :            :                        int *curvatures_1_size,
    3116                 :            :                        /*inout*/ double **curvatures_2,
    3117                 :            :                        int *curvatures_2_allocated,
    3118                 :            :                        int *curvatures_2_size,
    3119                 :            :                        int* err )
    3120                 :            : {
    3121                 :            :     /* set up iteration according to storage order.
    3122                 :            :        allow either gentity_handles or near_coordinates to contain
    3123                 :            :        only one value, where that single value is applied for every
    3124                 :            :        entry in the other list.
    3125                 :            :     */
    3126                 :          0 :   size_t coord_step, on_step = 1, ent_step;
    3127                 :            :   int count;
    3128         [ #  # ]:          0 :   if (3*face_handles_size == coordinates_size) {
    3129                 :          0 :     coord_step = ent_step = 1;
    3130                 :          0 :     count = face_handles_size;
    3131                 :            :   }
    3132         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    3133                 :          0 :     coord_step = 0;
    3134                 :          0 :     ent_step = 1;
    3135                 :          0 :     count = face_handles_size;
    3136                 :            :   }
    3137         [ #  # ]:          0 :   else if (face_handles_size == 1) {
    3138                 :          0 :     coord_step = 1;
    3139                 :          0 :     ent_step = 0;
    3140                 :          0 :     count = coordinates_size / 3;
    3141                 :            :   }
    3142                 :            :   else {
    3143         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched array sizes" );
    3144                 :            :   }
    3145                 :            : 
    3146                 :            :     // check or pre-allocate the coordinate arrays
    3147 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( on_coords, 3*count );
    3148 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( normals, 3*count );
                 [ #  # ]
    3149 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( curvatures_1, 3*count );
                 [ #  # ]
    3150 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( curvatures_2, 3*count );
                 [ #  # ]
    3151                 :            :   
    3152                 :            :   const double *coord_x, *coord_y, *coord_z;
    3153                 :            :   double *on_x, *on_y, *on_z;
    3154                 :            :   double *norm_x, *norm_y, *norm_z;
    3155                 :            :   double *curv1_x, *curv1_y, *curv1_z;
    3156                 :            :   double *curv2_x, *curv2_y, *curv2_z;
    3157         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    3158                 :          0 :     coord_x = coordinates;
    3159                 :          0 :     coord_y = coord_x + coordinates_size/3;
    3160                 :          0 :     coord_z = coord_y + coordinates_size/3;
    3161                 :          0 :     on_x = *on_coords;
    3162                 :          0 :     on_y = on_x + count;
    3163                 :          0 :     on_z = on_y + count;
    3164                 :          0 :     norm_x = *normals;
    3165                 :          0 :     norm_y = norm_x + count;
    3166                 :          0 :     norm_z = norm_y + count;
    3167                 :          0 :     curv1_x = *curvatures_1;
    3168                 :          0 :     curv1_y = curv1_x + count;
    3169                 :          0 :     curv1_z = curv1_y + count;
    3170                 :          0 :     curv2_x = *curvatures_2;
    3171                 :          0 :     curv2_y = curv2_x + count;
    3172                 :          0 :     curv2_z = curv2_y + count;
    3173                 :          0 :     on_step = 1;
    3174                 :            :   }
    3175                 :            :   else {
    3176                 :          0 :     storage_order = iBase_INTERLEAVED; /* set if unspecified */
    3177                 :          0 :     coord_x = coordinates;
    3178                 :          0 :     coord_y = coord_x+1;
    3179                 :          0 :     coord_z = coord_x+2;
    3180                 :          0 :     on_x = *on_coords;
    3181                 :          0 :     on_y = on_x + 1;
    3182                 :          0 :     on_z = on_x + 2;
    3183                 :          0 :     norm_x = *normals;
    3184                 :          0 :     norm_y = norm_x+1;
    3185                 :          0 :     norm_z = norm_x+2;
    3186                 :          0 :     curv1_x = *curvatures_1;
    3187                 :          0 :     curv1_y = curv1_x + 1;
    3188                 :          0 :     curv1_z = curv1_x + 2;
    3189                 :          0 :     curv2_x = *curvatures_2;
    3190                 :          0 :     curv2_y = curv2_x + 1;
    3191                 :          0 :     curv2_z = curv2_x + 2;
    3192                 :          0 :     coord_step *= 3;
    3193                 :          0 :     on_step = 3;
    3194                 :            :   }
    3195                 :            :   
    3196                 :          0 :   RefEntity** ent_iter = (RefEntity**)face_handles;
    3197                 :          0 :   iBase_ErrorType result = iBase_SUCCESS;
    3198         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    3199         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*ent_iter);
    3200         [ #  # ]:          0 :     if (!face) {
    3201         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Non-face input handle.");
    3202                 :            :       result = iBase_INVALID_ENTITY_TYPE;
    3203                 :            :     }
    3204                 :            :     else {
    3205         [ #  # ]:          0 :       const CubitVector coords( *coord_x, *coord_y, *coord_z );
    3206 [ #  # ][ #  # ]:          0 :       CubitVector on, norm, curv1, curv2;
         [ #  # ][ #  # ]
    3207         [ #  # ]:          0 :       Surface* surf = face->get_surface_ptr();
    3208                 :            : #ifdef CGM_HAVE_FACET_ENGINE_ONLY
    3209                 :            :       CubitStatus s = surf->closest_point( coords, &on, &norm);
    3210                 :            : #else
    3211         [ #  # ]:          0 :       CubitStatus s = surf->closest_point( coords, &on, &norm, &curv1, &curv2 );
    3212                 :            : #endif
    3213         [ #  # ]:          0 :       if (s == CUBIT_FAILURE)
    3214                 :          0 :         result = iBase_FAILURE;
    3215         [ #  # ]:          0 :       on.get_xyz( *on_x, *on_y, *on_z );
    3216         [ #  # ]:          0 :       norm.get_xyz( *norm_x, *norm_y, *norm_z );
    3217         [ #  # ]:          0 :       curv1.get_xyz( *curv1_x, *curv1_y, *curv1_z );
    3218         [ #  # ]:          0 :       curv2.get_xyz( *curv2_x, *curv2_y, *curv2_z );
    3219                 :            :     }
    3220                 :            :     
    3221                 :          0 :     ent_iter += ent_step;
    3222                 :          0 :     coord_x += coord_step;
    3223                 :          0 :     coord_y += coord_step;
    3224                 :          0 :     coord_z += coord_step;
    3225                 :          0 :     on_x += on_step;
    3226                 :          0 :     on_y += on_step;
    3227                 :          0 :     on_z += on_step;
    3228                 :          0 :     norm_x += on_step;
    3229                 :          0 :     norm_y += on_step;
    3230                 :          0 :     norm_z += on_step;
    3231                 :          0 :     curv1_x += on_step;
    3232                 :          0 :     curv1_y += on_step;
    3233                 :          0 :     curv1_z += on_step;
    3234                 :          0 :     curv2_x += on_step;
    3235                 :          0 :     curv2_y += on_step;
    3236                 :          0 :     curv2_z += on_step;
    3237                 :            :   }
    3238                 :            :   
    3239         [ #  # ]:          0 :   KEEP_ARRAY( on_coords );
    3240         [ #  # ]:          0 :   KEEP_ARRAY( normals );
    3241         [ #  # ]:          0 :   KEEP_ARRAY( curvatures_1 );
    3242         [ #  # ]:          0 :   KEEP_ARRAY( curvatures_2 );
    3243 [ #  # ][ #  # ]:          0 :   RETURN(result);
    3244                 :            : }
    3245                 :            : 
    3246                 :            : /**
    3247                 :            :  * Return the arc length / area / volume of the entities
    3248                 :            :  * @param gentity_handles Entities for which measure is requested
    3249                 :            :  * @param gentity_handles_size Number of gentities
    3250                 :            :  * @param measures Arc length / area / volume of the entities
    3251                 :            :  * @param measures_length Number of entries in measures
    3252                 :            :  */
    3253                 :            : ITAPS_API void
    3254                 :          0 : iGeom_measure( iGeom_Instance instance,
    3255                 :            :                /*in*/ const iBase_EntityHandle *gentity_handles,
    3256                 :            :                int gentity_handles_size,
    3257                 :            :                /*out*/ double **measures,
    3258                 :            :                int *measures_allocated,
    3259                 :            :                int *measures_size,
    3260                 :            :                int* err )
    3261                 :            : {
    3262                 :          0 :   RefEntity **handle_array = (RefEntity**)(gentity_handles);
    3263                 :            : 
    3264                 :            :     // check or pre-allocate the measure arrays
    3265 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(measures, gentity_handles_size);
                 [ #  # ]
    3266         [ #  # ]:          0 :   for (int i = 0; i < gentity_handles_size; i++)
    3267         [ #  # ]:          0 :     (*measures)[i] = handle_array[i]->measure();
    3268                 :            :   
    3269 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3270                 :            : }
    3271                 :            : 
    3272                 :            : ITAPS_API void
    3273                 :          4 : iGeom_getEntBoundBox( iGeom_Instance instance,
    3274                 :            :                       /*in*/ iBase_EntityHandle entity_handle,
    3275                 :            :                       /*out*/ double* min_x,
    3276                 :            :                       /*out*/ double* min_y,
    3277                 :            :                       /*out*/ double* min_z,
    3278                 :            :                       /*out*/ double* max_x,
    3279                 :            :                       /*out*/ double* max_y,
    3280                 :            :                       /*out*/ double* max_z,
    3281                 :            :                       int* err )
    3282                 :            : {
    3283                 :          4 :   RefEntity* entity = (RefEntity*)entity_handle;
    3284 [ +  - ][ +  - ]:          4 :   CubitVector minc, maxc;
    3285         [ +  - ]:          4 :   CubitStatus status = iGeom_bounding_box( entity, minc, maxc );
    3286         [ +  - ]:          4 :   minc.get_xyz( *min_x, *min_y, *min_z );
    3287         [ +  - ]:          4 :   maxc.get_xyz( *max_x, *max_y, *max_z );
    3288 [ +  - ][ +  - ]:          4 :   RETURN( (status == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    3289                 :            : }
    3290                 :            : 
    3291                 :            : /**
    3292                 :            :  * Return the type of surface as a string; if not a surface, an error is returned
    3293                 :            :  * @param face_handle Face for which the type is requested
    3294                 :            :  * @param face_type Type of face, returned as a string
    3295                 :            :  */
    3296                 :            : ITAPS_API void
    3297                 :          0 : iGeom_getFaceType( iGeom_Instance instance,
    3298                 :            :                    /*in*/ iBase_EntityHandle gentity_handle,
    3299                 :            :                    /*out*/ char *face_type,
    3300                 :            :                    int* err,
    3301                 :            :                    int *face_type_length )
    3302                 :            : {
    3303                 :            :   static const char *surf_types[] = {"cone", "plane", "sphere", "spline", 
    3304                 :            :                                      "torus", "best_fit", "facet", "undefined"};
    3305                 :            :   
    3306                 :          0 :   RefEntity *this_ent = ENTITY_HANDLE(gentity_handle);
    3307         [ #  # ]:          0 :   RefFace *this_face = dynamic_cast<RefFace*>(this_ent);
    3308         [ #  # ]:          0 :   if (!this_face)
    3309                 :          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    3310                 :          0 :   GeometryType this_type = this_face->get_surface_ptr()->geometry_type();
    3311 [ #  # ][ #  # ]:          0 :   if (this_type < CONE_SURFACE_TYPE || this_type > UNDEFINED_SURFACE_TYPE) {
    3312                 :          0 :     RETURN(iBase_FAILURE);
    3313                 :            :   }
    3314                 :            :   
    3315                 :          0 :   const char* result = surf_types[this_type - CONE_SURFACE_TYPE];
    3316                 :          0 :   const int len = strlen(result);
    3317         [ #  # ]:          0 :   if (len < *face_type_length) {
    3318                 :          0 :     strcpy(face_type, result);
    3319                 :          0 :     *face_type_length = len;
    3320                 :            :   }
    3321                 :            :   else {
    3322                 :          0 :     strncpy(face_type, result, *face_type_length-1);
    3323                 :          0 :     face_type[*face_type_length] = '\0';
    3324                 :            :   }
    3325                 :            : 
    3326                 :          0 :   RETURN(iBase_SUCCESS);
    3327                 :            : }
    3328                 :            : 
    3329                 :            : /**
    3330                 :            :  * Return the bounding boxex of given entities; coordinates returned
    3331                 :            :  * interleaved.
    3332                 :            :  * @param gentity_handles The gentities being queried
    3333                 :            :  * @param min_corners Minimum corner coordinates of the boxes, interleaved
    3334                 :            :  * @param max_corners Maximum corner coordinates of the boxes, interleaved
    3335                 :            :  */
    3336                 :            : ITAPS_API void
    3337                 :          2 : iGeom_getArrBoundBox( iGeom_Instance instance,
    3338                 :            :                       /*in*/ const iBase_EntityHandle *gentity_handles,
    3339                 :            :                       int gentity_handles_size,
    3340                 :            :                       /*in*/ int storage_order,
    3341                 :            :                       /*out*/ double **min_corner,
    3342                 :            :                       int *min_corner_allocated,
    3343                 :            :                       int *min_corner_size,
    3344                 :            :                       /*out*/ double **max_corner,
    3345                 :            :                       int *max_corner_allocated,
    3346                 :            :                       int *max_corner_size,
    3347                 :            :                       int* err )
    3348                 :            : {
    3349                 :            :     // check or pre-allocate the coordinate arrays
    3350 [ +  - ][ -  + ]:          2 :   ALLOC_CHECK_ARRAY(min_corner, 3*gentity_handles_size);
    3351 [ +  - ][ -  + ]:          4 :   ALLOC_CHECK_ARRAY(max_corner, 3*gentity_handles_size);
                 [ +  - ]
    3352                 :            :   
    3353                 :            :   size_t step, init;
    3354         [ -  + ]:          2 :   if (storage_order == iBase_BLOCKED) {
    3355                 :          0 :     step = 1;
    3356                 :          0 :     init = gentity_handles_size;
    3357                 :            :   }
    3358                 :            :   else {
    3359                 :          2 :     step = 3;
    3360                 :          2 :     init = 1;
    3361                 :            :   }
    3362                 :            :   double *min_x, *min_y, *min_z, *max_x, *max_y, *max_z;
    3363                 :          2 :   min_x = *min_corner;
    3364                 :          2 :   max_x = *max_corner;
    3365                 :          2 :   min_y = min_x + init;
    3366                 :          2 :   max_y = max_x + init;
    3367                 :          2 :   min_z = min_y + init;
    3368                 :          2 :   max_z = max_y + init;
    3369                 :            :   
    3370                 :          2 :   iBase_ErrorType result = iBase_SUCCESS;
    3371                 :          2 :   RefEntity** entities = (RefEntity**)gentity_handles;
    3372         [ +  + ]:          8 :   for (int i = 0; i < gentity_handles_size; ++i)
    3373                 :            :   {
    3374 [ +  - ][ +  - ]:          6 :     CubitVector min_c, max_c;
    3375         [ +  - ]:          6 :     CubitStatus s = iGeom_bounding_box( entities[i], min_c, max_c );
    3376         [ -  + ]:          6 :     if (s != CUBIT_SUCCESS)
    3377                 :          0 :       result = iBase_FAILURE;
    3378         [ +  - ]:          6 :     min_c.get_xyz( *min_x, *min_y, *min_z );
    3379         [ +  - ]:          6 :     max_c.get_xyz( *max_x, *max_y, *max_z );
    3380                 :            :     
    3381                 :          6 :     min_x += step;
    3382                 :          6 :     max_x += step;
    3383                 :          6 :     min_y += step;
    3384                 :          6 :     max_y += step;
    3385                 :          6 :     min_z += step;
    3386                 :          6 :     max_z += step;
    3387                 :            :   }
    3388                 :            : 
    3389         [ +  - ]:          2 :   KEEP_ARRAY(min_corner);
    3390         [ +  - ]:          2 :   KEEP_ARRAY(max_corner);
    3391 [ +  - ][ +  - ]:          4 :   RETURN(result);
    3392                 :            : }
    3393                 :            : 
    3394                 :            : ITAPS_API void
    3395                 :          0 : iGeom_getVtxCoord( iGeom_Instance instance,
    3396                 :            :                    /*in*/ iBase_EntityHandle vertex_handle,
    3397                 :            :                    /*out*/ double* x,
    3398                 :            :                    /*out*/ double* y,
    3399                 :            :                    /*out*/ double* z,
    3400                 :            :                    int* err )
    3401                 :            : {
    3402                 :          0 :   RefEntity* entity = (RefEntity*)vertex_handle;
    3403         [ #  # ]:          0 :   RefVertex* vertex = dynamic_cast<RefVertex*>(entity);
    3404         [ #  # ]:          0 :   if (!vertex) {
    3405                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Entity not a vertex");
    3406                 :            :   }
    3407         [ #  # ]:          0 :   vertex->coordinates().get_xyz(*x, *y, *z);
    3408                 :          0 :   RETURN(iBase_SUCCESS);
    3409                 :            : }
    3410                 :            : 
    3411                 :            : /**
    3412                 :            :  * Return the coordinates of the specified vertices; returns error if any
    3413                 :            :  * of the entities are not gvertices.  Coordinates returned interleaved.
    3414                 :            :  * @param gentity_handles The gentities being queried
    3415                 :            :  * @param coordinates The coordinates of the gvertices, interleaved.
    3416                 :            :  */
    3417                 :            : ITAPS_API void
    3418                 :          0 : iGeom_getVtxArrCoords( iGeom_Instance instance,
    3419                 :            :                        /*in*/ const iBase_EntityHandle *gentity_handles,
    3420                 :            :                        int gentity_handles_size,
    3421                 :            :                        /*in*/ int storage_order,
    3422                 :            :                        /*out*/ double **coordinates,
    3423                 :            :                        int *coordinates_allocated,
    3424                 :            :                        int *coordinates_size,
    3425                 :            :                        int* err )
    3426                 :            : {
    3427                 :          0 :   const RefEntity **handle_array = (const RefEntity**)(gentity_handles);
    3428                 :            : 
    3429                 :            :     // check or pre-allocate the coordinate arrays
    3430 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(coordinates, 3*gentity_handles_size);
    3431                 :            :   
    3432         [ #  # ]:          0 :   CubitVector dumvec;
    3433                 :            :   const RefVertex *this_vertex;
    3434                 :            : 
    3435                 :            :   double *x, *y, *z;
    3436                 :            :   size_t step;
    3437         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    3438                 :          0 :     x = *coordinates;
    3439                 :          0 :     y = x + gentity_handles_size;
    3440                 :          0 :     z = y + gentity_handles_size;
    3441                 :          0 :     step = 1;
    3442                 :            :   }
    3443                 :            :   else {
    3444                 :          0 :     x = *coordinates;
    3445                 :          0 :     y = x + 1;
    3446                 :          0 :     z = x + 2;
    3447                 :          0 :     step = 3;
    3448                 :            :   }
    3449                 :            : 
    3450         [ #  # ]:          0 :   for (int i = 0; i < gentity_handles_size; i++) {
    3451         [ #  # ]:          0 :     this_vertex = dynamic_cast<const RefVertex*>(handle_array[i]);
    3452         [ #  # ]:          0 :     if (NULL == this_vertex) {
    3453         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Entities passed into getGvertexCoordinates must be vertices.");
    3454                 :            :     }
    3455                 :            :     else {
    3456 [ #  # ][ #  # ]:          0 :       dumvec = this_vertex->coordinates();
    3457         [ #  # ]:          0 :       dumvec.get_xyz(*x,*y,*z);
    3458                 :          0 :       x += step;
    3459                 :          0 :       y += step;
    3460                 :          0 :       z += step;
    3461                 :            :     }
    3462                 :            :   }
    3463                 :            : 
    3464         [ #  # ]:          0 :   KEEP_ARRAY(coordinates);
    3465 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3466                 :            : }
    3467                 :            : 
    3468                 :            : ITAPS_API void
    3469                 :          0 : iGeom_getPntRayIntsct( iGeom_Instance instance,
    3470                 :            :                        /*in*/ double x,
    3471                 :            :                        /*in*/ double y,
    3472                 :            :                        /*in*/ double z,
    3473                 :            :                        /*in*/ double dx,
    3474                 :            :                        /*in*/ double dy,
    3475                 :            :                        /*in*/ double dz,
    3476                 :            :                        /*inout*/ iBase_EntityHandle **intersect_entity_handles,
    3477                 :            :                        int *intersect_entity_handles_allocated,
    3478                 :            :                        int *intersect_entity_handles_size,
    3479                 :            :                        /*in*/ int storage_order,
    3480                 :            :                        /*inout*/ double **intersect_coords,
    3481                 :            :                        int *intersect_coords_allocated,
    3482                 :            :                        int *intersect_coords_size,
    3483                 :            :                        /*inout*/ double **param_coords,
    3484                 :            :                        int *param_coords_allocated,
    3485                 :            :                        int *param_coords_size,
    3486                 :            :                        int* err )
    3487                 :            : {
    3488         [ #  # ]:          0 :   DLIList<double> ray_params;
    3489 [ #  # ][ #  # ]:          0 :   DLIList<RefEntity*> entities;
    3490 [ #  # ][ #  # ]:          0 :   CubitVector point(x,y,z), dir(dx,dy,dz);
    3491         [ #  # ]:          0 :   CubitStatus status = iGeom_fire_ray( point, dir, entities, ray_params );
    3492         [ #  # ]:          0 :   if (status != CUBIT_SUCCESS)
    3493         [ #  # ]:          0 :     RETURN(iBase_FAILURE);
    3494                 :            :   
    3495 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( intersect_entity_handles, entities.size() );
         [ #  # ][ #  # ]
                 [ #  # ]
    3496 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( intersect_coords, 3*ray_params.size() );
         [ #  # ][ #  # ]
                 [ #  # ]
    3497 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( param_coords, ray_params.size() );
         [ #  # ][ #  # ]
                 [ #  # ]
    3498                 :            :   
    3499                 :            :   size_t init, step;
    3500         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    3501         [ #  # ]:          0 :     init = ray_params.size();
    3502                 :          0 :     step = 1;
    3503                 :            :   }
    3504                 :            :   else {
    3505                 :          0 :     init = 1;
    3506                 :          0 :     step = 3;
    3507                 :            :   }
    3508                 :            :   
    3509                 :          0 :   double *x_iter = *intersect_coords;
    3510                 :          0 :   double *y_iter = x_iter + init;
    3511                 :          0 :   double *z_iter = y_iter + init;
    3512 [ #  # ][ #  # ]:          0 :   for (size_t i = ray_params.size(); i > 0; --i) {
    3513         [ #  # ]:          0 :     double t = ray_params.get_and_step();
    3514 [ #  # ][ #  # ]:          0 :     CubitVector pos = t * dir + point;
    3515         [ #  # ]:          0 :     pos.get_xyz( *x_iter, *y_iter, *z_iter );
    3516                 :          0 :     x_iter += step;
    3517                 :          0 :     y_iter += step;
    3518                 :          0 :     z_iter += step;
    3519                 :            :   }
    3520         [ #  # ]:          0 :   ray_params.copy_to( *param_coords );
    3521         [ #  # ]:          0 :   entities.copy_to( (RefEntity**)*intersect_entity_handles );
    3522                 :            :          
    3523 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);  
    3524                 :            : }
    3525                 :            : 
    3526                 :            : ITAPS_API void
    3527                 :          0 : iGeom_getPntArrRayIntsct( iGeom_Instance instance,
    3528                 :            :                           /*in*/ int storage_order,
    3529                 :            :                           /*in*/ const double *points,
    3530                 :            :                           int points_size,
    3531                 :            :                           /*in*/ const double *directions,
    3532                 :            :                           int directions_size,
    3533                 :            :                           /*inout*/ iBase_EntityHandle **intersect_entity_handles,
    3534                 :            :                           int *intersect_entity_handles_allocated,
    3535                 :            :                           int *intersect_entity_handles_size,
    3536                 :            :                           /*inout*/ int **offset,
    3537                 :            :                           int *offset_allocated,
    3538                 :            :                           int *offset_size,
    3539                 :            :                           /*inout*/ double **intersect_coords,
    3540                 :            :                           int *intersect_coords_allocated,
    3541                 :            :                           int *intersect_coords_size,
    3542                 :            :                           /*inout*/ double **param_coords,
    3543                 :            :                           int *param_coords_allocated,
    3544                 :            :                           int *param_coords_size,
    3545                 :            :                           int* err )
    3546                 :            : {
    3547 [ #  # ][ #  # ]:          0 :   if (points_size != directions_size || points_size % 3) {
    3548         [ #  # ]:          0 :     ERROR(iBase_INVALID_ARGUMENT, "Mismatched or invalid input array size");
    3549                 :            :   }
    3550                 :            :   
    3551                 :          0 :   const int count = points_size / 3;
    3552 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( offset, count );
    3553                 :            :   
    3554                 :            :   const double *px, *py, *pz, *dx, *dy, *dz;
    3555                 :            :   size_t init, step;
    3556         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    3557                 :          0 :     init = count;
    3558                 :          0 :     step = 1;
    3559                 :            :   }
    3560                 :            :   else {
    3561                 :          0 :     storage_order = iBase_INTERLEAVED;
    3562                 :          0 :     init = 1;
    3563                 :          0 :     step = 3;
    3564                 :            :   }
    3565                 :          0 :   px = points;
    3566                 :          0 :   py = px + init;
    3567                 :          0 :   pz = py + init;
    3568                 :          0 :   dx = directions;
    3569                 :          0 :   dy = dx + init;
    3570                 :          0 :   dz = dy + init;
    3571                 :            :   
    3572 [ #  # ][ #  # ]:          0 :   DLIList<RefEntity*> entities, tmp_entities;
         [ #  # ][ #  # ]
    3573 [ #  # ][ #  # ]:          0 :   DLIList<double> params, tmp_params;
         [ #  # ][ #  # ]
    3574 [ #  # ][ #  # ]:          0 :   std::vector<CubitVector> coords;
    3575         [ #  # ]:          0 :   for (int i = 0; i < count; ++i)
    3576                 :            :   {
    3577         [ #  # ]:          0 :     tmp_entities.clean_out();
    3578         [ #  # ]:          0 :     tmp_params.clean_out();
    3579         [ #  # ]:          0 :     (*offset)[i] = params.size();
    3580 [ #  # ][ #  # ]:          0 :     const CubitVector point(*px, *py, *pz), dir(*dx, *dy, *dz);
    3581         [ #  # ]:          0 :     CubitStatus s = iGeom_fire_ray( point, dir, tmp_entities, tmp_params );
    3582         [ #  # ]:          0 :     if (CUBIT_SUCCESS != s) {
    3583         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    3584                 :            :     }
    3585                 :            : 
    3586         [ #  # ]:          0 :     entities += tmp_entities;
    3587         [ #  # ]:          0 :     params += tmp_params;
    3588         [ #  # ]:          0 :     tmp_params.reset();
    3589 [ #  # ][ #  # ]:          0 :     for (int j = tmp_params.size(); j > 0; --j) 
    3590 [ #  # ][ #  # ]:          0 :       coords.push_back( tmp_params.get_and_step() * dir + point );
         [ #  # ][ #  # ]
    3591                 :            :     
    3592                 :          0 :     px += step;
    3593                 :          0 :     py += step;
    3594                 :          0 :     pz += step;
    3595                 :          0 :     dx += step;
    3596                 :          0 :     dy += step;
    3597                 :          0 :     dz += step;
    3598                 :            :   }
    3599                 :            :   
    3600 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( intersect_entity_handles, entities.size() );
         [ #  # ][ #  # ]
                 [ #  # ]
    3601 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( intersect_coords, coords.size() );
         [ #  # ][ #  # ]
                 [ #  # ]
    3602 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( param_coords, params.size() );
         [ #  # ][ #  # ]
                 [ #  # ]
    3603         [ #  # ]:          0 :   entities.copy_to( (RefEntity**)*intersect_entity_handles );
    3604         [ #  # ]:          0 :   params.copy_to( *param_coords );
    3605                 :            :   
    3606                 :          0 :   double *x = *intersect_coords;
    3607                 :          0 :   double *y = x + init;
    3608                 :          0 :   double *z = y + init;
    3609 [ #  # ][ #  # ]:          0 :   for (std::vector<CubitVector>::const_iterator k = coords.begin(); k != coords.end(); ++k)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3610                 :            :   {
    3611 [ #  # ][ #  # ]:          0 :     k->get_xyz( *x, *y, *z );
    3612                 :          0 :     x += step;
    3613                 :          0 :     y += step;
    3614                 :          0 :     z += step;
    3615                 :            :   }
    3616                 :            :   
    3617         [ #  # ]:          0 :   KEEP_ARRAY(offset);
    3618 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3619                 :            : }
    3620                 :            : 
    3621                 :            : ITAPS_API void
    3622                 :          0 : iGeom_getPntClsf( iGeom_Instance instance,
    3623                 :            :                   /*in*/ double x,
    3624                 :            :                   /*in*/ double y,
    3625                 :            :                   /*in*/ double z,
    3626                 :            :                   /*out*/ iBase_EntityHandle* entity_handle,
    3627                 :            :                   int* err )
    3628                 :            : {
    3629                 :          0 :   RefEntity** ptr = (RefEntity**)entity_handle;
    3630         [ #  # ]:          0 :   const CubitVector pt(x,y,z);
    3631         [ #  # ]:          0 :   *ptr = iGeom_get_point_containment( pt );
    3632 [ #  # ][ #  # ]:          0 :   RETURN( *ptr ? iBase_SUCCESS : iBase_FAILURE );
    3633                 :            : }
    3634                 :            : 
    3635                 :            : ITAPS_API void
    3636                 :          0 : iGeom_getPntArrClsf( iGeom_Instance instance,
    3637                 :            :                      /*in*/ int storage_order,
    3638                 :            :                      /*in*/ const double *coords,
    3639                 :            :                      int coords_size,
    3640                 :            :                      /*inout*/ iBase_EntityHandle **entity_handles,
    3641                 :            :                      int *entity_handles_allocated,
    3642                 :            :                      int *entity_handles_size,
    3643                 :            :                      int* err )
    3644                 :            : {
    3645                 :            :   size_t init, step;
    3646                 :          0 :   int count = coords_size / 3;
    3647         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    3648                 :          0 :     init = count;
    3649                 :          0 :     step = 1;
    3650                 :            :   }
    3651                 :            :   else {
    3652                 :          0 :     storage_order = iBase_INTERLEAVED;
    3653                 :          0 :     init = 1;
    3654                 :          0 :     step = 3;
    3655                 :            :   }
    3656                 :          0 :   const double *x = coords;
    3657                 :          0 :   const double *y = x + init;
    3658                 :          0 :   const double *z = y + init;
    3659                 :            :   
    3660 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( entity_handles, count );
    3661                 :            :   
    3662                 :          0 :   RefEntity** array = (RefEntity**)*entity_handles;
    3663         [ #  # ]:          0 :   for (int i = 0; i < count; ++i)
    3664                 :            :   {
    3665         [ #  # ]:          0 :     const CubitVector pt( *x, *y, *z );
    3666         [ #  # ]:          0 :     array[i] = iGeom_get_point_containment( pt );
    3667         [ #  # ]:          0 :     if (!array[i]) {
    3668         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    3669                 :            :     }
    3670                 :          0 :     x += step;
    3671                 :          0 :     y += step;
    3672                 :          0 :     z += step;
    3673                 :            :   }
    3674                 :            :   
    3675         [ #  # ]:          0 :   KEEP_ARRAY(entity_handles);
    3676 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3677                 :            : }
    3678                 :            : 
    3679                 :            : /**
    3680                 :            :  * Return the sense of a face with respect to a region.  Sense is either
    3681                 :            :  * forward (=1), reverse (=-1), both (=0).  Error is returned
    3682                 :            :  * if first entity is not a gface or second entity is not a gregion.
    3683                 :            :  * @param gface face whose sense is being queried.
    3684                 :            :  * @param gregion region gface is being queried with respect to
    3685                 :            :  */
    3686                 :            : ITAPS_API void
    3687                 :        686 : iGeom_getEntNrmlSense( iGeom_Instance instance,
    3688                 :            :                        /*in*/ iBase_EntityHandle gface,
    3689                 :            :                        /*in*/ iBase_EntityHandle gregion,
    3690                 :            :                        int* rel_sense,
    3691                 :            :                        int* err )
    3692                 :            : {
    3693         [ -  + ]:        686 :   const RefFace *face_ent = dynamic_cast<const RefFace*>(ENTITY_HANDLE(gface));
    3694         [ -  + ]:        686 :   if (NULL == face_ent) {
    3695                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "1st argument to getEntNrmlSense must be a face.");
    3696                 :            :   }
    3697                 :            : 
    3698                 :            :   // XXX: workaround; remove this when we switch iBase_REGIONs to RefVolume
    3699                 :            :   const RefVolume *volume_ent;
    3700         [ -  + ]:        686 :   Body *body_ent = dynamic_cast<Body*>(ENTITY_HANDLE(gregion));
    3701         [ +  - ]:        686 :   if (NULL != body_ent) {
    3702         [ +  - ]:        686 :     DLIList<RefEntity*> children;
    3703         [ +  - ]:        686 :     body_ent->get_child_ref_entities(children);
    3704 [ +  - ][ -  + ]:        686 :     if (children.size() != 1) {
    3705         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Can only support bodies with one volume");
    3706                 :            :     }
    3707 [ +  - ][ -  + ]:        686 :     volume_ent = dynamic_cast<const RefVolume*>(children[0]);
         [ +  - ][ +  - ]
    3708                 :            :   }
    3709                 :            :   else {
    3710         [ #  # ]:          0 :     volume_ent = dynamic_cast<const RefVolume*>(ENTITY_HANDLE(gregion));
    3711                 :            :   }
    3712                 :            : 
    3713         [ -  + ]:        686 :   if (NULL == volume_ent) {
    3714                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "2nd argument to getEntNrmlSense must be a region.");
    3715                 :            :   }
    3716                 :            : 
    3717                 :        686 :   *rel_sense = iGeom_get_nonmanifold_sense( face_ent, volume_ent, err );
    3718                 :            : }
    3719                 :            : 
    3720                 :            : ITAPS_API void
    3721                 :          0 : iGeom_getArrNrmlSense( iGeom_Instance instance,
    3722                 :            :                        /*in*/ iBase_EntityHandle const *faces,
    3723                 :            :                        int faces_size,
    3724                 :            :                        /*in*/ iBase_EntityHandle const *regions,
    3725                 :            :                        int regions_size,
    3726                 :            :                        /*inout*/ int **senses,
    3727                 :            :                        int *senses_allocated,
    3728                 :            :                        int *senses_size,
    3729                 :            :                        int* err )
    3730                 :            : {
    3731                 :            :   size_t faces_step, regions_step;
    3732                 :            :   int count;
    3733         [ #  # ]:          0 :   if (faces_size == regions_size) {
    3734                 :          0 :     faces_step = regions_step = 1;
    3735                 :          0 :     count = faces_size;
    3736                 :            :   }
    3737         [ #  # ]:          0 :   else if (faces_size == 1) {
    3738                 :          0 :     faces_step = 0;
    3739                 :          0 :     regions_step = 1;
    3740                 :          0 :     count = regions_size;
    3741                 :            :   }
    3742         [ #  # ]:          0 :   else if (regions_size == 1) {
    3743                 :          0 :     faces_step = 1;
    3744                 :          0 :     regions_step = 0;
    3745                 :          0 :     count = faces_size;
    3746                 :            :   }
    3747                 :            :   else {
    3748         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes" );
    3749                 :            :     RETURN (iBase_INVALID_ENTITY_COUNT);
    3750                 :            :   }
    3751                 :            :   
    3752                 :          0 :   RefEntity** face_iter = (RefEntity**)faces;
    3753                 :          0 :   RefEntity** region_iter = (RefEntity**)regions;
    3754 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( senses, count );
    3755         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    3756         [ #  # ]:          0 :     RefFace *face_ent = dynamic_cast<RefFace*>(*face_iter);
    3757         [ #  # ]:          0 :     if (NULL == face_ent) {
    3758         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "1st argument to getArrNrmlSense must be a face.");
    3759                 :            :     }
    3760                 :            : 
    3761                 :            :     // XXX: workaround; remove this when we switch iBase_REGIONs to RefVolume
    3762                 :            :     const RefVolume *volume_ent;
    3763         [ #  # ]:          0 :     Body *body_ent = dynamic_cast<Body*>(*region_iter);
    3764         [ #  # ]:          0 :     if (NULL != body_ent) {
    3765         [ #  # ]:          0 :       DLIList<RefEntity*> children;
    3766         [ #  # ]:          0 :       body_ent->get_child_ref_entities(children);
    3767 [ #  # ][ #  # ]:          0 :       if (children.size() != 1) {
    3768         [ #  # ]:          0 :         ERROR(iBase_FAILURE, "Can only support bodies with one volume");
    3769                 :            :       }
    3770 [ #  # ][ #  # ]:          0 :       volume_ent = dynamic_cast<const RefVolume*>(children[0]);
         [ #  # ][ #  # ]
    3771                 :            :     }
    3772                 :            :     else {
    3773         [ #  # ]:          0 :       volume_ent = dynamic_cast<const RefVolume*>(*region_iter);
    3774                 :            :     }
    3775                 :            : 
    3776         [ #  # ]:          0 :     if (NULL == volume_ent) {
    3777         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "2nd argument to getArrNrmlSense must be a region.");
    3778                 :            :     }
    3779                 :            : 
    3780         [ #  # ]:          0 :     (*senses)[i] = iGeom_get_nonmanifold_sense( face_ent, volume_ent, err );
    3781         [ #  # ]:          0 :     if (iBase_SUCCESS != *err)
    3782                 :          0 :       return;
    3783                 :            : 
    3784                 :          0 :     face_iter += faces_step;
    3785                 :          0 :     region_iter += regions_step;
    3786                 :            :   }
    3787                 :            :   
    3788         [ #  # ]:          0 :   KEEP_ARRAY(senses);
    3789 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3790                 :            : }
    3791                 :            : 
    3792                 :            : 
    3793                 :            : 
    3794                 :            : /**
    3795                 :            :  * Return the sense of a gedge with respect to a gface.  Sense is either
    3796                 :            :  * forward (=1), reverse (=-1), both (=0), or unknown (=2).  Error is returned
    3797                 :            :  * if first entity is not a gedge or second entity is not a gface.
    3798                 :            :  * @param gedge Gedge whose sense is being queried.
    3799                 :            :  * @param gface Gface gedge is being queried with respect to
    3800                 :            :  */
    3801                 :            : ITAPS_API void
    3802                 :        680 : iGeom_getEgFcSense( iGeom_Instance instance,
    3803                 :            :                     /*in*/ iBase_EntityHandle gedge,
    3804                 :            :                     /*in*/ iBase_EntityHandle gface,
    3805                 :            :                     int* rel_sense,
    3806                 :            :                     int* err )
    3807                 :            : {
    3808         [ -  + ]:        680 :   const RefEdge *edge_ent = dynamic_cast<const RefEdge*>(ENTITY_HANDLE(gedge));
    3809         [ -  + ]:        680 :   if (NULL == edge_ent) {
    3810                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "1st argument to getGtangentSense must be an edge.");
    3811                 :            :   }
    3812         [ -  + ]:        680 :   const RefFace *face_ent = dynamic_cast<const RefFace*>(ENTITY_HANDLE(gface));
    3813         [ -  + ]:        680 :   if (NULL == face_ent) {
    3814                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "2nd argument to getGtangentSense must be a face.");
    3815                 :            :   }
    3816                 :        680 :   *rel_sense = iGeom_get_nonmanifold_sense( edge_ent, face_ent, err );
    3817                 :        680 :   RETURN(iBase_SUCCESS);
    3818                 :            : }
    3819                 :            : 
    3820                 :            : ITAPS_API void
    3821                 :          0 : iGeom_getEgFcArrSense( iGeom_Instance instance,
    3822                 :            :                        /*in*/ iBase_EntityHandle const *edges,
    3823                 :            :                        int edges_size,
    3824                 :            :                        /*in*/ iBase_EntityHandle const *faces,
    3825                 :            :                        int faces_size,
    3826                 :            :                        /*inout*/ int **senses,
    3827                 :            :                        int *senses_allocated,
    3828                 :            :                        int *senses_size,
    3829                 :            :                        int* err )
    3830                 :            : {
    3831                 :            :   size_t faces_step, edges_step;
    3832                 :            :   int count;
    3833         [ #  # ]:          0 :   if (faces_size == edges_size) {
    3834                 :          0 :     faces_step = edges_step = 1;
    3835                 :          0 :     count = faces_size;
    3836                 :            :   }
    3837         [ #  # ]:          0 :   else if (faces_size == 1) {
    3838                 :          0 :     faces_step = 0;
    3839                 :          0 :     edges_step = 1;
    3840                 :          0 :     count = edges_size;
    3841                 :            :   }
    3842         [ #  # ]:          0 :   else if (edges_size == 1) {
    3843                 :          0 :     faces_step = 1;
    3844                 :          0 :     edges_step = 0;
    3845                 :          0 :     count = faces_size;
    3846                 :            :   }
    3847                 :            :   else {
    3848         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes" );
    3849                 :            :   }
    3850                 :            :   
    3851                 :          0 :   RefEntity** face_iter = (RefEntity**)faces;
    3852                 :          0 :   RefEntity** edge_iter = (RefEntity**)edges;
    3853 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( senses, count );
    3854         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    3855         [ #  # ]:          0 :     RefEdge *edge_ent = dynamic_cast<RefEdge*>(*edge_iter);
    3856         [ #  # ]:          0 :     if (NULL == edge_ent) {
    3857         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "1st argument to getGnormalSense must be a face.");
    3858                 :            :     }
    3859         [ #  # ]:          0 :     RefFace *face_ent = dynamic_cast<RefFace*>(*face_iter);
    3860         [ #  # ]:          0 :     if (NULL == face_ent) {
    3861         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "2nd argument to getGnormalSense must be a region.");
    3862                 :            :     }
    3863         [ #  # ]:          0 :     (*senses)[i] = iGeom_get_nonmanifold_sense( edge_ent, face_ent, err );
    3864         [ #  # ]:          0 :     if (iBase_SUCCESS != *err)
    3865                 :          0 :       return;
    3866                 :            : 
    3867                 :          0 :     face_iter += faces_step;
    3868                 :          0 :     edge_iter += edges_step;
    3869                 :            :   }
    3870                 :            :   
    3871         [ #  # ]:          0 :   KEEP_ARRAY(senses);
    3872 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3873                 :            : }
    3874                 :            : 
    3875                 :            : /**
    3876                 :            :  * Return the sense of a gedge with respect to a specified order of
    3877                 :            :  * vertices bounding the gedge.  Sense is either forward (=1), reverse (=-1), 
    3878                 :            :  * or closed (=0).  Error is returned if any gentities are not the expected
    3879                 :            :  * type or if the gedge is bounded by only one gvertex (in this case, use
    3880                 :            :  * getGtangentSense).
    3881                 :            :  * @param gedge Gedge whose sense is being queried.
    3882                 :            :  * @param gvertex1 First gvertex
    3883                 :            :  * @param gvertex2 Second gvertex
    3884                 :            :  */
    3885                 :            : ITAPS_API void
    3886                 :          0 : iGeom_getEgVtxSense( iGeom_Instance instance,
    3887                 :            :                      /*in*/ iBase_EntityHandle gedge,
    3888                 :            :                      /*in*/ iBase_EntityHandle gvertex1,
    3889                 :            :                      /*in*/ iBase_EntityHandle gvertex2,
    3890                 :            :                      int* rel_sense,
    3891                 :            :                      int* err )
    3892                 :            : {
    3893         [ #  # ]:          0 :   const RefEdge *this_edge = dynamic_cast<const RefEdge*>(ENTITY_HANDLE(gedge));
    3894         [ #  # ]:          0 :   const RefVertex *vertex1 = dynamic_cast<const RefVertex*>(ENTITY_HANDLE(gvertex1));
    3895         [ #  # ]:          0 :   const RefVertex *vertex2 = dynamic_cast<const RefVertex*>(ENTITY_HANDLE(gvertex2));
    3896 [ #  # ][ #  # ]:          0 :   if (NULL == this_edge || NULL == vertex1 || NULL == vertex2) {
                 [ #  # ]
    3897                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Bad entity argument to getGvertexTangentSense.");
    3898                 :            :   }
    3899                 :          0 :   *rel_sense = iGeom_edge_vertex_sense( this_edge, vertex1, vertex2, err );
    3900                 :          0 :   RETURN(iBase_SUCCESS);
    3901                 :            : }
    3902                 :            : 
    3903                 :            : ITAPS_API void
    3904                 :          0 : iGeom_getEgVtxArrSense( iGeom_Instance instance,
    3905                 :            :                         /*in*/ iBase_EntityHandle const *edges ,
    3906                 :            :                         int edges_size,
    3907                 :            :                         /*in*/ iBase_EntityHandle const *start_vertices ,
    3908                 :            :                         int start_vertices_size,
    3909                 :            :                         /*in*/ iBase_EntityHandle const *end_vertices ,
    3910                 :            :                         int end_vertices_size,
    3911                 :            :                         /*inout*/  int **senses ,
    3912                 :            :                         int *senses_allocated,
    3913                 :            :                         int *senses_size,
    3914                 :            :                         int* err )
    3915                 :            : {
    3916                 :            :   int count;
    3917                 :            :   size_t edge_step, start_step, end_step;
    3918                 :          0 :   edge_step = edges_size > 1;
    3919                 :          0 :   start_step = start_vertices_size > 1;
    3920                 :          0 :   end_step = end_vertices_size > 1;
    3921                 :          0 :   count = edges_size;
    3922         [ #  # ]:          0 :   if (count != 1) {
    3923 [ #  # ][ #  # ]:          0 :     if (start_vertices_size != 1 && start_vertices_size != count) {
    3924         [ #  # ]:          0 :       ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes" );
    3925                 :            :     }
    3926                 :            :   }
    3927                 :            :   else
    3928                 :          0 :     count = start_vertices_size;
    3929         [ #  # ]:          0 :   if (count != 1) {
    3930 [ #  # ][ #  # ]:          0 :     if (end_vertices_size != 1 && end_vertices_size != count) {
    3931         [ #  # ]:          0 :       ERROR( iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes" );
    3932                 :            :     }
    3933                 :            :   }
    3934                 :            :   else
    3935                 :          0 :     count = end_vertices_size;
    3936                 :            :     
    3937 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( senses, count );
    3938                 :            :   
    3939                 :          0 :   RefEntity** edge_iter = (RefEntity**)edges;
    3940                 :          0 :   RefEntity** start_iter = (RefEntity**)start_vertices;
    3941                 :          0 :   RefEntity** end_iter = (RefEntity**)end_vertices;
    3942         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    3943         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*edge_iter);
    3944         [ #  # ]:          0 :     RefVertex* vtx1 = dynamic_cast<RefVertex*>(*start_iter);
    3945         [ #  # ]:          0 :     RefVertex* vtx2 = dynamic_cast<RefVertex*>(*end_iter);
    3946 [ #  # ][ #  # ]:          0 :     if (!edge || !vtx1 || !vtx2) {
                 [ #  # ]
    3947         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Bad entity argument to getGvertexTangentSense.");
    3948                 :            :     }
    3949                 :            :     
    3950         [ #  # ]:          0 :     (*senses)[i] = iGeom_edge_vertex_sense( edge, vtx1, vtx2, err );
    3951         [ #  # ]:          0 :     if (iBase_SUCCESS != *err)
    3952                 :          0 :       return;
    3953                 :          0 :     edge_iter += edge_step;
    3954                 :          0 :     start_iter += start_step;
    3955                 :          0 :     end_iter += end_step;
    3956                 :            :   }
    3957                 :            :   
    3958         [ #  # ]:          0 :   KEEP_ARRAY(senses);
    3959 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    3960                 :            : }
    3961                 :            :   
    3962                 :            :   
    3963                 :            :     
    3964                 :            :       
    3965                 :            : 
    3966                 :            : /**
    3967                 :            :  * Returns the number of gentity_sets contained in a given model or
    3968                 :            :  * gentity_set one level deep
    3969                 :            :  * @param gentity_set_handle Entity set being queried
    3970                 :            :  * @return Number of entity sets in gentity_set_handle
    3971                 :            :  */
    3972                 :            : ITAPS_API void
    3973                 :          2 : iGeom_getNumEntSets( iGeom_Instance instance,
    3974                 :            :                      /*in*/ iBase_EntitySetHandle entity_set,
    3975                 :            :                      /*in*/ int num_hops,
    3976                 :            :                      int* num_ent_sets,
    3977                 :            :                      int* err )
    3978                 :            : {
    3979                 :            :     // HJK: num_hops has to be handled
    3980         [ -  + ]:          2 :   if (0 < num_hops) {
    3981                 :          0 :     ERROR(iBase_NOT_SUPPORTED, "Num_hops argument not yet supported.");
    3982                 :            :   }
    3983                 :            :   
    3984                 :          2 :   const RefGroup *this_set = SET_HANDLE(entity_set);
    3985         [ +  + ]:          2 :   if (NULL == this_set)
    3986                 :          1 :     *num_ent_sets = RefEntityFactory::instance()->num_ref_groups();
    3987                 :            :   else {
    3988         [ +  - ]:          1 :     DLIList<RefEntity*> tmp_ents;
    3989 [ +  - ][ +  - ]:          2 :     DLIList<RefGroup*> groups;
    3990         [ +  - ]:          1 :     const_cast<RefGroup*>(this_set)->get_child_ref_entities(tmp_ents);
    3991 [ +  - ][ +  - ]:          5 :     CAST_LIST(tmp_ents, groups, RefGroup);
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
                 [ +  + ]
    3992 [ +  - ][ +  - ]:          2 :     *num_ent_sets = groups.size();
    3993                 :            :   }
    3994                 :            : 
    3995                 :          2 :   RETURN(iBase_SUCCESS);
    3996                 :            : }
    3997                 :            : 
    3998                 :            : /**
    3999                 :            :  * Returns the gentity_set handles contained in a given model or
    4000                 :            :  * gentity_set one level deep
    4001                 :            :  * @param gentity_set_handle Entity set being queried
    4002                 :            :  * @param contained_gentity_set_handles Number of entity sets in 
    4003                 :            :  *  gentity_set_handle
    4004                 :            :  */
    4005                 :            : ITAPS_API void
    4006                 :          3 : iGeom_getEntSets( iGeom_Instance instance,
    4007                 :            :                   /*in*/ iBase_EntitySetHandle entity_set,
    4008                 :            :                   /*in*/ int num_hops,
    4009                 :            :                   /*inout*/ iBase_EntitySetHandle **contained_entity_set_handles,
    4010                 :            :                   int *contained_entity_set_handles_allocated,
    4011                 :            :                   int *contained_entity_set_handles_size,
    4012                 :            :                   int *err )
    4013                 :            : {
    4014         [ -  + ]:          3 :   if (0 < num_hops) {
    4015         [ #  # ]:          0 :     ERROR(iBase_NOT_SUPPORTED, "Num_hops argument not yet supported.");
    4016                 :            :   }
    4017                 :            : 
    4018                 :          3 :   const RefGroup *this_set = SET_HANDLE(entity_set);
    4019         [ +  - ]:          3 :   DLIList<RefEntity*> tmp_ents;
    4020 [ +  - ][ +  - ]:          6 :   DLIList<RefGroup*> groups;
    4021         [ +  + ]:          3 :   if (NULL == this_set)
    4022 [ +  - ][ +  - ]:          1 :     RefEntityFactory::instance()->ref_groups(groups);
    4023                 :            :   else {
    4024         [ +  - ]:          2 :     const_cast<RefGroup*>(this_set)->get_child_ref_entities(tmp_ents);
    4025 [ +  - ][ +  - ]:         10 :     CAST_LIST(tmp_ents, groups, RefGroup);
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
                 [ +  + ]
    4026                 :            :   }
    4027                 :            :   
    4028 [ +  - ][ +  - ]:          6 :   ALLOC_CHECK_ARRAY_NOFAIL(contained_entity_set_handles, groups.size());
         [ -  + ][ +  - ]
                 [ +  - ]
    4029                 :            : 
    4030         [ +  - ]:          3 :   groups.copy_to(*SET_HANDLE_ARRAY_PTR(contained_entity_set_handles));
    4031                 :            :   
    4032 [ +  - ][ +  - ]:          6 :   RETURN(iBase_SUCCESS);
    4033                 :            : }
    4034                 :            : 
    4035                 :            : /**
    4036                 :            :  * This function allows a new gentity_set to be created.  The user may 
    4037                 :            :  * set the multiset, ordered, isMesh, flags as needed; otherwise default values 
    4038                 :            :  * (all false) will be used.  On creation, Entitysets are empty of
    4039                 :            :  * entities and contained in the parent geometry interface.  They must be
    4040                 :            :  * explicitly filled with entities using the addGentities call and
    4041                 :            :  * relationships with other Entitysets must be done through the
    4042                 :            :  * addEntityset and parent/child relationship calls.
    4043                 :            :  * @param multiset If true, gentities can appear more than once in this gentity_set
    4044                 :            :  * @param ordered If true, order of addition and removal is maintained for
    4045                 :            :  *   this gentity_set
    4046                 :            :  * @param gentity_set_created Entity_set created by this function
    4047                 :            :  */
    4048                 :            : ITAPS_API void
    4049                 :          8 : iGeom_createEntSet( iGeom_Instance instance,
    4050                 :            :                     /*in*/ int isList,
    4051                 :            :                     /*out*/ iBase_EntitySetHandle *entity_set,
    4052                 :            :                     int* err )
    4053                 :            : {
    4054                 :          8 :   RefGroup* grp = RefEntityFactory::instance()->construct_RefGroup();
    4055                 :          8 :   *entity_set = reinterpret_cast<iBase_EntitySetHandle>(grp);
    4056                 :            :     // need to set a tag denoting multiset or not...
    4057         [ -  + ]:          8 :   if (*entity_set == NULL) {
    4058                 :          0 :     RETURN(iBase_FAILURE);
    4059                 :            :   }
    4060                 :            :   
    4061                 :            :   else {
    4062                 :          8 :     RETURN(iBase_SUCCESS);
    4063                 :            :   }
    4064                 :            : }
    4065                 :            : 
    4066                 :            : /**
    4067                 :            :  *   Destroy the gentity set.  This method only destroys the grouping of
    4068                 :            :  *   gentities, not the gentities themselves.
    4069                 :            :  * @param gentity_set Entity_set to be destroyed
    4070                 :            :  */
    4071                 :            : ITAPS_API void
    4072                 :          0 : iGeom_destroyEntSet( iGeom_Instance instance,
    4073                 :            :                      /*in*/ iBase_EntitySetHandle entity_set,
    4074                 :            :                      int* err )
    4075                 :            : {
    4076         [ #  # ]:          0 :   if (NULL == entity_set) {
    4077                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Can't destroy interface set.");
    4078                 :            :   }
    4079                 :            :       
    4080                 :          0 :   CubitStatus result = RefGroup::delete_group(SET_HANDLE(entity_set));
    4081         [ #  # ]:          0 :   if (CUBIT_SUCCESS == result) {
    4082                 :          0 :     RETURN(iBase_SUCCESS);
    4083                 :            :   }
    4084                 :            :   
    4085                 :            :   else {
    4086                 :          0 :     RETURN(iBase_FAILURE);
    4087                 :            :   }
    4088                 :            :   
    4089                 :            : }
    4090                 :            : 
    4091                 :            : ITAPS_API void
    4092                 :          0 : iGeom_isList( iGeom_Instance instance,
    4093                 :            :               /*in*/ iBase_EntitySetHandle entity_set,
    4094                 :            :               int* result,
    4095                 :            :               int* err )
    4096                 :            : {
    4097                 :          0 :   *result = true;
    4098                 :          0 :   RETURN (iBase_SUCCESS);
    4099                 :            : }
    4100                 :            : 
    4101                 :            : /**
    4102                 :            :  *   Allows the user to explicitly add one or more gentity_sets to
    4103                 :            :  *   another.  This automatically sets the contained in relationship,
    4104                 :            :  *   but not the parent/child relationships.  All gentity_set handles
    4105                 :            :  *   are automatically contained in the parent mesh interface, so
    4106                 :            :  *   passing in NULL as the first argument results in no action.
    4107                 :            :  * @param gentity_set Set to which other sets are being added
    4108                 :            :  * @param gentity_set_handles Sets added to gentity_set
    4109                 :            :  */
    4110                 :            : ITAPS_API void
    4111                 :          4 : iGeom_addEntSet( iGeom_Instance instance,
    4112                 :            :                  /*in*/ iBase_EntitySetHandle entity_set_to_add,
    4113                 :            :                  /*inout*/ iBase_EntitySetHandle entity_set_handle,
    4114                 :            :                  int* err )
    4115                 :            : {
    4116                 :          4 :   iGeom_addEntToSet(instance, reinterpret_cast<iBase_EntityHandle>(entity_set_to_add), entity_set_handle, err);
    4117                 :          4 : }
    4118                 :            : 
    4119                 :            : /**
    4120                 :            :  *   Allows the user to remove one or more gentity_sets from another
    4121                 :            :  *   gentity_set.  Users cannot delete a contained in relationship of an
    4122                 :            :  *   gentity set with the parent mesh interface so passing in a NULL
    4123                 :            :  *   value for the first argument results in no action.
    4124                 :            :  * @param gentity_set Set from which other sets are being removed
    4125                 :            :  * @param gentity_set_handles Sets being removed from gentity_set
    4126                 :            :  */
    4127                 :            : ITAPS_API void
    4128                 :          0 : iGeom_rmvEntSet( iGeom_Instance instance,
    4129                 :            :                  /*in*/ iBase_EntitySetHandle entity_set_to_remove,
    4130                 :            :                  /*inout*/ iBase_EntitySetHandle entity_set_handle,
    4131                 :            :                  int* err )
    4132                 :            : {
    4133                 :          0 :   iGeom_rmvEntFromSet(instance, reinterpret_cast<iBase_EntityHandle>(entity_set_to_remove), entity_set_handle, err);
    4134                 :          0 : }
    4135                 :            : 
    4136                 :            : /**
    4137                 :            :  *   Allows the user to explicitly add one or more gentity_sets to
    4138                 :            :  *   another.  This automatically sets the contained in relationship,
    4139                 :            :  *   but not the parent/child relationships.  All gentity_set handles
    4140                 :            :  *   are automatically contained in the parent mesh interface, so
    4141                 :            :  *   passing in NULL as the first argument results in no action.
    4142                 :            :  * @param gentity_set Set to which other sets are being added
    4143                 :            :  * @param gentity_set_handles Sets added to gentity_set
    4144                 :            :  */
    4145                 :            : ITAPS_API void
    4146                 :          4 : iGeom_addEntToSet( iGeom_Instance instance,
    4147                 :            :                    /*in*/ iBase_EntityHandle entity_to_add,
    4148                 :            :                    /*inout*/ iBase_EntitySetHandle entity_set_handle,
    4149                 :            :                    int* err )
    4150                 :            : {
    4151         [ -  + ]:          4 :   if (NULL == entity_to_add) RETURN(iBase_INVALID_ARGUMENT);
    4152                 :            :   
    4153                 :            :   CubitStatus status = SET_HANDLE(entity_set_handle)->
    4154                 :          4 :     add_ref_entity(const_cast<RefEntity*>(ENTITY_HANDLE(entity_to_add)));
    4155                 :            :   
    4156         [ -  + ]:          4 :   if (CUBIT_SUCCESS != status) {
    4157                 :          0 :     ERROR(iBase_FAILURE, "Problem adding entity to another set.");
    4158                 :            :   }
    4159                 :            : 
    4160                 :          4 :   RETURN(iBase_SUCCESS);
    4161                 :            : }
    4162                 :            : 
    4163                 :            : /**
    4164                 :            :  *   Allows the user to remove one or more gentity_sets from another
    4165                 :            :  *   gentity_set.  Users cannot delete a contained in relationship of an
    4166                 :            :  *   gentity set with the parent mesh interface so passing in a NULL
    4167                 :            :  *   value for the first argument results in no action.
    4168                 :            :  * @param gentity_set Set from which other sets are being removed
    4169                 :            :  * @param gentity_set_handles Sets being removed from gentity_set
    4170                 :            :  */
    4171                 :            : ITAPS_API void
    4172                 :          0 : iGeom_rmvEntFromSet( iGeom_Instance instance,
    4173                 :            :                      /*in*/ iBase_EntityHandle entity_to_remove,
    4174                 :            :                      /*inout*/ iBase_EntitySetHandle entity_set_handle,
    4175                 :            :                      int* err )
    4176                 :            : {
    4177         [ #  # ]:          0 :   if (NULL == entity_set_handle) RETURN(iBase_INVALID_ARGUMENT);
    4178                 :            :   
    4179                 :            :   CubitStatus status = SET_HANDLE(entity_set_handle)->
    4180                 :          0 :     remove_ref_entity(const_cast<RefEntity*>(ENTITY_HANDLE(entity_to_remove)));
    4181         [ #  # ]:          0 :   if (CUBIT_SUCCESS != status) {
    4182                 :          0 :     ERROR(iBase_FAILURE, "Problem removing entity from a set.");
    4183                 :            :   }
    4184                 :            :   
    4185                 :          0 :   RETURN(iBase_SUCCESS);
    4186                 :            : }
    4187                 :            : 
    4188                 :            : ITAPS_API void
    4189                 :          0 : iGeom_isEntContained( iGeom_Instance instance,
    4190                 :            :                       /*in*/ iBase_EntitySetHandle containing_entity_set,
    4191                 :            :                       /*in*/ iBase_EntityHandle contained_entity,
    4192                 :            :                       int* is_contained,
    4193                 :            :                       int* err )
    4194                 :            : {
    4195                 :            :     // everything is contained in root set
    4196 [ #  # ][ #  # ]:          0 :   if (NULL == containing_entity_set && NULL != contained_entity) {
    4197                 :          0 :     *is_contained = true;
    4198         [ #  # ]:          0 :     RETURN( iBase_SUCCESS );
    4199                 :            :   }
    4200                 :            : 
    4201         [ #  # ]:          0 :   DLIList<RefGroup*> containing_groups;
    4202                 :          0 :   RefEntity *contained_entity_temp = const_cast<RefEntity*>(ENTITY_HANDLE(contained_entity));
    4203         [ #  # ]:          0 :   RefGroup::get_groups_within(contained_entity_temp, containing_groups, CUBIT_FALSE);
    4204 [ #  # ][ #  # ]:          0 :   *is_contained = containing_groups.size() > 0 &&
                 [ #  # ]
    4205 [ #  # ][ #  # ]:          0 :       containing_groups.move_to(const_cast<RefGroup*>(SET_HANDLE(containing_entity_set))) ;
                 [ #  # ]
    4206                 :            : 
    4207 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4208                 :            : }
    4209                 :            : 
    4210                 :            : ITAPS_API void
    4211                 :          0 : iGeom_isEntArrContained( iGeom_Instance instance,
    4212                 :            :                          /*in*/ iBase_EntitySetHandle containing_set,
    4213                 :            :                          /*in*/ const iBase_EntityHandle* entity_handles,
    4214                 :            :                          /*in*/ int num_entity_handles,
    4215                 :            :                          /*inout*/ int** is_contained,
    4216                 :            :                          /*inout*/ int* is_contained_allocated,
    4217                 :            :                          /*out*/ int* is_contained_size,
    4218                 :            :                          /*out*/ int* err )
    4219                 :            : {
    4220                 :            :     // go through each entity and look up its dimension
    4221 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(is_contained, num_entity_handles);
    4222                 :            : 
    4223         [ #  # ]:          0 :   for (int i = 0; i < num_entity_handles; ++i) {
    4224         [ #  # ]:          0 :     iGeom_isEntContained( instance, containing_set, entity_handles[i], (*is_contained)+i, err );
    4225         [ #  # ]:          0 :     if (iBase_SUCCESS != *err)
    4226                 :          0 :       return;
    4227                 :            :   }
    4228                 :            : 
    4229         [ #  # ]:          0 :   KEEP_ARRAY(is_contained);
    4230 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4231                 :            : }
    4232                 :            : 
    4233                 :            : ITAPS_API void
    4234                 :          0 : iGeom_isEntSetContained( iGeom_Instance instance,
    4235                 :            :                          /*in*/ iBase_EntitySetHandle containing_entity_set,
    4236                 :            :                          /*in*/ iBase_EntitySetHandle contained_entity_set,
    4237                 :            :                          int* is_contained,
    4238                 :            :                          int* err )
    4239                 :            : {
    4240                 :            :   iGeom_isEntContained( instance, containing_entity_set, 
    4241                 :            :                         reinterpret_cast<iBase_EntityHandle>(contained_entity_set),
    4242                 :          0 :                         is_contained, err);
    4243                 :          0 : }
    4244                 :            : 
    4245                 :            : /**
    4246                 :            :  *   Add existing gentities to the gentity_set (do not create them).
    4247                 :            :  *   Note that if a gentity of dimension d>0 is added to the gentityset,
    4248                 :            :  *   the lower-dimensional gentities that bound it are not
    4249                 :            :  *   automatically associated with the gentityset.
    4250                 :            :  * @param gentity_set Set being added to
    4251                 :            :  * @param gentity_handles Gentities being added to gentity_set
    4252                 :            :  */
    4253                 :            : ITAPS_API void
    4254                 :          9 : iGeom_addEntArrToSet( iGeom_Instance instance,
    4255                 :            :                       /*in*/ iBase_EntityHandle const* entity_handles,
    4256                 :            :                       int entity_handles_size,
    4257                 :            :                       /*inout*/ iBase_EntitySetHandle entity_set,
    4258                 :            :                       int* err )
    4259                 :            : {
    4260         [ -  + ]:          9 :   if (NULL == entity_set) RETURN(iBase_INVALID_ARGUMENT);
    4261                 :            : 
    4262                 :          9 :   RefGroup *this_set = SET_HANDLE(entity_set);
    4263                 :          9 :   RefEntity **ent_array = (RefEntity**)(entity_handles);
    4264                 :          9 :   CubitStatus status = CUBIT_SUCCESS, tmp_status;
    4265         [ +  + ]:        776 :   for (int i = 0; i < entity_handles_size; i++) {
    4266                 :        767 :     tmp_status = this_set->add_ref_entity(ent_array[i]);
    4267         [ -  + ]:        767 :     if (CUBIT_SUCCESS != tmp_status) status = tmp_status;
    4268                 :            :   }
    4269                 :            : 
    4270         [ -  + ]:          9 :   if (CUBIT_SUCCESS != status) {
    4271                 :          0 :     ERROR(iBase_FAILURE, "Problem adding entities to a set.");
    4272                 :            :   }
    4273                 :            :   
    4274                 :          9 :   RETURN(iBase_SUCCESS);
    4275                 :            : }
    4276                 :            : 
    4277                 :            : /**
    4278                 :            :  *   Remove existing gentities from the gentity_set (do not delete them)
    4279                 :            :  * @param gentity_set Set being removed from
    4280                 :            :  * @param gentity_handles Gentities being removed from gentity_set
    4281                 :            :  */
    4282                 :            : ITAPS_API void
    4283                 :          1 : iGeom_rmvEntArrFromSet( iGeom_Instance instance,
    4284                 :            :                         /*in*/ iBase_EntityHandle const* entity_handles,
    4285                 :            :                         int entity_handles_size,
    4286                 :            :                         /*inout*/ iBase_EntitySetHandle entity_set,
    4287                 :            :                         int* err )
    4288                 :            : {
    4289         [ -  + ]:          1 :   if (NULL == entity_set) RETURN(iBase_INVALID_ARGUMENT);
    4290                 :            : 
    4291                 :          1 :   RefGroup *this_set = SET_HANDLE(entity_set);
    4292                 :          1 :   RefEntity **ent_array = (RefEntity**)(entity_handles);
    4293                 :          1 :   CubitStatus status = CUBIT_SUCCESS, tmp_status;
    4294         [ +  + ]:         64 :   for (int i = 0; i < entity_handles_size; i++) {
    4295                 :         63 :     tmp_status = this_set->remove_ref_entity(ent_array[i]);
    4296         [ -  + ]:         63 :     if (CUBIT_SUCCESS != tmp_status) status = tmp_status;
    4297                 :            :   }
    4298                 :            : 
    4299         [ -  + ]:          1 :   if (CUBIT_SUCCESS != status) {
    4300                 :          0 :     ERROR(iBase_FAILURE, "Problem removing entities from a set.");
    4301                 :            :   }
    4302                 :            :   
    4303                 :          1 :   RETURN(iBase_SUCCESS);
    4304                 :            : }
    4305                 :            : 
    4306                 :            : /**
    4307                 :            :  * Return the relative and absolute tolerances at the modeler level.  If
    4308                 :            :  * model does not have a modeler-wide tolerance, zero is returned for both
    4309                 :            :  * values.
    4310                 :            :  * @param relative_tolerance Relative tolerance for model as a whole
    4311                 :            :  * @param absolute_tolerance Absolute tolerance for model as a whole
    4312                 :            :  */
    4313                 :            : ITAPS_API void
    4314                 :          0 : iGeom_getTolerance( iGeom_Instance instance,
    4315                 :            :                     /*out*/ int* type,
    4316                 :            :                     /*out*/ double* tolerance,
    4317                 :            :                     int* err )
    4318                 :            : {
    4319                 :          0 :   *type = 1;
    4320                 :          0 :   *tolerance = gqt->get_sme_resabs_tolerance();
    4321                 :          0 :   RETURN(iBase_SUCCESS);
    4322                 :            : }
    4323                 :            : 
    4324                 :            : ITAPS_API void
    4325                 :          0 : iGeom_getEntTolerance( iGeom_Instance instance,
    4326                 :            :                        /*in*/ iBase_EntityHandle entity_handle,
    4327                 :            :                        double* tolerance,
    4328                 :            :                        int* err )
    4329                 :            : {
    4330                 :          0 :   *tolerance = gqt->get_sme_resabs_tolerance();
    4331                 :          0 :   RETURN(iBase_SUCCESS);
    4332                 :            : }
    4333                 :            : 
    4334                 :            : /**
    4335                 :            :  * Return the relative and absolute tolerances for specified gentities.  If
    4336                 :            :  * a gentity does not have a specific tolerance, zero is returned for both
    4337                 :            :  * values.
    4338                 :            :  * @param gentity_handles Gentities being queried
    4339                 :            :  * @param relative_tolerances Relative tolerances
    4340                 :            :  * @param absolute_tolerances Absolute tolerances
    4341                 :            :  */
    4342                 :            : ITAPS_API void
    4343                 :          0 : iGeom_getArrTolerance( iGeom_Instance instance,
    4344                 :            :                        /*in*/ iBase_EntityHandle const *gentity_handles,
    4345                 :            :                        const int gentity_handles_size,
    4346                 :            :                        /*out*/ double **tolerances,
    4347                 :            :                        int *tolerances_allocated,
    4348                 :            :                        int *tolerances_size,
    4349                 :            :                        int* err )
    4350                 :            : {
    4351 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL(tolerances, gentity_handles_size);
                 [ #  # ]
    4352 [ #  # ][ #  # ]:          0 :   double dum_abs_tol = gqt->get_sme_resabs_tolerance();
    4353         [ #  # ]:          0 :   for (int i = 0; i < gentity_handles_size; i++) {
    4354                 :          0 :     (*tolerances)[i] = dum_abs_tol;
    4355                 :            :   }
    4356 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4357                 :            : }
    4358                 :            : 
    4359                 :            : ITAPS_API void
    4360                 :          0 : iGeom_getParametric( iGeom_Instance instance,
    4361                 :            :                      int* is_parametric,
    4362                 :            :                      int* err )
    4363                 :            : {
    4364                 :          0 :   *is_parametric = true;
    4365                 :          0 :   RETURN(iBase_SUCCESS);
    4366                 :            : }
    4367                 :            : 
    4368                 :            : /**
    4369                 :            :  * Return whether a given gentity is parametric or not.  If a gentity
    4370                 :            :  * is not parametric, all of the following functions will return an error
    4371                 :            :  * when called on that entity.
    4372                 :            :  * @param gentity_handle Entity being queried.
    4373                 :            :  */
    4374                 :            : ITAPS_API void
    4375                 :          0 : iGeom_isEntParametric( iGeom_Instance instance,
    4376                 :            :                        /*in*/ iBase_EntityHandle gentity_handle,
    4377                 :            :                        int* is_parametric,
    4378                 :            :                        int* err )
    4379                 :            : {
    4380                 :          0 :   *is_parametric = iGeom_is_parametric( (RefEntity*)gentity_handle );
    4381                 :          0 :   RETURN (iBase_SUCCESS);
    4382                 :            : }
    4383                 :            : 
    4384                 :            : ITAPS_API void
    4385                 :          0 : iGeom_isArrParametric( iGeom_Instance instance,
    4386                 :            :                        iBase_EntityHandle const *entity_handles,
    4387                 :            :                        int entity_handles_size,
    4388                 :            :                        int **is_parametric,
    4389                 :            :                        int *is_parametric_allocated,
    4390                 :            :                        int *is_parametric_size,
    4391                 :            :                        int* err )
    4392                 :            : {
    4393 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( is_parametric, entity_handles_size );
                 [ #  # ]
    4394                 :          0 :   RefEntity** const ent_array = (RefEntity**)entity_handles;
    4395         [ #  # ]:          0 :   for (int i = 0; i < entity_handles_size; ++i)
    4396         [ #  # ]:          0 :     (*is_parametric)[i] = iGeom_is_parametric( ent_array[i] );
    4397 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4398                 :            : }
    4399                 :            : 
    4400                 :            : ITAPS_API void
    4401                 :          0 : iGeom_getEntUVtoXYZ( iGeom_Instance instance,
    4402                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    4403                 :            :                      /*in*/ double u,
    4404                 :            :                      /*in*/ double v,
    4405                 :            :                      /*out*/ double* x,
    4406                 :            :                      /*out*/ double* y,
    4407                 :            :                      /*out*/ double* z,
    4408                 :            :                      int* err )
    4409                 :            : {
    4410                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4411         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    4412         [ #  # ]:          0 :   if (!face) {
    4413         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4414                 :            :   }
    4415                 :            :   
    4416         [ #  # ]:          0 :   CubitVector xyz = face->position_from_u_v( u, v );
    4417         [ #  # ]:          0 :   xyz.get_xyz( *x, *y, *z );
    4418         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4419                 :            : }
    4420                 :            : 
    4421                 :            : /**
    4422                 :            :  * Given sets of parametric coordinates, return the corresponding real
    4423                 :            :  * space coordinates on the gentities.  Input and output coordinates are
    4424                 :            :  * interleaved.
    4425                 :            :  * @param gentity_handles Gentities being queried.
    4426                 :            :  * @param uv Input parametric coordinates
    4427                 :            :  * @param xyz Output real space coordinates
    4428                 :            :  */
    4429                 :            : ITAPS_API void
    4430                 :          0 : iGeom_getArrUVtoXYZ( iGeom_Instance instance,
    4431                 :            :                      /*in*/ iBase_EntityHandle const *gentity_handles,
    4432                 :            :                      int gentity_handles_size,
    4433                 :            :                      /*in*/ int storage_order,
    4434                 :            :                      /*in*/ const double *uv,
    4435                 :            :                      int uv_size,
    4436                 :            :                      /*out*/ double **coordinates,
    4437                 :            :                      int *coordinates_allocated,
    4438                 :            :                      int *coordinates_size,
    4439                 :            :                      int* err )
    4440                 :            : {
    4441                 :            :   size_t ent_step, coord_step, uv_step;
    4442                 :            :   int count;
    4443         [ #  # ]:          0 :   if (2*gentity_handles_size == uv_size) {
    4444                 :          0 :     ent_step = uv_step = 1;
    4445                 :          0 :     count = gentity_handles_size;
    4446                 :            :   }
    4447         [ #  # ]:          0 :   else if (uv_size == 2) {
    4448                 :          0 :     ent_step = 1;
    4449                 :          0 :     uv_step = 0;
    4450                 :          0 :     count = gentity_handles_size;
    4451                 :            :   }
    4452         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    4453                 :          0 :     ent_step = 0;
    4454                 :          0 :     uv_step = 1;
    4455                 :          0 :     count = uv_size/2;
    4456                 :            :   }
    4457                 :            :   else {
    4458         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    4459                 :            :   }
    4460                 :            : 
    4461 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( coordinates, 3*count );
    4462                 :            :     
    4463                 :            :   const double *u, *v;
    4464                 :            :   double *x, *y, *z;
    4465                 :          0 :   u = uv;
    4466                 :          0 :   x = *coordinates;
    4467         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    4468         [ #  # ]:          0 :     v = u + (uv_step ? count : 1);
    4469                 :          0 :     y = x + count;
    4470                 :          0 :     z = y + count;
    4471                 :          0 :     coord_step = 1;
    4472                 :            :   } 
    4473                 :            :   else {
    4474                 :          0 :     storage_order = iBase_INTERLEAVED;
    4475                 :          0 :     v = u + 1;
    4476                 :          0 :     y = x + 1;
    4477                 :          0 :     z = x + 2;
    4478                 :          0 :     coord_step = 3;
    4479                 :          0 :     uv_step *= 2;
    4480                 :            :   }
    4481                 :            :   
    4482                 :          0 :   RefEntity** ent = (RefEntity**)gentity_handles;
    4483         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    4484         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*ent);
    4485         [ #  # ]:          0 :     if (!face) {
    4486         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4487                 :            :     }
    4488                 :            :     
    4489         [ #  # ]:          0 :     CubitVector xyz = face->position_from_u_v( *u, *v );
    4490         [ #  # ]:          0 :     xyz.get_xyz( *x, *y, *z );
    4491                 :            :     
    4492                 :          0 :     ent += ent_step;
    4493                 :          0 :     u += uv_step;
    4494                 :          0 :     v += uv_step;
    4495                 :          0 :     x += coord_step;
    4496                 :          0 :     y += coord_step;
    4497                 :          0 :     z += coord_step;
    4498                 :            :   }
    4499                 :            :   
    4500         [ #  # ]:          0 :   KEEP_ARRAY(coordinates);
    4501 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4502                 :            : }
    4503                 :            : 
    4504                 :            : ITAPS_API void
    4505                 :          0 : iGeom_getEntUtoXYZ( iGeom_Instance instance,
    4506                 :            :                     /*in*/ iBase_EntityHandle entity_handle,
    4507                 :            :                     /*in*/ double u,
    4508                 :            :                     /*out*/ double* x,
    4509                 :            :                     /*out*/ double* y,
    4510                 :            :                     /*out*/ double* z,
    4511                 :            :                     int* err )
    4512                 :            : {
    4513                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4514         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>(entity);
    4515         [ #  # ]:          0 :   if (!edge) {
    4516         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected edge for 1-param method.");
    4517                 :            :   }
    4518                 :            :   
    4519         [ #  # ]:          0 :   CubitVector xyz;
    4520         [ #  # ]:          0 :   CubitStatus s = edge->position_from_u( u, xyz );
    4521         [ #  # ]:          0 :   xyz.get_xyz( *x, *y, *z );
    4522 [ #  # ][ #  # ]:          0 :   RETURN( (s == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    4523                 :            : }
    4524                 :            : 
    4525                 :            : ITAPS_API void
    4526                 :          0 : iGeom_getArrUtoXYZ( iGeom_Instance instance,
    4527                 :            :                     /*in*/ iBase_EntityHandle const *gentity_handles,
    4528                 :            :                     int gentity_handles_size,
    4529                 :            :                     /*in*/ const double *u,
    4530                 :            :                     int u_size,
    4531                 :            :                     /*in*/ int storage_order,
    4532                 :            :                     /*out*/ double **coordinates,
    4533                 :            :                     int *coordinates_allocated,
    4534                 :            :                     int *coordinates_size,
    4535                 :            :                     int* err )
    4536                 :            : {
    4537                 :            :   int count;
    4538                 :            :   size_t ent_step, coord_step, u_step;
    4539         [ #  # ]:          0 :   if (gentity_handles_size == u_size) {
    4540                 :          0 :     ent_step = u_step = 1;
    4541                 :          0 :     count = gentity_handles_size;
    4542                 :            :   }
    4543         [ #  # ]:          0 :   else if (u_size == 1) {
    4544                 :          0 :     ent_step = 1;
    4545                 :          0 :     u_step = 0;
    4546                 :          0 :     count = gentity_handles_size;
    4547                 :            :   }
    4548         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    4549                 :          0 :     ent_step = 0;
    4550                 :          0 :     u_step = 1;
    4551                 :          0 :     count = u_size;
    4552                 :            :   }
    4553                 :            :   else {
    4554         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    4555                 :            :   }
    4556                 :            :     
    4557 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( coordinates, 3*count );
    4558                 :            :   
    4559                 :            :   const double *u_iter;
    4560                 :            :   double *x, *y, *z;
    4561                 :          0 :   u_iter = u;
    4562                 :          0 :   x = *coordinates;
    4563         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    4564                 :          0 :     y = x + count;
    4565                 :          0 :     z = y + count;
    4566                 :          0 :     coord_step = 1;
    4567                 :            :   } 
    4568                 :            :   else {
    4569                 :          0 :     y = x + 1;
    4570                 :          0 :     z = x + 2;
    4571                 :          0 :     coord_step = 3;
    4572                 :            :   }
    4573                 :            :   
    4574                 :          0 :   iBase_ErrorType result = iBase_SUCCESS;
    4575                 :          0 :   RefEntity** ent = (RefEntity**)gentity_handles;
    4576         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    4577         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*ent);
    4578         [ #  # ]:          0 :     if (!edge) {
    4579         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected edge for 1-param method.");
    4580                 :            :     }
    4581                 :            :     
    4582         [ #  # ]:          0 :     CubitVector xyz;
    4583         [ #  # ]:          0 :     CubitStatus s = edge->position_from_u( *u_iter, xyz );
    4584         [ #  # ]:          0 :     if (CUBIT_SUCCESS != s)
    4585                 :          0 :       result = iBase_FAILURE;
    4586         [ #  # ]:          0 :     xyz.get_xyz( *x, *y, *z );
    4587                 :            :     
    4588                 :          0 :     ent += ent_step;
    4589                 :          0 :     u_iter += u_step;
    4590                 :          0 :     x += coord_step;
    4591                 :          0 :     y += coord_step;
    4592                 :          0 :     z += coord_step;
    4593                 :            :   }
    4594                 :            :   
    4595         [ #  # ]:          0 :   KEEP_ARRAY(coordinates);
    4596 [ #  # ][ #  # ]:          0 :   RETURN(result);
    4597                 :            : }
    4598                 :            : 
    4599                 :            : ITAPS_API void
    4600                 :          0 : iGeom_getEntXYZtoUV( iGeom_Instance instance,
    4601                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    4602                 :            :                      /*in*/ double x,
    4603                 :            :                      /*in*/ double y,
    4604                 :            :                      /*in*/ double z,
    4605                 :            :                      /*out*/ double* u,
    4606                 :            :                      /*out*/ double* v,
    4607                 :            :                      int* err )
    4608                 :            : {
    4609                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4610         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    4611         [ #  # ]:          0 :   if (!face) {
    4612         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4613                 :            :   }
    4614                 :            :   
    4615         [ #  # ]:          0 :   const CubitVector xyz( x, y, z );
    4616         [ #  # ]:          0 :   CubitStatus s = face->u_v_from_position( xyz, *u, *v );
    4617 [ #  # ][ #  # ]:          0 :   RETURN( (s == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    4618                 :            : }
    4619                 :            : 
    4620                 :            : 
    4621                 :            : /**
    4622                 :            :  * Given sets of real space coordinates, return the corresponding 
    4623                 :            :  * parametric coordinates on the gentities.  Input and output coordinates 
    4624                 :            :  * are interleaved.
    4625                 :            :  * @param gentity_handles Gentities being queried.
    4626                 :            :  * @param xyz Input real space coordinates
    4627                 :            :  * @param uv Output parametric coordinates
    4628                 :            :  */
    4629                 :            : ITAPS_API void
    4630                 :          0 : iGeom_getArrXYZtoUV( iGeom_Instance instance,
    4631                 :            :                      /*in*/ iBase_EntityHandle const *gentity_handles,
    4632                 :            :                      int gentity_handles_size,
    4633                 :            :                      /*in*/ int storage_order,
    4634                 :            :                      /*in*/ const double *coordinates,
    4635                 :            :                      int coordinates_size,
    4636                 :            :                      /*out*/ double **uv,
    4637                 :            :                      int *uv_allocated,
    4638                 :            :                      int *uv_size,
    4639                 :            :                      int* err )
    4640                 :            : {
    4641                 :            :   int count;
    4642                 :            :   size_t ent_step, coord_step, uv_step;
    4643         [ #  # ]:          0 :   if (3*gentity_handles_size == coordinates_size) {
    4644                 :          0 :     ent_step = coord_step = 1;
    4645                 :          0 :     count = gentity_handles_size;
    4646                 :            :   }
    4647         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    4648                 :          0 :     ent_step = 1;
    4649                 :          0 :     coord_step = 0;
    4650                 :          0 :     count = gentity_handles_size;
    4651                 :            :   }
    4652         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    4653                 :          0 :     ent_step = 0;
    4654                 :          0 :     coord_step = 1;
    4655                 :          0 :     count = coordinates_size/3;
    4656                 :            :   }
    4657                 :            :   else {
    4658         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    4659                 :            :   }
    4660                 :            : 
    4661 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( uv, 2*count );
    4662                 :            : 
    4663                 :            :   double *u, *v;
    4664                 :            :   const double *x, *y, *z;
    4665                 :          0 :   u = *uv;
    4666                 :          0 :   x = coordinates;
    4667         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    4668                 :          0 :     v = u + count;
    4669         [ #  # ]:          0 :     y = x + (coord_step ? count : 1);
    4670         [ #  # ]:          0 :     z = y + (coord_step ? count : 1);
    4671                 :          0 :     uv_step = 1;
    4672                 :            :   } 
    4673                 :            :   else {
    4674                 :          0 :     storage_order = iBase_INTERLEAVED;
    4675                 :          0 :     v = u + 1;
    4676                 :          0 :     y = x + 1;
    4677                 :          0 :     z = x + 2;
    4678                 :          0 :     coord_step *= 3;
    4679                 :          0 :     uv_step = 2;
    4680                 :            :   }
    4681                 :            :   
    4682                 :          0 :   RefEntity** ent = (RefEntity**)gentity_handles;
    4683         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    4684         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*ent);
    4685         [ #  # ]:          0 :     if (!face) {
    4686         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4687                 :            :     }
    4688                 :            :     
    4689         [ #  # ]:          0 :     CubitVector xyz( *x, *y, *z );
    4690         [ #  # ]:          0 :     CubitStatus s = face->u_v_from_position( xyz, *u, *v );
    4691         [ #  # ]:          0 :     if (CUBIT_SUCCESS != s)
    4692         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    4693                 :            :     
    4694                 :          0 :     ent += ent_step;
    4695                 :          0 :     u += uv_step;
    4696                 :          0 :     v += uv_step;
    4697                 :          0 :     x += coord_step;
    4698                 :          0 :     y += coord_step;
    4699                 :          0 :     z += coord_step;
    4700                 :            :   }
    4701                 :            :   
    4702         [ #  # ]:          0 :   KEEP_ARRAY(uv);
    4703 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4704                 :            : }
    4705                 :            : 
    4706                 :            : 
    4707                 :            : ITAPS_API void
    4708                 :          0 : iGeom_getEntXYZtoU( iGeom_Instance instance,
    4709                 :            :                     /*in*/ iBase_EntityHandle entity_handle,
    4710                 :            :                     /*in*/ double x,
    4711                 :            :                     /*in*/ double y,
    4712                 :            :                     /*in*/ double z,
    4713                 :            :                     /*out*/ double* u,
    4714                 :            :                     int* err )
    4715                 :            : {
    4716                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4717         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>(entity);
    4718         [ #  # ]:          0 :   if (!edge) {
    4719         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected edge for 1-param method.");
    4720                 :            :   }
    4721                 :            :   
    4722         [ #  # ]:          0 :   const CubitVector xyz( x, y, z );
    4723         [ #  # ]:          0 :   *u = edge->u_from_position( xyz );
    4724         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4725                 :            : }
    4726                 :            : 
    4727                 :            : 
    4728                 :            : ITAPS_API void
    4729                 :          0 : iGeom_getArrXYZtoU( iGeom_Instance instance,
    4730                 :            :                     /*in*/ iBase_EntityHandle const *gentity_handles,
    4731                 :            :                     int gentity_handles_size,
    4732                 :            :                     /*in*/ int storage_order,
    4733                 :            :                     /*in*/ const double *coordinates,
    4734                 :            :                     int coordinates_size,
    4735                 :            :                     /*out*/ double **u,
    4736                 :            :                     int *u_allocated,
    4737                 :            :                     int *u_size,
    4738                 :            :                     int* err )
    4739                 :            : {
    4740                 :            :   int count;
    4741                 :            :   size_t ent_step, coord_step;
    4742         [ #  # ]:          0 :   if (3*gentity_handles_size == coordinates_size) {
    4743                 :          0 :     ent_step = coord_step = 1;
    4744                 :          0 :     count = gentity_handles_size;
    4745                 :            :   }
    4746         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    4747                 :          0 :     ent_step = 1;
    4748                 :          0 :     coord_step = 0;
    4749                 :          0 :     count = gentity_handles_size;
    4750                 :            :   }
    4751         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    4752                 :          0 :     ent_step = 0;
    4753                 :          0 :     coord_step = 1;
    4754                 :          0 :     count = coordinates_size/3;
    4755                 :            :   }
    4756                 :            :   else {
    4757         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    4758                 :            :   }
    4759                 :            :     
    4760                 :            :   const double *x, *y, *z;
    4761                 :          0 :   x = coordinates;
    4762         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    4763         [ #  # ]:          0 :     y = x + (coord_step ? count : 1);
    4764         [ #  # ]:          0 :     z = y + (coord_step ? count : 1);
    4765                 :            :   } 
    4766                 :            :   else {
    4767                 :          0 :     storage_order = iBase_INTERLEAVED;
    4768                 :          0 :     y = x + 1;
    4769                 :          0 :     z = x + 2;
    4770                 :          0 :     coord_step *= 3;
    4771                 :            :   }
    4772                 :            :   
    4773 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( u, count );
    4774                 :            :   
    4775                 :          0 :   RefEntity** ent = (RefEntity**)gentity_handles;
    4776         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    4777         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*ent);
    4778         [ #  # ]:          0 :     if (!edge) {
    4779         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected edge for 1-param method.");
    4780                 :            :     }
    4781                 :            :     
    4782         [ #  # ]:          0 :     CubitVector xyz( *x, *y, *z );
    4783         [ #  # ]:          0 :     (*u)[i] = edge->u_from_position( xyz );
    4784                 :            :     
    4785                 :          0 :     ent += ent_step;
    4786                 :          0 :     x += coord_step;
    4787                 :          0 :     y += coord_step;
    4788                 :          0 :     z += coord_step;
    4789                 :            :   }
    4790                 :            :   
    4791         [ #  # ]:          0 :   KEEP_ARRAY(u);
    4792 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4793                 :            : }
    4794                 :            : 
    4795                 :            : ITAPS_API void
    4796                 :          0 : iGeom_getEntXYZtoUVHint( iGeom_Instance instance,
    4797                 :            :                          /*in*/ iBase_EntityHandle entity_handle,
    4798                 :            :                          /*in*/ double x,
    4799                 :            :                          /*in*/ double y,
    4800                 :            :                          /*in*/ double z,
    4801                 :            :                          /*inout*/ double* u,
    4802                 :            :                          /*inout*/ double* v,
    4803                 :            :                          int* err )
    4804                 :            : {
    4805                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4806         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    4807         [ #  # ]:          0 :   if (!face) {
    4808         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4809                 :            :   }
    4810                 :            :   
    4811         [ #  # ]:          0 :   CubitVector xyz( x, y, z );
    4812         [ #  # ]:          0 :   face->move_to_surface( xyz, u, v );
    4813         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4814                 :            : }
    4815                 :            : 
    4816                 :            : 
    4817                 :            : /**
    4818                 :            :  * Given sets of real space coordinates, return the corresponding 
    4819                 :            :  * parametric coordinates on the gentities.  Input and output coordinates 
    4820                 :            :  * are interleaved.
    4821                 :            :  * @param gentity_handles Gentities being queried.
    4822                 :            :  * @param xyz Input real space coordinates
    4823                 :            :  * @param uv Output parametric coordinates
    4824                 :            :  */
    4825                 :            : ITAPS_API void
    4826                 :          0 : iGeom_getArrXYZtoUVHint( iGeom_Instance instance,
    4827                 :            :                          /*in*/ iBase_EntityHandle const *gentity_handles,
    4828                 :            :                          int gentity_handles_size,
    4829                 :            :                          /*in*/ int storage_order,
    4830                 :            :                          /*in*/ const double *coordinates,
    4831                 :            :                          int coordinates_size,
    4832                 :            :                          /*inout*/ double **uv,
    4833                 :            :                          int *uv_allocated,
    4834                 :            :                          int *uv_size,
    4835                 :            :                          int* err )
    4836                 :            : {
    4837                 :            :   int count;
    4838                 :            :   size_t ent_step, coord_step, uv_step;
    4839         [ #  # ]:          0 :   if (3*gentity_handles_size == coordinates_size) {
    4840                 :          0 :     ent_step = coord_step = 1;
    4841                 :          0 :     count = gentity_handles_size;
    4842                 :            :   }
    4843         [ #  # ]:          0 :   else if (coordinates_size == 3) {
    4844                 :          0 :     ent_step = 1;
    4845                 :          0 :     coord_step = 0;
    4846                 :          0 :     count = gentity_handles_size;
    4847                 :            :   }
    4848         [ #  # ]:          0 :   else if (gentity_handles_size == 1) {
    4849                 :          0 :     ent_step = 0;
    4850                 :          0 :     coord_step = 1;
    4851                 :          0 :     count = coordinates_size/3;
    4852                 :            :   }
    4853                 :            :   else {
    4854         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    4855                 :            :   }
    4856                 :            :     
    4857                 :            :   double *u, *v;
    4858                 :            :   const double *x, *y, *z;
    4859                 :          0 :   u = *uv;
    4860                 :          0 :   x = coordinates;
    4861         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    4862                 :          0 :     v = u + count;
    4863         [ #  # ]:          0 :     y = x + (coord_step ? count : 1);
    4864         [ #  # ]:          0 :     z = y + (coord_step ? count : 1);
    4865                 :          0 :     uv_step = 1;
    4866                 :            :   } 
    4867                 :            :   else {
    4868                 :          0 :     storage_order = iBase_INTERLEAVED;
    4869                 :          0 :     v = u + 1;
    4870                 :          0 :     y = x + 1;
    4871                 :          0 :     z = x + 2;
    4872                 :          0 :     coord_step *= 3;
    4873                 :          0 :     uv_step = 2;
    4874                 :            :   }
    4875                 :            :   
    4876 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( uv, 2*count );
    4877                 :            :   
    4878                 :          0 :   RefEntity** ent = (RefEntity**)gentity_handles;
    4879         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    4880         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*ent);
    4881         [ #  # ]:          0 :     if (!face) {
    4882         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4883                 :            :     }
    4884                 :            :     
    4885         [ #  # ]:          0 :     CubitVector xyz( *x, *y, *z );
    4886         [ #  # ]:          0 :     face->move_to_surface( xyz, u, v );
    4887                 :            :     
    4888                 :          0 :     ent += ent_step;
    4889                 :          0 :     u += uv_step;
    4890                 :          0 :     v += uv_step;
    4891                 :          0 :     x += coord_step;
    4892                 :          0 :     y += coord_step;
    4893                 :          0 :     z += coord_step;
    4894                 :            :   }
    4895                 :            :   
    4896         [ #  # ]:          0 :   KEEP_ARRAY(uv);
    4897 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4898                 :            : }
    4899                 :            : 
    4900                 :            : ITAPS_API void
    4901                 :          0 : iGeom_getEntUVRange( iGeom_Instance instance,
    4902                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    4903                 :            :                      /*out*/ double *u_min,
    4904                 :            :                      /*out*/ double *v_min,
    4905                 :            :                      /*out*/ double *u_max,
    4906                 :            :                      /*out*/ double *v_max,
    4907                 :            :                      int* err )
    4908                 :            : {
    4909                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4910         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>(entity);
    4911         [ #  # ]:          0 :   if (!face) {
    4912                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4913                 :            :   }
    4914                 :            :   
    4915                 :          0 :   CubitBoolean r1 = face->get_param_range_U(*u_min, *u_max);
    4916                 :          0 :   CubitBoolean r2 = face->get_param_range_V(*v_min, *v_max);
    4917 [ #  # ][ #  # ]:          0 :   RETURN( ((r1 && r2) ? iBase_SUCCESS : iBase_FAILURE) );
    4918                 :            : }
    4919                 :            : 
    4920                 :            : ITAPS_API void
    4921                 :          0 : iGeom_getEntURange( iGeom_Instance instance,
    4922                 :            :                     /*in*/ iBase_EntityHandle entity_handle,
    4923                 :            :                     /*out*/ double *u_min,
    4924                 :            :                     /*out*/ double *u_max,
    4925                 :            :                     int* err )
    4926                 :            : {
    4927                 :          0 :   RefEntity* entity = (RefEntity*)entity_handle;
    4928         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>(entity);
    4929         [ #  # ]:          0 :   if (!edge) {
    4930                 :          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Expected edge for 1-param method.");
    4931                 :            :   }
    4932                 :            :   
    4933                 :          0 :   CubitBoolean r1 = edge->get_param_range(*u_min, *u_max);
    4934         [ #  # ]:          0 :   RETURN( (r1 ? iBase_SUCCESS : iBase_FAILURE) );
    4935                 :            : }
    4936                 :            :     
    4937                 :            : 
    4938                 :            : /**
    4939                 :            :  * Return the uv range of the specified gentities.  Parameters are interleaved.
    4940                 :            :  * @param gentity_handles Gentities being queried.
    4941                 :            :  * @param uv_min Minimum parameters of gentities, interleaved
    4942                 :            :  * @param uv_max Maximum parameters of gentities, interleaved
    4943                 :            :  */
    4944                 :            : ITAPS_API void
    4945                 :          0 : iGeom_getArrUVRange( iGeom_Instance instance,
    4946                 :            :                      /*in*/ iBase_EntityHandle const *gentity_handles,
    4947                 :            :                      int gentity_handles_size,
    4948                 :            :                      /*in*/ int storage_order,
    4949                 :            :                      /*out*/ double **uv_min,
    4950                 :            :                      int *uv_min_allocated,
    4951                 :            :                      int *uv_min_size,
    4952                 :            :                      /*out*/ double **uv_max,
    4953                 :            :                      int *uv_max_allocated,
    4954                 :            :                      int *uv_max_size,
    4955                 :            :                      int* err )
    4956                 :            : {
    4957 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(uv_min, 2*gentity_handles_size);
    4958 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(uv_max, 2*gentity_handles_size);
                 [ #  # ]
    4959                 :            :   
    4960                 :            :   size_t init, step;
    4961         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    4962                 :          0 :     init = gentity_handles_size;
    4963                 :          0 :     step = 1;
    4964                 :            :   }
    4965                 :            :   else {
    4966                 :          0 :     init = 1;
    4967                 :          0 :     step = 2;
    4968                 :            :   }
    4969                 :            :   
    4970                 :          0 :   double *u_min = *uv_min;
    4971                 :          0 :   double *v_min = u_min + init;
    4972                 :          0 :   double *u_max = *uv_max;
    4973                 :          0 :   double *v_max = u_max + init;
    4974                 :            :   
    4975                 :          0 :   RefEntity** entities = (RefEntity**)gentity_handles;
    4976         [ #  # ]:          0 :   for (int i = 0; i < gentity_handles_size; ++i) {
    4977         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(entities[i]);
    4978         [ #  # ]:          0 :     if (!face) {
    4979         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected face for UV method.");
    4980                 :            :     }
    4981                 :            :     
    4982         [ #  # ]:          0 :     CubitBoolean r1 = face->get_param_range_U(*u_min, *u_max);
    4983         [ #  # ]:          0 :     CubitBoolean r2 = face->get_param_range_V(*v_min, *v_max);
    4984 [ #  # ][ #  # ]:          0 :     if (!(r1 && r2)) {
    4985         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    4986                 :            :     }
    4987                 :            :     
    4988                 :          0 :     u_min += step;
    4989                 :          0 :     v_min += step;
    4990                 :          0 :     u_max += step;
    4991                 :          0 :     v_max += step;
    4992                 :            :   }
    4993                 :            :   
    4994         [ #  # ]:          0 :   KEEP_ARRAY(uv_min);
    4995         [ #  # ]:          0 :   KEEP_ARRAY(uv_max);
    4996 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    4997                 :            : }
    4998                 :            : 
    4999                 :            : ITAPS_API void
    5000                 :          0 : iGeom_getArrURange( iGeom_Instance instance,
    5001                 :            :                     /*in*/ iBase_EntityHandle const *gentity_handles,
    5002                 :            :                     const int gentity_handles_size,
    5003                 :            :                     /*out*/ double **u_min,
    5004                 :            :                     int *u_min_allocated,
    5005                 :            :                     int *u_min_size,
    5006                 :            :                     /*out*/ double **u_max,
    5007                 :            :                     int *u_max_allocated,
    5008                 :            :                     int *u_max_size,
    5009                 :            :                     int* err )
    5010                 :            : {
    5011 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(u_min, gentity_handles_size);
    5012 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY(u_max, gentity_handles_size);
                 [ #  # ]
    5013                 :            :   
    5014                 :          0 :   RefEntity** entities = (RefEntity**)gentity_handles;
    5015         [ #  # ]:          0 :   for (int i = 0; i < gentity_handles_size; ++i) {
    5016         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(entities[i]);
    5017         [ #  # ]:          0 :     if (!edge) {
    5018         [ #  # ]:          0 :       ERROR(iBase_INVALID_ENTITY_TYPE, "Expected edge for 1-param method.");
    5019                 :            :     }
    5020                 :            :     
    5021         [ #  # ]:          0 :     CubitBoolean r1 = edge->get_param_range((*u_min)[i], (*u_max)[i]);
    5022         [ #  # ]:          0 :     if (!r1) {
    5023         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    5024                 :            :     }
    5025                 :            :   }
    5026                 :            :   
    5027         [ #  # ]:          0 :   KEEP_ARRAY(u_min);
    5028         [ #  # ]:          0 :   KEEP_ARRAY(u_max);
    5029 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5030                 :            : }
    5031                 :            : 
    5032                 :            : ITAPS_API void
    5033                 :          0 : iGeom_getEntUtoUV( iGeom_Instance instance,
    5034                 :            :                    /*in*/ iBase_EntityHandle edge_handle,
    5035                 :            :                    /*in*/ iBase_EntityHandle face_handle,
    5036                 :            :                    /*in*/ double in_u,
    5037                 :            :                    /*out*/ double* u,
    5038                 :            :                    /*out*/ double* v,
    5039                 :            :                    int* err )
    5040                 :            : {
    5041         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>((RefEntity*)edge_handle);
    5042         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>((RefEntity*)face_handle);
    5043 [ #  # ][ #  # ]:          0 :   if (!edge || !face) {
    5044         [ #  # ]:          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    5045                 :            :   }
    5046                 :            :   
    5047         [ #  # ]:          0 :   CubitVector xyz;
    5048                 :            :   CubitStatus s;
    5049         [ #  # ]:          0 :   s = edge->position_from_u( in_u, xyz );
    5050         [ #  # ]:          0 :   if (s != CUBIT_SUCCESS)
    5051         [ #  # ]:          0 :     RETURN(iBase_FAILURE);
    5052                 :            : 
    5053         [ #  # ]:          0 :   s = face->u_v_from_position( xyz, *u, *v );
    5054 [ #  # ][ #  # ]:          0 :   RETURN( (s == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    5055                 :            : }
    5056                 :            : 
    5057                 :            : static bool
    5058                 :          0 : iGeom_check_array_size(int size1, int size2)
    5059                 :            : {
    5060 [ #  # ][ #  # ]:          0 :     return size1 == 1 || size2 == 1 || size1 == size2;        
                 [ #  # ]
    5061                 :            : }
    5062                 :            : 
    5063                 :            : ITAPS_API void
    5064                 :          0 : iGeom_getArrUtoUV( iGeom_Instance instance,
    5065                 :            :                    /*in*/ iBase_EntityHandle const *edge_handles,
    5066                 :            :                    int edge_handles_size,
    5067                 :            :                    /*in*/ iBase_EntityHandle const *face_handles,
    5068                 :            :                    int face_handles_size,
    5069                 :            :                    /*in*/ const double *in_u,
    5070                 :            :                    int in_u_size,
    5071                 :            :                    /*in*/ int storage_order,
    5072                 :            :                    /*inout*/ double **uv,
    5073                 :            :                    int *uv_allocated,
    5074                 :            :                    int *uv_size,
    5075                 :            :                    int* err )
    5076                 :            : {
    5077                 :            :   int count;
    5078                 :            :   size_t edge_step, face_step, coord_step, in_u_step;
    5079                 :            : 
    5080 [ #  # ][ #  # ]:          0 :   if (!(iGeom_check_array_size(edge_handles_size, face_handles_size) &&
    5081                 :          0 :         iGeom_check_array_size(edge_handles_size, in_u_size) &&
    5082 [ #  # ][ #  # ]:          0 :         iGeom_check_array_size(face_handles_size, in_u_size))) {
    5083         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    5084                 :            :   }
    5085                 :            : 
    5086                 :          0 :   edge_step = (edge_handles_size == 1) ? 0:1;
    5087                 :          0 :   face_step = (face_handles_size == 1) ? 0:1;
    5088                 :          0 :   in_u_step = (in_u_size == 1) ? 0:1;
    5089                 :            : 
    5090 [ #  # ][ #  # ]:          0 :   count = std::max(edge_handles_size, std::max(face_handles_size, in_u_size));
    5091                 :            : 
    5092 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( uv, 2*count );
    5093                 :            :   
    5094                 :            :   const double *in_u_iter;
    5095                 :            :   double *u, *v;
    5096                 :          0 :   in_u_iter = in_u;
    5097                 :          0 :   u = *uv;
    5098         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    5099                 :          0 :     v = u + count;
    5100                 :          0 :     coord_step = 1;
    5101                 :            :   } 
    5102                 :            :   else {
    5103                 :          0 :     v = u + 1;
    5104                 :          0 :     coord_step = 2;
    5105                 :            :   }
    5106                 :            :   
    5107                 :          0 :   RefEntity** edge_ent = (RefEntity**)edge_handles;
    5108                 :          0 :   RefEntity** face_ent = (RefEntity**)face_handles;
    5109         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    5110         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*edge_ent);
    5111         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*face_ent);
    5112 [ #  # ][ #  # ]:          0 :     if (!edge || !face) {
    5113         [ #  # ]:          0 :       RETURN(iBase_INVALID_ENTITY_TYPE);
    5114                 :            :     }
    5115                 :            :     
    5116         [ #  # ]:          0 :     CubitVector xyz;
    5117                 :            :     CubitStatus s;
    5118         [ #  # ]:          0 :     s = edge->position_from_u( *in_u_iter, xyz );
    5119         [ #  # ]:          0 :     if (CUBIT_SUCCESS != s)
    5120         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    5121         [ #  # ]:          0 :     s = face->u_v_from_position( xyz, *u, *v );
    5122         [ #  # ]:          0 :     if (CUBIT_SUCCESS != s)
    5123         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    5124                 :            : 
    5125                 :          0 :     edge_ent += edge_step;
    5126                 :          0 :     face_ent += face_step;
    5127                 :          0 :     in_u_iter += in_u_step;
    5128                 :          0 :     u += coord_step;
    5129                 :          0 :     v += coord_step;
    5130                 :            :   }
    5131                 :            :   
    5132         [ #  # ]:          0 :   KEEP_ARRAY(uv);
    5133 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5134                 :            : }
    5135                 :            : 
    5136                 :            : ITAPS_API void
    5137                 :          0 : iGeom_getVtxToUV( iGeom_Instance instance,
    5138                 :            :                   /*in*/ iBase_EntityHandle vertex_handle,
    5139                 :            :                   /*in*/ iBase_EntityHandle face_handle,
    5140                 :            :                   /*out*/ double* u,
    5141                 :            :                   /*out*/ double* v,
    5142                 :            :                   int* err )
    5143                 :            : {
    5144         [ #  # ]:          0 :   RefVertex* vtx = dynamic_cast<RefVertex*>((RefEntity*)vertex_handle);
    5145         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>((RefEntity*)face_handle);
    5146 [ #  # ][ #  # ]:          0 :   if (!vtx || !face) {
    5147                 :          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    5148                 :            :   }
    5149                 :            : 
    5150                 :          0 :   iBase_ErrorType result = iGeom_get_vtx_to_uv( vtx, face, *u, *v );
    5151                 :          0 :   RETURN(result);
    5152                 :            : }  
    5153                 :            : 
    5154                 :            : ITAPS_API void
    5155                 :          0 : iGeom_getVtxArrToUV( iGeom_Instance instance,
    5156                 :            :                      /*in*/ iBase_EntityHandle const *vertex_handles,
    5157                 :            :                      int vertex_handles_size,
    5158                 :            :                      /*in*/ iBase_EntityHandle const *face_handles,
    5159                 :            :                      int face_handles_size,
    5160                 :            :                      /*in*/ int storage_order,
    5161                 :            :                      /*inout*/ double **uv,
    5162                 :            :                      int *uv_allocated,
    5163                 :            :                      int *uv_size,
    5164                 :            :                      int* err )
    5165                 :            : {
    5166                 :            :   int count;
    5167                 :            :   size_t vtx_step, face_step, uv_step;
    5168         [ #  # ]:          0 :   if (vertex_handles_size == face_handles_size) {
    5169                 :          0 :     count = vertex_handles_size;
    5170                 :          0 :     vtx_step = face_step = 1;
    5171                 :            :   }
    5172         [ #  # ]:          0 :   else if (face_handles_size == 1) {
    5173                 :          0 :     count = vertex_handles_size;
    5174                 :          0 :     vtx_step = 1;
    5175                 :          0 :     face_step = 0;
    5176                 :            :   }
    5177         [ #  # ]:          0 :   else if (vertex_handles_size == 1) {
    5178                 :          0 :     count = face_handles_size;
    5179                 :          0 :     vtx_step = 0;
    5180                 :          0 :     face_step = 1;
    5181                 :            :   }
    5182                 :            :   else {
    5183         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    5184                 :            :   }
    5185                 :            :   
    5186 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( uv, 2*count );
    5187                 :            : 
    5188                 :            :   double *u, *v;
    5189                 :          0 :   u = *uv;
    5190         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    5191                 :          0 :     v = u + count;
    5192                 :          0 :     uv_step = 1;
    5193                 :            :   } 
    5194                 :            :   else {
    5195                 :          0 :     storage_order = iBase_INTERLEAVED;
    5196                 :          0 :     v = u + 1;
    5197                 :          0 :     uv_step = 2;
    5198                 :            :   }
    5199                 :            :   
    5200                 :          0 :   RefEntity** vtx_iter = (RefEntity**)vertex_handles;
    5201                 :          0 :   RefEntity** face_iter = (RefEntity**)face_handles;
    5202         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    5203         [ #  # ]:          0 :     RefVertex* vtx = dynamic_cast<RefVertex*>(*vtx_iter);
    5204         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*face_iter);
    5205 [ #  # ][ #  # ]:          0 :     if (!vtx || !face) {
    5206         [ #  # ]:          0 :       RETURN(iBase_INVALID_ENTITY_TYPE);
    5207                 :            :     }
    5208                 :            :     
    5209         [ #  # ]:          0 :     iBase_ErrorType rval = iGeom_get_vtx_to_uv( vtx, face, *u, *v );
    5210         [ #  # ]:          0 :     if (iBase_SUCCESS != rval) {
    5211         [ #  # ]:          0 :       RETURN(rval);
    5212                 :            :     }
    5213                 :            : 
    5214                 :          0 :     vtx_iter += vtx_step;
    5215                 :          0 :     face_iter += face_step;
    5216                 :          0 :     u += uv_step;
    5217                 :          0 :     v += uv_step;
    5218                 :            :   }
    5219         [ #  # ]:          0 :   KEEP_ARRAY(uv);
    5220 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5221                 :            : }
    5222                 :            : 
    5223                 :            : ITAPS_API void
    5224                 :          0 : iGeom_getVtxToU( iGeom_Instance instance,
    5225                 :            :                  /*in*/ iBase_EntityHandle vertex_handle,
    5226                 :            :                  /*in*/ iBase_EntityHandle edge_handle,
    5227                 :            :                  /*out*/ double* u,
    5228                 :            :                  int* err )
    5229                 :            : {
    5230         [ #  # ]:          0 :   RefVertex* vtx = dynamic_cast<RefVertex*>((RefEntity*)vertex_handle);
    5231         [ #  # ]:          0 :   RefEdge* edge = dynamic_cast<RefEdge*>((RefEntity*)edge_handle);
    5232 [ #  # ][ #  # ]:          0 :   if (!vtx || !edge) {
    5233                 :          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    5234                 :            :   }
    5235                 :            :   
    5236                 :          0 :   iBase_ErrorType result = iGeom_get_vtx_to_u( vtx, edge, *u );
    5237                 :          0 :   RETURN(result);
    5238                 :            : }
    5239                 :            : 
    5240                 :            : ITAPS_API void
    5241                 :          0 : iGeom_getVtxArrToU( iGeom_Instance instance,
    5242                 :            :                     /*in*/ iBase_EntityHandle const *vertex_handles ,
    5243                 :            :                     int vertex_handles_size,
    5244                 :            :                     /*in*/ iBase_EntityHandle const *edge_handles ,
    5245                 :            :                     int edge_handles_size,
    5246                 :            :                     /*inout*/  double **u ,
    5247                 :            :                     int *u_allocated,
    5248                 :            :                     int *u_size,
    5249                 :            :                     int* err )
    5250                 :            : {
    5251                 :            :   int count;
    5252                 :            :   size_t vtx_step, edge_step;
    5253         [ #  # ]:          0 :   if (vertex_handles_size == edge_handles_size) {
    5254                 :          0 :     count = vertex_handles_size;
    5255                 :          0 :     vtx_step = edge_step = 1;
    5256                 :            :   }
    5257         [ #  # ]:          0 :   else if (edge_handles_size == 1) {
    5258                 :          0 :     count = vertex_handles_size;
    5259                 :          0 :     vtx_step = 1;
    5260                 :          0 :     edge_step = 0;
    5261                 :            :   }
    5262         [ #  # ]:          0 :   else if (vertex_handles_size == 1) {
    5263                 :          0 :     count = edge_handles_size;
    5264                 :          0 :     vtx_step = 0;
    5265                 :          0 :     edge_step = 1;
    5266                 :            :   }
    5267                 :            :   else {
    5268         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    5269                 :            :   }
    5270                 :            :   
    5271 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( u, count );
    5272                 :            :   
    5273                 :          0 :   RefEntity** vtx_iter = (RefEntity**)vertex_handles;
    5274                 :          0 :   RefEntity** edge_iter = (RefEntity**)edge_handles;
    5275         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    5276         [ #  # ]:          0 :     RefVertex* vtx = dynamic_cast<RefVertex*>(*vtx_iter);
    5277         [ #  # ]:          0 :     RefEdge* edge = dynamic_cast<RefEdge*>(*edge_iter);
    5278 [ #  # ][ #  # ]:          0 :     if (!vtx || !edge) {
    5279         [ #  # ]:          0 :       RETURN(iBase_INVALID_ENTITY_TYPE);
    5280                 :            :     }
    5281                 :            :     
    5282         [ #  # ]:          0 :     iBase_ErrorType rval = iGeom_get_vtx_to_u( vtx, edge, (*u)[i] );
    5283         [ #  # ]:          0 :     if (iBase_SUCCESS != rval) {
    5284         [ #  # ]:          0 :       RETURN(rval);
    5285                 :            :     }
    5286                 :            :     
    5287                 :          0 :     vtx_iter += vtx_step;
    5288                 :          0 :     edge_iter += edge_step;
    5289                 :            :   }
    5290         [ #  # ]:          0 :   KEEP_ARRAY(u);
    5291 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5292                 :            : }
    5293                 :            : 
    5294                 :            : ITAPS_API void
    5295                 :          0 : iGeom_getEntNrmlUV( iGeom_Instance instance,
    5296                 :            :                     /*in*/ iBase_EntityHandle entity_handle,
    5297                 :            :                     /*in*/ double u,
    5298                 :            :                     /*in*/ double v,
    5299                 :            :                     /*out*/ double* nrml_i,
    5300                 :            :                     /*out*/ double* nrml_j,
    5301                 :            :                     /*out*/ double* nrml_k,
    5302                 :            :                     int* err )
    5303                 :            : {
    5304         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>((RefEntity*)entity_handle);
    5305         [ #  # ]:          0 :   if (!face) {
    5306         [ #  # ]:          0 :     RETURN (iBase_INVALID_ENTITY_TYPE);
    5307                 :            :   }
    5308                 :            :   
    5309         [ #  # ]:          0 :   CubitVector normal;
    5310         [ #  # ]:          0 :   CubitStatus s = iGeom_normal_from_uv( face, u, v, normal );
    5311         [ #  # ]:          0 :   normal.get_xyz( *nrml_i, *nrml_j, *nrml_k );
    5312 [ #  # ][ #  # ]:          0 :   RETURN ((s == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE));
    5313                 :            : }
    5314                 :            : 
    5315                 :            : /**
    5316                 :            :  * Return the normals at specified uv positions on gfaces.  If any
    5317                 :            :  * gentity input is not a face, returns error.  Input parameters and 
    5318                 :            :  * output normals are interleaved.
    5319                 :            :  * @param gface_handles The entities being queried
    5320                 :            :  * @param parameters The uv parameters of points being queried, interleaved
    5321                 :            :  * @param normals Normals at specified points, interleaved
    5322                 :            :  */
    5323                 :            : ITAPS_API void
    5324                 :          0 : iGeom_getArrNrmlUV( iGeom_Instance instance,
    5325                 :            :                     /*in*/ iBase_EntityHandle const *gface_handles,
    5326                 :            :                     int gface_handles_size,
    5327                 :            :                     /*in*/ int storage_order,
    5328                 :            :                     /*in*/ const double *parameters,
    5329                 :            :                     int parameters_size,
    5330                 :            :                     /*out*/ double **normals,
    5331                 :            :                     int *normals_allocated,
    5332                 :            :                     int *normals_size,
    5333                 :            :                     int* err )
    5334                 :            : {
    5335                 :            :   int count;
    5336                 :            :   size_t face_step, param_step, norm_step;
    5337         [ #  # ]:          0 :   if (2*gface_handles_size == parameters_size) {
    5338                 :          0 :     count = gface_handles_size;
    5339                 :          0 :     face_step = param_step = 1;
    5340                 :            :   }
    5341         [ #  # ]:          0 :   else if (parameters_size == 2) {
    5342                 :          0 :     count = gface_handles_size;
    5343                 :          0 :     face_step = 1;
    5344                 :          0 :     param_step = 0;
    5345                 :            :   }
    5346         [ #  # ]:          0 :   else if (gface_handles_size == 1) {
    5347                 :          0 :     count = parameters_size/2;
    5348                 :          0 :     face_step = 0;
    5349                 :          0 :     param_step = 1;
    5350                 :            :   }
    5351                 :            :   else {
    5352         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    5353                 :            :   }
    5354                 :            :   
    5355                 :            :     // check or pre-allocate the coordinate arrays
    5356 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( normals, 3*count );
    5357                 :            : 
    5358                 :            :   const double *u, *v;
    5359                 :            :   double *x, *y, *z;
    5360                 :          0 :   u = parameters;
    5361                 :          0 :   x = *normals;
    5362         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    5363         [ #  # ]:          0 :     v = u + (param_step ? count : 1);
    5364                 :          0 :     y = x + count;
    5365                 :          0 :     z = y + count;
    5366                 :          0 :     norm_step = 1;
    5367                 :            :   }
    5368                 :            :   else {
    5369                 :          0 :     storage_order = iBase_INTERLEAVED;
    5370                 :          0 :     v = u + 1;
    5371                 :          0 :     y = x + 1;
    5372                 :          0 :     z = x + 2;
    5373                 :          0 :     norm_step = 3;
    5374                 :          0 :     param_step *= 2;
    5375                 :            :   }
    5376                 :            :   
    5377                 :          0 :   RefEntity** face_iter = (RefEntity**)gface_handles;
    5378         [ #  # ]:          0 :   for (int i = 0; i < count; ++i) {
    5379         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(*face_iter);
    5380 [ #  # ][ #  # ]:          0 :     if (!face) { RETURN (iBase_INVALID_ENTITY_TYPE); }
    5381                 :            :     
    5382         [ #  # ]:          0 :     CubitVector normal;
    5383         [ #  # ]:          0 :     CubitStatus s = iGeom_normal_from_uv( face, *u, *v, normal );
    5384         [ #  # ]:          0 :     normal.get_xyz( *x, *y, *z );
    5385         [ #  # ]:          0 :     if (CUBIT_SUCCESS != s) {
    5386         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    5387                 :            :     }
    5388                 :            :     
    5389                 :          0 :     face_iter += face_step;
    5390                 :          0 :     x += norm_step;
    5391                 :          0 :     y += norm_step;
    5392                 :          0 :     z += norm_step;
    5393                 :          0 :     u += param_step;
    5394                 :          0 :     v += param_step;
    5395                 :            :   }
    5396                 :            :   
    5397         [ #  # ]:          0 :   KEEP_ARRAY(normals);
    5398 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5399                 :            : }
    5400                 :            : 
    5401                 :            : 
    5402                 :            : ITAPS_API void
    5403                 :          0 : iGeom_getEntTgntU( iGeom_Instance instance,
    5404                 :            :                    /*in*/ iBase_EntityHandle entity_handle,
    5405                 :            :                    /*in*/ double param_coord,
    5406                 :            :                    /*out*/ double* tngt_i,
    5407                 :            :                    /*out*/ double* tngt_j,
    5408                 :            :                    /*out*/ double* tngt_k,
    5409                 :            :                    int* err )
    5410                 :            : {
    5411                 :            :   double x, y, z;
    5412         [ #  # ]:          0 :   iGeom_getEntUtoXYZ( instance, entity_handle, param_coord, &x, &y, &z, err );
    5413         [ #  # ]:          0 :   if (iBase_SUCCESS == *err)
    5414         [ #  # ]:          0 :     iGeom_getEntTgntXYZ( instance, entity_handle, x, y, z, tngt_i, tngt_j, tngt_k, err );
    5415                 :          0 : }
    5416                 :            : 
    5417                 :            : /**
    5418                 :            :  * Return the tangents at specified u positions on gedges.  If any
    5419                 :            :  * gentity input is not a face, returns error.  Output normals are 
    5420                 :            :  * interleaved.
    5421                 :            :  * @param gentity_handles The gedges being queried
    5422                 :            :  * @param parameters The u parameters of points being queried
    5423                 :            :  * @param tangents Tangents at specified points, interleaved
    5424                 :            :  */
    5425                 :            : ITAPS_API void
    5426                 :          0 : iGeom_getArrTgntU( iGeom_Instance instance,
    5427                 :            :                    /*in*/ iBase_EntityHandle const *gedge_handles,
    5428                 :            :                    int gedge_handles_size,
    5429                 :            :                    /*in*/ int storage_order,
    5430                 :            :                    /*in*/ const double *parameters,
    5431                 :            :                    int parameters_size,
    5432                 :            :                    /*out*/ double **tangents,
    5433                 :            :                    int *tangents_allocated,
    5434                 :            :                    int *tangents_size,
    5435                 :            :                    int* err )
    5436                 :            : {
    5437                 :            :   iGeom_getArrUtoXYZ(instance, ARRAY_IN(gedge_handles),
    5438                 :            :                      ARRAY_IN(parameters), storage_order, 
    5439                 :          0 :                      ARRAY_INOUT(tangents), err); 
    5440         [ #  # ]:          0 :   if (iBase_SUCCESS == *err)
    5441                 :            :     iGeom_getArrTgntXYZ(instance, ARRAY_IN(gedge_handles), storage_order,
    5442                 :          0 :                         *tangents, *tangents_size, ARRAY_INOUT(tangents), err);
    5443                 :          0 : }
    5444                 :            : 
    5445                 :            : ITAPS_API void
    5446                 :          0 : iGeom_getEnt1stDrvt( iGeom_Instance instance,
    5447                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    5448                 :            :                      /*in*/ double u,
    5449                 :            :                      /*in*/ double v,
    5450                 :            :                      /*inout*/  double **dvrt_u ,
    5451                 :            :                      int *dvrt_u_allocated,
    5452                 :            :                      int *dvrt_u_size,
    5453                 :            :                      /*inout*/  double **dvrt_v ,
    5454                 :            :                      int *dvrt_v_allocated,
    5455                 :            :                      int *dvrt_v_size,
    5456                 :            :                      int* err )
    5457                 :            : {
    5458         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>((RefEntity*)entity_handle);
    5459         [ #  # ]:          0 :   if (!face) { 
    5460         [ #  # ]:          0 :     ERROR( iBase_INVALID_ENTITY_TYPE, "Derivatives only for faces." );
    5461                 :            :   }
    5462                 :            :   
    5463 [ #  # ][ #  # ]:          0 :   CubitVector du, dv;
    5464 [ #  # ][ #  # ]:          0 :   CubitStatus s = face->get_surface_ptr()->uv_derivitives( u, v, du, dv );
    5465         [ #  # ]:          0 :   if (CUBIT_SUCCESS != s) {
    5466         [ #  # ]:          0 :     RETURN(iBase_FAILURE);
    5467                 :            :   }
    5468                 :            :   
    5469 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( dvrt_u, 3 );
                 [ #  # ]
    5470 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY_NOFAIL( dvrt_v, 3 );
         [ #  # ][ #  # ]
    5471         [ #  # ]:          0 :   du.get_xyz( *dvrt_u );
    5472         [ #  # ]:          0 :   dv.get_xyz( *dvrt_v );
    5473 [ #  # ][ #  # ]:          0 :   RETURN (iBase_SUCCESS);
    5474                 :            : }
    5475                 :            : 
    5476                 :            : ITAPS_API void
    5477                 :          0 : iGeom_getArr1stDrvt( iGeom_Instance instance,
    5478                 :            :                      /*in*/ iBase_EntityHandle const *entity_handles ,
    5479                 :            :                      int entity_handles_size,
    5480                 :            :                      /*in*/ int storage_order,
    5481                 :            :                      /*in*/ const  double *uv ,
    5482                 :            :                      int uv_size,
    5483                 :            :                      /*inout*/  double **drvt_u ,
    5484                 :            :                      int *drvt_u_allocated,
    5485                 :            :                      int *drvt_u_size,
    5486                 :            :                      /*inout*/  int **u_offset ,
    5487                 :            :                      int *u_offset_allocated,
    5488                 :            :                      int *u_offset_size,  
    5489                 :            :                      /*inout*/  double **drvt_v ,
    5490                 :            :                      int *drvt_v_allocated,
    5491                 :            :                      int *drvt_v_size,
    5492                 :            :                      /*inout*/  int **v_offset ,
    5493                 :            :                      int *v_offset_allocated,
    5494                 :            :                      int *v_offset_size,
    5495                 :            :                      int* err )
    5496                 :            : {
    5497         [ #  # ]:          0 :   if (2*entity_handles_size != uv_size) {
    5498         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_COUNT, "Mismatched input array sizes.");
    5499                 :            :     RETURN(iBase_INVALID_ENTITY_COUNT);
    5500                 :            :   }
    5501                 :            :   
    5502 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( drvt_u, 3*entity_handles_size );
    5503 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( drvt_v, 3*entity_handles_size );
                 [ #  # ]
    5504 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( u_offset, entity_handles_size+1 );
                 [ #  # ]
    5505 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( v_offset, entity_handles_size+1 );
                 [ #  # ]
    5506                 :            :   
    5507                 :            :   size_t u_step, du_step, init;
    5508         [ #  # ]:          0 :   if (storage_order == iBase_BLOCKED) {
    5509                 :          0 :     u_step = du_step = 1;
    5510                 :          0 :     init = entity_handles_size;
    5511                 :            :   }
    5512                 :            :   else {
    5513                 :          0 :     storage_order = iBase_INTERLEAVED;
    5514                 :          0 :     u_step = 2;
    5515                 :          0 :     du_step = 3;
    5516                 :          0 :     init = 1;
    5517                 :            :   }
    5518                 :            :   
    5519                 :          0 :   const double *u = uv;
    5520                 :          0 :   const double *v = u + init;
    5521                 :          0 :   double *du_x = *drvt_u;
    5522                 :          0 :   double *du_y = du_x + init;
    5523                 :          0 :   double *du_z = du_y + init;
    5524                 :          0 :   double *dv_x = *drvt_v;
    5525                 :          0 :   double *dv_y = dv_x + init;
    5526                 :          0 :   double *dv_z = dv_y + init;
    5527                 :            :   
    5528                 :          0 :   int off = 0;
    5529                 :          0 :   RefEntity** entities = (RefEntity**)entity_handles;
    5530         [ #  # ]:          0 :   for (int i = 0; i < entity_handles_size; ++i) {
    5531         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(entities[i]);
    5532         [ #  # ]:          0 :     if (!face) { 
    5533         [ #  # ]:          0 :       ERROR( iBase_INVALID_ENTITY_TYPE, "Derivatives only for faces." );
    5534                 :            :     }
    5535                 :            :     
    5536 [ #  # ][ #  # ]:          0 :     CubitVector du, dv;
    5537 [ #  # ][ #  # ]:          0 :     CubitStatus s = face->get_surface_ptr()->uv_derivitives( *u, *v, du, dv );
    5538 [ #  # ][ #  # ]:          0 :     if (s != CUBIT_SUCCESS) { RETURN(iBase_FAILURE); }
    5539         [ #  # ]:          0 :     du.get_xyz( *du_x, *du_y, *du_z );
    5540         [ #  # ]:          0 :     dv.get_xyz( *dv_x, *dv_y, *dv_z );
    5541                 :            :   
    5542                 :          0 :     u += u_step;
    5543                 :          0 :     v += u_step;
    5544                 :          0 :     du_x += du_step;
    5545                 :          0 :     du_y += du_step;
    5546                 :          0 :     du_z += du_step;
    5547                 :          0 :     dv_x += du_step;
    5548                 :          0 :     dv_y += du_step;
    5549                 :          0 :     dv_z += du_step;
    5550                 :            : 
    5551                 :          0 :     (*u_offset)[i] = off;
    5552                 :          0 :     (*v_offset)[i] = off;
    5553                 :          0 :     off += du_step;
    5554                 :            :   }
    5555                 :          0 :   (*u_offset)[entity_handles_size] = off;
    5556                 :          0 :   (*v_offset)[entity_handles_size] = off; 
    5557                 :            : 
    5558         [ #  # ]:          0 :   KEEP_ARRAY( drvt_u );
    5559         [ #  # ]:          0 :   KEEP_ARRAY( drvt_v );
    5560         [ #  # ]:          0 :   KEEP_ARRAY( u_offset );
    5561         [ #  # ]:          0 :   KEEP_ARRAY( v_offset );
    5562 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5563                 :            : }
    5564                 :            : 
    5565                 :            : ITAPS_API void
    5566                 :          0 : iGeom_getEnt2ndDrvt( iGeom_Instance instance,
    5567                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    5568                 :            :                      /*in*/ double u,
    5569                 :            :                      /*in*/ double v,
    5570                 :            :                      /*inout*/  double **dvrt_uu ,
    5571                 :            :                      int *dvrt_uu_allocated,
    5572                 :            :                      int *dvrt_uu_size,
    5573                 :            :                      /*inout*/  double **dvrt_uv ,
    5574                 :            :                      int *dvrt_uv_allocated,
    5575                 :            :                      int *dvrt_uv_size,
    5576                 :            :                      /*inout*/  double **dvrt_vv ,
    5577                 :            :                      int *dvrt_vv_allocated,
    5578                 :            :                      int *dvrt_vv_size,
    5579                 :            :                      int* err )
    5580                 :            : {
    5581                 :          0 :   RETURN(iBase_NOT_SUPPORTED);
    5582                 :            : }
    5583                 :            : 
    5584                 :            : ITAPS_API void
    5585                 :          0 : iGeom_getArr2ndDrvt( iGeom_Instance instance,
    5586                 :            :                      /*in*/ iBase_EntityHandle const *entity_handles ,
    5587                 :            :                      int entity_handles_size,
    5588                 :            :                      /*in*/ int storage_order,
    5589                 :            :                      /*in*/ const  double *uv ,
    5590                 :            :                      int uv_size,
    5591                 :            :                      /*inout*/  double **drvt_uu ,
    5592                 :            :                      int *drvt_uu_allocated,
    5593                 :            :                      int *drvt_uu_size,
    5594                 :            :                      /*inout*/  int **uu_offset ,
    5595                 :            :                      int *uu_offset_allocated,
    5596                 :            :                      int *uu_offset_size,  
    5597                 :            :                      /*inout*/  double **drvt_uv ,
    5598                 :            :                      int *drvt_uv_allocated,
    5599                 :            :                      int *drvt_uv_size,
    5600                 :            :                      /*inout*/  int **uv_offset ,
    5601                 :            :                      int *uv_offset_allocated,
    5602                 :            :                      int *uv_offset_size,  
    5603                 :            :                      /*inout*/  double **drvt_vv ,
    5604                 :            :                      int *drvt_vv_allocated,
    5605                 :            :                      int *drvt_vv_size,
    5606                 :            :                      /*inout*/  int **vv_offset ,
    5607                 :            :                      int *vv_offset_allocated,
    5608                 :            :                      int *vv_offset_size,
    5609                 :            :                      int* err )
    5610                 :            : {
    5611                 :          0 :   RETURN(iBase_NOT_SUPPORTED);
    5612                 :            : }
    5613                 :            : 
    5614                 :            : ITAPS_API void
    5615                 :          0 : iGeom_getFcCvtrUV( iGeom_Instance instance,
    5616                 :            :                    /*in*/ iBase_EntityHandle entity_handle,
    5617                 :            :                    /*in*/ double u,
    5618                 :            :                    /*in*/ double v,
    5619                 :            :                    /*out*/ double* cvtr1_i,
    5620                 :            :                    /*out*/ double* cvtr1_j,
    5621                 :            :                    /*out*/ double* cvtr1_k,
    5622                 :            :                    /*out*/ double* cvtr2_i,
    5623                 :            :                    /*out*/ double* cvtr2_j,
    5624                 :            :                    /*out*/ double* cvtr2_k,
    5625                 :            :                    int* err )
    5626                 :            : {
    5627                 :            :   double x, y, z;
    5628         [ #  # ]:          0 :   iGeom_getEntUVtoXYZ(instance, entity_handle, u, v, &x, &y, &z, err );
    5629         [ #  # ]:          0 :   if (*err == iBase_SUCCESS)
    5630                 :            :     iGeom_getFcCvtrXYZ(instance, entity_handle, x, y, z, 
    5631                 :            :                        cvtr1_i, cvtr1_j, cvtr1_k,
    5632                 :            :                        cvtr2_i, cvtr2_j, cvtr2_k,
    5633         [ #  # ]:          0 :                        err );
    5634                 :          0 : }
    5635                 :            : 
    5636                 :            : 
    5637                 :            : ITAPS_API void
    5638                 :          0 : iGeom_getFcArrCvtrUV( iGeom_Instance instance,
    5639                 :            :                       /*in*/ const  iBase_EntityHandle *face_handles ,
    5640                 :            :                       int face_handles_size,
    5641                 :            :                       /*in*/ int storage_order,
    5642                 :            :                       /*in*/ const  double *uv ,
    5643                 :            :                       int uv_size,
    5644                 :            :                       /*inout*/  double **cvtr_1 ,
    5645                 :            :                       int *cvtr_1_allocated,
    5646                 :            :                       int *cvtr_1_size,
    5647                 :            :                       /*inout*/  double **cvtr_2 ,
    5648                 :            :                       int *cvtr_2_allocated,
    5649                 :            :                       int *cvtr_2_size,
    5650                 :            :                       int* err )
    5651                 :            : {
    5652                 :            :   iGeom_getArrUVtoXYZ(instance, ARRAY_IN(face_handles), storage_order, 
    5653                 :          0 :                       ARRAY_IN(uv), ARRAY_INOUT(cvtr_1), err);
    5654         [ #  # ]:          0 :   if (*err == iBase_SUCCESS)
    5655                 :            :     iGeom_getEntArrCvtrXYZ(instance, ARRAY_IN(face_handles), storage_order,
    5656                 :            :                            *cvtr_1, *cvtr_1_size, 
    5657                 :          0 :                            ARRAY_INOUT(cvtr_1), ARRAY_INOUT(cvtr_2), err);
    5658                 :          0 : }
    5659                 :            : 
    5660                 :            : ITAPS_API void
    5661                 :          0 : iGeom_isEntPeriodic( iGeom_Instance instance, 
    5662                 :            :                      /*in*/ iBase_EntityHandle entity_handle,
    5663                 :            :                      /*out*/ int* in_u,
    5664                 :            :                      /*out*/ int* in_v,
    5665                 :            :                      int* err )
    5666                 :            : {
    5667                 :          0 :   CubitStatus s = iGeom_is_periodic( (RefEntity*)entity_handle, *in_u, *in_v );
    5668         [ #  # ]:          0 :   RETURN( (s == CUBIT_SUCCESS ? iBase_SUCCESS : iBase_FAILURE) );
    5669                 :            : }
    5670                 :            : 
    5671                 :            : ITAPS_API void
    5672                 :          0 : iGeom_isArrPeriodic( iGeom_Instance instance,
    5673                 :            :                      /*in*/ iBase_EntityHandle const *entity_handles ,
    5674                 :            :                      const int entity_handles_size,
    5675                 :            :                      /*inout*/  int **in_uv ,
    5676                 :            :                      int *in_uv_allocated,
    5677                 :            :                      int *in_uv_size,
    5678                 :            :                      int* err )
    5679                 :            : {
    5680 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( in_uv, 2*entity_handles_size );
    5681                 :          0 :   RefEntity** ents = (RefEntity**)entity_handles;
    5682         [ #  # ]:          0 :   for (int i = 0; i < entity_handles_size; ++i) {
    5683         [ #  # ]:          0 :     CubitStatus s = iGeom_is_periodic( ents[i], (*in_uv)[2*i], (*in_uv)[2*i+1] );
    5684         [ #  # ]:          0 :     if (s != CUBIT_SUCCESS) {
    5685         [ #  # ]:          0 :       RETURN(iBase_FAILURE);
    5686                 :            :     }
    5687                 :            :   }
    5688         [ #  # ]:          0 :   KEEP_ARRAY(in_uv);
    5689 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5690                 :            : }
    5691                 :            : 
    5692                 :            : ITAPS_API void
    5693                 :          0 : iGeom_isFcDegenerate( iGeom_Instance instance,
    5694                 :            :                       /*in*/ iBase_EntityHandle entity_handle,
    5695                 :            :                       int* is_degenerate,
    5696                 :            :                       int* err )
    5697                 :            : {
    5698         [ #  # ]:          0 :   RefFace* face = dynamic_cast<RefFace*>((RefEntity*)entity_handle);
    5699         [ #  # ]:          0 :   if (!face) { RETURN (iBase_INVALID_ENTITY_TYPE); }
    5700                 :          0 :   *is_degenerate = iGeom_is_face_degenerate(face);
    5701                 :          0 :   RETURN (iBase_SUCCESS);
    5702                 :            : }
    5703                 :            : 
    5704                 :            : ITAPS_API void
    5705                 :          0 : iGeom_isFcArrDegenerate( iGeom_Instance instance,
    5706                 :            :                          /*in*/ iBase_EntityHandle const *face_handles ,
    5707                 :            :                          const int face_handles_size,
    5708                 :            :                          /*inout*/  int **degenerate ,
    5709                 :            :                          int *degenerate_allocated,
    5710                 :            :                          int *degenerate_size,
    5711                 :            :                          int* err )
    5712                 :            : {
    5713 [ #  # ][ #  # ]:          0 :   ALLOC_CHECK_ARRAY( degenerate, face_handles_size );
    5714                 :          0 :   RefEntity** faces = (RefEntity**)face_handles;
    5715         [ #  # ]:          0 :   for (int i = 0; i < face_handles_size; ++i) {
    5716         [ #  # ]:          0 :     RefFace* face = dynamic_cast<RefFace*>(faces[i]);
    5717 [ #  # ][ #  # ]:          0 :     if (!face) { RETURN (iBase_INVALID_ENTITY_TYPE); }
    5718         [ #  # ]:          0 :     (*degenerate)[i] = iGeom_is_face_degenerate( face );
    5719                 :            :   }
    5720         [ #  # ]:          0 :   KEEP_ARRAY(degenerate);
    5721 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    5722                 :            : }
    5723                 :            :                
    5724                 :            : 
    5725                 :            : /**
    5726                 :            :  *   Subtract the gentities in gentity_set_2 from the gentities in
    5727                 :            :  *   gentity_set_1; the result is returned in gentity_set_1.  If
    5728                 :            :  *   gentity_set 1 is a multiset and contains m entries of a particular
    5729                 :            :  *   gentity, say gentity k, and gentity_set 2 contains n entry of gentity
    5730                 :            :  *   k, the result contains m-n entries of gentity k.  (What about
    5731                 :            :  *   ordered sets? What if gentity_set 2 is not a subset of gentity set
    5732                 :            :  *   1?  Should be consistent with STL... )
    5733                 :            :  */
    5734                 :            : ITAPS_API void
    5735                 :          1 : iGeom_subtract( iGeom_Instance instance,
    5736                 :            :                 /*in*/ iBase_EntitySetHandle entity_set_1,
    5737                 :            :                 /*in*/ iBase_EntitySetHandle entity_set_2,
    5738                 :            :                 /*out*/ iBase_EntitySetHandle *result_entity_set,
    5739                 :            :                 int* err )
    5740                 :            : {
    5741                 :          1 :   const RefGroup *set1 = SET_HANDLE(entity_set_1);
    5742                 :          1 :   const RefGroup *set2 = SET_HANDLE(entity_set_2);
    5743                 :          1 :   RefGroup *set3 = SET_HANDLE(*result_entity_set);
    5744         [ -  + ]:          1 :   if (NULL == set3) {
    5745                 :          0 :     set3 = RefEntityFactory::instance()->construct_RefGroup();
    5746                 :          0 :     *result_entity_set = reinterpret_cast<iBase_EntitySetHandle>(set3);
    5747                 :            :   }
    5748                 :            :     
    5749                 :          1 :   const_cast<RefGroup*>(set1)->subtract(const_cast<RefGroup*>(set2), set3);
    5750                 :          1 :   RETURN(iBase_SUCCESS);
    5751                 :            : }
    5752                 :            : 
    5753                 :            : /**
    5754                 :            :  *   Intersect gentity_set_1 and gentity_set_2; the result is returned in
    5755                 :            :  *   gentity_set_1.  If both are multisets and both contain 2 entries of
    5756                 :            :  *   gentity k, the intersection contains 2 entries as well.
    5757                 :            :  */
    5758                 :            : ITAPS_API void
    5759                 :          1 : iGeom_intersect( iGeom_Instance instance,
    5760                 :            :                  /*in*/ iBase_EntitySetHandle entity_set_1,
    5761                 :            :                  /*in*/ iBase_EntitySetHandle entity_set_2,
    5762                 :            :                  /*out*/ iBase_EntitySetHandle *result_entity_set,
    5763                 :            :                  int* err )
    5764                 :            : {
    5765                 :          1 :   const RefGroup *set1 = SET_HANDLE(entity_set_1);
    5766                 :          1 :   const RefGroup *set2 = SET_HANDLE(entity_set_2);
    5767                 :          1 :   RefGroup *set3 = SET_HANDLE(*result_entity_set);
    5768         [ -  + ]:          1 :   if (NULL == set3) {
    5769                 :          0 :     set3 = RefEntityFactory::instance()->construct_RefGroup();
    5770                 :          0 :     *result_entity_set = reinterpret_cast<iBase_EntitySetHandle>(set3);
    5771                 :            :   }
    5772                 :            : 
    5773                 :          1 :   const_cast<RefGroup*>(set1)->intersect(const_cast<RefGroup*>(set2), set3);
    5774                 :          1 :   RETURN(iBase_SUCCESS);
    5775                 :            : }
    5776                 :            : 
    5777                 :            : /**
    5778                 :            :  *   Union the gentities in gentity_set_1 and gentity_set_2; the result is
    5779                 :            :  *   returned in gentity_set_1.  The multiset flag in gentityset 1
    5780                 :            :  *   determines if duplicate entries are allowed.
    5781                 :            :  */
    5782                 :            : ITAPS_API void
    5783                 :          1 : iGeom_unite( iGeom_Instance instance,
    5784                 :            :              /*in*/ iBase_EntitySetHandle entity_set_1,
    5785                 :            :              /*in*/ iBase_EntitySetHandle entity_set_2,
    5786                 :            :              /*out*/ iBase_EntitySetHandle *result_entity_set,
    5787                 :            :              int* err )
    5788                 :            : {
    5789                 :          1 :   const RefGroup *set1 = SET_HANDLE(entity_set_1);
    5790                 :          1 :   const RefGroup *set2 = SET_HANDLE(entity_set_2);
    5791                 :          1 :   RefGroup *set3 = SET_HANDLE(*result_entity_set);
    5792         [ -  + ]:          1 :   if (NULL == set3) {
    5793                 :          0 :     set3 = RefEntityFactory::instance()->construct_RefGroup();
    5794                 :          0 :     *result_entity_set = reinterpret_cast<iBase_EntitySetHandle>(set3);
    5795                 :            :   }
    5796                 :            : 
    5797                 :          1 :   const_cast<RefGroup*>(set1)->unite(const_cast<RefGroup*>(set2), set3);
    5798                 :          1 :   RETURN(iBase_SUCCESS);
    5799                 :            : }
    5800                 :            : 
    5801                 :            : ITAPS_API void
    5802                 :          1 : iGeom_copyEnt( iGeom_Instance instance,
    5803                 :            :                /*in*/ iBase_EntityHandle geom_entity,
    5804                 :            :                /*out*/ iBase_EntityHandle *geom_entity2,
    5805                 :            :                int* err )
    5806                 :            : {
    5807         [ -  + ]:          1 :   Body *this_body = dynamic_cast<Body*>(ENTITY_HANDLE(geom_entity));
    5808         [ -  + ]:          1 :   RefVolume *this_vol = dynamic_cast<RefVolume*>(ENTITY_HANDLE(geom_entity));
    5809 [ +  - ][ +  - ]:          1 :   if (NULL != this_vol || NULL != this_body) {
    5810                 :            :       // need to get the associated body, since cgm only supports copying bodies,
    5811                 :            :       // not volumes
    5812         [ -  + ]:          1 :     if (NULL == this_body) {
    5813                 :          0 :       this_body = this_vol->get_body_ptr();
    5814         [ #  # ]:          0 :       if (NULL == this_body) {
    5815                 :          0 :         ERROR(iBase_FAILURE, "Can't get body from volume.");
    5816                 :            :       }
    5817                 :            :     }
    5818                 :            : 
    5819         [ +  - ]:          1 :     RefEntity *temp_entity = gmt->copy_body(this_body);
    5820                 :          1 :     *geom_entity2 = reinterpret_cast<iBase_EntityHandle>(temp_entity);
    5821                 :            :   }
    5822                 :            :   else {
    5823                 :          0 :     RefEntity *this_ent = ENTITY_HANDLE(geom_entity);
    5824                 :          0 :     RefEntity *temp_entity = gmt->copy_refentity(this_ent);
    5825                 :          0 :     *geom_entity2 = reinterpret_cast<iBase_EntityHandle>(temp_entity);
    5826                 :            :   }
    5827                 :            : 
    5828         [ -  + ]:          1 :   if (NULL == *geom_entity2) {
    5829                 :          0 :     ERROR(iBase_FAILURE, "NULL returned from CGM copy.");
    5830                 :            :   }
    5831                 :            :   
    5832                 :          1 :   RETURN(iBase_SUCCESS);
    5833                 :            : }
    5834                 :            :       
    5835                 :            : ITAPS_API void
    5836                 :          1 : iGeom_sweepEntAboutAxis( iGeom_Instance instance,
    5837                 :            :                          /*in*/ iBase_EntityHandle geom_entity,
    5838                 :            :                          /*in*/ const double angle,
    5839                 :            :                          /*in*/ const double axis_normal_x,
    5840                 :            :                          /*in*/ const double axis_normal_y,
    5841                 :            :                          /*in*/ const double axis_normal_z,
    5842                 :            :                          /*out*/ iBase_EntityHandle *geom_entity2,
    5843                 :            :                          int* err )
    5844                 :            : {
    5845         [ +  - ]:          1 :   DLIList<RefEntity*> ents;
    5846                 :          1 :   RefEntity *this_ent = ENTITY_HANDLE(geom_entity);
    5847         [ -  + ]:          1 :   if (NULL == this_ent) {
    5848         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Can't get ref entity from specified entity.");
    5849                 :            :   }
    5850 [ +  - ][ -  + ]:          1 :   else if (this_ent->dimension() > 2) {
    5851         [ #  # ]:          0 :     ERROR(iBase_INVALID_ENTITY_TYPE, "Can't sweep 3-d entities.");
    5852                 :            :   }
    5853                 :            : 
    5854 [ +  - ][ +  - ]:          1 :   RefEntity *new_ent = gmt->copy_refentity(this_ent);
    5855         [ +  - ]:          1 :   ents.append(new_ent);
    5856                 :            :   
    5857         [ +  - ]:          1 :   CubitVector origin(0.0, 0.0, 0.0);
    5858         [ +  - ]:          1 :   CubitVector direction(axis_normal_x, axis_normal_y, axis_normal_z);
    5859                 :            : 
    5860                 :          1 :   double radian_angle = angle * DEG_TO_RAD;
    5861                 :            :   
    5862 [ +  - ][ +  - ]:          2 :   DLIList<Body*> new_bodies;
    5863                 :            :   CubitStatus result = gmt->sweep_rotational(ents, origin, direction,
    5864                 :            :                                              radian_angle, new_bodies,
    5865 [ +  - ][ +  - ]:          1 :                                              CUBIT_FALSE, CUBIT_FALSE);
    5866         [ -  + ]:          1 :   if (CUBIT_FAILURE == result) {
    5867                 :            :       // destroy entity we copied before
    5868 [ #  # ][ #  # ]:          0 :     gqt->delete_RefEntity(new_ent);
    5869         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Sweep returned failure.");
    5870                 :            :   }
    5871                 :            :   
    5872                 :            :   else {
    5873                 :            :       // HACK to get last entity created, because cgm doesn't return
    5874                 :            :       // body created by sweep
    5875 [ +  - ][ +  - ]:          1 :     RefEntity *new_body = new_bodies.get();
    5876                 :          1 :     *geom_entity2 = reinterpret_cast<iBase_EntityHandle>(new_body);
    5877                 :            : 
    5878                 :            :       // now we know it's succeeded, delete original body
    5879 [ -  + ][ +  - ]:          1 :     Body *this_body = dynamic_cast<TopologyEntity*>(this_ent)->body();
    5880         [ +  - ]:          1 :     if (NULL != this_body)
    5881 [ +  - ][ +  - ]:          1 :       gqt->delete_RefEntity(this_body);
                 [ +  - ]
    5882                 :            :     else
    5883 [ #  # ][ #  # ]:          0 :       gqt->delete_RefEntity(this_ent);
    5884                 :            :   }
    5885                 :            : 
    5886                 :            : 
    5887         [ -  + ]:          1 :   if (NULL == *geom_entity2) {
    5888         [ #  # ]:          0 :     RETURN(iBase_FAILURE);
    5889                 :            :   }
    5890                 :            :   
    5891 [ +  - ][ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    5892                 :            : }
    5893                 :            : 
    5894                 :            : ITAPS_API void
    5895                 :          4 : iGeom_deleteAll( iGeom_Instance,
    5896                 :            :                  int* err )
    5897                 :            : {
    5898                 :          4 :   GeometryQueryTool::instance()->delete_geometry();
    5899                 :          4 :   *err = iBase_SUCCESS;
    5900                 :          4 : }
    5901                 :            : 
    5902                 :            : 
    5903                 :            : ITAPS_API void
    5904                 :          6 : iGeom_deleteEnt( iGeom_Instance instance,
    5905                 :            :                  /*in*/ iBase_EntityHandle geom_entity,
    5906                 :            :                  int* err )
    5907                 :            : {
    5908                 :          6 :   RefEntity *this_ent = ENTITY_HANDLE(geom_entity);
    5909                 :            : 
    5910                 :            :     // special case: if this is a volume, delete the body instead
    5911                 :            :   CubitStatus result;
    5912         [ -  + ]:          6 :   RefVolume *this_vol = CAST_TO(this_ent, RefVolume);
    5913         [ -  + ]:          6 :   if (NULL != this_vol)
    5914                 :          0 :     result = gqt->delete_Body(this_vol->body());
    5915                 :            :   else    
    5916                 :          6 :     result = gqt->delete_RefEntity(this_ent);
    5917                 :            : 
    5918         [ -  + ]:          6 :   if (CUBIT_FAILURE == result) {
    5919                 :          0 :     ERROR(iBase_FAILURE, "Problems deleting entity.");
    5920                 :            :   }
    5921                 :            : 
    5922                 :            :     // check to see if this was last thing deleted; if so, reset ids
    5923                 :          6 :   RefEntityFactory *rfi = RefEntityFactory::instance();
    5924 [ #  # ][ -  + ]:         12 :   if (rfi->num_bodies() == 0 && 
    5925         [ #  # ]:          0 :       rfi->num_ref_volumes() == 0 &&
    5926         [ #  # ]:          0 :       rfi->num_ref_faces() == 0 &&
    5927 [ -  + ][ #  # ]:          6 :       rfi->num_ref_edges() == 0 &&
    5928                 :          0 :       rfi->num_ref_vertices() == 0)
    5929                 :          0 :     rfi->reset_ids();
    5930                 :            :   
    5931                 :          6 :   RETURN(iBase_SUCCESS);
    5932                 :            : }
    5933                 :            : 
    5934                 :            : ITAPS_API void
    5935                 :          0 : iGeom_createSphere( iGeom_Instance instance,
    5936                 :            :                     double radius,
    5937                 :            :                     iBase_EntityHandle *geom_entity,
    5938                 :            :                     int* err )
    5939                 :            : {
    5940         [ #  # ]:          0 :   if (radius <= 0.0) {
    5941                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Sphere radius must be must be positive.");
    5942                 :            :   }
    5943                 :            :   
    5944         [ #  # ]:          0 :   RefEntity* tmp_body = gmt->sphere( radius );
    5945                 :          0 :   *geom_entity = reinterpret_cast<iBase_EntityHandle>(tmp_body);
    5946         [ #  # ]:          0 :   RETURN ((tmp_body ? iBase_SUCCESS : iBase_FAILURE));
    5947                 :            : }
    5948                 :            : 
    5949                 :            : 
    5950                 :            : ITAPS_API void
    5951                 :          1 : iGeom_createPrism( iGeom_Instance instance,
    5952                 :            :                    /*in*/ double height,
    5953                 :            :                    /*in*/ int n_sides,
    5954                 :            :                    /*in*/ double major_rad,
    5955                 :            :                    /*in*/ double minor_rad,
    5956                 :            :                    /*out*/ iBase_EntityHandle *geom_entity,
    5957                 :            :                    int* err )
    5958                 :            : {
    5959         [ -  + ]:          1 :   if ( 0.0>=height ) {
    5960                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Prism height must be positive.");
    5961         [ -  + ]:          1 :   } else if ( 3>n_sides ) {
    5962                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Prism must have at least three sides.");
    5963                 :            :   }
    5964                 :            :   
    5965         [ +  - ]:          1 :   RefEntity* tmp_body = gmt->prism( height, n_sides, major_rad, minor_rad );
    5966                 :          1 :   *geom_entity = reinterpret_cast<iBase_EntityHandle>(tmp_body);
    5967         [ +  - ]:          1 :   RETURN ((tmp_body ? iBase_SUCCESS :iBase_FAILURE));
    5968                 :            : }
    5969                 :            : 
    5970                 :            : 
    5971                 :            : ITAPS_API void
    5972                 :          3 : iGeom_createBrick( iGeom_Instance instance,
    5973                 :            :                    /*in*/ double x,
    5974                 :            :                    /*in*/ double y,
    5975                 :            :                    /*in*/ double z,
    5976                 :            :                    /*out*/ iBase_EntityHandle *geom_entity,
    5977                 :            :                    int* err )
    5978                 :            : {
    5979                 :          3 :   double tmp_x = x;
    5980                 :          3 :   double tmp_y = y;
    5981                 :          3 :   double tmp_z = z;
    5982                 :            :   
    5983 [ +  + ][ +  - ]:          3 :   if (0.0 == y && 0.0 == z) {
    5984                 :          1 :     tmp_y = x;
    5985                 :          1 :     tmp_z = x;
    5986                 :            :   }
    5987                 :            :   
    5988 [ +  - ][ +  - ]:          3 :   if (0.0 >= tmp_x || 0.0 >= tmp_y || 0.0 >= tmp_z) {
                 [ -  + ]
    5989                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Dimensions must be >= 0, or y & z must both be zero.");
    5990                 :            :   }
    5991                 :            :     
    5992         [ +  - ]:          3 :   RefEntity *temp_body = gmt->brick(tmp_x, tmp_y, tmp_z);
    5993                 :          3 :   *geom_entity = reinterpret_cast<iBase_EntityHandle>(temp_body);
    5994                 :            : 
    5995         [ -  + ]:          3 :   if (NULL == *geom_entity) {
    5996                 :          0 :     RETURN(iBase_FAILURE);
    5997                 :            :   }
    5998                 :            : 
    5999                 :          3 :   RETURN(iBase_SUCCESS);
    6000                 :            : }
    6001                 :            :           
    6002                 :            : ITAPS_API void
    6003                 :          5 : iGeom_createCylinder( iGeom_Instance instance,
    6004                 :            :                       /*in*/ double height,
    6005                 :            :                       /*in*/ double major_rad,
    6006                 :            :                       /*in*/ double minor_rad,
    6007                 :            :                       /*out*/ iBase_EntityHandle *geom_entity,
    6008                 :            :                       int* err )
    6009                 :            : {
    6010         [ +  + ]:          5 :   double tmp_minor = (0.0 == minor_rad ? major_rad : minor_rad);
    6011                 :            :   RefEntity *temp_body = 
    6012         [ +  - ]:          5 :     gmt->cylinder(height, major_rad, tmp_minor, major_rad);
    6013                 :          5 :   *geom_entity = reinterpret_cast<iBase_EntityHandle>(temp_body);
    6014                 :            : 
    6015                 :            : 
    6016         [ -  + ]:          5 :   if (NULL == *geom_entity) {
    6017                 :          0 :     RETURN(iBase_FAILURE);
    6018                 :            :   }
    6019                 :            : 
    6020                 :          5 :   RETURN(iBase_SUCCESS);
    6021                 :            : }
    6022                 :            :       
    6023                 :            : ITAPS_API void
    6024                 :          0 : iGeom_createCone( iGeom_Instance instance,
    6025                 :            :                   /*in*/ double height,
    6026                 :            :                   /*in*/ double major_rad_base,
    6027                 :            :                   /*in*/ double minor_rad_base,
    6028                 :            :                   /*in*/ double rad_top,
    6029                 :            :                   /*out*/ iBase_EntityHandle *geom_entity,
    6030                 :            :                   int* err )
    6031                 :            : {
    6032         [ #  # ]:          0 :   double tmp_minor = (0.0 == minor_rad_base ? major_rad_base : minor_rad_base);
    6033                 :            :   RefEntity *temp_body = 
    6034         [ #  # ]:          0 :     gmt->cylinder(height, major_rad_base, tmp_minor, rad_top);
    6035                 :          0 :   *geom_entity = reinterpret_cast<iBase_EntityHandle>(temp_body);
    6036                 :            : 
    6037                 :            : 
    6038         [ #  # ]:          0 :   if (NULL == *geom_entity) {
    6039                 :          0 :     RETURN(iBase_FAILURE);
    6040                 :            :   }
    6041                 :            : 
    6042                 :          0 :   RETURN(iBase_SUCCESS);
    6043                 :            : }
    6044                 :            :     
    6045                 :            : ITAPS_API void
    6046                 :          1 : iGeom_createTorus( iGeom_Instance instance,
    6047                 :            :                    /*in*/ double major_rad,
    6048                 :            :                    /*in*/ double minor_rad,
    6049                 :            :                    /*out*/ iBase_EntityHandle *geom_entity,
    6050                 :            :                    int* err )
    6051                 :            : {
    6052         [ -  + ]:          1 :   if (minor_rad >= major_rad) {
    6053                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Major radius must be greater than minor radius for tori.");
    6054                 :            :   }
    6055                 :            :   
    6056         [ +  - ]:          1 :   RefEntity *temp_body = gmt->torus(major_rad, minor_rad);
    6057                 :          1 :   *geom_entity = reinterpret_cast<iBase_EntityHandle>(temp_body);
    6058                 :            :    
    6059         [ -  + ]:          1 :   if (NULL == *geom_entity) {
    6060                 :          0 :     RETURN(iBase_FAILURE);
    6061                 :            :   }
    6062                 :            : 
    6063                 :          1 :   RETURN(iBase_SUCCESS);
    6064                 :            : }
    6065                 :            : 
    6066                 :            : ITAPS_API void
    6067                 :          3 : iGeom_moveEnt( iGeom_Instance instance,
    6068                 :            :                /*inout*/ iBase_EntityHandle geom_entity,
    6069                 :            :                /*in*/ double x,
    6070                 :            :                /*in*/ double y,
    6071                 :            :                /*in*/ double z,
    6072                 :            :                int* err )
    6073                 :            : {
    6074         [ +  - ]:          3 :   CubitVector vec(x, y, z);
    6075         [ -  + ]:          3 :   Body *this_bod = dynamic_cast<Body*>(ENTITY_HANDLE(geom_entity));
    6076         [ +  - ]:          3 :   DLIList<Body*> bods;
    6077         [ +  - ]:          3 :   bods.append(this_bod);
    6078                 :            :   CubitStatus result;
    6079         [ +  - ]:          3 :   if (NULL != this_bod) {
    6080 [ +  - ][ +  - ]:          3 :     result = gqt->translate(bods, vec);
    6081         [ -  + ]:          3 :     if (CUBIT_SUCCESS != result) {
    6082         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to move body.");
    6083                 :            :       RETURN(iBase_FAILURE);
    6084                 :            :     }
    6085                 :            :     
    6086         [ +  - ]:          3 :     RETURN(iBase_SUCCESS);
    6087                 :            :   }
    6088                 :            :   
    6089         [ #  # ]:          0 :   BasicTopologyEntity *this_bte = dynamic_cast<BasicTopologyEntity*>(ENTITY_HANDLE(geom_entity));
    6090         [ #  # ]:          0 :   if (NULL != this_bte) {
    6091                 :            :       // non-body move; check to see if there are any siblings to this entity in the
    6092                 :            :       // same body; if so, we can't move it; if not, get the body and move that; if
    6093                 :            :       // there is no body, it's a free entity and we can move it anyway
    6094         [ #  # ]:          0 :     Body *this_body = this_bte->body();
    6095         [ #  # ]:          0 :     if (NULL == this_body) {
    6096         [ #  # ]:          0 :       DLIList<BasicTopologyEntity*> btes;
    6097         [ #  # ]:          0 :       btes.append(this_bte);
    6098 [ #  # ][ #  # ]:          0 :       result = gqt->translate(btes, vec);
    6099         [ #  # ]:          0 :       if (CUBIT_SUCCESS != result) {
    6100 [ #  # ][ #  # ]:          0 :         ERROR(iBase_FAILURE, "Failed to move entity.");
                 [ #  # ]
    6101                 :          0 :       }
    6102                 :            :     }
    6103                 :            :     else {
    6104                 :          0 :       int num_sibs = -1;
    6105         [ #  # ]:          0 :       switch (this_bte->dimension()) {
           [ #  #  #  # ]
    6106         [ #  # ]:          0 :         case 0: num_sibs = this_body->num_ref_vertices(); break;
    6107         [ #  # ]:          0 :         case 1: num_sibs = this_body->num_ref_edges(); break;
    6108         [ #  # ]:          0 :         case 2: num_sibs = this_body->num_ref_faces(); break;
    6109                 :            :       }
    6110         [ #  # ]:          0 :       if (num_sibs == 1) {
    6111                 :            :           // ok to move the body instead
    6112 [ #  # ][ #  # ]:          0 :         result = gqt->translate(bods, vec);
    6113         [ #  # ]:          0 :         if (CUBIT_SUCCESS != result) {
    6114         [ #  # ]:          0 :           ERROR(iBase_FAILURE, "Failed to move body even only one entity of that"
    6115                 :            :                              " dimension in the body.");
    6116                 :            :         }
    6117                 :            :       }
    6118                 :            :       else {
    6119         [ #  # ]:          0 :         ERROR(iBase_FAILURE, "Too many siblings for an entity to move it.");
    6120                 :            :       }
    6121                 :            :     }
    6122                 :            : 
    6123         [ #  # ]:          0 :     RETURN(iBase_SUCCESS);
    6124                 :            :   }
    6125                 :            :   
    6126 [ #  # ][ +  - ]:          3 :   ERROR(iBase_INVALID_ENTITY_TYPE, "Wrong type of entity specified for move.");
    6127                 :            : }
    6128                 :            :       
    6129                 :            : ITAPS_API void
    6130                 :          1 : iGeom_rotateEnt( iGeom_Instance instance,
    6131                 :            :                  /*inout*/ iBase_EntityHandle geom_entity,
    6132                 :            :                  /*in*/ double angle,
    6133                 :            :                  /*in*/ double axis_normal_x,
    6134                 :            :                  /*in*/ double axis_normal_y,
    6135                 :            :                  /*in*/ double axis_normal_z,
    6136                 :            :                  int* err )
    6137                 :            : {
    6138         [ +  - ]:          1 :   CubitVector this_axis(axis_normal_x, axis_normal_y, axis_normal_z);
    6139         [ -  + ]:          1 :   Body *this_bod = dynamic_cast<Body*>(ENTITY_HANDLE(geom_entity));
    6140         [ +  - ]:          1 :   DLIList<Body*> bods;
    6141         [ +  - ]:          1 :   bods.append(this_bod);
    6142                 :            :   CubitStatus result;
    6143         [ +  - ]:          1 :   if (NULL != this_bod) {
    6144 [ +  - ][ +  - ]:          1 :     result = gqt->rotate(bods, this_axis, angle);
    6145         [ -  + ]:          1 :     if (CUBIT_SUCCESS != result) {
    6146         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to rotate body.");
    6147                 :            :     }
    6148                 :            :     
    6149         [ +  - ]:          1 :     RETURN(iBase_SUCCESS);
    6150                 :            :   }
    6151                 :            :   
    6152         [ #  # ]:          0 :   BasicTopologyEntity *this_bte = dynamic_cast<BasicTopologyEntity*>(ENTITY_HANDLE(geom_entity));
    6153         [ #  # ]:          0 :   if (NULL != this_bte) {
    6154         [ #  # ]:          0 :     DLIList<BasicTopologyEntity*> btes;
    6155         [ #  # ]:          0 :     btes.append(this_bte);
    6156 [ #  # ][ #  # ]:          0 :     result = gqt->rotate(btes, this_axis, angle);
    6157         [ #  # ]:          0 :     if (CUBIT_SUCCESS != result) {
    6158         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to rotate entity.");
    6159                 :            :     }
    6160                 :            :     
    6161 [ #  # ][ #  # ]:          0 :     RETURN(iBase_SUCCESS);
    6162                 :            :   }
    6163                 :            :   
    6164 [ #  # ][ +  - ]:          1 :   ERROR(iBase_INVALID_ENTITY_TYPE, "Wrong type of entity specified for move.");
    6165                 :            : }
    6166                 :            : 
    6167                 :            : ITAPS_API void
    6168                 :          1 : iGeom_reflectEnt( iGeom_Instance instance,
    6169                 :            :                   /*inout*/ iBase_EntityHandle geom_entity,
    6170                 :            :                   /*in*/ double point_x,
    6171                 :            :                   /*in*/ double point_y,
    6172                 :            :                   /*in*/ double point_z,
    6173                 :            :                   /*in*/ double plane_normal_x,
    6174                 :            :                   /*in*/ double plane_normal_y,
    6175                 :            :                   /*in*/ double plane_normal_z,
    6176                 :            :                   int* err )
    6177                 :            : {
    6178         [ +  - ]:          1 :   CubitVector this_plane(plane_normal_x, plane_normal_y, plane_normal_z);
    6179         [ +  - ]:          1 :   CubitVector point(point_x, point_y, point_z);
    6180         [ -  + ]:          1 :   Body *this_bod = dynamic_cast<Body*>(ENTITY_HANDLE(geom_entity));
    6181         [ +  - ]:          1 :   DLIList<Body*> bods;
    6182         [ +  - ]:          1 :   bods.append(this_bod);
    6183                 :            :   CubitStatus result;
    6184         [ +  - ]:          1 :   if (NULL != this_bod) {
    6185 [ +  - ][ +  - ]:          1 :     result = gqt->reflect(bods, point , this_plane);
    6186         [ -  + ]:          1 :     if (CUBIT_SUCCESS != result) {
    6187         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to reflect body.");
    6188                 :            :     }
    6189                 :            :     
    6190         [ +  - ]:          1 :     RETURN(iBase_SUCCESS);
    6191                 :            :   }
    6192                 :            :   
    6193         [ #  # ]:          0 :   BasicTopologyEntity *this_bte = dynamic_cast<BasicTopologyEntity*>(ENTITY_HANDLE(geom_entity));
    6194         [ #  # ]:          0 :   if (NULL != this_bte) {
    6195         [ #  # ]:          0 :     DLIList<BasicTopologyEntity*> btes;
    6196         [ #  # ]:          0 :     btes.append(this_bte);
    6197 [ #  # ][ #  # ]:          0 :     result = gqt->reflect(btes, point, this_plane);
    6198         [ #  # ]:          0 :     if (CUBIT_SUCCESS != result) {
    6199         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to reflect entity.");
    6200                 :            :     }
    6201                 :            :     
    6202 [ #  # ][ #  # ]:          0 :     RETURN(iBase_SUCCESS);
    6203                 :            :   }
    6204                 :            :   
    6205 [ #  # ][ +  - ]:          1 :   ERROR(iBase_INVALID_ENTITY_TYPE, "Wrong type of entity specified for reflect.");
    6206                 :            : }
    6207                 :            : 
    6208                 :            : ITAPS_API void
    6209                 :          0 : iGeom_scaleEnt( iGeom_Instance instance,
    6210                 :            :                 /*inout*/ iBase_EntityHandle geom_entity,
    6211                 :            :                 /*in*/ double point_x,
    6212                 :            :                 /*in*/ double point_y,
    6213                 :            :                 /*in*/ double point_z,
    6214                 :            :                 /*in*/ double scale_x,
    6215                 :            :                 /*in*/ double scale_y,
    6216                 :            :                 /*in*/ double scale_z,
    6217                 :            :                 int* err )
    6218                 :            : {
    6219         [ #  # ]:          0 :   CubitVector factor(scale_x, scale_y, scale_z);
    6220         [ #  # ]:          0 :   CubitVector point(point_x, point_y, point_z);
    6221         [ #  # ]:          0 :   Body *this_bod = dynamic_cast<Body*>(ENTITY_HANDLE(geom_entity));
    6222                 :            :   CubitStatus result;
    6223         [ #  # ]:          0 :   if (NULL != this_bod) {
    6224 [ #  # ][ #  # ]:          0 :     result = gqt->scale(this_bod, point, factor);
    6225         [ #  # ]:          0 :     if (CUBIT_SUCCESS != result) {
    6226         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to scale body.");
    6227                 :            :     }
    6228                 :            :     
    6229         [ #  # ]:          0 :     RETURN(iBase_SUCCESS);
    6230                 :            :   }
    6231                 :            :   
    6232         [ #  # ]:          0 :   BasicTopologyEntity *this_bte = dynamic_cast<BasicTopologyEntity*>(ENTITY_HANDLE(geom_entity));
    6233                 :            :     // non-body move; check to see if there are any siblings to this entity in the
    6234                 :            :     // same body; if so, we can't move it; if not, get the body and move that; if
    6235                 :            :     // there is no body, it's a free entity and we can move it anyway
    6236         [ #  # ]:          0 :   Body *this_body = this_bte->body();
    6237 [ #  # ][ #  # ]:          0 :   if (NULL == this_body && NULL != this_bte) {
    6238 [ #  # ][ #  # ]:          0 :     result = gqt->scale(this_bte, point, factor);
    6239         [ #  # ]:          0 :     if (CUBIT_SUCCESS != result) {
    6240         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Failed to scale entity.");
    6241                 :            :     }
    6242                 :            :   }
    6243 [ #  # ][ #  # ]:          0 :   else if (NULL != this_body && NULL != this_bte) {
    6244                 :          0 :     int num_sibs = -1;
    6245 [ #  # ][ #  #  :          0 :     switch (this_bte->dimension()) {
                #  #  # ]
    6246         [ #  # ]:          0 :       case 0: num_sibs = this_body->num_ref_vertices(); break;
    6247         [ #  # ]:          0 :       case 1: num_sibs = this_body->num_ref_edges(); break;
    6248         [ #  # ]:          0 :       case 2: num_sibs = this_body->num_ref_faces(); break;
    6249                 :            :           // for TSTT, always scale volumes
    6250                 :          0 :       case 3: num_sibs = 1; break;
    6251                 :            :     }
    6252         [ #  # ]:          0 :     if (num_sibs == 1) {
    6253                 :            :         // ok to scale the body instead
    6254 [ #  # ][ #  # ]:          0 :       result = gqt->scale(this_body, point, factor);
    6255         [ #  # ]:          0 :       if (CUBIT_SUCCESS != result) {
    6256         [ #  # ]:          0 :         ERROR(iBase_FAILURE, "Failed to scale body even only one entity of that"
    6257                 :            :                            " dimension in the body.");
    6258                 :            :       }
    6259                 :            :     }
    6260                 :            :     else {
    6261         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Too many siblings for an entity to scale it.");
    6262                 :            :     }
    6263                 :            :   }
    6264                 :            : 
    6265         [ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    6266                 :            : }
    6267                 :            : 
    6268                 :            : ITAPS_API void
    6269                 :          1 : iGeom_uniteEnts( iGeom_Instance instance,
    6270                 :            :                  /*in*/ iBase_EntityHandle const* geom_entities,
    6271                 :            :                  int geom_entities_size,
    6272                 :            :                  /*out*/ iBase_EntityHandle *geom_entity,
    6273                 :            :                  int* err )
    6274                 :            : {
    6275 [ +  - ][ +  - ]:          2 :   DLIList<Body*> bods, orig_bods;
                 [ +  - ]
    6276                 :          1 :   RefEntity* const* handle_array = ENTITY_HANDLE_CONST_ARRAY(geom_entities);
    6277         [ +  + ]:          3 :   for (int i = 0; i < geom_entities_size; i++) {
    6278         [ -  + ]:          2 :     Body *this_body = dynamic_cast<Body*>(handle_array[i]);
    6279         [ +  - ]:          2 :     if (NULL != this_body) {
    6280 [ +  - ][ +  - ]:          2 :       Body *new_body = gmt->copy_body(this_body);
    6281         [ +  - ]:          2 :       if (NULL != new_body) {
    6282         [ +  - ]:          2 :         bods.append(this_body);
    6283         [ +  - ]:          2 :         orig_bods.append(new_body);
    6284                 :            :       }
    6285                 :            :     }
    6286                 :            :   }
    6287 [ +  - ][ -  + ]:          1 :   if (bods.size() < geom_entities_size) {
    6288         [ #  # ]:          0 :     ERROR(iBase_INVALID_ARGUMENT, "Not all entities input were regions.");
    6289                 :            :     for (int i = bods.size(); i > 0; i--)
    6290                 :            :       gqt->delete_RefEntity(bods.get_and_step());
    6291                 :            :     
    6292                 :            :     RETURN(iBase_SUCCESS);
    6293                 :            :   }
    6294                 :            :   
    6295 [ +  - ][ +  - ]:          2 :   DLIList<Body*> new_bods;
    6296 [ +  - ][ +  - ]:          1 :   CubitStatus result = gmt->unite(bods, new_bods, false);
    6297 [ +  - ][ +  - ]:          1 :   if (CUBIT_SUCCESS != result || 1 != new_bods.size()) {
         [ -  + ][ -  + ]
    6298         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Unite failed.");
    6299                 :            :   }
    6300                 :            :     
    6301                 :            :   else {
    6302 [ +  - ][ +  - ]:          1 :     *geom_entity = reinterpret_cast<iBase_EntityHandle>(dynamic_cast<RefEntity*>(new_bods.get()));
    6303 [ +  - ][ +  + ]:          3 :     for (int i = orig_bods.size(); i > 0; i--)
    6304 [ +  - ][ +  - ]:          2 :       gqt->delete_RefEntity(orig_bods.get_and_step());
         [ +  - ][ +  - ]
    6305                 :            :   }
    6306                 :            : 
    6307 [ +  - ][ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    6308                 :            : }
    6309                 :            : 
    6310                 :            : ITAPS_API void
    6311                 :          2 : iGeom_subtractEnts( iGeom_Instance instance,
    6312                 :            :                     /*in*/ iBase_EntityHandle blank,
    6313                 :            :                     /*in*/ iBase_EntityHandle tool,
    6314                 :            :                     /*out*/ iBase_EntityHandle *geom_entity,
    6315                 :            :                     int* err )
    6316                 :            : {
    6317         [ -  + ]:          2 :   Body *this_blank = dynamic_cast<Body*>(ENTITY_HANDLE(blank));
    6318 [ +  - ][ +  - ]:          2 :   Body *blank_copy = gmt->copy_body(this_blank);
    6319         [ -  + ]:          2 :   if (NULL == blank_copy) {
    6320         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Trouble copying blank.");
    6321                 :            :   }
    6322         [ -  + ]:          2 :   Body *this_tool = dynamic_cast<Body*>(ENTITY_HANDLE(tool));
    6323 [ +  - ][ +  - ]:          2 :   Body *tool_copy = gmt->copy_body(this_tool);
    6324         [ -  + ]:          2 :   if (NULL == tool_copy) {
    6325         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Trouble copying tool.");
    6326                 :            :     gqt->delete_RefEntity(blank_copy);
    6327                 :            :     RETURN(iBase_FAILURE);
    6328                 :            :   }
    6329                 :            : 
    6330 [ +  - ][ +  - ]:          4 :   DLIList<Body*> blank_list, new_body_list;
                 [ +  - ]
    6331         [ +  - ]:          2 :   blank_list.append(blank_copy);
    6332                 :            :   
    6333                 :          2 :   RefEntity *new_body = NULL;
    6334 [ +  - ][ +  - ]:          2 :   CubitStatus result = gmt->subtract(tool_copy, blank_list, new_body_list);
    6335 [ +  - ][ +  - ]:          2 :   if (CUBIT_SUCCESS != result || 0 == new_body_list.size()) {
         [ -  + ][ -  + ]
    6336         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Subtract failed.");
    6337                 :            :   }
    6338                 :            :   else {
    6339 [ +  - ][ +  - ]:          2 :     new_body = new_body_list.get();
    6340                 :          2 :     *geom_entity = reinterpret_cast<iBase_EntityHandle>(new_body);
    6341 [ +  - ][ +  - ]:          2 :     gqt->delete_RefEntity(this_blank);
                 [ +  - ]
    6342 [ +  - ][ +  - ]:          2 :     gqt->delete_RefEntity(this_tool);
                 [ +  - ]
    6343                 :            :   }
    6344                 :            : 
    6345 [ +  - ][ +  - ]:          4 :   RETURN(iBase_SUCCESS);
    6346                 :            : }
    6347                 :            : 
    6348                 :            : ITAPS_API void
    6349                 :          0 : iGeom_intersectEnts( iGeom_Instance instance,
    6350                 :            :                      /*in*/ iBase_EntityHandle ent1,
    6351                 :            :                      /*in*/ iBase_EntityHandle ent2,
    6352                 :            :                      /*out*/ iBase_EntityHandle *geom_entity,
    6353                 :            :                      int* err )
    6354                 :            : {
    6355         [ #  # ]:          0 :   Body *this_ent1 = dynamic_cast<Body*>(ENTITY_HANDLE(ent1));
    6356 [ #  # ][ #  # ]:          0 :   Body *ent1_copy = gmt->copy_body(this_ent1);
    6357         [ #  # ]:          0 :   if (NULL == ent1_copy) {
    6358         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Trouble copying blank.");
    6359                 :            :   }
    6360         [ #  # ]:          0 :   Body *this_ent2 = dynamic_cast<Body*>(ENTITY_HANDLE(ent2));
    6361 [ #  # ][ #  # ]:          0 :   Body *ent2_copy = gmt->copy_body(this_ent2);
    6362         [ #  # ]:          0 :   if (NULL == ent2_copy) {
    6363         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Trouble copying tool.");
    6364                 :            :     gqt->delete_RefEntity(ent1_copy);
    6365                 :            :     RETURN(iBase_FAILURE);
    6366                 :            :   }
    6367                 :            : 
    6368 [ #  # ][ #  # ]:          0 :   DLIList<Body*> ent1_list, new_body_list;
                 [ #  # ]
    6369         [ #  # ]:          0 :   ent1_list.append(ent1_copy);
    6370                 :            :   
    6371                 :          0 :   RefEntity *new_body = NULL;
    6372 [ #  # ][ #  # ]:          0 :   CubitStatus result = gmt->intersect(ent2_copy, ent1_list, new_body_list);
    6373 [ #  # ][ #  # ]:          0 :   if (CUBIT_SUCCESS != result || 0 == new_body_list.size()) {
         [ #  # ][ #  # ]
    6374         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Intersect failed.");
    6375                 :            :   }
    6376                 :            :   else {
    6377 [ #  # ][ #  # ]:          0 :     new_body = new_body_list.get();
    6378                 :          0 :     *geom_entity = reinterpret_cast<iBase_EntityHandle>(new_body);
    6379 [ #  # ][ #  # ]:          0 :     gqt->delete_RefEntity(this_ent2);
                 [ #  # ]
    6380 [ #  # ][ #  # ]:          0 :     gqt->delete_RefEntity(this_ent1);
                 [ #  # ]
    6381                 :            :   }
    6382                 :            : 
    6383 [ #  # ][ #  # ]:          0 :   RETURN(iBase_SUCCESS);
    6384                 :            : }
    6385                 :            : 
    6386                 :            : ITAPS_API void
    6387                 :          1 : iGeom_sectionEnt( iGeom_Instance instance,
    6388                 :            :                   /*inout*/ iBase_EntityHandle geom_entity,
    6389                 :            :                   /*in*/ double plane_normal_x,
    6390                 :            :                   /*in*/ double plane_normal_y,
    6391                 :            :                   /*in*/ double plane_normal_z,
    6392                 :            :                   /*in*/ double offset,
    6393                 :            :                   /*in*/ int reverse,
    6394                 :            :                   /*out*/ iBase_EntityHandle *geom_entity2,
    6395                 :            :                   int* err )
    6396                 :            : {
    6397         [ -  + ]:          1 :   Body *this_body = dynamic_cast<Body*>(ENTITY_HANDLE(geom_entity));
    6398         [ -  + ]:          1 :   if (NULL == this_body) {
    6399         [ #  # ]:          0 :     RefVolume *this_vol = dynamic_cast<RefVolume*>(ENTITY_HANDLE(geom_entity));
    6400         [ #  # ]:          0 :     if (NULL != this_vol)
    6401         [ #  # ]:          0 :       this_body = this_vol->get_body_ptr();
    6402                 :            :   }
    6403         [ -  + ]:          1 :   if (NULL == this_body) {
    6404         [ #  # ]:          0 :     ERROR(iBase_INVALID_ARGUMENT, "Can only section bodies.");
    6405                 :            :   }
    6406                 :            : 
    6407         [ +  - ]:          1 :   CubitVector normal(plane_normal_x, plane_normal_y, plane_normal_z);
    6408 [ +  - ][ -  + ]:          1 :   if (normal.length_squared() == 0.0) {
    6409         [ #  # ]:          0 :     ERROR(iBase_INVALID_ARGUMENT, "Zero-length vector input.");
    6410                 :            :   }
    6411                 :            :   
    6412 [ +  - ][ +  - ]:          1 :   CubitVector point1 = normal * CubitVector(1.0, 0.0, 0.0);
    6413 [ +  - ][ +  - ]:          1 :   if (point1.length_squared() == 0.0)
    6414 [ +  - ][ +  - ]:          1 :     point1 = normal * CubitVector(0.0, 1.0, 0.0);
                 [ +  - ]
    6415                 :            :     
    6416         [ +  - ]:          1 :   CubitVector point2 = normal * point1;
    6417         [ +  - ]:          1 :   CubitVector point3(0.0, 0.0, 0.0);
    6418                 :            : 
    6419         [ +  - ]:          1 :   if (0.0 != offset) {
    6420         [ +  - ]:          1 :     normal.normalize();
    6421         [ +  - ]:          1 :     normal *= offset;
    6422         [ +  - ]:          1 :     point1 += normal;
    6423         [ +  - ]:          1 :     point2 += normal;
    6424         [ +  - ]:          1 :     point3 += normal;
    6425                 :            :   }
    6426                 :            : 
    6427                 :            :   
    6428 [ +  - ][ +  - ]:          2 :   DLIList<Body*> blank_list, new_body_list;
                 [ +  - ]
    6429 [ +  - ][ +  - ]:          1 :   blank_list.append(gmt->copy_body(this_body));
                 [ +  - ]
    6430                 :            :   CubitStatus result = gmt->section(blank_list, point1, point2, point3,
    6431                 :            :                                     new_body_list, !reverse,
    6432 [ +  - ][ +  - ]:          1 :                                     false);
    6433 [ +  - ][ +  - ]:          1 :   if (CUBIT_SUCCESS != result || 0 == new_body_list.size()) {
         [ -  + ][ -  + ]
    6434 [ #  # ][ #  # ]:          0 :     gqt->delete_RefEntity(blank_list.get());
         [ #  # ][ #  # ]
    6435         [ #  # ]:          0 :     ERROR(iBase_FAILURE, "Section failed.");
    6436                 :            :   }
    6437                 :            :     
    6438                 :            :   else {
    6439                 :            :       // need to assign it to a RE* first so the void cast gets done right
    6440 [ +  - ][ +  - ]:          1 :     RefEntity *new_body = new_body_list.get();
    6441                 :          1 :     *geom_entity2 = reinterpret_cast<iBase_EntityHandle>(new_body);
    6442                 :            :       // also, delete the original body, now that the section worked
    6443 [ +  - ][ +  - ]:          1 :     gqt->delete_RefEntity(this_body);
                 [ +  - ]
    6444                 :            :   }
    6445                 :            : 
    6446 [ +  - ][ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    6447                 :            : }
    6448                 :            : 
    6449                 :            : ITAPS_API void
    6450                 :          1 : iGeom_imprintEnts( iGeom_Instance instance,
    6451                 :            :                    /*in*/ iBase_EntityHandle const* gentity_handles,
    6452                 :            :                    int gentity_handles_size,
    6453                 :            :                    int* err )
    6454                 :            : {
    6455         [ -  + ]:          1 :   if (gentity_handles_size < 1) // GMT::imprint segfaults if passed an empty list
    6456         [ #  # ]:          0 :     RETURN(iBase_SUCCESS);
    6457                 :            : 
    6458         [ +  - ]:          1 :   DLIList<Body*> bods;
    6459 [ +  - ][ +  - ]:          2 :   DLIList<RefVolume*> vols, temp_vols;
         [ +  - ][ +  - ]
    6460                 :          1 :   RefEntity* const* handle_array = ENTITY_HANDLE_CONST_ARRAY(gentity_handles);
    6461                 :          1 :   CubitStatus status = CUBIT_SUCCESS;
    6462         [ +  + ]:          4 :   for (int i = 0; i < gentity_handles_size; i++) {
    6463         [ -  + ]:          3 :     Body *temp_bod = dynamic_cast<Body*>(handle_array[i]);
    6464         [ +  - ]:          3 :     if (NULL != temp_bod) {
    6465         [ +  - ]:          3 :       bods.append_unique(temp_bod);
    6466                 :          3 :       continue;
    6467                 :            :     }
    6468                 :            :     
    6469         [ #  # ]:          0 :     RefVolume *temp_vol = dynamic_cast<RefVolume*>(handle_array[i]);
    6470         [ #  # ]:          0 :     if (NULL != temp_vol) {
    6471         [ #  # ]:          0 :       TopologyEntity *topo_ent = dynamic_cast<TopologyEntity*>(handle_array[i]);
    6472         [ #  # ]:          0 :       if (NULL == topo_ent) {
    6473                 :          0 :         status = CUBIT_FAILURE;
    6474                 :          0 :         continue;
    6475                 :            :       }
    6476         [ #  # ]:          0 :       temp_bod = topo_ent->body();
    6477         [ #  # ]:          0 :       if (NULL == temp_bod) {
    6478                 :          0 :         status = CUBIT_FAILURE;
    6479                 :          0 :         continue;
    6480                 :            :       }
    6481         [ #  # ]:          0 :       bods.append_unique(temp_bod);
    6482                 :          0 :       continue;
    6483                 :            :     }
    6484                 :            : 
    6485                 :            :       // if we've gotten here, it's an error
    6486                 :          0 :     status = CUBIT_FAILURE;
    6487                 :            :   }
    6488                 :            :   
    6489 [ -  + ][ #  # ]:          1 :   if (CUBIT_SUCCESS != status) RETURN(iBase_FAILURE);
    6490                 :            : 
    6491 [ +  - ][ +  - ]:          2 :   DLIList<Body*> temp_bods;
    6492 [ +  - ][ +  - ]:          1 :   status = GeometryModifyTool::instance()->imprint(bods, temp_bods, false);
    6493                 :            :   
    6494 [ +  - ][ +  - ]:          2 :   RETURN(iBase_SUCCESS);
    6495                 :            : }
    6496                 :            :   
    6497                 :            : ITAPS_API void
    6498                 :          1 : iGeom_mergeEnts( iGeom_Instance instance,
    6499                 :            :                  /*in*/ iBase_EntityHandle const* gentity_handles,
    6500                 :            :                  int gentity_handles_size,
    6501                 :            :                  double tolerance,
    6502                 :            :                  int* err )
    6503                 :            : {
    6504 [ +  - ][ +  - ]:          1 :   double old_factor = GeometryQueryTool::instance()->get_geometry_factor();
    6505         [ +  - ]:          1 :   if (tolerance != old_factor) 
    6506 [ +  - ][ +  - ]:          1 :     GeometryQueryTool::instance()->set_geometry_factor(tolerance*1.0e6);
    6507                 :          0 :   else old_factor = 0.0;
    6508                 :            :   
    6509         [ +  - ]:          1 :   DLIList<Body*> bods;
    6510 [ +  - ][ +  - ]:          2 :   DLIList<RefVolume*> vols, temp_vols;
         [ +  - ][ +  - ]
    6511 [ +  - ][ +  - ]:          2 :   DLIList<RefFace*> faces;
    6512 [ +  - ][ +  - ]:          2 :   DLIList<RefEdge*> edges;
    6513 [ +  - ][ +  - ]:          2 :   DLIList<RefVertex*> verts;
    6514                 :          1 :   RefEntity* const* handle_array = ENTITY_HANDLE_CONST_ARRAY(gentity_handles);
    6515         [ +  + ]:          4 :   for (int i = 0; i < gentity_handles_size; i++) {
    6516         [ -  + ]:          3 :     TopologyEntity *topo_ent = dynamic_cast<TopologyEntity*>(handle_array[i]);
    6517         [ -  + ]:          3 :     if (NULL == topo_ent) continue;
    6518                 :            :     Body *temp_bod;
    6519                 :            :     RefVolume *temp_vol;
    6520                 :            :     RefFace *temp_face;
    6521                 :            :     RefEdge *temp_edge;
    6522                 :            :     RefVertex *temp_vert;
    6523 [ +  - ][ +  -  :          3 :     switch (handle_array[i]->dimension()) {
             -  -  -  - ]
    6524                 :            :       case -1:
    6525                 :            :           // it should be a body
    6526         [ -  + ]:          3 :         temp_bod = dynamic_cast<Body*>(handle_array[i]);
    6527 [ -  + ][ #  # ]:          3 :         if (NULL == temp_bod) RETURN(iBase_FAILURE);
    6528         [ +  - ]:          3 :         temp_vols.clean_out();
    6529         [ +  - ]:          3 :         topo_ent->ref_volumes(temp_vols);
    6530         [ +  - ]:          3 :         vols += temp_vols;
    6531                 :          3 :         break;
    6532                 :            :       case 0:
    6533         [ #  # ]:          0 :         temp_vert = dynamic_cast<RefVertex*>(handle_array[i]);
    6534 [ #  # ][ #  # ]:          0 :         if (NULL == temp_vert) RETURN(iBase_FAILURE);
    6535         [ #  # ]:          0 :         verts.append(temp_vert);
    6536                 :          0 :         break;
    6537                 :            :       case 1:
    6538         [ #  # ]:          0 :         temp_edge = dynamic_cast<RefEdge*>(handle_array[i]);
    6539 [ #  # ][ #  # ]:          0 :         if (NULL == temp_edge) RETURN(iBase_FAILURE);
    6540         [ #  # ]:          0 :         edges.append(temp_edge);
    6541                 :          0 :         break;
    6542                 :            :       case 2:
    6543         [ #  # ]:          0 :         temp_face = dynamic_cast<RefFace*>(handle_array[i]);
    6544 [ #  # ][ #  # ]:          0 :         if (NULL == temp_face) RETURN(iBase_FAILURE);
    6545         [ #  # ]:          0 :         faces.append(temp_face);
    6546                 :          0 :         break;
    6547                 :            :       case 3:
    6548         [ #  # ]:          0 :         temp_vol = dynamic_cast<RefVolume*>(handle_array[i]);
    6549 [ #  # ][ #  # ]:          0 :         if (NULL == temp_vol) RETURN(iBase_FAILURE);
    6550         [ #  # ]:          0 :         vols.append(temp_vol);
    6551                 :          3 :         break;
    6552                 :            :     }
    6553                 :            :   }
    6554                 :            :   
    6555                 :          1 :   CubitStatus status = CUBIT_SUCCESS, temp_status;
    6556                 :            :     
    6557 [ +  - ][ -  + ]:          1 :   if (verts.size() != 0) {
    6558 [ #  # ][ #  # ]:          0 :     temp_status = MergeTool::instance()->merge_refvertices(verts, false);
    6559         [ #  # ]:          0 :     if (CUBIT_SUCCESS != temp_status) status = temp_status;
    6560                 :            :   }
    6561                 :            :     
    6562 [ +  - ][ -  + ]:          1 :   if (edges.size() != 0) {
    6563 [ #  # ][ #  # ]:          0 :     temp_status = MergeTool::instance()->merge_refedges(edges, true, false);
    6564         [ #  # ]:          0 :     if (CUBIT_SUCCESS != temp_status) status = temp_status;
    6565                 :            :   }
    6566                 :            :     
    6567 [ +  - ][ -  + ]:          1 :   if (faces.size() != 0) {
    6568 [ #  # ][ #  # ]:          0 :     temp_status = MergeTool::instance()->merge_reffaces(faces, false);
    6569         [ #  # ]:          0 :     if (CUBIT_SUCCESS != temp_status) status = temp_status;
    6570                 :            :   }
    6571                 :            :     
    6572 [ +  - ][ +  - ]:          1 :   if (vols.size() != 0) {
    6573 [ +  - ][ +  - ]:          1 :     temp_status = MergeTool::instance()->merge_volumes(vols, false);
    6574         [ -  + ]:          1 :     if (CUBIT_SUCCESS != temp_status) status = temp_status;
    6575                 :            :   }
    6576                 :            :     
    6577 [ +  - ][ -  + ]:          1 :   if (bods.size() != 0) {
    6578 [ #  # ][ #  # ]:          0 :     temp_status = MergeTool::instance()->merge_bodies(bods);
    6579         [ #  # ]:          0 :     if (CUBIT_SUCCESS != temp_status) status = temp_status;
    6580                 :            :   }
    6581                 :            : 
    6582         [ +  - ]:          1 :   if (0 != old_factor)
    6583 [ +  - ][ +  - ]:          1 :     GeometryQueryTool::instance()->set_geometry_factor(old_factor);
    6584                 :            :     
    6585         [ -  + ]:          1 :   if (CUBIT_SUCCESS != status) {
    6586         [ #  # ]:          0 :     RETURN(iBase_FAILURE);
    6587                 :            :   }
    6588                 :            :   
    6589                 :            :   else {
    6590         [ +  - ]:          1 :     RETURN(iBase_SUCCESS);
    6591         [ +  - ]:          1 :   }
    6592                 :            : }
    6593                 :            : 
    6594                 :            : ITAPS_API void
    6595                 :          0 : iGeom_isPositionOn( iGeom_Instance instance,
    6596                 :            :                     iBase_EntityHandle entity,
    6597                 :            :                     double x,
    6598                 :            :                     double y,
    6599                 :            :                     double z,
    6600                 :            :                     int* IsOn )
    6601                 :            : {
    6602         [ #  # ]:          0 :   CubitVector position(x,y,z);
    6603         [ #  # ]:          0 :   RefVertex* ref_v = dynamic_cast<RefVertex*>(ENTITY_HANDLE(entity));
    6604         [ #  # ]:          0 :   if(ref_v)
    6605                 :            :   {
    6606         [ #  # ]:          0 :     CubitVector v_loc = ref_v->coordinates();
    6607         [ #  # ]:          0 :     CubitBoolean test = v_loc.about_equal(position);
    6608         [ #  # ]:          0 :     if (test == CUBIT_TRUE)
    6609                 :          0 :       *IsOn = 1;
    6610                 :            :     else
    6611                 :          0 :       *IsOn = 0;
    6612                 :          0 :     return;
    6613                 :            :   }
    6614                 :            : 
    6615                 :          0 :   CubitPointContainment pc = CUBIT_PNT_UNKNOWN;
    6616         [ #  # ]:          0 :   RefFace *ref_face = dynamic_cast<RefFace*>(ENTITY_HANDLE(entity));
    6617         [ #  # ]:          0 :   if(ref_face)
    6618         [ #  # ]:          0 :     pc = ref_face->point_containment(position);
    6619                 :            : 
    6620         [ #  # ]:          0 :   RefEdge *ref_edge = dynamic_cast<RefEdge*>(ENTITY_HANDLE(entity));
    6621         [ #  # ]:          0 :   if(ref_edge)
    6622         [ #  # ]:          0 :     pc = ref_edge->point_containment(position);
    6623                 :            : 
    6624         [ #  # ]:          0 :   Body *body = dynamic_cast<Body*>(ENTITY_HANDLE(entity));
    6625         [ #  # ]:          0 :   if(body)
    6626         [ #  # ]:          0 :     pc = body->point_containment(position);
    6627                 :            : 
    6628 [ #  # ][ #  # ]:          0 :   if (pc == CUBIT_PNT_INSIDE || pc == CUBIT_PNT_BOUNDARY)
    6629                 :          0 :     *IsOn = 1;
    6630                 :            : 
    6631                 :            :   else
    6632                 :          0 :     *IsOn = 0;
    6633                 :          0 :   return;
    6634                 :            : }
    6635                 :            : 
    6636                 :            : } // extern "C"
    6637                 :            : 
    6638                 :            : /********************* HELPER FUNCTION IMPLEMENTATIONS ***************************/
    6639                 :            : 
    6640                 :          9 : static void tokenize( const std::string& str, 
    6641                 :            :                       std::vector<std::string>& tokens )
    6642                 :            : {
    6643                 :          9 :   char delim =  str[0];
    6644                 :          9 :   std::string::size_type last = str.find_first_not_of( delim, 1 );
    6645                 :          9 :   std::string::size_type pos  = str.find_first_of( delim, last );
    6646 [ -  + ][ #  # ]:          9 :   while (std::string::npos != pos && std::string::npos != last) {
    6647         [ #  # ]:          0 :     tokens.push_back( str.substr( last, pos - last ) );
    6648                 :          0 :     last = str.find_first_not_of( delim, pos );
    6649                 :          0 :     pos  = str.find_first_of( delim, last ); 
    6650                 :            :   }
    6651                 :          9 : }
    6652                 :            : 
    6653                 :            : // Expect option of the form "NAME=VALUE".
    6654                 :            : // If NAME portion matches, pass back VALUE and return true.
    6655                 :            : // Otherwise, leave 'value' unchanged and return false.
    6656                 :          0 : static bool match_option( const std::string& opt,
    6657                 :            :                           const char* name,
    6658                 :            :                           std::string& value )
    6659                 :            : {
    6660                 :          0 :   std::string::size_type len = strlen( name );
    6661         [ #  # ]:          0 :   if (opt[len] != '=')
    6662                 :          0 :     return false;
    6663         [ #  # ]:          0 :   if (opt.compare( 0, len, name, len ))
    6664                 :          0 :     return false;
    6665         [ #  # ]:          0 :   value = opt.substr( len + 1 );
    6666                 :          0 :   return true;
    6667                 :            : }
    6668                 :            : 
    6669                 :            : 
    6670                 :            : static void
    6671                 :       1899 : iGeom_get_adjacent_entities( const RefEntity *from, 
    6672                 :            :                              const int to_dim,
    6673                 :            :                              DLIList<RefEntity*> &adj_ents,
    6674                 :            :                              int* err ) 
    6675                 :            : {
    6676         [ -  + ]:       1899 :   TopologyEntity *topo_ent = const_cast<TopologyEntity*>(dynamic_cast<const TopologyEntity*>(from));
    6677         [ -  + ]:       1899 :   if (NULL == topo_ent) {
    6678                 :          0 :     ERROR(iBase_INVALID_ARGUMENT, "Bad entity input.");
    6679                 :            :   }
    6680                 :            :   
    6681                 :       1899 :   adj_ents.clean_out();
    6682 [ +  + ][ +  - ]:       1899 :   static DLIList<RefVertex*> tmp_verts;
         [ +  - ][ #  # ]
    6683 [ +  + ][ +  - ]:       1899 :   static DLIList<RefEdge*> tmp_edges;
         [ +  - ][ #  # ]
    6684 [ +  + ][ +  - ]:       1899 :   static DLIList<RefFace*> tmp_faces;
         [ +  - ][ #  # ]
    6685 [ +  + ][ +  - ]:       1899 :   static DLIList<Body*> tmp_bodies;
         [ +  - ][ #  # ]
    6686                 :            :   
    6687   [ +  +  +  +  :       1899 :   switch (to_dim) {
                      - ]
    6688                 :            :     case 0:
    6689                 :        223 :       tmp_verts.clean_out();
    6690                 :        223 :       topo_ent->ref_vertices(tmp_verts);
    6691 [ +  - ][ +  - ]:        950 :       CAST_LIST_TO_PARENT(tmp_verts, adj_ents);
                 [ +  + ]
    6692                 :        223 :       break;
    6693                 :            :     case 1:
    6694                 :        382 :       tmp_edges.clean_out();
    6695                 :        382 :       topo_ent->ref_edges(tmp_edges);
    6696 [ +  - ][ +  - ]:       2215 :       CAST_LIST_TO_PARENT(tmp_edges, adj_ents);
                 [ +  + ]
    6697                 :        382 :       break;
    6698                 :            :     case 2:
    6699                 :        973 :       tmp_faces.clean_out();
    6700                 :        973 :       topo_ent->ref_faces(tmp_faces);
    6701 [ +  - ][ +  - ]:       3373 :       CAST_LIST_TO_PARENT(tmp_faces, adj_ents);
                 [ +  + ]
    6702                 :        973 :       break;
    6703                 :            :     case 3:
    6704                 :        321 :       tmp_bodies.clean_out();
    6705                 :        321 :       topo_ent->bodies(tmp_bodies);
    6706 [ +  - ][ +  - ]:        642 :       CAST_LIST_TO_PARENT(tmp_bodies, adj_ents);
                 [ +  + ]
    6707                 :        321 :       break;
    6708                 :            :     default:
    6709                 :          0 :       ERROR(iBase_INVALID_ARGUMENT, "Bad input dimension getting adjacent entities.");
    6710                 :            :   }
    6711                 :            :   
    6712                 :       1899 :   RETURN(iBase_SUCCESS);
    6713                 :            : }
    6714                 :            : 
    6715                 :            : /* Common implementation for both single-entity and array functions. */
    6716                 :          0 : static CubitStatus iGeom_closest_point( RefEntity* this_entity,
    6717                 :            :                                         const CubitVector& near,
    6718                 :            :                                         CubitVector& on )
    6719                 :            : {
    6720                 :            :   RefEdge *this_edge;
    6721                 :            :   RefFace *this_face;
    6722                 :            :   Surface *this_surf;
    6723                 :            :   CubitStatus status;
    6724                 :            :  
    6725   [ #  #  #  # ]:          0 :   switch (this_entity->dimension()) {
    6726                 :            :     case 0:
    6727 [ #  # ][ #  # ]:          0 :       on = dynamic_cast<RefVertex*>(this_entity)->coordinates();
    6728                 :          0 :       status = CUBIT_SUCCESS;
    6729                 :          0 :       break;
    6730                 :            :     case 1:
    6731         [ #  # ]:          0 :       this_edge = dynamic_cast<RefEdge*>(this_entity);
    6732         [ #  # ]:          0 :       if (NULL == this_edge) return CUBIT_FAILURE;
    6733                 :            : 
    6734                 :          0 :       status = this_edge->closest_point(near, on);
    6735                 :            : 
    6736                 :            :       if (debug) {
    6737                 :            :         std::cout << "Edge " << this_edge->id() << " closest point to (" 
    6738                 :            :                   << near.x() << ", " << near.y() << ", " << near.z() 
    6739                 :            :                   << ") is "
    6740                 :            :                   << on.x() << ", " << on.y() << ", " << on.z() 
    6741                 :            :                   << ")" << std::endl;
    6742                 :            :       }
    6743                 :          0 :       break;
    6744                 :            :     case 2:
    6745         [ #  # ]:          0 :       this_face = dynamic_cast<RefFace*>(this_entity);
    6746         [ #  # ]:          0 :       if (NULL == this_face) return CUBIT_FAILURE;
    6747                 :          0 :       this_surf = this_face->get_surface_ptr();
    6748         [ #  # ]:          0 :       if (NULL == this_surf) return CUBIT_FAILURE;
    6749                 :          0 :       status = this_surf->closest_point( near, &on );
    6750                 :          0 :       break;
    6751                 :            :     default:
    6752                 :            :         // just copy over the coordinates
    6753                 :          0 :       on = near;
    6754                 :          0 :       status = CUBIT_SUCCESS;
    6755                 :          0 :       break;
    6756                 :            :   }
    6757                 :            :   
    6758                 :          0 :   return status;
    6759                 :            : }
    6760                 :            : 
    6761                 :          0 : static CubitStatus iGeom_closest_point_trimmed( RefEntity* this_entity,
    6762                 :            :                                                 const CubitVector& near,
    6763                 :            :                                                 CubitVector& on )
    6764                 :            : {
    6765                 :            :   RefEdge *this_edge;
    6766                 :            :   RefFace *this_face;
    6767                 :            :   Surface *this_surf;
    6768                 :            :   CubitStatus status;
    6769                 :            : 
    6770   [ #  #  #  # ]:          0 :   switch (this_entity->dimension()) {
    6771                 :            :     case 0:
    6772 [ #  # ][ #  # ]:          0 :       on = dynamic_cast<RefVertex*>(this_entity)->coordinates();
    6773                 :          0 :       status = CUBIT_SUCCESS;
    6774                 :          0 :       break;
    6775                 :            :     case 1:
    6776         [ #  # ]:          0 :       this_edge = dynamic_cast<RefEdge*>(this_entity);
    6777         [ #  # ]:          0 :       if (NULL == this_edge) return CUBIT_FAILURE;
    6778                 :            : 
    6779                 :          0 :       status = this_edge->closest_point(near, on);
    6780                 :            : 
    6781                 :            :       if (debug) {
    6782                 :            :         std::cout << "Edge " << this_edge->id() << " closest point to ("
    6783                 :            :                   << near.x() << ", " << near.y() << ", " << near.z()
    6784                 :            :                   << ") is "
    6785                 :            :                   << on.x() << ", " << on.y() << ", " << on.z()
    6786                 :            :                   << ")" << std::endl;
    6787                 :            :       }
    6788                 :          0 :       break;
    6789                 :            :     case 2:
    6790         [ #  # ]:          0 :       this_face = dynamic_cast<RefFace*>(this_entity);
    6791         [ #  # ]:          0 :       if (NULL == this_face) return CUBIT_FAILURE;
    6792                 :          0 :       this_surf = this_face->get_surface_ptr();
    6793         [ #  # ]:          0 :       if (NULL == this_surf) return CUBIT_FAILURE;
    6794         [ #  # ]:          0 :       this_surf->closest_point_trimmed( near, on );
    6795                 :          0 :       status = CUBIT_SUCCESS;
    6796                 :          0 :       break;
    6797                 :            :     default:
    6798                 :            :         // just copy over the coordinates
    6799                 :          0 :       on = near;
    6800                 :          0 :       status = CUBIT_SUCCESS;
    6801                 :          0 :       break;
    6802                 :            :   }
    6803                 :            : 
    6804                 :          0 :   return status;
    6805                 :            : }
    6806                 :            : 
    6807                 :            : static CubitStatus
    6808                 :          6 : iGeom_closest_point_and_normal( RefEntity* this_entity, 
    6809                 :            :                                 const CubitVector& near,
    6810                 :            :                                 CubitVector& on,
    6811                 :            :                                 CubitVector& normal )
    6812                 :            : {
    6813                 :            :   RefEdge* this_edge;
    6814                 :            :   RefFace* this_face;
    6815                 :            :   Surface* this_surf;
    6816                 :            :   CubitStatus status;
    6817   [ -  -  +  - ]:          6 :   switch (this_entity->dimension()) {
    6818                 :            :     case 0:
    6819 [ #  # ][ #  # ]:          0 :       on = dynamic_cast<RefVertex*>(this_entity)->coordinates();
    6820                 :          0 :       normal.set( 0, 0, 0 );
    6821                 :          0 :       status = CUBIT_SUCCESS;
    6822                 :          0 :       break;
    6823                 :            :     case 1:
    6824         [ #  # ]:          0 :       this_edge = dynamic_cast<RefEdge*>(this_entity);
    6825         [ #  # ]:          0 :       if (NULL == this_edge) return CUBIT_FAILURE;
    6826                 :            :       
    6827                 :          0 :       status = this_edge->closest_point( near, on );
    6828                 :            :       if (debug) {
    6829                 :            :         std::cout << "Edge " << this_edge->id() << " closest point to (" 
    6830                 :            :                   << near.x() << ", " << near.y() << ", " << near.z() 
    6831                 :            :                   << ") is "
    6832                 :            :                   << on.x() << ", " << on.y() << ", " << on.x()
    6833                 :            :                   << ")" << std::endl;
    6834                 :            :       }
    6835                 :          0 :       break;
    6836                 :            :     case 2:
    6837         [ -  + ]:          6 :       this_face = dynamic_cast<RefFace*>(this_entity);
    6838         [ -  + ]:          6 :       if (NULL == this_face) return CUBIT_FAILURE;
    6839                 :          6 :       this_surf = this_face->get_surface_ptr();
    6840         [ -  + ]:          6 :       if (NULL == this_surf) return CUBIT_FAILURE;
    6841                 :          6 :       status = this_surf->closest_point( near, &on, &normal );
    6842         [ -  + ]:          6 :       if (this_surf->bridge_sense() == CUBIT_REVERSED)
    6843         [ #  # ]:          0 :         normal = -normal;
    6844                 :          6 :       break;
    6845                 :            :     default:
    6846                 :            :         // just copy over the coordinates
    6847                 :          0 :       on = near;
    6848                 :          0 :       normal.set( 0, 0, 0 );
    6849                 :          0 :       status = CUBIT_SUCCESS;
    6850                 :          0 :       break;
    6851                 :            :   }
    6852                 :            :   
    6853                 :          6 :   return status;
    6854                 :            : }
    6855                 :            : 
    6856                 :            : static CubitStatus
    6857                 :         10 : iGeom_bounding_box( RefEntity* entity, CubitVector& minc, CubitVector& maxc )
    6858                 :            : {
    6859         [ +  - ]:         10 :   CubitBox box;
    6860 [ -  + ][ +  + ]:         10 :   if (BasicTopologyEntity* bte = dynamic_cast<BasicTopologyEntity*>(entity))
    6861 [ +  - ][ +  - ]:          3 :     box = bte->bounding_box();
                 [ +  - ]
    6862 [ -  + ][ +  - ]:          7 :   else if(Body* body = dynamic_cast<Body*>(entity))
    6863 [ +  - ][ +  - ]:          7 :     box = body->bounding_box();
                 [ +  - ]
    6864                 :            :   else {
    6865         [ #  # ]:          0 :     CGM_iGeom_setLastError(iBase_INVALID_ENTITY_HANDLE, "Entities passed into gentityBoundingBox must be vertex, edge, face, or region."); 
    6866                 :          0 :     return CUBIT_FAILURE;
    6867                 :            :   }
    6868                 :            :   
    6869 [ +  - ][ +  - ]:         10 :   minc = box.minimum();
    6870 [ +  - ][ +  - ]:         10 :   maxc = box.maximum();
    6871         [ +  - ]:         10 :   return CUBIT_SUCCESS;
    6872                 :            : }
    6873                 :            : 
    6874                 :            : /** We could use Smits' algorithm here, but only if we turned of
    6875                 :            :     floating-point exceptions */
    6876                 :            : /*
    6877                 :            : static inline void box_min_max( double dir,
    6878                 :            :                                 double min,
    6879                 :            :                                 double max,
    6880                 :            :                                 double pt,
    6881                 :            :                                 double& tmin,
    6882                 :            :                                 double& tmax )
    6883                 :            : {
    6884                 :            :   if (dir == 0) {
    6885                 :            :     tmin = std::numeric_limits<double>::min();
    6886                 :            :     tmax = std::numeric_limits<double>::max();
    6887                 :            :   }
    6888                 :            :   else if (dir > 0.0) {
    6889                 :            :     tmin = (min - pt) / dir;
    6890                 :            :     tmax = (max - pt) / dir;
    6891                 :            :   }
    6892                 :            :   else {
    6893                 :            :     tmin = (max - pt) / dir;
    6894                 :            :     tmax = (min - pt) / dir;
    6895                 :            :   }
    6896                 :            : }
    6897                 :            : */
    6898                 :            : 
    6899                 :            : /*
    6900                 :            : static bool
    6901                 :            : iBase_intersect_ray_box( const CubitBox& box,
    6902                 :            :                          const CubitVector& point,
    6903                 :            :                          const CubitVector& direction )
    6904                 :            : {
    6905                 :            :   double txmin, txmax, tymin, tymax, tzmin, tzmax;
    6906                 :            :   box_min_max( direction.x(), box.minimum().x(), box.maximum().x(), point.x(), txmin, txmax );
    6907                 :            :   box_min_max( direction.y(), box.minimum().y(), box.maximum().y(), point.y(), tymin, tymax );
    6908                 :            :   if (txmin > tymax || tymin > txmax)
    6909                 :            :     return false;
    6910                 :            :   
    6911                 :            :   if (tymin > txmin)
    6912                 :            :     txmin = tymin;
    6913                 :            :   if (tymax < txmax)
    6914                 :            :     txmax = tymax;
    6915                 :            :   
    6916                 :            :   box_min_max( direction.z(), box.minimum().z(), box.maximum().z(), point.z(), tzmin, tzmax );
    6917                 :            :   if (txmin > txmax || tzmin > txmax)
    6918                 :            :     return false;
    6919                 :            :   
    6920                 :            :   return true;
    6921                 :            : }
    6922                 :            : */
    6923                 :            : 
    6924                 :            : static CubitStatus
    6925                 :          0 : iGeom_fire_ray( const CubitVector& point,
    6926                 :            :                 const CubitVector& direction,
    6927                 :            :                 DLIList<RefEntity*>& entities,
    6928                 :            :                 DLIList<double>& ray_params )
    6929                 :            : {
    6930                 :          0 :   const double EPSILON = 0.0;
    6931                 :            :   CubitStatus s;
    6932 [ #  # ][ #  # ]:          0 :   CubitVector nc_point(point), nc_direction(direction);
    6933                 :            :   
    6934                 :            :     // get all free entities in model
    6935         [ #  # ]:          0 :   DLIList<RefEntity*> target_entities;
    6936 [ #  # ][ #  # ]:          0 :   s = GeometryQueryTool::instance()->get_free_ref_entities( target_entities );
    6937         [ #  # ]:          0 :   if (CUBIT_SUCCESS != s) return s;
    6938 [ #  # ][ #  # ]:          0 :   DLIList<Body*> bodies;
    6939 [ #  # ][ #  # ]:          0 :   GeometryQueryTool::instance()->bodies( bodies );
    6940 [ #  # ][ #  # ]:          0 :   CAST_LIST_TO_PARENT( bodies, target_entities );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    6941                 :            :     
    6942                 :            :     // do ray fire at list of free entities
    6943                 :            :   return GeometryQueryTool::instance()->
    6944 [ #  # ][ #  # ]:          0 :     fire_ray( nc_point, nc_direction, target_entities, ray_params, 0, EPSILON, &entities );
                 [ #  # ]
    6945                 :            : }
    6946                 :            : 
    6947                 :          0 : static RefEntity* point_classification( const CubitVector& pt, RefVertex* vtx )
    6948                 :            : {
    6949 [ #  # ][ #  # ]:          0 :   return (pt - vtx->coordinates()).length_squared() > GEOMETRY_RESABS*GEOMETRY_RESABS ? 0 : vtx;
         [ #  # ][ #  # ]
    6950                 :            : }
    6951                 :            : 
    6952                 :          0 : static RefEntity* point_classification( const CubitVector& pt, RefEdge* edge )
    6953                 :            : {
    6954         [ #  # ]:          0 :   CubitVector closest;
    6955         [ #  # ]:          0 :   edge->closest_point_trimmed( pt, closest );
    6956 [ #  # ][ #  # ]:          0 :   if ((pt - closest).length_squared() > GEOMETRY_RESABS*GEOMETRY_RESABS)
                 [ #  # ]
    6957                 :          0 :     return 0;
    6958                 :            :   
    6959 [ #  # ][ #  # ]:          0 :   if (RefEntity* vtx = point_classification( pt, edge->start_vertex() ))
                 [ #  # ]
    6960                 :          0 :     return vtx;
    6961 [ #  # ][ #  # ]:          0 :   else if (RefEntity* vtx = point_classification( pt, edge->end_vertex() ))
                 [ #  # ]
    6962                 :          0 :     return vtx;
    6963                 :            :   else
    6964         [ #  # ]:          0 :     return edge;
    6965                 :            : }
    6966                 :            : 
    6967                 :          0 : static RefEntity* point_classification( const CubitVector& pt, RefFace* face )
    6968                 :            : {
    6969         [ #  # ]:          0 :   CubitBox extents = face->bounding_box();
    6970 [ #  # ][ #  # ]:          0 :   if (extents.distance_squared(pt) > GEOMETRY_RESABS*GEOMETRY_RESABS)
    6971                 :          0 :     return 0;
    6972                 :            :   
    6973         [ #  # ]:          0 :   CubitVector closest;
    6974 [ #  # ][ #  # ]:          0 :   face->find_closest_point_trimmed( pt, closest );
    6975 [ #  # ][ #  # ]:          0 :   if ((pt - closest).length_squared() > GEOMETRY_RESABS*GEOMETRY_RESABS)
                 [ #  # ]
    6976                 :          0 :     return 0;
    6977                 :            :   
    6978 [ #  # ][ #  # ]:          0 :   DLIList<RefEdge*> edges;
    6979         [ #  # ]:          0 :   face->ref_edges( edges );
    6980         [ #  # ]:          0 :   edges.last();
    6981 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < edges.size(); ++i)
    6982 [ #  # ][ #  # ]:          0 :     if (RefEntity* ent = point_classification( pt, edges.step_and_get() ))
                 [ #  # ]
    6983                 :          0 :       return ent;
    6984                 :            :   
    6985 [ #  # ][ #  # ]:          0 :   return face;
    6986                 :            : }
    6987                 :            : 
    6988                 :          0 : static RefEntity* point_classification( const CubitVector& pt, Body* body )
    6989                 :            : {
    6990         [ #  # ]:          0 :   CubitVector nonconst_pt(pt);
    6991         [ #  # ]:          0 :   CubitPointContainment pc = body->point_containment( nonconst_pt );
    6992         [ #  # ]:          0 :   if (CUBIT_PNT_INSIDE == pc) 
    6993         [ #  # ]:          0 :     return body;
    6994         [ #  # ]:          0 :   else if (CUBIT_PNT_BOUNDARY != pc)
    6995                 :          0 :     return 0;
    6996                 :            :   
    6997                 :            :     // If we're here, then we're on the boundary.  
    6998                 :            :     // Find which boundary entity we're on.
    6999         [ #  # ]:          0 :   DLIList<RefFace*> faces;
    7000         [ #  # ]:          0 :   body->ref_faces( faces );
    7001         [ #  # ]:          0 :   faces.last();
    7002 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < faces.size(); ++i)
    7003 [ #  # ][ #  # ]:          0 :     if (RefEntity* ent = point_classification( pt, faces.step_and_get() ))
                 [ #  # ]
    7004                 :          0 :       return ent;
    7005                 :            :   
    7006                 :            :     // We don't appear to be on any face.  Is the tolerance for
    7007                 :            :     // Body::point_classification something other than GEOMETRY_RESABS??
    7008 [ #  # ][ #  # ]:          0 :   return body;
    7009                 :            : }
    7010                 :            : 
    7011                 :            : 
    7012                 :            : 
    7013                 :            : static RefEntity*
    7014                 :          0 : iGeom_get_point_containment( const CubitVector& pt )
    7015                 :            : {
    7016         [ #  # ]:          0 :   DLIList<RefEntity*> ents;
    7017 [ #  # ][ #  # ]:          0 :   gqt->get_free_ref_entities( ents );
    7018                 :            :   
    7019         [ #  # ]:          0 :   ents.reset();
    7020 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < ents.size(); ++i)
    7021 [ #  # ][ #  # ]:          0 :     if (RefVertex* vtx = dynamic_cast<RefVertex*>(ents.get_and_step()))
                 [ #  # ]
    7022 [ #  # ][ #  # ]:          0 :       if (RefEntity* ent = point_classification( pt, vtx ))
    7023                 :          0 :         return ent;
    7024 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < ents.size(); ++i)
    7025 [ #  # ][ #  # ]:          0 :     if (RefEdge* edge = dynamic_cast<RefEdge*>(ents.get_and_step()))
                 [ #  # ]
    7026 [ #  # ][ #  # ]:          0 :       if (RefEntity* ent = point_classification( pt, edge ))
    7027                 :          0 :         return ent;
    7028 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < ents.size(); ++i)
    7029 [ #  # ][ #  # ]:          0 :     if (RefFace* face = dynamic_cast<RefFace*>(ents.get_and_step()))
                 [ #  # ]
    7030 [ #  # ][ #  # ]:          0 :       if (RefEntity* ent = point_classification( pt, face ))
    7031                 :          0 :         return ent;
    7032                 :            :         
    7033 [ #  # ][ #  # ]:          0 :   DLIList<Body*> bodies;
    7034 [ #  # ][ #  # ]:          0 :   gqt->bodies( bodies );
    7035         [ #  # ]:          0 :   bodies.reset();
    7036 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < bodies.size(); ++i)
    7037 [ #  # ][ #  # ]:          0 :    if (RefEntity* ent = point_classification( pt, bodies.get_and_step() ))
                 [ #  # ]
    7038                 :          0 :      return ent;
    7039                 :            :   
    7040         [ #  # ]:          0 :   return 0;
    7041                 :            : }
    7042                 :            : 
    7043                 :       1366 : static int iGeom_get_nonmanifold_sense( const BasicTopologyEntity* child,
    7044                 :            :                                         const BasicTopologyEntity* parent,
    7045                 :            :                                         int* err )
    7046                 :            : {
    7047         [ +  - ]:       1366 :   DLIList<SenseEntity*> se_list(1);
    7048                 :            :   const_cast<BasicTopologyEntity*>(child)
    7049         [ +  - ]:       1366 :     ->get_sense_entities( se_list, const_cast<BasicTopologyEntity*>(parent) );
    7050 [ +  - ][ -  + ]:       1366 :   if (se_list.size() == 0) {
    7051         [ #  # ]:          0 :     CGM_iGeom_setLastError((*err = iBase_INVALID_ENTITY_HANDLE), "Relative senes of unrelated entities"); 
    7052                 :          0 :     return 2;
    7053                 :            :   }
    7054         [ +  - ]:       1366 :   se_list.reset();
    7055 [ +  - ][ +  - ]:       1366 :   CubitSense sense = se_list.get_and_step()->get_sense();
    7056 [ +  - ][ -  + ]:       1366 :   for (int i = se_list.size() - 1; i > 0; --i)
    7057 [ #  # ][ #  # ]:          0 :     if (se_list.get_and_step()->get_sense() != sense) {
                 [ #  # ]
    7058                 :          0 :       *err = iBase_SUCCESS;
    7059                 :          0 :       return 0;
    7060                 :            :     }
    7061                 :       1366 :   *err = iBase_SUCCESS;
    7062 [ +  + ][ +  - ]:       1366 :   return sense == CUBIT_FORWARD ? 1 : -1;
    7063                 :            : }
    7064                 :            : 
    7065                 :            : static
    7066                 :          0 : int iGeom_edge_vertex_sense( const RefEdge* cedge,
    7067                 :            :                              const RefVertex* vtx1,
    7068                 :            :                              const RefVertex* vtx2,
    7069                 :            :                              int* err )
    7070                 :            : {
    7071                 :          0 :   RefEdge* edge = const_cast<RefEdge*>(cedge);
    7072 [ #  # ][ #  # ]:          0 :   if (edge->start_vertex() == vtx1 && edge->end_vertex() == vtx2) 
                 [ #  # ]
    7073                 :          0 :     return vtx1 == vtx2 ? 0 : 1;
    7074 [ #  # ][ #  # ]:          0 :   else if (edge->start_vertex() == vtx2 && edge->end_vertex() == vtx1)
                 [ #  # ]
    7075                 :          0 :     return -1;
    7076                 :          0 :   CGM_iGeom_setLastError((*err = iBase_INVALID_ENTITY_HANDLE), "Relative senes of unrelated entities"); 
    7077                 :          0 :   return 2;
    7078                 :            : }
    7079                 :            : 
    7080                 :          0 : static int iGeom_is_parametric( RefEntity* entity )
    7081                 :            : {
    7082 [ #  # ][ #  # ]:          0 :   if (RefFace* face = dynamic_cast<RefFace*>(entity))
    7083                 :          0 :     return face->is_parametric();
    7084 [ #  # ][ #  # ]:          0 :   else if (dynamic_cast<RefEdge*>(entity))
                 [ #  # ]
    7085                 :          0 :     return true;
    7086                 :            :   else
    7087                 :          0 :     return false;
    7088                 :            : }
    7089                 :            : 
    7090                 :            : static iBase_ErrorType
    7091                 :          0 : iGeom_get_vtx_to_u(RefVertex* vertex,
    7092                 :            :                    RefEdge* edge,
    7093                 :            :                    double& u)
    7094                 :            : {
    7095         [ #  # ]:          0 :   if (edge->start_vertex() == vertex)
    7096                 :          0 :     u = edge->start_param();
    7097         [ #  # ]:          0 :   else if (edge->end_vertex() == vertex)
    7098                 :          0 :     u = edge->end_param();
    7099                 :            :   else
    7100                 :          0 :     return iBase_INVALID_ARGUMENT;
    7101                 :          0 :   return iBase_SUCCESS;
    7102                 :            : }
    7103                 :            : 
    7104                 :            : static iBase_ErrorType
    7105                 :          0 : iGeom_get_vtx_to_uv(RefVertex* vertex, RefFace* face, double& u, double& v)
    7106                 :            : {
    7107         [ #  # ]:          0 :   DLIList<RefVertex*> pts;
    7108                 :          0 :   TopologyEntity *topo_ent = dynamic_cast<TopologyEntity*>(face);
    7109         [ #  # ]:          0 :   topo_ent->ref_vertices(pts);
    7110                 :            : 
    7111         [ #  # ]:          0 :   pts.reset();
    7112 [ #  # ][ #  # ]:          0 :   for(int i=0; i<pts.size(); i++) {
    7113 [ #  # ][ #  # ]:          0 :     if (pts.get_and_step() == vertex) {
    7114 [ #  # ][ #  # ]:          0 :       face->u_v_from_position( vertex->coordinates(), u, v );         
    7115                 :          0 :       return iBase_SUCCESS;
    7116                 :            :     }
    7117                 :            :   }
    7118         [ #  # ]:          0 :   return iBase_INVALID_ARGUMENT;
    7119                 :            : }
    7120                 :            : 
    7121                 :            : static CubitStatus
    7122                 :          0 : iGeom_normal_from_uv( RefFace* face, double u, double v, CubitVector& normal )
    7123                 :            : {
    7124                 :            :   
    7125         [ #  # ]:          0 :   CubitVector coords = face->position_from_u_v( u, v );
    7126         [ #  # ]:          0 :   Surface* surf_ptr = face->get_surface_ptr();
    7127         [ #  # ]:          0 :   CubitStatus rval = surf_ptr->closest_point_uv_guess( coords, u, v, 0, &normal );
    7128 [ #  # ][ #  # ]:          0 :   if (surf_ptr->bridge_sense() == CUBIT_REVERSED)
    7129 [ #  # ][ #  # ]:          0 :     normal = -normal;
    7130                 :          0 :   return rval;
    7131                 :            : }
    7132                 :            : 
    7133                 :            : static CubitStatus
    7134                 :          0 : iGeom_is_periodic( RefEntity* entity, int& u, int& v )
    7135                 :            : {
    7136 [ #  # ][ #  # ]:          0 :   if (RefEdge* edge = dynamic_cast<RefEdge*>(entity)) {
    7137                 :          0 :     u = edge->is_periodic();
    7138                 :          0 :     v = CUBIT_FALSE;
    7139                 :            :   }
    7140 [ #  # ][ #  # ]:          0 :   else if (RefFace* face = dynamic_cast<RefFace*>(entity)) {
    7141                 :            :     double period;
    7142         [ #  # ]:          0 :     u = face->is_periodic_in_U(period);
    7143         [ #  # ]:          0 :     v = face->is_periodic_in_V(period);
    7144                 :            :   }
    7145                 :            :   else {
    7146                 :          0 :     u = v = CUBIT_FALSE;
    7147                 :            :   }
    7148                 :            :   
    7149                 :          0 :   return CUBIT_SUCCESS;
    7150                 :            : }
    7151                 :            : 
    7152                 :            : static bool
    7153                 :          0 : iGeom_is_face_degenerate( RefFace* face )
    7154                 :            : {
    7155                 :          0 :   double param = 0;
    7156                 :          0 :   CubitBoolean b1 = face->is_singular_in_U(param);
    7157                 :          0 :   CubitBoolean b2 = face->is_singular_in_V(param);
    7158 [ #  # ][ #  # ]:          0 :   return b1 || b2;
    7159                 :            : }
    7160                 :            : 
    7161                 :            : static iBase_ErrorType 
    7162                 :          7 : process_attribs(iGeom_Instance instance, DLIList<RefEntity*> &ref_list) 
    7163                 :            : {
    7164                 :            :     // go through all entities, checking for remaining simple attribs
    7165         [ +  - ]:          7 :   DLIList<CubitSimpleAttrib> csa_list;
    7166                 :          7 :   iBase_ErrorType result = iBase_SUCCESS;
    7167                 :            : 
    7168 [ +  - ][ +  + ]:       1734 :   for (int i = ref_list.size(); i > 0; i--) {
    7169         [ +  - ]:       1727 :     csa_list.clean_out();
    7170                 :            : 
    7171                 :            :       // get all the csa's still on this entity
    7172         [ +  - ]:       1727 :     RefEntity *this_ent = ref_list.get_and_step();
    7173         [ -  + ]:       1727 :     TopologyEntity *topo_ent = dynamic_cast<TopologyEntity*>(this_ent);
    7174 [ +  - ][ +  - ]:       1727 :     topo_ent->bridge_manager()->topology_bridge()->get_simple_attribute(csa_list);
                 [ +  - ]
    7175                 :            : 
    7176 [ +  - ][ -  + ]:       1727 :     for (int j = csa_list.size(); j > 0; j--) {
    7177                 :            :         // see if there's a tag for this csa already
    7178 [ #  # ][ #  # ]:          0 :       CubitSimpleAttrib csa = csa_list.get_and_step();
    7179 [ #  # ][ #  # ]:          0 :       const char *tag_name = csa.character_type().c_str();
                 [ #  # ]
    7180         [ #  # ]:          0 :       long tag = TM->getTagHandle(tag_name);
    7181         [ #  # ]:          0 :       if (tag < 0) continue;
    7182         [ #  # ]:          0 :       else if (0 == tag) {
    7183                 :            :           // don't have a tag handle for this yet - make one
    7184         [ #  # ]:          0 :         result = TM->create_csa_tag(tag_name, &tag);
    7185 [ #  # ][ #  # ]:          0 :         if (iBase_SUCCESS != result || 0 == tag) return iBase_FAILURE;
    7186                 :            :       }
    7187                 :            :         
    7188                 :            :         // now set the tag
    7189         [ #  # ]:          0 :       iBase_ErrorType tmp_result = TM->set_csa_tag(this_ent, tag, &csa);
    7190 [ #  # ][ #  # ]:          0 :       if (iBase_SUCCESS != tmp_result) result = tmp_result;
              [ #  #  # ]
    7191                 :          0 :     }
    7192                 :            :   }
    7193                 :            : 
    7194         [ +  - ]:          7 :   return iBase_SUCCESS;
    7195                 :            : }
    7196                 :            : 
    7197                 :            : 
    7198                 :            : template <typename T> static inline 
    7199                 :         12 : int count_type( const DLIList<CubitEntity*>& list )
    7200                 :            : {
    7201                 :         12 :   int count = 0, size = list.size();
    7202 [ +  + ][ +  + ]:       1002 :   for (int i = 0; i < size; ++i)
         [ +  + ][ +  + ]
                 [ #  # ]
    7203 [ +  - ][ +  - ]:        990 :     if (dynamic_cast<T*>(list[i]))
         [ +  - ][ +  - ]
         [ +  + ][ +  + ]
         [ +  - ][ +  + ]
         [ +  + ][ +  - ]
         [ +  + ][ +  + ]
         [ #  # ][ #  # ]
                 [ #  # ]
    7204                 :        609 :       ++count;
    7205                 :         12 :   return count;
    7206                 :            : }
    7207                 :            : 
    7208                 :            : static inline
    7209                 :         12 : int count_ibase_type( int ibase_type, const DLIList<CubitEntity*>& list, int* err )
    7210                 :            : {
    7211                 :         12 :   *err = iBase_SUCCESS;
    7212   [ -  +  +  +  :         12 :   switch (ibase_type) {
                   +  - ]
    7213                 :          0 :     case iBase_ALL_TYPES: return list.size() - count_type<RefGroup>(list);
    7214                 :          3 :     case iBase_REGION:    return count_type<Body>(list);
    7215                 :          5 :     case iBase_FACE:      return count_type<RefFace>(list);
    7216                 :          3 :     case iBase_EDGE:      return count_type<RefEdge>(list);
    7217                 :          1 :     case iBase_VERTEX:    return count_type<RefVertex>(list);
    7218                 :            :     default:
    7219                 :          0 :       *err = iBase_INVALID_ENTITY_TYPE;
    7220                 :          0 :       CGM_iGeom_setLastError( *err );
    7221                 :          0 :       return -1;
    7222                 :            :   }
    7223                 :            : }
    7224                 :            : 
    7225                 :            : template <typename TARGET_TYPE, typename LIST_TYPE> static inline 
    7226                 :          0 : void append_type( const DLIList<CubitEntity*>& source_list,
    7227                 :            :                   DLIList<LIST_TYPE*>& target_list )
    7228                 :            : {
    7229                 :          0 :   int size = source_list.size();
    7230 [ #  # ][ #  # ]:          0 :   for (int i = 0; i < size; ++i) 
         [ #  # ][ #  # ]
    7231 [ #  # ][ #  # ]:          0 :     if (TARGET_TYPE* ent = dynamic_cast<TARGET_TYPE*>(source_list[i]))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    7232 [ #  # ][ #  # ]:          0 :       target_list.append(ent);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    7233                 :          0 : }
    7234                 :            : 
    7235                 :            : template <typename SKIP_TYPE, typename LIST_TYPE> static inline 
    7236                 :          0 : void append_not_type( const DLIList<CubitEntity*>& source_list,
    7237                 :            :                       DLIList<LIST_TYPE*>& target_list )
    7238                 :            : {
    7239                 :          0 :   int size = source_list.size();
    7240         [ #  # ]:          0 :   for (int i = 0; i < size; ++i) 
    7241 [ #  # ][ #  # ]:          0 :     if (!dynamic_cast<SKIP_TYPE*>(source_list[i]))
                 [ #  # ]
    7242 [ #  # ][ #  # ]:          0 :       if (RefEntity* ent = dynamic_cast<LIST_TYPE*>(source_list[i]))
                 [ #  # ]
    7243         [ #  # ]:          0 :         target_list.append(ent);
    7244                 :          0 : }
    7245                 :            : 
    7246                 :            : // Returns count of entities appended.
    7247                 :            : template <typename TARGET_TYPE> static inline 
    7248                 :          4 : int append_type( const DLIList<CubitEntity*>& source_list,
    7249                 :            :                  iBase_EntityHandle* array, int array_size )
    7250                 :            : {
    7251                 :            :   RefEntity* re_ptr;
    7252                 :          4 :   int len = source_list.size();
    7253                 :          4 :   int count = 0;
    7254 [ #  # ][ +  + ]:        290 :   for (int i = 0; i < len; ++i) {
         [ +  + ][ +  + ]
    7255 [ #  # ][ #  # ]:        286 :     if (TARGET_TYPE* ent = dynamic_cast<TARGET_TYPE*>(source_list[i])) {
         [ -  + ][ +  - ]
         [ -  + ][ +  - ]
         [ -  + ][ +  - ]
    7256 [ #  # ][ +  - ]:        286 :       if (count < array_size)
         [ +  - ][ +  - ]
    7257 [ #  # ][ +  - ]:        286 :         array[count] = reinterpret_cast<iBase_EntityHandle>(re_ptr = ent);
         [ +  - ][ +  - ]
    7258                 :        286 :       ++count;
    7259                 :            :     }
    7260                 :            :   }
    7261                 :          4 :   return count;
    7262                 :            : }
    7263                 :            : 
    7264                 :            : template <typename SKIP_TYPE> static inline 
    7265                 :          0 : int append_not_type( const DLIList<CubitEntity*>& source_list,
    7266                 :            :                      iBase_EntityHandle* array, int array_size )
    7267                 :            : {
    7268                 :          0 :   int len = source_list.size();
    7269                 :          0 :   int count = 0;
    7270         [ #  # ]:          0 :   for (int i = 0; i < len; ++i) {
    7271 [ #  # ][ #  # ]:          0 :     if (!dynamic_cast<SKIP_TYPE*>(source_list[i])) {
                 [ #  # ]
    7272         [ #  # ]:          0 :       if (count == array_size) 
    7273                 :          0 :         return -1;
    7274 [ #  # ][ #  # ]:          0 :       else if (RefEntity* ent = dynamic_cast<RefEntity*>(source_list[i]))
    7275                 :          0 :         array[count++] = reinterpret_cast<iBase_EntityHandle>(ent);
    7276                 :            :     }
    7277                 :            :   }
    7278                 :          0 :   return count;
    7279                 :            : }
    7280                 :            : 
    7281                 :            : static 
    7282                 :          4 : void copy_ibase_type( int ibase_type, 
    7283                 :            :                       const DLIList<CubitEntity*>& list,
    7284                 :            :                       iBase_EntityHandle** entity_handles,
    7285                 :            :                       int* entity_handles_alloc,
    7286                 :            :                       int* entity_handles_size,
    7287                 :            :                       int* err )
    7288                 :            : {
    7289                 :            :   int count;
    7290         [ +  - ]:          4 :   if (*entity_handles_alloc == 0) {
    7291                 :          4 :     count = count_ibase_type( ibase_type, list, err );
    7292         [ -  + ]:          4 :     if (count < 0)
    7293                 :          0 :       return;
    7294                 :          4 :     *entity_handles = (iBase_EntityHandle*)malloc( count * sizeof(iBase_EntityHandle) );
    7295         [ -  + ]:          4 :     if (!*entity_handles) 
    7296                 :          0 :       RETURN(iBase_MEMORY_ALLOCATION_FAILED);
    7297                 :          4 :     *entity_handles_alloc = count;
    7298                 :            :   }
    7299                 :            :   
    7300   [ -  +  +  +  :          4 :   switch (ibase_type) {
                   -  - ]
    7301                 :            :     case iBase_ALL_TYPES:
    7302                 :          0 :       count = append_not_type<RefGroup>(list,*entity_handles, *entity_handles_alloc);
    7303                 :          0 :       break;
    7304                 :            :     case iBase_REGION:
    7305                 :          1 :       count = append_type<Body>(list,*entity_handles, *entity_handles_alloc);
    7306                 :          1 :       break;
    7307                 :            :     case iBase_FACE:
    7308                 :          2 :       count = append_type<RefFace>(list,*entity_handles, *entity_handles_alloc);
    7309                 :          2 :       break;
    7310                 :            :     case iBase_EDGE:
    7311                 :          1 :       count = append_type<RefEdge>(list,*entity_handles, *entity_handles_alloc);
    7312                 :          1 :       break;
    7313                 :            :     case iBase_VERTEX:
    7314                 :          0 :       count = append_type<RefVertex>(list,*entity_handles, *entity_handles_alloc);
    7315                 :          0 :       break;
    7316                 :            :     default:
    7317                 :          0 :       RETURN(iBase_INVALID_ENTITY_TYPE);
    7318                 :            :       break;
    7319                 :            :   }
    7320                 :            :   
    7321                 :          4 :   *entity_handles_size = count;
    7322         [ -  + ]:          4 :   if (count > *entity_handles_alloc)
    7323                 :          0 :     RETURN(iBase_BAD_ARRAY_DIMENSION);
    7324                 :            :   
    7325                 :          4 :   RETURN(iBase_SUCCESS);
    7326                 :            : }
    7327                 :            : 
    7328                 :            : static 
    7329                 :          0 : void append_ibase_type( int ibase_type, 
    7330                 :            :                         const DLIList<CubitEntity*>& source_list,
    7331                 :            :                         DLIList<RefEntity*>& target_list,
    7332                 :            :                         int* err )
    7333                 :            : {
    7334   [ #  #  #  #  :          0 :   switch (ibase_type) {
                   #  # ]
    7335                 :            :     case iBase_ALL_TYPES:
    7336                 :          0 :       append_not_type<RefGroup>(source_list, target_list);
    7337                 :          0 :       break;
    7338                 :            :     case iBase_REGION:
    7339                 :          0 :       append_type<Body>(source_list, target_list);
    7340                 :          0 :       break;
    7341                 :            :     case iBase_FACE:
    7342                 :          0 :       append_type<RefFace>(source_list, target_list);
    7343                 :          0 :       break;
    7344                 :            :     case iBase_EDGE:
    7345                 :          0 :       append_type<RefEdge>(source_list, target_list);
    7346                 :          0 :       break;
    7347                 :            :     case iBase_VERTEX:
    7348                 :          0 :       append_type<RefVertex>(source_list, target_list);
    7349                 :          0 :       break;
    7350                 :            :     default:
    7351                 :          0 :       RETURN(iBase_INVALID_ENTITY_TYPE);
    7352                 :            :       break;
    7353                 :            :   }
    7354                 :            :   
    7355                 :          0 :   RETURN(iBase_SUCCESS);
    7356                 :            : }
    7357                 :            : 
    7358                 :            : static 
    7359                 :         26 : void append_all_ibase_type( int ibase_type, 
    7360                 :            :                             DLIList<RefEntity*>& target_list,
    7361                 :            :                             int* err )
    7362                 :            : {
    7363                 :         26 :   RefEntityFactory *const ref = RefEntityFactory::instance();
    7364         [ +  + ]:         26 :   if (ibase_type == iBase_ALL_TYPES) {
    7365         [ +  + ]:          5 :     for (int i = 0; i < 4; ++i) {
    7366         [ +  - ]:          4 :       DLIList<RefEntity*> tmp;
    7367         [ +  - ]:          4 :       ref->ref_entity_list( iGeom_entity_type_names[i], tmp );
    7368         [ +  - ]:          4 :       target_list += tmp;
    7369         [ +  - ]:          4 :     }
    7370                 :            :   }
    7371 [ +  - ][ +  - ]:         25 :   else if (abs(ibase_type) < iBase_ALL_TYPES) {
    7372                 :         25 :     ref->ref_entity_list( iGeom_entity_type_names[ibase_type], target_list );
    7373                 :            :   }
    7374                 :            :   else {
    7375                 :          0 :     RETURN(iBase_INVALID_ENTITY_TYPE);
    7376                 :            :   }
    7377                 :            :   
    7378                 :         26 :   RETURN(iBase_SUCCESS);
    7379                 :            : }
    7380                 :            : 
    7381                 :         28 : void iGeom_getFacets(iGeom_Instance instance,
    7382                 :            :                      iBase_EntityHandle entity,
    7383                 :            :                      double dist_tolerance,
    7384                 :            :                      double **points, int *points_allocated, int *points_size,
    7385                 :            :                      int **facets, int *facets_allocated, int *facets_size,
    7386                 :            :                      int *err)
    7387                 :            : {
    7388         [ +  - ]:         28 :   GMem gMem;
    7389                 :         28 :   CubitStatus resl = CUBIT_SUCCESS;
    7390         [ -  + ]:         28 :   RefFace *ref_face = dynamic_cast<RefFace*>(ENTITY_HANDLE(entity));
    7391         [ +  + ]:         28 :   if(ref_face)
    7392         [ +  - ]:          7 :     resl = ref_face->get_graphics(gMem, 15, dist_tolerance);
    7393                 :            : 
    7394         [ -  + ]:         28 :   RefEdge *ref_edge = dynamic_cast<RefEdge*>(ENTITY_HANDLE(entity));
    7395         [ +  + ]:         28 :   if(ref_edge)
    7396         [ +  - ]:         12 :     resl = ref_edge->get_graphics(gMem, 15, dist_tolerance);
    7397                 :            : 
    7398         [ -  + ]:         28 :   if(resl == CUBIT_FAILURE)
    7399         [ #  # ]:          0 :       ERROR(iBase_FAILURE, "Can't get facets for this entity.");
    7400                 :            : 
    7401 [ +  + ][ +  + ]:         28 :   if(ref_face || ref_edge)
    7402                 :            :   {
    7403         [ +  - ]:         19 :     int p_count = gMem.point_list_size(); 
    7404         [ +  - ]:         19 :     int f_count = gMem.facet_list_size();
    7405         [ +  - ]:         19 :     if(p_count)
    7406                 :            :     {
    7407 [ +  - ][ +  + ]:         19 :       ALLOC_CHECK_ARRAY_NOFAIL(points, p_count * 3);
                 [ +  - ]
    7408         [ +  - ]:         18 :       GPoint* gpoints = gMem.point_list();
    7409                 :            :       double *x, *y, *z;
    7410                 :         18 :       x = *points;
    7411                 :         18 :       y = x + 1;
    7412                 :         18 :       z = x + 2;
    7413                 :         18 :       size_t step = 3;
    7414 [ +  + ][ +  - ]:         67 :       for(int i = 0; i < p_count; i++)
                 [ +  + ]
    7415                 :            :       {
    7416                 :         48 :         GPoint pt = gpoints[i];       
    7417                 :         48 :         *x = pt.x;
    7418                 :         48 :         *y = pt.y;
    7419                 :         48 :         *z = pt.z;
    7420                 :         48 :         x += step;
    7421                 :         48 :         y += step;
    7422                 :         48 :         z += step; 
    7423                 :         19 :       } 
    7424                 :            :     }
    7425         [ +  + ]:         18 :     if(f_count)
    7426                 :            :     {
    7427                 :            :       //return all the triangles. Current gMem gives 4*triangle facets which
    7428                 :            :       //includes a '3' for each facet set to indicate there are 3 nodes on 
    7429                 :            :       //the tessilation. Here trying to ignore the '3'.
    7430 [ +  - ][ -  + ]:          6 :       ALLOC_CHECK_ARRAY_NOFAIL(facets, f_count*3/4);
                 [ +  - ]
    7431                 :            :       int *connectivity;
    7432                 :          6 :       connectivity = *facets;
    7433         [ +  - ]:          6 :       int* list = gMem.facet_list();
    7434 [ +  + ][ +  - ]:         18 :       for (int i = 0; i < f_count/4; i++)
                 [ +  - ]
    7435                 :            :       {
    7436                 :         12 :          *connectivity = list[i*4 + 1];
    7437                 :         12 :          *(connectivity + 1) = list[i*4 + 2];
    7438                 :         12 :          *(connectivity + 2) = list[i*4 + 3];
    7439                 :         12 :          connectivity += 3;
    7440                 :          6 :       }
    7441                 :            :     } 
    7442         [ +  - ]:         18 :     RETURN(iBase_SUCCESS); 
    7443                 :            :   }
    7444                 :            :   else
    7445 [ +  - ][ +  - ]:         28 :     RETURN(iBase_INVALID_ENTITY_TYPE);
                 [ -  + ]
    7446 [ +  - ][ +  - ]:         16 : }
    7447                 :            : 

Generated by: LCOV version 1.11