//////////////////////////////////////////////////////////////////////
// Code Example: Using the bulletin board
//
//////////////////////////////////////////////////////////////////////
// This function is passed the step number. This allows for an application to
// produce code with several steps as demonstrated.
// Return 1 if you have finished, 0 if otherwise and -1 to exit.
int CMyCode::RunMyCode(int step)
{
//The code below is sample code. On exiting the function the bodies that
//exist will be drawn
static PK_BB_t m_board;
static PK_BODY_t block;
static PK_BODY_t wire_circle;
static int low_param = -499; /// Low parameter of interval inside size box for a PK_CLASS_line
static int high_param = 499; /// High parameter of interval inside size box for a PK_CLASS_line
PK_CLASS_t list1[ 4 ] = { PK_CLASS_body, PK_CLASS_face, PK_CLASS_edge, PK_CLASS_vertex };
PK_CLASS_t list2[ 3 ] = { PK_CLASS_face, PK_CLASS_edge, PK_CLASS_vertex };
PK_CLASS_array_t bb_list = { list1, 4 };
PK_CLASS_array_t bb_list_2 = { list2, 3 };
PK_CLASS_array_t null_list = { NULL, 0 };
int finished = 0;
int n_entities = 0;
int *events = NULL;
PK_ENTITY_t *entities = NULL;
PK_BB_event_t *event_types = NULL;
PK_CLASS_t *classes = NULL;
int *user_fields = NULL;
PK_AXIS2_sf_t basis_set;
static PK_FACE_t imprinted_face;
int n_parts = 0;
PK_PART_t *parts = NULL;
PK_LINE_t line;
PK_INTERVAL_t interval;
PK_CURVE_project_r_t project_results;
PK_ENTITY_track_r_t project_tracking;
PK_CURVE_project_o_t project_opts;
int n_curves = 0;
PK_CURVE_t* curve_array;
PK_INTERVAL_t* interval_array;
PK_TOPOL_delete_redundant_2_o_t delete_options;
PK_TOPOL_track_r_t delete_tracking;
PK_TOPOL_t* topol_array;
int n_topols = 0;
void DisplayBBResults(int n_entities, int *events, PK_ENTITY_t *entities, PK_BB_event_t *event_types, PK_CLASS_t *classes);
switch( step )
{
case 1:
PK_BB_sf_t bsf;
CExampleAppDoc::ExAppSetStatusBarString("Created bulletin board to record create, delete, merge and split events. Created a solid block.");
bsf.create = bb_list;
bsf.deleet = bb_list;
bsf.copy = null_list;
bsf.transfer = null_list;
bsf.merge = bb_list_2;
bsf.split = bb_list_2;
bsf.transform = null_list;
bsf.change_attrib = null_list;
bsf.change = null_list;
PK_BB_create( &bsf, &m_board );
PK_BB_set_status( m_board, PK_BB_status_on_c );
PK_BODY_create_solid_block( 10.0, 10.0, 10.0, NULL, &block );
PK_BB_output_events(m_board, PK_LOGICAL_true, &n_entities, &events, &entities, &event_types, &classes, &user_fields);
DisplayBBResults(n_entities, events, entities, event_types, classes);
if(n_entities)
{
PK_MEMORY_free(events);
PK_MEMORY_free(entities);
PK_MEMORY_free(event_types);
PK_MEMORY_free(classes);
}
PK_BB_set_status(m_board, PK_BB_status_off_c);
break;
case 2:
CExampleAppDoc::ExAppSetStatusBarString("Created a circular curve. Switched bulletin board on and imprinted the curve on the block.");
int i;
PK_CIRCLE_sf_t circle_sf;
basis_set.location.coord[0] = 0;
basis_set.location.coord[1] = 0;
basis_set.location.coord[2] = 20;
basis_set.axis.coord[0] = 0;
basis_set.axis.coord[1] = 0;
basis_set.axis.coord[2] = 1;
basis_set.ref_direction.coord[0] = 1;
basis_set.ref_direction.coord[1] = 0;
basis_set.ref_direction.coord[2] = 0;
circle_sf.basis_set = basis_set;
circle_sf.radius = 2.5;
PK_CIRCLE_create( &circle_sf, &wire_circle);
PK_BB_set_status(m_board, PK_BB_status_on_c);
PK_CURVE_ask_interval( wire_circle, &interval);
curve_array = new PK_CURVE_t[1];
curve_array[0] = wire_circle;
interval_array = new PK_INTERVAL_t[1];
interval_array[0] = interval;
n_curves = 1;
PK_CURVE_project_o_m( project_opts );
project_opts.function = PK_proj_function_imprint_c;
PK_CURVE_project(n_curves, curve_array, interval_array, 1, &block, &project_opts, &project_results, &project_tracking);
delete[] curve_array;
delete[] interval_array;
PK_BB_output_events(m_board, PK_LOGICAL_true, &n_entities, &events, &entities, &event_types, &classes, &user_fields);
DisplayBBResults(n_entities, events, entities, event_types, classes);
for(i=0;i< n_entities;i++)
{
if(event_types[i] == PK_BB_event_split_c)
{
imprinted_face = entities[i+1];
break;
}
}
if(n_entities)
{
PK_MEMORY_free(events);
PK_MEMORY_free(entities);
PK_MEMORY_free(event_types);
PK_MEMORY_free(classes);
}
PK_BB_set_status(m_board, PK_BB_status_off_c);
PK_CURVE_project_r_f( &project_results );
PK_ENTITY_track_r_f( &project_tracking );
break;
case 3:
CExampleAppDoc::ExAppSetStatusBarString("Created a line. Switched bulletin board on and imprinted the line on the circular face of the block.");
PK_LINE_sf_t line_sf_t;
line_sf_t.basis_set.location.coord[0] = 0;
line_sf_t.basis_set.location.coord[1] = 0;
line_sf_t.basis_set.location.coord[2] = 20;
line_sf_t.basis_set.axis.coord[0] = 1;
line_sf_t.basis_set.axis.coord[1] = 0;
line_sf_t.basis_set.axis.coord[2] = 0;
PK_LINE_create(&line_sf_t, &line);
PK_BB_set_status(m_board, PK_BB_status_on_c);
/// Set interval to be inside size box
interval.value[0] = low_param;
interval.value[1] = high_param;
curve_array = new PK_CURVE_t[1];
curve_array[0] = line;
interval_array = new PK_INTERVAL_t[1];
interval_array[0] = interval;
n_curves = 1;
PK_CURVE_project_o_m( project_opts );
project_opts.function = PK_proj_function_imprint_c;
PK_CURVE_project(n_curves, curve_array, interval_array, 1, &imprinted_face, &project_opts, &project_results, &project_tracking);
delete[] curve_array;
delete[] interval_array;
PK_BB_output_events(m_board, PK_LOGICAL_true, &n_entities, &events, &entities, &event_types, &classes, &user_fields);
DisplayBBResults(n_entities, events, entities, event_types, classes);
if(n_entities)
{
PK_MEMORY_free(events);
PK_MEMORY_free(entities);
PK_MEMORY_free(event_types);
PK_MEMORY_free(classes);
}
PK_BB_set_status(m_board, PK_BB_status_off_c);
PK_CURVE_project_r_f( &project_results );
PK_ENTITY_track_r_f( &project_tracking );
break;
case 4:
CExampleAppDoc::ExAppSetStatusBarString("Switched on the bulletin board and swept one of the semi-circular faces");
int n_laterals;
PK_FACE_t *laterals;
PK_EDGE_t *bases;
PK_VECTOR_t vector;
PK_local_check_t check_result;
vector.coord[0] = 0;
vector.coord[1] = 0;
vector.coord[2] = 10;
PK_BB_set_status(m_board, PK_BB_status_on_c);
PK_FACE_sweep(1, &imprinted_face, vector, PK_LOGICAL_true, &n_laterals, &laterals, &bases, &check_result);
if(n_laterals)
{
PK_MEMORY_free(laterals);
PK_MEMORY_free(bases);
}
PK_BB_output_events(m_board, PK_LOGICAL_true, &n_entities, &events, &entities, &event_types, &classes, &user_fields);
DisplayBBResults(n_entities, events, entities, event_types, classes);
if(n_entities)
{
PK_MEMORY_free(events);
PK_MEMORY_free(entities);
PK_MEMORY_free(event_types);
PK_MEMORY_free(classes);
}
PK_BB_set_status(m_board, PK_BB_status_off_c);
break;
case 5:
CExampleAppDoc::ExAppSetStatusBarString("Switched on the bulletin board and deleted redundant topology");
PK_BB_set_status(m_board, PK_BB_status_on_c);
topol_array = new PK_TOPOL_t[1];
topol_array[0] = block;
n_topols = 1;
PK_TOPOL_delete_redundant_2_o_m( delete_options );
PK_TOPOL_delete_redundant_2(n_topols, topol_array, &delete_options, &delete_tracking);
delete[] topol_array;
PK_BB_output_events(m_board, PK_LOGICAL_true, &n_entities, &events, &entities, &event_types, &classes, &user_fields);
DisplayBBResults(n_entities, events, entities, event_types, classes);
if(n_entities)
{
PK_MEMORY_free(events);
PK_MEMORY_free(entities);
PK_MEMORY_free(event_types);
PK_MEMORY_free(classes);
}
PK_BB_set_status(m_board, PK_BB_status_off_c);
PK_TOPOL_track_r_f( &delete_tracking );
break;
case 6:
CExampleAppDoc::ExAppSetStatusBarString("Deleted parts in the session.");
PK_BB_set_status(m_board, PK_BB_status_on_c);
PK_SESSION_ask_parts(&n_parts, &parts);
PK_ENTITY_delete(n_parts, parts);
PK_BB_output_events(m_board, PK_LOGICAL_true, &n_entities, &events, &entities, &event_types, &classes, &user_fields);
DisplayBBResults(n_entities, events, entities, event_types, classes);
if(n_entities)
{
PK_MEMORY_free(events);
PK_MEMORY_free(entities);
PK_MEMORY_free(event_types);
PK_MEMORY_free(classes);
}
PK_BB_set_status(m_board, PK_BB_status_off_c);
break;
default:
finished = 1;
}
return finished;
}
void DisplayBBResults(int n_entities, int *events, PK_ENTITY_t *entities, PK_BB_event_t *event_types, PK_CLASS_t *classes)
{
CString result;
CString class_types;
CString event_no;
CString entity_types;
for(int i=0; i< n_entities; i++)
{
char pcBuffer[PC_BUFFER_SIZE];
sprintf_s(pcBuffer, PC_BUFFER_SIZE, "Event: %d, ", events[i]);
result.Append(CString(pcBuffer));
//find event type
result.Append(CString("Event type: "));
if(event_types[i] == PK_BB_event_create_c)
result.Append(CString("Create, "));
else if(event_types[i] == PK_BB_event_delete_c)
result.Append(CString("Delete, "));
else if(event_types[i] == PK_BB_event_change_c)
result.Append(CString("Change, "));
else if(event_types[i] == PK_BB_event_split_c)
result.Append(CString("Split, "));
else if(event_types[i] == PK_BB_event_merge_c)
result.Append(CString("Merge, "));
else
result.Append(CString("Unknown, "));
//find class
result.Append(CString("Class: "));
if(classes[i] == PK_CLASS_body)
result.Append(CString("Body, "));
else if(classes[i] == PK_CLASS_face)
result.Append(CString("Face, "));
else if(classes[i] == PK_CLASS_edge)
result.Append(CString("Edge, "));
else if(classes[i] == PK_CLASS_vertex)
result.Append(CString("Vertex, "));
else
result.Append(CString("Unknown, "));
//find entity
char pcEntityType[PC_BUFFER_SIZE];
sprintf_s(pcEntityType, PC_BUFFER_SIZE, "Entity: %d\r\n", entities[i]);
result.Append(CString(pcEntityType));
}
AfxMessageBox(result);
}