jianbaoxia
CAD master
Hi Bros, I'm JianBaoxia.
After I finally the wire build with you help yestoday, I keep try to use it to build a TopoDS_Face,
however, there seems get something wrong without error raise.
I get a TopoDS_Face from file "cylFaceForCut.step"(Fig 1), and get TopoDS_Wire from file "wire.step"(Fig 2), their relationship is show in file "face_wire.step"(Fig 3).
I try to build a face through the TopoDS_Face and TopoDS_Wire get from file.
After use "BRepBuilderAPI_MakeFace", it seems success, however,when try to output the face as .step or .brep, it failed.
I think may be failed in BRepBuilderAPI_MakeFace, but the code seems normal.
There are Fig 1~3 below:
There is my demo:
Hope for youe suggestion.
After I finally the wire build with you help yestoday, I keep try to use it to build a TopoDS_Face,
however, there seems get something wrong without error raise.
I get a TopoDS_Face from file "cylFaceForCut.step"(Fig 1), and get TopoDS_Wire from file "wire.step"(Fig 2), their relationship is show in file "face_wire.step"(Fig 3).
I try to build a face through the TopoDS_Face and TopoDS_Wire get from file.
After use "BRepBuilderAPI_MakeFace", it seems success, however,when try to output the face as .step or .brep, it failed.
I think may be failed in BRepBuilderAPI_MakeFace, but the code seems normal.
There are Fig 1~3 below:
There is my demo:
Code:
TopoDS_Shape ReadStepFile(const std::string& filepath)
{
STEPControl_Reader reader;
reader.ReadFile(filepath.c_str());
reader.TransferRoots();
TopoDS_Shape shape = reader.OneShape();
return shape;
}
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/";
TopoDS_Shape cylShape = ReadStepFile(filePath + "cylFaceForCut.step");
TopoDS_Shape wireShape = ReadStepFile(filePath + "wire.step");
TopoDS_Face cyl; // the face for cut
for (TopExp_Explorer exp(cylShape, TopAbs_FACE); exp.More(); exp.Next())
cyl = TopoDS::Face(exp.Current());
BRepBuilderAPI_MakeWire mkWire;
for (TopExp_Explorer exp(wireShape, TopAbs_EDGE); exp.More(); exp.Next())
mkWire.Add(TopoDS::Edge(exp.Current()));
TopoDS_Wire wire = mkWire.Wire(); // the wire to cut a face
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(cyl, wire); // build face
//! I try to output the face I build for check, and failed
// WriteStepFile(aFace, filePath + "aFace.step");
std::filebuf aFileBuf;
std::ostream aStream(&aFileBuf);
if (aFileBuf.open(filePath + "aFace.brep", ios::out))
{
BRepTools::Write(aFace, aStream);
}
aFileBuf.close();
return 0;
}
Hope for youe suggestion.