123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- using GrxCAD.ApplicationServices;
- using GrxCAD.DatabaseServices;
- using GrxCAD.EditorInput;
- using System.Collections;
- using GrxCAD.Geometry;
-
- namespace HCTools
- {
- public struct points
- {
- public Point3d pt;
- public ObjectId objID;
- }
-
- class ElePtCheck
- {
- public static int blc;//比例尺
- public static string EleLayerName;//高程点图层名
-
- public double radius;//半径
- //public double length;//搜索半径
-
- int j = 0;//记录错误点个数
-
- //存放所有高程点数组
- public List<points> pointarrlist = new List<points>();
- //存放有问题的高程点数组
- public List<points> errorpointarrlist = new List<points>();
-
-
-
- /// <summary>
- /// 检查错误的高程点并画圆标记
- /// </summary>
- public void pointcheck()
- {
- double flagradius = 4.0 * blc / 1000;//画圆标记半径
-
- if (blc == 500)
- {
- radius = 1.5;
- }
- else if (blc == 1000)
- {
- radius = 2.5;
- }
- else if (blc == 2000)
- {
- radius = 4;
- }
- else if (blc == 5000)
- {
- radius = 10.5;
- }
- //外切圆半径
- //length = radius * Math.Pow(2, 0.5);
-
-
- //检查高程点与注记是否一致或为零
- check();
-
- //创建存放错误点的图层
- LayerControl layerscontrol = new LayerControl();
- string layname = "错误高程点";
- if (!layerscontrol.haslayername(layname))
- {
- colorgb col = new colorgb(255, 0, 255);
- layerscontrol.creatlayer(layname, col);
- layerscontrol.movelayertofront(layname);
- }
- else
- layerscontrol.movelayertofront(layname);
-
- //创建错误点标记的图层
- LayerControl layerscontrol1 = new LayerControl();
- string layname1 = "错误高程点标记";
- if (!layerscontrol1.haslayername(layname1))
- {
- colorgb col = new colorgb(0, 225, 255);
- layerscontrol1.creatlayer(layname1, col);
- layerscontrol1.movelayertofront(layname1);
- }
- else
- layerscontrol1.movelayertofront(layname1);
-
- Database database = HostApplicationServices.WorkingDatabase;
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable;
-
- for (int i = 0; i < errorpointarrlist.Count; i++)
- {
- BasicFunction functions = new BasicFunction();
- BlockReference blr= traction.GetObject(errorpointarrlist[i].objID,OpenMode.ForWrite)as BlockReference;
- blr.Layer = "错误高程点";
- functions.makeflag(errorpointarrlist[i].pt.X, errorpointarrlist[i].pt.Y, 0, flagradius, "错误高程点标记");
-
- Point3d p1 = new Point3d(errorpointarrlist[i].pt.X - radius, errorpointarrlist[i].pt.Y - radius, 0);
- Point3d p2 = new Point3d(errorpointarrlist[i].pt.X + radius, errorpointarrlist[i].pt.Y + radius, 0);
- TypedValue[] typedvalue = new TypedValue[2];
-
- typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, EleLayerName), 1);
-
- SelectionFilter filter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = editor.SelectCrossingWindow(p1, p2, filter);
-
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet set = psr.Value;
- ObjectId[] objs = new ObjectId[set.Count];
- objs = set.GetObjectIds();
- for (int ii = 0; ii < objs.Length; ii++)
- {
- DBText Text = (DBText)traction.GetObject(objs[ii], OpenMode.ForWrite);
- Text.Layer = "错误高程点";
- }
- }
- }
-
- traction.Commit();
- documentlock.Dispose();
- traction.Dispose();
- }
-
- editor.WriteMessage("\n共有" + j + "处错误");
- }
-
- /// <summary>
- /// 检查高程点与注记是否一致或为零
- /// </summary>
- private void check()
- {
- string LayerName = EleLayerName;
- getptInLayer(LayerName);
-
- if (pointarrlist == null)
- return;
- Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- for (int i = 0; i < pointarrlist.Count; i++)
- {
- Point3d pt = pointarrlist[i].pt;
- string getword = GetTxt(pt, LayerName);
- if (pt.Z == 0)
- {
- errorpointarrlist.Add(pointarrlist[i]);
- j++;
- }
- else if (!getword.Contains('.') || getword.Contains(".0"))
- {
- errorpointarrlist.Add(pointarrlist[i]);
- j++;
- }
- else
- {
- if (pt.Z.ToString("f1") == getword && pt.Z % (blc / 1000) != 0)
- {
- continue;
- }
- else
- {
- errorpointarrlist.Add(pointarrlist[i]);
- j++;
- }
- }
- }
- }
-
-
- /// <summary>
- /// 获取图层上高程点坐标
- /// </summary>
- private void getptInLayer(string LayerName)
- {
- Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
-
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,LayerName),
- new TypedValue((int)DxfCode.Start,"Insert")
- };//设置筛选条件
- SelectionFilter filter = new SelectionFilter(value);
-
- //选择区域中全部对象
- //PromptSelectionResult psr = ed.SelectAll(filter);
- // 要求在图形区域中手动选择对象
- PromptSelectionResult psr = ed.GetSelection(filter);
-
-
- if (psr.Status == PromptStatus.OK)
- {
- using (Transaction transaction = db.TransactionManager.StartTransaction())
- {
- SelectionSet ss = psr.Value;
- ObjectId[] ids = ss.GetObjectIds();
-
- points ptlist = new points();
- foreach (ObjectId etId in ids)
- {
- BlockReference blr = transaction.GetObject(etId, OpenMode.ForRead) as BlockReference;
- ptlist.pt = blr.Position;
- ptlist.objID = blr.Id;
- pointarrlist.Add(ptlist);
- }
-
- transaction.Commit();
- }
- }
- }
-
- /// <summary>
- /// 筛选坐标点附近文字信息
- /// </summary>
- private static String GetTxt(Point3d pt, string LayerName)
- {
- ObjectId[] objss = null;//文本对象的ID数组
- Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
- TypedValue[] val = new TypedValue[]
- { new TypedValue(0, "TEXT"),
- new TypedValue((int)DxfCode.LayerName,LayerName)
- };//需要筛选的类型值
- SelectionFilter fil = new SelectionFilter(val);//选择过滤器
- PromptSelectionResult pro = ed.SelectCrossingWindow(new Point3d(pt.X - 4.0 * blc / 2000, pt.Y - 4.0 * blc / 2000, 0),
- new Point3d(pt.X + 4.0 * blc / 2000, pt.Y + 4.0 * blc / 2000, 0), fil);
- //PromptSelectionResult pro = ed.SelectAll(fil);//获取结果
- SelectionSet ss = pro.Value;//赋值给选择集
- String txt = null;
-
- if (ss != null)
- {
- objss = ss.GetObjectIds();//将选择集内对象ID赋值给ID数组
- if (objss.Length > 1)
- {
- for (int i = 0; i < objss.Length; i++)
- {
- DBText buftext = GetDBObject(objss[i]) as DBText;
- if (pt.Z.ToString("f1") == buftext.TextString)
- txt = buftext.TextString;
- }
- }
- else
- {
- DBText buftext = GetDBObject(objss[0]) as DBText;
- txt = buftext.TextString;
- }
- }
- //for (int i = 0; i < objss.Length; i++)
- //{
- // DBText buftext = GetDBObject(objss[i]) as DBText;//遍历数组ID将对象赋值给单行文本
- // Point3d po = buftext.Position;//获取单行文本的坐标点
- // if (Math.Sqrt((po.X - x) * (po.X - x) + (po.Y - y) * (po.Y - y)) < 10)
- // {
- // txt = buftext.TextString;//筛选出的单行文本对象
- // }
- // else
- // continue;
- //}
- return txt;
- }
-
- private static Entity GetDBObject(ObjectId i)
- {
- Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Entity ent = null;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- ent = (Entity)tr.GetObject(i, OpenMode.ForRead, true);
- tr.Commit();
- }
- return ent;
- }
-
- }
- }
|