Пример #1
0
        public void NotAllowDuplicate()
        {
            Line        line = new Line();
            CadDocument doc  = new CadDocument();

            doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line);

            Assert.Throws <ArgumentException>(() => doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line));
        }
Пример #2
0
        /// <inheritdoc/>
        public override CadDocument Read()
        {
            this._document = new CadDocument(false);
            this._builder  = new DxfDocumentBuilder(this._document, this.OnNotificationHandler);

            this._reader = this._reader ?? this.getReader();

            while (this._reader.LastValueAsString != DxfFileToken.EndOfFile)
            {
                if (this._reader.LastValueAsString != DxfFileToken.BeginSection)
                {
                    this._reader.ReadNext();
                    continue;
                }
                else
                {
                    this._reader.ReadNext();
                }

                switch (this._reader.LastValueAsString)
                {
                case DxfFileToken.HeaderSection:
                    this._document.Header = this.ReadHeader();
                    break;

                case DxfFileToken.ClassesSection:
                    this._document.Classes = this.readClasses();
                    break;

                case DxfFileToken.TablesSection:
                    this.readTables();
                    break;

                case DxfFileToken.BlocksSection:
                    this.readBlocks();
                    break;

                case DxfFileToken.EntitiesSection:
                    this.readEntities();
                    break;

                case DxfFileToken.ObjectsSection:
                    this.readObjects();
                    break;

                default:
                    this.OnNotificationHandler(this, new NotificationEventArgs($"Section not implemented {this._reader.LastValueAsString}"));
                    break;
                }

                this._reader.ReadNext();
            }

            this._builder.BuildDocument();

            return(this._document);
        }
Пример #3
0
        static IEnumerable <Insert> getInsertEntities(string file, string blockname)
        {
            CadDocument doc = DwgReader.Read(file);

            // Get the model space where all the drawing entities are
            BlockRecord modelSpace = doc.BlockRecords["*Model_Space"];

            // Get the insert instance that is using the block that you are looking for
            return(modelSpace.Entities.OfType <Insert>().Where(e => e.Block.Name == blockname));
        }
Пример #4
0
        /// <summary>
        /// Read a dxf document in a stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="notification">Notification handler, sends any message or notification about the reading process.</param>
        /// <returns></returns>
        public static CadDocument Read(Stream stream, NotificationEventHandler notification = null)
        {
            CadDocument doc = null;

            using (DxfReader reader = new DxfReader(stream, notification))
            {
                doc = reader.Read();
            }

            return(doc);
        }
Пример #5
0
        /// <summary>
        /// Read the complete document.
        /// </summary>
        public CadDocument Read()
        {
            CadDocument doc = new CadDocument();

            doc.Header  = ReadHeader();
            doc.Classes = ReadClasses();
            ReadTables(doc);
            ReadEntities(doc);

            return(doc);
        }
Пример #6
0
 public static void AssertTableHirearchy(CadDocument doc)
 {
     //Assert all the tables in the doc
     assertTable(doc, doc.AppIds);
     assertTable(doc, doc.BlockRecords);
     assertTable(doc, doc.DimensionStyles);
     assertTable(doc, doc.Layers);
     assertTable(doc, doc.LineTypes);
     assertTable(doc, doc.TextStyles);
     assertTable(doc, doc.UCSs);
     assertTable(doc, doc.Views);
     assertTable(doc, doc.VPorts);
 }
Пример #7
0
        /// <summary>
        /// Read the ENTITIES section of the DXF file.
        /// </summary>
        public void ReadEntities(CadDocument document)
        {
            //https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-7D07C886-FD1D-4A0C-A7AB-B4D21F18E484
            //Get the needed handler
            m_reader = getSectionHandler(DxfFileToken.EntitiesSection);

            //Advance to the first value in the section
            m_reader.ReadNext();
            //Loop until the section ends
            while (!m_reader.EndSectionFound)
            {
                document.AddEntity(readEntity());
            }
        }
Пример #8
0
        public static void AssertBlockRecords(CadDocument doc)
        {
            foreach (BlockRecord br in doc.BlockRecords)
            {
                Assert.Equal(br.Name, br.BlockEntity.Name);

                documentObjectNotNull(doc, br.BlockEntity);
                documentObjectNotNull(doc, br.BlockEnd);

                foreach (Entities.Entity e in br.Entities)
                {
                    documentObjectNotNull(doc, e);
                }
            }
        }
Пример #9
0
        public void AddCadObject()
        {
            Line        line = new Line();
            CadDocument doc  = new CadDocument();

            doc.BlockRecords[BlockRecord.ModelSpaceName].Entities.Add(line);

            CadObject l = doc.GetCadObject(line.Handle);

            //Assert existing element
            Assert.NotNull(l);
            Assert.Equal(line, l);
            Assert.False(0 == l.Handle);
            Assert.Equal(line.Handle, l.Handle);
        }
Пример #10
0
        static void ReadDwg()
        {
            string[] files = Directory.GetFiles(PathSamples + "/dwg/", "*.dwg");

            foreach (var f in files)
            {
                using (DwgReader reader = new DwgReader(f, onNotification))
                {
                    CadDocument doc = reader.Read();
                }

                Console.WriteLine($"file read : {f}");
                Console.ReadLine();
            }
        }
Пример #11
0
        static void ReadDwg()
        {
            //string file = Path.Combine(PathSamples, "dwg/drawing_2000.dwg");
            //string file = Path.Combine(PathSamples, "dwg/drawing_2007.dwg");
            //string file = Path.Combine(PathSamples, "dwg/drawing_2010.dwg");

            //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_R14.dwg");
            //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2000.dwg");
            string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2007.dwg");

            //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2010.dwg");
            //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2013.dwg");
            //string file = Path.Combine(PathSamples, "dwg/single_entities/sample_2018.dwg");

            using (DwgReader reader = new DwgReader(file))
            {
                CadDocument doc = reader.Read(onProgress);
            }
        }
Пример #12
0
        public static void AssertDocumentDefaults(CadDocument doc)
        {
            //Assert the default values for the document
            entryNotNull(doc.BlockRecords, "*Model_Space");
            entryNotNull(doc.BlockRecords, "*Paper_Space");

            entryNotNull(doc.LineTypes, "ByLayer");
            entryNotNull(doc.LineTypes, "ByBlock");
            entryNotNull(doc.LineTypes, "Continuous");

            entryNotNull(doc.Layers, "0");

            entryNotNull(doc.TextStyles, "Standard");

            entryNotNull(doc.AppIds, "ACAD");

            entryNotNull(doc.DimensionStyles, "Standard");

            entryNotNull(doc.VPorts, "*Active");

            notNull(doc.Layouts.FirstOrDefault(l => l.Name == "Model"), "Model");
        }
Пример #13
0
        private static void assertTable <T>(CadDocument doc, Table <T> table)
            where T : TableEntry
        {
            Assert.NotNull(table);

            notNull(table.Document, $"Document not assigned to table {table}");
            Assert.Equal(doc, table.Document);
            Assert.Equal(doc, table.Owner);

            Assert.True(table.Handle != 0);

            CadObject t = doc.GetCadObject(table.Handle);

            Assert.Equal(t, table);

            foreach (T entry in table)
            {
                Assert.Equal(entry.Owner.Handle, table.Handle);
                Assert.Equal(entry.Owner, table);

                documentObjectNotNull(doc, entry);
            }
        }
Пример #14
0
        /// <summary>
        /// Read the TABLES section of the DXF file.
        /// </summary>
        /// <param name="document">Document where the tables reside.</param>
        public void ReadTables(CadDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            //https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-A9FD9590-C97B-4E41-9F26-BD82C34A4F9F
            //Get the needed handler
            m_reader = getSectionHandler(DxfFileToken.TablesSection);

            //Advance to the first value in the section
            m_reader.ReadNext();
            //Loop until the section ends
            while (!m_reader.EndSectionFound)
            {
                readTable(document);

                if (m_reader.LastValueAsString == DxfFileToken.EndTable)
                {
                    m_reader.ReadNext();
                }
            }
        }
Пример #15
0
 public DxfDocumentBuilder(CadDocument document, NotificationEventHandler notification = null) : base(document, notification)
 {
 }
Пример #16
0
 internal AppIdsTable(CadDocument document) : base(document)
 {
 }
Пример #17
0
        public void ReadCrcEnabledTest(string test)
        {
            DwgReaderFlags flags = DwgReaderFlags.CheckCrc;

            CadDocument doc = DwgReader.Read(test, flags, this.onNotification);
        }
Пример #18
0
 internal DimensionStylesTable(CadDocument document) : base(document)
 {
 }
Пример #19
0
 protected Table(CadDocument document)
 {
     this.Owner = document;
     document.RegisterCollection(this);
 }
Пример #20
0
 internal LineTypesTable(CadDocument document) : base(document)
 {
 }
Пример #21
0
        public static void AssertDocumentTree(CadDocument doc)
        {
            CadDocumentTree tree = System.Text.Json.JsonSerializer.Deserialize <CadDocumentTree>(File.ReadAllText(_documentTree));

            assertTable(doc.BlockRecords, tree.BlocksTable, doc.Header.Version >= ACadVersion.AC1021);
        }
Пример #22
0
        public void CadDocumentDefaultTest()
        {
            CadDocument doc = new CadDocument();

            DocumentIntegrity.AssertDocumentDefaults(doc);
        }
Пример #23
0
 internal BlockRecordsTable(CadDocument document) : base(document)
 {
 }
Пример #24
0
        public void CadDocumentTest()
        {
            CadDocument doc = new CadDocument();

            DocumentIntegrity.AssertTableHirearchy(doc);
        }
Пример #25
0
 internal UCSTable(CadDocument document) : base(document)
 {
 }
Пример #26
0
 internal ViewsTable(CadDocument document) : base(document)
 {
 }
Пример #27
0
 internal TextStylesTable(CadDocument document) : base(document)
 {
 }
Пример #28
0
 public DwgDocumentBuilder(CadDocument document, DwgReaderFlags flags, NotificationEventHandler notification = null)
     : base(document, notification)
 {
     this.Flags = flags;
 }
Пример #29
0
 public CadDocumentBuilder(CadDocument document, NotificationEventHandler notification = null)
 {
     this.DocumentToBuild     = document;
     this.NotificationHandler = notification;
 }
Пример #30
0
 private static void documentObjectNotNull <T>(CadDocument doc, T o)
     where T : CadObject
 {
     Assert.True(doc.GetCadObject(o.Handle) != null, $"Object of type {typeof(T)} | {o.Handle} not found in the doucment");
 }