Example Code for api_check_entity


The following sample code shows the use of api_check_entity and how to process the results from that function.

// Create a list of entities to be checked

ENTITY_LIST entities_to_check;
...

// Fill in the list of entities to check
...

// Set the check level to at least 30, to activate the
// surface checks which we are looking for in this example.

check_level.set(30);

// Check each entity in turn

for(int index = 0; index<entities.count(); ++index)

{
    // Get the next entity to be checked from the list
   
   ENTITY* entity_to_check = entities_to_check[index];

   // Initialize the list of errors to null.

   insanity_list* errors = 0;

   // Perform the check on the entity.

   outcome result = api_check_entity(entity_to_check, errors);

   // Test that the check was performed successfully before analyzing the results

   if(result.ok())
   {
        insanity_list* this_list = errors;

        // Loop over all insanities found for the entity

        for(; this_list; this_list = this_list->next())
        {
             insanity_data* data = this_list->data();

             // For this example, we are looking for faces that
             // have illegal surfaces with either "irregular" or
             // "bad degeneracy" errors. Therefore we do not worry
             // about any insanities that are not of "error" type.

             if(data && data->get_type()==ERROR_TYPE)
             {
                  // Now pick out the particular errors that we are looking for.
                  
                  int insane_id = data->get_insane_id())
                  if (IRREG_SURF == insane_id)
                  {
                       // Report that the entity has an irregular surface.
                       // We print a slightly different message depending on
                       // whether the entity with the bad surface is the one
                       // we checked, or one of its children.

                       if (data->get_ent()==entity_to_check)
                       {
                            printf("Surface of entity 0x%x is irregular.", entity_to_check);
                       }
                       else
                       {
                            printf("Surface of entity 0x%x (owning entity 0x%x) is irregular.", data->get_ent(),entity_to_check);
                       }

                       // Now check whether the irregularity is due to
                       // extreme curvature on the surface.

                       if (data->get_sub_category()==HIGH_CURVATURE)
                       {
                            // It is true. Report it.

                            printf(" Surface has high curvature");

                            // Check if the data includes a parameter
                            // position indicating the region of high curvature.
                            // get_par_pos() sets uv and returns TRUE if
                            // a parameter position is stored.

                            SPApar_pos uv;
                            if (data->get_par_pos(uv))
                            {
                                 // It does. Report this as well.

                                 printf(" around (%g,%g).",uv.u,uv.v);
                            }
                       }
                       printf("\n");
                  }

                  else if (SURF_BAD_DEGEN == insane_id)
                  {
                       // Report that the entity has a surface with a bad
                       // degeneracy. We print a slightly different message
                       // depending on whether the entity with the bad surface
                       // is the one we checked, or one of its children.

                       if(data->get_ent()==entity_to_check)
                       {
                            printf("Surface of entity 0x%x has a bad degeneracy.\n", entity_to_check);
                       }
                       else
                       {
                            printf("Surface of entity 0x%x (owning entity 0x%x) has a bad degeneracy.\n",
                                                                          data->get_ent(),entity_to_check);  
                       }
                  }

                  else
                  {
                      // We are not interested in this error type. Ignore it

                  }
             }
        }
   }
   else
   {
        // Handle failure of api_check_entity()
   }
   // Discard the returned error data for this entity

   ACIS_DELETE errors;
}

[Top]