//////////////////////////////////////////////////////////////////////
// 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 = 27;
int n_relations = 46;
PK_CLASS_t classes[27] = {
PK_CLASS_body, PK_CLASS_region, PK_CLASS_shell, PK_CLASS_face, PK_CLASS_loop,
PK_CLASS_edge, PK_CLASS_vertex, PK_CLASS_vertex, PK_CLASS_edge, PK_CLASS_vertex,
PK_CLASS_loop, PK_CLASS_edge, PK_CLASS_vertex, PK_CLASS_edge, PK_CLASS_vertex,
PK_CLASS_edge, PK_CLASS_loop, PK_CLASS_edge, PK_CLASS_vertex, PK_CLASS_edge,
PK_CLASS_vertex, PK_CLASS_edge, PK_CLASS_edge, PK_CLASS_vertex, PK_CLASS_edge,
PK_CLASS_face, PK_CLASS_face };
int parents[46]= {0, 1, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 8, 8, 8, 8, 8, 10, 10, 10,
10, 11, 11, 13, 13, 15, 15, 16, 16, 16, 16, 17, 17, 19, 19, 21, 21, 22, 22, 24, 24, 25, 26};
int children[46] = {1, 2, 3, 25, 26, 3, 25, 26, 4, 5, 8, 22, 24, 6, 7, 9, 6, 10, 16, 4,
11, 13, 15, 8, 12, 9, 14, 12, 6, 14, 17, 8, 19, 21, 6, 18, 20, 9, 18, 20, 23, 9, 7, 23, 10, 16};
PK_TOPOL_sense_t senses[46] = {
PK_TOPOL_sense_negative_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_negative_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_negative_c,
PK_TOPOL_sense_negative_c, PK_TOPOL_sense_negative_c, PK_TOPOL_sense_negative_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_negative_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_none_c, PK_TOPOL_sense_none_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;
int n_faces = 0;
int n_edges = 0;
int n_vertices = 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[10] = {PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null,
PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null};
PK_CURVE_t curves[10] = {PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null,
PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null};
PK_VERTEX_t vertices[8] = {PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null,
PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null};
PK_POINT_t points[8] = {PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null,
PK_ENTITY_null, PK_ENTITY_null, PK_ENTITY_null};
switch( step )
{
case 1:
CExampleAppDoc::ExAppSetStatusBarString("Using the boundary representation method to import a t-sheet 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[3]; // Topology 3
faces[1] = const_creation.topols[25]; // Topology 25
faces[2] = const_creation.topols[26]; // Topology 26
// Edges
edges[0] = const_creation.topols[11]; // Topology 11
edges[1] = const_creation.topols[13]; // Topology 13
edges[2] = const_creation.topols[15]; // Topology 15
edges[3] = const_creation.topols[8]; // Topology 8
edges[4] = const_creation.topols[22]; // Topology 22
edges[5] = const_creation.topols[24]; // Topology 24
edges[6] = const_creation.topols[5]; // Topology 5
edges[7] = const_creation.topols[17]; // Topology 17
edges[8] = const_creation.topols[21]; // Topology 21
edges[9] = const_creation.topols[19]; // Topology 19
// Vertices
vertices[0] = const_creation.topols[12]; // Topology 12
vertices[1] = const_creation.topols[14]; // Topology 14
vertices[2] = const_creation.topols[6]; // Topology 6
vertices[3] = const_creation.topols[9]; // Topology 9
vertices[4] = const_creation.topols[23]; // Topology 23
vertices[5] = const_creation.topols[7]; // Topology 7
vertices[6] = const_creation.topols[18]; // Topology 18
vertices[7] = const_creation.topols[20]; // Topology 20
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 3
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] = 1.0;
plane1_sf.basis_set.axis.coord[2] = 0.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 25
PK_PLANE_sf_t plane2_sf;
plane2_sf.basis_set.location.coord[0] = 0.0;
plane2_sf.basis_set.location.coord[1] = -5.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[1]);
// Plane 3 - Attach to topology 26
PK_PLANE_sf_t plane3_sf;
plane3_sf.basis_set.location.coord[0] = 0.0;
plane3_sf.basis_set.location.coord[1] = 5.0;
plane3_sf.basis_set.location.coord[2] = 0.0;
plane3_sf.basis_set.axis.coord[0] = 0.0;
plane3_sf.basis_set.axis.coord[1] = 0.0;
plane3_sf.basis_set.axis.coord[2] = -1.0;
plane3_sf.basis_set.ref_direction.coord[0] = 1.0;
plane3_sf.basis_set.ref_direction.coord[1] = 0.0;
plane3_sf.basis_set.ref_direction.coord[2] = 0.0;
PK_PLANE_create(&plane3_sf, &surfs[2]);
// Curve 1 - Attach to topology 11
PK_LINE_sf_t curve1_sf;
curve1_sf.basis_set.location.coord[0] = -5.0;
curve1_sf.basis_set.location.coord[1] = -10.0;
curve1_sf.basis_set.location.coord[2] = 0.0;
curve1_sf.basis_set.axis.coord[0] = 0.0;
curve1_sf.basis_set.axis.coord[1] = 1.0;
curve1_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve1_sf, &curves[0]);
// Curve 2 - Attach to topology 13
PK_LINE_sf_t curve2_sf;
curve2_sf.basis_set.location.coord[0] = 5.0;
curve2_sf.basis_set.location.coord[1] = -10.0;
curve2_sf.basis_set.location.coord[2] = 0.0;
curve2_sf.basis_set.axis.coord[0] = -1.0;
curve2_sf.basis_set.axis.coord[1] = 0.0;
curve2_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve2_sf, &curves[1]);
// Curve 3 - Attach to topology 15
PK_LINE_sf_t curve3_sf;
curve3_sf.basis_set.location.coord[0] = 5.0;
curve3_sf.basis_set.location.coord[1] = 0.0;
curve3_sf.basis_set.location.coord[2] = 0.0;
curve3_sf.basis_set.axis.coord[0] = 0.0;
curve3_sf.basis_set.axis.coord[1] = -1.0;
curve3_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve3_sf, &curves[2]);
// Curve 4 - Attach to topology 8
PK_LINE_sf_t curve4_sf;
curve4_sf.basis_set.location.coord[0] = -5.0;
curve4_sf.basis_set.location.coord[1] = 0.0;
curve4_sf.basis_set.location.coord[2] = 0.0;
curve4_sf.basis_set.axis.coord[0] = 1.0;
curve4_sf.basis_set.axis.coord[1] = 0.0;
curve4_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve4_sf, &curves[3]);
// Curve 5 - Attached to topology 22
PK_LINE_sf_t curve5_sf;
curve5_sf.basis_set.location.coord[0] = -5.0;
curve5_sf.basis_set.location.coord[1] = 0.0;
curve5_sf.basis_set.location.coord[2] = 10.0;
curve5_sf.basis_set.axis.coord[0] = 0.0;
curve5_sf.basis_set.axis.coord[1] = 0.0;
curve5_sf.basis_set.axis.coord[2] = -1.0;
PK_LINE_create(&curve5_sf, &curves[4]);
// Curve 6 - Attach to topology 24
PK_LINE_sf_t curve6_sf;
curve6_sf.basis_set.location.coord[0] = 5.0;
curve6_sf.basis_set.location.coord[1] = 0.0;
curve6_sf.basis_set.location.coord[2] = 10.0;
curve6_sf.basis_set.axis.coord[0] = -1.0;
curve6_sf.basis_set.axis.coord[1] = 0.0;
curve6_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve6_sf, &curves[5]);
// Curve 7 - Attach to topology 5
PK_LINE_sf_t curve7_sf;
curve7_sf.basis_set.location.coord[0] = 5.0;
curve7_sf.basis_set.location.coord[1] = 0.0;
curve7_sf.basis_set.location.coord[2] = 0.0;
curve7_sf.basis_set.axis.coord[0] = 0.0;
curve7_sf.basis_set.axis.coord[1] = 0.0;
curve7_sf.basis_set.axis.coord[2] = 1.0;
PK_LINE_create(&curve7_sf, &curves[6]);
// Curve 8 - Attach to topology 17
PK_LINE_sf_t curve8_sf;
curve8_sf.basis_set.location.coord[0] = 5.0;
curve8_sf.basis_set.location.coord[1] = 0.0;
curve8_sf.basis_set.location.coord[2] = 0.0;
curve8_sf.basis_set.axis.coord[0] = 0.0;
curve8_sf.basis_set.axis.coord[1] = 1.0;
curve8_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve8_sf, &curves[7]);
// Curve 9 - Attach to topology 21
PK_LINE_sf_t curve9_sf;
curve9_sf.basis_set.location.coord[0] = 5.0;
curve9_sf.basis_set.location.coord[1] = 10.0;
curve9_sf.basis_set.location.coord[2] = 0.0;
curve9_sf.basis_set.axis.coord[0] = -1.0;
curve9_sf.basis_set.axis.coord[1] = 0.0;
curve9_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve9_sf, &curves[8]);
// Curve 10 - Attach to topology 19
PK_LINE_sf_t curve10_sf;
curve10_sf.basis_set.location.coord[0] = -5.0;
curve10_sf.basis_set.location.coord[1] = 10.0;
curve10_sf.basis_set.location.coord[2] = 0.0;
curve10_sf.basis_set.axis.coord[0] = 0.0;
curve10_sf.basis_set.axis.coord[1] = -1.0;
curve10_sf.basis_set.axis.coord[2] = 0.0;
PK_LINE_create(&curve10_sf, &curves[9]);
// Point 1 - Attach to topology 12
PK_POINT_sf_t point1_sf;
point1_sf.position.coord[0] = -5.0;
point1_sf.position.coord[1] = -10.0;
point1_sf.position.coord[2] = 0.0;
PK_POINT_create(&point1_sf, &points[0]);
// Point 2 - Attach to topology 14
PK_POINT_sf_t point2_sf;
point2_sf.position.coord[0] = 5.0;
point2_sf.position.coord[1] = -10.0;
point2_sf.position.coord[2] = 0.0;
PK_POINT_create(&point2_sf, &points[1]);
// Point 3 - Attach to topology 6
PK_POINT_sf_t point3_sf;
point3_sf.position.coord[0] = 5.0;
point3_sf.position.coord[1] = 0.0;
point3_sf.position.coord[2] = 0.0;
PK_POINT_create(&point3_sf, &points[2]);
// Point 4 - Attach to topology 9
PK_POINT_sf_t point4_sf;
point4_sf.position.coord[0] = -5.0;
point4_sf.position.coord[1] = 0.0;
point4_sf.position.coord[2] = 0.0;
PK_POINT_create(&point4_sf, &points[3]);
// Point 5 - Attach to topology 23
PK_POINT_sf_t point5_sf;
point5_sf.position.coord[0] = -5.0;
point5_sf.position.coord[1] = 0.0;
point5_sf.position.coord[2] = 10.0;
PK_POINT_create(&point5_sf, &points[4]);
// Point 6 - Attach to topology 7
PK_POINT_sf_t point6_sf;
point6_sf.position.coord[0] = 5.0;
point6_sf.position.coord[1] = 0.0;
point6_sf.position.coord[2] = 10.0;
PK_POINT_create(&point6_sf, &points[5]);
// Point 7 - Attach to topology 18
PK_POINT_sf_t point7_sf;
point7_sf.position.coord[0] = 5.0;
point7_sf.position.coord[1] = 10.0;
point7_sf.position.coord[2] = 0.0;
PK_POINT_create(&point7_sf, &points[6]);
// Point 8 - Attach to topology 20
PK_POINT_sf_t point8_sf;
point8_sf.position.coord[0] = -5.0;
point8_sf.position.coord[1] = 10.0;
point8_sf.position.coord[2] = 0.0;
PK_POINT_create(&point8_sf, &points[7]);
CExampleAppDoc::ExAppShowMessage("Created 3 planes, 10 lines and 8 points");
// Attach Geometry
face_senses[0] = PK_LOGICAL_true;
face_senses[1] = PK_LOGICAL_true;
face_senses[2] = PK_LOGICAL_true;
n_faces = 3;
n_edges = 10;
n_vertices = 8;
PK_VERTEX_attach_points(n_vertices, vertices, points);
PK_EDGE_attach_curves_o_m(options_attach);
PK_EDGE_attach_curves_2(n_edges, edges, curves, &options_attach, &tracking);
PK_FACE_attach_surfs(n_faces, faces, surfs, face_senses);
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;
}