public Polyline(EntityObject entity) : base(EdgeType.Polyline) { if (entity == null) { throw new ArgumentNullException("entity"); } if (entity is Entities.LwPolyline) { LwPolyline poly = (LwPolyline)entity; if (!poly.IsClosed) { throw new ArgumentException("Only closed polyline are supported as hatch boundary edges.", "entity"); } this.Vertexes = new Vector3[poly.Vertexes.Count]; for (int i = 0; i < poly.Vertexes.Count; i++) { this.Vertexes[i] = new Vector3(poly.Vertexes[i].Location.X, poly.Vertexes[i].Location.Y, poly.Vertexes[i].Bulge); } this.IsClosed = true; } else if (entity is Entities.Polyline) { Entities.Polyline poly = (Entities.Polyline)entity; if (!poly.IsClosed) { throw new ArgumentException("Only closed polyline are supported as hatch boundary edges.", "entity"); } this.Vertexes = new Vector3[poly.Vertexes.Count]; for (int i = 0; i < poly.Vertexes.Count; i++) { this.Vertexes[i] = new Vector3(poly.Vertexes[i].Location.X, poly.Vertexes[i].Location.Y, 0.0); } this.IsClosed = true; } else { throw new ArgumentException("The entity is not a LwPolyline or a Polyline", "entity"); } }
/// <summary> /// Initializes a new instance of the <c>HatchBoundaryPath.Polyline</c> class. /// </summary> /// <param name="entity"><see cref="EntityObject">Entity</see> that represents the edge.</param> public Polyline(EntityObject entity) : base(EdgeType.Polyline) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Type == EntityType.LwPolyline) { Entities.LwPolyline poly = (Entities.LwPolyline)entity; this.IsClosed = poly.IsClosed; this.Vertexes = new Vector3[poly.Vertexes.Count]; for (int i = 0; i < poly.Vertexes.Count; i++) { this.Vertexes[i] = new Vector3(poly.Vertexes[i].Position.X, poly.Vertexes[i].Position.Y, poly.Vertexes[i].Bulge); } } else if (entity.Type == EntityType.Polyline) { Matrix3 trans = MathHelper.ArbitraryAxis(entity.Normal).Transpose(); Entities.Polyline poly = (Entities.Polyline)entity; this.IsClosed = poly.IsClosed; this.Vertexes = new Vector3[poly.Vertexes.Count]; for (int i = 0; i < poly.Vertexes.Count; i++) { Vector3 point = trans * poly.Vertexes[i].Position; this.Vertexes[i] = new Vector3(point.X, point.Y, 0.0); } } else { throw new ArgumentException("The entity is not a LwPolyline or a Polyline", nameof(entity)); } }
private void SetInternalInfo(IEnumerable <EntityObject> contourn, bool clearEdges) { bool containsPolyline = false; if (clearEdges) { this.edges.Clear(); } foreach (EntityObject entity in contourn) { if (containsPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } // it seems that AutoCad does not have problems on creating loops that theoretically does not make sense, // like, for example, an internal loop that is made of a single arc. // so if AutoCAD is OK with that I am too, the program that make use of this information will take care of this inconsistencies switch (entity.Type) { case EntityType.Arc: this.edges.Add(Arc.ConvertFrom(entity)); break; case EntityType.Circle: this.edges.Add(Arc.ConvertFrom(entity)); break; case EntityType.Ellipse: this.edges.Add(Ellipse.ConvertFrom(entity)); break; case EntityType.Line: this.edges.Add(Line.ConvertFrom(entity)); break; case EntityType.LwPolyline: Entities.LwPolyline lwpoly = (Entities.LwPolyline)entity; if (lwpoly.IsClosed) { if (this.edges.Count != 0) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Polyline.ConvertFrom(entity)); this.pathType |= HatchBoundaryPathTypeFlags.Polyline; containsPolyline = true; } else { this.SetInternalInfo(lwpoly.Explode(), false); // open polylines will always be exploded, only one polyline can be present in a path } break; case EntityType.Polyline: Entities.Polyline poly = (Entities.Polyline)entity; if (poly.IsClosed) { if (this.edges.Count != 0) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Polyline.ConvertFrom(entity)); this.pathType |= HatchBoundaryPathTypeFlags.Polyline; containsPolyline = true; } else { this.SetInternalInfo(poly.Explode(), false); // open polylines will always be exploded, only one polyline can be present in a path } break; case EntityType.Spline: this.edges.Add(Spline.ConvertFrom(entity)); break; default: throw new ArgumentException(string.Format("The entity type {0} cannot be part of a hatch boundary. Only Arc, Circle, Ellipse, Line, LwPolyline, and Spline entities are allowed.", entity.Type)); } } }