In the previous exemple the wires were composed by one edge and this has hidden one potential issue. If one want to insert a square for the central boundary :
The inner wire should have connected edges, to do this the easiest way is to use a tool class from Toolkit TKShHealing : ShapeAnalysis_FreeBounds::ConnectEdgesToWires, C.f. OpenCASCADE’s technical documentation about this tool for further informations. a basic exemple about using this tool is given between the lines 20 to 33 of the code proposed below. The rest of the code is similar to the previous exemple
Note the use of BRepBuilderAPI_MakeEdge to easily create an edge from 2 points, a deeper look about this class in the help will show you other way to build edge from other geometric primitives.
//Init brep builder utility BRep_Builder aBuilder; //Creation an inifite face lying on a plane gp_Pln planeXY; TopoDS_Face aFace = BRepBuilderAPI_MakeFace(planeXY); //Crationg to wires to bound the face gp_Ax2 Ax2(gp_Pnt(),gp_Dir(0,0,1),gp_Dir(1,0,0)); TopoDS_Wire wireIn; /*********************************** * The above commented lines are not working * the edges need to be glued ***********************************/ // aBuilder.MakeWire(wireIn); // aBuilder.Add(wireIn,BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,0),gp_Pnt(1,0,0))); // aBuilder.Add(wireIn,BRepBuilderAPI_MakeEdge(gp_Pnt(1,0,0),gp_Pnt(1,1,0))); // aBuilder.Add(wireIn,BRepBuilderAPI_MakeEdge(gp_Pnt(1,1,0),gp_Pnt(0,1,0))); // aBuilder.Add(wireIn,BRepBuilderAPI_MakeEdge(gp_Pnt(0,1,0),gp_Pnt(0,0,0))); // bool isWireClosed = wireIn.Closed(); Handle_TopTools_HSequenceOfShape edgesWire = new TopTools_HSequenceOfShape; Handle_TopTools_HSequenceOfShape myWires = new TopTools_HSequenceOfShape; edgesWire->Append(BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,0),gp_Pnt(1,0,0))); edgesWire->Append(BRepBuilderAPI_MakeEdge(gp_Pnt(1,0,0),gp_Pnt(1,1,0))); edgesWire->Append(BRepBuilderAPI_MakeEdge(gp_Pnt(1,1,0),gp_Pnt(0,1,0))); edgesWire->Append(BRepBuilderAPI_MakeEdge(gp_Pnt(0,1,0),gp_Pnt(0,0,0))); double tol =1e-3; ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edgesWire,tol,false,myWires); if(myWires->Length()){ wireIn = TopoDS::Wire(myWires->Value(1));//By construction only one wire should be found //Note hte conversion from shape to wire } gp_Trsf translation; translation.SetTranslation(gp_Vec(-0.5,-0.5,0)); wireIn.Move(translation); TopoDS_Wire wireOut = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Circ(Ax2,2))); //Add outer bound to the face aBuilder.Add(aFace,wireOut); //Add inner bound. Must be reversed aBuilder.Add(aFace,wireIn.Reversed()); //Add more inner boundaries int nCuts=30; for(int i = 0 ; i < nCuts ; i++){ gp_Ax2 Ax(gp_Pnt(1.5,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0)); TopoDS_Wire wire = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Circ(Ax,0.1))); gp_Trsf rot; rot.SetRotation(gp_Ax1(gp_Pnt(),gp_Dir(0,0,1)),2.*M_PI*i/(nCuts-1.)); wire.Move(rot); aBuilder.Add(aFace,wire.Reversed()); }