Exemple #1
0
        /// <summary>
        /// Explodes the current insert.
        /// </summary>
        /// <returns>A list of entities.</returns>
        public List <EntityObject> Explode()
        {
            List <EntityObject> entities       = new List <EntityObject>();
            Matrix3             transformation = this.GetTransformation();
            Vector3             translation    = this.Position - transformation * this.block.Origin;

            foreach (EntityObject entity in this.block.Entities)
            {
                Vector3 localScale     = MathHelper.Transform(this.Scale, entity.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                bool    isUniformScale = MathHelper.IsEqual(localScale.X, localScale.Y);

                // entities with reactors are associated with other entities they will handle the transformation
                if (entity.Reactors.Count > 0)
                {
                    continue;
                }

                if (!isUniformScale)
                {
                    switch (entity.Type)
                    {
                    case EntityType.Circle:
                    {
                        Circle  circle  = (Circle)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center    = circle.Center,
                            MajorAxis = 2 * circle.Radius,
                            MinorAxis = 2 * circle.Radius,
                            Thickness = circle.Thickness
                        };

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.Arc:
                    {
                        Arc     arc     = (Arc)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center     = arc.Center,
                            MajorAxis  = 2 * arc.Radius,
                            MinorAxis  = 2 * arc.Radius,
                            StartAngle = arc.StartAngle,
                            EndAngle   = arc.EndAngle,
                            Thickness  = arc.Thickness
                        };

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.LwPolyline:
                    {
                        List <EntityObject> newEntities = ((LwPolyline)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            if (newEntity.Type == EntityType.Arc)
                            {
                                Arc     arc     = (Arc)newEntity;
                                Ellipse ellipse = new Ellipse
                                {
                                    //EntityObject properties
                                    Layer         = (Layer)entity.Layer.Clone(),
                                    Linetype      = (Linetype)entity.Linetype.Clone(),
                                    Color         = (AciColor)entity.Color.Clone(),
                                    Lineweight    = entity.Lineweight,
                                    Transparency  = (Transparency)entity.Transparency.Clone(),
                                    LinetypeScale = entity.LinetypeScale,
                                    Normal        = entity.Normal,
                                    IsVisible     = entity.IsVisible,
                                    //Ellipse properties
                                    Center     = arc.Center,
                                    MajorAxis  = 2 * arc.Radius,
                                    MinorAxis  = 2 * arc.Radius,
                                    StartAngle = arc.StartAngle,
                                    EndAngle   = arc.EndAngle,
                                    Thickness  = arc.Thickness
                                };

                                ellipse.TransformBy(transformation, translation);
                                entities.Add(ellipse);
                            }
                            else
                            {
                                newEntity.TransformBy(transformation, translation);
                                entities.Add(newEntity);
                            }
                        }
                        break;
                    }

                    case EntityType.MLine:
                    {
                        List <EntityObject> newEntities = ((MLine)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            if (newEntity.Type == EntityType.Arc)
                            {
                                Arc     arc     = (Arc)newEntity;
                                Ellipse ellipse = new Ellipse
                                {
                                    //EntityObject properties
                                    Layer         = (Layer)entity.Layer.Clone(),
                                    Linetype      = (Linetype)entity.Linetype.Clone(),
                                    Color         = (AciColor)entity.Color.Clone(),
                                    Lineweight    = entity.Lineweight,
                                    Transparency  = (Transparency)entity.Transparency.Clone(),
                                    LinetypeScale = entity.LinetypeScale,
                                    Normal        = entity.Normal,
                                    IsVisible     = entity.IsVisible,
                                    //Ellipse properties
                                    Center     = arc.Center,
                                    MajorAxis  = 2 * arc.Radius,
                                    MinorAxis  = 2 * arc.Radius,
                                    StartAngle = arc.StartAngle,
                                    EndAngle   = arc.EndAngle,
                                    Thickness  = arc.Thickness
                                };

                                ellipse.TransformBy(transformation, translation);
                                entities.Add(ellipse);
                            }
                            else
                            {
                                newEntity.TransformBy(transformation, translation);
                                entities.Add(newEntity);
                            }
                        }
                        break;
                    }

                    default:
                    {
                        EntityObject newEntity = (EntityObject)entity.Clone();
                        newEntity.TransformBy(transformation, translation);
                        entities.Add(newEntity);
                        break;
                    }
                    }
                }
                else
                {
                    EntityObject newEntity = (EntityObject)entity.Clone();
                    newEntity.TransformBy(transformation, translation);
                    entities.Add(newEntity);
                }
            }

            foreach (Attribute attribute in this.attributes)
            {
                // the attributes will be exploded as a Text entity
                Text text = new Text
                {
                    //Attribute properties
                    Layer         = (Layer)attribute.Layer.Clone(),
                    Linetype      = (Linetype)attribute.Linetype.Clone(),
                    Color         = (AciColor)attribute.Color.Clone(),
                    Lineweight    = attribute.Lineweight,
                    Transparency  = (Transparency)attribute.Transparency.Clone(),
                    LinetypeScale = attribute.LinetypeScale,
                    Normal        = attribute.Normal,
                    IsVisible     = attribute.IsVisible,
                    Height        = attribute.Height,
                    WidthFactor   = attribute.WidthFactor,
                    ObliqueAngle  = attribute.ObliqueAngle,
                    Value         = attribute.Value.ToString(),
                    Style         = (TextStyle)attribute.Style.Clone(),
                    Position      = attribute.Position,
                    Rotation      = attribute.Rotation,
                    Alignment     = attribute.Alignment,
                    IsBackward    = attribute.IsBackward,
                    IsUpsideDown  = attribute.IsUpsideDown
                };
                entities.Add(text);
            }

            return(entities);
        }
Exemple #2
0
        /// <summary>
        /// Explodes the current insert.
        /// </summary>
        /// <returns>A list of entities.</returns>
        /// <remarks>
        /// Non-uniform scaling is not supported by all entities. Read the documentation of the entities TranformBy method.
        /// </remarks>
        public List <EntityObject> Explode()
        {
            bool isUniformScale = MathHelper.IsEqual(scale.X, scale.Y) &&
                                  MathHelper.IsEqual(scale.Y, scale.Z);

            List <EntityObject> entities       = new List <EntityObject>();
            Matrix3             transformation = GetTransformation(Owner == null ? DrawingUnits.Unitless : Block.Record.Owner.Owner.DrawingVariables.InsUnits);
            Vector3             translation    = Position - transformation * block.Origin;

            foreach (EntityObject entity in block.Entities)
            {
                // TODO: entities with no implemented TransformBy method
                if (entity.Type == EntityType.Viewport)
                {
                    continue;
                }

                // entities with reactors are associated with other entities they will handle the transformation
                if (entity.Reactors.Count > 0)
                {
                    continue;
                }

                if (!isUniformScale)
                {
                    switch (entity.Type)
                    {
                    case EntityType.Circle:
                    {
                        Circle circle = (Circle)entity;

                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center    = circle.Center,
                            MajorAxis = 2 * circle.Radius,
                            MinorAxis = 2 * circle.Radius,
                            Thickness = circle.Thickness
                        };
                        foreach (XData data in XData.Values)
                        {
                            entity.XData.Add((XData)data.Clone());
                        }

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.Arc:
                    {
                        Arc     arc     = (Arc)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center     = arc.Center,
                            MajorAxis  = 2 * arc.Radius,
                            MinorAxis  = 2 * arc.Radius,
                            StartAngle = arc.StartAngle,
                            EndAngle   = arc.EndAngle,
                            Thickness  = arc.Thickness
                        };
                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.LwPolyline:
                    {
                        List <EntityObject> newEntities = ((LwPolyline)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            newEntity.TransformBy(transformation, translation);
                            entities.Add(newEntity);
                        }
                        break;
                    }

                    case EntityType.MLine:
                    {
                        List <EntityObject> newEntities = ((MLine)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            newEntity.TransformBy(transformation, translation);
                            entities.Add(newEntity);
                        }
                        break;
                    }

                    default:
                    {
                        EntityObject newEntity = (EntityObject)entity.Clone();
                        newEntity.TransformBy(transformation, translation);
                        entities.Add(newEntity);
                        break;
                    }
                    }
                }
                else
                {
                    EntityObject newEntity = (EntityObject)entity.Clone();
                    newEntity.TransformBy(transformation, translation);
                    entities.Add(newEntity);
                }
            }

            return(entities);
        }