//////////////////////////////////////////////////////////////////////
// Code Example: Importing data: B-rep method
//
//////////////////////////////////////////////////////////////////////
// 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
int n_topols = 4;
int n_relations = 3;
int n_edges = 0;
PK_CLASS_t classes[4] = {PK_CLASS_body, PK_CLASS_region, PK_CLASS_shell, PK_CLASS_edge};
int parents[3] = {0, 1, 2};
int children[3] = {1, 2, 3};
PK_TOPOL_sense_t senses[3] = {PK_TOPOL_sense_negative_c, PK_TOPOL_sense_none_c, PK_TOPOL_sense_none_c};
PK_BODY_create_topology_2_o_t options;
PK_BODY_create_topology_2_r_t const_creation;
CString text;
int finished = 0;
PK_EDGE_attach_curves_o_t options_attach;
PK_ENTITY_track_r_t tracking;
PK_EDGE_t edges[1] = {PK_ENTITY_null};
PK_CURVE_t curves[1] = {PK_ENTITY_null};
switch( step )
{
case 1:
CExampleAppDoc::ExAppSetStatusBarString("Using the boundary representation method to import a wire to Parasolid");
// Create topology
PK_BODY_create_topology_2_o_m(options);
options.body_type = PK_BODY_type_wire_c;
PK_BODY_create_topology_2(n_topols, classes, n_relations, parents, children, senses, &options, &const_creation);
if (const_creation.create_faults[0].state == PK_BODY_state_ok_c)
{
// Edges
edges[0] = const_creation.topols[3]; // Topology 3
CExampleAppDoc::ExAppShowMessage( "Created Topology" );
}
else
{
CExampleAppDoc::ExAppShowMessage("Failed to Create Topology - stopping" );
return -1;
}
// Free the memory associated with the return structure
PK_BODY_create_topology_2_r_f(&const_creation);
// Create Geometry
// Circle 1 - Attach to topology 3
PK_CIRCLE_sf_t circle3_sf;
circle3_sf.basis_set.location.coord[0] = 0.0;
circle3_sf.basis_set.location.coord[1] = 0.0;
circle3_sf.basis_set.location.coord[2] = 0.0;
circle3_sf.basis_set.axis.coord[0] = 0.0;
circle3_sf.basis_set.axis.coord[1] = 0.0;
circle3_sf.basis_set.axis.coord[2] = 1.0;
circle3_sf.basis_set.ref_direction.coord[0] = 1.0;
circle3_sf.basis_set.ref_direction.coord[1] = 0.0;
circle3_sf.basis_set.ref_direction.coord[2] = 0.0;
circle3_sf.radius = 10;
PK_CIRCLE_create(&circle3_sf, &curves[0]);
CExampleAppDoc::ExAppShowMessage("One curve created" );
// Attach Geometry
n_edges = 1;
PK_EDGE_attach_curves_o_m(options_attach);
PK_EDGE_attach_curves_2(n_edges, edges, curves, &options_attach, &tracking);
PK_ENTITY_track_r_f(&tracking);
CExampleAppDoc::ExAppShowMessage("Attached geometry to topology");
// The model is now complete and can now be used for modelling in Parasolid
// We will need to switch to wireframe view at this point to see the wire
break;
default:
int n_parts;
PK_PART_t *parts;
PK_SESSION_ask_parts(&n_parts, &parts);
PK_ENTITY_delete(n_parts, parts);
PK_MEMORY_free(parts);
finished = 1;
}
return finished;
}