public void colorize(MyDB2 mydb, List <System.Drawing.Color> cl) { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; if (hadColorized(mydb)) { editor.WriteMessage("\n 已经填充过颜色,不能重复填充"); } Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { bool ifContinue = calcSegment(); if (!ifContinue) { return; } calcClosedRegion(mydb, cl); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }
public bool hadColorized(MyDB2 mydb) { string dxfName = RXObject.GetClass(typeof(Region)).DxfName; ObjectId[] ids = My.Selection.GetObjectIDs(dxfName, ccLayerNamePrefix + "_" + mydb.Resolution); return(ids != null && ids.Length > 0); }
public void Contour(UserCmd cmd, string refrencePlan, double startElevation, double endElevation, double spacing, string whatCADData, string prefix) { this.cmd = cmd; MyDB2 mydb = cmd.mydb; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { //ObjectId[] objectId_ = CommandLineQuerries.SelectFaces(false); ObjectId[] faceIDs = Selection.getFaceIds(mydb.getFaceLayerName()); ContourLineComputation.string_0 = refrencePlan; CoordinateSystem coordinateSystem = CoordinateSystem.Global(); if (ContourLineComputation.string_0 == "U") { coordinateSystem = Conversions.GetUCS(); } if (ContourLineComputation.string_0 == "3P") { coordinateSystem = CommandLineQuerries.Specify3PSystem(); } coordinateSystem.Orthonormalize(); ContourLineComputation.startElevation = startElevation; ContourLineComputation.endElevation = Math.Max(ContourLineComputation.endElevation, ContourLineComputation.startElevation); bool flag = false; while (!flag) { ContourLineComputation.endElevation = endElevation; if (ContourLineComputation.startElevation > ContourLineComputation.endElevation) { editor.WriteMessage("\nStart elevation must be less or equal end elevation."); } else { flag = true; } } ContourLineComputation.spacing = spacing; ContourLineComputation.whatCADData = whatCADData;//CommandLineQuerries.InsertOnLayer_Current_Face_Elevation_Index(ContourLineComputation.whichLayer); if (ContourLineComputation.whatCADData != "F" && ContourLineComputation.whatCADData != "C") { ContourLineComputation.prefix = prefix;// CommandLineQuerries.SpecifyPrefixString(ContourLineComputation.prefix); } this.genContour2(faceIDs, coordinateSystem); } catch (System.Exception ex) { editor.WriteMessage("\n" + ex.Message + "\n"); } }
public void drawColorCulumn(MyDB2 mydb, List <System.Drawing.Color> cl) { ObjectId[] bidArray = Selection.getBoundarys(); Extents3d? ext = AcadUtil.getBound(bidArray); if (ext == null) { return; } Point3d leftBottom = new Point3d(ext.Value.MaxPoint.X + 10, ext.Value.MinPoint.Y, 0); for (int i = 0; i < cl.Count; i++) { //Rectangle3d rec=new Rectangle3d(new Point3d()) } }
static void genIntersection(MyDB2 mydb) { ObjectId[] boundary = Selection.getBoundarys(); ObjectId[] contours = Selection.getContours(LayerUtil.contourLayerName(mydb.Resolution)); Database db = HostApplicationServices.WorkingDatabase; using (Transaction tran = db.TransactionManager.StartTransaction()) { for (int i = 0; i < contours.Length; i++) { Polyline pl = tran.GetObject(contours[i], OpenMode.ForRead) as Polyline; for (int j = 0; j < boundary.Length; j++) { Polyline b = tran.GetObject(boundary[i], OpenMode.ForRead) as Polyline; double p = b.GetParameterAtPoint(pl.StartPoint); } } } }
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); } }
public static void Colorize(MyDB2 mydb, List <System.Drawing.Color> cl, FaceColorizeType type) { TEDictionary ted = mydb.TEDicList[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 { ObjectId[] faceIDs = Selection.getFaceIds(mydb.getFaceLayerName()); List <Triangle> triList = Conversions.ToCeometricAcDbTriangleList(faceIDs); Global.SuspendEpsilon(0.0, 0.0); //List<Triangle> triList = ted.TriangleList; Global.ResumeEpsilon(); double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; double range; if (type == FaceColorizeType.CenterZ) { range = ted.maxCZ - ted.minCZ; } else if (type == FaceColorizeType.MaxZ) { range = ted.maxMaxZ - ted.minMaxZ; } else { throw new System.Exception("无效的颜色类型"); } double sec = range / cl.Count; progressMeter.SetLimit(triList.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 < triList.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } int colorIndex; if (type == FaceColorizeType.CenterZ) { colorIndex = (int)Math.Floor((triList[i].Center.Z - ted.minCZ) / sec); } else if (type == FaceColorizeType.MaxZ) { colorIndex = (int)Math.Floor((Math.Max(Math.Max(triList[i].Vertex1.Z, triList[i].Vertex2.Z), triList[i].Vertex3.Z) - ted.minMaxZ) / sec); } else { throw new System.Exception("无效的类型"); } if (colorIndex >= cl.Count) { colorIndex = cl.Count - 1; } Face face = (Face)transaction.GetObject(triList[i].AcDbFace.ObjectId, (OpenMode)1); face.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); } }
public static Color getColorIndex(MyDB2 mydb, double elevation) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; return(getColorIndex(elevation, ted.maxMaxZ, ted.minMinZ, mydb.tcSetting.FaceColorList2.colorList)); }