Example Color Attribute Application
List of: Discussion Topic
Subjects: Attributes
Contents: Kernel

Example 3-7 shows an application program that uses the color attribute. The program initializes ACIS, makes a block, and applies a color attribute to the block. The program then writes out a debug file and a SAT file.

C++ Example

#include <stdio.h>
#include <stdlib.h>
#include "kernel/acis.hxx"
#include "kernel/logical.h"
#include "kernel/kernapi/api/api.hxx"
#include "kernel/kernapi/api/kernapi.hxx"
#include "kernel/kerndata/lists/lists.hxx"
#include "kernel/kerndata/top/body.hxx"
#include "kernel/kernutil/vector/position.hxx"
#include "constrct/kernapi/api/cstrapi.hxx"
#include "kernel/kerndata/data/debug.hxx"
#include "color_attrib.hxx"

void check_outcome (outcome result, char *string);
logical initialize_acis_components();
logical terminate_acis_components();

void main()
{

// Initialization of the modeler must be done

// before any other calls.

outcome result = api_start_modeller( 0 );

check_outcome(result, "Error starting modeler");


// Call the main library initialization routine.

// This routine is meant to initialize the various ACIS

// libraries that will be linked in.

initialize_acis_components();


// Create positions for geometry elements

SPAposition pts[2];

pts[0] = SPAposition( 10, 10, 10);

pts[1] = SPAposition( 15, 20, 30);


BODY* my_block;


// Create a solid block.

result = api_solid_block( pts[0], pts[1], my_block);

check_outcome(result, "Error solid block");



BODY* b1;

api_make_cuboid(10, 10, 10, b1);


// Apply a color attribute of type 1, "red" to the block.

new ATTRIB_COL (my_block, 1);

// Write out the debug data file

FILE* fp = fopen("Example3-7.dbg", "w");

debug_entity(my_block, fp);

fclose(fp);


// Write out the "SAT" data file

FILE* save_file = fopen("Example3-7.sat", "w");

ENTITY_LIST slist;

slist.add(my_block);

api_save_entity_list(save_file, TRUE, slist);

fclose(save_file);


terminate_acis_components();

printf("Program ended without error.\n");
}

void check_outcome(outcome result, char* string){

if (result.ok())


return;

printf("Error %s\n", string);

printf("Error %d - %s\n",result.error_number(),


find_err_mess( result.error_number() ));

exit(1);
}

logical initialize_acis_components(){

logical result = TRUE;

result &= api_initialize_kernel().ok();

result &= api_initialize_constructors().ok();

return result;
}

logical terminate_acis_components(){

logical result = TRUE;

result &= api_terminate_kernel().ok();

result &= api_terminate_constructors().ok();

return result;
}

Example 3-7. Example Application Program
PDF/KERN/03ATT.PDF
HTM/DATA/KERN/KERN/03ATT/0019.HTM