예제 #1
0
        public static void Touch(ObjectId[] polylineIds)
        {
            var database = polylineIds[0].Database;

            using (var tr = database.TransactionManager.StartTransaction())
            {
                foreach (var polylineId in polylineIds)
                {
                    var curve = tr.GetObject(polylineId, OpenMode.ForRead) as Curve;

                    // 读取CAD图元
                    var reader     = new DwgReader();
                    var lineString = reader.ReadGeometry(curve, tr) as LineString;
                    //lineString.Touches()

                    // 做出缓冲区
                    var geometry = LineStringSelfIntersectionsOp(lineString);

                    if (geometry.GeometryType == "Point")
                    {
                        var     writer = new DwgWriter();
                        DBPoint dbPt   = writer.WriteDbPoint(geometry as Point);
                        CadUtils.DrawPoint(tr, database, dbPt);
                    }
                }

                tr.Commit();
            }
        }
예제 #2
0
        public static void FindTouchedEdge(ObjectId[] polylineIds)
        {
            if (polylineIds.Length != 2)
            {
                return;
            }

            //var ids = CadUtils.FindAllPolylines(Application.DocumentManager.MdiActiveDocument);
            var database = Application.DocumentManager.MdiActiveDocument.Database;

            using (var tr = database.TransactionManager.StartTransaction())
            {
                var reader = new DwgReader();

                var entity1     = tr.GetObject(polylineIds[0], OpenMode.ForRead) as Curve;
                var lineString1 = reader.ReadCurveAsLineString(tr, entity1);
                lineString1.UserData = polylineIds[0];

                var entity2     = tr.GetObject(polylineIds[1], OpenMode.ForRead) as Curve;
                var lineString2 = reader.ReadCurveAsLineString(tr, entity2);
                lineString2.UserData = polylineIds[1];

                var isTouch = lineString1.Touches(lineString2);
                System.Diagnostics.Trace.WriteLine(isTouch);

                IGeometry intersections = lineString1.Intersection(lineString2);

                //IGeometry intersections = CommonUtils.GetIntersectionPoints(lineString, polygon1);
                if (intersections.Coordinates.Any())
                {
                    foreach (var Coordinate in intersections.Coordinates)
                    {
                        var dbpoint = new DBPoint(new Point3d(Coordinate.X, Coordinate.Y, 0));
                        CadUtils.DrawPoint(tr, database, dbpoint);
                    }

                    // Draw all
                    var d = new DBPoint(new Point3d(intersections.Coordinates[0].X, intersections.Coordinates[0].Y, 0));
                    CadUtils.DrawPoint(tr, database, d, 2);

                    var lastIndex = intersections.Coordinates[intersections.Coordinates.Length - 1];
                    var d1        = new DBPoint(new Point3d(lastIndex.X,
                                                            lastIndex.Y, 0));
                    CadUtils.DrawPoint(tr, database, d1, 2);
                }

                tr.Commit();
            }
        }