Exemplo n.º 1
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
            };
        }
Exemplo n.º 2
0
 private void AttributeDefinitions_BeforeAddItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // null, attributes with the same tag, and attribute definitions already owned by another Block are not allowed in the attributes list.
     if (e.Item == null)
     {
         e.Cancel = true;
     }
     else if (this.attributes.ContainsTag(e.Item.Tag))
     {
         e.Cancel = true;
     }
     else if (this.readOnly)
     {
         e.Cancel = true;
     }
     else if (e.Item.Owner != null)
     {
         // if the block does not belong to a document, all attribute definitions which owner is not null will be rejected
         if (this.Record.Owner == null)
         {
             e.Cancel = true;
         }
         // if the block belongs to a document, the entity will be added to the block only if both, the block and the attribute definitions document, are the same
         // this is handled by the BlocksRecordCollection
     }
     else
     {
         e.Cancel = false;
     }
 }
Exemplo n.º 3
0
 private void AttributeDefinitions_BeforeAddItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // attributes with the same tag, and attribute definitions already owned by another Block are not allowed in the attributes list.
     if (e.Item == null)
     {
         e.Cancel = true;
     }
     else if (Flags.HasFlag(BlockTypeFlags.ExternallyDependent))
     {
         e.Cancel = true;
     }
     else if (Name.StartsWith(DefaultPaperSpaceName)) // paper space blocks do not contain attribute definitions
     {
         e.Cancel = true;
     }
     else if (attributes.ContainsTag(e.Item.Tag))
     {
         e.Cancel = true;
     }
     else if (e.Item.Owner != null)
     {
         // if the block does not belong to a document, all attribute definitions which owner is not null will be rejected
         if (Record.Owner == null)
         {
             e.Cancel = true;
         }
         // if the block belongs to a document, the entity will be added to the block only if both, the block and the attribute definitions document, are the same
         // this is handled by the BlocksRecordCollection
     }
     else
     {
         e.Cancel = false;
     }
 }
Exemplo n.º 4
0
 private void AttributeDefinitions_ItemAdd(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     OnAttributeDefinitionAddedEvent(e.Item);
     e.Item.Owner = this;
     // the block has attributes
     flags |= BlockTypeFlags.NonConstantAttributeDefinitions;
 }
Exemplo n.º 5
0
 private void AttributeDefinitions_BeforeAddItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // attributes with the same tag, and attribute definitions already owned by another Block are not allowed in the attributes list.
     if (e.Item == null)
     {
         e.Cancel = true;
     }
     else if (this.Flags.HasFlag(BlockTypeFlags.ExternallyDependent))
     {
         e.Cancel = true;
     }
     else if (this.Name.StartsWith(DefaultPaperSpaceName)) // paper space blocks do not contain attribute definitions
     {
         e.Cancel = true;
     }
     else if (this.attributes.ContainsTag(e.Item.Tag))
     {
         e.Cancel = true;
     }
     else if (e.Item.Owner != null)
     {
         e.Cancel = true;
     }
     else
     {
         e.Cancel = false;
     }
 }
Exemplo n.º 6
0
 private void AttributeDefinitions_RemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     OnAttributeDefinitionRemovedEvent(e.Item);
     e.Item.Owner = null;
     if (attributes.Count == 0)
     {
         flags &= ~BlockTypeFlags.NonConstantAttributeDefinitions;
     }
 }
Exemplo n.º 7
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;
     }
 }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
 private void AttributeDefinitions_BeforeAddItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // null, attributes with the same tag, and attribute definitions already owned by another Block are not allowed in the attributes list.
     if (e.Item == null)
     {
         e.Cancel = true;
     }
     else if (this.attributes.ContainsTag(e.Item.Tag))
     {
         e.Cancel = true;
     }
     else if (e.Item.Owner != null)
     {
         e.Cancel = true;
     }
     else
     {
         e.Cancel = false;
     }
 }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 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;
 }
Exemplo n.º 12
0
 private void AttributeDefinitions_BeforeRemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // only attribute definitions owned by the actual block can be removed
     e.Cancel = !ReferenceEquals(e.Item.Owner, this);
 }
Exemplo n.º 13
0
 private void AttributeDefinitions_ItemAdd(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     e.Item.Owner = this;
 }
Exemplo n.º 14
0
 private void AttributeDefinitions_RemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     e.Item.Owner = null;
 }
Exemplo n.º 15
0
 private void AttributeDefinitions_BeforeAddItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // null, attributes with the same tag, and attribute definitions already owned by another Block are not allowed in the attributes list.
     if (e.Item == null)
         e.Cancel = true;
     else if (this.attributes.ContainsTag(e.Item.Tag))
         e.Cancel = true;
     else if (this.readOnly)
         e.Cancel = true;
     else if (e.Item.Owner != null)
     {
         // if the block does not belong to a document, all attribute definitions which owner is not null will be rejected
         if (this.Record.Owner == null)
             e.Cancel = true;
         // if the block belongs to a document, the entity will be added to the block only if both, the block and the attribute definitions document, are the same
         // this is handled by the BlocksRecordCollection
     }
     else
         e.Cancel = false;
 }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 private void AttributeDefinitions_BeforeRemoveItem(AttributeDefinitionDictionary sender, AttributeDefinitionDictionaryEventArgs e)
 {
     // only attribute definitions owned by the actual block can be removed
     e.Cancel = !ReferenceEquals(e.Item.Owner, this) || this.readOnly;
 }
Exemplo n.º 18
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;
 }