//-------------------------------------------------------------------------------------------------- public TopoDS_Compound Reconstruct() { var compound = new TopoDS_Compound(); var builder = new BRep_Builder(); builder.MakeCompound(compound); var thicknessVector = SliceDirection.ToVec().Multiplied(SliceThickness / Slices.Length); if (thicknessVector.SquareMagnitude() == 0) { Messages.Error("Sliced shape has no thickness."); return(compound); } for (int index = 0; index < Slices.Length; index++) { var basePlane = Slices[index].CutPlane.Translated(thicknessVector.Multiplied(0.5).ToPnt(), Pnt.Origin); var location = new TopLoc_Location(new Trsf(basePlane.Position, Ax3.XOY)); var relocatedShape = Slices[index].BRep.Located(location); var thickener = new BRepPrimAPI_MakePrism(relocatedShape, thicknessVector, true); builder.Add(compound, thickener.Shape()); } return(compound); }
//-------------------------------------------------------------------------------------------------- bool _Make2D() { // We work with 2D shapes as source var faceShape = GetOperand2DFaces(0, null); if (faceShape == null) { return(false); } // Get plane if (!FaceAlgo.GetPlaneOfFaces(faceShape, out var plane)) { return(false); } // If extrusion vector has zero length, just copy the source shape converted to faces if (Depth == 0) { BRep = faceShape; return(base.MakeInternal(MakeFlags.NoTransformation)); } // Generate vector var vector = plane.Axis.Direction.ToVec().Multiplied(Depth); // Offset if symmetric if (Symmetric) { var offset = vector.Reversed().Multiplied(0.5); var transform = new BRepBuilderAPI_Transform(faceShape, new Trsf(Pnt.Origin, offset.ToPnt())); faceShape = transform.Shape(); } // Do it! var makePrism = new BRepPrimAPI_MakePrism(faceShape, vector); // Get final shape BRep = makePrism.Shape(); return(true); }
//-------------------------------------------------------------------------------------------------- bool _MakeFlangeSection(MakeContext context) { if (_Length <= 0) { return(true); } var brepAdaptor = new BRepAdaptor_Surface(context.FlangeFace); if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane) { Messages.Error("Flanges can only be added to planar faces."); return(false); } var direction = brepAdaptor.Plane().Position.Direction; if (context.FlangeFace.Orientation() == TopAbs_Orientation.TopAbs_REVERSED) { direction.Reverse(); } // Extrude var makePrism = new BRepPrimAPI_MakePrism(context.FlangeFace, direction.ToVec().Multiplied(_Length)); if (!makePrism.IsDone()) { Messages.Error("Failed building flange."); return(false); } var flangeShape = makePrism.Shape(); // Rotate if bended if (_Angle > 0) { var trsf = new Trsf(context.BendAxis, _Angle.Clamp(0.0, 180.0).ToRad()); flangeShape.Location(new TopLoc_Location(trsf)); } context.FlangeShape = flangeShape; return(true); }