public void calcClosedRegion(MyDB2 mydb, List <System.Drawing.Color> cl) { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ObjectId layerId = LayerUtil.CreateLayer(ccLayerNamePrefix + "_" + mydb.Resolution, 127, false); List <TBPoint> ps = new List <TBPoint>(); List <Loop> boundarys = new List <Loop>(); ed.WriteMessage("contours.count:" + contours.Count); for (int i = 0; i < contours.Count; i++) { CContour2 contour = contours[i]; Loop closedBoundary = TraceBoundary.TraceBoundary.getClosedBoundary(contour.tbPLine, contour); if (closedBoundary != null) { boundarys.Add(closedBoundary); continue; } List <TBPLineSegment> segs = contour.tbPLine.SegmentedPlines; if (segs.Count <= 0) { continue; } List <Point3d> boundaryPoints = new List <Point3d>(); for (int j = 0; j < 2; j++)//两个方向都求边界,确保loop的elevation属于最小的contour的。 { Loop minBoundary = TraceBoundary.TraceBoundary.getMinBoundary(segs[0], contour); if (minBoundary == null) { //ed.WriteMessage(""); continue; } //minBoundary.userData = contour; boundarys.Add(minBoundary); List <LoopSeg> loopsegs = minBoundary.segments; if (loopsegs == null) { continue; } } } /*for (int j = 0; j < originalBoundarys.Count; j++) * { * Loop minBoundary = * TraceBoundary.TraceBoundary.getMinBoundary(originalBoundarys[j].segmentedPlines[0]); * boundarys.Add(minBoundary); * }*/ for (int k = 0; k < boundarys.Count - 1; k++) { try { Loop boundary = boundarys[k]; TraceBoundary.TraceBoundary.calcAllInnerLoop(boundary, boundarys); //TraceBoundary.TraceBoundary.calcAllInnerLoop(boundary, boundarys.GetRange(k+1,boundarys.Count-k-1)); //TraceBoundary.TraceBoundary.calcNeighbourInnerLoop(boundary); //CContour2 contour = boundary.userData as CContour2; //Color color = ColorizeBase.getColorIndex(mydb, contour.elevation); //Region region = MyRegion.NewRegion(MyConvert.toDBObjects(boundary), color); } catch (System.Exception ex) { ed.WriteMessage("\n192 k:" + k + "--" + ex.Message); } } for (int kk = 0; kk < boundarys.Count; kk++) { DBObjectCollection outerLoopObjs = null; try { Loop boundary = boundarys[kk]; //TraceBoundary.TraceBoundary.calcAllInnerLoop(boundary, boundarys); TraceBoundary.TraceBoundary.calcNeighbourInnerLoop(boundary); CContour2 contour = boundary.userData as CContour2; Color color = ColorizeBase.getColorIndex(mydb, contour.elevation); //Region region = MyRegion.NewRegion(MyConvert.toDBObjects(boundary), color); outerLoopObjs = boundary.getOuterLoopObjs(); Region region = MyRegion.NewRegion(outerLoopObjs, boundary.getInnerLoopObjsList(), color, layerId); outerLoopObjs = null; } catch (System.Exception ex2) { ed.WriteMessage("\n210 kk:" + kk + "--" + ex2.Message); if (outerLoopObjs != null) { ed.WriteMessage("\nobjs:\n"); for (int ee = 0; ee < outerLoopObjs.Count; ee++) { Polyline3d pl = outerLoopObjs[ee] as Polyline3d; if (pl != null) { ed.WriteMessage(pl.StartPoint.X + "," + pl.StartPoint.Y); ed.WriteMessage("\n"); ed.WriteMessage(pl.EndPoint.X + "," + pl.EndPoint.Y); ed.WriteMessage("\n"); } } } ed.WriteMessage("\n210 kk:" + kk + "--" + ex2.Message); } } //Region region = MyRegion.NewRegion(MyConvert.toDBObjects(segs)); //region.Color = ColorizeBase.getColorIndex(mydb, contour.elevation); }
public static void Colorize(MyDB2 mydb, List <System.Drawing.Color> cl) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; AssistContourDic assistContourDic = mydb.assistContourDics[mydb.Resolution]; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; double range = ted.maxMaxZ - ted.minCZ; double sec = range / cl.Count; progressMeter.SetLimit(assistContourDic.elevations.Count); progressMeter.Start("Colorizing property"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord arg_3D7_0 = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); int i = 0; while (i < assistContourDic.elevations.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } int colorIndex; double elevation = assistContourDic.elevations[i]; List <BASE.PLine> pls = assistContourDic.plines[i]; colorIndex = (int)Math.Floor((elevation - ted.minCZ) / sec); if (colorIndex >= cl.Count) { colorIndex = cl.Count - 1; } //Face face = (Face)transaction.GetObject(triList[i].AcDbFace.ObjectId, (OpenMode)1); for (int j = 0; j < pls.Count; j++) { PointSet ps = pls[j].GetVertices(); if (ps.Count <= 2) { continue; } Region h = MyRegion.NewRegion(ps[1]); if (h != null) { h.Color = Autodesk.AutoCAD.Colors.Color.FromColor(cl[colorIndex]); } } i++; continue; } transaction.Commit(); } progressMeter.Stop(); return; throw new System.Exception("Invalid target property"); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }