SystemParseManager.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:SystemParseManager
  3. * 作者:xulisong
  4. * 创建时间: 2019/1/10 14:34:23
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Windows.Media.Media3D;
  11. using Autodesk.Revit.DB;
  12. using Autodesk.Revit.DB.Mechanical;
  13. using Autodesk.Revit.DB.Plumbing;
  14. using SAGA.DotNetUtils.Data;
  15. using SAGA.Models;
  16. using SAGA.Models.GplotElement;
  17. using SAGA.Models.Graphs;
  18. using SAGA.RevitUtils;
  19. using SAGA.RevitUtils.Data.Graph;
  20. using SAGA.RevitUtils.Extends;
  21. using SAGA.RevitUtils.MEP;
  22. namespace SAGA.GplotRelationComputerManage
  23. {
  24. /// <summary>
  25. /// 系统解析管理
  26. /// </summary>
  27. public class SystemParseManager
  28. {
  29. #region 解析管路系统数据
  30. #region 通用基础方法
  31. /// <summary>
  32. /// 创建树节点
  33. /// </summary>
  34. /// <param name="startElement"></param>
  35. /// <param name="startConnector"></param>
  36. /// <param name="predicateEnd"></param>
  37. /// <returns></returns>
  38. public static ElementTreeNode CreateTreeNode(Element startElement, Connector startConnector,
  39. Predicate<Element> predicateEnd)
  40. {
  41. ElementTreeNode node = new ElementTreeNode();
  42. node.Current = startElement;
  43. List<ElementTreeNode> reference = new List<ElementTreeNode>();
  44. reference.Add(node);
  45. for (int i = 0; i < reference.Count; i++)
  46. {
  47. var baseNode = reference[i];
  48. List<Connector> connectors;
  49. if (i == 0 && startConnector != null)
  50. {
  51. connectors = new List<Connector> { startConnector };
  52. }
  53. else
  54. {
  55. connectors = baseNode.Current.GetAllConnectors().ToList();
  56. }
  57. foreach (var connector in connectors)
  58. {
  59. if (connector.Searchable())
  60. {
  61. var refConnectors = connector.GetReferenceConnectors()
  62. .Where(c => ConnectorType.Physical.HasFlag(c.ConnectorType)).ToList();
  63. foreach (var refConnector in refConnectors)
  64. {
  65. var refElement = refConnector.Owner;
  66. if (reference.Reverse<ElementTreeNode>().Any(e => e.Current.Id.IntegerValue == refElement.Id.IntegerValue))
  67. {
  68. continue;
  69. }
  70. ElementTreeNode refNode = new ElementTreeNode();
  71. refNode.Current = refElement;
  72. refNode.StartLocation = refConnector.Origin;
  73. baseNode.Nodes.Add(refNode);
  74. if (predicateEnd != null && predicateEnd(refElement))
  75. {
  76. continue;
  77. }
  78. //if (reference.All(e => e.Current.Id.IntegerValue != refElement.Id.IntegerValue))
  79. //{
  80. reference.Add(refNode);
  81. //}
  82. }
  83. }
  84. }
  85. }
  86. return node;
  87. }
  88. #endregion
  89. /// <summary>
  90. /// 构件系统连接节点
  91. /// </summary>
  92. /// <param name="etn">开始元素</param>
  93. /// <param name="domain"></param>
  94. /// <param name="endConditon">遍历中断条件,遇到指定条件的管道则停止遍历</param>
  95. /// <returns>树形节点中包好的Id信息</returns>
  96. public static List<int> BuildSystemNode(ElementTreeNode etn, Domain domain, Func<MEPCurve, bool> endConditon)
  97. {
  98. List<int> useIds = new List<int>();
  99. etn.GetAllNodes().ForEach(n =>
  100. {
  101. if (!n.IsLeaf&&n.Current != null)
  102. {
  103. useIds.Add(n.Current.Id.IntegerValue);
  104. }
  105. });
  106. var leaves = etn.GetLeaves();
  107. foreach (var elementTreeNode in leaves)
  108. {
  109. BuildSystemNode(elementTreeNode, domain, useIds, endConditon);
  110. }
  111. return useIds;
  112. }
  113. private static void BuildSystemNode(ElementTreeNode etn, Domain domain, List<int> useIds, Func<MEPCurve, bool> endConditon)
  114. {
  115. var useElement = etn.Current;
  116. #region 预判退出
  117. if (useElement == null)
  118. {
  119. return;
  120. }
  121. if (useIds.Any(id => id == useElement.Id.IntegerValue))
  122. {
  123. return;
  124. }
  125. #endregion
  126. useIds.Add(useElement.Id.IntegerValue);
  127. var connectors = useElement.GetConnectors(domain);
  128. foreach (var baseConnector in connectors)
  129. {
  130. if (!baseConnector.Searchable())
  131. continue;
  132. var refConnectors = baseConnector.GetReferenceConnectors()
  133. .Where(c => ConnectorType.Physical.HasFlag(c.ConnectorType)).ToList();
  134. foreach (var refConnector in refConnectors)
  135. {
  136. var refElement = refConnector.Owner;
  137. //逻辑变更,如果存在,不继续遍历。但要完成本次操作;移动到最后
  138. //if (useIds.Any(id => id == refElement.Id.IntegerValue))
  139. //{
  140. // continue;
  141. //}
  142. //初始化当前节点,未必一定加入集合,为了下面代码书写方便,先进性初始化
  143. ElementTreeNode currentNode = new ElementTreeNode()
  144. {
  145. Current = refElement,
  146. StartLocation = refConnector.Origin
  147. };
  148. if (refElement is MEPCurve mepCurve)
  149. {
  150. //优先判定系统,再进行立管相关逻辑的处理;如果系统不兼容则直接退出遍历
  151. //var systemName=mepCurve.GetSystemTypeName();
  152. if (endConditon != null && endConditon(mepCurve))
  153. {
  154. continue;
  155. }
  156. if (SystemCalcUtil.IsStart(mepCurve))
  157. {
  158. currentNode.ElementTypeName = AcType.MarkStandPipe;
  159. etn.AddChild(currentNode);
  160. useIds.Add(refElement.Id.IntegerValue);
  161. continue;
  162. }
  163. }
  164. else if (refElement is FamilyInstance fi)
  165. {
  166. //非管线,遇到结束标志,加入当前子节点,但不在进行递归;
  167. if (SystemCalcUtil.IsStart(fi))
  168. {
  169. currentNode.ElementTypeName = AcType.Valve;
  170. etn.AddChild(currentNode);
  171. useIds.Add(refElement.Id.IntegerValue);
  172. continue;
  173. }
  174. }
  175. //useIds的控制:跳出时,直接加入UseIds。继续遍历的,在遍历函数中加入
  176. etn.AddChild(currentNode);
  177. if (useIds.Any(id => id == refElement.Id.IntegerValue))
  178. {
  179. continue;
  180. }
  181. BuildSystemNode(currentNode, domain, useIds, endConditon);
  182. }
  183. }
  184. }
  185. #endregion
  186. #region 创建绘图数据相关
  187. /// <summary>
  188. /// 构件绘图数据
  189. /// </summary>
  190. /// <param name="etn"></param>
  191. /// <returns></returns>
  192. public static SystemDrawItems CreateDrawing(ElementTreeNode etn)
  193. {
  194. #region 描述
  195. /*
  196. *读取几何信息
  197. * 1、管道,管件直接按connector连线获取。
  198. * 2、设备,可能出现多个connector,确定有效的连线;
  199. * 最终:如果是管道,通过本身的connector生成线。如果是familyInstance通过定位点连接,父节点和子节点
  200. * 3、具体名字相关内容,后续操作中添加
  201. */
  202. #endregion
  203. List<SystemCurveItem> curveItems = new List<SystemCurveItem>();
  204. List<SystemPointItem> pointItems = new List<SystemPointItem>();
  205. Queue<ElementTreeNode> nodeQueue = new Queue<ElementTreeNode>() ;
  206. nodeQueue.Enqueue(etn);
  207. while (nodeQueue.Any())
  208. {
  209. #region 控制验证
  210. var currentNode = nodeQueue.Dequeue();
  211. if (currentNode == null)
  212. continue;
  213. var element = currentNode.Current;
  214. if (element == null)
  215. continue;
  216. #endregion
  217. if (element is MEPCurve mepCurve)
  218. {
  219. #region 联通线处理
  220. Curve curve = mepCurve.GetCurve();
  221. var xyzs = curve.Tessellate().Select(xyz => xyz.XYZToPoint());
  222. SystemCurveItem curveItem = new SystemCurveItem();
  223. curveItem.Points.AddRange(xyzs.ToList());
  224. curveItem.RefId = element.Id.IntegerValue;
  225. curveItems.Add(curveItem);
  226. #endregion
  227. #region 点信息处理
  228. if (SystemCalcUtil.IsStart(mepCurve))
  229. {
  230. SystemPointItem point = new SystemPointItem();
  231. point.Point = mepCurve.GetCurve().StartPoint().XYZToPoint();
  232. point.RefId = mepCurve.Id.IntegerValue;
  233. point.IsVirtual = true;
  234. point.EquipmentType = PointItemType.StandPipe.ToString();
  235. point.Name = AppSetting.StartFlag;
  236. pointItems.Add(point);
  237. }
  238. #endregion
  239. }
  240. else if (element is FamilyInstance fiEq)
  241. {
  242. #region 获取引用点
  243. List<XYZ> usePoints = new List<XYZ>();
  244. if (currentNode.StartLocation != null)
  245. {
  246. usePoints.Add(currentNode.StartLocation);
  247. }
  248. foreach (ElementTreeNode childNode in currentNode.Nodes)
  249. {
  250. var usePoint = childNode.StartLocation;
  251. if (usePoint != null)
  252. {
  253. usePoints.Add(usePoint);
  254. }
  255. }
  256. #endregion
  257. var location = element.GetBoxCenter().XYZToPoint();
  258. #region 根据定位点并创建线条
  259. foreach (var usePoint in usePoints)
  260. {
  261. SystemCurveItem curveItem = new SystemCurveItem();
  262. curveItem.Points.Add(location);
  263. curveItem.Points.Add(usePoint.XYZToPoint());
  264. curveItem.RefId = element.Id.IntegerValue;
  265. curveItems.Add(curveItem);
  266. }
  267. #endregion
  268. #region 判断是否是设备
  269. //先初始化不一定加入
  270. SystemPointItem point = new SystemPointItem();
  271. point.Point = location;
  272. point.RefId = fiEq.Id.IntegerValue;
  273. point.BimId = element.GetBimId();
  274. if (MBIInfoUtil.IsEquipment(fiEq))
  275. {
  276. point.Name = string.Empty;
  277. point.EquipmentType = PointItemType.Equipment.ToString();
  278. var equipExtend = currentNode.GetTag<NodeExtendData>();
  279. if (equipExtend != null)
  280. {
  281. point.Name = equipExtend.Name;
  282. point.EquipmentType = equipExtend.Category;
  283. }
  284. pointItems.Add(point);
  285. }
  286. else if (SystemCalcUtil.IsStart(fiEq))
  287. {
  288. point.Name = string.Empty;
  289. point.EquipmentType = PointItemType.StartValve.ToString(); ;
  290. point.IsVirtual = true;
  291. point.Name=AppSetting.StartFlag;
  292. pointItems.Add(point);
  293. }
  294. #endregion
  295. }
  296. else if (element is Space)
  297. {
  298. SystemPointItem point = new SystemPointItem();
  299. point.Point = element.GetLocationPoint().XYZToPoint();
  300. point.RefId = element.Id.IntegerValue;
  301. point.EquipmentType = PointItemType.Space.ToString();
  302. point.IsVirtual = true;
  303. pointItems.Add(point);
  304. }
  305. currentNode.Nodes.ForEach(e => nodeQueue.Enqueue(e));
  306. }
  307. SystemDrawItems drawItems = new SystemDrawItems();
  308. drawItems.Curves = curveItems;
  309. drawItems.Points = pointItems;
  310. return drawItems;
  311. }
  312. #endregion
  313. #region 创建关系数据相关
  314. public static List<BinaryRelationItem> CreateRelation(ElementTreeNode etn)
  315. {
  316. List<BinaryRelationItem> result = new List<BinaryRelationItem>();
  317. #region 描述
  318. /*
  319. * 1、将树形结构初步处理,修剪成存留设备之间的关系;
  320. * 2、处理成二维关系
  321. */
  322. #endregion
  323. var equipmentNodes= ConvertEquipmentNodes(etn);
  324. var loopNodes = new List<EquipmentNode>(equipmentNodes);
  325. for (int i = 0; i < loopNodes.Count; i++)
  326. {
  327. var currentNode = loopNodes[i];
  328. foreach (var childNode in currentNode.Nodes)
  329. {
  330. BinaryRelationItem relation = new BinaryRelationItem();
  331. relation.From = currentNode.CloneCurrentNode();
  332. relation.To = childNode.CloneCurrentNode();
  333. result.Add(relation);
  334. loopNodes.Add(childNode);
  335. }
  336. }
  337. return result;
  338. }
  339. /// <summary>
  340. /// 将elment树转换成设备节点类
  341. /// </summary>
  342. /// <param name="etn"></param>
  343. /// <returns></returns>
  344. private static List<EquipmentNode> ConvertEquipmentNodes(ElementTreeNode etn)
  345. {
  346. List<EquipmentNode> nodes = new List<EquipmentNode>();
  347. List<ElementTreeNode> loopNodes = new List<ElementTreeNode>(){ etn };
  348. for (int i = 0; i < loopNodes.Count; i++)
  349. {
  350. var currentNode = loopNodes[i];
  351. if (TryGetNode(currentNode.Current, out EquipmentNode outNode))
  352. {
  353. foreach (var currentNodeNode in currentNode.Nodes)
  354. {
  355. outNode.AddChildren(ConvertEquipmentNodes(currentNodeNode));
  356. }
  357. nodes.Add(outNode);
  358. }
  359. else
  360. {
  361. loopNodes.AddRange(currentNode.Nodes);
  362. }
  363. }
  364. return nodes;
  365. }
  366. /// <summary>
  367. /// 获取element对应节点
  368. /// </summary>
  369. /// <param name="element">输入element</param>
  370. /// <param name="outNode">成功获取时,node真实值</param>
  371. /// <returns>成功获取</returns>
  372. private static bool TryGetNode(Element element,out EquipmentNode outNode)
  373. {
  374. bool flag = false;
  375. EquipmentNode node = new EquipmentNode();
  376. if (element is Space space)
  377. {
  378. node.Category = PointItemType.Space.ToString();
  379. }
  380. else if (element is Pipe&& SystemCalcUtil.IsStart(element))
  381. {
  382. node.Category = PointItemType.StandPipe.ToString();
  383. }
  384. else if (element is FamilyInstance)
  385. {
  386. string tempCategory;
  387. if (MBIInfoUtil.TryGetEquipmentCategory(element,out tempCategory))
  388. {
  389. node.Category = tempCategory;
  390. node.IsRealEquipment = true;
  391. }
  392. else if (SystemCalcUtil.IsStart(element))
  393. {
  394. node.Category = PointItemType.StartValve.ToString();
  395. }
  396. }
  397. flag = !string.IsNullOrEmpty(node.Category);
  398. outNode = flag ? node : null;
  399. #region 确定返回之后进行后初始化处理
  400. if (outNode != null)
  401. {
  402. outNode.RevitId = element.Id.ToString();
  403. outNode.BimId = element.GetBimId();
  404. }
  405. #endregion
  406. return flag;
  407. }
  408. #endregion
  409. #region 创建立面绘图和关系数据
  410. /// <summary>
  411. /// 计算立面数据
  412. /// </summary>
  413. public static VerticalResult ComputerVerticalData(List<VerticalPipe> pipeDatas, List<LevelData> levelDatas)
  414. {
  415. List<VerticalDrawRecord> drawRecords = new List<VerticalDrawRecord>();
  416. List<VerticalRelationRecord> relationRecords = new List<VerticalRelationRecord>();
  417. #region 标高绘图数据整理
  418. List<VFloor> floors = new List<VFloor>();
  419. for (int i = 0; i < levelDatas.Count; i++)
  420. {
  421. var tempFloor = new VFloor();
  422. tempFloor.Name = levelDatas[i].Name;
  423. if (tempFloor.Name == "F1")
  424. {
  425. tempFloor.ValueDescription = "G";
  426. }
  427. tempFloor.Index = i;
  428. tempFloor.FloorId = i.ToString();
  429. tempFloor.LinkId = levelDatas[i].Id;
  430. floors.Add(tempFloor);
  431. }
  432. #endregion
  433. #region 立管或相当于立管的空间处理
  434. /*
  435. * 按系统分组,[一个空间会不会对应多个系统]
  436. */
  437. var comparer = new VpComparer();
  438. int groupId = 0;
  439. //按系统分组
  440. var goupSystems = pipeDatas.GroupBy(p => p.PipeSytemType);
  441. foreach (var groupSystem in goupSystems)
  442. {
  443. //按坐标分组
  444. foreach (var groupPosition in groupSystem.GroupBy(p=>p.DownPoint3D, comparer))
  445. {
  446. var currentGroupdId = ++groupId ;
  447. SetRelationItem set = new SetRelationItem();
  448. #region 处理绘图数据
  449. foreach (var groupFloor in groupPosition.GroupBy(p => p.LevelName))
  450. {
  451. var verData = groupFloor.FirstOrDefault();
  452. string floorId = floors.FirstOrDefault(c => c.Name == groupFloor.Key)?.FloorId;
  453. #region 生成存储核心数据
  454. VPipe pipe = new VPipe();
  455. pipe.LinkId = verData.Id;
  456. pipe.Name = string.Join(",", groupFloor.Select(v => v.Display));//verData.Display;
  457. pipe.Tip = verData.DisplayTip;
  458. pipe.PipeSystemType = verData.PipeSytemType;
  459. pipe.FloorId = floorId;
  460. #endregion
  461. VerticalDrawRecord drawRecord = new VerticalDrawRecord();
  462. drawRecord.GroupId = currentGroupdId.ToString();
  463. drawRecord.RefPipe = pipe;
  464. drawRecord.SystemName = groupSystem.Key;
  465. drawRecords.Add(drawRecord);
  466. set.AddRange(groupFloor.Select(v => string.Format("{0}:{1}", floorId, v.Id)));
  467. }
  468. #endregion
  469. #region 处理关系数据
  470. VerticalRelationRecord relationRecord = new VerticalRelationRecord();
  471. relationRecord.SystemName = groupSystem.Key;
  472. relationRecord.RelationItems = set;
  473. relationRecords.Add(relationRecord);
  474. #endregion
  475. }
  476. }
  477. #endregion
  478. VerticalResult result = new VerticalResult();
  479. result.DrawData = new VerticalDrawData() { LevelDatas = floors, DrawRecords = drawRecords };
  480. result.RelationData = relationRecords;
  481. return result;
  482. }
  483. #endregion
  484. #region 创建机房绘图数据
  485. /// <summary>
  486. /// 创建机房绘图数据
  487. /// </summary>
  488. /// <param name="document"></param>
  489. /// <returns></returns>
  490. public static SystemDrawItems CreateRoomDrawing(GplotDocument document)
  491. {
  492. List<SystemCurveItem> curveItems = new List<SystemCurveItem>();
  493. List<SystemPointItem> pointItems = new List<SystemPointItem>();
  494. foreach (var element in document.Elements)
  495. {
  496. if (element is TVertex vertex)
  497. {
  498. SystemPointItem point = new SystemPointItem();
  499. point.Point = vertex.Location;
  500. point.Name = vertex.Name;
  501. point.IsVirtual = vertex.VertexType != VertexType.Solid;
  502. pointItems.Add(point);
  503. continue;
  504. }
  505. if (element is TLine line)
  506. {
  507. SystemCurveItem curveItem = new SystemCurveItem();
  508. curveItem.Points.Add(line.StartPoint);
  509. curveItem.Points.Add(line.EndPoint);
  510. curveItems.Add(curveItem);
  511. continue;
  512. }
  513. if (element is TText text)
  514. {
  515. continue;
  516. }
  517. }
  518. SystemDrawItems drawItems = new SystemDrawItems();
  519. drawItems.Curves = curveItems;
  520. drawItems.Points = pointItems;
  521. return drawItems;
  522. }
  523. /// <summary>
  524. /// 创建机房绘图数据
  525. /// </summary>
  526. /// <param name="graphs"></param>
  527. /// <returns></returns>
  528. public static List<GNodeGraph> CreateRoomDrawing(List<SystemGraph> graphs)
  529. {
  530. List<GNodeGraph> nodeGraphs = new List<GNodeGraph>();
  531. foreach (var graph in graphs)
  532. {
  533. var edges = graph.GeFirstStateEdges();
  534. GNodeGraph nodeGraph = new GNodeGraph();
  535. foreach (var elementsEdge in edges)
  536. {
  537. GNodePath path = new GNodePath();
  538. //path.Id = elementsEdge.Id;
  539. path.StartNodeId = elementsEdge.StartVertex;
  540. path.EndNodeId = elementsEdge.EndVertex;
  541. nodeGraph.Paths.Add(path);
  542. }
  543. var vertexes = graph.GetBootVertexs();
  544. foreach (var elementsVertex in vertexes)
  545. {
  546. GNode node = new GNode();
  547. node.SetId(elementsVertex.Id);
  548. var equipmentItem = elementsVertex.GetEquipment();
  549. if (equipmentItem != null)
  550. {
  551. node.Name = equipmentItem.Name;
  552. }
  553. nodeGraph.Nodes.Add(node);
  554. }
  555. #region 调整入度为零的点的顺序
  556. var dic = BinaryRelationUtil.CreateVertexGroup<GNodePath>(new List<GNodePath>(nodeGraph.Paths),
  557. g => g.StartNodeId, g => g.EndNodeId);
  558. #region 原始值操作
  559. var inZeroVertexes = dic.Values.Where(r => r.InItems.Count == 0 && r.OutItems.Count != 0);
  560. GNode virtualNode = new GNode();
  561. virtualNode.SetId("-1");
  562. nodeGraph.Nodes.Insert(0,virtualNode);
  563. foreach (var relationVertexEntity in inZeroVertexes)
  564. {
  565. GNodePath path = new GNodePath();
  566. path.StartNodeId = virtualNode.Id;
  567. path.EndNodeId = relationVertexEntity.VertexId;
  568. nodeGraph.Paths.Add(path);
  569. }
  570. #endregion
  571. #endregion
  572. nodeGraphs.Add(nodeGraph);
  573. }
  574. return nodeGraphs;
  575. }
  576. /// <summary>
  577. /// 创建机房图关系
  578. /// </summary>
  579. /// <param name="graphs"></param>
  580. /// <returns></returns>
  581. public static List<EquipmentRelation> CreateRoomRelation(List<SystemGraph> graphs)
  582. {
  583. List<EquipmentRelation> relations = new List<EquipmentRelation>();
  584. foreach (var graph in graphs)
  585. {
  586. var sytemVertexes = graph.GetBootVertexs().Where(v => v.IsEquipment());
  587. var currentRelation = new List<EquipmentRelation>();
  588. foreach (SystemVertex vertex in sytemVertexes)
  589. {
  590. var paths = graph.GetPaths(vertex, v => v.IsEquipment());
  591. foreach (var path in paths)
  592. {
  593. if (path == null)
  594. {
  595. continue;
  596. }
  597. var firstEdge = path.FirstOrDefault()?.Path;
  598. var lastNode = path.LastOrDefault()?.NextNode;
  599. if (lastNode == null)
  600. {
  601. continue;
  602. }
  603. var tempRelation = new EquipmentRelation(vertex.GetEquipment(), lastNode.GetEquipment());
  604. if (currentRelation.Any(r => r.Id == tempRelation.Id))
  605. {
  606. continue;
  607. }
  608. string category = firstEdge?.EdgeCategory ?? string.Empty;
  609. tempRelation.LinkType = category;
  610. currentRelation.Add(tempRelation);
  611. }
  612. }
  613. relations.AddRange(currentRelation);
  614. }
  615. return relations;
  616. }
  617. #endregion
  618. }
  619. /// <summary>
  620. /// 点位置比较相关
  621. /// </summary>
  622. public class VpComparer : IEqualityComparer<Point3D>
  623. {
  624. /// <summary>
  625. /// 立管左右错开小于2Cm
  626. /// </summary>
  627. /// <param name="x"></param>
  628. /// <param name="y"></param>
  629. /// <returns></returns>
  630. public bool Equals(Point3D x, Point3D y)
  631. {//数据为英寸
  632. var diff = 2 * 10d / 304.8;
  633. return Math.Abs(x.X - y.X) <= diff && Math.Abs(x.Y - y.Y) <= diff;
  634. }
  635. public int GetHashCode(Point3D obj)
  636. {
  637. return 0;
  638. }
  639. }
  640. }