void TestMkFillet(){ TopoDS_Shape Box = BRepPrimAPI_MakeBox(10., 10., 10.); BRepFilletAPI_MakeFillet mkFillet(Box); TopTools_IndexedMapOfShape edges; TopExp::MapShapes(Box, TopAbs_EDGE, edges); TopoDS_Edge edge = TopoDS::Edge(edges.FindKey(3)); mkFillet.Add(1., 1., edge); mkFillet.Build(); TopoDS_Shape result = mkFillet.Shape(); TopTools_IndexedMapOfShape faces; TopExp::MapShapes(Box, TopAbs_FACE, faces); TopoDS_Face face = TopoDS::Face(faces.FindKey(3)); TopTools_ListOfShape modified = mkFillet.Modified(face); TopTools_ListIteratorOfListOfShape modIt; for (int i=1; modIt.More(); modIt.Next(), i++){ TopoDS_Face curFace = TopoDS::Face(modIt.Value()); TopoNamingHelper::WriteShape(curFace, "00_02_ModifiedFace", i); } TopoNamingHelper::WriteShape(result, "00_00_FilletResult"); TopoNamingHelper::WriteShape(face, "00_01_BaseFace_3"); }
void Werkstuck::LZ(float endPunkt, float Rwz, float Lwz, float Rwz2) // прямое фрезерование по оси Z // endPunkt - конечная точка { Zwz=endPunkt; if (Zwz<H0) { gp_Pnt punkt_zent(Xwz,Ywz,Zwz); gp_Dir wzNormal = gp::DZ(); gp_Ax2 wzAchse(punkt_zent,wzNormal); BRepPrimAPI_MakeCylinder zLZ(wzAchse,Rwz,Lwz); TopoDS_Shape sLZ=zLZ.Shape(); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLZ); TopExp_Explorer aEdgeExplorer(sLZ , TopAbs_EDGE); while(aEdgeExplorer.More()) { TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLZ = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLZ); } }
TopoShape DuplicateCylinderFilletBug(){ TopoDS_Shape Box = BRepPrimAPI_MakeBox(10., 10., 10.); TopoDS_Shape Cylinder = BRepPrimAPI_MakeCylinder(2., 10.); // in FreeCAD, every operation first creates a blank TopoShape and then adds the // TopoDS_Shape to it TopoShape BoxShape, CylShape, FusedShape; // The current FreeCAD source will directly set TopoShape._Shape from all kinds of // places in the code. I have added a TopoShape::setShape method so that we can have // some control over this. Note that this method is overloaded a few times BoxShape.setShape(Box, "Primitive Box"); CylShape.setShape(Cylinder, "Primitive Cylinder"); // As of now, I don't see the TopoShape fuse being used. rather, the fuse is done // outside and then stored to the TopoShape BRepAlgoAPI_Fuse mkFuse(Box, Cylinder); // in my current implementation, I send the FIRST TopoShape from the Fuse operation to // the setShape, and copy it's _TopoNamer FusedShape.setShape(BoxShape, mkFuse); // Now let's select an edge, then fillet it TopoDS_Shape BaseShape = mkFuse.Shape(); // Finaly, 'Select' the edge std::string selectionLabel = FusedShape.selectEdge(3); std::cout << "Selected Edge Node = " << selectionLabel << std::endl; // Write out the current-state of things //FusedShape.OCCDeepDump(); FusedShape.WriteTNamingNode("0:1:1", "01_Selected", true); FusedShape.WriteTNamingNode("0:2", "02_BaseBox", false); FusedShape.WriteTNamingNode("0:3", "03_BaseCyl", false); FusedShape.WriteTNamingNode("0:4", "04_FusedShape", false); // Fillet the selected edge TopoDS_Edge RecoveredEdge = FusedShape.getSelectedEdge(selectionLabel); BRepFilletAPI_MakeFillet mkFillet(FusedShape.getShape()); mkFillet.Add(2., 2., RecoveredEdge); mkFillet.Build(); // Record the Fillet Operation TopoShape FilletedShape;// = mkFillet.Shape(); FilletedShape.setShape(FusedShape, mkFillet); // write out the latest node FusedShape.WriteTNamingNode("0:5", "05_FilletedShape", false); //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- // FUSE DONE, ABOUT TO RESIZE THE CYLINDER //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- // resize the cylinder. I believe FreeCAD just creates a whole new cylinder TopoDS_Shape Cylinder2 = BRepPrimAPI_MakeCylinder(2., 15.); TopoShape NewCylShape; NewCylShape.setShape(Cylinder2); // Now the FreeCAD algorithms figure out that Fuse and Fillet need to be re-run // First, re-do Fuse TopoShape ReFusedShape; BRepAlgoAPI_Fuse mkFuse2(BoxShape.getShape(), NewCylShape.getShape()); ReFusedShape.setShape(BoxShape, mkFuse2); BRepFilletAPI_MakeFillet mkFillet2(ReFusedShape.getShape()); // grab the selected edge from our tree to re-fillet TopoDS_Edge RecoveredEdge2 = ReFusedShape.getSelectedEdge(selectionLabel); // now re-do fillet mkFillet2.Add(2., 2., RecoveredEdge); mkFillet2.Build(); // Record the Fillet Operation TopoShape ReFilletedShape;// = mkFillet2.Shape(); ReFilletedShape.setShape(ReFusedShape, mkFillet2); // Write out some more shapes FusedShape.WriteTNamingNode("0:6", "06_PartOfFusionMaybe", false); FusedShape.WriteTNamingNode("0:7", "07_ReFusion", false); FusedShape.WriteTNamingNode("0:8", "08_ReFillet", false); return FusedShape; }
void Werkstuck::LY(float endPunkt, float Rwz, float Lwz, float Rwz2) // прямое фрезерование по оси Х // endPunkt - конечная точка { if (Zwz<H0) { gp_Pnt punkt1(Xwz-Rwz,Ywz,Zwz); gp_Pnt punkt2(Xwz+Rwz,Ywz,Zwz); gp_Pnt punkt3(Xwz+Rwz,endPunkt,Zwz); gp_Pnt punkt4(Xwz,endPunkt,Zwz); if (endPunkt>=Ywz) punkt4.SetY(endPunkt+Rwz); else punkt4.SetY(endPunkt-Rwz); gp_Pnt punkt5(Xwz-Rwz,endPunkt,Zwz); Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2); Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3); Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeArcOfCircle(punkt3,punkt4 ,punkt5); Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt5 , punkt1); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2); TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3); TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4); TopoDS_Wire Basis = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4); TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis); if (firstRun) { fBasis = FlacheBasis; firstRun = false; } else { fBasis = BRepAlgo_Fuse(fBasis, FlacheBasis); gp_Vec PrismVec(0 , 0 , Lwz); TopoDS_Shape sLY = BRepPrimAPI_MakePrism(fBasis , PrismVec); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLY); TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE); while(aEdgeExplorer.More()) { TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLY = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLY); firstRun = true; } /*gp_Vec PrismVec(0 , 0 , Lwz); TopoDS_Shape sLY = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLY); TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE); while(aEdgeExplorer.More()){ TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLY = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLY);*/ } Ywz=endPunkt; }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { // Profile : Define Support Points gp_Pnt aPnt1(-myWidth / 2., 0, 0); gp_Pnt aPnt2(-myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt3(0, -myThickness / 2., 0); gp_Pnt aPnt4(myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt5(myWidth / 2., 0, 0); // Profile : Define the Geometry Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3,aPnt4); Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2); Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5); // Profile : Define the Topology TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1); TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle); TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3); // Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf aTrsf; aTrsf.SetMirror(xAxis); BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf); TopoDS_Shape aMirroredShape = aBRepTrsf.Shape(); TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape); BRepBuilderAPI_MakeWire mkWire; mkWire.Add(aWire); mkWire.Add(aMirroredWire); TopoDS_Wire myWireProfile = mkWire.Wire(); // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Body : Apply Fillets BRepFilletAPI_MakeFillet mkFillet(myBody); TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE); while(anEdgeExplorer.More()) { TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current()); //Add edge to fillet algorithm mkFillet.Add(myThickness / 12., anEdge); anEdgeExplorer.Next(); } myBody = mkFillet.Shape(); // Body : Add the Neck gp_Pnt neckLocation(0, 0, myHeight); gp_Dir neckAxis = gp::DZ(); gp_Ax2 neckAx2(neckLocation, neckAxis); Standard_Real myNeckRadius = myThickness / 4.; Standard_Real myNeckHeight = myHeight / 10.; BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight); TopoDS_Shape myNeck = MKCylinder.Shape(); myBody = BRepAlgoAPI_Fuse(myBody, myNeck); // Body : Create a Hollowed Solid TopoDS_Face faceToRemove; Standard_Real zMax = -1; for(TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) { TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); // Check if <aFace> is the top face of the bottle�s neck Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace); if(aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface); gp_Pnt aPnt = aPlane->Location(); Standard_Real aZ = aPnt.Z(); if(aZ > zMax) { zMax = aZ; faceToRemove = aFace; } } } TopTools_ListOfShape facesToRemove; facesToRemove.Append(faceToRemove); myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1.e-3); // Threading : Create Surfaces Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99); Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05); // Threading : Define 2D Curves gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.); gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.); gp_Ax2d anAx2d(aPnt, aDir); Standard_Real aMajor = 2. * M_PI; Standard_Real aMinor = myNeckHeight / 10; Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor); Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4); Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI); Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI); gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2); // Threading : Build Edges and Wires TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1); TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1); TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2); TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2); TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1); TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2); BRepLib::BuildCurves3d(threadingWire1); BRepLib::BuildCurves3d(threadingWire2); // Create Threading BRepOffsetAPI_ThruSections aTool(Standard_True); aTool.AddWire(threadingWire1); aTool.AddWire(threadingWire2); aTool.CheckCompatibility(Standard_False); TopoDS_Shape myThreading = aTool.Shape(); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound (aRes); aBuilder.Add (aRes, myBody); aBuilder.Add (aRes, myThreading); return aRes; }