public void BinaryReadWrite() { var originalBytes = TestData.GetTestData(@"SourceData\Brep\ImprintRingFace.brep"); Assume.That(originalBytes, Is.Not.Null); // Read in as ASCII var originalShape = BRepExchange.ReadASCII(originalBytes); Assert.IsNotNull(originalShape); Assert.AreEqual(TopAbs_ShapeEnum.TopAbs_COMPOUND, originalShape.ShapeType()); // Write out var writtenBytes = BRepExchange.WriteBinary(originalShape, false); Assert.IsNotNull(writtenBytes); Assert.AreEqual(7222, writtenBytes.Length); // Re-read in var rereadShape = BRepExchange.ReadBinary(writtenBytes); Assert.IsNotNull(rereadShape); Assert.AreEqual(TopAbs_ShapeEnum.TopAbs_COMPOUND, rereadShape.ShapeType()); Assert.IsFalse(_HasTriangulation(rereadShape), "HasTriangulation"); Assert.IsTrue(ModelCompare.CompareShape(rereadShape, @"SourceData\Brep\ImprintRingFace")); }
public void BinaryTriangulation() { var originalBytes = TestData.GetTestData(@"SourceData\Brep\Motor-c.brep"); Assume.That(originalBytes, Is.Not.Null); // Read in var originalShape = BRepExchange.ReadASCII(originalBytes); Assert.IsNotNull(originalShape); Assert.AreEqual(TopAbs_ShapeEnum.TopAbs_COMPOUND, originalShape.ShapeType()); // Write out with triangulation var writtenBytes = BRepExchange.WriteBinary(originalShape, true); Assert.IsNotNull(writtenBytes); Assert.AreEqual(1624845, writtenBytes.Length); // Re-read in with triangulation var rereadShape = BRepExchange.ReadBinary(writtenBytes); Assert.IsNotNull(rereadShape); Assert.AreEqual(TopAbs_ShapeEnum.TopAbs_COMPOUND, rereadShape.ShapeType()); Assert.IsTrue(_HasTriangulation(rereadShape), "HasTriangulation"); Assert.IsTrue(ModelCompare.CompareShape(rereadShape, @"SourceData\Brep\Motor-c")); // Write out w/o triangulation writtenBytes = BRepExchange.WriteBinary(originalShape, false); Assert.IsNotNull(writtenBytes); Assert.AreEqual(665759, writtenBytes.Length); // Re-read in w/o triangulation rereadShape = BRepExchange.ReadBinary(writtenBytes); Assert.IsNotNull(rereadShape); Assert.AreEqual(TopAbs_ShapeEnum.TopAbs_COMPOUND, rereadShape.ShapeType()); Assert.IsFalse(_HasTriangulation(rereadShape), "HasTriangulation"); Assert.IsTrue(ModelCompare.CompareShape(rereadShape, @"SourceData\Brep\Motor-c")); }
//-------------------------------------------------------------------------------------------------- #endregion #region IBrepExporter bool IBodyExporter.DoExport(string fileName, IEnumerable <Body> bodies) { try { var builder = new BRep_Builder(); var compound = new TopoDS_Compound(); builder.MakeCompound(compound); foreach (var body in bodies) { var bodyShape = body.Shape?.GetTransformedBRep(); if (bodyShape == null) { Messages.Warning($"BRep Exporter: The body {body.Name} has no valid shape, thus it will not be included in the export."); continue; } builder.Add(compound, bodyShape); } var bytes = Settings.ExportBinaryFormat ? BRepExchange.WriteBinary(compound, true) : BRepExchange.WriteASCII(compound, true); if (bytes == null || bytes.Length == 0) { Messages.Error("BRep Exporter: Error generating BRep from body shapes."); return(false); } File.WriteAllBytes(fileName, bytes); return(true); } catch (Exception e) { Console.WriteLine(e); Messages.Exception("Error exporting file " + fileName + ".", e); } return(false); }