private static void SearchWalls(List <LineSegment3d> outLines, List <LineSegment3d> allLines) { WallInfor wallInfo = null; using (var tolerance = new Utils.SafeToleranceOverride()) { wallInfo = WallRecognizer.getWallinfors(outLines, allLines); } if (wallInfo == null) { return; } // Test Code! var visited = new HashSet <WallInfor>(); var database = Application.DocumentManager.MdiActiveDocument.Database; using (var transaction = database.TransactionManager.StartTransaction()) { var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(database); var modelspace = (BlockTableRecord)transaction.GetObject(modelspaceId, OpenMode.ForWrite); var color = Color.FromColorIndex(ColorMethod.ByAci, 4); // Cyan ObjectId layerId = LayerUtils.AddNewLayer(database, "temp-poly2", "Continuous", color); var currentInfo = wallInfo; var count = 0; while (currentInfo != null && currentInfo.outline != null) { if (visited.Contains(currentInfo)) { break; } var line = new Line(currentInfo.outline.StartPoint, currentInfo.outline.EndPoint); line.Color = color; line.LayerId = layerId; modelspace.AppendEntity(line); transaction.AddNewlyCreatedDBObject(line, add: true); foreach (var innerSeg in currentInfo.innerlines) { var innerLine = new Line(innerSeg.StartPoint, innerSeg.EndPoint); innerLine.Color = color; innerLine.LayerId = layerId; modelspace.AppendEntity(innerLine); transaction.AddNewlyCreatedDBObject(innerLine, add: true); } visited.Add(currentInfo); count++; currentInfo = currentInfo.next; if (currentInfo == wallInfo) { break; } } transaction.Commit(); } }
public static bool isPartOfWallinfor(LineSegment3d line, WallInfor wallInfor) { WallInfor tmpWallInfor = wallInfor; while (tmpWallInfor != null) { List <Point3d> points = new List <Point3d>(); if (tmpWallInfor.outline != null) { if (!points.Contains(tmpWallInfor.outline.StartPoint)) { points.Add(tmpWallInfor.outline.StartPoint); } if (!points.Contains(tmpWallInfor.outline.EndPoint)) { points.Add(tmpWallInfor.outline.EndPoint); } } if (tmpWallInfor.innerlines != null) { foreach (LineSegment3d innerline in tmpWallInfor.innerlines) { if (!points.Contains(innerline.StartPoint)) { points.Add(innerline.StartPoint); } if (!points.Contains(innerline.EndPoint)) { points.Add(innerline.EndPoint); } } } if (points.Contains(line.StartPoint) && points.Contains(line.EndPoint)) { return(true); } tmpWallInfor = tmpWallInfor.next; } return(false); }
public static WallInfor getWallinfors(List <LineSegment3d> outLines, List <LineSegment3d> allLines) { WallInfor wallInfor = new WallInfor(); // step1: get the biggest length of outline var index = 0; var length = outLines[index].Length; int size = outLines.Count; for (int i = 1; i < size; i++) { if (DoubleExtensions.Larger(outLines[i].Length, length)) { index = i; length = outLines[index].Length; } } var currentWallInfor = wallInfor; // step2: get the outline wall infor for (int i = 0; i < size; i++) { var line = outLines[(i + index) % size]; // skip the line if it is in part exist wall infor if (!isPartOfWallinfor(line, wallInfor)) { List <LineSegment3d> innerlines = WallRecognizer.getWallline(line, allLines); // set the wall infor currentWallInfor.outline = line; currentWallInfor.innerlines = innerlines; currentWallInfor.next = new WallInfor(); currentWallInfor = currentWallInfor.next; } } return(wallInfor); }