//-------------------------------------------------------------------------------------------------- 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); }
//-------------------------------------------------------------------------------------------------- bool _DoOffset(MakeContext context) { if (_Offset <= 0) { return(false); } // Move neutral plane var newPlane = context.NeutralPlane.Translated(context.Direction.ToVec().Multiplied(_Offset)); // Create section edge var faceOfPlane = new BRepBuilderAPI_MakeFace(new Geom_Plane(newPlane), Precision.Confusion()).Shape(); var section = new BRepAlgoAPI_Section(context.Face, faceOfPlane); section.Build(); if (!section.IsDone()) { Messages.Warning("The offset can not be performed, section operation failed."); return(false); } var newEdge = section.Shape().Edges().FirstOrDefault(); if (!section.IsDone() || newEdge == null) { Messages.Warning("The offset value seems to be out of range."); return(false); } if (context.ReversedFaceSense) { newEdge.Orientation(TopAbs_Orientation.TopAbs_REVERSED); } // Split face with section edge var splitShape = new BRepFeat_SplitShape(context.Source); splitShape.Add(newEdge, context.Face); splitShape.Build(); if (!splitShape.IsDone()) { Messages.Warning("The offset can not be performed, the face split operation failed."); return(false); } var newShape = splitShape.Shape(); var newFace = splitShape.DirectLeft().First().ToFace(); // Reduce continuity of new edge to C0 to allow the draft algo to make a sharp corner var(face1, face2) = EdgeAlgo.FindAdjacentFaces(newShape, newEdge); if (face1 == null || face2 == null) { Messages.Warning("The offset can not be performed, invalid face count after split operation."); return(false); } var builder = new BRep_Builder(); builder.Continuity(newEdge, face1, face2, GeomAbs_Shape.GeomAbs_C0); // Set results context.NeutralPlane = newPlane; context.Source = newShape; context.Face = newFace; UpdateModifiedSubshapes(context.Source, splitShape); return(true); }