WinMachineRoomView.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. using DrawData;
  17. using SAGA.DotNetUtils.Logger;
  18. using SAGA.GplotRelationComputerManage.Draw;
  19. using SAGA.Models;
  20. using SAGA.Models.GplotElement;
  21. using SAGA.RevitUtils.Windows;
  22. namespace SAGA.GplotDrawData
  23. {
  24. /// <summary>
  25. /// WinMachineRoomView.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class WinMachineRoomView : WinBase
  28. {
  29. public WinMachineRoomView()
  30. {
  31. InitializeComponent();
  32. Vertex.SetRadius(6, 6);
  33. }
  34. public Func<List<DocumentNode>> LoadData;
  35. private ObservableCollection<DocumentNode> DocumentNodes { get; set; }
  36. protected override void OnLoaded(object sender, RoutedEventArgs e)
  37. {
  38. base.OnLoaded(sender, e);
  39. DocumentNodes = new ObservableCollection<DocumentNode>(this.LoadData?.Invoke()??new List<DocumentNode>());
  40. this.TreeRootNode.ItemsSource = DocumentNodes;
  41. if (DocumentNodes.Any())
  42. {
  43. SetSelectedItem(DocumentNodes[0].GetLeaves().FirstOrDefault() as DocumentNode);
  44. }
  45. }
  46. private void SetSelectedItem(DocumentNode node)
  47. {
  48. node.IsSelected = true;
  49. node.IsExpanded = true;
  50. var parent = node.Parent;
  51. while (parent != null)
  52. {
  53. parent.IsExpanded = true;
  54. parent = parent.Parent;
  55. }
  56. RootNode_OnSelectedItemChanged(null, null);
  57. }
  58. #region 事件相关
  59. private void RootNode_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  60. {
  61. if (TreeRootNode.SelectedItem is DocumentNode ln)
  62. {
  63. Draw(ln);
  64. }
  65. }
  66. #endregion
  67. private void Draw(DocumentNode docNode)
  68. {
  69. if (docNode?.LinkDocument == null)
  70. return;
  71. GplotDocument document = docNode.LinkDocument;
  72. RoomGraphView view = new RoomGraphView();
  73. var db = view.CreateDb(document);
  74. var strJson=db.CreateJsonStrGroup();
  75. File.WriteAllText(@"c:\roomCl.json", strJson);
  76. var panel = ucShowElement.Canvas;
  77. panel.Children.Clear();
  78. //DrawDocumentUtil.CoordiateMatrix = DrawDocumentUtil.CreateMatrix(ucShowElement, document.GetRect());
  79. var transformGroup = new TransformGroup();
  80. transformGroup.Children.Add(new MatrixTransform(DrawDocumentUtil.CreateMatrix(ucShowElement.viewer, document.GetRect())));
  81. panel.RenderTransform = transformGroup;
  82. DrawDocumentUtil.Draw(document, panel);
  83. }
  84. }
  85. }