//////////////////////////////////////////////////////////////////////
// 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 = 18;
int n_relations = 22;
PK_CLASS_t classes[18] = {PK_CLASS_body, PK_CLASS_region, PK_CLASS_region, PK_CLASS_shell,
PK_CLASS_shell, PK_CLASS_face, PK_CLASS_face, PK_CLASS_face,
PK_CLASS_loop, PK_CLASS_loop, PK_CLASS_loop, PK_CLASS_loop,
PK_CLASS_fin, PK_CLASS_fin, PK_CLASS_fin, PK_CLASS_fin,
PK_CLASS_edge, PK_CLASS_edge};
int parents[22]= {0, 0, 1, 2, 3, 3, 3, 4, 4, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int children[22] = {1, 2, 3, 4, 5, 6, 7, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 17, 17};
PK_TOPOL_sense_t senses[22] = {PK_TOPOL_sense_negative_c, PK_TOPOL_sense_positive_c, PK_TOPOL_sense_none_c,
PK_TOPOL_sense_none_c, PK_TOPOL_sense_positive_c, PK_TOPOL_sense_positive_c,
PK_TOPOL_sense_positive_c, PK_TOPOL_sense_negative_c, PK_TOPOL_sense_negative_c,
PK_TOPOL_sense_negative_c, PK_TOPOL_sense_none_c, PK_TOPOL_sense_none_c,
PK_TOPOL_sense_none_c, PK_TOPOL_sense_none_c, PK_TOPOL_sense_none_c,
PK_TOPOL_sense_none_c, PK_TOPOL_sense_none_c, PK_TOPOL_sense_none_c,
PK_TOPOL_sense_positive_c, PK_TOPOL_sense_negative_c, PK_TOPOL_sense_negative_c,
PK_TOPOL_sense_positive_c};
PK_BODY_create_topology_2_o_t options;
PK_BODY_create_topology_2_r_t const_creation;
CString text;
int finished = 0;
int n_faces = 0;
int n_edges = 0;
PK_FACE_t faces[3] = {PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null};
PK_SURF_t surfs[3] = {PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null};
PK_LOGICAL_t face_senses[3] = {PK_LOGICAL_false, PK_LOGICAL_false, PK_LOGICAL_false};
PK_EDGE_t edges[2] = {PK_ENTITY_null, PK_ENTITY_null};
PK_CURVE_t curves[2] = {PK_ENTITY_null, PK_ENTITY_null};
PK_EDGE_attach_curves_o_t options_attach;
PK_ENTITY_track_r_t tracking;
switch( step )
{
case 1:
CExampleAppDoc::ExAppSetStatusBarString("Using the boundary representation method to import a cylinder to Parasolid");
// Create topology
PK_BODY_create_topology_2_o_m(options);
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)
{
// Faces
faces[0] = const_creation.topols[5]; // Topology 5
faces[1] = const_creation.topols[6]; // Topology 6
faces[2] = const_creation.topols[7]; // Topology 7
// Edges
edges[0] = const_creation.topols[16]; // Topology 16
edges[1] = const_creation.topols[17]; // Topology 17
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
// Plane 1 - Attach to topology 5
PK_PLANE_sf_t plane1_sf;
plane1_sf.basis_set.location.coord[0] = 0.0;
plane1_sf.basis_set.location.coord[1] = 0.0;
plane1_sf.basis_set.location.coord[2] = 5.0;
plane1_sf.basis_set.axis.coord[0] = 0.0;
plane1_sf.basis_set.axis.coord[1] = 0.0;
plane1_sf.basis_set.axis.coord[2] = 1.0;
plane1_sf.basis_set.ref_direction.coord[0] = 1.0;
plane1_sf.basis_set.ref_direction.coord[1] = 0.0;
plane1_sf.basis_set.ref_direction.coord[2] = 0.0;
PK_PLANE_create(&plane1_sf, &surfs[0]);
// Plane 2 - Attach to topology 7
PK_PLANE_sf_t plane2_sf;
plane2_sf.basis_set.location.coord[0] = 0.0;
plane2_sf.basis_set.location.coord[1] = 0.0;
plane2_sf.basis_set.location.coord[2] = 0.0;
plane2_sf.basis_set.axis.coord[0] = 0.0;
plane2_sf.basis_set.axis.coord[1] = 0.0;
plane2_sf.basis_set.axis.coord[2] = -1.0;
plane2_sf.basis_set.ref_direction.coord[0] = 1.0;
plane2_sf.basis_set.ref_direction.coord[1] = 0.0;
plane2_sf.basis_set.ref_direction.coord[2] = 0.0;
PK_PLANE_create(&plane2_sf, &surfs[2]);
// Cylindrical Surface - Attach to topology 6
PK_CYL_sf_t cyl_sf;
cyl_sf.basis_set.location.coord[0] = 0.0;
cyl_sf.basis_set.location.coord[1] = 0.0;
cyl_sf.basis_set.location.coord[2] = 0.0;
cyl_sf.basis_set.axis.coord[0] = 0.0;
cyl_sf.basis_set.axis.coord[1] = 0.0;
cyl_sf.basis_set.axis.coord[2] = 1.0;
cyl_sf.basis_set.ref_direction.coord[0] = 1.0;
cyl_sf.basis_set.ref_direction.coord[1] = 0.0;
cyl_sf.basis_set.ref_direction.coord[2] = 0.0;
cyl_sf.radius = 10.0;
PK_CYL_create(&cyl_sf, &surfs[1]);
// Curve 1 - Attach to topology 16
PK_CIRCLE_sf_t circle1_sf;
circle1_sf.basis_set.location.coord[0] = 0.0;
circle1_sf.basis_set.location.coord[1] = 0.0;
circle1_sf.basis_set.location.coord[2] = 5.0;
circle1_sf.basis_set.axis.coord[0] = 0.0;
circle1_sf.basis_set.axis.coord[1] = 0.0;
circle1_sf.basis_set.axis.coord[2] = 1.0;
circle1_sf.basis_set.ref_direction.coord[0] = 1.0;
circle1_sf.basis_set.ref_direction.coord[1] = 0.0;
circle1_sf.basis_set.ref_direction.coord[2] = 0.0;
circle1_sf.radius = 10.0;
PK_CIRCLE_create(&circle1_sf, &curves[0]);
// Curve 2 - Attach to topology 17
PK_CIRCLE_sf_t circle2_sf;
circle2_sf.basis_set.location.coord[0] = 0.0;
circle2_sf.basis_set.location.coord[1] = 0.0;
circle2_sf.basis_set.location.coord[2] = 0.0;
circle2_sf.basis_set.axis.coord[0] = 0.0;
circle2_sf.basis_set.axis.coord[1] = 0.0;
circle2_sf.basis_set.axis.coord[2] = -1.0;
circle2_sf.basis_set.ref_direction.coord[0] = 1.0;
circle2_sf.basis_set.ref_direction.coord[1] = 0.0;
circle2_sf.basis_set.ref_direction.coord[2] = 0.0;
circle2_sf.radius = 10.0;
PK_CIRCLE_create(&circle2_sf, &curves[1]);
CExampleAppDoc::ExAppShowMessage("Created 2 planes, a cylindrical surface and two circular curves");
//Attach geometry to topology
n_faces = 3;
n_edges = 2;
face_senses[0] = PK_LOGICAL_true;
face_senses[1] = PK_LOGICAL_true;
face_senses[2] = PK_LOGICAL_true;
PK_FACE_attach_surfs(n_faces, faces, surfs, face_senses);
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
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;
}