How to generate the desired wire

When I cut the figure, I just want to get the outermost cut outline of the remaining figure, but I never know the right way to do it.
BRepAlgoAPI_Section section(tube,ParentBox,Standard_True);
section.ComputePCurveOn1(Standard_True);
section.Approximation(Standard_True);
section.Build();
OuterWiredraw(section);
void MyOcct::OuterWiredraw(TopoDS_Shape selectshape)
{
ShapeAnalysis_FreeBounds freeBounds;
Handle(TopTools_HSequenceOfShape) edgesList = new TopTools_HSequenceOfShape();
Handle(TopTools_HSequenceOfShape) wiresList = new TopTools_HSequenceOfShape();
for (TopExp_Explorer explorer(selectshape, TopAbs_EDGE); explorer.More(); explorer.Next())
{
const TopoDS_Edge& edge = TopoDS::Edge(explorer.Current());
edgesList->Append(edge);
}
Standard_Real tolerance = 0.001;
Standard_Boolean shared = Standard_False;

freeBounds.ConnectEdgesToWires(edgesList, tolerance, shared, wiresList);

int flag = 0;
if(wiresList->Length() < 4)
{
TopoDS_Wire wire = TopoDS::Wire(wiresList->Value(1));
mwire.append(wire);
if(0 == flag)
{
Handle(AIS_Shape) awire = new AIS_Shape(wire);
awire->SetColor(Quantity_NOC_GREEN1);
awire->SetWidth(3);
mAiswire.append(awire);
myOccView->getContext()->Display(awire,Standard_True);
myOccView->getContext()->UpdateCurrentViewer();
}
}
else
{
TopoDS_Wire wire = TopoDS::Wire(wiresList->Value(1));
mwire.append(wire);

Handle(AIS_Shape) awire = new AIS_Shape(wire);
awire->SetColor(Quantity_NOC_GREEN1);
awire->SetWidth(3);
mAiswire.append(awire);
myOccView->getContext()->Display(awire,Standard_True);
myOccView->getContext()->UpdateCurrentViewer();

TopoDS_Wire wire1 = TopoDS::Wire(wiresList->Value(2));
mwire.append(wire1);

Handle(AIS_Shape) awire1 = new AIS_Shape(wire1);
awire1->SetColor(Quantity_NOC_GREEN1);
awire1->SetWidth(3);
mAiswire.append(awire1);
myOccView->getContext()->Display(awire1,Standard_True);
myOccView->getContext()->UpdateCurrentViewer();

}
}
}
This is how I generate the outline, but if the second cut overlaps part of the previous one,it is not gonna get what I want.
somebody can help me,thanks

Yang Yang's picture

This is a picture of the situation

Attachments: