public static TopoDS_Edge MakeEdge(Geom2d_Curve curve2d, Pln plane) { var curve = GeomAPI.To3d(curve2d, plane); var edge = new BRepBuilderAPI_MakeEdge(curve).Edge(); return(edge); }
public static FaceIntersectionLineResult IntersectLine(this TopoDS_Face face, TopoDS_Face other, double tol) { var s1 = face.Surface(); var s2 = other.Surface(); var a = new GeomAPI_IntSS(s1, s2, tol); var C = a.Line(1); var edge = new BRepBuilderAPI_MakeEdge(C, C.FirstParameter(), C.LastParameter()); var v1 = edge.Vertex1(); var v2 = edge.Vertex2(); var i1 = BRep_Tool.Pnt(v1); var i2 = BRep_Tool.Pnt(v2); return(new FaceIntersectionLineResult(C, new Line3D(i1.ToVector3D(), i2.ToVector3D()))); }
//-------------------------------------------------------------------------------------------------- public static TopoDS_Face MakeFace(Pnt[] points) { Debug.Assert(points.Length == 4); var edges = new TopoDS_Edge[4]; for (int i = 0; i < 4; i++) { edges[i] = new BRepBuilderAPI_MakeEdge(points[i], points[i == 3 ? 0 : i + 1]).Edge(); } var wire = new BRepBuilderAPI_MakeWire(edges[0], edges[1], edges[2], edges[3]).Wire(); return(new BRepBuilderAPI_MakeFace(wire).Face()); }
/// <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> /// 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; } }
//-------------------------------------------------------------------------------------------------- bool _MakeFlangeFace(MakeContext context) { if (_StartGap <= 0 && _EndGap <= 0) { context.FlangeFace = context.TargetFace; return(true); } // Get points from bend edge and opposite edge var points = new Pnt[4]; var bendEdgeAdaptor = new BRepAdaptor_Curve(context.BendEdge); points[0] = bendEdgeAdaptor.Value(bendEdgeAdaptor.FirstParameter()); points[1] = bendEdgeAdaptor.Value(bendEdgeAdaptor.LastParameter()); if (points[0].Distance(points[1]) <= (_StartGap + _EndGap)) { Messages.Error("The sum of start and end gap is higher than the length of the bending edge."); return(false); } if (context.OppositeEdge == null) { Messages.Error("No opposite edge found for building flange face."); return(false); } // Move vertices from bend edge to op edge var distTool = new BRepExtrema_DistShapeShape(context.BendEdge, context.OppositeEdge); var upVector = context.TopDirection.ToVec().Reversed() * distTool.Value(); points[2] = points[0].Translated(upVector); points[3] = points[1].Translated(upVector); // Sort points, Short edges must be 1->2 and 3->0 if (context.BendEdge.Orientation() == TopAbs_Orientation.TopAbs_REVERSED) { points.Swap(0, 1); } if (points[0].Distance(points[3]) > points[0].Distance(points[2])) { points.Swap(2, 3); } // Move if (_StartGap > 0) { var startVector = context.BendAxis.Direction.ToVec().Multiplied(_StartGap); points[0].Translate(startVector); points[3].Translate(startVector); } if (_EndGap > 0) { var endVector = context.BendAxis.Direction.ToVec().Multiplied(-_EndGap); points[1].Translate(endVector); points[2].Translate(endVector); } // Generate face and new edges context.FlangeFace = TopoUtils.MakeFace(points); if (context.FlangeFace == null) { Messages.Error("Failed making flange face with gaps."); return(false); } context.BendEdge = new BRepBuilderAPI_MakeEdge(points[0], points[1]).Edge(); context.OppositeEdge = new BRepBuilderAPI_MakeEdge(points[3], points[2]).Edge(); // Split original face to avoid problems with additional flanges on the same face TopoDS_Edge startGapEdge = null, endGapEdge = null; var splitOp = new BRepFeat_SplitShape(context.TargetShape); if (_StartGap > 0) { startGapEdge = new BRepBuilderAPI_MakeEdge(points[0], points[3]).Edge(); splitOp.Add(startGapEdge, context.TargetFace); } if (_EndGap > 0) { endGapEdge = new BRepBuilderAPI_MakeEdge(points[1], points[2]).Edge(); splitOp.Add(endGapEdge, context.TargetFace); } splitOp.Build(); if (!splitOp.IsDone()) { Messages.Error("Failed spliting gap edges into target face."); return(false); } UpdateModifiedSubshapes(context.TargetShape, splitOp); context.ModifiedTargetShape = splitOp.Shape(); // Update named shapes var splitFaceList = splitOp.Modified(context.TargetFace).ToList(); foreach (var splitShape in splitFaceList) { var edges = splitShape.Edges(); foreach (var edge in edges) { if (startGapEdge != null && context.StartGapFace == null && edge.Orientation() == splitShape.Orientation() && edge.IsSame(startGapEdge)) { context.StartGapFace = splitShape; break; } if (endGapEdge != null && context.EndGapFace == null && edge.Orientation() != splitShape.Orientation() && edge.IsSame(endGapEdge)) { context.EndGapFace = splitShape; break; } } } return(true); }