工具箱相关
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ElePtCheck.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GrxCAD.ApplicationServices;
  7. using GrxCAD.DatabaseServices;
  8. using GrxCAD.EditorInput;
  9. using System.Collections;
  10. using GrxCAD.Geometry;
  11. namespace HCTools
  12. {
  13. public struct points
  14. {
  15. public Point3d pt;
  16. public ObjectId objID;
  17. }
  18. class ElePtCheck
  19. {
  20. public static int blc;//比例尺
  21. public static string EleLayerName;//高程点图层名
  22. public double radius;//半径
  23. //public double length;//搜索半径
  24. int j = 0;//记录错误点个数
  25. //存放所有高程点数组
  26. public List<points> pointarrlist = new List<points>();
  27. //存放有问题的高程点数组
  28. public List<points> errorpointarrlist = new List<points>();
  29. /// <summary>
  30. /// 检查错误的高程点并画圆标记
  31. /// </summary>
  32. public void pointcheck()
  33. {
  34. double flagradius = 4.0 * blc / 1000;//画圆标记半径
  35. if (blc == 500)
  36. {
  37. radius = 1.5;
  38. }
  39. else if (blc == 1000)
  40. {
  41. radius = 2.5;
  42. }
  43. else if (blc == 2000)
  44. {
  45. radius = 4;
  46. }
  47. else if (blc == 5000)
  48. {
  49. radius = 10.5;
  50. }
  51. //外切圆半径
  52. //length = radius * Math.Pow(2, 0.5);
  53. //检查高程点与注记是否一致或为零
  54. check();
  55. //创建存放错误点的图层
  56. LayerControl layerscontrol = new LayerControl();
  57. string layname = "错误高程点";
  58. if (!layerscontrol.haslayername(layname))
  59. {
  60. colorgb col = new colorgb(255, 0, 255);
  61. layerscontrol.creatlayer(layname, col);
  62. layerscontrol.movelayertofront(layname);
  63. }
  64. else
  65. layerscontrol.movelayertofront(layname);
  66. //创建错误点标记的图层
  67. LayerControl layerscontrol1 = new LayerControl();
  68. string layname1 = "错误高程点标记";
  69. if (!layerscontrol1.haslayername(layname1))
  70. {
  71. colorgb col = new colorgb(0, 225, 255);
  72. layerscontrol1.creatlayer(layname1, col);
  73. layerscontrol1.movelayertofront(layname1);
  74. }
  75. else
  76. layerscontrol1.movelayertofront(layname1);
  77. Database database = HostApplicationServices.WorkingDatabase;
  78. Document doc = Application.DocumentManager.MdiActiveDocument;
  79. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  80. using (Transaction traction = database.TransactionManager.StartTransaction())
  81. {
  82. DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  83. BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable;
  84. for (int i = 0; i < errorpointarrlist.Count; i++)
  85. {
  86. BasicFunction functions = new BasicFunction();
  87. BlockReference blr= traction.GetObject(errorpointarrlist[i].objID,OpenMode.ForWrite)as BlockReference;
  88. blr.Layer = "错误高程点";
  89. functions.makeflag(errorpointarrlist[i].pt.X, errorpointarrlist[i].pt.Y, 0, flagradius, "错误高程点标记");
  90. Point3d p1 = new Point3d(errorpointarrlist[i].pt.X - radius, errorpointarrlist[i].pt.Y - radius, 0);
  91. Point3d p2 = new Point3d(errorpointarrlist[i].pt.X + radius, errorpointarrlist[i].pt.Y + radius, 0);
  92. TypedValue[] typedvalue = new TypedValue[2];
  93. typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
  94. typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, EleLayerName), 1);
  95. SelectionFilter filter = new SelectionFilter(typedvalue);
  96. PromptSelectionResult psr = editor.SelectCrossingWindow(p1, p2, filter);
  97. if (psr.Status == PromptStatus.OK)
  98. {
  99. SelectionSet set = psr.Value;
  100. ObjectId[] objs = new ObjectId[set.Count];
  101. objs = set.GetObjectIds();
  102. for (int ii = 0; ii < objs.Length; ii++)
  103. {
  104. DBText Text = (DBText)traction.GetObject(objs[ii], OpenMode.ForWrite);
  105. Text.Layer = "错误高程点";
  106. }
  107. }
  108. }
  109. traction.Commit();
  110. documentlock.Dispose();
  111. traction.Dispose();
  112. }
  113. editor.WriteMessage("\n共有" + j + "处错误");
  114. }
  115. /// <summary>
  116. /// 检查高程点与注记是否一致或为零
  117. /// </summary>
  118. private void check()
  119. {
  120. string LayerName = EleLayerName;
  121. getptInLayer(LayerName);
  122. if (pointarrlist == null)
  123. return;
  124. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  125. for (int i = 0; i < pointarrlist.Count; i++)
  126. {
  127. Point3d pt = pointarrlist[i].pt;
  128. string getword = GetTxt(pt, LayerName);
  129. if (pt.Z == 0)
  130. {
  131. errorpointarrlist.Add(pointarrlist[i]);
  132. j++;
  133. }
  134. else if (!getword.Contains('.') || getword.Contains(".0"))
  135. {
  136. errorpointarrlist.Add(pointarrlist[i]);
  137. j++;
  138. }
  139. else
  140. {
  141. if (pt.Z.ToString("f1") == getword && pt.Z % (blc / 1000) != 0)
  142. {
  143. continue;
  144. }
  145. else
  146. {
  147. errorpointarrlist.Add(pointarrlist[i]);
  148. j++;
  149. }
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 获取图层上高程点坐标
  155. /// </summary>
  156. private void getptInLayer(string LayerName)
  157. {
  158. Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  159. Database db = HostApplicationServices.WorkingDatabase;
  160. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  161. TypedValue[] value = new TypedValue[]
  162. {
  163. new TypedValue((int)DxfCode.LayerName,LayerName),
  164. new TypedValue((int)DxfCode.Start,"Insert")
  165. };//设置筛选条件
  166. SelectionFilter filter = new SelectionFilter(value);
  167. //选择区域中全部对象
  168. //PromptSelectionResult psr = ed.SelectAll(filter);
  169. // 要求在图形区域中手动选择对象
  170. PromptSelectionResult psr = ed.GetSelection(filter);
  171. if (psr.Status == PromptStatus.OK)
  172. {
  173. using (Transaction transaction = db.TransactionManager.StartTransaction())
  174. {
  175. SelectionSet ss = psr.Value;
  176. ObjectId[] ids = ss.GetObjectIds();
  177. points ptlist = new points();
  178. foreach (ObjectId etId in ids)
  179. {
  180. BlockReference blr = transaction.GetObject(etId, OpenMode.ForRead) as BlockReference;
  181. ptlist.pt = blr.Position;
  182. ptlist.objID = blr.Id;
  183. pointarrlist.Add(ptlist);
  184. }
  185. transaction.Commit();
  186. }
  187. }
  188. }
  189. /// <summary>
  190. /// 筛选坐标点附近文字信息
  191. /// </summary>
  192. private static String GetTxt(Point3d pt, string LayerName)
  193. {
  194. ObjectId[] objss = null;//文本对象的ID数组
  195. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  196. TypedValue[] val = new TypedValue[]
  197. { new TypedValue(0, "TEXT"),
  198. new TypedValue((int)DxfCode.LayerName,LayerName)
  199. };//需要筛选的类型值
  200. SelectionFilter fil = new SelectionFilter(val);//选择过滤器
  201. PromptSelectionResult pro = ed.SelectCrossingWindow(new Point3d(pt.X - 4.0 * blc / 2000, pt.Y - 4.0 * blc / 2000, 0),
  202. new Point3d(pt.X + 4.0 * blc / 2000, pt.Y + 4.0 * blc / 2000, 0), fil);
  203. //PromptSelectionResult pro = ed.SelectAll(fil);//获取结果
  204. SelectionSet ss = pro.Value;//赋值给选择集
  205. String txt = null;
  206. if (ss != null)
  207. {
  208. objss = ss.GetObjectIds();//将选择集内对象ID赋值给ID数组
  209. if (objss.Length > 1)
  210. {
  211. for (int i = 0; i < objss.Length; i++)
  212. {
  213. DBText buftext = GetDBObject(objss[i]) as DBText;
  214. if (pt.Z.ToString("f1") == buftext.TextString)
  215. txt = buftext.TextString;
  216. }
  217. }
  218. else
  219. {
  220. DBText buftext = GetDBObject(objss[0]) as DBText;
  221. txt = buftext.TextString;
  222. }
  223. }
  224. //for (int i = 0; i < objss.Length; i++)
  225. //{
  226. // DBText buftext = GetDBObject(objss[i]) as DBText;//遍历数组ID将对象赋值给单行文本
  227. // Point3d po = buftext.Position;//获取单行文本的坐标点
  228. // if (Math.Sqrt((po.X - x) * (po.X - x) + (po.Y - y) * (po.Y - y)) < 10)
  229. // {
  230. // txt = buftext.TextString;//筛选出的单行文本对象
  231. // }
  232. // else
  233. // continue;
  234. //}
  235. return txt;
  236. }
  237. private static Entity GetDBObject(ObjectId i)
  238. {
  239. Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  240. Database db = doc.Database;
  241. Entity ent = null;
  242. using (Transaction tr = db.TransactionManager.StartTransaction())
  243. {
  244. ent = (Entity)tr.GetObject(i, OpenMode.ForRead, true);
  245. tr.Commit();
  246. }
  247. return ent;
  248. }
  249. }
  250. }