|
Once the assembly classes and methods are defined, instances are created and initialized with proper data. The
INSTANCE class is derived from
ENTITY.
|
|
|
If this example were used to construct a room (assembly) full of chairs (instances), each instance's body pointer would point to the template of a chair, the assembly pointer would point to the room, and the transform would locate each individual chair somewhere in the room.
|
|
|
When a constructor creates an instance, the instance's template body, the assembly to which the instance belongs, and the spatial transformation are all initially
NULL. Member routines provide a way to set and to inquire these parameters.
|
|
|
The
instance.hxx header file prototypes the functions and includes other necessary header files. The
instance.cxx source file implements the functions for instantiation.
|
|
|
C++ Example
|
|
|
// instance.hxx
|
|
#if !defined( INSTANCE_CLASS )
|
|
#define INSTANCE_CLASS
|
|
|
#include "ent_xyz.hxx"
|
|
class BODY;
|
|
class TRANSFRM;
|
|
class ASSEMBLY;
|
|
|
// Identifier that gives number of levels of derivation of this
|
|
// class from ENTITY
|
|
extern int INSTANCE_TYPE;
|
|
#define INSTANCE_LEVEL (ENTITY_XYZ_LEVEL + 1)
|
|
|
// INSTANCE declaration proper.
|
|
class INSTANCE: public ENTITY_XYZ
|
|
{
|
|
// Pointer to the start of a list of instances
|
|
ASSEMBLY *assembly_ptr;
|
|
|
INSTANCE *next_ptr;
|
|
INSTANCE *previous_ptr;
|
|
|
// This transformation relates the local coordinate system to
|
|
// the global one in which the assembly resides.
|
|
TRANSFORM *transform_ptr;
|
|
BODY *body_ptr;
|
|
|
// Include the standard member functions for all entities.
|
|
ENTITY_FUNCTIONS( INSTANCE, NONE )
|
|
|
// Search a private list for this object, used for debugging.
|
|
|
LOOKUP_FUNCTION
|
|
// Now the functions specific to INSTANCE.
|
|
// The instance constructor initializes the record, and makes
|
|
// a new bulletin entry in the current bulletin board to
|
|
// record the creation of the instance.
|
|
INSTANCE( ASSEMBLY *ass = NULL, BODY *b = NULL,
|
|
|
TRANSFORM *t = NULL);
|
|
|
// Data reading routines.
|
|
ASSEMBLY *assembly() const { return assembly_ptr; }
|
|
INSTANCE *previous() const { return previous_ptr; }
|
|
INSTANCE *next() const { return next_ptr; }
|
|
TRANSFORM *transform() const { return transform_ptr; }
|
|
BODY *body() const { return body_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 set_assembly( ASSEMBLY * );
|
|
void set_previous( INSTANCE * );
|
|
void set_next( INSTANCE * );
|
|
void set_transform( TRANSFORM * );
|
|
void set_body( BODY * );
|
|
};
|
|
#endif
|
|
|
Example 8-12. instance.hxx
|
|
|
C++ Example
|
|
|
// instance.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/top/body.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() INSTANCE
|
|
#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 INSTANCE_NAME "instance"
|
|
|
ENTITY_DEF( INSTANCE_NAME )
|
|
// Print out a readable description of this entity.
|
|
debug_new_pointer( "Owning assembly", assembly(), fp );
|
|
debug_new_pointer( "Next instance", next(), fp );
|
|
debug_new_pointer( "Previous instance", previous(), fp );
|
|
debug_new_pointer( "Transform", transform(), fp );
|
|
debug_new_pointer( "Body", body(), fp );
|
|
|
LOOKUP_DEF
|
|
|
SAVE_DEF
|
|
write_ptr( assembly(), list );
|
|
write_ptr( transform(), list );
|
|
write_ptr( body(), list );
|
|
write_ptr( previous(), list );
|
|
write_ptr( next(), list );
|
|
|
RESTORE_DEF
|
|
assembly_ptr = (ASSEMBLY *)read_ptr();
|
|
transform_ptr = (TRANSFORM *)read_ptr();
|
|
body_ptr = (BODY*)read_ptr();
|
|
previous_ptr = (INSTANCE*)read_ptr();
|
|
next_ptr = (INSTANCE*)read_ptr();
|
|
|
COPY_DEF
|
|
assembly_ptr = (ASSEMBLY *)list.lookup( from->assembly() );
|
|
transform_ptr = (TRANSFORM *)list.lookup( from->transform() );
|
|
body_ptr = (BODY*)list.lookup( from->body() );
|
|
previous_ptr = (INSTANCE*)list.lookup( from->previous() );
|
|
next_ptr = (INSTANCE*)list.lookup( from->next() );
|
|
|
SCAN_DEF
|
|
list.add( assembly() );
|
|
list.add( transform() );
|
|
list.add( body() );
|
|
list.add( previous() );
|
|
list.add( next() );
|
|
|
FIX_POINTER_DEF
|
|
set_assembly( (ASSEMBLY *)read_array( array,
|
|
|
(int)assembly() ) );
|
|
set_transform( (TRANSFORM*)read_array( array,
|
|
|
(int)transform() ) );
|
|
set_body( (BODY*)read_array( array, (int)body() ) );
|
|
set_previous( (INSTANCE*)read_array( array,
|
|
|
(int)previous() ) );
|
|
set_next( (INSTANCE*)read_array( array, (int)next() ) );
|
|
|
TERMINATE_DEF
|
|
|
// ************************************************************
|
|
//
|
|
// Now implement the members specific to INSTANCE, and those which
|
|
// are not part of the macros.
|
|
//
|
|
// ************************************************************
|
|
INSTANCE::INSTANCE(ASSEMBLY *ass, BODY *b, TRANSFORM *t)
|
|
{
|
|
//printf("Instance Created\n");
|
|
set_assembly(ass);
|
|
if ( ass != NULL )
|
|
{
|
|
|
ass->add_instance(this);
|
|
}
|
|
set_body(b);
|
|
set_transform(t);
|
|
set_previous(NULL);
|
|
}
|
|
|
// Fix up a copy of this object for a change bulletin, after the
|
|
// object is constructed and copied memberwise.
|
|
void INSTANCE::fixup_copy(
|
|
|
|
INSTANCE *rollback
|
|
|
) const
|
|
{
|
|
PARENT()::fixup_copy( rollback );
|
|
}
|
|
|
// User "destructor" for an INSTANCE. Performs type-specific work,
|
|
// then leaves the rest to the generic ENTITY destructor.
|
|
void INSTANCE::lose()
|
|
{
|
|
transform_ptr->lose();
|
|
|
|
|
|
|
|
// This record is itself rolled back,
|
|
|
|
|
|
|
|
// so we don't set the pointer to NULL
|
|
ENTITY::lose();
|
|
}
|
|
|
// Final record discard.
|
|
INSTANCE::~INSTANCE()
|
|
{
|
|
check_destroy();
|
|
}
|
|
|
// Member-setting functions. Each ensures that the object has been
|
|
// backed up for rollback before making any change.
|
|
void INSTANCE::set_previous( INSTANCE * inst)
|
|
{
|
|
//printf("Instance - Setting previous instance pointer\n");
|
|
backup();
|
|
previous_ptr = inst;
|
|
}
|
|
|
void INSTANCE::set_next( INSTANCE * inst)
|
|
{
|
|
//printf("Instance - Setting next instance pointer\n");
|
|
backup();
|
|
next_ptr = inst;
|
|
}
|
|
|
void INSTANCE::set_assembly( ASSEMBLY * ass )
|
|
{
|
|
//printf("Instance - Setting assembly pointer\n");
|
|
backup();
|
|
assembly_ptr = ass;
|
|
}
|
|
|
void INSTANCE::set_body( BODY * b )
|
|
{
|
|
//printf("Instance - Setting body pointer\n");
|
|
backup();
|
|
body_ptr = b;
|
|
}
|
|
|
void INSTANCE::set_transform( TRANSFORM * trfm )
|
|
{
|
|
//printf("Instance - Setting transform pointer\n");
|
|
backup();
|
|
transform_ptr = trfm;
|
|
}
|
|
|
Example 8-13. instance.cxx
|