public void LwPolylineWithLargeArcTest1() { var vertices = new List <DxfLwPolylineVertex>() { new DxfLwPolylineVertex() { X = 0.6802950090711775, Y = 1.360590018142377, Bulge = 1.523362963416235 }, new DxfLwPolylineVertex() { X = 1.176774337206015, Y = 0.2152040759172933 } }; var poly = new DxfLwPolyline(vertices); var path = poly.GetSvgPath(); Assert.Equal(2, path.Segments.Count); var move = (SvgMoveToPath)path.Segments[0]; AssertClose(0.6802950090711775, move.LocationX); AssertClose(1.360590018142377, move.LocationY); var arc = (SvgArcToPath)path.Segments[1]; AssertClose(1.176774337206015, arc.EndPointX); AssertClose(0.2152040759172933, arc.EndPointY); AssertClose(0.68029500907118867, arc.RadiusX); AssertClose(0.68029500907118867, arc.RadiusY); Assert.True(arc.IsCounterClockwiseSweep); Assert.True(arc.IsLargeArc); Assert.Equal(0.0, arc.XAxisRotation); }
private static IEnumerable <IPdfPathItem> ConvertPolyline(DxfLwPolyline lwPolyline, DxfLayer layer, Matrix4 affine, Matrix4 scale) { var pdfStreamState = new PdfStreamState( strokeColor: GetPdfColor(lwPolyline, layer), strokeWidth: GetStrokeWidth(lwPolyline, layer)); IList <DxfLwPolylineVertex> vertices = lwPolyline.Vertices; int n = vertices.Count; DxfLwPolylineVertex vertex = vertices[0]; for (int i = 1; i < n; i++) { DxfLwPolylineVertex next = vertices[i]; yield return(ConvertPolylineSegment(vertex, next, affine, scale, pdfStreamState)); vertex = next; } if (lwPolyline.IsClosed) { var next = vertices[0]; var p1 = affine.Transform(new Vector(vertex.X, vertex.Y, 0)) .ToPdfPoint(PdfMeasurementType.Point); var p2 = affine.Transform(new Vector(next.X, next.Y, 0)) .ToPdfPoint(PdfMeasurementType.Point); yield return(new PdfLine(p1, p2, pdfStreamState)); } }
public void LwPolylineWithLargeArcTest2() { var vertices = new List <DxfLwPolylineVertex>() { new DxfLwPolylineVertex() { X = 1.176774337206015, Y = 0.2152040759172933, Bulge = -0.1085213126826841 }, new DxfLwPolylineVertex() { X = 1.501796342836956, Y = 0.2867624159371331 } }; var poly = new DxfLwPolyline(vertices); var path = poly.GetSvgPath(); Assert.Equal(2, path.Segments.Count); var move = (SvgMoveToPath)path.Segments[0]; AssertClose(1.176774337206015, move.LocationX); AssertClose(0.2152040759172933, move.LocationY); var arc = (SvgArcToPath)path.Segments[1]; AssertClose(1.501796342836956, arc.EndPointX); AssertClose(0.2867624159371331, arc.EndPointY); AssertClose(0.77571287053371341, arc.RadiusX); AssertClose(0.77571287053371341, arc.RadiusY); Assert.False(arc.IsCounterClockwiseSweep); Assert.False(arc.IsLargeArc); Assert.Equal(0.0, arc.XAxisRotation); }
void ProcessDxfLwPolyline(DxfLwPolyline dxfPolyline) { if (dxfPolyline.Vertices.Count < 2) { return; } int iVertexCount = 0; Vector2D startPoint = new Vector2D(); foreach (var vertex in dxfPolyline.Vertices) { Vector2D endPoint = new Vector2D(vertex.X, vertex.Y); if (iVertexCount > 0) { PicSegment picSegment = Factory.AddSegment( DxfColor2PicLT(dxfPolyline), 0, 0 , startPoint , endPoint); picSegment.Group = DxfLayer2PicGrp(dxfPolyline.Layer); } startPoint = endPoint; ++iVertexCount; } PicSegment endSegment = Factory.AddSegment( DxfColor2PicLT(dxfPolyline), 0, 0 , startPoint , new Vector2D(dxfPolyline.Vertices[0].X, dxfPolyline.Vertices[0].Y) ); endSegment.Group = DxfLayer2PicGrp(dxfPolyline.Layer); }
public void WriteLwPolylineWithOptionalValuesTest() { var lwpolyline = new DxfLwPolyline(); lwpolyline.Vertices.Add(new DxfLwPolylineVertex() { X = 2.0, Y = 0.0, Bulge = 0.7 }); lwpolyline.Vertices.Add(new DxfLwPolylineVertex() { X = 1.0, Y = 2.5 }); lwpolyline.Vertices.Add(new DxfLwPolylineVertex() { X = -1.0, Y = 2.5, Bulge = 0.7 }); lwpolyline.Vertices.Add(new DxfLwPolylineVertex() { X = -2.0, Y = 0.0 }); EnsureFileContainsEntity(lwpolyline, @" 0 LWPOLYLINE 5 # 100 AcDbEntity 8 0 100 AcDbPolyline 90 4 70 0 10 2.0 20 0.0 42 0.7 10 1.0 20 2.5 10 -1.0 20 2.5 42 0.7 10 -2.0 20 0.0 ", DxfAcadVersion.R14); }
public void RenderEntity(DxfLwPolyline dxfLwPolyline, Graphics graphics, int height) { var dxfPolylineVertices = dxfLwPolyline.Vertices; var points = dxfPolylineVertices .Select(t => new PointF((float)t.X * ScaleFactor + OffsetX, height - (float)t.Y * ScaleFactor + OffsetY)) .ToArray(); graphics.DrawLines(Pens.Black, points); }
public static XElement ToXElement(this DxfLwPolyline poly) { var path = poly.GetSvgPath(); return(new XElement(DxfToSvgConverter.Xmlns + "path", new XAttribute("d", path.ToString()), new XAttribute("fill-opacity", 0)) .AddStroke(poly.Color) .AddStrokeWidth(1.0) .AddVectorEffect()); }
public static Polyline ToPolyline(this DxfLwPolyline poly) { var vertices = poly.Vertices.Select(v => v.ToVertex(poly.Elevation)).ToList(); if (poly.IsClosed && vertices.Count > 0) { vertices.Add(vertices[0]); } return(new Polyline(vertices, poly.GetEntityColor(), poly)); }
public string EntityToJson(DxfLwPolyline dxfLwPolyline) { // TODO! var dxfLwPolylineVertices = dxfLwPolyline.Vertices; var json = string.Join(", ", dxfLwPolylineVertices.Select(cp => string.Format(Format, "[{0:F},{1:F}]", cp.X, cp.Y))); return(string.Format("[\"lwpolyline\",{0}]", json)); }
public Class1030(DxfModel model) { DxfVersion acadVersion = model.Header.AcadVersion; if (acadVersion < DxfVersion.Dxf15) { this.short_4 = DxfHatch.smethod_2(model.Classes).ClassNumber; this.short_3 = DxfLwPolyline.smethod_2(model.Classes).ClassNumber; this.short_9 = DxfClass.smethod_19(model.Classes).ClassNumber; } if (acadVersion < DxfVersion.Dxf18) { this.short_8 = DxfClass.smethod_15(model.Classes).ClassNumber; this.short_7 = DxfClass.smethod_16(model.Classes).ClassNumber; } this.dxfClass_0 = DxfClass.smethod_0(model.Classes); this.dxfClass_1 = DxfDataTable.smethod_2(model.Classes); this.dxfClass_5 = DxfClass.smethod_1(model.Classes); this.short_0 = DxfClass.smethod_20(model.Classes).ClassNumber; this.short_1 = DxfClass.smethod_21(model.Classes).ClassNumber; this.dxfClass_6 = DxfClass.smethod_5(model.Classes); this.dxfClass_14 = DxfClass.smethod_2(model.Classes); this.dxfClass_10 = DxfClass.smethod_6(model.Classes); this.dxfClass_22 = DxfVisualStyle.smethod_2(model.Classes); this.dxfClass_23 = DxfWipeoutVariables.smethod_2(model.Classes); this.dxfClass_11 = DxfClass.smethod_7(model.Classes); this.short_6 = this.dxfClass_11.ClassNumber; this.short_2 = this.dxfClass_6.ClassNumber; this.dxfClass_7 = DxfMLeader.smethod_2(model.Classes); this.dxfClass_8 = DxfMLeaderStyle.smethod_3(model.Classes); this.dxfClass_9 = DxfMLeaderObjectContextData.smethod_16(model.Classes); this.short_5 = this.dxfClass_10.ClassNumber; this.dxfClass_12 = DxfClass.smethod_3(model.Classes); this.dxfClass_16 = DxfClass.smethod_10(model.Classes); this.dxfClass_17 = DxfClass.smethod_11(model.Classes); this.dxfClass_18 = DxfClass.smethod_14(model.Classes); this.dxfClass_15 = DxfClass.smethod_12(model.Classes); this.dxfClass_19 = DxfClass.smethod_17(model.Classes); this.dxfClass_20 = DxfClass.smethod_18(model.Classes); this.dxfClass_21 = DxfTableContent.smethod_2(model.Classes); this.dxfClass_2 = DxfField.smethod_2(model.Classes); this.dxfClass_3 = DxfFieldList.smethod_2(model.Classes); this.dxfClass_4 = DxfGeoData.smethod_2(model.Classes); this.dxfClass_13 = DxfPlotSettings.smethod_2(model.Classes); this.class1032_0 = new Class1030.Class1032(model); this.class1031_0 = new Class1030.Class1031(model); }
//LWPOLYLINE public static List <string> LwPolyline(DxfEntity _entity, string _origin) { DxfLwPolyline lwPolyline = _entity as DxfLwPolyline; List <string> newVertices = new List <string>(); //loop over all vertices in entity foreach (DxfLwPolyline.Vertex vertex in lwPolyline.Vertices) { newVertices.Add(RemoveSpaces(vertex.Position.ToString())); } //Transformed points list List <string> verticesTransformed = new List <string>(); foreach (string item in newVertices) { verticesTransformed.Add(TransformPoint(item, _origin)); } return(verticesTransformed); }
internal static SvgPath GetSvgPath(this DxfLwPolyline poly) { var first = poly.Vertices.First(); var segments = new List <SvgPathSegment>(); segments.Add(new SvgMoveToPath(first.X, first.Y)); var last = first; foreach (var next in poly.Vertices.Skip(1)) { segments.Add(FromPolylineVertices(last, next)); last = next; } if (poly.IsClosed) { segments.Add(FromPolylineVertices(last, first)); } return(new SvgPath(segments)); }
/// <summary> /// Converts dxf lwpolyline into rhino polyline. This method will approximate arcs to small lines. /// TODO: check magic numbers (int precision=36, double lengthTolerance=.001) /// </summary> /// <param name="precision"></param> /// <param name="lengthTolerance"></param> /// <returns></returns> private Polyline GetApproxRhinoPolyline(int precision = 16, double lengthTolerance = .001) { if (DxfLwPolyline != null) { IList <Vector2> vertexes = DxfLwPolyline.PolygonalVertexes(precision, lengthTolerance, .001); List <Point3d> RhPlVertexes = new List <Point3d>(); Polyline pl = new Rhino.Geometry.Polyline(); foreach (var item in vertexes) { RhPlVertexes.Add(new Point3d(item.X, item.Y, 0)); } pl = new Polyline(RhPlVertexes); return(pl); } else { return(null); } }
public void ReadLwPolylineTest() { var lwpoly = new DxfLwPolyline(new[] { new DxfLwPolylineVertex() { X = 1.0, Y = 2.0 }, new DxfLwPolylineVertex() { X = 3.0, Y = 4.0 } }) { Elevation = 12.0 }; var poly = (Polyline)lwpoly.ToEntity(); Assert.Equal(2, poly.Vertices.Count()); Assert.Equal(new Point(1.0, 2.0, 12.0), poly.Vertices.First().Location); Assert.Equal(new Point(3.0, 4.0, 12.0), poly.Vertices.Last().Location); }
public float GetEntityLength(DxfLwPolyline dxfLwPolyline) { var dxfPolylineVertices = dxfLwPolyline.Vertices; var sumDistance = 0f; using (var enumerator = dxfPolylineVertices.GetEnumerator()) { if (!enumerator.MoveNext()) { return(sumDistance); } var last = enumerator.Current; while (enumerator.MoveNext()) { var current = enumerator.Current; sumDistance += Distance(current, last); last = current; } } return(sumDistance); }
/// <summary> /// Visits the specified entity. /// See the <see cref="IEntityVisitor"/> for more details. /// </summary> public override void Visit(DxfLwPolyline polyline) { HandleEntity(polyline); }
//Get All Booth Info for a given model public Stream GetBoothsInfo(Stream input) { string body = new StreamReader(input).ReadToEnd(); NameValueCollection _nvc = HttpUtility.ParseQueryString(body); string _fileName = _nvc["FileName"]; string _client_id = _nvc["ClientId"]; string _show_id = _nvc["ShowId"]; string _boothOutlineLayer = _nvc["BoothOutline"]; string _boothNumberLayer = _nvc["BoothNumber"]; DxfModel _model = ReadDxf("h://dxf_uploads//" + _client_id + " // " + _show_id + "//" + _fileName); BoundsCalculator _mBounds = new BoundsCalculator(); _mBounds.GetBounds(_model); Bounds3D _cBounds = _mBounds.Bounds; //get screen origin string _screenOrigin = GetScreenOrigin(_cBounds.ToString()); //Empty List to attach all booth information List <Booth> _boothInfo = new List <Booth>(); //Empty List to hold vertices of all Booths List <Point> _allVertices = new List <Point>(); //loop over all Entites in a model foreach (DxfEntity _entity in _model.Entities) { if (_entity.Layer.ToString().Equals(_boothOutlineLayer, StringComparison.InvariantCultureIgnoreCase)) //(_entity.Layer.ToString() == _boothOutlineLayer) { if (_entity.EntityType.ToString() == "LWPOLYLINE" || _entity.EntityType.ToString() == "POLYLINE") { var verticesTransformed = LwPolyline(_entity, _screenOrigin); Booth _booth = PassBooth(_model, _boothNumberLayer, verticesTransformed, _screenOrigin); Point[] verticesArray = VerticesToList(verticesTransformed).ToArray(); foreach (Point _vertex in verticesArray) { _allVertices.Add(_vertex); } _boothInfo.Add(_booth); } else if (_entity.EntityType.ToString() == "INSERT") { DxfInsert Insertentity = _entity as DxfInsert; Matrix4D transform = Insertentity.BlockInsertionTransformations[0, 0] * Insertentity.Block.BaseTransformation; DxfBlock block = Insertentity.Block; foreach (DxfEntity lwEntity in block.Entities) { if (lwEntity.EntityType == "LWPOLYLINE") { DxfLwPolyline lwPolyline = lwEntity as DxfLwPolyline; Matrix4D _insertedPolylineTransform = transform * lwPolyline.Transform; List <string> _newVertices = new List <string>(); //loop over all vertices in entity foreach (DxfLwPolyline.Vertex vertex in lwPolyline.Vertices) { _newVertices.Add(RemoveSpaces(_insertedPolylineTransform.Transform(vertex.Position).ToString())); } List <string> verticesTransformed = new List <string>(); foreach (string item in _newVertices) { verticesTransformed.Add(TransformPoint(item, _screenOrigin)); } Booth _booth = PassBooth(_model, _boothNumberLayer, verticesTransformed, _screenOrigin); Point[] verticesArray = VerticesToList(verticesTransformed).ToArray(); foreach (Point _vertex in verticesArray) { _allVertices.Add(_vertex); } _boothInfo.Add(_booth); } } } } } Booth _boundaries = new Booth() { BOOTHNUMBER = "", INSERTPOINT = _screenOrigin, SHAPE = "origin", SIZEX = "", SIZEY = "" }; _boothInfo.Add(_boundaries); string gridline = FindGridLine(_allVertices.ToArray()); string[] gridLine = gridline.Split(','); Booth _gridLine = new Booth() { BOOTHNUMBER = "", INSERTPOINT = "", SHAPE = "Grid Line", SIZEX = gridLine[0], SIZEY = gridLine[1] }; _boothInfo.Add(_gridLine); string boothInformation = JsonConvert.SerializeObject(_boothInfo); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return(new MemoryStream(Encoding.UTF8.GetBytes(boothInformation))); //return JsonConvert.SerializeObject(_boothInfo); }
public virtual void Visit(DxfLwPolyline polyline) { }
public static completeDxfStruct processDxfFile(string in_obtainedFileName) { completeDxfStruct valueToReturn = new completeDxfStruct(); DxfFile dxfFile; using (System.IO.FileStream fs = new System.IO.FileStream(in_obtainedFileName, System.IO.FileMode.Open)) { dxfFile = DxfFile.Load(fs); IList <DxfBlock> allBlocks = dxfFile.Blocks; IList <DxfEntity> usedEntities; if ((allBlocks.Count == 0) || (allBlocks[0].Name.ToUpper().Contains("MODEL") == false)) { usedEntities = dxfFile.Entities; } else { usedEntities = allBlocks[0].Entities; } foreach (DxfEntity entity in dxfFile.Entities) { switch (entity.EntityType) { case DxfEntityType.Line: { DxfLine line = (DxfLine)entity; MyDxfLine TransfLine = new MyDxfLine(line.P1.X, line.P1.Y, line.P2.X, line.P2.Y, line.Layer); valueToReturn.addDxfDrawingEntry(TransfLine); break; } case DxfEntityType.Arc: { DxfArc arc = (DxfArc)entity; MyDxfArc TransfArc = new MyDxfArc(arc.Center.X, arc.Center.Y, arc.StartAngle, arc.EndAngle, arc.Radius, arc.Layer); valueToReturn.addDxfDrawingEntry(TransfArc); break; } case DxfEntityType.LwPolyline: { //polyline. It has vertices. DxfLwPolyline polylineS = entity as DxfLwPolyline; int totalnumberOfVertices = polylineS.Vertices.Count; for (int i = 0; i < totalnumberOfVertices - 1; i++) { //iterate through vertices, taking them by 2. A figure is between these two DxfLwPolylineVertex point1 = polylineS.Vertices[i]; DxfLwPolylineVertex point2 = polylineS.Vertices[i + 1]; if (point1.Bulge == 0) { MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y, polylineS.Layer); valueToReturn.addDxfDrawingEntry(TransfLine); } else //it is arc // The bulge is the tangent of one fourth the included angle for an arc segment, // made negative if the arc goes clockwise from the start point to the endpoint. // A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle { double angleOfArcRad = System.Math.Atan(Math.Abs(point1.Bulge)) * 4; // http://mymathforum.com/algebra/21368-find-equation-circle-given-two-points-arc-angle.html // tides of Internet have almost washed this post in forum double xA; double xB; double yA; double yB; if (point1.Bulge < 0) { xA = point2.X; yA = point2.Y; xB = point1.X; yB = point1.Y; } else { xA = point1.X; yA = point1.Y; xB = point2.X; yB = point2.Y; } double d_square = (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB); double r_square = (d_square) / (2.0 * (1.0 - Math.Cos(angleOfArcRad))); double m = (xA - xB) / (yB - yA); double a = Math.Sqrt(r_square - d_square / 4.0); double xM = (xA + xB) / 2.0; double yM = (yA + yB) / 2.0; double xC_plus = xM + a / Math.Sqrt(m * m + 1); double xC_minus = xM - a / Math.Sqrt(m * m + 1); double yC_plus = yM + m * a / Math.Sqrt(m * m + 1); double yC_minus = yM - m * a / Math.Sqrt(m * m + 1); // https://en.wikipedia.org/wiki/Linear_equation#Point%E2%80%93slope_form double usedXCenter; double usedYCenter; double usedAngle1; double usedAngle2; // https://stackoverflow.com/questions/1311049/how-to-map-atan2-to-degrees-0-360 double angle1_candidate1 = (Math.Atan2(yA - yC_plus, xA - xC_plus) * 180 / Math.PI + 360) % 360; double angle2_candidate1 = (Math.Atan2(yB - yC_plus, xB - xC_plus) * 180 / Math.PI + 360) % 360; double angle1_candidate2 = (Math.Atan2(yA - yC_minus, xA - xC_minus) * 180 / Math.PI + 360) % 360; double angle2_candidate2 = (Math.Atan2(yB - yC_minus, xB - xC_minus) * 180 / Math.PI + 360) % 360; //mydxfarc expects angles counterclockwise if (point1.Bulge > 0) { if (angle1_candidate1 < angle2_candidate1) { usedAngle1 = angle1_candidate1; usedAngle2 = angle2_candidate1; usedXCenter = xC_plus; usedYCenter = yC_plus; } else { usedAngle1 = angle1_candidate2; usedAngle2 = angle2_candidate2; usedXCenter = xC_minus; usedYCenter = yC_minus; } } else { if (angle1_candidate1 > angle2_candidate1) { usedAngle1 = angle1_candidate2; usedAngle2 = angle2_candidate2; usedXCenter = xC_minus; usedYCenter = yC_minus; } else { usedAngle1 = angle1_candidate1; usedAngle2 = angle2_candidate1; usedXCenter = xC_plus; usedYCenter = yC_plus; } } MyDxfArc TransfArc = new MyDxfArc(usedXCenter, usedYCenter, usedAngle1, usedAngle2, Math.Sqrt(r_square), polylineS.Layer); valueToReturn.addDxfDrawingEntry(TransfArc); } } if (polylineS.IsClosed) { DxfLwPolylineVertex point1 = polylineS.Vertices[totalnumberOfVertices - 1]; DxfLwPolylineVertex point2 = polylineS.Vertices[0]; if (point1.Bulge == 0) { MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y, polylineS.Layer); valueToReturn.addDxfDrawingEntry(TransfLine); } else // arc // I so like the code above, so I cannot resist to copypaste it { double angleOfArcRad = System.Math.Atan(Math.Abs(point1.Bulge)) * 4; double xA; double xB; double yA; double yB; if (point1.Bulge < 0) { xA = point2.X; yA = point2.Y; xB = point1.X; yB = point1.Y; } else { xA = point1.X; yA = point1.Y; xB = point2.X; yB = point2.Y; } double d_square = (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB); double r_square = (d_square) / (2.0 * (1.0 - Math.Cos(angleOfArcRad))); double m = (xA - xB) / (yB - yA); double a = Math.Sqrt(r_square - d_square / 4.0); double xM = (xA + xB) / 2.0; double yM = (yA + yB) / 2.0; double xC_plus = xM + a / Math.Sqrt(m * m + 1); double xC_minus = xM - a / Math.Sqrt(m * m + 1); double yC_plus = yM + m * a / Math.Sqrt(m * m + 1); double yC_minus = yM - m * a / Math.Sqrt(m * m + 1); // https://en.wikipedia.org/wiki/Linear_equation#Point%E2%80%93slope_form double usedXCenter; double usedYCenter; double usedAngle1; double usedAngle2; // https://stackoverflow.com/questions/1311049/how-to-map-atan2-to-degrees-0-360 double angle1_candidate1 = (Math.Atan2(yA - yC_plus, xA - xC_plus) * 180 / Math.PI + 360) % 360; double angle2_candidate1 = (Math.Atan2(yB - yC_plus, xB - xC_plus) * 180 / Math.PI + 360) % 360; double angle1_candidate2 = (Math.Atan2(yA - yC_minus, xA - xC_minus) * 180 / Math.PI + 360) % 360; double angle2_candidate2 = (Math.Atan2(yB - yC_minus, xB - xC_minus) * 180 / Math.PI + 360) % 360; //mydxfarc expects angles counterclockwise if (point1.Bulge > 0) { if (angle1_candidate1 < angle2_candidate1) { usedAngle1 = angle1_candidate1; usedAngle2 = angle2_candidate1; usedXCenter = xC_plus; usedYCenter = yC_plus; } else { usedAngle1 = angle1_candidate2; usedAngle2 = angle2_candidate2; usedXCenter = xC_minus; usedYCenter = yC_minus; } } else { if (angle1_candidate1 > angle2_candidate1) { usedAngle1 = angle1_candidate2; usedAngle2 = angle2_candidate2; usedXCenter = xC_minus; usedYCenter = yC_minus; } else { usedAngle1 = angle1_candidate1; usedAngle2 = angle2_candidate1; usedXCenter = xC_plus; usedYCenter = yC_plus; } } MyDxfArc TransfArc = new MyDxfArc(usedXCenter, usedYCenter, usedAngle1, usedAngle2, Math.Sqrt(r_square), polylineS.Layer); valueToReturn.addDxfDrawingEntry(TransfArc); } } break; } case DxfEntityType.Polyline: { //this is a spawn of autocad. Either copypaste code from LwPolyline section. Or just save the file in QCad. //QCad replaces all polylines by lwPolylines //https://github.com/IxMilia/Dxf/issues/90 DxfPolyline polyline = entity as DxfPolyline; break; } } } } return(valueToReturn); }
public virtual void Visit(DxfLwPolyline polyline) { this.VisitEntity((DxfEntity)polyline); }
/// <summary> /// Parse DXF into VectorShape list. /// </summary> public static List <VectorShape> ReadDXF(Stream dxfStream) { List <VectorShape> shapes = new List <VectorShape>(); DxfFile dxfFile = DxfFile.Load(dxfStream); Dictionary <string, Color32> layerColors = new Dictionary <string, Color32>(); foreach (DxfLayer layer in dxfFile.Layers) { layerColors.Add(layer.Name, ConvertColor(layer.Color)); } foreach (DxfEntity entity in dxfFile.Entities) { VectorShape shape = null; switch (entity.EntityType) { case DxfEntityType.Point: DxfModelPoint point = entity as DxfModelPoint; shape = new PointShape(ConvertPoint(point.Location)); break; case DxfEntityType.Line: DxfLine line = entity as DxfLine; Vector2[] endpoints = new Vector2[2]; endpoints[0] = ConvertPoint(line.P1); endpoints[1] = ConvertPoint(line.P2); shape = new PolyShape(endpoints); break; case DxfEntityType.Spline: DxfSpline spline = entity as DxfSpline; if ((spline.NumberOfControlPoints % spline.DegreeOfCurve) != 1) { Debug.LogError("Invalid spline data! Wrong number of points. " + spline); break; } Vector2[] controlPoints = new Vector2[spline.NumberOfControlPoints]; for (int i = 0; i < controlPoints.Length; i++) { controlPoints[i] = ConvertPoint(spline.ControlPoints[i]); } shape = new PolyShape(controlPoints[0]); PolyShape shapeSpline = shape as PolyShape; switch (spline.DegreeOfCurve) { case 1: for (int i = 1; i < controlPoints.Length; i++) { shapeSpline.LineTo(controlPoints[i]); } break; case 2: for (int i = 1; i < controlPoints.Length; i += 2) { shapeSpline.CurveTo(controlPoints[i + 1], controlPoints[i]); } break; case 3: for (int i = 1; i < controlPoints.Length; i += 3) { shapeSpline.CurveTo(controlPoints[i + 2], controlPoints[i], controlPoints[i + 1]); } break; default: Debug.LogWarning("Spline with unsupported curve of degree: " + spline.DegreeOfCurve); break; } break; case DxfEntityType.Arc: DxfArc arc = entity as DxfArc; // If the arc is a complete circle just make one of those float startAngle = (float)arc.StartAngle; while (startAngle < 0f) { startAngle += 360f; } float endAngle = (float)arc.EndAngle; while (endAngle < startAngle) { endAngle += 360f; } float sweep = endAngle - startAngle; shape = new CircleShape(ConvertPoint(arc.Center), (float)arc.Radius, startAngle, sweep); break; case DxfEntityType.Circle: DxfCircle circle = entity as DxfCircle; shape = new CircleShape(ConvertPoint(circle.Center), (float)circle.Radius * dxfScale); break; case DxfEntityType.Ellipse: DxfEllipse ellipse = entity as DxfEllipse; // If the ellipse is actually a circle just make one of those if (Mathf.Approximately((float)ellipse.MinorAxisRatio, 1f)) { shape = new CircleShape(ConvertPoint(ellipse.Center), (float)ellipse.MajorAxis.Length * dxfScale); } else { shape = new EllipseShape(ConvertPoint(ellipse.Center), ConvertVector(ellipse.MajorAxis), (float)ellipse.MinorAxisRatio); } break; case DxfEntityType.Polyline: DxfPolyline polyline = entity as DxfPolyline; if (polyline.ContainsVertices) { Vector2[] vertices = new Vector2[polyline.Vertices.Count]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = ConvertPoint(polyline.Vertices[i].Location); } shape = new PolyShape(vertices[0]); PolyShape shapePolyline = shape as PolyShape; for (int i = 1; i < vertices.Length; i++) { float bulge = (float)polyline.Vertices[i - 1].Bulge; shapePolyline.ArcToDXF(vertices[i], bulge); } if (polyline.IsClosed) { float bulge = (float)polyline.Vertices[vertices.Length - 1].Bulge; shapePolyline.ArcToDXF(vertices[0], bulge); shape.Closed = true; } } break; case DxfEntityType.LwPolyline: { DxfLwPolyline lwPolyline = entity as DxfLwPolyline; Vector2[] vertices = new Vector2[lwPolyline.Vertices.Count]; for (int i = 0; i < vertices.Length; i++) { DxfLwPolylineVertex lwpVertex = lwPolyline.Vertices[i]; vertices[i] = ConvertPoint(lwpVertex.X, lwpVertex.Y); } shape = new PolyShape(vertices[0]); PolyShape shapePolyline = shape as PolyShape; for (int i = 1; i < vertices.Length; i++) { float bulge = (float)lwPolyline.Vertices[i - 1].Bulge; shapePolyline.ArcToDXF(vertices[i], bulge); } if (lwPolyline.IsClosed) { float bulge = (float)lwPolyline.Vertices[vertices.Length - 1].Bulge; shapePolyline.ArcToDXF(vertices[0], bulge); shape.Closed = true; } } break; default: Debug.Log("Unhandled entity of type: " + entity.EntityType); break; } if (shape != null) { if (entity.IsVisible) { Color32 shapeColor = ConvertColor(entity.Color); //layerColors.TryGetValue(entity.Layer, out shapeColor); shape.colorOutline = shapeColor; shapes.Add(shape); } } } return(shapes); }
public static RawDetail loadDxf(string path) { FileInfo fi = new FileInfo(path); DxfFile dxffile = DxfFile.Load(fi.FullName); RawDetail s = new RawDetail(); //used to replace the dxf on a nested sheet s.Name = fi.FullName; //for now only store used types less for each iterations required IEnumerable <DxfEntity> entities = dxffile.Entities.Where(ent => ent.EntityType == DxfEntityType.Polyline || ent.EntityType == DxfEntityType.LwPolyline); foreach (DxfEntity ent in entities) { LocalContour points = new LocalContour(); switch (ent.EntityType) { case DxfEntityType.LwPolyline: { DxfLwPolyline poly = (DxfLwPolyline)ent; if (poly.Vertices.Count() < 2) { continue; } foreach (DxfLwPolylineVertex vert in poly.Vertices) { points.Points.Add(new PointF((float)vert.X, (float)vert.Y)); } break; } case DxfEntityType.Polyline: { DxfPolyline poly = (DxfPolyline)ent; if (poly.Vertices.Count() < 2) { continue; } foreach (DxfVertex vert in poly.Vertices) { points.Points.Add(new PointF((float)vert.Location.X, (float)vert.Location.Y)); } break; } } ; if (points.Points.Count() < 3) { continue; } s.Outers.Add(points); } return(s); }
public completeDxfStruct processDxfFile(string in_obtainedFileName) { completeDxfStruct valueToReturn = new completeDxfStruct(); DxfFile dxfFile; using (System.IO.FileStream fs = new System.IO.FileStream(in_obtainedFileName, System.IO.FileMode.Open)) { dxfFile = DxfFile.Load(fs); IList <DxfBlock> allBlocks = dxfFile.Blocks; IList <DxfEntity> usedEntities; if ((allBlocks.Count == 0) || (allBlocks[0].Name.ToUpper().Contains("MODEL") == false)) { usedEntities = dxfFile.Entities; } else { usedEntities = allBlocks[0].Entities; } foreach (DxfEntity entity in dxfFile.Entities) { switch (entity.EntityType) { case DxfEntityType.Line: { DxfLine line = (DxfLine)entity; MyDxfLine TransfLine = new MyDxfLine(line.P1.X, line.P1.Y, line.P2.X, line.P2.Y); valueToReturn.addDxfDrawingEntry(TransfLine); break; } case DxfEntityType.Arc: { DxfArc arc = (DxfArc)entity; MyDxfArc TransfArc = new MyDxfArc(arc.Center.X, arc.Center.Y, arc.StartAngle, arc.EndAngle, arc.Radius); valueToReturn.addDxfDrawingEntry(TransfArc); break; } case DxfEntityType.LwPolyline: { //polyline. It has vertices. DxfLwPolyline polylineS = entity as DxfLwPolyline; int totalnumberOfVertices = polylineS.Vertices.Count; for (int i = 0; i < totalnumberOfVertices - 1; i++) { //iterate through vertices, taking them by 2. A figure is between these two DxfLwPolylineVertex point1 = polylineS.Vertices[i]; DxfLwPolylineVertex point2 = polylineS.Vertices[i + 1]; if (point1.Bulge == 0) { MyDxfLine TransfLine = new MyDxfLine(point1.X, point1.Y, point2.X, point2.Y); valueToReturn.addDxfDrawingEntry(TransfLine); } else //it is arc // The bulge is the tangent of one fourth the included angle for an arc segment, // made negative if the arc goes clockwise from the start point to the endpoint. // A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle { double angleOfArc = System.Math.Atan(point1.Bulge) * 180.0 / Math.PI * 4; double startAngle = Math.Atan(point1.Y / point1.X) * 180.0 / Math.PI; //double endAngle = } } break; } case DxfEntityType.Polyline: { //https://github.com/IxMilia/Dxf/issues/90 DxfPolyline polyline = entity as DxfPolyline; break; } } } } return(valueToReturn); }
public void RenderOpenLwPolylineTest() { // 1,1 D // ------------- 2,1 C // | // / // ____________- // 0,0 1,0 // A B var bulge90Degrees = Math.Sqrt(2.0) - 1.0; var vertices = new List <DxfLwPolylineVertex>() { new DxfLwPolylineVertex() { X = 0.0, Y = 0.0 }, // A new DxfLwPolylineVertex() { X = 1.0, Y = 0.0, Bulge = bulge90Degrees }, // B new DxfLwPolylineVertex() { X = 2.0, Y = 1.0 }, // C new DxfLwPolylineVertex() { X = 1.0, Y = 1.0, Bulge = bulge90Degrees } // D }; var poly = new DxfLwPolyline(vertices); poly.IsClosed = false; var path = poly.GetSvgPath(); Assert.Equal(4, path.Segments.Count); var start = (SvgMoveToPath)path.Segments[0]; AssertClose(0.0, start.LocationX); AssertClose(0.0, start.LocationY); var segmentAB = (SvgLineToPath)path.Segments[1]; AssertClose(1.0, segmentAB.LocationX); AssertClose(0.0, segmentAB.LocationY); var segmentBC = (SvgArcToPath)path.Segments[2]; AssertClose(2.0, segmentBC.EndPointX); AssertClose(1.0, segmentBC.EndPointY); AssertClose(1.0, segmentBC.RadiusX); AssertClose(1.0, segmentBC.RadiusY); AssertClose(0.0, segmentBC.XAxisRotation); Assert.False(segmentBC.IsLargeArc); Assert.True(segmentBC.IsCounterClockwiseSweep); var segmentCD = (SvgLineToPath)path.Segments[3]; AssertClose(1.0, segmentCD.LocationX); AssertClose(1.0, segmentCD.LocationY); var expected = new XElement("path", new XAttribute("d", path.ToString()), new XAttribute("fill-opacity", "0"), new XAttribute("stroke-width", "1.0px"), new XAttribute("vector-effect", "non-scaling-stroke")); var actual = poly.ToXElement(); AssertXElement(expected, actual); }
static void FindEntities(DxfEntityCollection Entities) { foreach (var entityGroups in Entities) { if (typeof(DxfLine) != entityGroups.GetType() && typeof(DxfLwPolyline) != entityGroups.GetType() && typeof(DxfMText) != entityGroups.GetType() && typeof(DxfText) != entityGroups.GetType() && typeof(DxfCircle) != entityGroups.GetType() && typeof(DxfHatch) != entityGroups.GetType() && typeof(DxfInsert) != entityGroups.GetType() && typeof(DxfSpline) != entityGroups.GetType()) { // Console.WriteLine(entityGroups.GetType()); } dxfType.Add(entityGroups.GetType().Name); if (typeof(DxfLine) == entityGroups.GetType()) { dxfLine = entityGroups as DxfLine; int color; if (dxfLine.Color.ColorType.ToString() == "ByLayer") { color = dxfLine.Layer.Color.Rgb; } else { color = dxfLine.Color.Rgb; } CADLine cADLine = new CADLine { parentHandle = dxfLine.OwnerObjectSoftReference.Handle, type = dxfLine.GetType().Name, color = color, transform = dxfLine.Transform.DebugString, startPoint = dxfLine.Start.ToString(), endPoint = dxfLine.End.ToString(), lineWeight = dxfLine.LineWeight }; cadEntities.Add(cADLine); } if (typeof(DxfLwPolyline) == entityGroups.GetType()) { //Console.WriteLine(dxfLwPolyline); dxfLwPolyline = entityGroups as DxfLwPolyline; string[] arrVertices = new string[dxfLwPolyline.Vertices.Count]; for (int i = 0; i < dxfLwPolyline.Vertices.Count; i++) { arrVertices[i] = dxfLwPolyline.Vertices[i].ToString(); } int color; if (dxfLwPolyline.Color.ColorType.ToString() == "ByLayer") { color = dxfLwPolyline.Layer.Color.Rgb; } else { color = dxfLwPolyline.Color.Rgb; } CADLwPolyLine cADLwPolyLine = new CADLwPolyLine { parentHandle = dxfLwPolyline.OwnerObjectSoftReference.Handle, type = dxfLwPolyline.GetType().Name, color = color, transform = dxfLwPolyline.Transform.DebugString, vertices = arrVertices, closed = dxfLwPolyline.Closed.ToString(), }; cadEntities.Add(cADLwPolyLine); } if (typeof(DxfXLine) == entityGroups.GetType()) { dxfXLine = entityGroups as DxfXLine; } if (typeof(DxfSpline) == entityGroups.GetType()) { dxfSpline = entityGroups as DxfSpline; string[] arrFitPoints = new string[dxfSpline.FitPoints.Count]; for (int i = 0; i < dxfSpline.FitPoints.Count; i++) { arrFitPoints[i] = dxfSpline.FitPoints[i].ToString(); } int color; if (dxfSpline.Color.ColorType.ToString() == "ByLayer") { color = dxfSpline.Layer.Color.Rgb; } else { color = dxfSpline.Color.Rgb; } CADSpline cADSpline = new CADSpline { parentHandle = dxfSpline.OwnerObjectSoftReference.Handle, type = dxfSpline.GetType().Name, color = color, transform = dxfSpline.Transform.DebugString, fitPoints = arrFitPoints, }; cadEntities.Add(cADSpline); } if (typeof(DxfCircle) == entityGroups.GetType()) { dxfCircle = entityGroups as DxfCircle; int color; if (dxfCircle.Color.ColorType.ToString() == "ByLayer") { color = dxfCircle.Layer.Color.Rgb; } else { color = dxfCircle.Color.Rgb; } CADCircle cADCircle = new CADCircle { parentHandle = dxfCircle.OwnerObjectSoftReference.Handle, type = dxfCircle.GetType().Name, color = color, transform = dxfCircle.Transform.DebugString, center = dxfCircle.Center.ToString(), radius = dxfCircle.Radius }; cadEntities.Add(cADCircle); kcircle.Add(dxfCircle); } if (typeof(DxfArc) == entityGroups.GetType()) { dxfArc = entityGroups as DxfArc; int color; if (dxfArc.Color.ColorType.ToString() == "ByLayer") { color = dxfArc.Layer.Color.Rgb; } else { color = dxfArc.Color.Rgb; } CADArc cADArc = new CADArc { parentHandle = dxfArc.OwnerObjectSoftReference.Handle, type = dxfArc.GetType().Name, color = color, transform = dxfArc.Transform.DebugString, center = dxfArc.Center.ToString(), startAngle = dxfArc.StartAngle, endAngle = dxfArc.EndAngle, radius = dxfArc.Radius }; cadEntities.Add(cADArc); } if (typeof(DxfEllipse) == entityGroups.GetType()) { dxfEllipse = entityGroups as DxfEllipse; int color; if (dxfEllipse.Color.ColorType.ToString() == "ByLayer") { color = dxfEllipse.Layer.Color.Rgb; } else { color = dxfEllipse.Color.Rgb; } CADEllipse cADEllipse = new CADEllipse { parentHandle = dxfEllipse.OwnerObjectSoftReference.Handle, type = dxfEllipse.GetType().Name, color = color, transform = dxfEllipse.Transform.DebugString, center = dxfEllipse.Center.ToString(), majorAxisEndPoint = dxfEllipse.MajorAxisEndPoint.ToString(), minorAxisEndPoint = dxfEllipse.MinorAxisEndPoint.ToString(), startParameter = dxfEllipse.StartParameter, endParameter = dxfEllipse.EndParameter }; cadEntities.Add(cADEllipse); } if (typeof(DxfMText) == entityGroups.GetType()) { dxfMText = entityGroups as DxfMText; int color; if (dxfMText.Color.ColorType.ToString() == "ByLayer") { color = dxfMText.Layer.Color.Rgb; } else { color = dxfMText.Color.Rgb; } if (dxfMText.SimplifiedText == "C座一层平面图") { ktls.Add(dxfMText); } CADMText cADMText = new CADMText { parentHandle = dxfMText.OwnerObjectSoftReference.Handle, type = dxfMText.GetType().Name, color = color, transform = dxfMText.Transform.DebugString, simplifiedText = dxfMText.SimplifiedText.ToString(), fontStyle = dxfMText.Style.ToString(), size = dxfMText.Height, attachmentPoint = dxfMText.AttachmentPoint.ToString(), boxHeight = dxfMText.BoxHeight, boxWidth = dxfMText.BoxWidth }; cadEntities.Add(cADMText); if (dxfMText.SimplifiedText.ToString() == "图 纸 目 录") { //Console.WriteLine(222222); ktls.Add(dxfMText); } if (dxfMText.SimplifiedText.ToString() == "JS-T5-302") { //Console.WriteLine(222222); ktls.Add(dxfMText); } } if (typeof(DxfText) == entityGroups.GetType()) { dxfText = entityGroups as DxfText; int color; if (dxfText.Color.ColorType.ToString() == "ByLayer") { color = dxfText.Layer.Color.Rgb; } else { color = dxfText.Color.Rgb; } CADText cADText = new CADText { parentHandle = dxfText.OwnerObjectSoftReference.Handle, type = dxfText.GetType().Name, color = color, transform = dxfText.Transform.DebugString, simplifiedText = dxfText.SimplifiedText.ToString(), fontStyle = dxfText.Style.ToString(), size = dxfText.Height, alignMentPoint1 = dxfText.AlignmentPoint1.ToString(), rotationAngle = dxfText.Rotation, }; if (dxfText.SimplifiedText == "JS-T5-001 ") { ktest.Add(dxfText); } cadEntities.Add(cADText); } if (typeof(DxfInsert) == entityGroups.GetType()) { dxfInsert = entityGroups as DxfInsert; kins.Add(dxfInsert); if (dxfInsert.Block != null) { ulong count; if (dxfInsert.Block != null) { count = dxfInsert.Block.Handle; } else { count = 0; } CADInsert cADInsert = new CADInsert(); cADInsert.parentHandle = dxfInsert.OwnerObjectSoftReference.Handle; cADInsert.type = dxfInsert.GetType().Name; cADInsert.transform = dxfInsert.Transform.DebugString; cADInsert.insertPoint = dxfInsert.InsertionPoint.ToString(); cADInsert.rotationAngle = dxfInsert.Rotation; cADInsert.insertName = dxfInsert.Block.Name; cADInsert.nowHandle = count; cADInsert.insertScale = dxfInsert.ScaleFactor.ToString(); cadEntities.Add(cADInsert); FindEntities(dxfInsert.Block.Entities); } } if (typeof(DxfAttributeDefinition) == entityGroups.GetType()) { dxfAttributeDefinition = entityGroups as DxfAttributeDefinition; //Console.WriteLine(dxfAttributeDefinition); } if (typeof(DxfDimension.Linear) == entityGroups.GetType()) { Console.WriteLine(11111); } } }
public static Polyline ToPolyline(this DxfLwPolyline poly) { return(new Polyline(poly.Vertices.Select(v => v.ToVertex(poly.Elevation)), poly.GetEntityColor(), poly)); }
/// <summary> /// h 获取Frame最右边的点坐标,用来动态增加框体的宽度 /// </summary> /// <param name="vertices"></param> /// <returns></returns> public static Point2D getFrameRightX(DxfLwPolyline.VertexCollection vertices) { Point2D tempPoint2D = new Point2D(0, 0); for (int i = 0; i < vertices.Count; i++) { if (i == 0) { tempPoint2D = vertices[i].Position; } if (tempPoint2D.X <= vertices[i].Position.X && tempPoint2D.Y <= vertices[i].Position.Y) { tempPoint2D.X = vertices[i].Position.X; tempPoint2D.Y = vertices[i].Position.Y; } } return tempPoint2D; }
public static RawDetail LoadDxf(string path) { FileInfo fi = new FileInfo(path); DxfFile dxffile = DxfFile.Load(fi.FullName); RawDetail s = new RawDetail(); s.Name = fi.FullName; IEnumerable <DxfEntity> entities = dxffile.Entities.ToArray(); List <LineElement> elems = new List <LineElement>(); foreach (DxfEntity ent in entities) { switch (ent.EntityType) { case DxfEntityType.LwPolyline: { DxfLwPolyline poly = (DxfLwPolyline)ent; if (poly.Vertices.Count() < 2) { continue; } LocalContour points = new LocalContour(); foreach (DxfLwPolylineVertex vert in poly.Vertices) { points.Points.Add(new PointF((float)vert.X, (float)vert.Y)); } for (int i = 0; i < points.Points.Count; i++) { var p0 = points.Points[i]; var p1 = points.Points[(i + 1) % points.Points.Count]; elems.Add(new LineElement() { Start = p0, End = p1 }); } } break; case DxfEntityType.Arc: { DxfArc arc = (DxfArc)ent; List <PointF> pp = new List <PointF>(); if (arc.StartAngle > arc.EndAngle) { arc.StartAngle -= 360; } for (double i = arc.StartAngle; i < arc.EndAngle; i += 15) { var tt = arc.GetPointFromAngle(i); pp.Add(new PointF((float)tt.X, (float)tt.Y)); } var t = arc.GetPointFromAngle(arc.EndAngle); pp.Add(new PointF((float)t.X, (float)t.Y)); for (int j = 1; j < pp.Count; j++) { var p1 = pp[j - 1]; var p2 = pp[j]; elems.Add(new LineElement() { Start = new PointF((float)p1.X, (float)p1.Y), End = new PointF((float)p2.X, (float)p2.Y) }); } } break; case DxfEntityType.Circle: { DxfCircle cr = (DxfCircle)ent; LocalContour cc = new LocalContour(); for (int i = 0; i <= 360; i += 15) { var ang = i * Math.PI / 180f; var xx = cr.Center.X + cr.Radius * Math.Cos(ang); var yy = cr.Center.Y + cr.Radius * Math.Sin(ang); cc.Points.Add(new PointF((float)xx, (float)yy)); } for (int i = 1; i < cc.Points.Count; i++) { var p1 = cc.Points[i - 1]; var p2 = cc.Points[i]; elems.Add(new LineElement() { Start = p1, End = p2 }); } } break; case DxfEntityType.Line: { DxfLine poly = (DxfLine)ent; elems.Add(new LineElement() { Start = new PointF((float)poly.P1.X, (float)poly.P1.Y), End = new PointF((float)poly.P2.X, (float)poly.P2.Y) }); break; } case DxfEntityType.Polyline: { DxfPolyline poly = (DxfPolyline)ent; if (poly.Vertices.Count() < 2) { continue; } LocalContour points = new LocalContour(); for (int i = 0; i < poly.Vertices.Count; i++) { DxfVertex vert = poly.Vertices[i]; points.Points.Add(new PointF((float)vert.Location.X, (float)vert.Location.Y)); } for (int i = 0; i < points.Points.Count; i++) { var p0 = points.Points[i]; var p1 = points.Points[(i + 1) % points.Points.Count]; elems.Add(new LineElement() { Start = p0, End = p1 }); } break; } default: throw new ArgumentException("unsupported entity type: " + ent); } ; } elems = elems.Where(z => z.Start.DistTo(z.End) > RemoveThreshold).ToList(); var cntrs2 = ConnectElements(elems.ToArray()); s.Outers.AddRange(cntrs2); if (s.Outers.Any(z => z.Points.Count < 3)) { throw new Exception("few points"); } return(s); }
private void button2_Click(object sender, EventArgs e) { //FecthDxfService fds = new FecthDxfService(); //OpenFileDialog openFileDialog = new OpenFileDialog(); //openFileDialog.ShowDialog(); //if (openFileDialog.FileName.Trim() != "") //{ // string path = openFileDialog.FileName; // fds.fs = new FileStream(path, FileMode.Open, FileAccess.Read); // fds.sr = new StreamReader(fds.fs); // fds.Read(); //} //DxfModel dxfModel = new DxfModel(); ////MessageBox.Show(fds.LineList.Count+""); //for (int i = 0; i < fds.LineList.Count;i++ ) //{ // DxfLine dxfLine = new DxfLine(); // LINE tempLine = new LINE(); // tempLine = fds.LineList[i]; // dxfLine.Start = new WW.Math.Point3D(tempLine.StartX, tempLine.StartY, 0); // dxfLine.End = new WW.Math.Point3D(tempLine.EndX, tempLine.EndY, 0); // dxfModel.Entities.Add(dxfLine); //} //DxfWriter.Write("test1.dxf", dxfModel, false); //DxfWriter.Write("test2.dxf", dxfModel, true); //DxfModel surcedfm = new DxfModel(); //surcedfm = DxfReader.Read("1.dxf"); //DxfModel s2 = new DxfModel(); //s2 = DxfReader.Read("2.dxf"); //DxfModel s3 = new DxfModel(); //s3= DxfReader.Read("3.dxf"); DxfModel s4 = new DxfModel(); s4 = DxfReader.Read("test.dxf"); DxfModel targetModel = new DxfModel(); //////// The ReferenceResolutionType.CloneMissing will result in the DASH_DOT line type created //////// above to also be cloned indirectly as a result of cloning the entities. CloneContext cloneContext = new CloneContext(targetModel, ReferenceResolutionType.CloneMissing); StreamWriter sw = new StreamWriter(@"EntityType.txt", true); //int x = 0; //int y = 0; //foreach (DxfEntity entity in surcedfm.Entities) //{ // DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext); // //sw.WriteLine(clonedEntity.EntityType); // string entityType=clonedEntity.EntityType; // targetModel.Entities.Add(clonedEntity); //} //foreach (DxfEntity entity in s2.Entities) //{ // DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext); // //sw.WriteLine(clonedEntity.EntityType); // targetModel.Entities.Add(clonedEntity); //} //foreach (DxfEntity entity in s3.Entities) //{ // DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext); // // sw.WriteLine(clonedEntity.EntityType); // targetModel.Entities.Add(clonedEntity); //} foreach (DxfEntity entity in s4.Entities) { DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext); sw.WriteLine(clonedEntity.EntityType); targetModel.Entities.Add(clonedEntity); } //cloneContext.ResolveReferences(); ////DxfWriter.Write("clone_source.dxf", sourceModel); DxfWriter.Write("clone_target1.dxf", targetModel); // DxfModel dxfM = new DxfModel(); // DxfArc arc = new DxfArc(); // arc.Center = new Point3D(-2d, 2d, 0); // arc.Radius=2d; // arc.StartAngle=0; // arc.EndAngle=Math.PI*0.3; // dxfM.Entities.Add(arc); //DxfWriter.Write("dxfArc.dxf", dxfM); DxfModel dxfModel = new DxfModel(); Point2D [] p=new Point2D[4]; p[0].X = 100; p[0].Y = 100; p[1].X = 1100; p[1].Y = 100; p[2].X = 1100; p[2].Y = 1100; p[3].X = 100; p[3].Y =1100; //p[4].X = 100; //p[4].Y = 100; DxfLwPolyline.VertexCollection vc = new DxfLwPolyline.VertexCollection(p); DxfLwPolyline testPolyLine = new DxfLwPolyline(p); testPolyLine.ConstantWidth = 10; testPolyLine.Plinegen = true; testPolyLine.Closed = true; dxfModel.Entities.Add(testPolyLine); DxfWriter.Write("test.dxf",dxfModel); DxfModel model = new DxfModel(); DxfSolid solid = new DxfSolid(); solid.Color = EntityColors.LightGreen; // A solid must have exactly 4 vertexes (the last 2 vertexes may be identical). solid.Points.Add(new Point3D(2d, 1d, 01)); solid.Points.Add(new Point3D(6d, 1d, 01)); // The 3rd and 4th vertexes are swapped always. solid.Points.Add(new Point3D(2d, 5d, 01)); solid.Points.Add(new Point3D(6d, 5d, 01)); model.Entities.Add(solid); DxfWriter.Write("DxfWriteSolidTest.dxf", model, false); Test1(); if (comboBox1.Text != null && comboBox2 != null && comboBox2.Text != null && comboBox3.Text != null && comboBox4.Text != null) { //List<string> list = new List<string>() {"1.dxf", "2.dxf", "3.dxf", "4.dxf" }; string frameName = "frame.dxf"; //MessageBox.Show(comboBox1.Text); List<string> list = new List<string>(); list.Add(comboBox1.Text); list.Add(comboBox2.Text); list.Add(comboBox3.Text); list.Add(comboBox4.Text); List<string> topViewList = new List<string>() { comboBox1.Text.Substring(0,1)+"E.dxf", comboBox2.Text.Substring(0,1)+"E.dxf", comboBox3.Text.Substring(0,1)+"E.dxf",comboBox4.Text.Substring(0,1)+"E.dxf"}; List<TextValue> valueList = new List<TextValue>() {new TextValue{text="产品代码:",value="0000001"}, new TextValue{text="项目名称:",value="0000001"} , new TextValue{text="设备描述:",value="0000002"} , new TextValue{text="买方:",value="石宏伟"} , new TextValue{text="订单号:",value="0000001"} , new TextValue{text="系列号:",value="0000001"} , new TextValue{text="时间:",value="2012-08-27"} , new TextValue{text="买方联系人:",value="0000001"} , new TextValue{text="易龙销售:",value="0000001"} , new TextValue{text="软件序列号:",value="0000001"}}; PuzzleService.puzzle(list, topViewList,valueList, frameName); } else { MessageBox.Show("请将排序图纸选全!"); } }
public void Visit(DxfLwPolyline polyline) { this.method_0((DxfEntity)polyline); }
public void Visit(DxfLwPolyline polyline) { this.bool_0 = true; }