Beispiel #1
0
        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"));
        }
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region IBrepImporter

        public bool DoImport(string fileName, out IEnumerable <Body> bodies)
        {
            bodies = null;
            try
            {
                var bytes    = File.ReadAllBytes(fileName);
                var occShape =
                    BRepExchange.ReadASCII(bytes)
                    ?? BRepExchange.ReadBinary(bytes);

                if (occShape == null)
                {
                    Messages.Error("Error importing file " + fileName + ".");
                    return(false);
                }

                // Get top level transformation for body
                var trsf     = occShape.Location().Transformation();
                var position = trsf.TranslationPart().ToPnt();
                var rotation = trsf.GetRotation();

                // eliminate top level transformation
                occShape.Location(new TopLoc_Location());

                var body = Body.Create(Solid.Create(occShape));
                body.Position = position;
                body.Rotation = rotation;
                body.Name     = Path.GetFileNameWithoutExtension(fileName);

                bodies = new[] { body };
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Messages.Exception("Error importing file " + fileName + ".", e);
            }
            return(false);
        }
Beispiel #3
0
        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"));
        }