/// <summary> /// Moves, scales, and/or rotates the current entity given a 3x3 transformation matrix and a translation vector. /// </summary> /// <param name="transformation">Transformation matrix.</param> /// <param name="translation">Translation vector.</param> public override void TransformBy(Matrix3 transformation, Vector3 translation) { Vector3 newNormal; double newScale; double newAngle; newNormal = transformation * this.Normal; Matrix3 transOW = MathHelper.ArbitraryAxis(this.Normal); Matrix3 transWO = MathHelper.ArbitraryAxis(newNormal).Transpose(); List <HatchBoundaryPath> paths = new List <HatchBoundaryPath>(); foreach (HatchBoundaryPath path in this.BoundaryPaths) { List <EntityObject> data = new List <EntityObject>(); foreach (HatchBoundaryPath.Edge edge in path.Edges) { EntityObject entity = edge.ConvertTo(); switch (entity.Type) { case EntityType.Arc: entity = ProcessArc((Arc)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation)); break; case EntityType.Circle: entity = ProcessCircle((Circle)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation)); break; case EntityType.Ellipse: entity = ProcessEllipse((Ellipse)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation)); break; case EntityType.Line: entity = ProcessLine((Line)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation)); break; case EntityType.LwPolyline: entity = ProcessLwPolyline((LwPolyline)entity, this.Normal, this.Elevation); break; case EntityType.Spline: entity = ProcessSpline((Spline)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation)); break; } entity.TransformBy(transformation, translation); data.Add(entity); } paths.Add(new HatchBoundaryPath(data)); } Vector3 position = transOW * new Vector3(0.0, 0.0, this.Elevation); position = transformation * position + translation; position = transWO * position; Vector2 refAxis = Vector2.Rotate(Vector2.UnitX, this.Pattern.Angle * MathHelper.DegToRad); refAxis = this.Pattern.Scale * refAxis; Vector3 v = transOW * new Vector3(refAxis.X, refAxis.Y, 0.0); v = transformation * v; v = transWO * v; Vector2 axis = new Vector2(v.X, v.Y); newAngle = Vector2.Angle(axis) * MathHelper.RadToDeg; newScale = axis.Modulus(); newScale = MathHelper.IsZero(newScale) ? MathHelper.Epsilon : newScale; this.Pattern.Scale = newScale; this.Pattern.Angle = newAngle; this.Elevation = position.Z; this.Normal = newNormal; this.BoundaryPaths.Clear(); this.BoundaryPaths.AddRange(paths); }
/// <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); }
/// <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); }