Пример #1
0
        //--------------------------------------------------------------------------------------------------

        bool _BuildResult(MakeContext context)
        {
            var shapeListArgs = new TopTools_ListOfShape();

            shapeListArgs.Append(context.ModifiedTargetShape ?? context.TargetShape);

            var shapeListTools = new TopTools_ListOfShape();

            if (context.BendSectionShape != null)
            {
                shapeListTools.Append(context.BendSectionShape);
            }
            if (context.FlangeShape != null)
            {
                shapeListTools.Append(context.FlangeShape);
            }

            var fuseOp = new BRepAlgoAPI_Fuse();

            fuseOp.SetArguments(shapeListArgs);
            fuseOp.SetTools(shapeListTools);
            fuseOp.SetGlue(BOPAlgo_GlueEnum.BOPAlgo_GlueShift);
            fuseOp.Build();
            if (!fuseOp.IsDone())
            {
                Messages.Error("Failed fusing generated geometry.");
                return(false);
            }

            context.ResultShape = fuseOp.Shape();

            if (context.BendSectionShape != null)
            {
                AddNamedSubshapes("Bend", context.BendSectionShape, fuseOp);
            }
            if (context.FlangeShape != null)
            {
                AddNamedSubshapes("Flange", context.FlangeShape, fuseOp);
            }
            if (context.StartGapFace != null)
            {
                AddNamedSubshapes("StartGap", context.StartGapFace, fuseOp);
                if (context.EndGapFace == null)
                {
                    AddNamedSubshapes("EndGap", context.StartGapFace, fuseOp);
                }
            }
            if (context.EndGapFace != null)
            {
                AddNamedSubshapes("EndGap", context.EndGapFace, fuseOp);
                if (context.StartGapFace == null)
                {
                    AddNamedSubshapes("StartGap", context.EndGapFace, fuseOp);
                }
            }

            UpdateModifiedSubshapes(context.ModifiedTargetShape ?? context.TargetShape, fuseOp);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// create a hollowed cone beheaded
        /// </summary>
        /// <param name="largeEndDiameter">diameter of the base</param>
        /// <param name="totalHeight">height of the cone</param>
        /// <param name="smallEndDiameter">radius of the top</param>
        /// <param name="wallThickness">thickness</param>
        public Cone(double wallThickness, double largeEndDiameter, double smallEndDiameter, double totalHeight, double useless1, double useless2, double useless3, double useless4, double useless5)
        {
            // external part
            BRepPrimAPI_MakeCone aMakeCone = new BRepPrimAPI_MakeCone(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), largeEndDiameter / 2, smallEndDiameter / 2, totalHeight);
            TopoDS_Shape         myBody    = aMakeCone.Shape();
            TopoDS_Solid         mySolid   = aMakeCone.Solid();

            // internal part
            BRepPrimAPI_MakeCone aMakeHollowedPart = new BRepPrimAPI_MakeCone(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), largeEndDiameter / 2 - wallThickness, smallEndDiameter / 2 - wallThickness, totalHeight);
            TopoDS_Shape         hollowedPart      = aMakeHollowedPart.Shape();

            // cut
            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();

            // triangulation
            myFaces = Triangulation(myBody, 0.7f);
        }
Пример #3
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);
        }
Пример #4
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));
        }
Пример #5
0
        //--------------------------------------------------------------------------------------------------

        bool _DoCutoutBoxes(MakeContext context)
        {
            var listOfTools = new TopTools_ListOfShape();

            foreach (var boxes in context.Boxes)
            {
                for (int boxIndex = _ReverseOrder == _IsFirst ? 0 : 1; boxIndex < boxes.Count; boxIndex += 2)
                {
                    listOfTools.Append(boxes[boxIndex]);
                }
            }

            var listOfArguments = new TopTools_ListOfShape();

            listOfArguments.Append(context.OwnBrep);

            var cutter = new BRepAlgoAPI_Cut();

            cutter.SetArguments(listOfArguments);
            cutter.SetTools(listOfTools);
            cutter.Build();
            if (!cutter.IsDone())
            {
                Messages.Error("Cannot cut boxes out of shape.");
                return(false);
            }

            context.Result = cutter.Shape();
            UpdateModifiedSubshapes(context.OwnBrep, cutter);

            return(true);
        }
Пример #6
0
        /// <summary>
        /// create a hollowed cone beheaded
        /// </summary>
        /// <param name="myRadius">radius of the base</param>
        /// <param name="myHeight">height of the cone</param>
        /// <param name="myHeadRadius">radius of the top</param>
        /// <param name="myThickness">thickness</param>
        public HollowedConeBeheaded(double baseDiameter, double myHeight, double headDiameter, double myThickness)
        {
            // external part
            BRepPrimAPI_MakeCone aMakeCone = new BRepPrimAPI_MakeCone(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), baseDiameter / 2, headDiameter / 2, myHeight);
            TopoDS_Shape         myBody    = aMakeCone.Shape();
            TopoDS_Solid         mySolid   = aMakeCone.Solid();

            // internal part
            BRepPrimAPI_MakeCone aMakeHollowedPart = new BRepPrimAPI_MakeCone(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), baseDiameter / 2 - myThickness, headDiameter / 2 - myThickness, myHeight);
            TopoDS_Shape         hollowedPart      = aMakeHollowedPart.Shape();

            // cut
            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();

            // triangulation
            myFaces = Triangulation(myBody, 0.7f);
        }
Пример #7
0
        //--------------------------------------------------------------------------------------------------

        bool _DoCutoffExcess(MakeContext context)
        {
            var listOfArguments = new TopTools_ListOfShape();

            listOfArguments.Append(context.OwnBrep);

            // Cutout Commons
            var listOfTools = new TopTools_ListOfShape();

            foreach (var commonSolid in context.Common)
            {
                listOfTools.Append(commonSolid);
            }

            var cutter = new BRepAlgoAPI_Cut();

            cutter.SetArguments(listOfArguments);
            cutter.SetTools(listOfTools);
            cutter.Build();
            if (!cutter.IsDone())
            {
                Messages.Error("Cannot determine excess of instrusion.");
                return(false);
            }

            // Check if we have more solids than before
            var originalSolidCount = context.OwnBrep.Solids().Count;
            var solids             = cutter.Shape().Solids();
            var excessCount        = solids.Count - originalSolidCount;

            if (excessCount <= 0)
            {
                return(true); // No excess found
            }
            // Cutout additional solids
            listOfTools = new TopTools_ListOfShape();
            var orderedSolids = solids.OrderBy(solid => solid.Volume()).Take(excessCount);

            foreach (var solid in orderedSolids)
            {
                listOfTools.Append(solid);
            }

            cutter = new BRepAlgoAPI_Cut();
            cutter.SetArguments(listOfArguments);
            cutter.SetTools(listOfTools);
            cutter.Build();
            if (!cutter.IsDone())
            {
                Messages.Error("Cannot remove excess of instrusion from shape.");
                return(false);
            }

            UpdateModifiedSubshapes(context.OwnBrep, cutter);
            context.OwnBrep = cutter.Shape();
            return(true);
        }
Пример #8
0
        public override void Build()
        {
            // convert values from UnitsNet
            double wallThick  = wallThickness.Meters;
            double bendingRad = bendingRadius.Meters;
            double bendingA   = bendingAngle.Degrees;
            double Len1       = firstEndAdditionalHeight.Meters;
            //double Len2 = L2.Meters; // not implemented yet


            // to calculate n
            double min        = 20;
            double max        = 50;
            double angleLimit = 15;
            double coef       = (bendingA - angleLimit) * (max - min) / (180 - angleLimit) > 0 ? (bendingA - angleLimit) * (max - min) / (180 - angleLimit) : 0;
            double n          = (int)(min + coef);

            // generate the POINTS for the spline
            double             smallShift = Math.PI / 16;
            TColgp_Array1OfPnt array1     = GenerateSpline(Len1, bendingRad, wallThick, 0);
            TColgp_Array1OfPnt array2     = GenerateSpline(Len1, bendingRad, wallThick, smallShift);

            // create the SPLINE with the points
            GeomAPI_PointsToBSpline aSpline1          = new GeomAPI_PointsToBSpline(array1);
            GeomAPI_PointsToBSpline aSpline2          = new GeomAPI_PointsToBSpline(array2);
            Geom_BSplineCurve       connectionSpline1 = aSpline1.Curve();
            Geom_BSplineCurve       connectionSpline2 = aSpline2.Curve();


            // create EXTERNAL shape with spline
            TopoDS_Shape myBody3 = Build(connectionSpline1, bendingA, bendingRad, n, 0);

            // create INTERNAL shape with spline
            TopoDS_Shape myBody32 = Build(connectionSpline2, bendingA, bendingRad - wallThick, n, smallShift);



            // ______________ hollowing ______________
            BOPAlgo_BOP cutter = new BOPAlgo_BOP();

            cutter.AddArgument(myBody3);
            TopTools_ListOfShape LSC = new TopTools_ListOfShape();

            LSC.Append(myBody32);
            cutter.SetTools(LSC);
            cutter.SetRunParallel(true);
            cutter.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            cutter.Perform();
            myBody3 = cutter.Shape();



            // ______________ triangulation ______________
            SetMyFaces(Triangulation(myBody3, 0.7f));//*/
        }
Пример #9
0
        /// <summary>
        /// put in MyFaces all the faces that we compute. Note that L1 doesn't exist in BaseElement but i don't figure out on how we can modelize it without L1, there also could be a L2
        /// </summary>
        /// <param name="L1">length between the origin and the most right part of the tube ( same for the top)</param>
        /// <param name="bendingRadius">radius of the pipe</param>
        /// <param name="wallThickness">thickness of the pipe</param>
        /// <param name="bendingAngle"> angle from 0*pi/180 to bendingAngle*pi/180</param>
        /// <param name="n">parameter that modifies the number of triangles</param>
        //public Elbow(double L1, double wallThickness, double bendingRadius, double bendingAngle)
        public Elbow(double wallThickness, double bendingRadius, double bendingAngle, double L1)
        {
            // to calculate n
            double min        = 20;
            double max        = 50;
            double angleLimit = 15;
            double coef       = (bendingAngle - angleLimit) * (max - min) / (180 - angleLimit) > 0 ? (bendingAngle - angleLimit) * (max - min) / (180 - angleLimit) : 0;
            double n          = (int)(min + coef);

            // generate the POINTS for the spline
            double             smallShift = Math.PI / 16;
            TColgp_Array1OfPnt array1     = GenerateSpline(L1, bendingRadius, wallThickness, 0);
            TColgp_Array1OfPnt array2     = GenerateSpline(L1, bendingRadius, wallThickness, smallShift);

            // create the SPLINE with the points
            GeomAPI_PointsToBSpline aSpline1          = new GeomAPI_PointsToBSpline(array1);
            GeomAPI_PointsToBSpline aSpline2          = new GeomAPI_PointsToBSpline(array2);
            Geom_BSplineCurve       connectionSpline1 = aSpline1.Curve();
            Geom_BSplineCurve       connectionSpline2 = aSpline2.Curve();

            // create EXTERNAL shape with spline
            TopoDS_Shape myBody3 = Build(connectionSpline1, bendingAngle, bendingRadius, n, 0);

            // create INTERNAL shape with spline
            TopoDS_Shape myBody32 = Build(connectionSpline2, bendingAngle, bendingRadius - wallThickness, n, smallShift);//*/



            // ______________ hollowing ______________
            BOPAlgo_BOP cutter = new BOPAlgo_BOP();

            cutter.AddArgument(myBody3);
            TopTools_ListOfShape LSC = new TopTools_ListOfShape();

            LSC.Append(myBody32);
            cutter.SetTools(LSC);
            cutter.SetRunParallel(true);
            cutter.SetOperation(BOPAlgo_Operation.BOPAlgo_CUT);
            cutter.Perform();
            myBody3 = cutter.Shape();//*/



            // ______________ triangulation ______________
            myFaces = Triangulation(myBody3, 0.7f);
        }
Пример #10
0
        public override void Build()
        {
            // convert values from UnitsNet
            double wallThick    = wallThickness.Meters;
            double largeEndDiam = largeEndDiameter.Meters;
            double smallEndDiam = smallEndDiameter.Meters;
            double totalH       = totalHeight.Meters;
            double use1         = useless1.Degrees;
            double use2         = useless2.Meters;
            double use3         = useless3.Meters;
            double use4         = useless4.Meters;
            double use5         = useless5.Meters;



            // external part
            BRepPrimAPI_MakeCone aMakeCone = new BRepPrimAPI_MakeCone(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), largeEndDiam / 2, smallEndDiam / 2, totalH);
            TopoDS_Shape         myBody    = aMakeCone.Shape();
            TopoDS_Solid         mySolid   = aMakeCone.Solid();

            // internal part
            BRepPrimAPI_MakeCone aMakeHollowedPart = new BRepPrimAPI_MakeCone(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1)), largeEndDiam / 2 - wallThick, smallEndDiam / 2 - wallThick, totalH);
            TopoDS_Shape         hollowedPart      = aMakeHollowedPart.Shape();

            // cut
            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();

            // triangulation
            SetMyFaces(Triangulation(myBody, 0.7f));
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
        //--------------------------------------------------------------------------------------------------

        #region Make

        protected override bool MakeInternal(MakeFlags flags)
        {
            BRep = null;
            ClearSubshapeLists();

            if (Operands.Count < 2)
            {
                Messages.Error("Boolean operations need at least two operand shapes.");
                return(false);
            }

            var shapeA = GetOperandBRep(0);

            if (shapeA == null)
            {
                return(false);
            }

            var shapeListArgs = new TopTools_ListOfShape();

            shapeListArgs.Append(shapeA);

            var shapeListTools = new TopTools_ListOfShape();

            for (int operandIndex = 1; operandIndex < Operands.Count; operandIndex++)
            {
                var shapeB = GetOperandBRep(operandIndex);
                if (shapeB == null)
                {
                    return(false);
                }

                shapeListTools.Append(shapeB);
            }

            var algo = CreateAlgoApi();

            algo.SetArguments(shapeListArgs);
            algo.SetTools(shapeListTools);
            algo.Build();
            if (!algo.IsDone())
            {
                Messages.Error("Boolean operation failed.");
                return(false);
            }

            var resultShape = algo.Shape();

            if (resultShape == null)
            {
                return(false);
            }

            UpdateModifiedSubshapes(shapeA, algo);
            foreach (var shapeB in shapeListTools.ToList())
            {
                UpdateModifiedSubshapes(shapeB, algo);
            }

            BRep = resultShape;

            return(base.MakeInternal(flags));
        }
Пример #14
0
        //--------------------------------------------------------------------------------------------------

        bool _DoThicken(MakeContext context)
        {
            // Do we need to thicken?
            if (context.AllWiresClosed &&
                _StartCapping != CappingMode.None &&
                _EndCapping != CappingMode.None)
            {
                return(true);
            }

            // Get tolerance
            var anaTolerance = new ShapeAnalysis_ShapeTolerance();
            var tolerance    = anaTolerance.Tolerance(context.Result, 1, TopAbs_ShapeEnum.TopAbs_SHAPE); // Get max of all

            var joinType = _ThickenCornerType == CornerType.Round ? GeomAbs_JoinType.GeomAbs_Arc : GeomAbs_JoinType.GeomAbs_Intersection;

            if (context.AllWiresClosed)
            {
                // Thicken Solid and remove Caps
                var removeFaceList = new TopTools_ListOfShape();
                if (_StartCapping == CappingMode.None)
                {
                    removeFaceList.Append(context.StartFace);
                }

                if (_EndCapping == CappingMode.None)
                {
                    removeFaceList.Append(context.EndFace);
                }

                // Build thicken solid
                var makeThick     = new BRepOffsetAPI_MakeThickSolid();
                var thicknessSign = ThickenDirection == Direction.Inwards ? -1 : 1;
                makeThick.MakeThickSolidByJoin(context.Result, removeFaceList, Thickness * thicknessSign, tolerance,
                                               BRepOffset_Mode.BRepOffset_Skin, true, false, joinType);

                if (!makeThick.IsDone())
                {
                    Messages.Error($"Failed to thicken solid: {makeThick.MakeOffset().Error().ToString()}.");
                    return(false);
                }

                context.Result = makeThick.Shape();
            }
            else
            {
                // Thicken shell
                var shell = context.Result.Shells()[0];
                if (shell == null)
                {
                    Messages.Error("Generated shell is invalid.");
                    return(false);
                }

                var makeThick     = new BRepOffset_MakeOffset();
                var thicknessSign = ThickenDirection == Direction.Inwards ? -1 : 1;
                makeThick.Initialize(shell, Thickness * thicknessSign, tolerance,
                                     BRepOffset_Mode.BRepOffset_Skin, true, false, joinType, true);
                makeThick.MakeOffsetShape();

                if (!makeThick.IsDone())
                {
                    Messages.Error($"Failed converting shell to thick solid: {makeThick.Error().ToString()}.");
                    return(false);
                }

                context.Result = makeThick.Shape();
                TopoUtils.UpdateSolidOrientation(context.Result);
            }

            return(true);
        }
Пример #15
0
        //--------------------------------------------------------------------------------------------------

        bool _DoCreateBoxes(MakeContext context)
        {
            foreach (var commonSolid in context.Common)
            {
                // Find smallest face
                var(_, startPlane, _, stopPlane) = FaceAlgo.FindFaceByAreaSize(commonSolid, (area1, area2) => area1 < area2);
                if (startPlane == null || stopPlane == null)
                {
                    Messages.Error("Cannot find two parallel plane faces in common shape.");
                    return(false);
                }

                // Create offsets
                var vector = new Vec(startPlane.Value.Location, stopPlane.Value.Location);

                var cutPlaneOffsets = new double[BoxCount - 1];
                if (_CustomBoxRatios != null && _CustomBoxRatios.Length != 0)
                {
                    // Create by custom sizes
                    var sumParts    = _CustomBoxRatios.Sum();
                    var planeOffset = 0.0;

                    for (int cutPlaneIndex = 0; cutPlaneIndex < _BoxCount - 1; cutPlaneIndex++)
                    {
                        planeOffset += _CustomBoxRatios[cutPlaneIndex];
                        cutPlaneOffsets[cutPlaneIndex] = planeOffset / sumParts;
                    }
                }
                else
                {
                    // Create by ratio
                    var firstPart   = _IsFirst != _ReverseOrder ? _Ratio : 1.0 - _Ratio;
                    var sumParts    = (BoxCount >> 1) * 1.0 + (_BoxCount & 1) * firstPart;
                    var planeOffset = 0.0;

                    for (int cutPlaneIndex = 0; cutPlaneIndex < _BoxCount - 1; cutPlaneIndex++)
                    {
                        planeOffset += (cutPlaneIndex & 1) > 0 ? 1.0 - firstPart : firstPart;
                        cutPlaneOffsets[cutPlaneIndex] = planeOffset / sumParts;
                    }
                }

                // Create cut tools
                var build       = new BRep_Builder();
                var listOfTools = new TopTools_ListOfShape();


                for (int cutPlaneIndex = 0; cutPlaneIndex < cutPlaneOffsets.Length; cutPlaneIndex++)
                {
                    var cutplane = startPlane.Value.Translated(vector.Multiplied(cutPlaneOffsets[cutPlaneIndex]));
                    var face     = new TopoDS_Face();
                    build.MakeFace(face, new Geom_Plane(cutplane), 1e-7);
                    listOfTools.Append(face);
                }

                // Split
                var listOfArguments = new TopTools_ListOfShape();
                listOfArguments.Append(commonSolid);
                var splitter = new BRepAlgoAPI_Splitter();
                splitter.SetArguments(listOfArguments);
                splitter.SetTools(listOfTools);
                splitter.Build();
                if (!splitter.IsDone())
                {
                    Messages.Error("Cannot split common shape into boxes.");
                    return(false);
                }

                context.Boxes.Add(splitter.Shape().Solids());
            }

            return(true);
        }
        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));
        }