public LwPolyline(netDxf.Entities.LwPolyline inputLwPolyline) { InputLwPolyline = inputLwPolyline; //for (int i = 1; i < InputLwPolyline.Vertexes.Count; i++) //{ // LinesOrArcsCollection.Add(new Line(InputLwPolyline.Vertexes[i - 1], InputLwPolyline.Vertexes[i])); //} var temp = InputLwPolyline.Explode(); foreach (var item in temp) { if (item.GetType() == typeof(netDxf.Entities.Line)) { LinesOrArcsCollection.Add(new Line((netDxf.Entities.Line)item)); } else if (item.GetType() == typeof(netDxf.Entities.Arc)) { LinesOrArcsCollection.Add(new Arc((netDxf.Entities.Arc)item)); } } foreach (var item in LinesOrArcsCollection) { CheckIfNewPointExtendArea(item.MaxXMaxY); CheckIfNewPointExtendArea(item.MinXMinY); Length += item.Length; } }
private void SetInternalInfo(IEnumerable <EntityObject> entities) { bool containsClosedPolyline = false; this.edges.Clear(); foreach (EntityObject entity in entities) { if (containsClosedPolyline) { 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.LightWeightPolyline: LwPolyline poly = (LwPolyline)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)); // A polyline HatchBoundaryPath must be closed this.pathType |= HatchBoundaryPathTypeFlags.Polyline; containsClosedPolyline = true; } else { this.SetInternalInfo(poly.Explode()); // 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.", entity.Type)); } } }
private static void ExplodeTest() { DxfDocument dxf = new DxfDocument(); //polyline LwPolylineVertex polyVertex; List<LwPolylineVertex> polyVertexes = new List<LwPolylineVertex>(); polyVertex = new LwPolylineVertex(new Vector2(-50, -23.5)); polyVertex.Bulge = 1.33; polyVertexes.Add(polyVertex); polyVertex = new LwPolylineVertex(new Vector2(34.8, -42.7)); polyVertexes.Add(polyVertex); polyVertex = new LwPolylineVertex(new Vector2(65.3, 54.7)); polyVertex.Bulge = -0.47; polyVertexes.Add(polyVertex); polyVertex = new LwPolylineVertex(new Vector2(-48.2, 42.5)); polyVertexes.Add(polyVertex); LwPolyline polyline2d = new LwPolyline(polyVertexes); polyline2d.Layer = new Layer("polyline2d"); polyline2d.Layer.Color.Index = 5; polyline2d.Normal = new Vector3(1, 1, 1); polyline2d.Elevation = 100.0f; dxf.AddEntity(polyline2d); dxf.AddEntity(polyline2d.Explode()); dxf.Save("explode.dxf"); }