Ejemplo n.º 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"));
        }
Ejemplo n.º 2
0
        public void AsciiReadWrite()
        {
            var originalBytes = TestData.GetTestData(@"SourceData\Brep\ImprintRingFace.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
            var writtenBytes = BRepExchange.WriteASCII(originalShape, false);

            Assert.IsNotNull(writtenBytes);
            Assert.AreEqual(4900, writtenBytes.Length, 50); // due to some slight differences (e.g. +/-0)

            // Re-read in
            var rereadShape = BRepExchange.ReadASCII(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"));
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------------------------------------------

        #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);
        }
Ejemplo n.º 4
0
        public void AsciiTriangulation()
        {
            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.WriteASCII(originalShape, true);

            Assert.IsNotNull(writtenBytes);
            Assert.AreEqual(2584000, writtenBytes.Length, 1000); // due to some slight differences (e.g. +/-0)

            // Re-read in with triangulation
            var rereadShape = BRepExchange.ReadASCII(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.WriteASCII(originalShape, false);
            Assert.IsNotNull(writtenBytes);
            Assert.AreEqual(1118000, writtenBytes.Length, 1000); // due to some slight differences (e.g. +/-0)

            // Re-read in w/o triangulation
            rereadShape = BRepExchange.ReadASCII(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"));
        }
Ejemplo n.º 5
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"));
        }