Ejemplo n.º 1
0
 public DxfSectionReaderBase(
     IDxfStreamReader reader,
     DxfDocumentBuilder builder,
     NotificationEventHandler notification = null)
 {
     this._reader       = reader;
     this._builder      = builder;
     this._notification = notification;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        private IDxfStreamReader getSectionHandler(string sectionName)
        {
            //Get the needed handler
            m_reader = m_reader ?? getHandler();
            //Go to the start of header section
            m_reader.Find(sectionName);

            return(m_reader);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Read the OBJECTS section of the DXF file.
        /// </summary>
        private void readObjects()
        {
            //Get the needed handler
            this._reader = this.goToSection(DxfFileToken.ObjectsSection);

            DxfObjectsSectionReader reader = new DxfObjectsSectionReader(
                this._reader,
                this._builder,
                this.OnNotificationHandler);

            reader.Read();
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
0
        private IDxfStreamReader goToSection(string sectionName)
        {
            //Get the needed handler
            this._reader = this._reader ?? this.getReader();

            if (this._reader.LastValueAsString == sectionName)
            {
                return(this._reader);
            }

            //Go to the start of header section
            this._reader.Find(sectionName);

            return(this._reader);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Read the BLOCKS section of the DXF file.
        /// </summary>
        public void ReadBlocks()
        {
            //Get the needed handler
            m_reader = getSectionHandler(DxfFileToken.BlocksSection);

            //Advance to the first value in the section
            m_reader.ReadNext();
            //Loop until the section ends
            while (!m_reader.EndSectionFound)
            {
                //if (m_reader.LastValueAsString == DxfFileToken.ClassEntry)
                //	classes.Add(readBlock());
                //else
                //	m_reader.ReadNext();
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        public override CadHeader ReadHeader()
        {
            this._reader = this.goToSection(DxfFileToken.HeaderSection);

            CadHeader header = new CadHeader();

            Dictionary <string, DxfCode[]> headerMap = CadHeader.GetHeaderMap();

            this._reader.ReadNext();

            //Loop until the section ends
            while (!this._reader.EndSectionFound)
            {
                //Get the current header variable
                string currVar = this._reader.LastValueAsString;

                if (this._reader.LastValueAsString == null || !headerMap.TryGetValue(currVar, out var codes))
                {
                    //this.notificationHandler(this, new NotificationEventArgs($"Header variable not implemented {currVar}"));
                    this._reader.ReadNext();
                    continue;
                }

                object[] parameters = new object[codes.Length];
                for (int i = 0; i < codes.Length; i++)
                {
                    this._reader.ReadNext();
                    parameters[i] = this._reader.LastValue;
                }

                //Set the header value by name
                header.SetValue(currVar, parameters);

                this._reader.ReadNext();
            }

            return(header);
        }
Ejemplo n.º 9
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();
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Read the CLASSES section of the DXF file.
        /// </summary>
        /// <returns></returns>
        public DxfClassCollection ReadClasses()
        {
            //Get the needed handler
            m_reader = getSectionHandler(DxfFileToken.ClassesSection);

            DxfClassCollection classes = new DxfClassCollection();

            //Advance to the first value in the section
            m_reader.ReadNext();
            //Loop until the section ends
            while (!m_reader.EndSectionFound)
            {
                if (m_reader.LastValueAsString == DxfFileToken.ClassEntry)
                {
                    classes.Add(readClass());
                }
                else
                {
                    m_reader.ReadNext();
                }
            }

            return(classes);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Read the HEADER section of the file.
        /// </summary>
        /// <returns></returns>
        public CadHeader ReadHeader()
        {
            //Get the needed handler
            m_reader = getSectionHandler(DxfFileToken.HeaderSection);

            CadHeader header = new CadHeader();

            Dictionary <string, DxfCode[]> headerMap = CadHeader.GetHeaderMap();

            //Loop until the section ends
            while (!m_reader.EndSectionFound)
            {
                //Get next key/value
                m_reader.ReadNext();

                //Get the current header variable
                string currVar = m_reader.LastValueAsString;

                if (!headerMap.TryGetValue(currVar, out var codes))
                {
                    continue;
                }

                object[] parameters = new object[codes.Length];
                for (int i = 0; i < codes.Length; i++)
                {
                    m_reader.ReadNext();
                    parameters[i] = m_reader.LastValue;
                }

                //Set the header value by name
                header.SetValue(currVar, parameters);
            }

            return(header);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Read the CLASSES section of the DXF file.
        /// </summary>
        /// <returns></returns>
        private DxfClassCollection readClasses()
        {
            //Get the needed handler
            this._reader = this.goToSection(DxfFileToken.ClassesSection);

            DxfClassCollection classes = new DxfClassCollection();

            //Advance to the first value in the section
            this._reader.ReadNext();
            //Loop until the section ends
            while (!this._reader.EndSectionFound)
            {
                if (this._reader.LastValueAsString == DxfFileToken.ClassEntry)
                {
                    classes.Add(this.readClass());
                }
                else
                {
                    this._reader.ReadNext();
                }
            }

            return(classes);
        }
Ejemplo n.º 13
0
 public DxfObjectsSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder, NotificationEventHandler notification = null)
     : base(reader, builder, notification)
 {
 }