예제 #1
0
        /// <summary>
        ///     Constructor that requires a path to a file.
        ///     This constructor will read the file and set up all of the required
        ///     tools for the DxfFile class
        /// </summary>
        /// <param name="pathToFile">An absolute or relative path to a dxf file</param>
        public DxfFile(string pathToFile)
        {
            // Initialize
            var fileReader = new DxfReader(pathToFile);

            Layers = new LayerDictionary();

            // Setup file
            PathToFile  = fileReader.PathToFile;
            FileName    = Path.GetFileName(PathToFile);
            DxfFileData = new TaggedDataList(fileReader.ReadFile());

            // The Main Parsing Calling Function
            var asciiParser = new AsciiParser(this);

            asciiParser.ParseFile();

            // Update the layer dictionary now that the Entities are all built
            Layers.UpdateDictionary(Entities.Values);
        }
예제 #2
0
        public void UpdateDictionaryTest()
        {
            // The test Dictionary
            var testDictionary = new LayerDictionary();

            // TestLine 0
            var testLine0 = new Line(new LineBuffer
            {
                EntityType = typeof(Line),
                Handle     = "1A",
                LayerName  = "TestLayer",
                Thickness  = 0,
                X0         = 0,
                X1         = 0,
                Y0         = 1,
                Y1         = 2
            });

            // TestLine1
            var testLine1 = new Line(new LineBuffer
            {
                EntityType = typeof(Line),
                Handle     = "2A",
                LayerName  = "TestLayer",
                Thickness  = 0,
                X0         = 0,
                X1         = 0,
                Y0         = 1,
                Y1         = 2
            });

            // Place the entities into a list
            var entities = new List <Entity> {
                testLine0, testLine1
            };

            // Create the Dictionary
            testDictionary.UpdateDictionary(entities);

            // Update Dictionary should have created the layer test Layer
            Assert.IsTrue(testDictionary.ContainsLayer("TestLayer"));
            Assert.IsTrue(testDictionary.Count == 1);
            // Change the layer of the second line
            testLine1.LayerName = "NewLayer";

            // Assert that the new layer was created,
            // The second line is now a member of the new layer and
            // that is is not a member of the old layer
            Assert.IsTrue(testDictionary.ContainsLayer("NewLayer"));
            Assert.IsTrue(testDictionary.GetLayer("NewLayer").ContainsEntity(testLine1.Handle));
            Assert.IsFalse(testDictionary.GetLayer("TestLayer").ContainsEntity(testLine1.Handle));

            // Now let us move it back
            testLine1.LayerName = "TestLayer";

            // Assert that the layer was changed back to TestLayer
            // Assert that it is no longer a member of NewLayer
            // Assert that the count of Newlayer is 0
            Assert.IsTrue(testDictionary.GetLayer("TestLayer").ContainsEntity(testLine1.Handle));
            Assert.IsFalse(testDictionary.GetLayer("NewLayer").ContainsEntity(testLine1.Handle));
            Assert.IsTrue(testDictionary.GetLayer("NewLayer").Count == 0);
        }