Exemplo n.º 1
0
        public static void TestSearchAllLoops()
        {
            var drawingDb = Application.DocumentManager.MdiActiveDocument.Database;
            var editor    = Application.DocumentManager.MdiActiveDocument.Editor;

            editor.WriteMessage("\n选择一条或几条曲线:\n");
            var result = editor.GetSelection();

            if (result.Status != PromptStatus.OK)
            {
                return;
            }

            var polylineids = result.Value.GetObjectIds();
            var polygons    = MinimalLoopSearcher2.GetAllLoopPolylines(polylineids, editor.Document);

            using (var transaction = drawingDb.TransactionManager.StartTransaction())
            {
                var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(drawingDb);
                var modelspace   = transaction.GetObject(modelspaceId, OpenMode.ForWrite) as BlockTableRecord;
                foreach (var polyline in polygons)
                {
                    polyline.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
                    modelspace.AppendEntity(polyline);
                    transaction.AddNewlyCreatedDBObject(polyline, true);
                }
                transaction.Commit();
            }
        }
Exemplo n.º 2
0
        bool AnalyzePolygonsUnionable(List <Point3d> sourcePolygon, List <Point3d> targetPolygon,
                                      out List <Point3d> unionPolygon)
        {
            unionPolygon = sourcePolygon;
            var unionResult = MinimalLoopSearcher2.ClipperBoolean(new List <List <Point3d> >()
            {
                sourcePolygon
            },
                                                                  new List <List <Point3d> >()
            {
                targetPolygon
            }, ClipType.ctUnion);

            if (unionResult.Count > 1)
            {
                if (unionResult.Count == 2)
                {
                    if ((PolygonIncludeSearcher.AreIdenticalCoordinates(sourcePolygon, unionResult[0]) ||
                         PolygonIncludeSearcher.AreIdenticalCoordinates(sourcePolygon, unionResult[1])))
                    {
                        return(false);
                    }
                }

                unionResult = unionResult
                              .OrderByDescending(it => ComputerGraphics.PolygonArea(it.ToArray()))
                              .ToList();
                var source = new List <List <Point3d> >()
                {
                    unionResult[0]
                };
                // 如果存在多于一个布尔运算结果的情况,需要分析他们是否有包含关系
                for (int i = 1; i < unionResult.Count; i++)
                {
                    var subUnionResult = MinimalLoopSearcher2.ClipperBoolean(
                        source, new List <List <Point3d> >()
                    {
                        unionResult[i]
                    }, ClipType.ctUnion);
                    if (subUnionResult.Count > 1 || subUnionResult.Count <= 0)
                    {
                        return(false);
                    }
                    source = subUnionResult;
                }

                unionResult = source;
            }

            if (unionResult.Count != 1)
            {
                return(false);
            }
            unionPolygon = unionResult[0];
            return(true);
        }
Exemplo n.º 3
0
        public static void TestSearchMinimumPolygons()
        {
            var drawingDb = Application.DocumentManager.MdiActiveDocument.Database;
            var editor    = Application.DocumentManager.MdiActiveDocument.Editor;

            editor.WriteMessage("\n选择一条或几条闭合曲线:\n");
            var result = editor.GetSelection();

            if (result.Status != PromptStatus.OK)
            {
                return;
            }
            var polylineids = result.Value.GetObjectIds();

            using (var tolerance = new SafeToleranceOverride(null, null))
                using (var transaction = drawingDb.TransactionManager.StartTransaction())
                {
                    var polylines = new List <Polyline>();
                    foreach (var polylineid in polylineids)
                    {
                        var polyline = transaction.GetObject(polylineid, OpenMode.ForRead) as Polyline;
                        polylines.Add(polyline.Clone() as Polyline);
                    }
                    Dictionary <Curve, List <Curve> > replaced = null;
                    var polygons     = MinimalLoopSearcher2.SearchMinimalPolygons(polylines, out replaced);
                    var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(drawingDb);
                    var modelspace   = transaction.GetObject(modelspaceId, OpenMode.ForWrite) as BlockTableRecord;
                    foreach (var polyline in polygons)
                    {
                        polyline.Layer = "dk";
                        polyline.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
                        modelspace.AppendEntity(polyline);
                        transaction.AddNewlyCreatedDBObject(polyline, true);
                    }
                    transaction.Commit();
                }
        }