/// <summary>
        /// Initializes a new instance of the <c>UnderlayDefinition</c> class.
        /// </summary>
        /// <param name="name">Underlay name.</param>
        /// <param name="file">Underlay file name with full or relative path.</param>
        /// <param name="type">Underlay type.</param>
        /// <remarks>
        /// The file extension must match the underlay type.
        /// </remarks>
        protected UnderlayDefinition(string name, string file, UnderlayType type)
            : base(name, DxfObjectCode.UnderlayDefinition, false)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (file.IndexOfAny(Path.GetInvalidPathChars()) == 0)
            {
                throw new ArgumentException("File path contains invalid characters.", nameof(file));
            }

            string ext = Path.GetExtension(file);

            switch (type)
            {
            case UnderlayType.DGN:
                if (!ext.Equals(".DGN", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ArgumentException("The underlay type and the file extension do not match.", nameof(file));
                }
                this.CodeName = DxfObjectCode.UnderlayDgnDefinition;
                break;

            case UnderlayType.DWF:
                if (!ext.Equals(".DWF", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ArgumentException("The underlay type and the file extension do not match.", nameof(file));
                }
                this.CodeName = DxfObjectCode.UnderlayDwfDefinition;
                break;

            case UnderlayType.PDF:
                if (!ext.Equals(".PDF", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ArgumentException("The underlay type and the file extension do not match.", nameof(file));
                }
                this.CodeName = DxfObjectCode.UnderlayPdfDefinition;
                break;
            }

            this.file = file;
            this.type = type;
        }
 /// <summary>
 /// Initializes a new instance of the <c>UnderlayDefinition</c> class.
 /// </summary>
 /// <param name="fileName">Underlay file name with full or relative path.</param>
 /// <param name="name">Underlay name.</param>
 /// <param name="type">Underlay type.</param>
 protected UnderlayDefinition(string fileName, string name, UnderlayType type)
     : base(name, DxfObjectCode.UnderlayDefinition, false)
 {
     this.fileName = fileName;
     this.type = type;
     switch (type)
     {
         case UnderlayType.DGN:
             this.codeName = DxfObjectCode.UnderlayDgnDefinition;
             break;
         case UnderlayType.DWF:
             this.codeName = DxfObjectCode.UnderlayDwfDefinition;
             break;
         case UnderlayType.PDF:
             this.codeName = DxfObjectCode.UnderlayPdfDefinition;
             break;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <c>UnderlayDefinition</c> class.
        /// </summary>
        /// <param name="name">Underlay name.</param>
        /// <param name="file">Underlay file name with full or relative path.</param>
        /// <param name="type">Underlay type.</param>
        protected UnderlayDefinition(string name, string file, UnderlayType type)
            : base(name, DxfObjectCode.UnderlayDefinition, false)
        {
            this.file = file;
            this.type = type;
            switch (type)
            {
            case UnderlayType.DGN:
                CodeName = DxfObjectCode.UnderlayDgnDefinition;
                break;

            case UnderlayType.DWF:
                CodeName = DxfObjectCode.UnderlayDwfDefinition;
                break;

            case UnderlayType.PDF:
                CodeName = DxfObjectCode.UnderlayPdfDefinition;
                break;
            }
        }
Ejemplo n.º 4
0
        private UnderlayDefinition ReadUnderlayDefinition(UnderlayType type)
        {
            string handle = null;
            string page = string.Empty;
            string ownerHandle = null;
            string fileName = null;
            string name = null;

            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 5:
                        handle = this.chunk.ReadHex();
                        this.chunk.Next();
                        break;
                    case 1:
                        fileName = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 2:
                        page = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 330:
                        ownerHandle = this.chunk.ReadHex();
                        this.chunk.Next();
                        break;
                    default:
                        this.chunk.Next();
                        break;
                }
            }

            if (ownerHandle != null)
            {
                DictionaryObject underlayDefDict = this.dictionaries[ownerHandle];
                if (handle == null)
                    throw new NullReferenceException("Null handle in underlay definition dictionary.");
                name = underlayDefDict.Entries[handle];
            }

            UnderlayDefinition underlayDef = null;
            switch (type)
            {
                case UnderlayType.DGN:
                    underlayDef = new UnderlayDgnDefinition(fileName, name)
                    {
                        Handle = handle,
                        Layout = page
                    };
                    break;
                case UnderlayType.DWF:
                    underlayDef = new UnderlayDwfDefinition(fileName, name)
                    {
                        Handle = handle
                    };
                    break;
                case UnderlayType.PDF:
                    underlayDef = new UnderlayPdfDefinition(fileName, name)
                    {
                        Handle = handle,
                        Page = page
                    };
                    break;
            }

            if (underlayDef == null)
                throw new NullReferenceException("Underlay reference definition.");
            this.underlayDefHandles.Add(underlayDef.Handle, underlayDef);
            return underlayDef;
        }