Пример #1
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);
        }
Пример #2
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();
        }
        /// <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);
        }
Пример #4
0
        private static Point2dCollection GetPointsForMainPolyline(Point3d insertionPoint, List <Point3d> middlePoints, Point3d endPoint)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var points = new Point2dCollection();

            points.Add(insertionPoint.ToPoint2d());
            middlePoints.ForEach(p => points.Add(p.ToPoint2d()));
            points.Add(endPoint.ToPoint2d());

            return(points);
        }
        // 多段线和直线求交点
        private void PolyIntersectWithLine(Polyline poly, Line line, double tol, ref Point3dCollection points)
        {
            Point2dCollection intPoints2d = new Point2dCollection();

            // 获得直线对应的几何类
            LineSegment2d geLine = new LineSegment2d(ToPoint2d(line.StartPoint), ToPoint2d(line.EndPoint));

            // 每一段分别计算交点
            Tolerance tolerance = new Tolerance(tol, tol);

            for (int i = 0; i < poly.NumberOfVertices; i++)
            {
                if (i < poly.NumberOfVertices - 1 || poly.Closed)
                {
                    SegmentType st = poly.GetSegmentType(i);
                    if (st == SegmentType.Line)
                    {
                        LineSegment2d geLineSeg = poly.GetLineSegment2dAt(i);
                        Point2d[]     pts       = geLineSeg.IntersectWith(geLine, tolerance);
                        if (pts != null)
                        {
                            for (int j = 0; j < pts.Length; j++)
                            {
                                if (FindPointIn(intPoints2d, pts[j], tol) < 0)
                                {
                                    intPoints2d.Add(pts[j]);
                                }
                            }
                        }
                    }
                    else if (st == SegmentType.Arc)
                    {
                        CircularArc2d geArcSeg = poly.GetArcSegment2dAt(i);
                        Point2d[]     pts      = geArcSeg.IntersectWith(geLine, tolerance);
                        if (pts != null)
                        {
                            for (int j = 0; j < pts.Length; j++)
                            {
                                if (FindPointIn(intPoints2d, pts[j], tol) < 0)
                                {
                                    intPoints2d.Add(pts[j]);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < intPoints2d.Count; i++)
            {
                points.Add(ToPoint3d(intPoints2d[i]));
            }
        }
Пример #6
0
        public void DrawStair(Point3d point, double w, double h, double ltw, double lth, double yc, double hd)
        {
            ptStart     = point;
            FloorWidth  = w;
            FloorHeight = h;
            LtW         = ltw;
            LtH         = lth;
            ExtW        = yc;
            ExtH        = hd;
            double num = Math.Ceiling(FloorWidth / LtW);

            LtH = FloorWidth / num;
            Point2d p0 = new Point2d(point.X - ExtW, point.Y);
            Point2d p1 = new Point2d(point.X, point.Y);

            pts.Add(p0); pts.Add(p1);
            Point2d ptl = Point2d.Origin;

            for (int i = 1; i < num; i++)
            {
                pts.Add(new Point2d(p0.X + (i - 1) * LtW, p0.Y + i * LtH));
                ptl = new Point2d(p0.X + i * LtW, p0.Y + i * LtH);
                pts.Add(ptl);
            }
            Point2d p3 = new Point2d(ptl.X + ExtW, ptl.Y);
            Point2d p4 = new Point2d(p3.X, p3.Y - ExtH);
            Point2d p5 = new Point2d(p4.X - ExtW, p4.Y);
            Point2d p6 = new Point2d(p1.X, p1.Y - ExtH);
            Point2d p7 = new Point2d(p0.X, p0.Y - ExtH);

            pts.Add(p3); pts.Add(p4); pts.Add(p5); pts.Add(p6); pts.Add(p7);

            pts2.Add(p1);
            for (int i = 1; i < num; i++)
            {
                pts2.Add(new Point2d(p0.X + i * LtW, p0.Y - (i - 1) * LtH));
                ptl = new Point2d(p0.X + i * LtW, p0.Y - i * LtH);
                pts2.Add(ptl);
            }
            Point2d p2_1 = new Point2d(ptl.X + ExtW, ptl.Y);

            pts2.Add(p2_1);
            Polyline pl = new Polyline();

            for (int i = 0; i < pts.Count; i++)
            {
                pl.AddVertexAt(i, pts[i], 0, 0, 0);
            }
            Polyline pl2 = new Polyline();

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

            // Point2d p2_2 = new Point2d(p2_1.X, p2_1.Y-ExtH);
        }
Пример #7
0
/*        public static void Main()
 *      {
 *          Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("ERROR! In Calcs.Main routine.");
 *      } */
        public static double areaPoly()
        {
            Document apdoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            PromptStringOptions strOpts = new PromptStringOptions("\nPlease enter the number of sides of the polyline: ");

            strOpts.AllowSpaces = false;
            PromptResult strRes   = apdoc.Editor.GetString(strOpts);
            int          maxCount = Int16.Parse(strRes.StringResult) + 1;

            PromptPointResult  pRes;
            Point2dCollection  pCol  = new Point2dCollection();
            PromptPointOptions pOpts = new PromptPointOptions("");

            pOpts.Message = "\nEnter the first point of the polyline.";
            pRes          = apdoc.Editor.GetPoint(pOpts);
            pCol.Add(new Point2d(pRes.Value.X, pRes.Value.Y));

            if (pRes.Status == PromptStatus.Cancel)
            {
                return(-1);
            }
            int i = 0;

            while (i < maxCount - 1)
            {
                pOpts.Message      = "\nEnter point number " + (i + 2) + ": ";
                pOpts.UseBasePoint = true;
                pOpts.BasePoint    = pRes.Value;

                pRes = apdoc.Editor.GetPoint(pOpts);
                pCol.Add(new Point2d(pRes.Value.X, pRes.Value.Y));
                if (pRes.Status == PromptStatus.Cancel)
                {
                    return(-1);
                }
                i++;
            }
            i = 0;
            using (Polyline poly = new Polyline())
            {
                while (i < maxCount)
                {
                    poly.AddVertexAt(i, pCol[i], 0, 0, 0);
                    i++;
                }
                poly.Closed = true;
                return(double.Parse(poly.Area.ToString()) / 144); //dividing by 144 to convert sq in to sq ft
            }
        }
Пример #8
0
        /// <summary>
        /// Sorts the specified collection.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <returns>Point2dCollection.</returns>
        public static Point2dCollection Sort(Point2dCollection collection)
        {
            IList <Point2d>   usedList  = new List <Point2d>();
            Point2dCollection pointsout = new Point2dCollection();
            Point2dCollection sorted    = new Point2dCollection();
            Point2d           last      = new Point2d();
            Point2d           first     = new Point2d();

            if (collection.Count < 2)
            {
                return(null);
            }

            if (collection.Count > 1)
            {
                first = collection[0];
                last  = collection[1];
            }

            //last item resorted
            foreach (var item in collection)
            {
                if (!item.Equals(last))
                {
                    pointsout.Add(item);
                }
            }
            pointsout.Add(last);
            //final sort nearestneighbor

            int count = 0;

            foreach (var item in pointsout)
            {
                if (count == 0)
                {
                    sorted.Add(item);
                    usedList.Add(item);
                }
                else
                {
                    sorted.Add(NearestNeighbor(sorted[count - 1], pointsout, usedList));
                    usedList.Add(sorted[count]);
                }
                count++;
            }
            sorted.Add(last);
            return(sorted);
        }
Пример #9
0
        /// <summary>
        /// 创建矩形
        /// </summary>
        /// <param name="pline">多段线对象</param>
        /// <param name="pt1">矩形的角点</param>
        /// <param name="pt2">矩形的角点</param>
        public static void CreateRectangle(this Polyline pline, Point2d pt1, Point2d pt2)
        {
            //设置矩形的4个顶点
            double            minX = Math.Min(pt1.X, pt2.X);
            double            maxX = Math.Max(pt1.X, pt2.X);
            double            minY = Math.Min(pt1.Y, pt2.Y);
            double            maxY = Math.Max(pt1.Y, pt2.Y);
            Point2dCollection pts  = new Point2dCollection();

            pts.Add(new Point2d(minX, minY));
            pts.Add(new Point2d(minX, maxY));
            pts.Add(new Point2d(maxX, maxY));
            pts.Add(new Point2d(maxX, minY));
            pline.CreatePolyline(pts);
            pline.Closed = true;//闭合多段线以形成矩形
        }
Пример #10
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);
        }
Пример #11
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));
            }
Пример #12
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();
                    }
                }
            }
        }
Пример #13
0
        public Point2dCollection Point3dCollectionTo2d(Point3dCollection pc)
        {
            Point2dCollection point2dCollection = new Point2dCollection();

            foreach (Point3d point3d in pc)
            {
                point2dCollection.Add(new Point2d(point3d.X, point3d.Y));
            }
            return(point2dCollection);
        }
Пример #14
0
        /// <summary>
        /// 三维点集合转二维点集合
        /// </summary>
        /// <param name="pc"></param>
        /// <returns></returns>
        public static Point2dCollection Point3dCollectionTo2d(Point3dCollection pc)
        {
            Point2dCollection pc2 = new Point2dCollection();

            foreach (Point3d pt in pc)
            {
                pc2.Add(new Point2d(pt.X, pt.Y));
            }
            return(pc2);
        }
Пример #15
0
        /// <summary>
        /// Converts the collections.
        /// </summary>
        /// <param name="original">The original.</param>
        /// <returns>Point2dCollection.</returns>
        private static Point2dCollection ConvertCollections(List <Point2d> original)
        {
            Point2dCollection _collection = new Point2dCollection();

            foreach (var pnts in original)
            {
                _collection.Add(pnts);
            }

            return(_collection);
        }
Пример #16
0
        public Oid CreateEntity(Database database)
        {
            var exterior = this.exterior;
            var ringType = exterior.Item;

            switch (ringType)
            {
            case LinearRingType lrt:
                DirectPositionListType dplt;
                if ((dplt = lrt.Items[0] as DirectPositionListType) != null)
                {
                    var points = dplt.GetPoints();

                    Point2dCollection points2d = new Point2dCollection();
                    DoubleCollection  dc       = new DoubleCollection();
                    //-1 beacuse the last point is a repetition of first
                    for (int i = 0; i < points.Length; i++)
                    {
                        points2d.Add(points[i].To2D());
                        dc.Add(0.0);
                    }

                    //Polyline pline = new Polyline(points.Length);
                    ////-1 beacuse the last point is a repetition of first
                    //for (int i = 0; i < points.Length - 1; i++)
                    //    pline.AddVertexAt(pline.NumberOfVertices, points[i].To2D(), 0, 0, 0);
                    //pline.Closed = true;
                    //Oid plineId = pline.AddEntityToDbModelSpace(database);

                    Hatch hatch = new Hatch();
                    hatch.Normal       = new Vector3d(0.0, 0.0, 1.0);
                    hatch.Elevation    = 0.0;
                    hatch.PatternScale = 1.0;
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    Oid hatchId = hatch.AddEntityToDbModelSpace(database);

                    hatch.AppendLoop(HatchLoopTypes.Default, points2d, dc);
                    hatch.EvaluateHatch(true);

                    return(hatchId);
                }
                else
                {
                    throw new System.Exception(
                              $"Unexpected type in PolygonType.exterior.Item.Items[0]: {lrt.Items[0].GetType().Name}");
                }

            case RingType rt:
                throw new System.NotImplementedException();

            default:
                throw new System.Exception($"Unexpected type in PolygonType.exterior.Item: {ringType.GetType().Name}");
            }
        }
Пример #17
0
        /// <summary>
        /// Converts the collections.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <returns>Point2dCollection.</returns>
        private static Point2dCollection ConvertCollections(Point2d[] points)
        {
            Point2dCollection _collection = new Point2dCollection();

            foreach (var pnts in points)
            {
                _collection.Add(pnts);
            }

            return(_collection);
        }
Пример #18
0
        /// <summary>
        /// Определение находится ли точка внутри полилинии по методу winding number algorithm
        /// Перегрузка для 3d точек. Точки рассматриваются в плане
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="pointsOfPolyline"></param>
        /// <returns></returns>
        public static bool PointIsInsidePolylineWindingNumber(Point3d pt, IEnumerable <Point3d> points3d)
        {
            Point2dCollection points = new Point2dCollection();

            foreach (Point3d p in points3d)
            {
                points.Add(new Point2d(p.X, p.Y));
            }

            return(PointIsInsidePolylineWindingNumber(new Point2d(pt.X, pt.Y), points));
        }
Пример #19
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;
 }
Пример #20
0
        /// <summary>
        /// Gets the extents into collection.
        /// </summary>
        /// <param name="extents">The extents.</param>
        /// <returns>Point2dCollection.</returns>
        public static Point2dCollection GetExtentsIntoCollection(Extents3d extents)
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                var max  = new Point2d(extents.MaxPoint.X, extents.MaxPoint.Y);
                var min  = new Point2d(extents.MinPoint.X, extents.MinPoint.Y);
                var minY = new Point2d(min.X, max.Y);
                var maxX = new Point2d(max.X, min.Y);

                var pcoll = new Point2dCollection();
                pcoll.Add(min);
                pcoll.Add(maxX);
                pcoll.Add(max);
                pcoll.Add(minY);
                pcoll.Add(min);

                return(pcoll);
            }
        }
Пример #21
0
        private Polyline CreatePolyLineOfRectangle()
        {
            double            height = Convert.ToDouble(nudBeamHeight.Value);
            double            width  = Convert.ToDouble(nudBeamTopHeight.Value);
            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;

            return(pl);
        }
Пример #22
0
        public void TcGangJin()
        {
            this.double_0 = CAD.GetScale();
            CAD.CreateLayer("钢筋", 14, "continuous", -1, false, true);
            this.point2dCollection_0 = new Point2dCollection();
            this.point3d_1           = CAD.GetPoint("选择插入点: ");
            Point3d point3d;

            if (!(this.point3d_1 == point3d))
            {
                Point2dCollection point2dCollection = this.point2dCollection_0;
                Point2d           point2d;
                point2d..ctor(this.point3d_1.X, this.point3d_1.Y);
                point2dCollection.Add(point2d);
                Polyline polyline  = new Polyline();
                ObjectId objectId_ = default(ObjectId);
                for (;;)
                {
                    short num = checked ((short)(this.point2dCollection_0.Count - 1));
                    if (num >= 1)
                    {
                        Class36.smethod_64(objectId_);
                        polyline = new Polyline();
                        polyline.SetDatabaseDefaults();
                        short num2 = 0;
                        short num3 = num;
                        short num4 = num2;
                        for (;;)
                        {
                            short num5 = num4;
                            short num6 = num3;
                            if (num5 > num6)
                            {
                                break;
                            }
                            polyline.AddVertexAt((int)num4, this.point2dCollection_0[(int)num4], 0.0, 45.0 * this.double_0, 45.0 * this.double_0);
                            num4 += 1;
                        }
                        polyline.Layer = "钢筋";
                        objectId_      = Class36.smethod_92(polyline);
                    }
                    short num7 = this.GangJin();
                    if (num7 != 1)
                    {
                        break;
                    }
                    this.point3d_1 = this.point3d_2;
                    Point2dCollection point2dCollection2 = this.point2dCollection_0;
                    point2d..ctor(this.point3d_2.X, this.point3d_2.Y);
                    point2dCollection2.Add(point2d);
                }
            }
        }
Пример #23
0
        /// <summary>
        /// Extract the points of a Polyline2d
        /// </summary>
        /// <param name="aPolyline"></param>
        /// <returns>Point2dCollection</returns>
        public static Point2dCollection GetPointsFromPolyline(Polyline2d aPolyline)
        {
            var polyPts      = new Point2dCollection();
            var polySegments = new DBObjectCollection();

            aPolyline.Explode(polySegments);

            // Cycle through the segments
            for (var i = 0; i <= polySegments.Count - 1; i++)
            {
                // if segment is Line
                var line = polySegments[i] as Line;
                if (line != null)
                {
                    var tempLine = line;
                    polyPts.Add(new Point2d(tempLine.StartPoint.X, tempLine.StartPoint.Y));
                    polyPts.Add(new Point2d(tempLine.EndPoint.X, tempLine.EndPoint.Y));
                }
                // else if segment is Arc
                else
                {
                    var arc = polySegments[i] as Arc;
                    if (arc != null)
                    {
                        var tempArc = arc;
                        polyPts.Add(new Point2d(tempArc.StartPoint.X, tempArc.StartPoint.Y));
                        polyPts.Add(new Point2d(tempArc.EndPoint.X, tempArc.EndPoint.Y));
                    }
                    // else is something else - this must never happen
                    else
                    {
                        throw new Exception(
                                  "KojtoCAD Error - Can not find the type of this polyline segment. Not Arc nor Line.");
                    }
                }
            }
            RemoveDuplicate(polyPts);
            return(polyPts);
        }
Пример #24
0
        addPolygon(Point3d pnt3d, double radius, int numSides)
        {
            ObjectId          idPoly = ObjectId.Null;
            Point2dCollection pnts2d = new Point2dCollection();

            Point2d pnt2dCen  = new Point2d(pnt3d.X, pnt3d.Y);
            Point2d pnt2dBase = Geom.traverse_pnt2d(pnt2dCen, 3 * System.Math.PI / 2, radius);

            pnts2d.Add(pnt2dBase);

            double angle  = 2 * System.Math.PI / numSides;
            double length = 2 * radius * System.Math.Sin(angle / 2);

            for (int i = 0; i < numSides; i++)
            {
                pnt2dBase = pnt2dBase.traverse(angle * (i + 1), length);
                pnts2d.Add(pnt2dBase);
            }

            idPoly = Base_Tools45.Draw.addPoly(pnts2d);
            return(idPoly);
        }
Пример #25
0
        poly_pnt2dColl(Polyline poly)
        {
            Point2dCollection pnts2d = new Point2dCollection();
            Point3d           pnt3d;
            Point2d           pnt2d;

            for (int i = 0; i < poly.NumberOfVertices; i++)
            {
                pnt3d = poly.GetPoint3dAt(i);
                pnt2d = new Point2d(pnt3d.X, pnt3d.Y);
                pnts2d.Add(pnt2d);
            }
            return(pnts2d);
        }
Пример #26
0
        /// <summary>
        /// 创建多边形
        /// </summary>
        /// <param name="pline">多段线对象</param>
        /// <param name="centerPoint">多边形中心点</param>
        /// <param name="number">边数</param>
        /// <param name="radius">外接圆半径</param>
        public static void CreatePolygon(this Polyline pline, Point2d centerPoint, int number, double radius)
        {
            Point2dCollection pts   = new Point2dCollection(number);
            double            angle = 2 * Math.PI / number;//计算每条边对应的角度

            //计算多边形的顶点
            for (int i = 0; i < number; i++)
            {
                Point2d pt = new Point2d(centerPoint.X + radius * Math.Cos(i * angle), centerPoint.Y + radius * Math.Sin(i * angle));
                pts.Add(pt);
            }
            pline.CreatePolyline(pts);
            pline.Closed = true;//闭合多段线以形成多边形
        }
        public static List <Datas> Aecc_Material_ids(SelectionSet acSSet)
        {
            Document     acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database     acCurDb = acDoc.Database;
            Editor       ed      = acDoc.Editor;
            List <Datas> result  = new List <Datas>();

            using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                try
                {
                    for (int i = 0; i < acSSet.Count; i++)
                    {
                        MaterialSection mtrl = trans.GetObject(acSSet[i].ObjectId, OpenMode.ForRead) as MaterialSection;
                        //result.Add(feat.ObjectId);

                        var    aecObj    = acSSet[i].ObjectId.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Entity;
                        string stylename = aecObj.StyleName;
                        string mtrlname  = Regex.Split(aecObj.Name, "-")[1];
                        double area      = 0.0;


                        Curve            baseCurve = aecObj.BaseCurve;
                        BlockTable       table     = trans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                        BlockTableRecord model     = trans.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                        model.AppendEntity(baseCurve);
                        trans.AddNewlyCreatedDBObject(baseCurve, true);

                        SectionPointCollection sPts = mtrl.SectionPoints;
                        Point2dCollection      p2   = new Point2dCollection();
                        foreach (SectionPoint pt in sPts)
                        {
                            p2.Add(new Point2d(pt.Location.X, pt.Location.Y));
                        }
                        area = Calculate.Area(p2);

                        result.Add(new Datas {
                            Material = mtrlname, Area = Math.Round(area, 1)
                        });
                    }
                    return(result);
                }
                catch (System.Exception ex) { }

                trans.Commit();

                return(null);
            }
        }
Пример #28
0
        public Point2dCollection WritePoint2DCollection(MultiPoint multiPoint)
        {
            var points = new Point2dCollection();

            foreach (IGeometry geometry in multiPoint)
            {
                var point = geometry as Point;
                if (point == null)
                {
                    continue;
                }
                points.Add(this.WritePoint2D(point));
            }
            return(points);
        }
Пример #29
0
        /// <summary>
        /// 添加分段导线
        /// </summary>
        /// <param name="objectId"></param>
        /// <param name="lineLayerID"></param>
        /// <param name="color"></param>
        /// <param name="lineWidth"></param>
        private void AddPolyline(ObjectId objectId, ObjectId lineLayerID, CADColor color, double lineWidth)
        {
            var ptcol = new Point2dCollection();

            for (int i = 0; i < pline.NumberOfVertices; i++)
            {
                ptcol.Add(pline.GetPoint2dAt(i));
            }
            PublicMethod.Instance.EraseObject(objectId);

            dxObjIdList = new Dictionary <ObjectId, LateralLineData>();
            for (var i = 0; i < ptcol.Count - 1; i++)
            {
                var lineString = new LineString();
                var pl         = new Polyline();
                pl.LayerId  = lineLayerID;
                pl.Color    = color;
                pl.Linetype = "Continuous";

                var startPoint = ptcol[i];
                var endPoint   = ptcol[i + 1];

                pl.AddVertexAt(pl.NumberOfVertices, new Point2d(startPoint.X, startPoint.Y), 0, lineWidth, lineWidth);
                lineString.Points.Add(new ElectronTransferModel.Geo.Point(new[] { startPoint.X, startPoint.Y, 0 }));
                pl.AddVertexAt(pl.NumberOfVertices, new Point2d(endPoint.X, endPoint.Y), 0, lineWidth, lineWidth);
                lineString.Points.Add(new ElectronTransferModel.Geo.Point(new[] { endPoint.X, endPoint.Y, 0 }));
                var id = PublicMethod.Instance.ToModelSpace(pl);

                var angle = PublicMethod.Instance.GetAngle(new Point2d(startPoint.X, startPoint.Y),
                                                           new Point2d(endPoint.X, endPoint.Y));


                var lld = new LateralLineData
                {
                    lineString = lineString,
                    lineAngle  = angle
                };
                if (i == 0)
                {
                    lld.startObjID = id;
                }
                if (i == 1)
                {
                    lld.endObjID = id;
                }
                dxObjIdList.Add(id, lld);
            }
        }
Пример #30
0
        public static Hatch CreateHatch(List <Point2d> points, VisualOption opt)
        {
            Point2d[] pts = DistincPoints(points);
            // Штриховка
            var ptCol = new Point2dCollection(pts);

            ptCol.Add(points[0]);
            var dCol = new DoubleCollection(new double[points.Count]);

            var h = new Hatch();

            h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            SetEntityOpt(h, opt);
            h.AppendLoop(HatchLoopTypes.Default, ptCol, dCol);
            return(h);
        }
Пример #31
0
        private static void AddVertexToCurrentWipeout(ObjectId wipeoutId)
        {
            var doc  = Application.DocumentManager.MdiActiveDocument;
            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();

                            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 jig    = new AddVertexJig();
                            var result = jig.StartJig(polyline);
                            if (result.Status != PromptStatus.OK)
                            {
                                loop = false;
                            }
                            else
                            {
                                polyline.AddVertexAt(jig.Vertex() + 1, jig.PickedPoint(), 0.0, 0.0, 0.0);
                                var new2DPoints = new Point2dCollection();
                                for (var i = 0; i < polyline.NumberOfVertices; i++)
                                {
                                    new2DPoints.Add(polyline.GetPoint2dAt(i));
                                }

                                wipeout.SetFrom(new2DPoints, polyline.Normal);
                            }
                        }

                        tr.Commit();
                    }
                }
            }
        }
Пример #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;
        }
Пример #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 가 있으므로 마찬가지로 안쪽에 위치해줘야한다.
                }
        }
Пример #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.
        }