WinDrawSpace-Web.xaml.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using CEFSharpWPF;
  6. using SAGA.GplotRelationComputerManage;
  7. using SAGA.Models;
  8. namespace SAGA.GplotDrawData
  9. {
  10. /// <summary>
  11. /// WinDrawSpace_Web.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class WinDrawSpace_Web : Window
  14. {
  15. public GplotShowType ShowType{ get; private set; }
  16. public WinDrawSpace_Web()
  17. {
  18. InitializeComponent();
  19. }
  20. public WinDrawSpace_Web(GplotShowType showType) : this()
  21. {
  22. this.ShowType = showType;
  23. this.Loaded += WinDrawWaterNode_Loaded;
  24. }
  25. private void WinDrawWaterNode_Loaded(object sender, RoutedEventArgs e)
  26. {
  27. try
  28. {
  29. if (ShowType == GplotShowType.VerticalPlan)
  30. {
  31. InitVerticalSpaces();
  32. }
  33. else
  34. {
  35. InitHSpaceTree();
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. DotNetUtils.Others.MessageShowBase.Show(ex);
  41. }
  42. }
  43. #region 立面空间处理
  44. /// <summary>
  45. /// 立面空间相关数据源
  46. /// </summary>
  47. public void InitVerticalSpaces()
  48. {
  49. var spaceData = SpaceComputerDataUtil.GetSpaceDataByType(SpaceRelatedEnum.Crossing);
  50. if (spaceData == null)
  51. return;
  52. InitVSpaceTree(spaceData.FloorDatas);
  53. }
  54. /// <summary>
  55. /// 绘制立面空间
  56. /// </summary>
  57. private void DrawVSpaces(DataNode node)
  58. {
  59. if (node == null)
  60. return;
  61. VirticalSpaceGraphView view = new VirticalSpaceGraphView();
  62. view.SpaceType = node.Sno;
  63. var db = view.CreateDb(node.GetData<BuildingItemData>());
  64. ConstData.ResponseData = db.CreateJObjectGroup();
  65. ucShowElement.Show(WebGplotSettings.VSpaceUrl);
  66. }
  67. public void InitVSpaceTree(List<FloorSpaceData> floorItems)
  68. {
  69. List<DataNode> treeData = new List<DataNode>();
  70. var buildGroup = floorItems.GroupBy(f => f.BuildingId);
  71. foreach (var build in buildGroup)
  72. {
  73. var tempFloors = build.ToList();
  74. var firstFloor = tempFloors.FirstOrDefault();
  75. if (firstFloor == null)
  76. {
  77. continue;
  78. }
  79. BuildingItemData buildItem = new BuildingItemData();
  80. buildItem.Id = firstFloor.BuildingId;
  81. buildItem.Name = firstFloor.BuildingName;
  82. buildItem.FloorDataItems.AddRange(tempFloors);
  83. var items = tempFloors.Select(f => f.LevelName).ToList();
  84. //items.Reverse();
  85. buildItem.Levels.AddRange(items);
  86. var buildNode = new DataNode() {EName = firstFloor.BuildingName, Sno = firstFloor.BuildingId};
  87. buildNode.Childrens.Add(new DataNode() { EName = "楼梯间", Sno = "140" });
  88. buildNode.Childrens.Add(new DataNode() { EName = "中庭", Sno = "150" });
  89. buildNode.Childrens.Add(new DataNode() { EName = "竖井", Sno = "1B0" });
  90. buildNode.Childrens.Add(new DataNode() { EName = "其他公共区域", Sno = "1A0" });
  91. buildNode.Childrens.ForEach(dn => dn.SetData(buildItem));
  92. treeData.Add(buildNode);
  93. }
  94. this.rootNode.ItemsSource = treeData;
  95. }
  96. #endregion
  97. private void RootNode_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  98. {
  99. if (rootNode.SelectedItem is DataNode ln)
  100. {
  101. if (ln.Childrens.Count != 0)
  102. {
  103. return;
  104. }
  105. if (ShowType == GplotShowType.ViewPlan)
  106. {
  107. Draw(ln);
  108. }
  109. else
  110. {
  111. DrawVSpaces(ln);
  112. }
  113. }
  114. }
  115. #region 平面处理
  116. private void Draw(DataNode dataNode)
  117. {
  118. var fd = dataNode.GetData<FloorSpaceData>();
  119. if (fd == null)
  120. {
  121. MessageBox.Show("楼层数据不存在");
  122. return;
  123. }
  124. SpaceGraphView view = new SpaceGraphView();
  125. var db = view.CreateDb(fd);
  126. ConstData.ResponseData = db.CreateJObjectGroup();
  127. ucShowElement.Show(WebGplotSettings.GplotUrl);
  128. }
  129. private void InitHSpaceTree()
  130. {
  131. /*
  132. * 层级结构:(建筑名称--空间关系)--四种关系--楼层
  133. */
  134. var buildNodes = new List<DataNode>();
  135. Dictionary<SpaceRelatedEnum, string> seeds = new Dictionary<SpaceRelatedEnum, string>();
  136. seeds[SpaceRelatedEnum.Adjacent] = "空间临接关系";
  137. seeds[SpaceRelatedEnum.Crossing] = "建筑交通关系";
  138. seeds[SpaceRelatedEnum.Ventilation] = "空气流通关系";
  139. seeds[SpaceRelatedEnum.Radiation] = "光照辐射关系";
  140. foreach (var seed in seeds)
  141. {
  142. var spaceDatas = SpaceComputerDataUtil.GetSpaceDataByType(seed.Key);
  143. if (spaceDatas == null)
  144. continue;
  145. var floorItems = spaceDatas.FloorDatas;
  146. var buildGroup = floorItems.GroupBy(f => f.BuildingId);
  147. foreach (var build in buildGroup)
  148. {
  149. var buildFloors = build.ToList();
  150. var firstFloor = buildFloors.FirstOrDefault();
  151. if (firstFloor == null)
  152. {
  153. continue;
  154. }
  155. #region 检测建筑节点
  156. var buildNode = buildNodes.FirstOrDefault(dn => dn.Sno == build.Key);
  157. if (buildNode == null)
  158. {
  159. buildNode = new DataNode() { EName = $"[{firstFloor.BuildingName}]--空间关系", Sno = firstFloor.BuildingId };
  160. buildNodes.Add(buildNode);
  161. }
  162. #endregion
  163. DataNode relationNode = new DataNode(seed.Value)
  164. {
  165. Childrens = buildFloors.Reverse<FloorSpaceData>().Select(f =>
  166. {
  167. var floorNode = new DataNode(f.Name);
  168. floorNode.SetData(f);
  169. return floorNode;
  170. }).ToList()
  171. };
  172. buildNode?.Childrens.Add(relationNode);
  173. }
  174. }
  175. this.rootNode.ItemsSource = buildNodes;
  176. }
  177. #endregion
  178. }
  179. }