/// <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)); }