Simple C++ Application Example
List of: Discussion Topic
Subjects: Building Applications, Examples
Contents: Application Development Manual

The code snippet in Example 2-1 illustrates the basic framework of a very simple ACIS-based C++ application. It starts and stops the modeler, initializes and terminates libraries, checks the results of API calls, etc. This example uses a simple macro for API result checking and error reporting. Complex applications may need sophisticated error handling.

The header files (or paths) and/or the API arguments may not be those for the current release.

C++ Example

// Include header files

#include <stdio.h>
#include "kernel/acis.hxx"
#include "kernel/kernapi/api/api.hxx"
#include "kernel/kernapi/api/kernapi.hxx"
#include "constrct/kernapi/api/cstrapi.hxx"
#include "kernel/kerndata/top/body.hxx"
#include "baseutil/vector/position.hxx"
#include "kernel/kerndata/data/entity.hxx"

// Create a simple macro for checking the results of an API call
// (using outcome class); this macro inserts the required semicolon
// following function call

#define CK_OK(API_FUNCTION)





\

{










\

outcome oc = API_FUNCTION;




\

if (!oc.ok())







\


{









\


err_mess_type errNum = oc.error_number(); \


fprintf(stderr, "%s (%d): %s (%d)\n",
\


__FILE__, __LINE__,





\


find_err_mess(errNum), errNum);


\

} /* end if */







\


}









\

}

void main ()
{

// Start the modeler and initialize component libraries


CK_OK(api_start_modeller(0)) // memory size as needed

CK_OK(api_initialize_constructors())


// Create a square block, called MyBlock; API api_solid_block

// defines a block using two ACIS positions, and each position

// is defined using 3 (xyz) coordinates


BODY *MyBlock;

CK_OK(api_solid_block(


position (-20, -20, -20),


position (20, 20, 20), MyBlock))


printf("Created the block.\n");


// Clean up memory allocation

CK_OK(api_del_entity(MyBlock))


// Terminate component libraries and stop modeler


CK_OK(api_terminate_constructors())

CK_OK(api_stop_modeller())

}

Example 2-1. Simple Application Example
PDF/APPDEV/02FRAME.PDF
HTM/DATA/ACIS/APPDEV/02FRAME/0004.HTM