/// <summary>
        /// 创建填充实体
        /// </summary>
        /// <param name="poly">多线段参数</param>
        /// <param name="patternScale">填充比例</param>
        /// <returns>填充对象</returns>
        public static Hatch GetHatch(this Polyline poly, double patternScale = 1)
        {
            var pts = poly.GetVertexs();

            var distinctPts = pts.Distinct(new PointEqual()).ToList();

            var point2dCollection = new Point2dCollection();

            distinctPts.ForEach(m =>
            {
                point2dCollection.Add(new Point2d(m.X, m.Y));
            });

            point2dCollection.Add(new Point2d(distinctPts[0].X, distinctPts[0].Y));

            var hatch = new Hatch();

            var dbCollection = new DoubleCollection()
            {
                0
            };

            hatch.AppendLoop(HatchLoopTypes.Polyline, point2dCollection, dbCollection);

            hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");

            hatch.PatternScale = patternScale;

            hatch.ColorIndex = GColor.Green;

            hatch.EvaluateHatch(true);

            return(hatch);
        }
Esempio n. 2
0
        public static Extents2d Limits(Extents2d baseExtents, Point2dCollection points)
        {
            Extents2d ex = Limits(points);

            return(new Extents2d(new Point2d(Math.Min(ex.MinPoint.X, baseExtents.MinPoint.X), Math.Min(ex.MinPoint.Y, baseExtents.MinPoint.Y)),
                                 new Point2d(Math.Max(ex.MaxPoint.X, baseExtents.MaxPoint.X), Math.Max(ex.MaxPoint.Y, baseExtents.MaxPoint.Y))));
        }
Esempio n. 3
0
        internal static bool PointInPolyline(Point2dCollection points, Point2dCollection tests)
        {
            var count1 = points.Count;
            var count2 = tests.Count;
            var flag   = false;
            var index1 = 0;
            var num1   = count2 - 1;

            for (; index1 < count2; ++index1)
            {
                var point2d1 = tests[index1];
                var index2   = 0;
                var index3   = count1 - 1;
                for (; index2 < count1; index3 = index2++)
                {
                    var point2d2 = points[index2];
                    var num2     = point2d2.Y > point2d1.Y ? 1 : 0;
                    point2d2 = points[index3];
                    var num3 = point2d2.Y > point2d1.Y ? 1 : 0;
                    int num4;
                    if (num2 != num3)
                    {
                        var x1 = point2d1.X;
                        point2d2 = points[index3];
                        var x2 = point2d2.X;
                        point2d2 = points[index2];
                        var x3   = point2d2.X;
                        var num5 = x2 - x3;
                        var y1   = point2d1.Y;
                        point2d2 = points[index2];
                        var y2   = point2d2.Y;
                        var num6 = y1 - y2;
                        var num7 = num5 * num6;
                        point2d2 = points[index3];
                        var y3 = point2d2.Y;
                        point2d2 = points[index2];
                        var y4   = point2d2.Y;
                        var num8 = y3 - y4;
                        var num9 = num7 / num8;
                        point2d2 = points[index2];
                        var x4    = point2d2.X;
                        var num10 = num9 + x4;
                        num4 = x1 < num10 ? 1 : 0;
                    }
                    else
                    {
                        num4 = 0;
                    }
                    if (num4 != 0)
                    {
                        flag = !flag;
                    }
                }
                if (flag)
                {
                    return(flag);
                }
            }
            return(flag);
        }
Esempio n. 4
0
        /// <summary>
        ///     Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername,
                                                  bool isClosed, string patternName)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddPredefinedHatch");
            var id = ObjectId.Null;
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            var tm = db.TransactionManager;

            using (var hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                var buldge = 0.0;

                var loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (var pt in points)
                {
                    var bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddPredefinedHatch");
            return(id);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds the polyline.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="colorIndex">Index of the color.</param>
        /// <returns></returns>
        public static ObjectId AddPolyline(Transaction trans, Point2dCollection points, string layername, bool isClosed, int colorIndex)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddPolyline");
            ObjectId id = ObjectId.Null;
            var      db = Active.Database;
            var      tm = db.TransactionManager;

            using (Polyline pline = new Polyline())
            {
                pline.SetDatabaseDefaults();
                pline.Layer = layername;
                if ((colorIndex > 0) && (colorIndex < 256))
                {
                    pline.ColorIndex = colorIndex;
                }
                int    index  = 0;
                double buldge = 0.0;
                double width  = 0.0;

                foreach (Point2d pt in points)
                {
                    pline.AddVertexAt(index++, pt, buldge, width, width);
                }

                pline.Closed = isClosed;
                id           = AddToDatabase(db, pline, trans);
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddPolyline");
            return(id);
        }
Esempio n. 6
0
        //private static readonly ILog //_logger = LogManager.GetLogger(typeof(AcadDatabaseManager));

        /// <summary>
        ///     Adds the polyline.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <returns></returns>
        public static ObjectId AddPolyline(Transaction trans, Point2dCollection points, string layername, bool isClosed)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddPolyline");
            var id = ObjectId.Null;
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            var tm = db.TransactionManager;

            using (var pline = new Polyline())
            {
                pline.SetDatabaseDefaults();
                pline.Layer = layername;

                var index  = 0;
                var buldge = 0.0;
                var width  = 0.0;

                foreach (var pt in points)
                {
                    pline.AddVertexAt(index++, pt, buldge, width, width);
                }

                pline.Closed = isClosed;
                id           = AddToDatabase(db, pline, trans);
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddPolyline");
            return(id);
        }
Esempio n. 7
0
        public static IList <PolylineChildren> CreatePolylineChildren(ACADDB.ObjectIdCollection polylines)
        {
            IList <PolylineChildren> children = new List <PolylineChildren>();

            foreach (ACADDB.ObjectId polyoid in polylines)
            {
                ACADDB.ObjectIdCollection collection  = null;
                Point2dCollection         innerpoints = null;
                Point2dCollection         outerpoints = null;

                outerpoints = PlineToPoints(polyoid);
                collection  = new ACADDB.ObjectIdCollection();

                //Is Polyline within Outer Polyline
                foreach (ACADDB.ObjectId polyline in polylines)
                {
                    innerpoints = PlineToPoints(polyline);
                    if (PointUtilities.PointInPolyline(outerpoints, innerpoints))
                    {
                        collection.Add(polyline);
                    }
                }
                children.Add(new PolylineChildren(polyoid, collection));
            }


            return(children);
        }
Esempio n. 8
0
        /// <summary>
        /// Points the in polyline.
        /// </summary>
        /// <param name="boundary points">The points.</param>
        /// <param name="test points">The tests.</param>
        /// <returns><c>true</c> if inside, <c>false</c> otherwise.</returns>
        public static bool PointInPolyline(Point2dCollection points, Point2d test)
        {
            int nvert = points.Count;
            int tvert = 1;

            int  i, j, m, n;
            bool c = false;

            for (m = 0, j = tvert - 1; m < tvert; n = m++)
            {
                for (i = 0, j = nvert - 1; i < nvert; j = i++)
                {
                    if (((points[i].Y > test.Y) != (points[j].Y > test.Y)) &&
                        (test.X < (points[j].X - points[i].X) * (test.Y - points[i].Y) / (points[j].Y - points[i].Y) + points[i].X))
                    {
                        c = !c;
                    }
                }

                if (c)
                {
                    return(c);   //break if point is inside poly
                }
            }


            return(c);
        }
Esempio n. 9
0
        public static IList <Point3dCollection> ProcessLidarFile(IList <Point2dCollection> boundary, string filename, string path)
        {
            if (boundary == null)
            {
                throw new ArgumentNullException(nameof(boundary));
            }
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            Point3dCollection         lidarpoints     = CreateAllSurface.ReadPointCloudFile.ReadFile(path, filename);
            Point2dCollection         points2D        = PGA.AcadUtilities.AcadUtilities.ConvertTo2d(lidarpoints);
            IList <Point3dCollection> parsecollection = new List <Point3dCollection>();

            foreach (Point2dCollection pline in boundary)
            {
                Point3dCollection local = new Point3dCollection();
                for (int i = 0; i < points2D.Count; i++)
                {
                    if (PointUtilities.PointInPolyline(pline, points2D[i]))
                    {
                        local.Add(lidarpoints[i]);
                    }
                }
                parsecollection.Add(local);
            }
            return(parsecollection);
        }
Esempio n. 10
0
        /// <summary>
        /// Closests the point.
        /// </summary>
        /// <param name="point3D">The point3 d.</param>
        /// <param name="collection">The collection.</param>
        public static void ClosestPoint(Point3d point3D, Point2dCollection collection)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Editor ed = doc.Editor;
            //PromptPointResult ppr = ed.GetPoint("\nSpecify a point: ");
            //if (ppr.Status != PromptStatus.OK) return;
            //Point3d pt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
            Point3d pt = point3D;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                var closest          = btr
                                       .Cast <ObjectId>()
                                       .Select(id => tr.GetObject(id, OpenMode.ForRead) as Polyline)
                                       .Where(ent => ent != null)
                                       .Select(pline => new { pLine = pline, Dist = pt.DistanceTo(pline.GetClosestPointTo(pt, false)) })
                                       .Aggregate((l1, l2) => l1.Dist < l2.Dist ? l1 : l2);
                if (closest != null)
                {
                    closest.pLine.Highlight();
                    ed.WriteMessage("\nDistance = {0}", closest.Dist);
                }
                tr.Commit();
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Gets the name of the polyline.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="index">The index.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool GetPolylineName(Point2dCollection points, int index)
        {
            DatabaseLogs.FormatLogs(String.Format("Polyline Position= {0} - Vertices= {1}",
                                                  index, points.Count));

            return(true);
        }
Esempio n. 12
0
        private void CreateRectangle()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //新建矩形
            int count = 5;

            while (count-- > 1)
            {
                Point2d           bPoint = new Point2d(-100 * count, 100 * count);
                double            height = 20;
                double            width  = 10;
                Point2dCollection ptCol  = new Point2dCollection();
                ptCol.Add(new Point2d(bPoint.X, bPoint.Y));
                ptCol.Add(new Point2d(bPoint.X, bPoint.Y + height));
                ptCol.Add(new Point2d(bPoint.X + width, bPoint.Y + height));
                ptCol.Add(new Point2d(bPoint.X + width, bPoint.Y));

                Polyline pl = new Polyline();

                for (int i = 0; i < ptCol.Count; i++)
                {
                    pl.AddVertexAt(i, ptCol[i], 0, 0, 0);
                }

                pl.Closed = true;
                DBOperation.AddToModelSpace(pl);
            }
            ed.UpdateScreen();
        }
Esempio n. 13
0
        public static Point2dCollection SortPoint2D(Point2dCollection point2Ds)
        {
            var raw = point2Ds.ToArray();

            Array.Sort(raw, new Sort2DbyX());
            return(new Point2dCollection(raw));
        }
Esempio n. 14
0
            public override bool WorldDraw(AcGi.Drawable drawable, AcGi.WorldDraw wd)
            {
                var line = drawable as Line;

                if (line != null)
                {
                    //delta,这条直线所代表的三维向量
                    var vec = line.Delta.RotateBy(Math.PI / 2, Vector3d.ZAxis).GetNormal();
                    var pts = new Point3dCollection()
                    {
                        line.StartPoint + vec, line.EndPoint + vec,
                        line.EndPoint - vec, line.StartPoint - vec,
                    };
                    wd.Geometry.Polygon(pts);

                    var hatch = new Hatch();
                    var pts2d = new Point2dCollection();
                    var bulge = new DoubleCollection();

                    foreach (Point3d pt3d in pts)
                    {
                        pts2d.Add(new Point2d(pt3d.X, pt3d.Y));
                        bulge.Add(0);
                    }

                    hatch.AppendLoop(HatchLoopTypes.Default, pts2d, bulge);
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANGLE");

                    hatch.WorldDraw(wd);
                }

                return(base.WorldDraw(drawable, wd));
            }
Esempio n. 15
0
        addPoly(Point2dCollection pnt2ds, string nameLayer = "0", short color = 256)
        {
            ObjectId idPoly = ObjectId.Null;
            Polyline poly   = new Polyline();

            Layer.manageLayers(nameLayer);
            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTableRecord MS = Blocks.getBlockTableRecordMS();

                    int i = -1;
                    poly.SetDatabaseDefaults();
                    poly.Layer = nameLayer;
                    poly.Color = Color.FromColorIndex(ColorMethod.ByBlock, color);
                    foreach (Point2d pnt2d in pnt2ds)
                    {
                        i = ++i;
                        poly.AddVertexAt(i, pnt2d, 0, 0, 0);
                    }

                    idPoly = MS.AppendEntity(poly);
                    tr.AddNewlyCreatedDBObject(poly, true);
                    tr.Commit();
                }// end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 261");
            }

            return(idPoly);
        }
Esempio n. 16
0
        internal static bool PointInPolyline(Point2dCollection points, Point2dCollection tests)
        {
            int     nvert = points.Count;
            int     tvert = tests.Count;
            Point2d test  = new Point2d();

            int  i, j, m, n;
            bool Inside = false;

            for (m = 0, j = tvert - 1; m < tvert; n = m++)
            {
                test = tests[m];

                for (i = 0, j = nvert - 1; i < nvert; j = i++)
                {
                    if (((points[i].Y > test.Y) != (points[j].Y > test.Y)) &&
                        (test.X < (points[j].X - points[i].X) * (test.Y - points[i].Y) / (points[j].Y - points[i].Y) + points[i].X))
                    {
                        Inside = !Inside;
                    }
                }
                Debug.WriteLine(System.DateTime.Now + " Inside =" + Inside);
                if (Inside)
                {
                    return(Inside);
                }
            }


            return(Inside);
        }
Esempio n. 17
0
        public Point2dCollection GetPointCollection(Point3d point1, Point3d point2, Point3d w)
        {
            Point2dCollection pts1 = new Point2dCollection();
            Point2dCollection pts3 = new Point2dCollection();
            //double gap = Math.Abs(point2.X - point1.X) / 60;
            double gap = Math.Abs(w.X - point1.X) / 20;
            double a   = 0; //斜率

            for (int i = 0; i <= 20; i++)
            {
                pts1.Add(new Point2d(point1.X + i * gap, point1.Y));
            }
            Point3d temp = new Point3d();

            temp = point2;
            for (int i = 19; i >= 0; i--)
            {
                a = (pts1[i].Y - temp.Y) / (pts1[i].X - temp.X);
                pts3.Add(new Point2d(temp.X - gap, temp.Y + gap * Math.Abs(a)));
                temp = new Point3d(temp.X - gap, temp.Y + gap * Math.Abs(a), 0);
            }
            pts3.Add(new Point2d(point1.X, point1.Y));
            //pts3.Add(new Point2d(point2.X, point2.Y));
            return(pts3);
        }
Esempio n. 18
0
        /// <summary>
        /// 局部加载处理
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        public static bool PartialOpenDatabase(Database db)
        {
            if (db == null)
            {
                return(false);            //数据库未赋值,返回
            }
            //指定局部加载的范围
            Point2d           pt1 = Point2d.Origin;
            Point2d           pt2 = new Point2d(100, 100);
            Point2dCollection pts = new Point2dCollection(2)
            {
                pt1, pt2
            };
            //创建局部加载范围过滤器
            SpatialFilterDefinition filterDef = new SpatialFilterDefinition(pts, Vector3d.ZAxis, 0.0, 0.0, 0.0, true);
            SpatialFilter           sFilter   = new SpatialFilter();

            sFilter.Definition = filterDef;
            //创建图层过滤器,只加载Circle和Line层
            LayerFilter layerFilter = new LayerFilter();

            layerFilter.Add("Circle");
            layerFilter.Add("Line");
            //对图形数据库应用局部加载
            db.ApplyPartialOpenFilters(sFilter, layerFilter);
            if (db.IsPartiallyOpened) //判断图形数据库是否已局部加载
            {
                db.CloseInput(true);  //关闭文件输入
                return(true);         //局部加载成功
            }
            return(false);            //局部加载失败
        }
Esempio n. 19
0
        /// <summary>
        /// Adds the polyline.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="colorIndex">Index of the color.</param>
        /// <returns></returns>
        public static ObjectId AddPolyline(Transaction trans, Point2dCollection points, string layername, bool isClosed, int colorIndex)
        {
            //_logger.Debug("Start AddPolyline");
            ObjectId id = ObjectId.Null;

            Autodesk.AutoCAD.DatabaseServices.Database           db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Polyline pline = new Polyline())
            {
                pline.SetDatabaseDefaults();
                pline.Layer = layername;
                if ((colorIndex > 0) && (colorIndex < 256))
                {
                    pline.ColorIndex = colorIndex;
                }
                int    index  = 0;
                double buldge = 0.0;
                double width  = 0.0;

                foreach (Point2d pt in points)
                {
                    pline.AddVertexAt(index++, pt, buldge, width, width);
                }

                pline.Closed = isClosed;
                id           = AddToDatabase(db, pline, trans);
            }
            //_logger.Debug("End AddPolyline");
            return(id);
        }
Esempio n. 20
0
        /// <summary>
        ///     Removes duplicated points in the collection.
        /// </summary>
        /// <param name="pts">The instance to which the method applies.</param>
        /// <param name="tol">The tolerance to use in comparisons.</param>
        public static void RemoveDuplicate(this Point2dCollection pts, Tolerance tol)
        {
            var ptlst = new List <Point2d>();

            for (var i = 0; i < pts.Count; i++)
            {
                ptlst.Add(pts[i]);
            }
            ptlst.Sort((p1, p2) => p1.X.CompareTo(p2.X));
            for (var i = 0; i < ptlst.Count - 1; i++)
            {
                for (var j = i + 1; j < ptlst.Count;)
                {
                    if (ptlst[j].X - ptlst[i].X > tol.EqualPoint)
                    {
                        break;
                    }
                    if (ptlst[i].IsEqualTo(ptlst[j], tol))
                    {
                        pts.Remove(ptlst[j]);
                        ptlst.RemoveAt(j);
                    }
                    else
                    {
                        j++;
                    }
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Nearests the neighbor.
        /// </summary>
        /// <param name="testpoint2D">The testpoint2 d.</param>
        /// <param name="collection">The collection.</param>
        /// <returns>Point2d.</returns>
        public static Point2d NearestNeighbor(Point2d testpoint2D, Point2dCollection collection)
        {
            Point2d nearPoint2D = new Point2d();
            double  MaxDistance = 0;
            double  MinDistance = 100000;
            double  _Distance   = 0;

            foreach (var point in collection)
            {
                if (!point.Equals(testpoint2D))
                {
                    _Distance = Distance(testpoint2D, point);
                    if (_Distance > MaxDistance)
                    {
                        MaxDistance = _Distance;
                    }
                    if (_Distance < MinDistance && Math.Abs(MinDistance) > 0.0001)
                    {
                        MinDistance = _Distance;
                        nearPoint2D = point;
                    }
                }
            }
            return(nearPoint2D);
        }
Esempio n. 22
0
        /// <summary>
        /// Gets the polyline points.
        /// </summary>
        /// <param name="poid">The poid.</param>
        /// <returns>Point2dCollection.</returns>
        private static Point2dCollection GetPolylinePoints(Acaddb.ObjectId poid)
        {
            Point2dCollection points;

            using (Acaddb.Transaction tr = Active.StartTransaction())
            {
                points = new Point2dCollection();

                Acaddb.DBObject obj =
                    tr.GetObject(poid, Acaddb.OpenMode.ForRead);

                Acaddb.Polyline lwp = obj as Acaddb.Polyline;

                if (lwp != null)
                {
                    if (lwp.Closed)
                    {
                        int vn = lwp.NumberOfVertices;

                        for (int i = 0; i < vn; i++)
                        {
                            Point2d pt = lwp.GetPoint2dAt(i);
                            points.Add(pt);
                        }
                    }
                }
            }

            return(points);
        }
Esempio n. 23
0
        /// <summary>
        /// Modifies the polyline vertices.
        /// </summary>
        /// <param name="originalpoints">The originalpoints.</param>
        /// <param name="sortedpoints">The sortedpoints.</param>
        /// <param name="polylineoId">The polylineo identifier.</param>
        private static void ModifyPolylineVertices(Point2dCollection originalpoints, Point2dCollection sortedpoints, ObjectId polylineoId)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;


            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                var obj  = tr.GetObject(polylineoId, OpenMode.ForRead);
                var pl   = obj as Polyline;
                var flag = false;

                if (pl != null)
                {
                    pl.UpgradeOpen();
                    for (int i = 1; i < pl.NumberOfVertices - 1; i++)
                    {
                        flag = false;
                        for (int j = 0; j < sortedpoints.Count; j++)
                        {
                            if ((pl.GetPoint2dAt(i).Equals(sortedpoints[j])))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag == false)
                        {
                            pl.RemoveVertexAt(i);
                        }
                    }
                }
                tr.Commit();
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername, bool isClosed, string patternName)
        {
            //_logger.Debug("Start AddPredefinedHatch");
            ObjectId id = ObjectId.Null;

            Autodesk.AutoCAD.DatabaseServices.Database           db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Hatch hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                double buldge = 0.0;

                HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (Point2d pt in points)
                {
                    BulgeVertex bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            //_logger.Debug("End AddPredefinedHatch");
            return(id);
        }
 /// <summary>
 /// 通过二维点集合创建多段线
 /// </summary>
 /// <param name="pline">多段线对象</param>
 /// <param name="pts">多段线的顶点</param>
 public static void CreatePolyline(this Polyline pline, Point2dCollection pts)
 {
     for (int i = 0; i < pts.Count; i++)
     {
         //添加多段线的顶点
         pline.AddVertexAt(i, pts[i], 0, 0, 0);
     }
 }
Esempio n. 26
0
        public static void SimplifyPolylinesTest()
        {
            // Get the document
            var doc = Application.DocumentManager.MdiActiveDocument;
            IList <Point2dCollection> point2DCollections = new List <Point2dCollection>();
            IList <Point2dCollection> reducedCollection  = new List <Point2dCollection>();
            Point2dCollection         sortedCollection   = new Point2dCollection();
            double tolerance = 0.001;

            try
            {
                //Select Polyline Objects
                ObjectIdCollection collection = GetIdsByTypeTypeValue("POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3D");

                if (collection == null || collection.Count == 0)
                {
                    return;
                }

                using (DocumentLock doclock = doc.LockDocument())
                {
                    //Get Point Collection of Polylines
                    foreach (ObjectId obj in collection)
                    {
                        point2DCollections.Add(GetPoint2dFromPolylines(obj));

                        //Log Original Information
                        GetPolylineName(obj, collection.IndexOf(obj));
                    }

                    foreach (Point2dCollection pnt2DCol in point2DCollections)
                    {
                        int            index = point2DCollections.IndexOf(pnt2DCol);
                        Point2d[]      reducedPoints;
                        List <Point2d> list = new List <Point2d>(pnt2DCol.ToArray());

                        //Reduce Polylines
                        reducedPoints = DouglasPeuckerImplementation.DouglasPeuckerReduction(list, tolerance);
                        reducedCollection.Add(ConvertCollections(reducedPoints));


                        sortedCollection = SortModified(list, ConvertCollections(reducedPoints));
                        // Add Reduced Polylines to Database
                        //CreateNewPolyliness(null, sortedCollection);
                        ModifyPolylineVertices(sortedCollection, collection[index]);
                        //Store Polyline Information

                        //Log Polyline Information
                        GetPolylineName(sortedCollection, point2DCollections.IndexOf(pnt2DCol));
                        index++;
                    }
                }
            }
            catch (System.Exception ex)
            {
                DatabaseLogs.FormatLogs("SimplifyPolylines: " + ex.Message);
            }
        }
 public HatchNestingNode(CompositeCurve2d boundary, Extents2d extends,
                         Point2dCollection ptsColl, List <double> ptParams, Hatch hatch) : base(ptsColl)
 {
     Boundary = boundary;
     Extents  = extends;
     //base.Point2dCollection = ptsColl;
     this.ptParams = ptParams;
     Hatch         = hatch;
 }
Esempio n. 28
0
        public Polyline Poly3dToPolyLine(Polyline3d poly3d)
        {
            Point3dCollection point3dCollection = new Point3dCollection();

            poly3d.GetStretchPoints(point3dCollection);
            Point2dCollection pc = this.Point3dCollectionTo2d(point3dCollection);

            return(this.Poly2dTiPolyline(pc, 0.0));
        }
Esempio n. 29
0
        private static void RemoveVertexFromCurrentWipeout(ObjectId wipeoutId)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;

            var loop = true;

            while (loop)
            {
                using (doc.LockDocument())
                {
                    using (var tr = doc.TransactionManager.StartTransaction())
                    {
                        var wipeout = tr.GetObject(wipeoutId, OpenMode.ForWrite) as Wipeout;
                        if (wipeout != null)
                        {
                            var points3D = wipeout.GetVertices();
                            if (points3D.Count > 3)
                            {
                                var polyline = new Polyline();
                                for (var i = 0; i < points3D.Count; i++)
                                {
                                    polyline.AddVertexAt(i, new Point2d(points3D[i].X, points3D[i].Y), 0.0, 0.0, 0.0);
                                }

                                var pickedPt = ed.GetPoint($"\n{Language.GetItem(LangItem, "msg22")}:");
                                if (pickedPt.Status != PromptStatus.OK)
                                {
                                    loop = false;
                                }
                                else
                                {
                                    var pt     = polyline.GetClosestPointTo(pickedPt.Value, false);
                                    var param  = polyline.GetParameterAtPoint(pt);
                                    var vertex = Convert.ToInt32(Math.Truncate(param));
                                    polyline.RemoveVertexAt(vertex);
                                    var new2DPoints = new Point2dCollection();
                                    for (var i = 0; i < polyline.NumberOfVertices; i++)
                                    {
                                        new2DPoints.Add(polyline.GetPoint2dAt(i));
                                    }

                                    wipeout.SetFrom(new2DPoints, polyline.Normal);
                                }
                            }
                            else
                            {
                                // message
                                loop = false;
                            }
                        }

                        tr.Commit();
                    }
                }
            }
        }
Esempio n. 30
0
 /// <summary>Изменение точек полилинии</summary>
 /// <param name="points">Коллекция 2Д точек</param>
 /// <param name="bulges">Список выпуклостей</param>
 private void FillMainPolylineWithPoints(Point2dCollection points, IList <double> bulges)
 {
     _mainPolyline = new Polyline(points.Count);
     SetImmutablePropertiesToNestedEntity(_mainPolyline);
     for (var i = 0; i < points.Count; i++)
     {
         _mainPolyline.AddVertexAt(i, points[i], bulges[i], 0.0, 0.0);
     }
 }
Esempio n. 31
0
 public static Hatch CreateHatch(this List<Point2d> pts)
 {
     pts = pts.DistinctPoints();
     var ptCol = new Point2dCollection(pts.ToArray());
     ptCol.Add(pts[0]);
     var dCol = new DoubleCollection(new double[pts.Count]);
     var h = new Hatch();
     h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
     h.AppendLoop(HatchLoopTypes.Default, ptCol, dCol);
     h.EvaluateHatch(false);
     return h;
 }
Esempio n. 32
0
        public static Curve2dCollection To2dCurve(this Grevit.Types.Component curve)
        {
            Curve2dCollection curveArray = new Curve2dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                curveArray.Add(new Line2d(baseline.from.ToPoint2d(), baseline.to.ToPoint2d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc baseline = (Grevit.Types.Arc)curve;
                curveArray.Add(new CircularArc2d(baseline.center.ToPoint2d(), baseline.radius, baseline.start, baseline.end, Vector2d.XAxis, true));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                curveArray.Add(new CircularArc2d(baseline.a.ToPoint2d(), baseline.c.ToPoint2d(), baseline.b.ToPoint2d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count - 1; i++)
                {
                    curveArray.Add(new Line2d(baseline.points[i].ToPoint2d(), baseline.points[i + 1].ToPoint2d()));
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s = (Grevit.Types.Spline)curve;
                Point2dCollection points = new Point2dCollection();
                foreach (Grevit.Types.Point p in s.controlPoints) points.Add(p.ToPoint2d());
                DoubleCollection dc = new DoubleCollection();
                foreach (double dbl in s.weights) dc.Add(dbl);
                NurbCurve2d sp = new NurbCurve2d(s.degree, new KnotCollection(), points, dc, s.isPeriodic);
                curveArray.Add(sp);
            }

            return curveArray;
        }
Esempio n. 33
0
        public void testpara(ListView mylist)
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DocumentLock loc = acDoc.LockDocument();
            Polyline test = new Polyline();

            using (loc)
            {
                Database acCurDb = acDoc.Database;
                PromptPointOptions pPtOpts = new PromptPointOptions(" 점을 입력하세요");
                PromptPointResult pPtRes = acDoc.Editor.GetPoint(pPtOpts);// PromptPointResult pPtRes = acDoc.Editor.GetPoint(pPtOpts); // 점을 사용자에게 가져온다
                Point2dCollection ptStart = new Point2dCollection(); // Point3d 의 배열형이라 생각하면 쉽다.

                pPtOpts.BasePoint = pPtRes.Value; // 기준점 (점선)
                pPtOpts.UseBasePoint = true;

                //pPtOpts.UseDashedLine = true;
                int count = 0; // 점갯수 count

                ptStart.Add(new Point2d(pPtRes.Value.X, pPtRes.Value.Y));

                while (pPtRes.Status == PromptStatus.OK) // 사용자한테 받는값이 있을때까지
                {
                    if (pPtRes.Status == PromptStatus.Cancel) { return; } // 캔슬시 리턴
                    pPtOpts.BasePoint = pPtRes.Value;
                    pPtOpts.Message = " 점을 입력하세요"; // ㅇㅇ
                    pPtRes = acDoc.Editor.GetPoint(pPtOpts);  // 사용자에게 점값을 받아온다

                    ptStart.Add(new Point2d(pPtRes.Value.X, pPtRes.Value.Y)); // 그값을 콜렉션에다가 배열로 저장
                    count++;

                }

                test.SetDatabaseDefaults(); // 폴리라인 초기화(버튼 두번누르면 초기화 안되므로)

                for (int i = 0; i < count; i++)
                {
                    test.AddVertexAt(i, ptStart[i], 0, 0, 0);
                }

                //          test.Closed = true; // 폴리라인을 폐합선으로 만들어줌 (도형)
                //

                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) // 트랜잭션으로 묵어줌 라인그리기 위해서
                {
                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                 OpenMode.ForRead) as BlockTable;

                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                    OpenMode.ForWrite) as BlockTableRecord;

                    acBlkTblRec.AppendEntity(test); // 폴리라인을 블럭테이블 레코드에 그려준다.
                    acTrans.AddNewlyCreatedDBObject(test, true);//디비 데이터에 넣어줌
                    acTrans.Commit(); // 트랜잭션 실행
                }

            }
            Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen(); // 화면 한번 업뎃 해주고

            Alignment al = this.CreateAlign(test); // 만들어논 메소드를 이용해서 만들어진 평면선형 클래스의 변수값을 가져온다.

                int temp=0;

                temp = 0;
                foreach(AlignmentEntity myAe in al.Entities) //  일반 라인과 호의 순서가 맞진 않지만 정보는 다 맞음
                {                                                   ///추후에 정교한 작업 필요할듯
                    temp++;
                    string msg1 = "";
                    mylist.BeginUpdate();
                    ListViewItem testLvi2 = new ListViewItem(string.Format("{0}",temp));   // 리스트뷰 값 넣어주는 부분
                    switch(myAe.EntityType)
                    {
                        case AlignmentEntityType.Line:
                            AlignmentLine myLine = myAe as AlignmentLine;
                            msg1 = myLine.StartPoint.ToString(); // 시작점
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myLine.EndPoint.ToString(); // 끝점
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myLine.Length.ToString(); // 길이
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myLine.StartStation.ToString(); // 시작 스테이션
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myLine.EndStation.ToString(); // 끝 스테이션
                            testLvi2.SubItems.Add(msg1);

                            mylist.Items.Add(testLvi2);
                            break;
                        case AlignmentEntityType.Arc:
                            AlignmentArc myArc = myAe as AlignmentArc;
                            msg1 = myArc.StartPoint.ToString(); // 시작점
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myArc.EndPoint.ToString(); // 끝점
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myArc.Length.ToString(); // 길이
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myArc.StartStation.ToString(); // 시작 스테이션
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myArc.EndStation.ToString(); // 끝 스테이션
                            testLvi2.SubItems.Add(msg1);
                            msg1 = myArc.Radius.ToString(); // r 값
                            testLvi2.SubItems.Add(msg1);

                            mylist.Items.Add(testLvi2);
                            break;
                        default:
                            mylist.Items.Add("");
                            break;
                    }

                    mylist.EndUpdate(); // 포문안에 beginupdata 가 있으므로 마찬가지로 안쪽에 위치해줘야한다.
                }
        }
Esempio n. 34
0
        // Get distance between two user selected points.
        public Double GetDistance()
        {
            Double dist = 0;

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //Prompt for user selection of points to calculate distance.
            PromptPointResult ppr;
            Point2dCollection colPt = new Point2dCollection();
            PromptPointOptions ppo = new PromptPointOptions("");

            //Prompt for first point
            ppo.Message = "\nSpecify mid of Leftmost Rack: ";
            ppr = ed.GetPoint(ppo);
            colPt.Add(new Point2d(ppr.Value.X, ppr.Value.Y));

            //Exit if the user presses ESC or cancels cmd
            if (ppr.Status == PromptStatus.Cancel) return 0;

            int count = 1;

            while (count <= 2)
            {
                //Prompt for next points
                switch (count)
                {
                    case 1:
                        ppo.Message = "\nSpecify mid of Center Rack: ";
                        break;
                    case 2:
                        ppo.Message = "\nSpecify mid of Rightmost Rack: ";
                        break;
                }
                //use the previous point as the base point
                ppo.UseBasePoint = true;
                ppo.BasePoint = ppr.Value;

                ppr = ed.GetPoint(ppo);
                colPt.Add(new Point2d(ppr.Value.X, ppr.Value.Y));

                if (ppr.Status == PromptStatus.Cancel) return 0;

                //Increment
                count = count + 1;
            }

            //Create the polyline
            using (Polyline acPoly = new Polyline())
            {
                acPoly.AddVertexAt(0, colPt[0], 0, 0, 0);
                acPoly.AddVertexAt(1, colPt[1], 0, 0, 0);
                acPoly.AddVertexAt(2, colPt[2], 0, 0, 0);

                //Don't close polyline
                acPoly.Closed = false;

                //Query the length
                dist = acPoly.Length;

            }//Dispose of polyline.

            return dist; //returns the value of the distance.
        }