在OCC中,将TopoDS_Edge转换为TopoDS_Wire
std::vector<TopoDS_Wire> GeoCommandTool::bulidWire(std::list<TopoDS_Edge>& edgeList)
{
std::vector<TopoDS_Wire> wires;
while (edgeList.size() > 0)
{
BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(edgeList.front());
edgeList.pop_front();
TopoDS_Wire new_wire = mkWire.Wire(); // current new wire
//只要有一条无法连接成线就失败了
bool found = false;
do {
found = false;
for (std::list<TopoDS_Edge>::iterator pE = edgeList.begin(); pE != edgeList.end(); ++pE)
{
mkWire.Add(*pE);
//检测没问题就直接添加
if (mkWire.Error() != BRepBuilderAPI_DisconnectedWire)
{
found = true;
edgeList.erase(pE);
new_wire = mkWire.Wire();
break;
}
}
} while (found);
//修复线
ShapeFix_Wire aFix;
//设置精度
aFix.SetPrecision(Precision::Confusion());
aFix.Load(new_wire);
//重新排序。修复操作一般都希望边是有序的
aFix.FixReorder();
aFix.FixConnected();
aFix.FixClosed();
wires.push_back(aFix.Wire());
}
return wires;
}