Example #1
0
        private void WriteImageDefReactor(ImageDefReactor reactor)
        {
            this.chunk.Write(0, reactor.CodeName);
            this.chunk.Write(5, reactor.Handle);
            this.chunk.Write(330, reactor.ImageHandle);

            this.chunk.Write(100, SubclassMarker.RasterImageDefReactor);
            this.chunk.Write(90, 2);
            this.chunk.Write(330, reactor.ImageHandle);
        }
Example #2
0
        internal void AddEntity(EntityObject entity, bool isBlockEntity, bool assignHandle)
        {
            // null entities are not allowed
            if (entity == null)
                throw new ArgumentNullException("entity");

            // entities already owned by another document are not allowed
            if (entity.Owner != null && !isBlockEntity)
                throw new ArgumentException("The entity already belongs to a document. Clone it instead.", "entity");

            // assign a handle
            if (assignHandle || string.IsNullOrEmpty(entity.Handle))
                this.NumHandles = entity.AsignHandle(this.NumHandles);

            // assign the owner
            if (!isBlockEntity)
            {
                entity.Owner = this.layouts[this.activeLayout].AssociatedBlock;
                this.layouts.References[this.activeLayout].Add(entity);
            }

            // 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:
                    Dimension dim = (Dimension) entity;
                    dim.Style = this.dimStyles.Add(dim.Style, assignHandle);
                    this.dimStyles.References[dim.Style.Name].Add(dim);
                    dim.DimensionStyleChange += this.Dimension_DimStyleChange;
                    // create the block that represent the dimension drawing
                    Block dimBlock = dim.Block;
                    if (dimBlock == null) dimBlock = dim.BuildBlock("*D" + ++this.DimensionBlocksGenerated);
                    dim.Block = this.blocks.Add(dimBlock);
                    this.blocks.References[dimBlock.Name].Add(dim);
                    dim.DimensionBlockChange += this.Dimension_DimBlockChange;
                    if (!isBlockEntity) this.dimensions.Add(dim);
                    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;

                    // the boundary entities of an associative hatch that belong to a block will be handle by that block
                    if (!isBlockEntity)
                    {
                        foreach (HatchBoundaryPath path in hatch.BoundaryPaths)
                        {
                            this.Hatch_BoundaryPathAdded(hatch, new ObservableCollectionEventArgs<HatchBoundaryPath>(path));
                        }
                        hatch.HatchBoundaryPathAdded += this.Hatch_BoundaryPathAdded;
                        hatch.HatchBoundaryPathRemoved += this.Hatch_BoundaryPathRemoved;
                        this.hatches.Add(hatch);
                    }
                    break;
                case EntityType.Insert:
                    Insert insert = (Insert) entity;
                    insert.Block = this.blocks.Add(insert.Block, assignHandle);
                    this.blocks.References[insert.Block.Name].Add(insert);
                    foreach (Attribute attribute in insert.Attributes)
                    {
                        attribute.Layer = this.layers.Add(attribute.Layer, assignHandle);
                        this.layers.References[attribute.Layer.Name].Add(attribute);
                        attribute.LayerChange += this.Entity_LayerChange;

                        attribute.LineType = this.lineTypes.Add(attribute.LineType, assignHandle);
                        this.lineTypes.References[attribute.LineType.Name].Add(attribute);
                        attribute.LineTypeChange += this.Entity_LineTypeChange;

                        attribute.Style = this.textStyles.Add(attribute.Style, assignHandle);
                        this.textStyles.References[attribute.Style.Name].Add(attribute);
                        attribute.TextStyleChange += this.Entity_TextStyleChange;
                    }
                    insert.AttributeAdded += this.Insert_AttributeAdded;
                    insert.AttributeRemoved += this.Insert_AttributeRemoved;
                    if (!isBlockEntity) this.inserts.Add(insert);
                    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.Trace:
                    if (!isBlockEntity) this.traces.Add((Trace)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, assignHandle);
                    this.textStyles.References[text.Style.Name].Add(text);
                    text.TextStyleChange += this.Entity_TextStyleChange;
                    if (!isBlockEntity) this.texts.Add(text);
                    break;
                case EntityType.MText:
                    MText mText = (MText) entity;
                    mText.Style = this.textStyles.Add(mText.Style, assignHandle);
                    this.textStyles.References[mText.Style.Name].Add(mText);
                    mText.TextStyleChange += this.Entity_TextStyleChange;
                    if (!isBlockEntity) this.mTexts.Add(mText);
                    break;
                case EntityType.Image:
                    Image image = (Image) entity;
                    image.Definition = this.imageDefs.Add(image.Definition, assignHandle);
                    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 mline = (MLine) entity;
                    mline.Style = this.mlineStyles.Add(mline.Style, assignHandle);
                    this.mlineStyles.References[mline.Style.Name].Add(mline);
                    mline.MLineStyleChange += this.MLine_MLineStyleChange;
                    if (!isBlockEntity) this.mLines.Add(mline);
                    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(viewport.ClippingBoundary != null) this.AddEntity(viewport.ClippingBoundary, isBlockEntity, assignHandle);
                    if (!isBlockEntity) this.viewports.Add(viewport);
                    break;
                case EntityType.AttributeDefinition:
                    AttributeDefinition attDef = (AttributeDefinition) entity;
                    attDef.Style = this.textStyles.Add(attDef.Style, assignHandle);
                    this.textStyles.References[attDef.Style.Name].Add(attDef);
                    attDef.TextStyleChange += this.Entity_TextStyleChange;
                    if (!isBlockEntity) this.attributeDefinitions.Add(attDef);
                    break;
                default:
                    throw new ArgumentException("The entity " + entity.Type + " is not implemented or unknown.");
            }

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

            entity.Layer = this.layers.Add(entity.Layer, assignHandle);
            this.layers.References[entity.Layer.Name].Add(entity);

            entity.LineType = this.lineTypes.Add(entity.LineType, assignHandle);
            this.lineTypes.References[entity.LineType.Name].Add(entity);

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

            entity.LayerChange += this.Entity_LayerChange;
            entity.LineTypeChange += this.Entity_LineTypeChange;
            entity.XDataAddAppReg += this.Entity_XDataAddAppReg;
            entity.XDataRemoveAppReg += this.Entity_XDataRemoveAppReg;
        }