示例#1
0
        public void ReadDxbNoLengthOrPositionStreamTest()
        {
            var data = new byte[]
            {
                // DXB sentinel
                (byte)'A', (byte)'u', (byte)'t', (byte)'o', (byte)'C', (byte)'A', (byte)'D', (byte)' ', (byte)'D', (byte)'X', (byte)'B', (byte)' ', (byte)'1', (byte)'.', (byte)'0', (byte)'\r', (byte)'\n', 0x1A, 0x0,

                // color
                136,        // type specifier for new color
                0x01, 0x00, // color index 1

                // line
                0x01,       // type specifier
                0x01, 0x00, // P1.X = 0x0001
                0x02, 0x00, // P1.Y = 0x0002
                0x03, 0x00, // P1.Z = 0x0003
                0x04, 0x00, // P1.X = 0x0004
                0x05, 0x00, // P1.Y = 0x0005
                0x06, 0x00, // P1.Z = 0x0006

                // null terminator
                0x0
            };

            using (var ms = new MemoryStream(data))
                using (var stream = new StreamWithNoLengthOrPosition(ms))
                {
                    var file = DxfFile.Load(stream);
                    var line = (DxfLine)file.Entities.Single();
                    Assert.Equal(1, line.Color.RawValue);
                    Assert.Equal(new DxfPoint(1, 2, 3), line.P1);
                    Assert.Equal(new DxfPoint(4, 5, 6), line.P2);
                }
        }
示例#2
0
        public void WriteVersionSpecificClassTest_R13()
        {
            var file = new DxfFile();

            file.Header.Version = DxfAcadVersion.R13;
            file.Classes.Add(new DxfClass()
            {
                ClassDxfRecordName = "<class dxf name>",
                CppClassName       = "CPP_CLASS_NAME",
                ApplicationName    = "<application name>",
                ClassVersionNumber = 42
            });
            VerifyFileContains(file, @"
  0
SECTION
  2
CLASSES
  0
<class dxf name>
  1
CPP_CLASS_NAME
  2
<application name>
 90
42
");
        }
示例#3
0
        public void GetInsertEntitiesWhenAddedToFile()
        {
            var line = new DxfLine(new DxfPoint(0.0, 0.0, 0.0), new DxfPoint(1.0, 1.0, 0.0));

            var block = new DxfBlock();

            block.Name = "some-block";
            block.Entities.Add(line);

            var insert = new DxfInsert();

            insert.Name = "some-block";

            var file = new DxfFile();

            file.Blocks.Add(block);

            // no entities because it's not yet part of the file
            Assert.Null(insert.Entities);

            file.Entities.Add(insert);

            // and now that it's in the file the entities can be found
            var foundEntity = insert.Entities.Single();

            Assert.Same(line, foundEntity);
        }
示例#4
0
        public void ThicknessTest_ThicknessShouldBe0()
        {
            var testFile = new DxfFile(PathToFile);
            var testLine = (Line)testFile.Entities.ElementAt(0).Value;

            Assert.IsTrue(Math.Abs(testLine.Thickness) < GeoMath.Tolerance);
        }
示例#5
0
        public void DictionaryRoundTripTest1()
        {
            // dictionary with DICTIONARYVAR values
            var dict = new DxfDictionary();

            dict["key-1"] = new DxfDictionaryVariable()
            {
                Value = "value-1"
            };
            dict["key-2"] = new DxfDictionaryVariable()
            {
                Value = "value-2"
            };

            var file = new DxfFile();

            file.Clear();
            file.Header.Version = DxfAcadVersion.R2000;
            file.Objects.Add(dict);
            var text = ToString(file);

            var parsedFile       = Parse(text);
            var roundTrippedDict = parsedFile.Objects.OfType <DxfDictionary>().Single(d => d.Keys.Count == 2);

            Assert.Equal("value-1", ((DxfDictionaryVariable)roundTrippedDict["key-1"]).Value);
            Assert.Equal("value-2", ((DxfDictionaryVariable)roundTrippedDict["key-2"]).Value);
        }
示例#6
0
        public void WriteDimensionWithStyleDifferenceXData()
        {
            var file             = new DxfFile();
            var standardDimStyle = file.DimensionStyles.Single(ds => ds.Name == "STANDARD");
            var customDimStyle   = new DxfDimStyle()
            {
                DimensioningSuffix = "some suffix"
            };
            var dim = new DxfAlignedDimension();

            dim.XData = DxfDimStyle.GenerateStyleDifferenceAsXData(standardDimStyle, customDimStyle);
            EnsureFileContainsEntity(dim, @"
1001
ACAD
1000
DSTYLE
1002
{
1070
   3
1000
some suffix
1002
}
  0
ENDSEC
", DxfAcadVersion.R14);
        }
        public void WriteVersionSpecificEntityProperties()
        {
            var file = new DxfFile();

            file.Entities.Add(new DxfLeader()
            {
                AnnotationOffset = new DxfVector(42.0, 43.0, 44.0),
            });

            // annotation offset is only written for >= R14
            var annotationOffsetText = @"
213
42.0
223
43.0
233
44.0
";

            file.Header.Version = DxfAcadVersion.R14;
            VerifyFileContains(file, annotationOffsetText);

            file.Header.Version = DxfAcadVersion.R13;
            VerifyFileDoesNotContain(file, annotationOffsetText);
        }
示例#8
0
        public void WriteLightListTest()
        {
            var file = new DxfFile();

            file.Clear();
            file.Header.Version = DxfAcadVersion.R14;
            file.Entities.Add(new DxfLight()
            {
                Name = "light-name"
            });
            var lightList = new DxfLightList();

            lightList.Version = 42;
            lightList.Lights.Add((DxfLight)file.Entities.Single());
            file.Objects.Add(lightList);
            VerifyFileContains(file, @"
  0
LIGHTLIST
  5
#
100
AcDbLightList
 90
42
 90
1
  5
#
  1
light-name
");
        }
示例#9
0
        public IActionResult Edit(int id, [Bind("Id,FK_ApplicatioUserId,FileName,StaticFilePath,RelativeFilePath,UploadedTime")] DxfFile dxfFile)
        {
            if (id != dxfFile.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    repo.Update(dxfFile);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DxfFileExists(dxfFile.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FK_ApplicatioUserId"] = new SelectList(_context.Users, "Id", "Id", dxfFile.FK_ApplicatioUserId);
            return(View(dxfFile));
        }
示例#10
0
        public void DictionaryRoundTripTest2()
        {
            // dictionary with sub-dictionary wit DICTIONARYVAR value
            var dict1 = new DxfDictionary();
            var dict2 = new DxfDictionary();

            dict1["key-1"] = dict2;
            dict2["key-2"] = new DxfDictionaryVariable()
            {
                Value = "value-2"
            };

            var file = new DxfFile();

            file.Clear();
            file.Header.Version = DxfAcadVersion.R2000;
            file.Objects.Add(dict1);
            var text = ToString(file);

            var parsedFile        = Parse(text);
            var roundTrippedDict1 = parsedFile.Objects.OfType <DxfDictionary>().First(d => d.ContainsKey("key-1"));
            var roundTrippedDict2 = (DxfDictionary)roundTrippedDict1["key-1"];

            Assert.Equal("value-2", ((DxfDictionaryVariable)roundTrippedDict2["key-2"]).Value);
        }
示例#11
0
        public void DictionaryRoundTripTest3()
        {
            // dictionary with default with DICTIONARYVAR values
            var dict = new DxfDictionaryWithDefault();

            dict.DefaultObject = new DxfDictionaryVariable()
            {
                Value = "default-value"
            };
            dict["key-1"] = new DxfDictionaryVariable()
            {
                Value = "value-1"
            };

            var file = new DxfFile();

            file.Clear();
            file.Header.Version = DxfAcadVersion.R2000;
            file.Objects.Add(dict);
            var text = ToString(file);

            var parsedFile       = Parse(text);
            var roundTrippedDict = parsedFile.Objects.OfType <DxfDictionaryWithDefault>().Single();

            Assert.Equal("value-1", ((DxfDictionaryVariable)roundTrippedDict["key-1"]).Value);
            Assert.Equal("default-value", ((DxfDictionaryVariable)roundTrippedDict.DefaultObject).Value);
        }
示例#12
0
        public void RenderInsertTest()
        {
            var block = new DxfBlock();

            block.Name = "some-block";
            block.Entities.Add(new DxfLine(new DxfPoint(0.0, 0.0, 0.0), new DxfPoint(10.0, 10.0, 0.0)));

            var insert = new DxfInsert();

            insert.Name     = "some-block";
            insert.Location = new DxfPoint(0.0, 5.0, 0.0);

            var file = new DxfFile();

            file.Blocks.Add(block);
            file.Entities.Add(insert);

            var expected = new XElement("g",
                                        new XAttribute("class", "dxf-insert some-block"),
                                        new XAttribute("transform", "translate(0.0 5.0) scale(1.0 1.0)"),
                                        new XElement("line",
                                                     new XAttribute("x1", "0.0"), new XAttribute("y1", "0.0"), new XAttribute("x2", "10.0"), new XAttribute("y2", "10.0"),
                                                     new XAttribute("stroke-width", "1.0px"),
                                                     new XAttribute("vector-effect", "non-scaling-stroke")));

            var actual = insert.ToXElement();

            AssertXElement(expected, actual);
        }
示例#13
0
        public void ReadDxbPolylineTest()
        {
            var data = DxbSentinel.Concat(new byte[]
            {
                19,         // polyline
                0x00, 0x00, // is closed = false

                20,         // vertex
                0x01, 0x00, // x
                0x02, 0x00, // y

                20,         // vertex
                0x03, 0x00, // x
                0x04, 0x00, // y

                17,         // seqend

                0x00        // null terminator
            }).ToArray();

            using (var stream = new MemoryStream(data))
            {
                var file = DxfFile.Load(stream);
                var poly = (DxfPolyline)file.Entities.Single();
                Assert.Equal(2, poly.Vertices.Count);
                Assert.Equal(new DxfPoint(1.0, 2.0, 0.0), poly.Vertices[0].Location);
                Assert.Equal(new DxfPoint(3.0, 4.0, 0.0), poly.Vertices[1].Location);
            }
        }
示例#14
0
        public void ReadDxbNoLengthOrPositionStreamTest()
        {
            var data = DxbSentinel.Concat(new byte[]
            {
                // color
                136,        // type specifier for new color
                0x01, 0x00, // color index 1

                // line
                0x01,       // type specifier
                0x01, 0x00, // P1.X = 0x0001
                0x02, 0x00, // P1.Y = 0x0002
                0x03, 0x00, // P1.Z = 0x0003
                0x04, 0x00, // P2.X = 0x0004
                0x05, 0x00, // P2.Y = 0x0005
                0x06, 0x00, // P2.Z = 0x0006

                0x0         // null terminator
            }).ToArray();

            using (var ms = new MemoryStream(data))
                using (var stream = new StreamWithNoLengthOrPosition(ms))
                {
                    var file = DxfFile.Load(stream);
                    var line = (DxfLine)file.Entities.Single();
                    Assert.Equal(1, line.Color.RawValue);
                    Assert.Equal(new DxfPoint(1, 2, 3), line.P1);
                    Assert.Equal(new DxfPoint(4, 5, 6), line.P2);
                }
        }
示例#15
0
        public void WriteLayersTableTest()
        {
            var layer = new DxfLayer("layer-name");

            layer.ExtensionDataGroups.Add(new DxfCodePairGroup("APP_NAME", new IDxfCodePairOrGroup[]
            {
                new DxfCodePair(1, "foo"),
                new DxfCodePair(2, "bar"),
            }));
            var file = new DxfFile();

            file.Layers.Add(layer);
            VerifyFileContains(file, @"
  0
LAYER
  5
#
102
{APP_NAME
  1
foo
  2
bar
102
}
");
        }
示例#16
0
        public async Task <IActionResult> CanvasDrawer([Bind("TopLeft,TopRight,BottomRight,BottomLeft,Precision")] Polygon polygon)
        {
            var CurrentDate       = DateTime.Now;
            var UploadDate        = CurrentDate.ToString("yyyyMMdd_hhmmss");
            var DxfFileStaticPath = TempData["DxfFileStaticPath1"];
            var DxFRelativePaths  = TempData["DxFRelativePaths1"];
            var StaticPath        = TempData["StaticImagePath1"];
            var FileNameFull      = TempData["FileNameFull1"].ToString();
            var DxfFileExtension  = ".dxf";
            //Function Here
            //var ExcuationStatus = ModelBuilder(StaticPathNameNoExtension);
            var ExcuationStatus = 0;
            var currentUser     = await _userManager.FindByNameAsync(User.Identity.Name);

            if (ExcuationStatus == 0)
            {
                var DxfFile = new DxfFile
                {
                    FileName            = FileNameFull,
                    StaticFilePath      = DxfFileStaticPath + DxfFileExtension,
                    RelativeFilePath    = DxfFileExtension,
                    FK_ApplicatioUserId = currentUser.Id,
                    UploadedTime        = CurrentDate
                };
                repo.Add(DxfFile);
                RedirectToAction("UploadCompelete");
            }
            else
            {
                RedirectToAction("ErrorPage");
            }
            return(Ok());
        }
示例#17
0
        private static void TestHeaderOrder(string expectedOrderText, DxfAcadVersion version)
        {
            var file = new DxfFile();

            file.Header.Version = version;
            file.Header.CurrentMaterialHandle = 100u;
            file.Header.InterferenceObjectVisualStylePointer   = 101u;
            file.Header.InterferenceViewPortVisualStylePointer = 102u;
            var contents     = ToString(file);
            var headerEndSec = contents.IndexOf("ENDSEC");

            contents = contents.Substring(0, headerEndSec);
            var expectedOrder = expectedOrderText
                                .Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                                .Where(s => s.StartsWith("$"))
                                .Select(s => s.Trim())
                                .ToArray();
            var actualOrder = contents
                              .Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                              .Where(s => s.StartsWith("$"))
                              .Select(s => s.Trim())
                              .ToArray();

            AssertArrayEqual(expectedOrder, actualOrder);
        }
示例#18
0
 private async Task <DxfFile> WriteToFile(Drawing drawing)
 {
     using (var stream = await WriteToStream(drawing))
     {
         return(DxfFile.Load(stream));
     }
 }
示例#19
0
        public void ODAReadAllObjectsTest()
        {
            // create a file with all objects and ensure ODA can read it
            var file = new DxfFile();

            file.Header.Version = DxfAcadVersion.R2013;
            var assembly = typeof(DxfFile).GetTypeInfo().Assembly;

            foreach (var type in assembly.GetTypes().Where(DxfReaderWriterTests.IsObjectOrDerived))
            {
                var ctor = type.GetConstructor(Type.EmptyTypes);
                if (ctor != null)
                {
                    // add the object with its default initialized values
                    var obj = (DxfObject)ctor.Invoke(new object[0]);
                    file.Objects.Add(obj);
                }
            }

            using (var input = new ManageTemporaryDirectory())
                using (var output = new ManageTemporaryDirectory())
                {
                    var inputFile = Path.Combine(input.DirectoryPath, "file.dxf");
                    using (var fs = new FileStream(inputFile, FileMode.Create))
                    {
                        file.Save(fs);
                    }

                    AssertODAConvert(input.DirectoryPath, output.DirectoryPath, DxfAcadVersion.R2013);
                }
        }
示例#20
0
        public void WriteTableWithExtendedDataTest()
        {
            var file = new DxfFile();

            file.Header.Version = DxfAcadVersion.R14;
            file.TablesSection.StyleTable.ExtensionDataGroups.Add(new DxfCodePairGroup("ACAD_XDICTIONARY",
                                                                                       new IDxfCodePairOrGroup[]
            {
                new DxfCodePair(360, "AAAA"),
                new DxfCodePair(360, "BBBB")
            }));
            file.Styles.Add(new DxfStyle());
            VerifyFileContains(file, @"
  0
TABLE
  2
STYLE
  5
#
102
{ACAD_XDICTIONARY
360
AAAA
360
BBBB
102
}
100
AcDbSymbolTable
");
        }
示例#21
0
        public void SimpleLineTest()
        {
            var dxf = new DxfFile();

            dxf.ActiveViewPort = new DxfViewPort("test")
            {
                LowerLeft  = new DxfPoint(0.0, 0.0, 0.0),
                ViewHeight = 11.0,
            };
            // line from (0,0) to (8.5,11), but half scale
            dxf.Entities.Add(new DxfLine(new DxfPoint(0.0, 0.0, 0.0), new DxfPoint(8.5, 11.0, 0.0)));
            var pdf = ConvertToString(dxf, scale: 0.5);
            // expected line from lower left of sheet to center
            var expected = NormalizeCrLf(@"
stream
0 w
0 0 0 RG
0 0 0 rg
0.00 0.00 m
306.00 396.00 l
S
endstream".Trim());

            Assert.Contains(expected, pdf);
        }
示例#22
0
        public void WriteNormalLayerColorTest()
        {
            var file = new DxfFile();

            file.Header.Version = DxfAcadVersion.R2000;
            file.Layers.Add(new DxfLayer("name", DxfColor.FromIndex(5))
            {
                IsLayerOn = true
            });
            VerifyFileContains(file, @"
  0
LAYER
  5
#
330
#
100
AcDbSymbolTableRecord
100
AcDbLayerTableRecord
  2
name
 70
0
 62
5
");
        }
示例#23
0
        /// <summary>
        /// Create a DXF Entity Object for a ContentElement.
        /// </summary>
        public override void TryAddDxfEntity(DxfFile doc, ContentElement contentElement, DxfRenderContext context)
        {
            try
            {
                var chosenSymbol = pickSymbolByContext(contentElement, context);
                if (chosenSymbol == null)
                {
                    Console.WriteLine($"Symbol for {contentElement.Id} was null");
                    chosenSymbol = generateSymbolFromBoundingBox(contentElement, context);
                    return;
                }
                // TODO: make all this handle await?
                var geometry = chosenSymbol.GetGeometryAsync().GetAwaiter().GetResult();
                if (geometry == null)
                {
                    Console.WriteLine($"Failed to get geometry for {contentElement.Id}");
                    return;
                }
                var polygons  = geometry.OfType <Polygon>().Select(p => p.ToDxf()).Where(e => e != null).ToList();
                var polylines = geometry.OfType <Polyline>().Select(p => p.ToDxf()).Where(e => e != null).ToList();
                var entities  = new List <DxfEntity>(polygons.Union(polylines));
                if (entities.Count() == 0)
                {
                    Console.WriteLine($"No entities for {contentElement.Id}");
                    return;
                }
                var blockName = contentElement.GetBlockName();
                var block     = new DxfBlock
                {
                    BasePoint = contentElement.Transform.ToDxfPoint(context),
                    Name      = blockName
                };
                doc.BlockRecords.Add(new DxfBlockRecord(blockName));

                foreach (var p in entities)
                {
                    block.Entities.Add(p);
                }
                AddElementToLayer(doc, contentElement, entities, context);
                doc.Blocks.Add(block);
                // if it's not being used as an element definition,
                // add an instance of it to the drawing.
                if (!contentElement.IsElementDefinition)
                {
                    var insert = new DxfInsert
                    {
                        Name     = blockName,
                        Location = contentElement.Transform.ToDxfPoint(context),
                    };
                    doc.Entities.Add(insert);
                    AddElementToLayer(doc, contentElement, new[] { insert }, context);
                }
            }
            catch (Exception e)
            {
                //TODO: implement exception logging
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
示例#24
0
        public void WriteVersionSpecificClassTest_R14()
        {
            var file = new DxfFile();

            file.Header.Version = DxfAcadVersion.R14;
            file.Classes.Add(new DxfClass()
            {
                ClassDxfRecordName = "<class dxf name>",
                CppClassName       = "CPP_CLASS_NAME",
                ApplicationName    = "<application name>",
                ProxyCapabilities  = new DxfProxyCapabilities(42)
            });
            VerifyFileContains(file, @"
  0
SECTION
  2
CLASSES
  0
CLASS
  1
<class dxf name>
  2
CPP_CLASS_NAME
  3
<application name>
 90
42
");
        }
示例#25
0
        public void TestingLinesFromEntities_CastingFromEntityToLine_GettingLength()
        {
            // The testfile
            var testFile =
                new DxfFile(@"C:\Dev\Dxflib\Dxflib.Tests\DxfTestFiles\LineParseTest.dxf");

            // Here I want to see if the Entity that is stored in the
            // dxf file will be able to be casted back to a Line without loosing any
            // information.
            double sum = 0;

            foreach (var entity in testFile.Entities.Values)
            {
                // Only cast the entity if the entity type is a line
                // to prevent errors
                Line testLine = null;
                if (entity.EntityType == typeof(Line))
                {
                    testLine = (Line)entity;
                }
                if (testLine != null)
                {
                    sum += testLine.Length;
                }
            }
            Debug.WriteLine(sum); // Print out the sum

            // Asset that the total length of the lines is ...
            Assert.IsTrue(Math.Abs(sum - 85591.0668) < GeoMath.Tolerance);
        }
示例#26
0
        public void EntityCountTest_ThereShouldBe2EntitesThatAreLines()
        {
            var testFile =
                new DxfFile(@"C:\Dev\Dxflib\Dxflib.Tests\DxfTestFiles\LineParseTest.dxf");

            Assert.IsTrue(testFile.Entities.Count == 2);
            Assert.IsTrue(((Line)testFile.Entities.ElementAt(0).Value).EntityType == typeof(Line));
        }
示例#27
0
        public void EntityTypeTest_ShouldBe2Lines()
        {
            var testFile =
                new DxfFile(@"C:\Dev\Dxflib\Dxflib.Tests\DxfTestFiles\LineParseTest.dxf");
            var linesSum = testFile.Entities.Values.Count(entity => entity.EntityType == typeof(Line));

            Assert.IsTrue(linesSum == 2);
        }
示例#28
0
        public void AreaTest_WithoutBulge()
        {
            var dxfFile   = new DxfFile(PathToFile);
            var polylines = dxfFile.Entities.GetEntitiesByType <LwPolyLine>();

            Debug.WriteLine($"Total Area of Polyline is: {polylines[0].Area}");
            Assert.IsTrue(Math.Abs(polylines[0].Area - 11.8750) < GeoMath.Tolerance);
        }
示例#29
0
        private static void EnsureFileDoesNotContainWithEntity(DxfEntity entity, string unwantedText, DxfAcadVersion version = DxfAcadVersion.R12)
        {
            var file = new DxfFile();

            file.Header.Version = version;
            file.Entities.Add(entity);
            VerifyFileDoesNotContain(file, unwantedText, sectionType: DxfSectionType.Entities);
        }
示例#30
0
        private static void EnsureFileContainsEntity(DxfEntity entity, string text, DxfAcadVersion version = DxfAcadVersion.R12)
        {
            var file = new DxfFile();

            file.Header.Version = version;
            file.Entities.Add(entity);
            VerifyFileContains(file, text, sectionType: DxfSectionType.Entities);
        }
示例#31
0
 public void WriteStringWithControlCharactersTest()
 {
     var file = new DxfFile();
     file.Entities.Add(new DxfText() { Value = "a\x7^\x1E b" });
     VerifyFileContains(file, @"
       1
     a^G^ ^^ b
     ");
 }
示例#32
0
 public void WriteLayersTableTest()
 {
     var layer = new DxfLayer("layer-name");
     layer.ExtensionDataGroups.Add(new DxfCodePairGroup("APP_NAME", new DxfCodePairOrGroup[]
     {
         new DxfCodePair(1, "foo"),
         new DxfCodePair(2, "bar"),
     }));
     var file = new DxfFile();
     file.Layers.Add(layer);
     VerifyFileContains(file, @"
       0
     LAYER
       5
     A
     102
     {APP_NAME
       1
     foo
       2
     bar
     102
     }
     ");
 }
示例#33
0
 public void WriteVersionSpecificBlockTest_R13()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R13;
     var block = new DxfBlock();
     block.Name = "<block name>";
     block.Handle = 0x42u;
     block.Layer = "<layer>";
     block.XrefName = "<xref>";
     block.BasePoint = new DxfPoint(11, 22, 33);
     block.Entities.Add(new DxfModelPoint(new DxfPoint(111, 222, 333)));
     file.Blocks.Add(block);
     VerifyFileContains(file, @"
       0
     SECTION
       2
     BLOCKS
       0
     BLOCK
       5
     42
     330
     0
     100
     AcDbEntity
       8
     <layer>
     100
     AcDbBlockBegin
       2
     <block name>
      70
     0
      10
     11.0
      20
     22.0
      30
     33.0
       3
     <block name>
       1
     <xref>
     ");
     VerifyFileContains(file, @"
      10
     111.0
      20
     222.0
      30
     333.0
     ");
     VerifyFileContains(file, @"
       0
     ENDBLK
       5
     4C
     100
     AcDbEntity
       8
     <layer>
     100
     AcDbBlockEnd
       0
     ENDSEC
     ");
 }
示例#34
0
 public void WriteThumbnailTest_SetThumbnailBitmap()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R2000;
     var header = DxfThumbnailImageSection.BITMAPFILEHEADER;
     var bitmap = header.Concat(new byte[] { 0x01, 0x23, 0x45 }).ToArray();
     file.SetThumbnailBitmap(bitmap);
     VerifyFileContains(file, @"  0
     SECTION
       2
     THUMBNAILIMAGE
      90
     3
     310
     012345
       0
     ENDSEC");
 }
示例#35
0
        public void WriteVersionSpecificBlockRecordTest_R13()
        {
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R13;
            file.BlockRecords.Add(new DxfBlockRecord());

            // BLOCK_RECORD added in R13
            VerifyFileContains(file, @"
              0
            TABLE
              2
            BLOCK_RECORD
            ");
        }
示例#36
0
        public void WriteVersionSpecificSectionsTest_R12()
        {
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R12;
            file.Classes.Add(new DxfClass());

            // no CLASSES section in R12
            VerifyFileDoesNotContain(file, @"
              0
            SECTION
              2
            CLASSES
            ");

            // no OBJECTS section in R12
            VerifyFileDoesNotContain(file, @"
              0
            SECTION
              2
            OBJECTS
            ");
        }
示例#37
0
 public void WriteThumbnailTestR14()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R14;
     file.RawThumbnail = new byte[] { 0x01, 0x23, 0x45 };
     VerifyFileDoesNotContain(file, @"  0
     SECTION
       2
     THUMBNAILIMAGE");
 }
示例#38
0
        public void AutoCadReadAllEntitiesTest()
        {
            // TODO: make these work with AutoCAD
            var unsupportedTypes = new[]
            {
                // unsupported because I need to write more information with them
                typeof(DxfInsert), // need a block to insert
                typeof(DxfLeader), // needs vertices
                typeof(DxfMLine), // need to set MLINESTYLE and MLINESTYLE dictionary
                typeof(DxfDgnUnderlay), // AcDbUnderlayDefinition object ID must be set
                typeof(DxfDwfUnderlay), // AcDbUnderlayDefinition object ID must be set
                typeof(DxfPdfUnderlay), // AcDbUnderlayDefinition object ID must be set
                typeof(DxfSpline), // need to supply control/fit points
                typeof(DxfVertex), // can't write a lone vertex?

                // unsupported for other reasons TBD
                typeof(Dxf3DSolid),
                typeof(DxfAttribute),
                typeof(DxfAttributeDefinition),
                typeof(DxfBody),
                typeof(DxfHelix), // acad expects AcDbSpline?
                typeof(DxfLight),
                typeof(DxfMText),
                typeof(DxfRegion),
                typeof(DxfProxyEntity),
                typeof(DxfShape),
                typeof(DxfTolerance),
            };

            // create a file with all entities and ensure AutoCAD can read it
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R2010;
            var assembly = typeof(DxfFile).Assembly;
            foreach (var type in assembly.GetTypes())
            {
                if (DxfReaderWriterTests.IsEntityOrDerived(type) && type.BaseType != typeof(DxfDimensionBase) && !unsupportedTypes.Contains(type))
                {
                    var ctor = type.GetConstructor(Type.EmptyTypes);
                    if (ctor != null)
                    {
                        // add the entity with its default initialized values
                        var entity = (DxfEntity)ctor.Invoke(new object[0]);
                        file.Entities.Add(entity);

                        if (entity is DxfText)
                        {
                            // set an explicit value to ensure that it could be round-tripped
                            ((DxfText)entity).Value = "sample text";
                        }
                    }
                }
            }

            using (var directory = new ManageTemporaryDirectory())
            {
                var sampleFilePath = Path.Combine(directory.DirectoryPath, "file.dxf");
                using (var fs = new FileStream(sampleFilePath, FileMode.Create))
                {
                    file.Save(fs);
                }

                var scriptFilePath = Path.Combine(directory.DirectoryPath, "script.scr");
                var outputFilePath = Path.Combine(directory.DirectoryPath, "result.dxf");
                File.WriteAllLines(scriptFilePath, new[]
                {
                    "FILEDIA 0",
                    $"DXFIN \"{sampleFilePath}\"",
                    $"DXFOUT \"{outputFilePath}\" 16",
                    "FILEDIA 1",
                    "QUIT Y"
                });
                ExecuteAutoCadScript(scriptFilePath);

                // read file back in and confirm DxfText value
                DxfFile resultFile;
                using (var fs = new FileStream(outputFilePath, FileMode.Open))
                {
                    resultFile = DxfFile.Load(fs);
                }

                var text = resultFile.Entities.OfType<DxfText>().Single();
                Assert.Equal("sample text", text.Value);
            }
        }
示例#39
0
 public void WriteVersionSpecificClassTest_R14()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R14;
     file.Classes.Add(new DxfClass()
     {
         ClassDxfRecordName = "<class dxf name>",
         CppClassName = "CPP_CLASS_NAME",
         ApplicationName = "<application name>",
         ProxyCapabilities = new DxfProxyCapabilities(42)
     });
     VerifyFileContains(file, @"
       0
     SECTION
       2
     CLASSES
       0
     CLASS
       1
     <class dxf name>
       2
     CPP_CLASS_NAME
       3
     <application name>
      90
     42
     ");
 }
示例#40
0
 public void TeighaReadIxMiliaNewFileCompatTest()
 {
     TestTeighaReadIxMiliaGeneratedFile(() =>
     {
         var file = new DxfFile();
         file.Entities.Add(new DxfLine(new DxfPoint(0, 0, 0), new DxfPoint(10, 10, 0)));
         return file;
     });
 }
示例#41
0
        public void TeighaReadAllObjectsTest()
        {
            // create a file with all objects and ensure Teigha can read it
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R2013;
            var assembly = typeof(DxfFile).Assembly;
            foreach (var type in assembly.GetTypes())
            {
                if (DxfReaderWriterTests.IsObjectOrDerived(type))
                {
                    var ctor = type.GetConstructor(Type.EmptyTypes);
                    if (ctor != null)
                    {
                        // add the object with its default initialized values
                        var obj = (DxfObject)ctor.Invoke(new object[0]);
                        file.Objects.Add(obj);
                    }
                }
            }

            using (var input = new ManageTemporaryDirectory())
            using (var output = new ManageTemporaryDirectory())
            {
                var inputFile = Path.Combine(input.DirectoryPath, "file.dxf");
                using (var fs = new FileStream(inputFile, FileMode.Create))
                {
                    file.Save(fs);
                }

                AssertTeighaConvert(input.DirectoryPath, output.DirectoryPath, DxfAcadVersion.R2013);
            }
        }
示例#42
0
        public void AutoCadReadIxMiliaFileCompatTest()
        {
            // save a DXF file in all the formats that IxMilia.Dxf and AutoCAD support and try to get AutoCAD to read all of them
            using (var directory = new ManageTemporaryDirectory())
            {
                var tempDir = directory.DirectoryPath;
                var versions = new[]
                {
                    DxfAcadVersion.R9,
                    DxfAcadVersion.R10,
                    DxfAcadVersion.R11,
                    DxfAcadVersion.R12,
                    //DxfAcadVersion.R13,
                    DxfAcadVersion.R14,
                    DxfAcadVersion.R2000,
                    DxfAcadVersion.R2004,
                    DxfAcadVersion.R2007,
                    DxfAcadVersion.R2010,
                    DxfAcadVersion.R2013
                };

                // save the minimal file with all versions
                var file = new DxfFile();
                var text = new DxfText(DxfPoint.Origin, 2.0, "");
                file.Entities.Add(text);
                foreach (var version in versions)
                {
                    var fileName = $"file.{version}.dxf";
                    file.Header.Version = version;
                    text.Value = version.ToString();
                    var outputPath = Path.Combine(tempDir, fileName);
                    using (var fs = new FileStream(outputPath, FileMode.Create))
                    {
                        file.Save(fs);
                    }
                }

                // open each file in AutoCAD and try to write it back out
                var lines = new List<string>();
                lines.Add("FILEDIA 0");
                foreach (var version in versions)
                {
                    lines.Add("ERASE ALL ");
                    lines.Add($"DXFIN \"{Path.Combine(tempDir, $"file.{version}.dxf")}\"");
                    lines.Add($"DXFOUT \"{Path.Combine(tempDir, $"result.{version}.dxf")}\" V R12 16");
                }

                lines.Add("FILEDIA 1");
                lines.Add("QUIT Y");

                // create and execute the script
                var scriptPath = Path.Combine(tempDir, "script.scr");
                File.WriteAllLines(scriptPath, lines);

                ExecuteAutoCadScript(scriptPath);

                // check each resultant file for the correct version and text
                foreach (var version in versions)
                {
                    DxfFile dxf;
                    using (var fs = new FileStream(Path.Combine(tempDir, $"result.{version}.dxf"), FileMode.Open))
                    {
                        dxf = DxfFile.Load(fs);
                    }

                    Assert.Equal(version.ToString(), ((DxfText)dxf.Entities.Single()).Value);
                }
            }
        }
示例#43
0
 public void WriteTableWithExtendedDataTest()
 {
     var file = new DxfFile();
     file.TablesSection.StyleTable.ExtensionDataGroups.Add(new DxfCodePairGroup("ACAD_XDICTIONARY",
         new DxfCodePairOrGroup[]
         {
             new DxfCodePair(360, "AAAA"),
             new DxfCodePair(360, "BBBB")
         }));
     file.Styles.Add(new DxfStyle());
     VerifyFileContains(file, @"
       0
     SECTION
       2
     TABLES
       0
     TABLE
       2
     STYLE
       5
     6
     102
     {ACAD_XDICTIONARY
     360
     AAAA
     360
     BBBB
     102
     }
     100
     AcDbSymbolTable
      70
     0
     ");
 }
示例#44
0
        public void WriteVersionSpecificSectionsTest_R13()
        {
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R13;
            file.Classes.Add(new DxfClass());

            // CLASSES section added in R13
            VerifyFileContains(file, @"
              0
            SECTION
              2
            CLASSES
            ");

            // OBJECTS section added in R13
            // NYI
            //            VerifyFileContains(file, @"
            //  0
            //SECTION
            //  2
            //OBJECTS
            //");
        }
示例#45
0
 public void WriteTableWithoutExtendedDataTest()
 {
     var file = new DxfFile();
     file.Styles.Add(new DxfStyle());
     VerifyFileContains(file, @"
       0
     SECTION
       2
     TABLES
       0
     TABLE
       2
     STYLE
       5
     6
     100
     AcDbSymbolTable
      70
     0
     ");
 }
示例#46
0
 public void WriteWithInvariantCultureTest()
 {
     var existingCulture = Thread.CurrentThread.CurrentCulture;
     try
     {
         Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
         var file = new DxfFile();
         file.Header.CreationDate = new DateTime(2013, 7, 4, 14, 9, 48, 355);
         VerifyFileContains(file, @"
     $TDCREATE
      40
     2456478.590143
     ");
     }
     finally
     {
         Thread.CurrentThread.CurrentCulture = existingCulture;
     }
 }
示例#47
0
 public void WriteThumbnailTestR2000()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R2000;
     file.RawThumbnail = new byte[] { 0x01, 0x23, 0x45 };
     VerifyFileContains(file, @"  0
     SECTION
       2
     THUMBNAILIMAGE
      90
     3
     310
     012345
       0
     ENDSEC");
 }
示例#48
0
 public void WritingEmptyBlockR2000Test()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R2000;
     file.Blocks.Add(new DxfBlock());
     using (var ms = new MemoryStream())
     {
         file.Save(ms);
     }
 }
示例#49
0
        public void WriteVersionSpecificBlockRecordTest_R12()
        {
            var file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R12;
            file.BlockRecords.Add(new DxfBlockRecord());

            // no BLOCK_RECORD in R12
            VerifyFileDoesNotContain(file, @"
              0
            TABLE
              2
            BLOCK_RECORD
            ");
        }
示例#50
0
 public void WritingPartiallyInitializedTablesTest()
 {
     var file = new DxfFile();
     file.ApplicationIds.Add(new DxfAppId());
     file.BlockRecords.Add(new DxfBlockRecord());
     file.DimensionStyles.Add(new DxfDimStyle());
     file.Layers.Add(new DxfLayer());
     file.Linetypes.Add(new DxfLineType());
     file.Styles.Add(new DxfStyle());
     file.UserCoordinateSystems.Add(new DxfUcs());
     file.Views.Add(new DxfView());
     file.ViewPorts.Add(new DxfViewPort());
     using (var ms = new MemoryStream())
     {
         file.Save(ms);
     }
 }
示例#51
0
 public void WriteVersionSpecificBlockRecordTest_R2000()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R2000;
     var blockRecord = new DxfBlockRecord()
     {
         Name = "<name>",
         XData = new DxfXData("ACAD",
             new DxfXDataItem[]
             {
                 new DxfXDataString("DesignCenter Data"),
                 new DxfXDataControlGroup(
                     new []
                     {
                         new DxfXDataInteger(0),
                         new DxfXDataInteger(1),
                         new DxfXDataInteger(2)
                     })
             }),
         BitmapData = new byte[]
         {
             0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
             0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09
         }
     };
     file.BlockRecords.Add(blockRecord);
     VerifyFileContains(file, @"
       0
     TABLE
       2
     BLOCK_RECORD
       5
     2
     330
     0
     100
     AcDbSymbolTable
      70
     0
       0
     BLOCK_RECORD
       5
     A
     330
     0
     100
     AcDbSymbolTableRecord
     100
     AcDbBlockTableRecord
       2
     <name>
     340
     0
     310
     010203040506070809010203040506070809
     1001
     ACAD
     1000
     DesignCenter Data
     1002
     {
     1070
     0
     1070
     1
     1070
     2
     1002
     }
       0
     ENDTAB
     ");
 }
示例#52
0
        public void Code280ShortInsteadOfCode290BoolTest()
        {
            // the spec says header variables $HIDETEXT, $INTERSECTIONDISPLAY,  and $XCLIPFRAME should be code 290
            // bools but some R2010 files encountered in the wild have a code 280 short instead

            // first test code 290 bool
            var file = Section("HEADER", @"
              9
            $ACADVER
              1
            AC1018
              9
            $HIDETEXT
            290
            1
              9
            $INTERSECTIONDISPLAY
            290
            1
              9
            $XCLIPFRAME
            290
            1
            ");
            Assert.True(file.Header.HideTextObjectsWhenProducintHiddenView);
            Assert.True(file.Header.DisplayIntersectionPolylines);
            Assert.True(file.Header.IsXRefClippingBoundaryVisible);

            // now test code 280 short
            file = Section("HEADER", @"
              9
            $ACADVER
              1
            AC1018
              9
            $HIDETEXT
            280
            1
              9
            $INTERSECTIONDISPLAY
            280
            1
              9
            $XCLIPFRAME
            280
            1
            ");
            Assert.True(file.Header.HideTextObjectsWhenProducintHiddenView);
            Assert.True(file.Header.DisplayIntersectionPolylines);
            Assert.True(file.Header.IsXRefClippingBoundaryVisible);

            // verify that these variables aren't written twice
            file = new DxfFile();
            file.Header.Version = DxfAcadVersion.R2004;
            var text = ToString(file);

            Assert.True(text.IndexOf("$HIDETEXT") > 0); // make sure it's there
            Assert.Equal(text.IndexOf("$HIDETEXT"), text.LastIndexOf("$HIDETEXT")); // first and last should be the same

            Assert.True(text.IndexOf("$INTERSECTIONDISPLAY") > 0); // make sure it's there
            Assert.Equal(text.IndexOf("$INTERSECTIONDISPLAY"), text.LastIndexOf("$INTERSECTIONDISPLAY")); // first and last should be the same

            Assert.True(text.IndexOf("$XCLIPFRAME") > 0); // make sure it's there
            Assert.Equal(text.IndexOf("$XCLIPFRAME"), text.LastIndexOf("$XCLIPFRAME")); // first and last should be the same
        }
示例#53
0
 public void WriteVersionSpecificClassTest_R13()
 {
     var file = new DxfFile();
     file.Header.Version = DxfAcadVersion.R13;
     file.Classes.Add(new DxfClass()
     {
         ClassDxfRecordName = "<class dxf name>",
         CppClassName = "CPP_CLASS_NAME",
         ApplicationName = "<application name>",
         ClassVersionNumber = 42
     });
     VerifyFileContains(file, @"
       0
     SECTION
       2
     CLASSES
       0
     <class dxf name>
       1
     CPP_CLASS_NAME
       2
     <application name>
      90
     42
     ");
 }
示例#54
0
        public void WriteDxbTest()
        {
            // write file
            var file = new DxfFile();
            file.Entities.Add(new DxfLine(new DxfPoint(1, 2, 3), new DxfPoint(4, 5, 6)));
            var stream = new MemoryStream();
            file.SaveDxb(stream);
            stream.Seek(0, SeekOrigin.Begin);

            // read it back in
            var dxb = DxfFile.Load(stream);
            var line = (DxfLine)dxb.Entities.Single();
            Assert.Equal(new DxfPoint(1, 2, 3), line.P1);
            Assert.Equal(new DxfPoint(4, 5, 6), line.P2);
        }
示例#55
0
        public void WriteVersionSpecificEntities()
        {
            var file = new DxfFile();
            file.Entities.Add(new DxfProxyEntity());

            file.Header.Version = DxfAcadVersion.R14;
            VerifyFileContains(file, "ACAD_PROXY_ENTITY");

            file.Header.Version = DxfAcadVersion.R13;
            VerifyFileDoesNotContain(file, "ACAD_PROXY_ENTITY");
        }
示例#56
0
 public void WriteSpecificHeaderValuesTest()
 {
     var file = new DxfFile();
     file.Header.DimensionLineGap = 11.0;
     VerifyFileContains(file, @"
       9
     $DIMGAP
      40
     11.0
     ");
 }
示例#57
0
        public void WriteLayersTest()
        {
            var file = new DxfFile();
            file.Layers.Add(new DxfLayer("default"));
            VerifyFileContains(file, @"
              0
            SECTION
              2
            TABLES
              0
            TABLE
              2
            LAYER
              5
            5
            100
            AcDbSymbolTable
             70
            0
              0
            LAYER
              5
            A
            100
            AcDbSymbolTableRecord
            100
            AcDbLayerTableRecord
              2
            default
             70
            0
             62
            1
              6

              0
            ENDTAB
              0
            ENDSEC
            ");
        }
示例#58
0
        public void WriteVersionSpecificEntityProperties()
        {
            var file = new DxfFile();
            file.Entities.Add(new DxfLeader());

            // annotation offset is only written for >= R14
            file.Header.Version = DxfAcadVersion.R14;
            VerifyFileContains(file, "213");

            file.Header.Version = DxfAcadVersion.R13;
            VerifyFileDoesNotContain(file, "213");
        }
示例#59
0
        public void WriteViewportTest()
        {
            var file = new DxfFile();
            file.ViewPorts.Add(new DxfViewPort());
            VerifyFileContains(file, @"
              0
            SECTION
              2
            TABLES
              0
            TABLE
              2
            VPORT
              5
            9
            100
            AcDbSymbolTable
             70
            0
              0
            VPORT
              5
            A
            100
            AcDbSymbolTableRecord
            100
            AcDbViewportTableRecord
              2

             70
            0
             10
            0.0
             20
            0.0
             11
            0.0
             21
            0.0
             12
            0.0
             22
            0.0
             13
            0.0
             23
            0.0
             14
            0.0
             24
            0.0
             15
            0.0
             25
            0.0
             16
            0.0
             26
            0.0
             36
            1.0
             17
            0.0
             27
            0.0
             37
            0.0
             40
            0.0
             41
            0.0
             42
            0.0
             43
            0.0
             44
            0.0
             50
            0.0
             51
            0.0
             71
            0
             72
            0
             73
            1
             74
            0
             75
            0
             76
            0
             77
            0
             78
            0
              0
            ENDTAB
              0
            ENDSEC
            ");
        }
示例#60
0
 private static void EnsureFileContainsEntity(DxfEntity entity, string text)
 {
     var file = new DxfFile();
     file.Entities.Add(entity);
     using (var stream = new MemoryStream())
     {
         file.Save(stream);
         stream.Flush();
         stream.Seek(0, SeekOrigin.Begin);
         using (var reader = new StreamReader(stream))
         {
             var actual = reader.ReadToEnd();
             Assert.Contains(text.Trim(), actual);
         }
     }
 }