/// <summary> /// create the face to be slided /// </summary> /// <param name="r">the radius of the circular face</param> /// <returns>a wire that is our face to be slided</returns> private TopoDS_Wire MakeCircularHollowedWire(double r) { /*gp_Circ2d cir1 = new gp_Circ2d(new gp_Ax2d(new gp_Pnt2d(new gp_XY(0f, 0f)), new gp_Dir2d(1, 0)), r); * * BRepBuilderAPI_MakeEdge2d mee1 = new BRepBuilderAPI_MakeEdge2d(cir1); * TopoDS_Edge e1 = mee1.Edge(); * * BRepBuilderAPI_MakeWire aMakeWire1 = new BRepBuilderAPI_MakeWire(e1); * TopoDS_Wire W = aMakeWire1.Wire();//*/ gp_Circ cir1 = new gp_Circ(new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(1, 0, 0)), r); BRepBuilderAPI_MakeEdge aMakeEdge = new BRepBuilderAPI_MakeEdge(cir1); BRepBuilderAPI_MakeWire aMakeWire1 = new BRepBuilderAPI_MakeWire(aMakeEdge.Edge()); TopoDS_Wire W = aMakeWire1.Wire(); return(W); }
/// <summary> /// build the shape of the elbow (internal or external) by building the sliding face and building the wire with the given spline /// </summary> /// <param name="connectionSpline"> the spline to slide on</param> /// <param name="bendingAngle">the angle of our future elbow</param> /// <param name="bendingRadius"> the radius of the elbow</param> /// <param name="n">modifies the number of triangles</param> /// <param name="shift">makes the shape begin before 0*pi/180 and end after bendingAngle, we use it to hollow correctly the shape (put 0 for the external part, and something like pi/16 for the internal part)</param> /// <returns>the shape of the elbow (external or internal part)</returns> public TopoDS_Shape Build(Geom_BSplineCurve connectionSpline, double bendingAngle, double bendingRadius, double n, double shift) { bool firstIteration = true; // check if it is the first iteration BRepBuilderAPI_MakeWire aMakeWire = new BRepBuilderAPI_MakeWire(); // initialize our wire gp_Pnt lastPnt = new gp_Pnt(); // initialize our last point double angle = bendingAngle * Math.PI / 180; // our angle in radian double lp = connectionSpline.LastParameter(); // often 1 double fp = connectionSpline.FirstParameter(); // often 0 double percentage = (angle + 2 * shift) / (2 * Math.PI); // percentage of the spline to get ( because our spline goes from 0 to 2pi, but we dont want all) double pas = (lp * percentage - fp) / n; // the step for the iteration on the spline for (double i = fp; i < lp * percentage; i = i + pas) // fp already includes the small shift if it got any { if (firstIteration) { // we get our first point lastPnt = connectionSpline.Value(i); firstIteration = false; } else { // and now we add a new edge(last point, current point) on our wire aMakeWire.Add(new BRepBuilderAPI_MakeEdge(lastPnt, connectionSpline.Value(i)).Edge()); lastPnt = connectionSpline.Value(i); } } // create the pipe with the spline and the section TopoDS_Wire W = MakeWire(bendingRadius); // the face to be slided BRepOffsetAPI_MakePipeShell piper = new BRepOffsetAPI_MakePipeShell(aMakeWire.Wire()); // initialize with the wire to slide on BRepBuilderAPI_TransitionMode Mode = new BRepBuilderAPI_TransitionMode(); Mode = BRepBuilderAPI_TransitionMode.BRepBuilderAPI_RoundCorner; piper.SetTransitionMode(Mode); // to have a curved shape piper.Add(W, true, true); // first= true to get a pipe and not something else really weird piper.Build(); // create the shape piper.MakeSolid(); //*/ return(piper.Shape()); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { if (!Segments.Any() || !Points.Any()) { var makeVertex = new BRepBuilderAPI_MakeVertex(Pnt.Origin); BRep = makeVertex.Vertex(); HasErrors = false; return(base.MakeInternal(flags)); } // Create edges var freeSegmentEdges = new Dictionary <SketchSegment, TopoDS_Edge>(); foreach (var segmentKvp in _Segments) { var segment = segmentKvp.Value; if (segment.IsAuxilliary) { continue; } var segEdge = segment.MakeEdge(_Points); if (segEdge == null) { Messages.Warning($"The segment {segmentKvp.Key} of type {segment.GetType().Name} failed creating an edge."); continue; } freeSegmentEdges.Add(segment, segEdge); AddNamedSubshape("seg", segEdge, segmentKvp.Key); } // Create wires var wires = new List <TopoDS_Wire>(); while (freeSegmentEdges.Any()) { var nextSegmentEdge = freeSegmentEdges.First(); var frontSegment = nextSegmentEdge.Key; freeSegmentEdges.Remove(nextSegmentEdge.Key); var makeWire = new BRepBuilderAPI_MakeWire(nextSegmentEdge.Value); if ((frontSegment.StartPoint != -1) || (frontSegment.EndPoint != -1)) { var backSegment = frontSegment; while (freeSegmentEdges.Any()) { nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(frontSegment)); if (nextSegmentEdge.Value != null) { frontSegment = nextSegmentEdge.Key; } else { nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(backSegment)); if (nextSegmentEdge.Value != null) { backSegment = nextSegmentEdge.Key; } else { // disconnected segment break; } } makeWire.Add(nextSegmentEdge.Value); freeSegmentEdges.Remove(nextSegmentEdge.Key); } } // Get wire shape var wire = makeWire.Wire(); if (wire == null) { Messages.Error("Error when creating a wire."); return(false); } wires.Add(wire); } // Create resulting shape var builder = new TopoDS_Builder(); var shape = new TopoDS_Compound(); builder.MakeCompound(shape); foreach (var wire in wires) { builder.Add(shape, wire); } BRep = shape; return(base.MakeInternal(flags)); }
/// <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() { double wallThick = wallThickness.Meters; double diam = diameter.Meters; double crownRad = crownRadius.Meters; double knucleRad = knucleRadius.Meters; double totalH = totalHeight.Meters; double use1 = useless1.Meters; double use2 = useless2.Bars; string use3 = useless3; // can't work if P == O if (crownRadius == knucleRadius) { return; } // _____________curved part_____________ // on va définir un certain nombre de points // certains avec des intersections de cercles, donc va y avoir un peu de calculs... gp_Pnt A = new gp_Pnt(wallThick, 0, 0); // point à droite de la base gp_Pnt B = new gp_Pnt(0, 0, 0); // point à gauche de la base gp_Pnt C = new gp_Pnt(0, totalH, 0); // debut de l'arc exterieur gp_Pnt H = new gp_Pnt(wallThick, totalH, 0); // debut de l'arc intérieur gp_Pnt P = new gp_Pnt(wallThick + crownRad, totalH, 0); // centre du petit cercle formant l'arc gp_Pnt O = new gp_Pnt(wallThick + knucleRad, totalH, 0); // centre du grand cercle formant le capot gp_Pnt a1 = new gp_Pnt(crownRad * Math.Cos(3 * Math.PI / 4) + P.X(), crownRad * Math.Sin(3 * Math.PI / 4) + P.Y(), 0); // point de l'arc de cercle intérieur gp_Pnt a2 = new gp_Pnt((crownRad + wallThick) * Math.Cos(3 * Math.PI / 4) + P.X(), (crownRad + wallThick) * Math.Sin(3 * Math.PI / 4) + P.Y(), 0); // point de l'arc de cercle extérieur // pour a3 et a4 c'est compliqué, je crois que je dois choisir un angle au hasard et que potentiellement ça peut tout niquer (si R2 trop petit comparé à R1) //gp_Pnt a3 = new gp_Pnt(-radius2 * Math.Cos(3 * Math.PI / 4) + thickness + radius2, radius2* Math.Sin(3 * Math.PI / 4)+ totalHeight - thickness - radius2, 0); // point de l'arc du capot intérieur //gp_Pnt a4 = new gp_Pnt(-(radius2 + thickness) * Math.Cos(3 * Math.PI / 4) + thickness + radius2, (radius2 + thickness) * Math.Sin(3 * Math.PI / 4) + totalHeight - thickness - radius2, 0); // point de l'arc du capot extérieur gp_Pnt E = new gp_Pnt(O.X(), O.Y() + knucleRad + wallThick, 0); // haut du capot gp_Pnt F = new gp_Pnt(O.X(), O.Y() + knucleRad, 0); // haut du capot mais côté intérieur // maintenant il faut définir les intersections des arcs de cercle et du capot // soit l'intersection du cercle de rayon myRadius1(R1) et de centre P (que l'on va abréger P(R1) ) avec O(R2) // et également (myThickness=T) P(R1+T) avec O(R2+T) gp_Pnt G = new gp_Pnt(P.X(), P.Y() + crownRad, 0); // point de l'arc de cercle intérieur gp_Pnt D = new gp_Pnt(P.X(), P.Y() + crownRad + wallThick, 0); // point de l'arc de cercle extérieur // maintenant qu'on a tous nos points faut les relier ;) TopoDS_Edge AB = new BRepBuilderAPI_MakeEdge(A, B).Edge(); TopoDS_Edge BC = new BRepBuilderAPI_MakeEdge(B, C).Edge(); GC_MakeArcOfCircle Ca2D = new GC_MakeArcOfCircle(C, a2, D); BRepBuilderAPI_MakeEdge meCa2D = new BRepBuilderAPI_MakeEdge(Ca2D.Value()); TopoDS_Edge CD = meCa2D.Edge(); TopoDS_Edge DE = new BRepBuilderAPI_MakeEdge(D, E).Edge(); TopoDS_Edge EF = new BRepBuilderAPI_MakeEdge(E, F).Edge(); TopoDS_Edge FG = new BRepBuilderAPI_MakeEdge(F, G).Edge(); GC_MakeArcOfCircle Ga1H = new GC_MakeArcOfCircle(G, a1, H); BRepBuilderAPI_MakeEdge meGa1H = new BRepBuilderAPI_MakeEdge(Ga1H.Value()); TopoDS_Edge GH = meGa1H.Edge(); TopoDS_Edge HA = new BRepBuilderAPI_MakeEdge(H, A).Edge(); // creating the wire BRepBuilderAPI_MakeWire aMakeWire = new BRepBuilderAPI_MakeWire(AB, BC, CD, DE); TopoDS_Wire aWire = aMakeWire.Wire(); aMakeWire = new BRepBuilderAPI_MakeWire(aWire, EF); aWire = aMakeWire.Wire(); aMakeWire = new BRepBuilderAPI_MakeWire(aWire, FG); aWire = aMakeWire.Wire(); aMakeWire = new BRepBuilderAPI_MakeWire(aWire, GH); aWire = aMakeWire.Wire(); aMakeWire = new BRepBuilderAPI_MakeWire(aWire, HA); aWire = aMakeWire.Wire();//*/ // rotation du wire gp_Ax1 Axis = new gp_Ax1(new gp_Pnt(wallThick + knucleRad, 0, 0), new gp_Dir(0, 1, 0)); // origine 0,0,0 avec dir 0,1,0 BRepBuilderAPI_MakeFace aMakeFace = new BRepBuilderAPI_MakeFace(aWire); TopoDS_Face face = aMakeFace.Face(); BRepPrimAPI_MakeRevol aMakeRevol = new BRepPrimAPI_MakeRevol(face, Axis, 2 * Math.PI); aMakeRevol.Build(); TopoDS_Shape aRotatedShape = aMakeRevol.Shape(); // _____________triangulation_____________ SetMyFaces(Triangulation(aRotatedShape, 0.007f)); //*/ }
//-------------------------------------------------------------------------------------------------- void _PreviewRadius(ToolAction toolAction) { if (!(toolAction is PointAction pointAction)) { return; } _ClearPreviews(); _PointPlane2 = pointAction.PointOnPlane; if (_PointPlane1.IsEqual(_PointPlane2, Double.Epsilon)) { return; } _Radius = new Vec2d(_PointPlane1, _PointPlane2).Magnitude(); if (_Radius <= Double.Epsilon) { return; } var makeCircle = new gce_MakeCirc(_PivotPoint, _Plane.Axis.Direction, _Radius); if (!makeCircle.IsDone()) { return; } var makeEdge = new BRepBuilderAPI_MakeEdge(makeCircle.Value()); if (!makeEdge.IsDone()) { return; } var makeWire = new BRepBuilderAPI_MakeWire(makeEdge.Edge()); if (!makeWire.IsDone()) { return; } var makeFace = new BRepBuilderAPI_MakeFace(makeWire.Wire(), true); if (!makeFace.IsDone()) { return; } _AisPreviewEdges = new AIS_Shape(makeFace.Face()); _AisPreviewEdges.SetDisplayMode(0); WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges); _AisPreviewSolid = new AIS_Shape(makeFace.Face()); _AisPreviewSolid.SetDisplayMode(1); WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid); StatusText = $"Select radius: {_Radius:0.00}"; if (_ValueHudElement != null) { _ValueHudElement.Value = _Radius; } if (_Coord2DHudElement != null) { _Coord2DHudElement.CoordinateX = pointAction.PointOnPlane.X; _Coord2DHudElement.CoordinateY = pointAction.PointOnPlane.Y; } }