int OCCWire::chamfer(std::vector<OCCVertex *> vertices, std::vector<double> distances) { int vertices_size = vertices.size(); int distances_size = distances.size(); BRepFilletAPI_MakeFillet2d MF; try { if (this->getShape().IsNull()) { StdFail_NotDone::Raise("Shapes is Null"); } MF.Init(BRepBuilderAPI_MakeFace(this->getWire())); // creat map of vertices TopTools_IndexedMapOfShape vertMap; for (unsigned i=0; i<vertices.size(); i++) vertMap.Add(vertices[i]->getShape()); bool first = true; TopoDS_Edge firstEdge, nextEdge; TopoDS_Vertex vertex; BRepTools_WireExplorer Ex1; for (Ex1.Init(this->getWire()); Ex1.More(); ) { if(first == true) { firstEdge = Ex1.Current(); first = false; } Ex1.Next(); //if the number of edges is odd don't proceed if(Ex1.More() == Standard_False) break; nextEdge = Ex1.Current(); //get the common vertex of the two edges if (!TopExp::CommonVertex(firstEdge, nextEdge, vertex)) { // disconnected wire first = true; continue; } if (vertMap.Contains(vertex)) { int i = vertMap.FindIndex(vertex) - 1; if (distances_size == 1) { // single distance MF.AddChamfer(firstEdge, nextEdge, distances[0], distances[0]); } else if (distances_size == vertices_size) { // distance given for each vertex MF.AddChamfer(firstEdge, nextEdge, distances[i], distances[i]); } else { StdFail_NotDone::Raise("distances argument has wrong size"); } } firstEdge = nextEdge; } // special case for closed wire if (isClosed()) { // find seam vertex TopoDS_Vertex aV1; TopExp::Vertices(this->getWire(), vertex, aV1); // check if seam vertex has chamfer value if (vertMap.Contains(vertex)) { int i = vertMap.FindIndex(vertex) - 1; // map vertices to edges to find edge pair TopTools_IndexedDataMapOfShapeListOfShape mapVertexEdge; TopExp::MapShapesAndAncestors(this->getWire(), TopAbs_VERTEX, TopAbs_EDGE, mapVertexEdge); const TopTools_ListOfShape& edges = mapVertexEdge.FindFromKey(vertex); firstEdge = TopoDS::Edge(edges.First()); nextEdge = TopoDS::Edge(edges.Last()); if (distances_size == 1) { // single distance MF.AddChamfer(firstEdge, nextEdge, distances[0], distances[0]); } else if (distances_size == vertices_size) { // distance given for each vertex MF.AddChamfer(firstEdge, nextEdge, distances[i], distances[i]); } else { StdFail_NotDone::Raise("distances argument has wrong size"); } } } if(MF.Status() != ChFi2d_IsDone) StdFail_NotDone::Raise("chamfer operation failed"); TopTools_IndexedMapOfShape aMap; TopExp::MapShapes(MF.Shape(), TopAbs_WIRE, aMap); if(aMap.Extent() != 1) StdFail_NotDone::Raise("chamfer result did not result in single wire");; //add edges to the wire BRepBuilderAPI_MakeWire wire; BRepTools_WireExplorer Ex2; for(Ex2.Init(TopoDS::Wire(aMap(1))); Ex2.More(); Ex2.Next()) { wire.Add(Ex2.Current()); } this->setShape(wire.Shape()); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to chamfer wire"); } return 0; } return 1; }
int OCCWire::fillet(std::vector<OCCVertex *> vertices, std::vector<double> radius) { int vertices_size = vertices.size(); int radius_size = radius.size(); BRepFilletAPI_MakeFillet2d MF; try { if (this->getShape().IsNull()) { StdFail_NotDone::Raise("Shapes is Null"); } MF.Init(BRepBuilderAPI_MakeFace(this->getWire())); for (unsigned i=0; i<vertices.size(); i++) { OCCVertex *vertex = vertices[i]; if (radius_size == 1) { // single radius MF.AddFillet(vertex->getVertex(), radius[0]); } else if (radius_size == vertices_size) { // radius given for each vertex MF.AddFillet(vertex->getVertex(), radius[i]); } else { StdFail_NotDone::Raise("radius argument has wrong size"); } } if(MF.Status() != ChFi2d_IsDone) StdFail_NotDone::Raise("fillet not completed"); BRepBuilderAPI_MakeWire wire; TopTools_IndexedMapOfShape aMap; BRepTools_WireExplorer Ex; TopExp::MapShapes(MF.Shape(), TopAbs_WIRE, aMap); if(aMap.Extent() != 1) StdFail_NotDone::Raise("Fillet operation did not result in single wire"); //add edges to the wire Ex.Clear(); for(Ex.Init(TopoDS::Wire(aMap(1))); Ex.More(); Ex.Next()) { wire.Add(Ex.Current()); } this->setShape(wire); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to fillet wire"); } return 0; } return 1; }