Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
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();
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        private DxfClass readClass()
        {
            DxfClass curr = new DxfClass();

            Debug.Assert(m_reader.LastValueAsString == DxfFileToken.ClassEntry);

            m_reader.ReadNext();
            //Loop until the next class or the end of the section
            while (m_reader.LastDxfCode != DxfCode.Start)
            {
                switch (m_reader.LastCode)
                {
                //Class DXF record name; always unique
                case 1:
                    curr.DxfName = m_reader.LastValueAsString;
                    break;

                //C++ class name. Used to bind with software that defines object class behavior; always unique
                case 2:
                    curr.CppClassName = m_reader.LastValueAsString;
                    break;

                //Application name. Posted in Alert box when a class definition listed in this section is not currently loaded
                case 3:
                    curr.ApplicationName = m_reader.LastValueAsString;
                    break;

                //Proxy capabilities flag.
                case 90:
                    curr.ProxyFlags = (ProxyFlags)m_reader.LastValueAsShort;
                    break;

                //Instance count for a custom class
                case 91:
                    curr.InstanceCount = m_reader.LastValueAsInt;
                    break;

                //Was-a-proxy flag. Set to 1 if class was not loaded when this DXF file was created, and 0 otherwise
                case 280:
                    curr.WasAProxy = m_reader.LastValueAsBool;
                    break;

                //Is - an - entity flag.
                case 281:
                    curr.IsAnEntity = m_reader.LastValueAsBool;
                    break;

                default:
                    break;
                }

                m_reader.ReadNext();
            }

            return(curr);
        }