예제 #1
0
        public ILineString ReadLineString(Transaction tr, Polyline3d polyline3D)
        {
            var coordinateList = new CoordinateList();

            if (polyline3D.PolyType == Poly3dType.SimplePoly) // 0??
            {
                foreach (var v in polyline3D)
                {
                    PolylineVertex3d vertex = null;
                    if (v is ObjectId)
                    {
                        vertex = tr.GetObject((ObjectId)v, OpenMode.ForRead) as PolylineVertex3d;
                    }
                    else if (v is PolylineVertex3d)
                    {
                        vertex = (PolylineVertex3d)v;
                    }

                    if (vertex != null)
                    {
                        coordinateList.Add(this.ReadCoordinate(vertex.Position), this.AllowRepeatedCoordinates);
                    }
                }
            }
            else
            {
                var dBObjectCollection = new DBObjectCollection();
                polyline3D.Explode(dBObjectCollection);
                try
                {
                    foreach (var dBObject in dBObjectCollection)
                    {
                        var line = (Line)dBObject;
                        coordinateList.Add(this.ReadCoordinate(line.StartPoint), false);
                        coordinateList.Add(this.ReadCoordinate(line.EndPoint), false);
                    }
                }
                finally
                {
                    foreach (var dBObject in dBObjectCollection)
                    {
                        if (dBObject is IDisposable)
                        {
                            (dBObject as IDisposable).Dispose();
                        }
                    }
                }
                dBObjectCollection.Dispose();
            }

            if (polyline3D.Closed)
            {
                coordinateList.Add(coordinateList[0]);
            }
            if (coordinateList.Count > 1)
            {
                return(this.GeometryFactory.CreateLineString(coordinateList.ToCoordinateArray()));
            }
            return(LineString.Empty);
        }
예제 #2
0
        /// <summary>
        /// Extract the points of a Polyline3d
        /// </summary>
        /// <param name="aPolyline"></param>
        /// <returns>Point3dCollection</returns>
        public static Point3dCollection GetPointsFromPolyline(Polyline3d aPolyline)
        {
            var polyPts      = new Point3dCollection();
            var polySegments = new DBObjectCollection();

            aPolyline.Explode(polySegments);

            // Cycle through the segments
            for (var i = 0; i <= polySegments.Count - 1; i++)
            {
                // if segment is Line
                var line = polySegments[i] as Line;
                if (line != null)
                {
                    var tempLine = line;
                    polyPts.Add(new Point3d(tempLine.StartPoint.X, tempLine.StartPoint.Y, tempLine.StartPoint.Z));
                    polyPts.Add(new Point3d(tempLine.EndPoint.X, tempLine.EndPoint.Y, tempLine.EndPoint.Z));
                }
                // else if segment is Arc
                else
                {
                    var arc = polySegments[i] as Arc;
                    if (arc != null)
                    {
                        var tempArc = arc;
                        polyPts.Add(new Point3d(tempArc.StartPoint.X, tempArc.StartPoint.Y, tempArc.StartPoint.Z));
                        polyPts.Add(new Point3d(tempArc.EndPoint.X, tempArc.EndPoint.Y, tempArc.EndPoint.Z));
                    }
                    // else is something else - this must never happen
                    else
                    {
                        throw new Exception(
                                  "KojtoCAD Error - Can not find the type of this polyline segment. Not Arc nor Line.");
                    }
                }
            }
            RemoveDuplicate(polyPts);
            return(polyPts);
        }