Esempio n. 1
0
        public static void getPointsBetween2Point(Polyline3d pl, double startParam, double endParam, Point3dCollection vertexes)
        {
            int n = 0;

            while (true)
            {
                double nextP;
                if (Math.Ceiling(startParam) - startParam < 1e-10)
                {
                    nextP = Math.Ceiling(startParam) + (++n);
                }
                else
                {
                    nextP = Math.Ceiling(startParam) + (n++);
                }

                if (nextP - endParam > 1e-10)
                {
                    break;
                }
                else if (Math.Abs(nextP - endParam) <= 1e-10)
                {
                    break;
                }

                vertexes.Add(pl.GetPointAtParameter(nextP));
            }
        }
Esempio n. 2
0
        public double scanAngle()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            double   r       = 0;

            //using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
            //{
            //Polyline3d pl = trans.GetObject(acPline.ObjectId, OpenMode.ForRead) as Polyline3d;
            for (int i = 0; i < acPline.EndParam - 1; i++)
            {
                r += AngleUtil.scanAngle(acPline.GetPointAtParameter(i), acPline.GetPointAtParameter(i + 1), acPline.GetPointAtParameter(i + 2));
            }
            //}
            return(r);
        }
        public static IEnumerable <DistanceBetween2PolylinesSectionResult> CalculateDistanceBetween3dPolylines(Database database, ObjectId pl1Id, ObjectId pl2Id)
        {
            Curve3d curve1, curve2 = null;
            int     polyline1EndParam;

            Point3d[] parameterListPoints = null;
            double[]  parameterListLength = null;
            using (Transaction transAction = database.TransactionManager.StartTransaction())
            {
                object objectX1 = transAction.GetObject(pl1Id, OpenMode.ForRead);
                object objectX2 = transAction.GetObject(pl2Id, OpenMode.ForRead);

                //Get a list of 3D points in parameter order
                using (Polyline3d pl1 = (Polyline3d)objectX1)
                    using (Polyline3d pl2 = (Polyline3d)objectX2)
                    {
                        // We get curve here, its faster to get the parameters and
                        // point on a non database object
                        curve1              = pl1.GetGeCurve(new Tolerance(1e-10, 1e-10));
                        curve2              = pl2.GetGeCurve(new Tolerance(1e-10, 1e-10));
                        polyline1EndParam   = (int)pl1.EndParam;
                        parameterListPoints = new Point3d[polyline1EndParam + 1];
                        parameterListLength = new double[polyline1EndParam + 1];
                        for (int y = 0; y <= polyline1EndParam; y++)
                        {
                            parameterListPoints[y] = pl1.GetPointAtParameter(y);
                            parameterListLength[y] = pl1.GetDistanceAtParameter(y);
                        }
                    }

                // Initialize list with dimensions specified (speed)
                DistanceBetween2PolylinesSectionResult[] arrRes = new DistanceBetween2PolylinesSectionResult[polyline1EndParam + 1];

                //for (int i = 0; i <= polyline1EndParam; i++)
                Parallel.For(0, polyline1EndParam + 1, (i) =>
                {
                    Point3d pointOnCurve1, pointOnCurve2;
                    lock (_curveLock)
                    {
                        pointOnCurve1 = parameterListPoints[i];
                        pointOnCurve2 = curve2.GetClosestPointTo(pointOnCurve1).Point;
                    }

                    // Add result to array
                    lock (_arrayLock)
                        arrRes[i] = new DistanceBetween2PolylinesSectionResult(
                            parameterListLength[i],
                            pointOnCurve1.Z - pointOnCurve2.Z,
                            pointOnCurve1.T2d().GetDistanceTo(pointOnCurve2.T2d()),
                            pointOnCurve1.DistanceTo(pointOnCurve2),
                            pointOnCurve1, pointOnCurve2);
                });
                transAction.Commit();
                return(arrRes);
            }
        }
        public static Point3d FindClosestPoint(Transaction trans, ObjectId idA, ObjectId idB)
        {
            Polyline3d curveA = trans.GetObject(idA, OpenMode.ForRead) as Polyline3d;
            Polyline3d curveB = trans.GetObject(idB, OpenMode.ForRead) as Polyline3d;

            double  distance = double.MaxValue;
            Point3d result   = Point3d.Origin;

            for (double param = curveA.StartParam; param < curveA.EndParam; param += ((curveA.EndParam - curveA.StartParam) / 100))
            {
                Point3d pointOnA        = curveA.GetPointAtParameter(param);
                Point3d closestPointOnB = curveB.GetClosestPointTo(pointOnA, false);

                double distanceBetweenPoints = pointOnA.DistanceTo(closestPointOnB);
                if (distanceBetweenPoints < distance)
                {
                    distance = distanceBetweenPoints;
                    result   = pointOnA; // equals closestPointOnB
                }
            }

            return(result);
        }
Esempio n. 5
0
        //project to level 0 to find the intersect point
        static public void CheckElevationDifference()
        {
            string msg = string.Empty;

            double checkDistance = 0.55;

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            HostApplicationServices hs = HostApplicationServices.Current;
            string outputPath          = hs.FindFile(doc.Name, doc.Database, FindFileHint.Default);
            string logPath             = outputPath + "_log.log";

            System.IO.File.WriteAllText(logPath, msg);

            //get user input
            //select point input file
            ed.WriteMessage("Select the Excel file contains the door step points");
            string excelPath = FileOps.SelectFile();

            #region get Excel Sheet Name
            PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter Sheet Name: ");
            pStrOpts.AllowSpaces = true;
            PromptResult pStrRes = doc.Editor.GetString(pStrOpts);
            string       shtName = pStrRes.StringResult;
            #endregion

            List <Point3d> doorStepPts = Excel.getAllpoint(doc, excelPath, shtName);

            PromptEntityResult per = ed.GetEntity("Select polylines");
            ObjectId           oid = per.ObjectId;

            ObjectIdCollection oDBO     = new ObjectIdCollection();
            List <Polyline3d>  poly3ds  = new List <Polyline3d>();
            List <Polyline3d>  poly3ds0 = new List <Polyline3d>();

            if (per.Status == PromptStatus.OK)
            {
                Transaction tr = db.TransactionManager.StartTransaction();

                BlockTable       bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                DBObject objPick = tr.GetObject(oid, OpenMode.ForRead);
                Entity   objEnt  = objPick as Entity;
                string   sLayer  = objEnt.Layer.ToString();

                oDBO = CADops.SelectAllPolyline(sLayer);
                foreach (ObjectId id in oDBO)
                {
                    Polyline3d pl = new Polyline3d();
                    System.IO.File.AppendAllText(logPath, $"{id}\n");
                    poly3ds0.Add(CADops.CreatePolylineOnXYPlane(doc, id, ref pl));
                    poly3ds.Add(pl);
                }
            }

            List <Point3d> output = new List <Point3d>();
            List <string>  data   = new List <string>();
            if (poly3ds.Count() > 0)
            {
                Transaction tr = db.TransactionManager.StartTransaction();

                BlockTable       bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                using (tr)
                {
                    List <Vector3d> vectorsAlongPath = new List <Vector3d>();
                    List <Vector3d> vectors          = CADops.getVectors(doorStepPts, doc, ref vectorsAlongPath);

                    //foreach (Point3d pt in doorStepPts)
                    for (int i = 0; i < doorStepPts.Count(); i++)
                    {
                        Point3d pt = doorStepPts[i];

                        Point3d pt0 = new Point3d(pt.X, pt.Y, 0);

                        Vector3d v   = vectors[i].GetNormal() * 5;
                        Matrix3d mat = Matrix3d.Displacement(v);
                        Point3d  npt = pt0.TransformBy(mat);

                        v   = vectors[i].GetNormal() * -5;
                        mat = Matrix3d.Displacement(v);
                        Point3d npt2 = pt0.TransformBy(mat);

                        //create a 2d line in XY plane
                        Line ln = new Line(npt, npt2);

                        btr.AppendEntity(ln);
                        tr.AddNewlyCreatedDBObject(ln, true);

                        msg = $"pt => {pt.X}, {pt.Y}, {pt.Z}\n";

                        #region get intersect point from point to polyline
                        Point3d ptNearest = Point3d.Origin;
                        for (int j = 0; j < poly3ds0.Count(); j++)
                        {
                            Polyline3d p3d0 = poly3ds0[j];
                            Polyline3d p3d  = poly3ds[j];

                            Point3d ptTemp = new Point3d();
                            #region get the alignment object and find the nearest point to the nominated point

                            Point3dCollection pts3D = new Point3dCollection();
                            p3d0.IntersectWith(ln, Intersect.OnBothOperands, pts3D, IntPtr.Zero, IntPtr.Zero);

                            try
                            {
                                if (pts3D.Count > 0)
                                {
                                    double para = p3d0.GetParameterAtPoint(pts3D[0]);
                                    //ed.WriteMessage($"{pts3D[0]}, {para}\n");
                                    ptTemp = p3d.GetPointAtParameter(para);
                                }
                            }
                            catch { }

                            #region get the point with lower Z
                            if (ptNearest == Point3d.Origin)
                            {
                                ptNearest = ptTemp;
                            }
                            else
                            {
                                if (ptNearest.Z > ptTemp.Z)
                                {
                                    ptNearest = ptTemp;
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #endregion

                        msg += $"ptNearest: {ptNearest.X}, {ptNearest.Y}, {ptNearest.Z}\n";

                        try
                        {
                            double diff = ptNearest.Z - pt.Z;
                            if (Math.Abs(diff) <= checkDistance)
                            {
                                Point3d newPt = new Point3d(pt.X, pt.Y, ptNearest.Z + checkDistance);
                                output.Add(newPt);
                                data.Add($"{newPt.X},{newPt.Y},{newPt.Z}, less, {diff}, {ptNearest.Z}");
                                msg += $", Z diff: {diff} => less than {checkDistance} => {newPt.X}, {newPt.Y}, {newPt.Z}\n\n";
                            }
                            else
                            {
                                Point3d newPt = pt;
                                output.Add(newPt);
                                data.Add($"{newPt.X},{newPt.Y},{newPt.Z}, more, {diff}, {ptNearest.Z}");
                                msg += $", Z diff: {diff} => more than {checkDistance} => {newPt.X}, {newPt.Y}, {newPt.Z}\n\n";
                            }
                        }
                        catch { }

                        System.IO.File.AppendAllText(logPath, msg);
                    }
                    tr.Commit();
                }
            }
            Excel.createCSV(data, outputPath);
            ed.WriteMessage("\ncsv file has been created under path " + outputPath);
        }
Esempio n. 6
0
        public void divide()
        {
            this.SegmentedPlines = new List <TBPLineSegment>();
            ObjectId layerId = My.LayerUtil.CreateLayer("segment", 255, false);

            try
            {
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                /*using (Transaction tran = acCurDb.TransactionManager.StartTransaction())
                 * {
                 *  BlockTable bt = tran.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                 *  BlockTableRecord modelSpace = tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;*/
                if (intersectPoints.Count <= 0)
                {
                    return;
                }
                for (int i = 0; i < intersectPoints.Count - 1; i++)
                {
                    TBPoint p1 = intersectPoints[i];
                    TBPoint p2 = intersectPoints[i + 1];

                    Point3dCollection vertexes = new Point3dCollection();
                    //My.MyDBUtility.addPolyline3d(segmentedPl, layerId);
                    //ObjectId oid = modelSpace.AppendEntity(segmentedPl);
                    //tran.AddNewlyCreatedDBObject(segmentedPl, true);
                    vertexes.Add(p1.acPoint);
                    //segmentedPl.AppendVertex(vertex);
                    int n           = 0;
                    int vertexCount = 1;
                    while (true)
                    {
                        double nextP;
                        if (Math.Ceiling(p1.TempParam) - p1.TempParam < 1e-10)
                        {
                            nextP = Math.Ceiling(p1.TempParam) + (++n);
                        }
                        else
                        {
                            nextP = Math.Ceiling(p1.TempParam) + (n++);
                        }

                        if (nextP - p2.TempParam > 1e-10)
                        {
                            break;
                        }
                        else if (Math.Abs(nextP - p2.TempParam) <= 1e-10)
                        {
                            break;
                        }
                        //segmentedPl.AppendVertex(new PolylineVertex3d(acPline.GetPointAtParameter(nextP)));
                        vertexes.Add(acPline.GetPointAtParameter(nextP));
                        vertexCount++;
                    }
                    //segmentedPl.AppendVertex(new PolylineVertex3d(p2.acPoint));
                    vertexes.Add(p2.acPoint);
                    vertexCount++;

                    if (vertexCount >= 2)
                    {
                        Polyline3d     segmentedPl = new Polyline3d(Poly3dType.SimplePoly, vertexes, false);
                        TBPLineSegment tbpline     = new TBPLineSegment(segmentedPl, p1, p2);
                        //tbpline.StartPoint = p1;
                        //tbpline.EndPoint = p2;
                        this.SegmentedPlines.Add(tbpline);
                        //p1.SegmentedPLines.Add(tbpline);
                        //p2.SegmentedPLines.Add(tbpline);
                        p1.addSegment(tbpline);
                        p2.addSegment(tbpline);
                    }
                }
                if (this.isClosed || this.IsLooped)
                {
                    TBPoint p1 = intersectPoints[intersectPoints.Count - 1];

                    Point3dCollection vertexes = new Point3dCollection();
                    vertexes.Add(p1.acPoint);

                    My.PolylineUtil.getPointsBetween2Point(acPline, p1.TempParam, acPline.EndParam, vertexes);
                    vertexes.Add(acPline.StartPoint);

                    TBPoint p2 = intersectPoints[0];
                    My.PolylineUtil.getPointsBetween2Point(acPline, 0, p2.TempParam, vertexes);
                    vertexes.Add(p2.acPoint);

                    if (vertexes.Count >= 2)
                    {
                        Polyline3d     segmentedPl = new Polyline3d(Poly3dType.SimplePoly, vertexes, false);
                        TBPLineSegment tbpline     = new TBPLineSegment(segmentedPl, p1, p2);
                        this.SegmentedPlines.Add(tbpline);
                        p1.addSegment(tbpline);
                        p2.addSegment(tbpline);
                    }
                }


                //tran.Commit();
                //}
            }
            catch (System.Exception ex)
            {
            }
        }
Esempio n. 7
0
        ///<summary>
        /// Get the intersection points between this planar entity and a curve.
        ///</summary>
        ///<param name="cur">The curve to check intersections against.</param>
        ///<returns>An array of Point3d intersections.</returns>
        public static Point3d IntersectWith(Point3d pt, Vector3d vect, Polyline3d poly0, Polyline3d poly, double testWidth, Document doc)
        {
            Database db = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);

                string layerName = CreateAndAssignALayer(Setting.defaultLayerName);//incase if this layer not exist
                if (layerName == string.Empty)
                {
                    layerName = "0";
                }

                #region create a 2d line on XY plane in order to find the intersect point for on TBM centerline
                //create a 2d point
                Point3d pt0 = new Point3d(pt.X, pt.Y, 0);

                Vector3d v   = vect.GetNormal() * testWidth;
                Matrix3d mat = Matrix3d.Displacement(v);
                Point3d  npt = pt0.TransformBy(mat);

                v   = vect.GetNormal() * -testWidth;
                mat = Matrix3d.Displacement(v);
                Point3d npt1 = pt0.TransformBy(mat);

                //create a 2d line in XY plane and add to drawing, this use to intersect with TBM alignment, so I can find the point in TBM alignment to create circle
                Line ln = new Line(npt, npt1);
                ln.Layer = layerName;
                btr.AppendEntity(ln);
                tr.AddNewlyCreatedDBObject(ln, true);

                //get the alignment object and find the nearest point to the nominated point
                Point3dCollection pts3D = new Point3dCollection();

                Point3d pt_intersect_in_TBM = Point3d.Origin;
                try
                {
                    poly0.IntersectWith(ln, Intersect.OnBothOperands, pts3D, IntPtr.Zero, IntPtr.Zero);

                    if (pts3D.Count > 0)
                    {
                        Point3d p     = pts3D[0];
                        DBPoint db_pt = new DBPoint(p);
                        db_pt.Layer = layerName;
                        btr.AppendEntity(db_pt);
                        tr.AddNewlyCreatedDBObject(db_pt, true);

                        try
                        {
                            double para = poly0.GetParameterAtPoint(pts3D[0]);//this is where it will fail, don't know why!
                            //ed.WriteMessage($"{pts3D[0]}, {para}\n");
                            pt_intersect_in_TBM = poly.GetPointAtParameter(para);
                            return(pt_intersect_in_TBM);
                        }
                        catch
                        {
                            pt_intersect_in_TBM = poly.GetClosestPointTo(p, Vector3d.ZAxis, true);//when GetParameterAtPoint fail, this is should work. but use in caution!
                        }
                    }
                    #endregion
                }
                catch { }

                tr.Commit();

                return(pt_intersect_in_TBM);
            }
        }
        private void btn_CADtoKML_Click(object sender, EventArgs e)
        {
            Editor ed = cadSer.Application.DocumentManager.MdiActiveDocument.Editor;
            //两直线合并误差
            double error_len = Convert.ToDouble(tbx_minLineSegmentLength.Text.Trim());


            try
            {
                double centerLongitude = Convert.ToDouble(tbx_CentrelBL.Text.Trim());
                bool   is80            = cbx_Is80.Checked;

                double estDelta   = Convert.ToDouble(tbx_EastDelta.Text);
                double northDelta = Convert.ToDouble(tbx_NorthDelta.Text);


                Database db     = HostApplicationServices.WorkingDatabase;
                var      middoc = cadSer.Application.DocumentManager.MdiActiveDocument;

                List <LineStringKML> lineListKML = new List <LineStringKML>();
                List <TextKML>       textListKML = new List <TextKML>();


                ObjectId[] objectIdsArr = ed.GetSelection().Value.GetObjectIds();
                ed.WriteMessage("==================================================\n");
                // ed.WriteMessage(objectIds.Count.ToString() + "\n");
                var      doc_lock = middoc.LockDocument();
                DBObject dbo;

                //提取polyline line spline circel arc ellipse polyline3d mtext dbtext
                foreach (ObjectId tempObjectId in objectIdsArr)
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        dbo = trans.GetObject(tempObjectId, OpenMode.ForRead);
                        #region 所有类型
                        //if (dbo.GetType().Equals(typeof(Polyline)) || dbo.GetType().Equals(typeof(Line)) || dbo.GetType().Equals(typeof(Spline)) || dbo.GetType().Equals(typeof(Circle)) || dbo.GetType().Equals(typeof(Arc)) || dbo.GetType().Equals(typeof(Ellipse)) || dbo.GetType().Equals(typeof(Polyline3d)))
                        //{
                        //    Curve dbo_bR = (Curve)dbo;

                        //    double length = dbo_bR.GetDistanceAtParameter(dbo_bR.EndParam);
                        //    LineStringKML lineStringKML = new LineStringKML();

                        //    for (double i = 0; i <length; i+=error_len)
                        //    {
                        //        Point3d tmpPoint = dbo_bR.GetPointAtDist(i);

                        //        lineStringKML.Add(new zPointXY(tmpPoint.X, tmpPoint.Y));
                        //    }


                        //       Point3d tmpPoint_1 = dbo_bR.GetPointAtParameter(dbo_bR.EndParam);

                        //        lineStringKML.Add(new zPointXY(tmpPoint_1.X, tmpPoint_1.Y));



                        //    lineListKML.Add(lineStringKML);
                        //}
                        #endregion
                        if (dbo.GetType().Equals(typeof(Line)))
                        {
                            Curve dbo_bR = (Curve)dbo;


                            LineStringKML lineStringKML = new LineStringKML();
                            Point3d       tmpPoint_0    = dbo_bR.StartPoint;

                            lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));


                            Point3d tmpPoint_1 = dbo_bR.EndPoint;

                            lineStringKML.Add(new zPointXY(tmpPoint_1.X, tmpPoint_1.Y));

                            lineListKML.Add(lineStringKML);
                        }

                        if (dbo.GetType().Equals(typeof(Polyline)))
                        {
                            Polyline      dbo_bR        = (Polyline)dbo;
                            LineStringKML lineStringKML = new LineStringKML();
                            // foreach(var tmp in dbo_bR.para)
                            double length = dbo_bR.GetDistanceAtParameter(dbo_bR.EndParam);


                            for (int i = 0; i < dbo_bR.EndParam; i++)
                            {
                                // Point3d tmpPoint = dbo_bR.GetPointAtParameter(i);

                                if (dbo_bR.GetSegmentType(i) == SegmentType.Line)
                                {
                                    Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(i);
                                    lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                                }
                                else if (dbo_bR.GetSegmentType(i) == SegmentType.Arc)
                                {
                                    for (double isegment = i; isegment < i + 1; isegment += 0.05)
                                    {
                                        Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(isegment);
                                        lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                                    }
                                }
                            }

                            Point3d tmpPoint_1 = dbo_bR.GetPointAtParameter(dbo_bR.EndParam);

                            lineStringKML.Add(new zPointXY(tmpPoint_1.X, tmpPoint_1.Y));

                            if (dbo_bR.Closed)
                            {
                                Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(dbo_bR.StartParam);
                                lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                            }


                            lineListKML.Add(lineStringKML);
                        }

                        if (dbo.GetType().Equals(typeof(Circle)) || dbo.GetType().Equals(typeof(Arc)) || dbo.GetType().Equals(typeof(Ellipse)))
                        {
                            Curve dbo_bR = (Curve)dbo;

                            double        length        = dbo_bR.GetDistanceAtParameter(dbo_bR.EndParam);
                            LineStringKML lineStringKML = new LineStringKML();

                            for (double i = dbo_bR.StartParam; i < dbo_bR.EndParam; i += (dbo_bR.EndParam - dbo_bR.StartParam) / 20.0)
                            {
                                Point3d tmpPoint = dbo_bR.GetPointAtParameter(i);

                                lineStringKML.Add(new zPointXY(tmpPoint.X, tmpPoint.Y));
                            }


                            Point3d tmpPoint_1 = dbo_bR.GetPointAtParameter(dbo_bR.EndParam);

                            lineStringKML.Add(new zPointXY(tmpPoint_1.X, tmpPoint_1.Y));

                            if (dbo_bR.Closed)
                            {
                                Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(dbo_bR.StartParam);
                                lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                            }

                            lineListKML.Add(lineStringKML);
                        }


                        if (dbo.GetType().Equals(typeof(Polyline3d)))
                        {
                            Polyline3d    dbo_bR        = (Polyline3d)dbo;
                            LineStringKML lineStringKML = new LineStringKML();
                            if (dbo_bR.PolyType == Poly3dType.SimplePoly)
                            {
                                for (int i = 0; i < dbo_bR.EndParam; i++)
                                {
                                    Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(i);
                                    lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                                }
                            }
                            else
                            {
                                double length = dbo_bR.GetDistanceAtParameter(dbo_bR.EndParam);
                                for (double i = 0; i < length; i += error_len)
                                {
                                    Point3d tmpPoint = dbo_bR.GetPointAtDist(i);

                                    lineStringKML.Add(new zPointXY(tmpPoint.X, tmpPoint.Y));
                                }
                            }
                            Point3d tmpPoint_1 = dbo_bR.GetPointAtParameter(dbo_bR.EndParam);

                            lineStringKML.Add(new zPointXY(tmpPoint_1.X, tmpPoint_1.Y));

                            if (dbo_bR.Closed)
                            {
                                Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(dbo_bR.StartParam);
                                lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                            }
                            lineListKML.Add(lineStringKML);
                        }


                        if (dbo.GetType().Equals(typeof(Spline)))
                        {
                            Spline dbo_bR = (Spline)dbo;


                            double        length        = dbo_bR.GetDistanceAtParameter(dbo_bR.EndParam);
                            LineStringKML lineStringKML = new LineStringKML();

                            for (double i = 0; i < length; i += error_len)
                            {
                                Point3d tmpPoint = dbo_bR.GetPointAtDist(i);

                                lineStringKML.Add(new zPointXY(tmpPoint.X, tmpPoint.Y));
                            }


                            Point3d tmpPoint_1 = dbo_bR.GetPointAtParameter(dbo_bR.EndParam);

                            lineStringKML.Add(new zPointXY(tmpPoint_1.X, tmpPoint_1.Y));

                            if (dbo_bR.Closed)
                            {
                                Point3d tmpPoint_0 = dbo_bR.GetPointAtParameter(dbo_bR.StartParam);
                                lineStringKML.Add(new zPointXY(tmpPoint_0.X, tmpPoint_0.Y));
                            }
                            lineListKML.Add(lineStringKML);
                        }

                        if (dbo.GetType().Equals(typeof(DBText)))
                        {
                            DBText dbtext = (DBText)dbo;
                            // string name = dbtext.TextString;
                            // Point3d point3D = dbtext.Position;
                            TextKML tmpkml = new TextKML(dbtext.TextString, new zPointXY(dbtext.Position.X, dbtext.Position.Y));
                            textListKML.Add(tmpkml);
                        }
                        if (dbo.GetType().Equals(typeof(MText)))
                        {
                            MText dbtext = (MText)dbo;
                            // string name = dbtext.Text;
                            //Point3d point3D = dbtext.Location;
                            TextKML tmpkml = new TextKML(dbtext.Text.Replace('\r', ' '), new zPointXY(dbtext.Location.X, dbtext.Location.Y));
                            textListKML.Add(tmpkml);
                        }

                        trans.Commit();
                    }
                }

                doc_lock.Dispose();

                ed.WriteMessage("===============读取完成=======================\n");

                //foreach(var tmp in  lineListKML )
                //{
                //    zjyCAD.zPolylineCreate(tmp.pointList,"zjy_assiaaaaaaaaaaaa");
                //}

                //foreach(var tmp in textListKML)
                //{
                //    zjyCAD.zCreatText(tmp.text, tmp.pointXY, 10, 0.8, "zjy_assiaaaaaaaaaaaa");
                //}

                string        pmPath  = tbx_SaveKMLPath.Text.Trim();
                List <string> xmlhead = new List <string>()
                {
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
                    //  "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">",
                    " <kml xmlns=\"http://earth.google.com/kml/2.1\">",
                    "<Document>",
                    "<name>zjy</name>",
                    // "<open>1</open>",
                    // "<description>zjy生成</description>",
                    "<Style id=\"yellowLineGreenPoly\" >",
                    "   <LineStyle>",
                    "       <color>ff000000</color>",
                    "       <width>4</width>",
                    "   </LineStyle>",
                    "   </Style>",
                    "<Folder>",
                    "<name>zjy</name>",
                    "       <visibility>1</visibility>",
                };

                List <string> xmlend = new List <string>()
                {
                    "</Folder>",
                    "</Document>",
                    "</kml>"
                };
                //生成kml文件
                List <string> kmlFile = new List <string>();
                kmlFile.AddRange(xmlhead);

                //生成路线信息图像


                foreach (var tmp in lineListKML)
                {
                    List <string> roadList = new List <string>()
                    {
                        "   <Placemark>",
                        "       <styleUrl>#yellowLineGreenPoly</styleUrl>",
                        "       <LineString>",
                        "       <tessellate>1</tessellate>",
                        "       <coordinates>"
                    };
                    foreach (zPointXY linePoint in tmp.pointList)
                    {
                        zPointXY xy = linePoint;
                        if (is80)
                        {
                            xy = linePoint + new zPointXY(estDelta, northDelta);
                        }

                        zPointXY tmp_BL = zjyCAD.WGS84_XYToBL(xy, centerLongitude);

                        roadList.Add("      " + tmp_BL.y.ToString() + "," + tmp_BL.x.ToString() + ",0.0000");
                    }
                    roadList.Add("      </coordinates>");
                    roadList.Add("      </LineString>");
                    roadList.Add("  </Placemark>");
                    kmlFile.AddRange(roadList);
                }



                //生成标签信息
                List <string> roadBQList = new List <string>();
                foreach (var tmp in textListKML)
                {
                    zPointXY xy = tmp.pointXY;
                    if (is80)
                    {
                        xy = tmp.pointXY + new zPointXY(estDelta, northDelta);
                    }


                    zPointXY tmp_BL = zjyCAD.WGS84_XYToBL(xy, centerLongitude);
                    roadBQList.Add("    <Placemark>");
                    roadBQList.Add("        <name>" + tmp.text + "</name>");
                    roadBQList.Add("        <Point>");
                    roadBQList.Add("        <coordinates>" + tmp_BL.y.ToString() + "," + tmp_BL.x.ToString() + ",0.0000" + "</coordinates>");
                    roadBQList.Add("        </Point>");
                    // roadBQList.Add("        <markerStyle>-2</markerStyle>");
                    roadBQList.Add("     </Placemark>");
                }
                kmlFile.AddRange(roadBQList);



                kmlFile.AddRange(xmlend);
                if (!Directory.Exists(pmPath))
                {
                    Directory.CreateDirectory(pmPath);
                }

                File.WriteAllLines(pmPath + "/" + tbx_KMLfileName.Text.Trim(), kmlFile.ToArray());
            }

            catch
            {
                ed.WriteMessage("出错\n");
            }
        }