Example #1
0
 private void AttributeDefinitions_ItemAdd(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     OnAttributeDefinitionAddedEvent(e.Item);
     e.Item.Owner = this;
     // the block has attributes
     flags |= BlockTypeFlags.NonConstantAttributeDefinitions;
 }
Example #2
0
        internal Block(string name, bool checkName)
            : base(name, DxfObjectCode.Block, checkName)
        {
            this.reserved    = name.Equals("*Model_Space", StringComparison.OrdinalIgnoreCase);
            this.description = string.Empty;
            this.position    = Vector3.Zero;
            this.layer       = Layer.Default;

            this.entities = new EntityCollection();
            this.entities.BeforeAddItem    += this.Entities_BeforeAddItem;
            this.entities.AddItem          += this.Entities_AddItem;
            this.entities.BeforeRemoveItem += this.Entities_BeforeRemoveItem;
            this.entities.RemoveItem       += this.Entities_RemoveItem;

            this.attributes = new AttributeDefinitionDictionary();
            this.attributes.BeforeAddItem    += this.AttributeDefinitions_BeforeAddItem;
            this.attributes.AddItem          += this.AttributeDefinitions_ItemAdd;
            this.attributes.BeforeRemoveItem += this.AttributeDefinitions_BeforeRemoveItem;
            this.attributes.RemoveItem       += this.AttributeDefinitions_RemoveItem;

            this.owner = new BlockRecord(name);
            this.flags = BlockTypeFlags.None;
            this.end   = new BlockEnd
            {
                Layer = this.layer,
                Owner = this.owner
            };
        }
Example #3
0
 private void AttributeDefinitions_RemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     OnAttributeDefinitionRemovedEvent(e.Item);
     e.Item.Owner = null;
     if (attributes.Count == 0)
     {
         flags &= ~BlockTypeFlags.NonConstantAttributeDefinitions;
     }
 }
Example #4
0
 private void AttributeDefinitions_RemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     if (this.readOnly)
     {
         return;
     }
     this.OnAttributeDefinitionRemovedEvent(e.Item);
     e.Item.Owner = null;
     if (this.attributes.Count == 0)
     {
         this.flags &= ~BlockTypeFlags.NonConstantAttributeDefinitions;
     }
 }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <c>Block</c> class as an external reference drawing.
        /// </summary>
        /// <param name="name">Block name.</param>
        /// <param name="xrefFile">External reference path name.</param>
        /// <param name="overlay">Specifies if the external reference is an overlay, by default it is set to false.</param>
        /// <remarks>Only DWG files can be used as externally referenced blocks.</remarks>
        public Block(string name, string xrefFile, bool overlay)
            : this(name, null, null, true)
        {
            if (string.IsNullOrEmpty(xrefFile))
            {
                throw new ArgumentNullException(nameof(xrefFile));
            }

            this.xrefFile = xrefFile;
            flags         = BlockTypeFlags.XRef | BlockTypeFlags.ResolvedExternalReference;
            if (overlay)
            {
                flags |= BlockTypeFlags.XRefOverlay;
            }
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <c>Block</c> class as an external reference drawing.
        /// </summary>
        /// <param name="name">Block name.</param>
        /// <param name="xrefFile">External reference path name.</param>
        /// <param name="overlay">Specifies if the external reference is an overlay. Default: false.</param>
        /// <remarks>Only DWG files can be used as externally referenced blocks.</remarks>
        public Block(string name, string xrefFile, bool overlay = false)
            : this(name)
        {
            if (string.IsNullOrEmpty(xrefFile))
            {
                throw new ArgumentNullException(nameof(xrefFile), "An external referenced block must point to a valid dwg file.");
            }

            this.readOnly = true;
            this.xrefFile = xrefFile;
            this.flags    = BlockTypeFlags.XRef | BlockTypeFlags.ResolvedExternalReference;
            if (overlay)
            {
                this.flags |= BlockTypeFlags.XRefOverlay;
            }
        }
Example #7
0
        internal Block(string name, bool checkName, IList <EntityObject> entities, IList <AttributeDefinition> attributes)
            : base(name, DxfObjectCode.Block, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.reserved = string.Equals(name, DefaultModelSpaceName, StringComparison.OrdinalIgnoreCase);
            this.readOnly = this.reserved || name.StartsWith(DefaultPaperSpaceName, StringComparison.OrdinalIgnoreCase);

            this.description = string.Empty;
            this.origin      = Vector3.Zero;
            this.layer       = Layer.Default;
            this.xrefFile    = string.Empty;

            this.entities = new EntityCollection();
            this.entities.BeforeAddItem    += this.Entities_BeforeAddItem;
            this.entities.AddItem          += this.Entities_AddItem;
            this.entities.BeforeRemoveItem += this.Entities_BeforeRemoveItem;
            this.entities.RemoveItem       += this.Entities_RemoveItem;

            this.attributes = new AttributeDefinitionDictionary();
            this.attributes.BeforeAddItem    += this.AttributeDefinitions_BeforeAddItem;
            this.attributes.AddItem          += this.AttributeDefinitions_ItemAdd;
            this.attributes.BeforeRemoveItem += this.AttributeDefinitions_BeforeRemoveItem;
            this.attributes.RemoveItem       += this.AttributeDefinitions_RemoveItem;

            this.owner = new BlockRecord(name);
            this.flags = BlockTypeFlags.None;
            this.end   = new EndBlock
            {
                Owner = this.owner
            };

            if (entities != null)
            {
                this.entities.AddRange(entities);
            }
            if (attributes != null)
            {
                this.attributes.AddRange(attributes);
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <c>Block</c> class as an external reference drawing.
        /// </summary>
        /// <param name="name">Block name.</param>
        /// <param name="xrefFile">External reference path name.</param>
        /// <param name="overlay">Specifies if the external reference is an overlay, by default it is set to false.</param>
        /// <remarks>Only DWG files can be used as externally referenced blocks.</remarks>
        public Block(string name, string xrefFile, bool overlay)
            : this(name, null, null, true)
        {
            if (string.IsNullOrEmpty(xrefFile))
            {
                throw new ArgumentNullException(nameof(xrefFile));
            }

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

            this.xrefFile = xrefFile;
            this.flags    = BlockTypeFlags.XRef | BlockTypeFlags.ResolvedExternalReference;
            if (overlay)
            {
                this.flags |= BlockTypeFlags.XRefOverlay;
            }
        }
Example #9
0
        internal Block(string name, IEnumerable <EntityObject> entities, IEnumerable <AttributeDefinition> attributes, bool checkName)
            : base(name, DxfObjectCode.Block, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            IsReserved     = string.Equals(name, DefaultModelSpaceName, StringComparison.OrdinalIgnoreCase);
            forInternalUse = name.StartsWith("*");
            description    = string.Empty;
            origin         = Vector3.Zero;
            layer          = Layer.Default;
            xrefFile       = string.Empty;
            Owner          = new BlockRecord(name);
            flags          = BlockTypeFlags.None;
            end            = new EndBlock(this);

            this.entities = new EntityCollection();
            this.entities.BeforeAddItem    += Entities_BeforeAddItem;
            this.entities.AddItem          += Entities_AddItem;
            this.entities.BeforeRemoveItem += Entities_BeforeRemoveItem;
            this.entities.RemoveItem       += Entities_RemoveItem;
            if (entities != null)
            {
                this.entities.AddRange(entities);
            }

            this.attributes = new AttributeDefinitionDictionary();
            this.attributes.BeforeAddItem    += AttributeDefinitions_BeforeAddItem;
            this.attributes.AddItem          += AttributeDefinitions_ItemAdd;
            this.attributes.BeforeRemoveItem += AttributeDefinitions_BeforeRemoveItem;
            this.attributes.RemoveItem       += AttributeDefinitions_RemoveItem;
            if (attributes != null)
            {
                this.attributes.AddRange(attributes);
            }
        }
Example #10
0
        internal Block(string name, bool checkName, ICollection<EntityObject> entities, ICollection<AttributeDefinition> attributes)
            : base(name, DxfObjectCode.Block, checkName)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            this.reserved = name.Equals(DefaultModelSpaceName, StringComparison.OrdinalIgnoreCase);
            this.readOnly = this.reserved || name.StartsWith(DefaultPaperSpaceName, StringComparison.OrdinalIgnoreCase);

            this.description = string.Empty;
            this.position = Vector3.Zero;
            this.layer = Layer.Default;

            this.entities = new EntityCollection();
            this.entities.BeforeAddItem += this.Entities_BeforeAddItem;
            this.entities.AddItem += this.Entities_AddItem;
            this.entities.BeforeRemoveItem += this.Entities_BeforeRemoveItem;
            this.entities.RemoveItem += this.Entities_RemoveItem;

            this.attributes = new AttributeDefinitionDictionary();
            this.attributes.BeforeAddItem += this.AttributeDefinitions_BeforeAddItem;
            this.attributes.AddItem += this.AttributeDefinitions_ItemAdd;
            this.attributes.BeforeRemoveItem += this.AttributeDefinitions_BeforeRemoveItem;
            this.attributes.RemoveItem += this.AttributeDefinitions_RemoveItem;

            this.owner = new BlockRecord(name);
            this.flags = BlockTypeFlags.None;
            this.end = new EndBlock
            {
                Owner = this.owner
            };

            if (entities != null) this.entities.AddRange(entities);
            if (attributes != null) this.attributes.AddRange(attributes);
        }
Example #11
0
 private void AttributeDefinitions_RemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     if (this.readOnly) return;
     this.OnAttributeDefinitionRemovedEvent(e.Item);
     e.Item.Owner = null;
     if(this.attributes.Count == 0)
         this.flags &= ~BlockTypeFlags.NonConstantAttributeDefinitions;
 }
Example #12
0
 private void AttributeDefinitions_ItemAdd(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     if (this.readOnly) return;
     this.OnAttributeDefinitionAddedEvent(e.Item);
     e.Item.Owner = this;
     // the block has attributes
     this.flags |= BlockTypeFlags.NonConstantAttributeDefinitions;
 }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <c>Block</c> class as an external reference drawing. 
        /// </summary>
        /// <param name="name">Block name.</param>
        /// <param name="xrefFile">External reference path name.</param>
        /// <param name="overlay">Specifies if the external reference is an overlay. Default: false.</param>
        /// <remarks>Only DWG files can be used as externally referenced blocks.</remarks>
        public Block(string name, string xrefFile, bool overlay = false)
            : this(name)
        {
            if (string.IsNullOrEmpty(xrefFile))
                throw new ArgumentNullException(nameof(xrefFile), "An external referenced block must point to a valid dwg file.");

            this.readOnly = true;
            this.xrefFile = xrefFile;
            this.flags = BlockTypeFlags.XRef | BlockTypeFlags.ResolvedExternalReference;
            if (overlay) this.flags |= BlockTypeFlags.XRefOverlay;
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <c>Block</c> class as an external reference drawing. 
        /// </summary>
        /// <param name="name">Block name.</param>
        /// <param name="xrefFile">External reference path name.</param>
        /// <param name="overlay">Specifies if the external reference is an overlay, by default it is set to false.</param>
        /// <remarks>Only DWG files can be used as externally referenced blocks.</remarks>
        public Block(string name, string xrefFile, bool overlay)
            : this(name, true, null, null)
        {
            if (string.IsNullOrEmpty(xrefFile))
                throw new ArgumentNullException(nameof(xrefFile));

            this.readOnly = true;
            this.xrefFile = xrefFile;
            this.flags = BlockTypeFlags.XRef | BlockTypeFlags.ResolvedExternalReference;
            if (overlay)
                this.flags |= BlockTypeFlags.XRefOverlay;
        }
Example #15
0
 public static bool HasFlag(this BlockTypeFlags flags, BlockTypeFlags flag)
 {
     return((flags & flag) != 0);
 }