public static void LoadBrepFile(string fileName, Document document) { var aSequence = new TopToolsHSequenceOfShape(); var aShape = new TopoDSShape(); var aBuilder = new BRepBuilder(); var result = BRepTools.Read(aShape, fileName, aBuilder, null); if (result) { if (!BRepAlgo.IsValid(aShape)) { // Warning: The shape is not valid! } else { aSequence.Append(aShape); } } if (aSequence.IsEmpty) { return; } document.Transact(); for (var i = 1; i <= aSequence.Length; i++) { var aisShape = aSequence.Value(i); var builder = new NodeBuilder(document, FunctionNames.Mesh); builder[0].Shape = aisShape; builder.ExecuteFunction(); } document.Commit("Added to scene filename: " + fileName); }
public static gp_Dir ComputeNormal(this TopoDS_Face face) { double umin = 0, umax = 0, vmin = 0, vmax = 0; BRepTools.UVBounds(face, ref umin, ref umax, ref vmin, ref vmax); var surface = BRep_Tool.Surface(face); var props = new GeomLProp_SLProps(surface, umin, vmin, 1.0, 1e-1); return(props.Normal()); }
public static UVBounds UVBounds(this TopoDS_Face face) { var umin = 0.0; var umax = 0.0; var vmin = 0.0; var vmax = 0.0; BRepTools.UVBounds(face, ref umin, ref umax, ref vmin, ref vmax); return(new UVBounds(umin, umax, vmin, vmax)); }
//-------------------------------------------------------------------------------------------------- public static Ax1 GetFaceCenterNormal(TopoDS_Face face) { double umin = 0, umax = 0, vmin = 0, vmax = 0; BRepTools.UVBounds(face, ref umin, ref umax, ref vmin, ref vmax); var props = new BRepGProp_Face(face); Pnt position = new Pnt(); Vec normal = new Vec(); props.Normal((umin + umax) / 2.0, (vmin + vmax) / 2.0, ref position, ref normal); return(new Ax1(position, normal.ToDir())); }
//-------------------------------------------------------------------------------------------------- public static bool RenderFaces(IDrawingRenderer renderer, TopoDS_Shape brepShape) { var res = true; renderer.BeginPath(); var faces = brepShape.Faces(); if (faces.Count == 0) { // Drawings may only contain lines, not faces res = RenderEdges(renderer, brepShape.Edges(), null); } else { foreach (var face in faces) { var outerWire = BRepTools.OuterWire(face); if (outerWire == null) { continue; } res &= RenderEdges(renderer, outerWire.Edges(), face); var wires = face.Wires(); foreach (var wire in wires) { if (wire.IsEqual(outerWire)) { continue; } res &= RenderEdges(renderer, wire.Edges(), face); } } } renderer.EndPath(); return(res); }
//-------------------------------------------------------------------------------------------------- bool _HasTriangulation(TopoDS_Shape shape) { var faces = shape.Faces(); return(faces.Any(face => BRepTools.Triangulation(face, Precision.Infinite()))); }
//-------------------------------------------------------------------------------------------------- SvgGroupElement _ExportLayer(VectorExportLayer layer) { if (_Styles == null || !_Styles.TryGetValue(layer.Type, out var lineStyle)) { return(null); } CurrentGroup = new SvgGroupElement { ID = layer.Name, Style = lineStyle }; if (layer.BRep == null) { return(null); } if (_Template == VectorExportTemplate.Contours) { CurrentGroup.IsLayer = true; } CurrentPath = null; if (_Template == VectorExportTemplate.Drawing) { // Drawings do only contain lines CombineToPath = false; _ExportEdges(layer.BRep.Edges(), null); } else { CombineToPath = layer.Type.HasFlag(VectorExportLayerType.Filled); var faces = layer.BRep.Faces(); foreach (var face in faces) { var outerWire = BRepTools.OuterWire(face); if (outerWire == null) { continue; } _ExportEdges(outerWire.Edges(), face); var wires = face.Wires(); foreach (var wire in wires) { if (wire.IsEqual(outerWire)) { continue; } _ExportEdges(wire.Edges(), face); } FinalizePath(); } } if (CurrentGroup.Children.Any()) { return(CurrentGroup); } return(null); }