ReadSpaceCommand.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. using Autodesk.Revit.DB;
  8. using Autodesk.Revit.DB.Mechanical;
  9. using Newtonsoft.Json.Linq;
  10. using SAGA.DotNetUtils.Extend;
  11. using SAGA.MBI.DataArrange;
  12. using SAGA.MBI.Model;
  13. using SAGA.MBI.RequestData;
  14. using SAGA.Models;
  15. using SAGA.RevitUtils;
  16. using SAGA.RevitUtils.Extends;
  17. using Point = System.Windows.Point;
  18. namespace SAGA.GplotRelationComputerManage
  19. {
  20. /// <summary>
  21. /// 空间关系
  22. /// </summary>
  23. public class ReadSpaceCommand
  24. {
  25. List<FamilyInstance> m_doors;
  26. List<FamilyInstance> m_windows;
  27. private Dictionary<Space, List<BoundarySegment>> m_levelSpaceData;
  28. //存放所有层的楼层名称与所有空间边线
  29. Dictionary<string /*楼层*/, Dictionary<Space /*空间*/, List<BoundarySegment> /*边线*/>> allSpace =
  30. new Dictionary<string, Dictionary<Space, List<BoundarySegment>>>();
  31. /// <summary>
  32. /// 缓存所有楼层的空间,避免重复加载数据
  33. /// </summary>
  34. Dictionary<string /*楼层*/, List<Space> /*空间*/> allSpaces =
  35. new Dictionary<string, List<Space>>();
  36. /// <summary>
  37. /// 缓存所有转换后的空间对象
  38. /// </summary>
  39. List<SgSpace> allSgSpaces = new List<SgSpace>();
  40. private bool m_isDraw = false;
  41. List<SgSpace> m_sgSpaces;
  42. private Dictionary<string /*bimId*/, JObject /*类型*/> m_dicServerSpace;
  43. List<List<Point>> m_connectionLine = new List<List<Point>>();
  44. private Document m_doc;
  45. //需要进行上下比较房间类型
  46. private List<string> roomFunCtype = new List<string>() { "140","150","1A0","1B0" };
  47. /// <summary>
  48. /// 初始化数据集合
  49. /// </summary>
  50. void Init()
  51. {
  52. m_doors = new List<FamilyInstance>();
  53. m_windows = new List<FamilyInstance>();
  54. m_levelSpaceData = new Dictionary<Space, List<BoundarySegment>>();
  55. m_sgSpaces = new List<SgSpace>();
  56. }
  57. /// <summary>
  58. /// 向集合内添加空间,防止空间重复
  59. /// </summary>
  60. /// <param name="sgSpace"></param>
  61. public void AddSpaces(SgSpace sgSpace)
  62. {
  63. var space = m_sgSpaces.FirstOrDefault(t => t.Id == sgSpace.Id);
  64. if (sgSpace != null)
  65. {
  66. m_sgSpaces.Remove(space);
  67. }
  68. m_sgSpaces.Add(sgSpace);
  69. }
  70. /// <summary>
  71. /// 对所有模型进行空间计算
  72. /// </summary>
  73. public void Computer()
  74. {
  75. //缓存所有空间数据
  76. //查询所有设备
  77. // var str = new string[] { "Si" };//元空间为Si
  78. //List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
  79. //m_dicServerSpace = new Dictionary<string, JObject>();
  80. //datas.ForEach(t =>
  81. //{
  82. // var bimId = GetValue(t, "BIMID");
  83. // if (!string.IsNullOrEmpty(bimId))
  84. // {
  85. // m_dicServerSpace[bimId] = t;
  86. // }
  87. //});
  88. //打开所有楼层数据
  89. //Stopwatch watch = new Stopwatch();
  90. //watch.Start();
  91. var fileInfos = RevitModelPath.GetAllRevitFiles();//.Where(t => t.IndexOf("71062c") > -1);
  92. SpaceComputerContext context = new SpaceComputerContext();
  93. foreach (var fileInfo in fileInfos)
  94. {
  95. if (File.Exists(fileInfo))
  96. {
  97. //var uiApp = ExternalDataWrapper.Current.UiApp.Application;
  98. // var doc = uiApp.OpenDocumentFile(fileInfo);
  99. FloorSpaceItems floorItems = context.GetFloorItems(fileInfo);
  100. floorItems.Parse(context);
  101. floorItems.Document.Close();
  102. //ComputerSpace(doc);
  103. }
  104. }
  105. //MessageShow.Infomation((watch.ElapsedMilliseconds / 1000).ToString());
  106. //watch.Stop();
  107. //MessageShow.Infomation((watch.ElapsedMilliseconds / 1000).ToString());
  108. }
  109. /// <summary>
  110. /// 获取指定属性的值
  111. /// </summary>
  112. /// <param name="equip"></param>
  113. /// <param name="propertyName"></param>
  114. /// <returns></returns>
  115. public string GetValue(JObject equip, string propertyName)
  116. {
  117. // equip.GetValue("infos")
  118. string result = "";
  119. if (equip != null)
  120. {
  121. result = equip["infos"][propertyName] + "";
  122. }
  123. return result;
  124. }
  125. /// <summary>
  126. /// 读取Document里面的所有空间
  127. /// </summary>
  128. /// <param name="doc"></param>
  129. /// <param name="filePath"></param>
  130. /// <returns></returns>
  131. List<Space> GetSpaces(Document doc, string filePath = "")
  132. {
  133. if (string.IsNullOrEmpty(filePath))
  134. filePath = doc.PathName;
  135. var modelId = Path.GetFileNameWithoutExtension(filePath);
  136. Debug.Assert(modelId != null, nameof(modelId) + " != null");
  137. if (allSpaces.ContainsKey(modelId))
  138. {
  139. return allSpaces[modelId];
  140. }
  141. if (doc == null)
  142. {
  143. if (File.Exists(filePath))
  144. {
  145. var uiApp = ExternalDataWrapper.Current.UiApp.Application;
  146. doc = uiApp.OpenDocumentFile(filePath);
  147. }
  148. else
  149. return new List<Space>();
  150. }
  151. List<Space> spaces = doc.GetAllElements().Where(e => e is Space space && !space.Area.IsZero()).Cast<Space>().ToList();
  152. allSpaces.Add(modelId, spaces);
  153. return spaces;
  154. }
  155. /// <summary>
  156. /// 将Revit空间数据转换成可序列化的数据
  157. /// </summary>
  158. /// <param name="space"></param>
  159. /// <param name="isCreate"></param>
  160. /// <returns></returns>
  161. SgSpace GetSgSpace(Space space, bool isCreate = true)
  162. {
  163. var sgSpace = allSgSpaces.FirstOrDefault(t => t.Id == space.Id.ToString());
  164. if (sgSpace == null || !isCreate)
  165. {
  166. var floorId = space.Document.PathName.GetFileName();
  167. var bimID = string.Format($"{floorId}:{space.Id.ToString()}");
  168. var localName = space.Name;
  169. var spaceType = string.Empty;
  170. m_dicServerSpace.TryGetValue(bimID, out JObject jo);
  171. if (jo != null)
  172. {
  173. localName = GetValue(jo, "RoomLocalName");
  174. spaceType=GetValue(jo, "RoomFuncType");
  175. }
  176. sgSpace = new SgSpace()
  177. {
  178. Id = space.Id.ToString(),
  179. Name =string.IsNullOrEmpty(localName)? space.Name: localName,
  180. Point = space.Location.GetPoint().ToW2DPoint(),
  181. // Point = GetCenter(space).ToW2DPoint(),
  182. RoomFuncType = spaceType,
  183. BoundarySegment = ConvertBoundarySegmentTo2D(new LvSpace(space))
  184. };
  185. if (isCreate)
  186. allSgSpaces.Add(sgSpace);
  187. return sgSpace;
  188. }
  189. return sgSpace;
  190. }
  191. /// <summary>
  192. /// 计算空间关系
  193. /// </summary>
  194. /// <param name="doc"></param>
  195. public void ComputerSpace(Document doc)
  196. {
  197. m_doc = doc;
  198. Init();
  199. m_doors = doc.GetElements<FamilyInstance>(BuiltInCategory.OST_Doors);
  200. m_windows = doc.GetElements<FamilyInstance>(BuiltInCategory.OST_Windows);
  201. List<Space> spaces = GetSpaces(doc);
  202. #region 计算平面拓扑
  203. System.Diagnostics.Debug.WriteLine(DateTime.Now + "平面计算开始");
  204. //转换所有空间
  205. var dataSpaces = ConvertSpace(spaces);
  206. //根据边上的Element分组
  207. var groupSpaces = dataSpaces.GroupBy(t => t.EdgeElement.Id.IntegerValue).ToList();
  208. //合并公共构建,如果是面层墙则进行合并
  209. var datas = CombinElement(groupSpaces);
  210. foreach (var groupSpace in datas)
  211. {
  212. var lSpaces = groupSpace.Value;
  213. var count = lSpaces.Count;
  214. if (count > 1)
  215. {
  216. for (int i = 0; i < count; i++)
  217. {
  218. var ls1 = lSpaces[i];
  219. var mySpace = ls1.Space;
  220. SgSpace currSgSpace = GetSgSpace(mySpace);
  221. AddSpaces(currSgSpace);
  222. for (int j = i + 1; j < count; j++)
  223. {
  224. var ls2 = lSpaces[j];
  225. var space = ls2.Space;
  226. if (mySpace.Id.IsEqual(space.Id)) continue;
  227. var sgSpace = GetSgSpace(space, false);
  228. //如果关系已经存在
  229. if ((sgSpace.AdjacentSpaces.Any(t => t.Space.Id == currSgSpace.Id) || currSgSpace.AdjacentSpaces.Any(t => t.Space.Id == sgSpace.Id))) continue;
  230. //分别做投影
  231. Curve curve1 = GetProjectLine(ls1.Edge, ls1.SegEdge);
  232. Curve curve2 = GetProjectLine(ls1.Edge, ls2.SegEdge);
  233. //判断投影是否相交或者包含
  234. //var isConn = curve2.Intersect(curve1) != SetComparisonResult.Disjoint;
  235. IntersectionResultArray ira;
  236. var isConn = curve2.Intersect(curve1, out ira) != SetComparisonResult.Disjoint;
  237. if (ira != null && ira.Size == 1) continue;
  238. var isVirtual = ls1.EType == typeof(ModelCurve);
  239. if (isConn)
  240. {
  241. //判断关系
  242. var spaceRelated = isVirtual
  243. ? SpaceRelatedEnum.All
  244. : JudgeDoorAndWindow(ls1.EdgeElement, curve1,
  245. curve2);
  246. var adjacentSpace = new AdjacentSpace()
  247. {
  248. Space = sgSpace,
  249. RelatedEnum = spaceRelated
  250. };
  251. currSgSpace.AdjacentSpaces.Add(adjacentSpace);
  252. m_connectionLine.Add(new List<Point>()
  253. {
  254. currSgSpace.Point,
  255. sgSpace.Point
  256. });
  257. }
  258. }
  259. }
  260. }
  261. }
  262. #endregion
  263. System.Diagnostics.Debug.WriteLine(DateTime.Now + "平面计算结束");
  264. var name = doc.Title;
  265. //上层模型名字
  266. var upFloor = GetUpFloorKey(name);
  267. if (upFloor != null)
  268. {
  269. var upSpaces = GetSpaces(null, upFloor.FullPath);
  270. var upLvSpaces = upSpaces.Select(t => new LvSpace(t)).ToList();
  271. var currLvSpaces = spaces.Select(t => new LvSpace(t));
  272. foreach (var lvSpace in currLvSpaces)
  273. {
  274. ComputerUpDownRelationship(lvSpace, upLvSpaces);
  275. }
  276. //判断上一层是否为夹层
  277. if (upFloor.FloorType == "4") //夹层为4
  278. {
  279. //取出夹层的上一层
  280. var upUpFloor = GetUpFloorKey(upFloor.FullPath);
  281. if (upUpFloor != null)
  282. {
  283. var upUpSpaces = GetSpaces(null, upUpFloor.FullPath);
  284. var upUpLvSpaces = upUpSpaces.Select(t => new LvSpace(t)).ToList();
  285. foreach (var lvSpace in currLvSpaces.Where(t => t.IsPaired == false))
  286. {
  287. ComputerUpDownRelationship(lvSpace, upUpLvSpaces);
  288. }
  289. }
  290. }
  291. }
  292. //保存数据到数据库
  293. var id = Regex.Replace(doc.PathName, @".+\\(\w+)\\(\w+).rvt$", "$1-$2");
  294. var saveName = DalProjectTree.GetFloorNameByFloorId(id.Split('-')[1]);
  295. var levels = doc.GetLevels();
  296. string levelName = saveName;
  297. var currLevels = levels.FirstOrDefault(t => t.Name.IndexOf("-saga") > -1);
  298. if (currLevels != null) levelName = currLevels.Name;
  299. FloorSpaceData floorData = new FloorSpaceData
  300. {
  301. Name = saveName,
  302. Id = id,
  303. LevelName = levelName.Replace("-saga", "")
  304. };
  305. m_sgSpaces.ForEach(s => floorData.EndPoints.Add(s));
  306. //获取标高名称,并按高度排序
  307. List<string> levelNames = levels.OrderBy(t => t.Elevation).Where(t => Regex.IsMatch(t.Name, "[F|B]")).Select(t => t.Name.Replace("-saga", "")).ToList();
  308. DrawDataServer.SaveSpaceFloorData(new List<FloorSpaceData>() { floorData }, levelNames);
  309. //换成楼层空间数据
  310. if (m_levelSpaceData.Count > 0 && !allSpace.ContainsKey(name))
  311. allSpace.Add(name, m_levelSpaceData);
  312. }
  313. /// <summary>
  314. /// 合并公共构件
  315. /// </summary>
  316. /// <param name="eleDatas"></param>
  317. /// <returns></returns>
  318. private List<KeyValuePair<int, List<SpaceEdgeInfo>>> CombinElement(List<IGrouping<int, SpaceEdgeInfo>> eleDatas)
  319. {
  320. var datas = eleDatas.ToDictionary(t => t.Key, t => t.ToList()).ToList();
  321. for (int i = datas.Count - 1; i >= 0; i--)
  322. {
  323. var d1 = datas[i];
  324. var e1 = d1.Value.FirstOrDefault().EdgeElement;
  325. var thickness1 = 0d;
  326. var line1 = GetElementLine(e1, out thickness1);
  327. if(line1==null)continue;
  328. var middle = line1.MiddlePoint();
  329. for (int j = i - 1; j >= 0; j--)
  330. {
  331. j = Math.Min(datas.Count-1, j);
  332. var d2 = datas[j];
  333. if (d2.Key == d1.Key) continue;
  334. var e2 = d2.Value.FirstOrDefault().EdgeElement;
  335. var thickness2 = 0d;
  336. var line2 = GetElementLine(e2, out thickness2);
  337. if(line2==null||line1==null)continue;
  338. if (line1.IsParallel(line2))//平行
  339. {
  340. //间距小于两个厚度之和的一半
  341. var project = line2.GetProjectPt(middle);
  342. var length = (middle - project).GetLength();
  343. if (((thickness1 + thickness2) / 2.0d).IsThanEq(length))
  344. {
  345. //将线投影到另外一条线上,两条线必须共线
  346. var projectLine = GetProjectLine(line1, line2);
  347. if (projectLine.Intersect(line1) != SetComparisonResult.Disjoint)
  348. {
  349. //合并两个Element,取长的保留
  350. if (line1.Length < line2.Length)
  351. {
  352. d2.Value.AddRange(d1.Value);
  353. datas.RemoveAll(t => t.Key == (d1.Key));
  354. }
  355. else
  356. {
  357. d1.Value.AddRange(d2.Value);
  358. datas.RemoveAll(t => t.Key == (d2.Key));
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. return datas;
  366. }
  367. /// <summary>
  368. /// 获取Element的厚度以及中轴线
  369. /// </summary>
  370. /// <param name="ele"></param>
  371. /// <param name="width"></param>
  372. /// <returns></returns>
  373. Line GetElementLine(Element ele, out double width)
  374. {
  375. width = 0;
  376. if (ele is Wall wall)
  377. {
  378. width = wall.WallType.GetParameterDouble(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);
  379. }
  380. return ele.GetLocationCurve().GetLine();
  381. }
  382. /// <summary>
  383. /// 获取Curve1在Curve2上的投影
  384. /// </summary>
  385. /// <param name="projectLine"></param>
  386. /// <param name="line"></param>
  387. /// <returns></returns>
  388. private Curve GetProjectLine(Curve projectLine, Curve line)
  389. {
  390. var startPoint = projectLine.GetProjectPt(line.StartPoint());
  391. var endPoint = projectLine.GetProjectPt(line.EndPoint());
  392. if (projectLine is Arc)
  393. {
  394. var middle = projectLine.GetProjectPt((startPoint + endPoint) / 2);
  395. return Arc.Create(startPoint, endPoint, middle);
  396. }
  397. return Line.CreateBound(startPoint, endPoint);
  398. }
  399. /// <summary>
  400. /// 判断当前两个空间是否有门窗
  401. /// </summary>
  402. /// <param name="wall"></param>
  403. /// <param name="curve1"></param>
  404. /// <param name="curve2"></param>
  405. /// <returns></returns>
  406. private SpaceRelatedEnum JudgeDoorAndWindow(Element wall, Curve curve1, Curve curve2)
  407. {
  408. var wallId = wall.Id;
  409. var wallWidth = (wall as Wall)?.WallType.Width;
  410. var z = curve1.StartPoint().Z;
  411. SpaceRelatedEnum spaceRelated = SpaceRelatedEnum.Adjacent;
  412. var doors = m_doors.Where(t => t.Host.Id.IsEqual(wallId));
  413. var windows = m_windows.Where(t => t.Host.Id.IsEqual(wallId));
  414. Predicate<XYZ> isHost = (point) =>
  415. {
  416. point = point.NewZ(z);
  417. //向两个线上做投影
  418. var point1 = curve1.GetProjectPt(point, false);
  419. var point2 = curve2.GetProjectPt(point, false);
  420. //定位点到两个投影的必须小于墙厚
  421. return (point - point1).GetLength() < wallWidth && (point - point2).GetLength() < wallWidth;
  422. };
  423. if (doors.Any(t => isHost(t.GetLocationPoint())))
  424. spaceRelated = spaceRelated | SpaceRelatedEnum.Crossing | SpaceRelatedEnum.Ventilation;
  425. if (windows.Any(t =>
  426. isHost(t.GetLocationPoint())))
  427. spaceRelated = spaceRelated | SpaceRelatedEnum.Radiation | SpaceRelatedEnum.Ventilation;
  428. return spaceRelated;
  429. }
  430. /// <summary>
  431. /// 计算上层相关联的空间
  432. /// </summary>
  433. /// <param name="space"></param>
  434. /// <param name="upSpaces"></param>
  435. void ComputerUpDownRelationship(LvSpace space, List<LvSpace> upSpaces)
  436. {
  437. var curves = space.ZeroCurves;
  438. var sgSpace = m_sgSpaces.FirstOrDefault(t => t.Id == space.Space.Id.ToString()) ?? GetSgSpace(space.Space, false);
  439. foreach (var upSpace in upSpaces)
  440. {
  441. if (ClosedIntersect(upSpace.ZeroCurves, curves))
  442. {
  443. space.IsPaired = true;
  444. var s = GetSgSpace(upSpace.Space, false);
  445. var related = SpaceRelatedEnum.Adjacent;
  446. //判断上下关系
  447. //TODO:此处取出空间类型属性,如果一致则建立关系,此处交通必须是一对一,如果不是,则不建立关系(1对多不建立关系)
  448. if (s.RoomFuncType == sgSpace.RoomFuncType && roomFunCtype.Contains(s.RoomFuncType))
  449. {
  450. related = related | SpaceRelatedEnum.Crossing;
  451. space.UpLvSpaces.Add(upSpace);
  452. }
  453. sgSpace.UpElements.Add(new AdjacentSpace()
  454. {
  455. Space = s,
  456. RelatedEnum = related
  457. });
  458. }
  459. }
  460. }
  461. /// <summary>
  462. /// 将空间轮廓转换成Win2d
  463. /// </summary>
  464. /// <param name="upSpace"></param>
  465. /// <returns></returns>
  466. private List<List<Point>> ConvertBoundarySegmentTo2D(LvSpace upSpace)
  467. {
  468. //取出边缘
  469. var datas = new List<List<Point>>();
  470. foreach (var curve in upSpace.ZeroCurves)
  471. {
  472. if (curve is Autodesk.Revit.DB.Line line)
  473. {
  474. // var line = segment.GetCurve().GetLine();
  475. datas.Add(new List<Point>(){
  476. line.GetEndPoint(0).ToW2DPoint()
  477. ,line.GetEndPoint(1).ToW2DPoint() });
  478. }
  479. else if (curve is Autodesk.Revit.DB.Arc arc)
  480. {
  481. datas.Add(arc.Tessellate().Select(xyz => xyz.ToW2DPoint()).ToList());
  482. }
  483. }
  484. return datas;
  485. }
  486. /// <summary>
  487. /// 判断两个区域是否相交或者相互包含
  488. /// </summary>
  489. /// <param name="closed1"></param>
  490. /// <param name="closed2"></param>
  491. /// <returns></returns>
  492. public bool ClosedIntersect(List<Curve> closed1, List<Curve> closed2)
  493. {
  494. //判断所有的线是否有相交
  495. foreach (var curve1 in closed1)
  496. {
  497. if (curve1.IsIntersectPoly(closed2)) return true;
  498. }
  499. //判断是否包含
  500. foreach (var curve in closed1)
  501. {
  502. if (curve.StartPoint().PointInPolygon(closed2)) return true;
  503. }
  504. return closed2.Any(curve => curve.StartPoint().PointInPolygon(closed1));
  505. }
  506. /// <summary>
  507. /// 获取上层空间信息
  508. /// </summary>
  509. /// <param name="key">楼层名称</param>
  510. /// <returns>上层楼层名称</returns>
  511. MFloor GetUpFloorKey(string key)
  512. {
  513. var modelName = System.IO.Path.GetFileNameWithoutExtension(key);
  514. MFloor floor = DalProjectTree.GetUpperFloor(modelName);
  515. return floor;
  516. }
  517. /// <summary>
  518. /// 将所有空间转换成边集合对象
  519. /// </summary>
  520. /// <param name="spaces"></param>
  521. /// <returns></returns>
  522. private List<SpaceEdgeInfo> ConvertSpace(List<Space> spaces)
  523. {
  524. var lSpaces = new List<SpaceEdgeInfo>();
  525. foreach (var space in spaces)
  526. {
  527. //如果空间内有多个柱子,每个柱子相当于一个封闭区域,也是一个List<BoundarySegment>,如果一个空间分隔符或者墙上有一个柱子,所在的空间轮廓就会多出两个边分别是柱子左边,柱子,柱子右边,他们三个的ElementId相同,getCurve不同
  528. IList<IList<BoundarySegment>> segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
  529. foreach (IList<BoundarySegment> boundarySegments in segments)
  530. {
  531. foreach (var segment in boundarySegments)
  532. {
  533. //去除不能构成边的元素
  534. if (segment.ElementId.IntegerValue != -1)
  535. {
  536. Curve wallLine = null;
  537. var elem = m_doc.GetElement(segment.ElementId);
  538. var type = typeof(object);
  539. //这里只处理墙和分隔符
  540. if (elem is Wall wall)
  541. {
  542. wallLine = wall.Location.GetCurve();
  543. type = typeof(Wall);
  544. }
  545. else if (elem is ModelCurve modelCurve)
  546. {
  547. wallLine = modelCurve.GetCurve();
  548. type = typeof(ModelCurve);
  549. }
  550. else
  551. {
  552. continue;
  553. }
  554. Curve segCurve1 = segment.GetCurve();
  555. lSpaces.Add(new SpaceEdgeInfo()
  556. {
  557. Space = space,
  558. Edge = wallLine,
  559. SegEdge = segCurve1,
  560. EdgeElement = elem,
  561. EType = type
  562. });
  563. }
  564. }
  565. }
  566. // var edgeCopy=Array.Copy()
  567. }
  568. return lSpaces;
  569. }
  570. }
  571. /// <summary>
  572. /// 比较轮廓边是否相等
  573. /// </summary>
  574. public class Comparea : IEqualityComparer<SpaceEdgeInfo>
  575. {
  576. public bool Equals(SpaceEdgeInfo x, SpaceEdgeInfo y)
  577. {
  578. return x.Space.Id.IsEqual(y.Space.Id);
  579. }
  580. public int GetHashCode(SpaceEdgeInfo obj)
  581. {
  582. return 0;
  583. }
  584. }
  585. }