bool WriteStepFile(const TopoDS_Shape& shape, const std::string filepath)
{
bool output_flag = true;
STEPControl_Writer writer;
Interface_Static::SetCVal("write.step.schema", "AP203");
IFSelect_ReturnStatus status = writer.Transfer(shape, STEPControl_AsIs);
if (status != IFSelect_RetDone) output_flag = false;
status = writer.Write(filepath.c_str());
if (status != IFSelect_RetDone) output_flag = false;
return output_flag;
}
int main()
{
std::string filePath = "C:/Users/14656/Desktop/Program/Open Cascade/Demo/";
// get the points
TColgp_HArray1OfPnt pointArr(1, 21);
gp_Pnt p1(-17.0162, 0, 280);
gp_Pnt p2(-22.1536, -3.41634, 277.45);
gp_Pnt p3(-20.6681, -4.98155, 277.45);
gp_Pnt p4(-19.03, -6.3841, 277.45);
gp_Pnt p5(-17.2566, -7.61345, 277.45);
gp_Pnt p6(-15.3654, -8.65899, 277.45);
gp_Pnt p7(-13.3761, -9.50423, 277.45);
gp_Pnt p8(-11.3099, -10.1266, 277.45);
gp_Pnt p9(-9.18854, -10.5033, 277.45);
gp_Pnt p10(-7.03537, -10.6153, 277.45);
gp_Pnt p11(-4.88287, -10.4614, 277.45);
gp_Pnt p12(-2.76636, -10.046, 277.45);
gp_Pnt p13(-0.72086, -9.37324, 277.45);
gp_Pnt p14(1.22832, -8.4578, 277.45);
gp_Pnt p15(3.06996, -7.33063, 277.45);
gp_Pnt p16(4.79384, -6.02448, 277.45);
gp_Pnt p17(6.39273, -4.57275, 277.45);
gp_Pnt p18(7.88223, -3.01022, 277.45);
gp_Pnt p19(9.28471, -1.36839, 277.45);
gp_Pnt p20(10.6082, 0.336572, 277.45);
gp_Pnt p21(9.77801, 0, 280);
pointArr.SetValue(1, p1);
pointArr.SetValue(2, p2);
pointArr.SetValue(3, p3);
pointArr.SetValue(4, p4);
pointArr.SetValue(5, p5);
pointArr.SetValue(6, p6);
pointArr.SetValue(7, p7);
pointArr.SetValue(8, p8);
pointArr.SetValue(9, p9);
pointArr.SetValue(10, p10);
pointArr.SetValue(11, p11);
pointArr.SetValue(12, p12);
pointArr.SetValue(13, p13);
pointArr.SetValue(14, p14);
pointArr.SetValue(15, p15);
pointArr.SetValue(16, p16);
pointArr.SetValue(17, p17);
pointArr.SetValue(18, p18);
pointArr.SetValue(19, p19);
pointArr.SetValue(20, p20);
pointArr.SetValue(21, p21);
// creat BSplin curve
Handle(TColgp_HArray1OfPnt) hhp = new TColgp_HArray1OfPnt(pointArr);
GeomAPI_Interpolate interp(hhp, false, Precision::Confusion());
interp.Perform();
Handle(Geom_BSplineCurve) bsc = interp.Curve();
TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge(bsc);
WriteStepFile(aEdge, filePath + "aEdge.step");
return 0;
}