Ejemplo n.º 1
0
        public static DTO.PolycurvePayload PointsToPolycurvePayload(List <Point3d> points, bool closed, double length, string layer)
        {
            DTO.Segment segment;
            var         polycurvePayload = new DTO.PolycurvePayload();

            polycurvePayload.Closed   = closed;
            polycurvePayload.Segments = new List <DTO.Segment>();

            for (int i = 0; i < points.Count - 2; i++)
            {
                segment             = new DTO.Segment();
                segment.SegmentType = SegmentType.Line;
                var linePayload = new DTO.LinePayload
                {
                    Coordinates = new List <double>
                    {
                        points[i].X,
                        points[i].Y,
                        points[i].Z,
                        points[i + 1].X,
                        points[i + 1].Y,
                        points[i + 1].Z
                    }
                };

                segment.Data = JsonConvert.SerializeObject(linePayload);
                polycurvePayload.Segments.Add(segment);
            }

            var lastIndex  = points.Count - 1;
            var properties = new Dictionary <string, dynamic>()
            {
                { "EndPoint", new DTO.PointPayload {
                      Value = new List <double> {
                          points[lastIndex].X, points[lastIndex].Y, points[lastIndex].Z
                      }
                  } },
                { "Layer", layer },
                { "Length", length },
                { "StartPoint", new DTO.PointPayload {
                      Value = new List <double> {
                          points[0].X, points[0].Y, points[0].Z
                      }
                  } },
            };

            polycurvePayload.Properties = properties;
            return(polycurvePayload);
        }
Ejemplo n.º 2
0
        public static DTO.PolycurvePayload ToPolycurvePayload(this Polyline polyline)
        {
            DTO.Segment segment;
            var         polycurvePayload = new DTO.PolycurvePayload();

            polycurvePayload.Closed   = polyline.Closed;
            polycurvePayload.Segments = new List <DTO.Segment>();

            for (int i = 0; i < polyline.NumberOfVertices; i++)
            {
                var segmentType = polyline.GetSegmentType(i);
                if (segmentType == Autodesk.AutoCAD.DatabaseServices.SegmentType.Arc)
                {
                    segment             = new DTO.Segment();
                    segment.SegmentType = SegmentType.Arc;
                    var arc = polyline.GetArcSegmentAt(i);
                    segment.Data = JsonConvert.SerializeObject(arc.ToArcPayload());
                    polycurvePayload.Segments.Add(segment);
                }
                else if (segmentType == Autodesk.AutoCAD.DatabaseServices.SegmentType.Line)
                {
                    segment             = new DTO.Segment();
                    segment.SegmentType = SegmentType.Line;
                    var line = polyline.GetLineSegmentAt(i);
                    segment.Data = JsonConvert.SerializeObject(line.ToLinePayload());
                    polycurvePayload.Segments.Add(segment);
                }
            }

            var properties = new Dictionary <string, dynamic>()
            {
                { "EndPoint", new DTO.PointPayload {
                      Value = new List <double> {
                          polyline.EndPoint.X, polyline.EndPoint.Y, polyline.EndPoint.Z
                      }
                  } },
                { "Layer", polyline.Layer },
                { "Length", polyline.Length },
                { "StartPoint", new DTO.PointPayload {
                      Value = new List <double> {
                          polyline.StartPoint.X, polyline.StartPoint.Y, polyline.StartPoint.Z
                      }
                  } },
            };

            polycurvePayload.Properties = properties;
            return(polycurvePayload);
        }