OpenCASCADE将图形保存至STEP文件

将TopoDS_Face类对象保存至STEP文件可使用如下代码:

	// 需要保存的图形
	TopoDS_Face Face;
	
	// 存放图形的容器
	Handle(TopTools_HSequenceOfShape) aHSequenceOfShape = new TopTools_HSequenceOfShape;
	aHSequenceOfShape->Clear();
	aHSequenceOfShape->Append(Face);

	IFSelect_ReturnStatus status;

	// 文件保存路径
	QString fileName = QFileDialog::getSaveFileName(QApplication::activeWindow(), QString::fromLocal8Bit("选择保存位置"), "Model.STEP","Text Files (*.STEP *.stp)");
	Standard_CString FileName = fileName.toLocal8Bit().data();

	// 保存文件
	STEPControl_StepModelType aValue = STEPControl_AsIs;
	STEPControl_Writer aWriter;

	for (Standard_Integer i = 1; i <= aHSequenceOfShape->Length(); i++)
	{
		//转换三维模型到aWriter
		status = aWriter.Transfer(aHSequenceOfShape->Value(i), aValue);
		if (status != IFSelect_RetDone)
			cout << "转化失败" << endl;
	}
	
	//保存数据到磁盘
	status = aWriter.Write(FileName);

你可能感兴趣的:(OpenCASCADE,c++)