Exemple #1
0
        /// <summary>
        /// generate a hollowed cylinder
        /// </summary>
        /// <param name="myDiameter">diameter</param>
        /// <param name="myLength">length</param>
        /// <param name="myThickness">thickness</param>
        public HollowedCylinder(double myDiameter, double myLength, double myThickness)
        {
            // external part
            BRepPrimAPI_MakeCylinder aMakeCylinder = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myDiameter / 2, myLength);
            TopoDS_Shape             myBody        = aMakeCylinder.Shape();

            // internal part
            BRepPrimAPI_MakeCylinder aMakeHollowedPart = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myDiameter / 2 - myThickness, myLength);
            TopoDS_Shape             hollowedPart      = aMakeHollowedPart.Shape();

            // cut
            BOPAlgo_BOP test = new BOPAlgo_BOP();

            test.AddArgument(myBody);
            TopTools_ListOfShape LS = new TopTools_ListOfShape();

            LS.Append(hollowedPart);
            test.SetTools(LS);
            test.SetRunParallel(true);
            test.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            test.Perform();
            myBody = test.Shape();



            // ______________ triangulation ______________
            myFaces = Triangulation(myBody, 0.7f);
        }
Exemple #2
0
        public override void Build()
        {
            // convert values from UnitsNet
            double diam = diameter.Meters;
            double wt   = wallthickness.Meters;
            double len  = length.Meters;

            // external part
            BRepPrimAPI_MakeCylinder aMakeCylinder = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), diam / 2, len);
            TopoDS_Shape             myBody        = aMakeCylinder.Shape();

            // internal part
            BRepPrimAPI_MakeCylinder aMakeHollowedPart = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), diam / 2 - wt, len);
            TopoDS_Shape             hollowedPart      = aMakeHollowedPart.Shape();

            // cut
            BOPAlgo_BOP test = new BOPAlgo_BOP();

            test.AddArgument(myBody);
            TopTools_ListOfShape LS = new TopTools_ListOfShape();

            LS.Append(hollowedPart);
            test.SetTools(LS);
            test.SetRunParallel(true);
            test.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            test.Perform();
            myBody = test.Shape();

            // ______________ triangulation ______________
            SetMyFaces(Triangulation(myBody, 0.7f));
        }
Exemple #3
0
        /// <summary>
        /// generate a cylinder
        /// </summary>
        /// <param name="myDiameter">diameter</param>
        /// <param name="myHeight">height</param>
        public Cylinder(double myDiameter, double myHeight)
        {
            BRepPrimAPI_MakeCylinder aMakeCylinder = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myDiameter / 2, myHeight);
            TopoDS_Shape             myBody        = aMakeCylinder.Shape();


            // ______________ triangulation ______________
            myFaces = Triangulation(myBody, 0.7f);
        }
Exemple #4
0
        /// <summary>
        /// create a hollowed cylinder that is pierced with another cylinder
        /// </summary>
        /// <param name="myRadius">radius of the big cylinder</param>
        /// <param name="myHeight">height of the big cylinder</param>
        /// <param name="myThickness">thickness of the big cylinder</param>
        /// <param name="myRadius2">radius of the small cylinder</param>
        /// <param name="myHeight2">height of the small cylinder</param>
        /// <param name="myThickness2">thickness of the small cylinder</param>
        /// <param name="pierceHeight">height on which we pierce</param>
        public HollowedCylinderPiercedWithHollowedCylinder(double myRadius, double myHeight, double myThickness, double myRadius2, double myHeight2, double myThickness2, double pierceHeight)
        {
            //  _______first cylinder (the big one) _______
            BRepPrimAPI_MakeCylinder aMakeCylinder = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myRadius, myHeight);
            TopoDS_Shape             myBody        = aMakeCylinder.Shape();
            TopoDS_Solid             mySolid       = aMakeCylinder.Solid();


            // inner cylinder of the bigger cylinder to be hollowed
            BRepPrimAPI_MakeCylinder aMakeHollowedPart = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myRadius - myThickness, myHeight);
            TopoDS_Shape             hollowedPart      = aMakeHollowedPart.Shape();

            // hollowing the bigger cylinder
            BOPAlgo_BOP test = new BOPAlgo_BOP();

            test.AddArgument(mySolid);
            TopTools_ListOfShape LS = new TopTools_ListOfShape();

            LS.Append(hollowedPart);
            test.SetTools(LS);
            test.SetRunParallel(true);
            test.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            test.Perform();
            myBody = test.Shape();


            // _______second cylinder (the smaller one) _______
            BRepPrimAPI_MakeCylinder aMakeCylinder2 = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, -myThickness + Math.Sqrt(myRadius * myRadius - myRadius2 * myRadius2), pierceHeight), new gp_Dir(0, 1, 0)), myRadius2, myHeight2);
            TopoDS_Shape             myBody2        = aMakeCylinder2.Shape();
            TopoDS_Solid             mySolid2       = aMakeCylinder2.Solid();


            // inner cylinder of the smaller cylinder to be hollowed
            BRepPrimAPI_MakeCylinder aMakeHollowedPart2 = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, -myThickness + Math.Sqrt(myRadius * myRadius - myRadius2 * myRadius2), pierceHeight), new gp_Dir(0, 1, 0)), myRadius2 - myThickness2, myHeight2);
            TopoDS_Shape             hollowedPart2      = aMakeHollowedPart2.Shape();


            // smaller cylinder hollowed
            BOPAlgo_BOP test2 = new BOPAlgo_BOP();

            test2.AddArgument(mySolid2);
            TopTools_ListOfShape LS2 = new TopTools_ListOfShape();

            LS2.Append(hollowedPart2);
            test2.SetTools(LS2);
            test2.SetRunParallel(true);
            test2.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            test2.Perform();
            TopoDS_Shape hollowedSmall = test2.Shape();

            // piercing
            BOPAlgo_BOP piercer = new BOPAlgo_BOP();

            piercer.AddArgument(myBody);
            TopTools_ListOfShape LSP = new TopTools_ListOfShape();

            LSP.Append(hollowedPart2);
            piercer.SetTools(LSP);
            piercer.SetRunParallel(true);
            piercer.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            piercer.Perform();
            myBody = piercer.Shape();


            // adding the tube
            BOPAlgo_BOP adder = new BOPAlgo_BOP();

            adder.AddArgument(myBody);
            TopTools_ListOfShape LSA = new TopTools_ListOfShape();

            LSA.Append(hollowedSmall);
            adder.SetTools(LSA);
            adder.SetRunParallel(true);
            adder.SetOperation(BOPAlgo_Operation.BOPAlgo_FUSE);
            adder.Perform();
            myBody = adder.Shape();//*/



            // _______triangulation_______
            myFaces = Triangulation(myBody, 0.007f);
        }
Exemple #5
0
        /// <summary>
        /// create a screw
        /// </summary>
        /// <param name="widthBase">length of the base</param>
        /// <param name="diameter">diameter of the screwed part</param>
        /// <param name="lengthVis">length of the screwed part</param>
        /// <param name="pas">distance travelled by the helicoidal part after 2*pi</param>
        /// <param name="heightBase">height of the base</param>
        /// <param name="profondeurSillon">depth of the screw</param>
        /// <param name="longueurSillon">length of the helicoidal part</param>
        public Vis(double widthBase, double diameter, double lengthVis, double pas, double heightBase, double profondeurSillon, double longueurSillon)
        {                                                     // it was hard to parameterize it "correctly", consider taking a screenshot before having fun in modifying it
            double param6  = 2;                               // pas / (2 * Math.PI); // pas trop grand please
            double param10 = pas / (Math.PI / 3);             // c'est pour definir le pas
            double param9  = 0;                               // -param10/2; // position de la vis ?
            double param1  = lengthVis - longueurSillon / 2;  // position du centre de la partie helicoidale par rapport au bout pointu de la vis

            double aMinor = 0.05;                             // epaisseur de la rainure
            double aMajor = (longueurSillon / pas) * Math.PI; // un pi par tour donc 2*pi = 2 tours

            // Base

            /*Cylinder myBase = new Cylinder(widthBase / 2, heightBase);
             * myBase.Translate(new Pnt(0, 0, -heightBase));//*/
            BRepPrimAPI_MakeCylinder aMakeCylinder = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, -heightBase), new gp_Dir(0, 0, 1)), widthBase / 2, heightBase);
            TopoDS_Shape             myBase        = aMakeCylinder.Shape();

            // helicoidal part
            //Cylinder neck = new Cylinder(diameter / 2, lengthVis);
            BRepPrimAPI_MakeCylinder aMakeCylinder2 = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), diameter / 2, lengthVis);
            TopoDS_Shape             neck           = aMakeCylinder2.Shape();

            //threading: define 2d curves
            double   depart = param1;
            gp_Pnt2d aPnt   = new gp_Pnt2d(2 * Math.PI, param9);
            gp_Dir2d aDir   = new gp_Dir2d(2 * Math.PI, param10);
            gp_Ax2d  anAx2d = new gp_Ax2d(aPnt, aDir);

            //double aMinor = longueurSillon/5; // epaisseur de la rainure
            Geom2d.Geom2d_Ellipse      anEllipse1 = new Geom2d.Geom2d_Ellipse(anAx2d, aMajor, aMinor);
            Geom2d.Geom2d_Ellipse      anEllipse2 = new Geom2d.Geom2d_Ellipse(anAx2d, aMajor, aMinor / param6);
            Geom2d.Geom2d_TrimmedCurve anArc1     = new Geom2d.Geom2d_TrimmedCurve(anEllipse1, 0, Math.PI);
            Geom2d.Geom2d_TrimmedCurve anArc2     = new Geom2d.Geom2d_TrimmedCurve(anEllipse2, 0, Math.PI);
            gp_Pnt2d          anEllipsePnt1       = anEllipse1.Value(0);
            gp_Pnt2d          anEllipsePnt2       = anEllipse1.Value(Math.PI);
            GCE2d_MakeSegment aMakeSegment        = new GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2);

            Geom2d.Geom2d_TrimmedCurve aSegment = aMakeSegment.Value();
            //threading: build edges and wires
            Geom_CylindricalSurface aCyl1 = new Geom_CylindricalSurface(new gp_Ax3(new gp_Ax2(new gp_Pnt(0, 0, depart), new gp_Dir(0, 0, 1))), (diameter / 2) * 0.99);
            Geom_CylindricalSurface aCyl2 = new Geom_CylindricalSurface(new gp_Ax3(new gp_Ax2(new gp_Pnt(0, 0, depart), new gp_Dir(0, 0, 1))), (diameter / 2) * (0.99 + profondeurSillon));
            //
            BRepBuilderAPI_MakeEdge aMakeEdge = new BRepBuilderAPI_MakeEdge(anArc1, aCyl1);

            aMakeEdge.Build();
            TopoDS_Edge anEdge1OnSurf1 = aMakeEdge.Edge();

            //
            aMakeEdge = new BRepBuilderAPI_MakeEdge(aSegment, aCyl1);
            aMakeEdge.Build();
            TopoDS_Edge anEdge2OnSurf1 = aMakeEdge.Edge();

            //
            aMakeEdge = new BRepBuilderAPI_MakeEdge(anArc2, aCyl2);
            aMakeEdge.Build();
            TopoDS_Edge anEdge1OnSurf2 = aMakeEdge.Edge();

            //
            aMakeEdge = new BRepBuilderAPI_MakeEdge(aSegment, aCyl2);
            aMakeEdge.Build();
            TopoDS_Edge anEdge2OnSurf2 = aMakeEdge.Edge();
            //
            BRepBuilderAPI_MakeWire aMakeWire = new BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1);

            aMakeWire.Build();
            TopoDS_Wire threadingWire1 = aMakeWire.Wire();

            aMakeWire = new BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2);
            aMakeWire.Build();
            TopoDS_Wire threadingWire2 = aMakeWire.Wire();

            BRepLib.BRepLib.BuildCurves3d(threadingWire1);
            BRepLib.BRepLib.BuildCurves3d(threadingWire2);
            //create threading
            BRepOffsetAPI_ThruSections aTool = new BRepOffsetAPI_ThruSections(true);

            aTool.AddWire(threadingWire1);
            aTool.AddWire(threadingWire2);
            aTool.CheckCompatibility(false);
            TopoDS_Shape myThreading = aTool.Shape();


            // _______fuse_______
            BOPAlgo_BOP adder = new BOPAlgo_BOP();

            adder.AddArgument(myBase);
            TopTools_ListOfShape LSA = new TopTools_ListOfShape();

            LSA.Append(neck);
            adder.SetTools(LSA);
            adder.SetRunParallel(true);
            adder.SetOperation(BOPAlgo_Operation.BOPAlgo_FUSE);
            adder.Perform();
            TopoDS_Shape myBody = adder.Shape();

            // _______fuse_______
            BOPAlgo_BOP adder2 = new BOPAlgo_BOP();

            adder2.AddArgument(myBody);
            TopTools_ListOfShape LSA2 = new TopTools_ListOfShape();

            LSA2.Append(myThreading);
            adder2.SetTools(LSA2);
            adder2.SetRunParallel(true);
            adder2.SetOperation(BOPAlgo_Operation.BOPAlgo_FUSE);
            adder2.Perform();
            myBody = adder2.Shape();

            // _______triangulation_______
            myFaces = Triangulation(myBody, 0.007f);
        }
        public override void Build()
        {
            // convert values from UnitsNet
            double myRad    = myRadius.Meters;
            double myH      = myHeight.Meters;
            double myThick  = myThickness.Meters;
            double myRad2   = myRadius2.Meters;
            double myH2     = myHeight2.Meters;
            double myThick2 = myThickness2.Meters;
            double pierceH  = pierceHeight.Meters;


            //  _______first cylinder (the big one) _______
            BRepPrimAPI_MakeCylinder aMakeCylinder = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myRad, myH);
            TopoDS_Shape             myBody        = aMakeCylinder.Shape();
            TopoDS_Solid             mySolid       = aMakeCylinder.Solid();


            // inner cylinder of the bigger cylinder to be hollowed
            BRepPrimAPI_MakeCylinder aMakeHollowedPart = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), myRad - myThick, myH);
            TopoDS_Shape             hollowedPart      = aMakeHollowedPart.Shape();

            // hollowing the bigger cylinder
            BOPAlgo_BOP test = new BOPAlgo_BOP();

            test.AddArgument(mySolid);
            TopTools_ListOfShape LS = new TopTools_ListOfShape();

            LS.Append(hollowedPart);
            test.SetTools(LS);
            test.SetRunParallel(true);
            test.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            test.Perform();
            myBody = test.Shape();


            // _______second cylinder (the smaller one) _______
            BRepPrimAPI_MakeCylinder aMakeCylinder2 = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, -myThick + Math.Sqrt(myRad * myRad - myRad2 * myRad2), pierceH), new gp_Dir(0, 1, 0)), myRad2, myH2);
            TopoDS_Shape             myBody2        = aMakeCylinder2.Shape();
            TopoDS_Solid             mySolid2       = aMakeCylinder2.Solid();


            // inner cylinder of the smaller cylinder to be hollowed
            BRepPrimAPI_MakeCylinder aMakeHollowedPart2 = new BRepPrimAPI_MakeCylinder(new gp_Ax2(new gp_Pnt(0, -myThick + Math.Sqrt(myRad * myRad - myRad2 * myRad2), pierceH), new gp_Dir(0, 1, 0)), myRad2 - myThick2, myH2);
            TopoDS_Shape             hollowedPart2      = aMakeHollowedPart2.Shape();


            // smaller cylinder hollowed
            BOPAlgo_BOP test2 = new BOPAlgo_BOP();

            test2.AddArgument(mySolid2);
            TopTools_ListOfShape LS2 = new TopTools_ListOfShape();

            LS2.Append(hollowedPart2);
            test2.SetTools(LS2);
            test2.SetRunParallel(true);
            test2.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            test2.Perform();
            TopoDS_Shape hollowedSmall = test2.Shape();

            // piercing
            BOPAlgo_BOP piercer = new BOPAlgo_BOP();

            piercer.AddArgument(myBody);
            TopTools_ListOfShape LSP = new TopTools_ListOfShape();

            LSP.Append(hollowedPart2);
            piercer.SetTools(LSP);
            piercer.SetRunParallel(true);
            piercer.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            piercer.Perform();
            myBody = piercer.Shape();


            // adding the tube
            BOPAlgo_BOP adder = new BOPAlgo_BOP();

            adder.AddArgument(myBody);
            TopTools_ListOfShape LSA = new TopTools_ListOfShape();

            LSA.Append(hollowedSmall);
            adder.SetTools(LSA);
            adder.SetRunParallel(true);
            adder.SetOperation(BOPAlgo_Operation.BOPAlgo_FUSE);
            adder.Perform();
            myBody = adder.Shape();//*/



            // _______triangulation_______
            SetMyFaces(Triangulation(myBody, 0.007f));
        }