ASSEMBLY Class
List of: Discussion Topic
Subjects: Extending ACIS, C++ Interface
Contents: Application Development Manual

The assembly.hxx file contains the class declaration, data definitions, inline methods, and prototypes for non-inline methods. The assembly.cxx source file contains implementations for all of the class's non-inline methods.

C++ Example

// assembly.hxx

#if !defined( ASSEMBLY_CLASS )
#define ASSEMBLY_CLASS

#include "ent_xyz.hxx"
#include "kernel/kerndata/geom/transfrm.hxx"

class INSTANCE;

// Identifier that gives number of levels of derivation of this
// class from ENTITY
extern int ASSEMBLY_TYPE;
#define ASSEMBLY_LEVEL (ENTITY_XYZ_LEVEL + 1)

// ASSEMBLY declaration proper.
class ASSEMBLY: public ENTITY_XYZ
{

// Pointer to the start of a list of instances

INSTANCE *instance_ptr;


// This transformation relates the local coordinate system

// to the global one in which the assembly resides.

TRANSFORM *transform_ptr;


// Include the standard member functions for all entities.

ENTITY_FUNCTIONS( ASSEMBLY, NONE )


// Search a private list for this object, used for debugging.

LOOKUP_FUNCTION


// Now the functions specific to ASSEMBLY.


// The assembly constructor initializes the record, and makes

// a new bulletin entry in the current bulletin board to

// record the creation of the assembly.

ASSEMBLY( INSTANCE * = NULL );


// Data reading routines.

INSTANCE *instance() const { return instance_ptr; }

TRANSFORM *transform() const { return transform_ptr; }


// Data changing routines. Each of these routines checks

// that the record has been posted on the bulletin-board

// before performing the change. If not, the routine provokes

// an error, so that the omission (forgetting to call backup()

// first) can be rectified in the program. In production

// versions of the program, these checks may be disabled, to

// improve efficiency.

void add_instance( INSTANCE * );

void set_instance( INSTANCE * );

void set_transform( TRANSFORM * );
};
#endif

Example 8-10. assembly.hxx

C++ Example

// assembly.cxx

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include "kernel/acis.hxx"
#include "kernel/logical.h"
#include "kernel/kerndata/geom/transfrm.hxx"
#include "kernel/kerndata/data/datamsc.hxx"
#include "assembly.hxx"
#include "instance.hxx"

// Include the standard member functions via the usual macros.
// First declare our class name and that of our parent.
#define THIS() ASSEMBLY
#define THIS_LIB NONE
#define PARENT() ENTITY_XYZ
#define PARENT_LIB NONE

// External name for this entity type, for save/restore and
// general communications with the user.
#define ASSEMBLY_NAME "assembly"

ENTITY_DEF( ASSEMBLY_NAME )

// Print out a readable description of this body.

debug_new_pointer( "Instance list", instance(), fp );

debug_new_pointer( "Transform", transform(), fp );

LOOKUP_DEF

SAVE_DEF

write_ptr( instance(), list );

write_ptr( transform(), list );

RESTORE_DEF

instance_ptr = (INSTANCE *)read_ptr();

transform_ptr = (TRANSFORM *)read_ptr();

COPY_DEF

instance_ptr = (INSTANCE *)list.lookup( from->instance() );

transform_ptr = (TRANSFORM *)list.lookup( from->transform() );

SCAN_DEF

list.add( instance() );

list.add( transform() );

FIX_POINTER_DEF

set_instance( (INSTANCE *)read_array( array, (int)instance() ) );

set_transform( (TRANSFORM*)read_array( array, (int)transform() ) );

TERMINATE_DEF

// ************************************************************
//
// Now implement the members specific to ASSEMBLY, and those which
// are not part of the macros.
//
// ************************************************************

ASSEMBLY::ASSEMBLY(INSTANCE *inst)
{

//printf("Assembly Constructor In\n");

set_instance(inst);

set_transform(NULL);


//printf("Set back pointers in instances\n");

// Set back pointers in instances

INSTANCE *this_inst = instance();

while (this_inst != NULL)

{


this_inst->set_assembly( this );


this_inst = this_inst->next();

}

//printf("Assembly Constructor Out\n");
}

// Fix up a copy of this object for a change bulletin, after the
// object is constructed and copied memberwise.
void ASSEMBLY::fixup_copy(



ASSEMBLY *rollback


) const
{

PARENT()::fixup_copy( rollback );
}

// User "destructor" for a ASSEMBLY. Performs type-specific work,
// then leaves the rest to the generic ENTITY destructor.
void ASSEMBLY::lose()
{

transform_ptr->lose();






// This record is itself rolled back, so we






// don't set the pointer to NULL

ENTITY::lose();
}

// Final record discard.
ASSEMBLY::~ASSEMBLY()
{

check_destroy();
}

// Member-setting functions. Each ensures that the object has been
// backed up for rollback before making any change.
void ASSEMBLY::add_instance( INSTANCE * inst)
{

//printf("Assembly - Adding instance pointer\n");

backup();

if ( inst == NULL )

{


printf("Error - Cannot add a NULL instance\n");


return;

} else {


inst->set_previous(NULL);


inst->set_next(instance());


if ( instance() != NULL )



instance()->set_previous(inst);


set_instance(inst);


inst->set_assembly(this);

}
}

void ASSEMBLY::set_instance( INSTANCE * inst)
{

//printf("Assembly - setting instance pointer\n");

backup();

instance_ptr = inst;
}

void ASSEMBLY::set_transform( TRANSFORM * trfm )
{

//printf("Assembly - Setting transform pointer\n");

backup();

transform_ptr = trfm;
}

Example 8-11. assembly.cxx
PDF/APPDEV/08EXT.PDF
HTM/DATA/ACIS/APPDEV/08EXT/0036.HTM