Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public List <Curve> GetCurves(Curve curve, double jd)
        {
            List <Curve> lstCurves = new List <Curve>();

            double totalLength = curve.GetDistanceAtParameter(curve.EndParam);

            if (totalLength < jd)
            {
                lstCurves.Add(curve);
                return(lstCurves);
            }
            double addLength = 0;

            Point3dCollection pt3dCol = new Point3dCollection();

            while (addLength < totalLength)
            {
                pt3dCol.Add(curve.GetPointAtDist(addLength));
                addLength += jd;
            }
            if (addLength != totalLength)
            {
                pt3dCol.Add(curve.GetPointAtDist(totalLength));
            }


            DBObjectCollection dbObjColl = curve.GetSplitCurves(pt3dCol);

            foreach (var item in dbObjColl)
            {
                lstCurves.Add((Curve)item);
            }

            dbObjColl.Dispose();

            return(lstCurves);
        }
Ejemplo n.º 3
0
        CoordinateList ReadCoordination(Polyline2d polyline2D, Transaction tr)
        {
            var coordinateList = new CoordinateList();

            if (polyline2D.PolyType == Poly2dType.SimplePoly)
            {
                foreach (var v in polyline2D)
                {
                    Vertex2d vertex = null;
                    if (v is ObjectId)
                    {
                        var id = (ObjectId)v;
                        if (id.IsValid)
                        {
                            vertex = tr.GetObject(id, OpenMode.ForRead) as Vertex2d;
                        }
                    }
                    else if (v is Vertex2d)
                    {
                        vertex = (Vertex2d)v;
                    }

                    if (vertex != null)
                    {
                        coordinateList.Add(this.ReadCoordinate(vertex.Position), this.AllowRepeatedCoordinates);
                    }
                }
            }
            else
            {
                var dBObjectCollection = new DBObjectCollection();
                polyline2D.Explode(dBObjectCollection);
                try
                {
                    foreach (var dBObject in dBObjectCollection)
                    {
                        if (dBObject is Arc)
                        {
                            var arc = (Arc)dBObject;
                            coordinateList.Add(this.GetTessellatedCurveCoordinates(arc), false);
                        }
                        else if (dBObject is Line)
                        {
                            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 (polyline2D.Closed)
            {
                coordinateList.Add(coordinateList[0]);
            }

            return(coordinateList);
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     _weldingArcs.Dispose();
     _weldingVertices.Dispose();
 }
Ejemplo n.º 5
0
        public static List <Polyline> RegionToPolylines(Database db, Transaction tr, Region reg,
                                                        Color color, bool willAddToModelSpace, bool needToConvertPolyline2d, ObjectId layerId)
        {
            var polylines = new List <Polyline>();
            var bt        = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
            var btr       = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

            if (reg != null && reg.IsNull == false)
            {
                // The resulting Polyline
                var p = new Polyline();

                // Explode Region -> collection of Curves
                var cvs = new DBObjectCollection();
                reg.Explode(cvs);

                // Create a plane to convert 3D coords
                // into Region coord system

                var pl = new Plane(new Point3d(0, 0, 0), reg.Normal);

                // Set common entity properties from the Region

                p.SetPropertiesFrom(reg);

                //check if exploded region is still a region. If yes, We also need to explode the childe region.
                bool hasRegion = false;
                foreach (DBObject obj in cvs)
                {
                    var region = obj as Region;
                    if (region != null)
                    {
                        hasRegion = true;
                        var subPolylines = RegionToPolylines(db, tr, region, color, willAddToModelSpace, needToConvertPolyline2d, layerId);
                        region.Dispose();
                        polylines.AddRange(subPolylines);
                    }
                }
                if (hasRegion)
                {
                    cvs.Dispose();
                    pl.Dispose();
                    return(polylines);
                }

                // For initial Curve take the first in the list

                var cv1 = cvs[0] as Curve;

                p.AddVertexAt(
                    p.NumberOfVertices,
                    cv1.StartPoint.Convert2d(pl),
                    BulgeFromCurve(cv1, false), 0, 0
                    );

                p.AddVertexAt(
                    p.NumberOfVertices,
                    cv1.EndPoint.Convert2d(pl),
                    0, 0, 0
                    );

                cvs.Remove(cv1);

                // The next point to look for

                Point3d nextPt = cv1.EndPoint;

                cv1.Dispose();

                // Find the line that is connected to
                // the next point

                // If for some reason the lines returned were not
                // connected, we could loop endlessly.
                // So we store the previous curve count and assume
                // that if this count has not been decreased by
                // looping completely through the segments once,
                // then we should not continue to loop.
                // Hopefully this will never happen, as the curves
                // should form a closed loop, but anyway...

                // Set the previous count as artificially high,
                // so that we loop once, at least.

                int prevCnt = cvs.Count + 1;
                while (cvs.Count > 0 && cvs.Count < prevCnt)
                {
                    prevCnt = cvs.Count;
                    foreach (Curve cv in cvs)
                    {
                        // If one end of the curve connects with the
                        // point we're looking for...

                        if (cv.StartPoint == nextPt ||
                            cv.EndPoint == nextPt)
                        {
                            // Calculate the bulge for the curve and
                            // set it on the previous vertex

                            double bulge = BulgeFromCurve(cv, cv.EndPoint == nextPt);
                            p.SetBulgeAt(p.NumberOfVertices - 1, bulge);

                            // Reverse the points, if needed

                            if (cv.StartPoint == nextPt)
                            {
                                nextPt = cv.EndPoint;
                            }
                            else
                            {
                                // cv.EndPoint == nextPt
                                nextPt = cv.StartPoint;
                            }

                            // Add out new vertex (bulge will be set next
                            // time through, as needed)

                            p.AddVertexAt(
                                p.NumberOfVertices,
                                nextPt.Convert2d(pl),
                                0, 0, 0
                                );

                            // Remove our curve from the list, which
                            // decrements the count, of course

                            cvs.Remove(cv);
                            cv.Dispose();
                            break;
                        }
                    }
                }
                if (cvs.Count >= prevCnt)
                {
                    // Error.
                    p.Dispose();
                }
                else
                {
                    // Once we have added all the Polyline's vertices,
                    // transform it to the original region's plane

                    p.TransformBy(Matrix3d.PlaneToWorld(pl));
                    if (layerId.IsValid)
                    {
                        p.LayerId = layerId;
                    }
                    p.Color = color;

                    // Extra checking if the polyline end point is same as start point. If yes, remove the end point.
                    var startPoint2d = p.GetPoint2dAt(0);
                    var endPoint2d   = p.GetPoint2dAt(p.NumberOfVertices - 1);
                    if (Math.Abs(startPoint2d.X - endPoint2d.X) < DistanceTolerance && Math.Abs(startPoint2d.Y - endPoint2d.Y) < DistanceTolerance)
                    {
                        double lastBulge = p.GetBulgeAt(p.NumberOfVertices - 2);
                        p.RemoveVertexAt(p.NumberOfVertices - 1);
                        p.SetBulgeAt(p.NumberOfVertices - 1, lastBulge);
                    }

                    // Make sure the polyline is closed.
                    if (!p.Closed)
                    {
                        p.Closed = true;
                    }

                    // 设置标高.
                    p.Elevation = 0.0;

                    if (p.Area < AreaTolerance)
                    {
                        p.Dispose();
                        return(polylines);
                    }

                    // Append our new Polyline to the database
                    if (willAddToModelSpace)
                    {
                        btr.UpgradeOpen();
                        btr.AppendEntity(p);
                        tr.AddNewlyCreatedDBObject(p, true);

                        //// 确保生成出来的polyline为顺时针方向
                        //GeometryUtils.EnsurePolylineClockWise(p.ObjectId);
                    }
                    pl.Dispose();
                    polylines.Add(p);
                    return(polylines);
                }

                pl.Dispose();
            }

            return(polylines);
        }