Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <c>DxfObject</c> class.
 /// </summary>
 /// <param name="codename"><see cref="DxfObjectCode">DXF object name</see>.</param>
 protected DxfObject(string codename)
 {
     this.codename            = codename;
     this.handle              = null;
     this.owner               = null;
     this.xData               = new XDataDictionary();
     this.xData.AddAppReg    += this.XData_AddAppReg;
     this.xData.RemoveAppReg += this.XData_RemoveAppReg;
 }
 /// <summary>
 /// Initializes a new instance of the <c>DxfObject</c> class.
 /// </summary>
 /// <param name="codeName">Object name.</param>
 protected DxfObject(string codeName)
 {
     this.codeName = codeName;
     this.handle   = null;
     this.owner    = null;
 }
Exemplo n.º 3
0
        internal bool AddEntity(EntityObject entity, bool isBlockEntity, bool assignHandle)
        {
            // no null entities allowed
            if (entity == null)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(entity.Handle))
            {
                // check if the entity handle has been assigned
                if (this.AddedObjects.ContainsKey(entity.Handle))
                {
                    // if the handle is equal the entity might come from another document, check if it is exactly the same object
                    DxfObject existing = this.AddedObjects[entity.Handle];
                    // if the entity is already in the document return false, do not add it again
                    if (existing.Equals(entity))
                    {
                        return(false);
                    }
                }
            }

            if (assignHandle)
            {
                this.NumHandles = entity.AsignHandle(this.NumHandles);
            }

            // the entities that are part of a block do not belong to any of the entities lists but to the block definition.
            switch (entity.Type)
            {
            case EntityType.Arc:
                if (!isBlockEntity)
                {
                    this.arcs.Add((Arc)entity);
                }
                break;

            case EntityType.Circle:
                if (!isBlockEntity)
                {
                    this.circles.Add((Circle)entity);
                }
                break;

            case EntityType.Dimension:
                if (!isBlockEntity)
                {
                    this.dimensions.Add((Dimension)entity);
                }
                ((Dimension)entity).Style = this.dimStyles.Add(((Dimension)entity).Style);
                this.dimStyles.References[((Dimension)entity).Style.Name].Add(entity);

                // create the block that represent the dimension drawing
                Block dimBlock = ((Dimension)entity).Block;
                if (dimBlock == null)
                {
                    dimBlock = ((Dimension)entity).BuildBlock("*D" + ++this.DimensionBlocksGenerated);
                    if (this.blocks.Contains(dimBlock.Name))
                    {
                        throw new ArgumentException("The list already contains the block: " + dimBlock.Name + ". The block names that start with *D are reserverd for dimensions");
                    }
                    dimBlock.Flags = BlockTypeFlags.AnonymousBlock;
                }
                this.blocks.Add(dimBlock);
                this.blocks.References[dimBlock.Name].Add(entity);
                break;

            case EntityType.Ellipse:
                if (!isBlockEntity)
                {
                    this.ellipses.Add((Ellipse)entity);
                }
                break;

            case EntityType.Face3D:
                if (!isBlockEntity)
                {
                    this.faces3d.Add((Face3d)entity);
                }
                break;

            case EntityType.Spline:
                if (!isBlockEntity)
                {
                    this.splines.Add((Spline)entity);
                }
                break;

            case EntityType.Hatch:
                Hatch hatch = (Hatch)entity;
                hatch.AddPatternXData();
                if (!isBlockEntity)
                {
                    this.hatches.Add(hatch);
                }
                break;

            case EntityType.Insert:
                ((Insert)entity).Block = this.blocks.Add(((Insert)entity).Block);
                this.blocks.References[((Insert)entity).Block.Name].Add(entity);
                foreach (Attribute attribute in ((Insert)entity).Attributes.Values)
                {
                    attribute.Layer = this.layers.Add(attribute.Layer);
                    this.layers.References[attribute.Layer.Name].Add(attribute);

                    attribute.LineType = this.lineTypes.Add(attribute.LineType);
                    this.lineTypes.References[attribute.LineType.Name].Add(attribute);

                    attribute.Style = this.textStyles.Add(attribute.Style);
                    this.textStyles.References[attribute.Style.Name].Add(attribute);
                }
                if (!isBlockEntity)
                {
                    this.inserts.Add((Insert)entity);
                }
                break;

            case EntityType.LightWeightPolyline:
                if (!isBlockEntity)
                {
                    this.lwPolylines.Add((LwPolyline)entity);
                }
                break;

            case EntityType.Line:
                if (!isBlockEntity)
                {
                    this.lines.Add((Line)entity);
                }
                break;

            case EntityType.Point:
                if (!isBlockEntity)
                {
                    this.points.Add((Point)entity);
                }
                break;

            case EntityType.PolyfaceMesh:
                if (!isBlockEntity)
                {
                    this.polyfaceMeshes.Add((PolyfaceMesh)entity);
                }
                break;

            case EntityType.Polyline:
                if (!isBlockEntity)
                {
                    this.polylines.Add((Polyline)entity);
                }
                break;

            case EntityType.Solid:
                if (!isBlockEntity)
                {
                    this.solids.Add((Solid)entity);
                }
                break;

            case EntityType.Mesh:
                if (!isBlockEntity)
                {
                    this.meshes.Add((Mesh)entity);
                }
                break;

            case EntityType.Text:
                Text text = (Text)entity;
                text.Style = this.textStyles.Add(text.Style);
                this.textStyles.References[text.Style.Name].Add(entity);
                if (!isBlockEntity)
                {
                    this.texts.Add(text);
                }
                break;

            case EntityType.MText:
                MText mText = (MText)entity;
                mText.Style = this.textStyles.Add(mText.Style);
                this.textStyles.References[mText.Style.Name].Add(entity);
                if (!isBlockEntity)
                {
                    this.mTexts.Add(mText);
                }
                break;

            case EntityType.Image:
                Image image = (Image)entity;
                image.Definition = this.imageDefs.Add(image.Definition);
                this.imageDefs.References[image.Definition.Name].Add(image);
                if (!image.Definition.Reactors.ContainsKey(image.Handle))
                {
                    ImageDefReactor reactor = new ImageDefReactor(image.Handle);
                    this.NumHandles = reactor.AsignHandle(this.NumHandles);
                    image.Definition.Reactors.Add(image.Handle, reactor);
                }
                if (!isBlockEntity)
                {
                    this.images.Add(image);
                }
                break;

            case EntityType.MLine:
                ((MLine)entity).Style = this.mlineStyles.Add(((MLine)entity).Style);
                this.mlineStyles.References[((MLine)entity).Style.Name].Add(entity);
                if (!isBlockEntity)
                {
                    this.mLines.Add((MLine)entity);
                }
                break;

            case EntityType.Ray:
                if (!isBlockEntity)
                {
                    this.rays.Add((Ray)entity);
                }
                break;

            case EntityType.XLine:
                if (!isBlockEntity)
                {
                    this.xlines.Add((XLine)entity);
                }
                break;

            case EntityType.Viewport:
                Viewport viewport = (Viewport)entity;
                if (!isBlockEntity)
                {
                    this.viewports.Add(viewport);
                }
                this.AddEntity(viewport.ClippingBoundary, isBlockEntity, assignHandle);
                break;

            case EntityType.AttributeDefinition:
                AttributeDefinition attDef = (AttributeDefinition)entity;
                attDef.Style = this.textStyles.Add(attDef.Style);
                this.textStyles.References[attDef.Style.Name].Add(entity);
                if (!isBlockEntity)
                {
                    this.attributeDefinitions.Add(attDef);
                }
                break;

            case EntityType.Attribute:
                throw new ArgumentException("The entity " + entity.Type + " is only allowed as part of an insert entity.", "entity");

            default:
                throw new ArgumentException("The entity " + entity.Type + " is not implemented or unknown.");
            }

            foreach (string appReg in entity.XData.Keys)
            {
                entity.XData[appReg].ApplicationRegistry = this.appRegistries.Add(entity.XData[appReg].ApplicationRegistry);
                this.appRegistries.References[appReg].Add(entity);
            }

            if (!isBlockEntity && this.layouts != null)
            {
                entity.Owner = this.layouts[this.activeLayout].AssociatedBlock;
                this.layouts.References[this.activeLayout].Add(entity);
            }

            this.AddedObjects.Add(entity.Handle, entity);

            if (this.layers != null)
            {
                entity.Layer = this.layers.Add(entity.Layer);
                this.layers.References[entity.Layer.Name].Add(entity);
            }

            if (this.lineTypes != null)
            {
                entity.LineType = this.lineTypes.Add(entity.LineType);
                this.lineTypes.References[entity.LineType.Name].Add(entity);
            }

            /*if (!isBlockEntity)
             * {
             *  entity.Owner = this.layouts[this.activeLayout].AssociatedBlock;
             *  this.layouts.References[this.activeLayout].Add(entity);
             * }
             *
             * this.AddedObjects.Add(entity.Handle, entity);
             *
             * entity.Layer = this.layers.Add(entity.Layer);
             * this.layers.References[entity.Layer.Name].Add(entity);
             *
             * entity.LineType = this.lineTypes.Add(entity.LineType);
             * this.lineTypes.References[entity.LineType.Name].Add(entity);*/
            return(true);
        }
Exemplo n.º 4
0
        private void RemoveDimensionStyleOverrides(DimensionStyleOverrideDictionary overrides, DxfObject entity)
        {
            // remove the style override referenced DxfObjects
            DimensionStyleOverride styleOverride;

            // add referenced text style
            overrides.TryGetValue(DimensionStyleOverrideType.TextStyle, out styleOverride);
            if (styleOverride != null)
            {
                TextStyle dimtxtsty = (TextStyle) styleOverride.Value;
                this.textStyles.References[dimtxtsty.Name].Remove(entity);
            }

            // add referenced blocks
            overrides.TryGetValue(DimensionStyleOverrideType.LeaderArrow, out styleOverride);
            if (styleOverride != null)
            {
                Block block = (Block) styleOverride.Value;
                if (block != null)
                {
                    this.blocks.References[block.Name].Remove(entity);
                }
            }

            overrides.TryGetValue(DimensionStyleOverrideType.DimArrow1, out styleOverride);
            if (styleOverride != null)
            {
                Block block = (Block) styleOverride.Value;
                if (block != null)
                {
                    this.blocks.References[block.Name].Remove(entity);
                }
            }

            overrides.TryGetValue(DimensionStyleOverrideType.DimArrow2, out styleOverride);
            if (styleOverride != null)
            {
                Block block = (Block) styleOverride.Value;
                if (block != null)
                {
                    this.blocks.References[block.Name].Remove(entity);
                }
            }

            // add referenced line types
            overrides.TryGetValue(DimensionStyleOverrideType.DimLineLinetype, out styleOverride);
            if (styleOverride != null)
            {
                Linetype linetype = (Linetype) styleOverride.Value;
                this.linetypes.References[linetype.Name].Remove(entity);
            }

            overrides.TryGetValue(DimensionStyleOverrideType.ExtLine1Linetype, out styleOverride);
            if (styleOverride != null)
            {
                Linetype linetype = (Linetype) styleOverride.Value;
                this.linetypes.References[linetype.Name].Remove(entity);
            }

            overrides.TryGetValue(DimensionStyleOverrideType.ExtLine2Linetype, out styleOverride);
            if (styleOverride != null)
            {
                Linetype linetype = (Linetype) styleOverride.Value;
                this.linetypes.References[linetype.Name].Remove(entity);
            }
        }
Exemplo n.º 5
0
        private void Entity_TextStyleChanged(DxfObject sender, TableObjectChangedEventArgs<TextStyle> e)
        {
            this.textStyles.References[e.OldValue.Name].Remove(sender);

            e.NewValue = this.textStyles.Add(e.NewValue);
            this.textStyles.References[e.NewValue.Name].Add(sender);
        }
Exemplo n.º 6
0
        private void Entity_LinetypeChanged(DxfObject sender, TableObjectChangedEventArgs<Linetype> e)
        {
            this.linetypes.References[e.OldValue.Name].Remove(sender);

            e.NewValue = this.linetypes.Add(e.NewValue);
            this.linetypes.References[e.NewValue.Name].Add(sender);
        }
Exemplo n.º 7
0
        private void Entity_LayerChange(DxfObject sender, TableObjectChangeEventArgs<Layer> e)
        {
            this.layers.References[e.OldValue.Name].Remove(sender);

            e.NewValue = this.layers.Add(e.NewValue);
            this.layers.References[e.NewValue.Name].Add(sender);
        }