DrawEnd.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /* ==============================================================================
  2. * 功能描述:DrawEnd
  3. * 创 建 者:SAGACLOUD
  4. * 创建日期:2017/9/20 9:46:12
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Drawing.Drawing2D;
  10. using System.Linq;
  11. using System.Runtime.Caching;
  12. using System.Text.RegularExpressions;
  13. using System.Windows;
  14. using System.Windows.Media.Media3D;
  15. using Autodesk.Revit.DB;
  16. using Autodesk.Revit.DB.Plumbing;
  17. using SAGA.Models;
  18. using SAGA.RevitUtils;
  19. using SAGA.RevitUtils.Extends;
  20. using SAGA.RevitUtils.MEP;
  21. using WPoint = System.Windows.Point;
  22. namespace SAGA.GplotRelationComputerManage.PumpEnd
  23. {
  24. /// <summary>
  25. /// DrawEnd
  26. /// </summary>
  27. public class DrawEnd
  28. {
  29. /// <summary>
  30. /// 空间数据
  31. /// </summary>
  32. private static SpaceData spaceData;
  33. private static SpaceData SpaceDatas
  34. {
  35. get
  36. {
  37. if (spaceData == null)
  38. {
  39. spaceData = DrawDataServer.GetSpaceData(SpaceRelatedEnum.All);
  40. }
  41. return spaceData;
  42. }
  43. }
  44. //从查找目录中移除同一系统中被找到标记立管和特殊阀门
  45. public static Action<ElementId> RemoveFindedElement;
  46. //所有终点
  47. public static List<SgElement> EndElements = new List<SgElement>();
  48. //所有线
  49. public static List<List<WPoint>> EndLines = new List<List<WPoint>>();
  50. //所有已遍历Element
  51. private static List<int> AllPipeSystemElement = new List<int>();
  52. /// <summary>
  53. /// 绘制风管末端平面
  54. /// </summary>
  55. /// <param name="elementTreeNode"></param>
  56. public static void DrawDuctPlane(ElementTreeNode elementTreeNode)
  57. {
  58. ClearDrawData();
  59. DrawTree(elementTreeNode, new List<XYZ>());
  60. }
  61. /// <summary>
  62. /// 绘制水管末端平面
  63. /// </summary>
  64. /// <param name="elementTreeNode"></param>
  65. public static void DrawPipePlane(ElementTreeNode elementTreeNode)
  66. {
  67. ClearDrawData();
  68. DrawPipePlane(elementTreeNode, new List<XYZ>());
  69. }
  70. /// <summary>
  71. /// 清空数据
  72. /// </summary>
  73. private static void ClearDrawData()
  74. {
  75. EndElements.Clear();
  76. EndLines.Clear();
  77. }
  78. /// <summary>
  79. /// 计算管道拓扑结构
  80. /// </summary>
  81. /// <param name="etn"></param>
  82. /// <param name="domain"></param>
  83. /// <returns></returns>
  84. public static SgElementTreeNode GetPipeSystemDataByValve(ElementTreeNode etn, Domain domain = Domain.DomainPiping)
  85. {
  86. ClearDrawData();
  87. AllPipeSystemElement.Clear();
  88. //计算
  89. if (etn.Nodes.Count > 0) //查找特殊阀门
  90. {
  91. //将特殊阀门放入已查找序列,他是从连接件开始
  92. AllPipeSystemElement.Add(etn.Current.Id.IntegerValue);
  93. etn.ElementTypeName = AcType.Valve;
  94. GetPipeSystem(etn.Nodes[0], domain);
  95. }
  96. else
  97. {
  98. etn.ElementTypeName = AcType.MarkStandPipe;
  99. GetPipeSystem(etn, domain);
  100. }
  101. //取值
  102. GetDrawData(etn);
  103. return ConvertToEtn(etn);
  104. }
  105. /// <summary>
  106. /// 将管道拓扑关系转换成可存储的数据结构
  107. /// </summary>
  108. /// <param name="ent"></param>
  109. /// <returns></returns>
  110. static SgElementTreeNode ConvertToEtn(ElementTreeNode ent)
  111. {
  112. var ele = ent.Current;
  113. SgElementTreeNode setn = new SgElementTreeNode();
  114. AcWaterData acWater = new AcWaterData
  115. {
  116. Id = ent.Current.Id.IntegerValue + "",
  117. Type = ent.ElementTypeName
  118. };
  119. if (ent.ElementTypeName == AcType.MarkStandPipe && ele is MEPCurve m)
  120. {
  121. acWater.UpPoint3D = Convert3DToWin(m.GetVerticalTopPoint());
  122. acWater.DownPoint3D = Convert3DToWin(m.GetVerticalBottomPoint());
  123. }
  124. if (IsEnd(ele)) acWater.Type = AcType.Terminal;
  125. setn.Current = acWater;
  126. setn.PipeSystemTypeName = ent.PipeSystemTypeName;
  127. setn.StartLocation = ent.StartLocation;
  128. foreach (var node in ent.Nodes)
  129. {
  130. setn.AddChild(ConvertToEtn(node));
  131. }
  132. return setn;
  133. }
  134. /// <summary>
  135. /// 转换3D数据
  136. /// </summary>
  137. /// <param name="xyz"></param>
  138. /// <returns></returns>
  139. static Point3D Convert3DToWin(XYZ xyz)
  140. {
  141. return new Point3D(xyz.X, xyz.Y, xyz.Z);
  142. }
  143. /// <summary>
  144. /// 画水管的平面图
  145. /// </summary>
  146. /// <param name="elementTreeNode"></param>
  147. /// <param name="xyzs"></param>
  148. private static void DrawPipePlane(ElementTreeNode elementTreeNode,
  149. List<XYZ> xyzs)
  150. {
  151. Element element = elementTreeNode.Current;
  152. var nodes = elementTreeNode.Nodes;
  153. if (nodes.Count == 1)
  154. {
  155. AddXyzs(xyzs, elementTreeNode);
  156. foreach (var node in nodes)
  157. {
  158. DrawPipePlane(node, xyzs);
  159. }
  160. }
  161. else
  162. {
  163. if (IsEnd(element))
  164. {
  165. AddXyzs(xyzs, elementTreeNode);
  166. DrawLine(xyzs);
  167. XYZ origin = xyzs.LastOrDefault();
  168. DrawPoint(origin, element);
  169. // EndPoints.Add(new WPoint(origin.X, origin.Y));
  170. }
  171. else
  172. {
  173. AddXyzs(xyzs, elementTreeNode);
  174. DrawLine(xyzs);
  175. }
  176. foreach (var node in nodes)
  177. {
  178. if (IsUseFullNode(node))
  179. {
  180. xyzs = new List<XYZ>();
  181. DrawPipePlane(node, xyzs);
  182. }
  183. }
  184. }
  185. }
  186. /// <summary>
  187. /// 画出图
  188. /// </summary>
  189. /// <param name="elementTreeNode"></param>
  190. /// <param name="xyzs"></param>
  191. private static void DrawTree(ElementTreeNode elementTreeNode, List<XYZ> xyzs)
  192. {
  193. Element element = elementTreeNode.Current;
  194. var nodes = elementTreeNode.Nodes;
  195. if (nodes.Count == 1)
  196. {
  197. AddXyzs(xyzs, elementTreeNode);
  198. foreach (var node in nodes)
  199. {
  200. DrawTree(node, xyzs);
  201. }
  202. }
  203. else
  204. {
  205. if (IsEnd(element))
  206. {
  207. AddLastPoint(xyzs, elementTreeNode);
  208. DrawLine(xyzs);
  209. XYZ origin = xyzs.LastOrDefault();
  210. DrawPoint(origin, element);
  211. }
  212. else
  213. {
  214. //AddXyzs(xyzs, element, parentElement);
  215. AddTeePoint(xyzs, elementTreeNode);
  216. DrawLine(xyzs);
  217. }
  218. foreach (var node in nodes)
  219. {
  220. if (IsUseFullNode(node))
  221. {
  222. xyzs = new List<XYZ>();
  223. DrawTree(node, xyzs);
  224. }
  225. }
  226. }
  227. }
  228. /// <summary>
  229. /// 是否为有用的节点
  230. /// </summary>
  231. /// <param name="elementTreeNode"></param>
  232. /// <returns></returns>
  233. private static bool IsUseFullNode(ElementTreeNode elementTreeNode)
  234. {
  235. var leaves = elementTreeNode.GetLeaves();
  236. return leaves.Any(t => IsEnd(t.Current));
  237. }
  238. /// <summary>
  239. /// 是否为末端
  240. /// </summary>
  241. /// <param name="element"></param>
  242. /// <returns></returns>
  243. private static bool IsEnd(Element element)
  244. {
  245. BuiltInCategory category = element.GetCategory();
  246. return (category == BuiltInCategory.OST_MechanicalEquipment ||
  247. category == BuiltInCategory.OST_DuctTerminal);
  248. }
  249. /// <summary>
  250. /// 添加三通(或者管替代三通)的定位点
  251. /// 如果为不包含末端的分支,舍弃掉
  252. /// </summary>
  253. /// <param name="xyzs"></param>
  254. /// <param name="elementTreeNode"></param>
  255. private static void AddTeePoint(List<XYZ> xyzs, ElementTreeNode elementTreeNode)
  256. {
  257. Element element = elementTreeNode.Current;
  258. Element parentElement = null;
  259. if (elementTreeNode.Parent != null)
  260. parentElement = elementTreeNode.Parent.Current;
  261. Curve curve = element.GetLocationCurve();
  262. if (curve != null)
  263. {
  264. Line line = curve as Line;
  265. if (line != null)
  266. {
  267. #region Start
  268. if (parentElement != null)
  269. {
  270. AddXyzs(xyzs, elementTreeNode);
  271. }
  272. #endregion
  273. foreach (var node in elementTreeNode.Nodes)
  274. {
  275. if (IsUseFullNode(node))
  276. {
  277. XYZ tempPoint = node.Current.GetLocationPoint();
  278. XYZ project = line.GetProjectPt(tempPoint);
  279. xyzs.Add(project);
  280. }
  281. }
  282. }
  283. }
  284. else
  285. {
  286. AddXyzs(xyzs, elementTreeNode);
  287. }
  288. }
  289. /// <summary>
  290. /// 如果最后一个管为立管,将其旋转为水平
  291. /// </summary>
  292. private static void AddLastPoint(List<XYZ> xyzs, ElementTreeNode elementTreeNode)
  293. {
  294. Element element = elementTreeNode.Current;
  295. XYZ origin = element.GetLocationPoint();
  296. try
  297. {
  298. Line parentLine = elementTreeNode.Parent.Current.GetLocationCurve() as Line;
  299. XYZ vector = parentLine.Direction;
  300. if (vector.IsParallel(XYZ.BasisZ))
  301. {
  302. var tempNode = elementTreeNode;
  303. while (true)
  304. {
  305. tempNode = tempNode.Parent;
  306. if (tempNode == null) break;
  307. Line line = tempNode.Current.GetLocationCurve() as Line;
  308. if (line != null)
  309. {
  310. if (!line.Direction.IsParallel(XYZ.BasisZ))
  311. {
  312. XYZ project = line.GetProjectPt(origin);
  313. XYZ farXyz = line.GetFarnessPoint(project);
  314. XYZ farVector = project - farXyz;
  315. XYZ horVector = farVector.VectorRotate(Math.PI / 2);
  316. double offset = project.Z - origin.Z;
  317. XYZ endXyz = project.OffsetPoint(horVector, offset);
  318. //xyzs.Clear();
  319. xyzs.Add(project);
  320. xyzs.Add(endXyz);
  321. break;
  322. }
  323. }
  324. }
  325. }
  326. else
  327. {
  328. xyzs.Add(origin);
  329. }
  330. }
  331. catch
  332. {
  333. xyzs.Add(origin);
  334. }
  335. }
  336. /// <summary>
  337. /// 向集合中添加点
  338. /// </summary>
  339. /// <param name="xyzs"></param>
  340. /// <param name="elementTreeNode"></param>
  341. private static void AddXyzs(List<XYZ> xyzs, ElementTreeNode elementTreeNode)
  342. {
  343. Element element = elementTreeNode.Current;
  344. XYZ elementXyz = element.GetLocationPoint();
  345. if (elementXyz != null)
  346. {
  347. try
  348. {
  349. ElementTreeNode parentNode = elementTreeNode.Parent;
  350. XYZ parentXyz = parentNode.Current.GetLocationPoint();
  351. if (parentXyz != null)
  352. {
  353. xyzs.Add(parentXyz);
  354. xyzs.Add(elementXyz);
  355. }
  356. else
  357. {
  358. Line parentLine = parentNode.Current.GetLocationCurve() as Line;
  359. XYZ project = parentLine.GetProjectPt(elementXyz);
  360. xyzs.Add(project);
  361. }
  362. }
  363. catch (Exception e)
  364. {
  365. xyzs.Add(elementXyz);
  366. }
  367. }
  368. else
  369. {
  370. Curve elementCurve = element.GetLocationCurve();
  371. if (elementCurve != null)
  372. {
  373. Line elementLine = element.GetLocationCurve() as Line;
  374. try
  375. {
  376. XYZ parentXyz = elementTreeNode.Parent.Current.GetLocationPoint();
  377. XYZ parentProject = elementLine.GetProjectPt(parentXyz);
  378. xyzs.Add(parentProject);
  379. foreach (ElementTreeNode node in elementTreeNode.Nodes)
  380. {
  381. if (IsUseFullNode(node))
  382. {
  383. XYZ childXyz = node.Current.GetLocationPoint();
  384. XYZ childProject = elementLine.GetProjectPt(childXyz);
  385. xyzs.Add(childProject);
  386. }
  387. }
  388. }
  389. catch (Exception e)
  390. {
  391. xyzs.Add(elementCurve.StartPoint());
  392. xyzs.Add(elementCurve.EndPoint());
  393. }
  394. }
  395. }
  396. }
  397. /// <summary>
  398. /// 画线
  399. /// </summary>
  400. /// <param name="xyzs"></param>
  401. private static void DrawLine(IList<XYZ> xyzs)
  402. {
  403. int count = xyzs.Count;
  404. for (int index = 0; index < count - 1; index++)
  405. {
  406. var start = xyzs[index].NewZ();
  407. var end = xyzs[index + 1].NewZ();
  408. if (!start.IsEqual(end))
  409. {
  410. // Line line = start.NewLine(end);
  411. // line.NewDetailCurve(view);
  412. EndLines.Add(new List<WPoint>()
  413. {
  414. new WPoint(start.X,start.Y), new WPoint(end.X,end.Y)
  415. });
  416. }
  417. }
  418. }
  419. /// <summary>
  420. /// 画节点
  421. /// </summary>
  422. /// <param name="center"></param>
  423. /// <param name="element"></param>
  424. private static void DrawPoint(XYZ center, Element element)
  425. {
  426. //此处构件坐标为管道末端,非构件端点
  427. EndElements.Add(new SgElement(element.Id.ToString(), element.Name)
  428. {
  429. Point = new WPoint(center.X, center.Y),
  430. FamilyName = element.GetFamily()?.Name,
  431. ElementType = element.GetFamilySymbol()?.Name
  432. });
  433. }
  434. /// <summary>
  435. /// 记录所有管道系统路径以及终点,此方法只适合没有回路的情况
  436. /// </summary>
  437. /// <param name="etn"></param>
  438. public static void GetPipeSystem(ElementTreeNode etn, Domain domain = Domain.DomainPiping)
  439. {
  440. var currentElement = etn.Current;
  441. if (!AllPipeSystemElement.Contains(currentElement.Id.IntegerValue))
  442. AllPipeSystemElement.Add(currentElement.Id.IntegerValue);
  443. else return;
  444. ////如果是横管记录坐标
  445. //if (currentElement is Pipe pipe && !pipe.IsVerticalPipe())
  446. //{
  447. // DrawLine(pipe.GetLocationCurve().Tessellate());
  448. // //如果管道一端没有连接东西,求此管道与空间的轮廓相交,终端用空间表示,找不到空间,直接标记室外
  449. //}
  450. //else if (IsEnd(currentElement)) //如果是水管设备记录设备
  451. //{
  452. // DrawPoint(currentElement.GetLocationPoint(), currentElement);
  453. //}
  454. foreach (Connector connector in currentElement.GetConnectors(domain))
  455. {
  456. if (connector.IsConnected)
  457. {
  458. //物理类型才会有origin
  459. foreach (Connector connector2 in connector.GetReferenceConnectors().Where(t => (t.ConnectorType & ConnectorType.Physical) == t.ConnectorType))
  460. {
  461. var refElement = connector2.Owner;
  462. if (refElement.Id.IsEqual(currentElement.Id)
  463. && refElement.Id.IsEqual(etn.Parent.Current.Id)) continue;
  464. if (AllPipeSystemElement.Contains(refElement.Id.IntegerValue)) continue;
  465. var theEtn = new ElementTreeNode()
  466. {
  467. Current = refElement,
  468. Parent = etn,
  469. StartLocation = connector2.Origin
  470. };
  471. if (refElement is MEPCurve p)//判断此管道系统是否和上一级保持一致
  472. {
  473. var systemType = p is Pipe ? p.GetParameterString(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM) :
  474. p.GetParameterString(BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM);//系统类型
  475. if (systemType != etn.PipeSystemTypeName)
  476. {
  477. continue;
  478. }
  479. }
  480. theEtn.PipeSystemTypeName = etn.PipeSystemTypeName;
  481. //检测当前设备是否为阀门,如果是阀门也跳过
  482. if (refElement is FamilyInstance fi)
  483. {
  484. if (Regex.IsMatch(fi.GetFamily()?.Name ?? "", "流向指示符|风向箭头"))
  485. {
  486. etn.AddChild(theEtn);
  487. theEtn.ElementTypeName = AcType.Valve;
  488. RemoveFindedElement?.Invoke(fi.Id);
  489. continue;
  490. }
  491. }
  492. //找到标记立管也停止
  493. if (refElement is MEPCurve pipe && pipe.IsVerticalPipe()
  494. && pipe.GetParameterString(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) == "start")
  495. {
  496. etn.AddChild(theEtn);
  497. theEtn.ElementTypeName = AcType.MarkStandPipe;
  498. RemoveFindedElement?.Invoke(pipe.Id);
  499. continue;
  500. }
  501. GetPipeSystem(theEtn, domain);
  502. etn.AddChild(theEtn);
  503. }
  504. }
  505. }
  506. }
  507. public static void GetDrawData(ElementTreeNode etn)
  508. {
  509. var currentElement = etn.Current;
  510. //如果是横管记录坐标
  511. if (currentElement is MEPCurve pipe && !pipe.IsVerticalPipe())
  512. {
  513. DrawLine(pipe.GetLocationCurve().Tessellate());
  514. //连线
  515. DrawLine(GetChildLine(etn, pipe.GetLocationCurve()));
  516. //如果管道一端没有连接东西,求此管道与空间的轮廓相交,终端用空间表示,找不到空间,直接标记室外
  517. var connector = currentElement.GetConnectors(Domain.DomainPiping).FirstOrDefault(t => !t.IsConnected);
  518. if (connector != null)//找到一端没有被连接的管道
  519. {
  520. bool isFind = false;
  521. var origin = connector.Origin;
  522. //获取上一级的连接件所在的空间
  523. if (etn.Parent != null && etn.Parent.Current is FamilyInstance fi && fi.Space != null)
  524. {
  525. var level = fi.Space.Level;
  526. //根据标高查找
  527. //找到本层的空间
  528. var levelSpaces = SpaceDatas?.FloorDatas.FirstOrDefault(t => t.LevelName == level.Name.Replace("-saga", ""));
  529. //空间轮廓与管线做相交判断
  530. if (levelSpaces != null)
  531. {
  532. foreach (var sgSpace in levelSpaces.EndPoints)
  533. {
  534. #region 点在区域内判断
  535. GraphicsPath myGraphicsPath = new GraphicsPath();
  536. Region myRegion = new Region();
  537. myGraphicsPath.Reset();
  538. sgSpace.BoundarySegment.ForEach(p =>
  539. {
  540. myGraphicsPath.AddCurve(p.Select(t => new System.Drawing.PointF((float)t.X, (float)t.Y)).ToArray());
  541. });
  542. // myGraphicsPath.AddPolygon(points);//points);
  543. myRegion.MakeEmpty();
  544. myRegion.Union(myGraphicsPath);
  545. //返回判断点是否在多边形里
  546. bool myPoint = myRegion.IsVisible(new PointF((float)origin.X, (float)origin.Y));
  547. //重新定位空间的位置,选用管道口的位置
  548. sgSpace.Point = new System.Windows.Point(origin.X, origin.Y);
  549. #endregion
  550. if (myPoint)
  551. {
  552. EndElements.Add(sgSpace);
  553. isFind = true;
  554. break;
  555. }
  556. }
  557. }
  558. //if (!isFind)
  559. //{
  560. // //如果找到则记录,找不到标记为户外
  561. // EndElements.Add(new SgElement("", "室外")
  562. // {
  563. // Point = new WPoint(origin.X, origin.Y),
  564. // FamilyName = "室外",
  565. // ElementType = "室外"
  566. // });
  567. //}
  568. }
  569. }
  570. }
  571. else if (IsEnd(currentElement)) //如果是水管设备记录设备
  572. {
  573. //设备连接管道,防止设备太大连接不上
  574. // DrawLine(GetChildLine(etn));现在取的是连接connector的origin,所以不需要再加了
  575. DrawPoint(etn.StartLocation, currentElement);
  576. }
  577. foreach (var etnNode in etn.Nodes)
  578. {
  579. //如果以流量指示符开始,父节点为空
  580. if (etnNode.Parent != null && etnNode.Current is FamilyInstance fi && Regex.IsMatch(fi.GetFamily()?.Name ?? "", "流向指示符|风向箭头"))
  581. {
  582. continue;
  583. }
  584. GetDrawData(etnNode);
  585. }
  586. }
  587. /// <summary>
  588. /// 当前设备与上一设备的连线
  589. /// </summary>
  590. /// <param name="etn"></param>
  591. /// <param name="pipeCurve"></param>
  592. /// <returns></returns>
  593. static List<XYZ> GetChildLine(ElementTreeNode etn, Curve pipeCurve)
  594. {
  595. if (etn.Parent == null) return new List<XYZ>();
  596. etn = etn.Parent;
  597. List<XYZ> linePoints = new List<XYZ>();
  598. Line line = null;
  599. var currentElement = etn.Current;
  600. //如果是横管记录坐标
  601. if (currentElement is MEPCurve pipe && !pipe.IsVerticalPipe())
  602. {
  603. var cpipe = pipe.GetLocationCurve();
  604. var list1 = new List<XYZ>() { pipeCurve.StartPoint(), pipeCurve.EndPoint() };
  605. var list2 = new List<XYZ>() { cpipe.StartPoint(), cpipe.EndPoint() };
  606. var length = double.MaxValue;
  607. var nearPoint = cpipe.StartPoint();
  608. var otherPoint = pipeCurve.StartPoint();
  609. foreach (var xyz in list1)
  610. {
  611. foreach (var xyz1 in list2)
  612. {
  613. var l = xyz.IsEqual(xyz1) ? 0 : xyz.NewLine(xyz1).Length;
  614. if (l < length)
  615. {
  616. length = l;
  617. nearPoint = xyz1;
  618. otherPoint = xyz;
  619. }
  620. }
  621. }
  622. linePoints.Add(otherPoint);
  623. linePoints.Add(nearPoint);
  624. return linePoints;
  625. }
  626. else if (IsEnd(currentElement)) //如果是水管设备记录设备
  627. {
  628. var p1 = pipeCurve.StartPoint();
  629. var p2 = pipeCurve.EndPoint();
  630. var p3 = etn.StartLocation;
  631. linePoints.Add(p3);
  632. linePoints.Add((p3 - p1).GetLength() < (p3 - p2).GetLength() ? p1 : p2);
  633. return linePoints;
  634. }
  635. linePoints = GetChildLine(etn, pipeCurve);
  636. return linePoints;
  637. }
  638. static List<XYZ> GetChildLine(ElementTreeNode etn)
  639. {
  640. if (etn.Parent == null) return new List<XYZ>();
  641. var parent = etn.Parent;
  642. List<XYZ> linePoints = new List<XYZ>();
  643. Line line = null;
  644. var currentElement = etn.Current;
  645. var parentElement = parent.Current;
  646. //如果是横管记录坐标
  647. if (parentElement is MEPCurve pipe && !pipe.IsVerticalPipe())
  648. {
  649. var pipeCurve = pipe.GetLocationCurve();
  650. var p1 = pipeCurve.StartPoint();
  651. var p2 = pipeCurve.EndPoint();
  652. var p3 = currentElement.GetLocationPoint();
  653. linePoints.Add(p3);
  654. linePoints.Add((p3 - p1).GetLength() < (p3 - p2).GetLength() ? p1 : p2);
  655. return linePoints;
  656. }
  657. linePoints = GetChildLine(parent);
  658. return linePoints;
  659. }
  660. }
  661. }