TreeNodeViewModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System.Collections.ObjectModel;
  2. using Microsoft.Practices.Prism.ViewModel;
  3. using NLog;
  4. namespace BehaviorTree
  5. {
  6. public class TreeNodeViewModel : NotificationObject
  7. {
  8. private static double width = 80;
  9. private static double height = 50;
  10. private double connectorX2 = 0;
  11. private double connectorY2 = 0;
  12. private TreeNode treeNode;
  13. private TreeNodeViewModel parent;
  14. private ObservableCollection<TreeNodeViewModel> children = new ObservableCollection<TreeNodeViewModel>();
  15. private Logger logger = LogManager.GetCurrentClassLogger();
  16. public TreeNodeViewModel(TreeNode treeNode, TreeNodeViewModel parent)
  17. {
  18. this.treeNode = treeNode;
  19. this.parent = parent ?? this;
  20. if (this.parent == this)
  21. {
  22. connectorX2 = 0;
  23. connectorY2 = this.Height / 2;
  24. }
  25. else
  26. {
  27. connectorX2 = this.Parent.Width + this.Parent.X - this.X;
  28. connectorY2 = this.Parent.Height / 2 + this.Parent.Y - this.Y;
  29. }
  30. }
  31. public double Width
  32. {
  33. get
  34. {
  35. return width;
  36. }
  37. set
  38. {
  39. width = value;
  40. }
  41. }
  42. public double Height
  43. {
  44. get
  45. {
  46. return height;
  47. }
  48. set
  49. {
  50. height = value;
  51. }
  52. }
  53. public double X
  54. {
  55. get
  56. {
  57. return treeNode.X;
  58. }
  59. set
  60. {
  61. if (treeNode.X == value)
  62. {
  63. return;
  64. }
  65. treeNode.X = value;
  66. RaisePropertyChanged("X");
  67. this.ConnectorX2 = this.Parent.Width + this.Parent.X - this.X;
  68. foreach (var child in Children)
  69. {
  70. child.ConnectorX2 = this.Width + treeNode.X - child.X;
  71. }
  72. }
  73. }
  74. public double Y
  75. {
  76. get
  77. {
  78. return treeNode.Y;
  79. }
  80. set
  81. {
  82. if (treeNode.Y == value)
  83. {
  84. return;
  85. }
  86. treeNode.Y = value;
  87. RaisePropertyChanged("Y");
  88. ConnectorY2 = this.Parent.Height / 2 + this.Parent.Y - this.Y;
  89. foreach (var child in Children)
  90. {
  91. child.ConnectorY2 = this.Height / 2 + treeNode.Y - child.Y;
  92. }
  93. }
  94. }
  95. public double ConnectorX1
  96. {
  97. get
  98. {
  99. return 0;
  100. }
  101. }
  102. public double ConnectorY1
  103. {
  104. get
  105. {
  106. return this.Height / 2;
  107. }
  108. }
  109. public double ConnectorX2
  110. {
  111. get
  112. {
  113. if (this.Parent == this)
  114. {
  115. return 0;
  116. }
  117. return this.connectorX2;
  118. }
  119. set
  120. {
  121. this.connectorX2 = value;
  122. RaisePropertyChanged("ConnectorX2");
  123. }
  124. }
  125. public double ConnectorY2
  126. {
  127. get
  128. {
  129. if (this.Parent == this)
  130. {
  131. return this.Height / 2;
  132. }
  133. return this.connectorY2;
  134. }
  135. set
  136. {
  137. this.connectorY2 = value;
  138. RaisePropertyChanged("ConnectorY2");
  139. }
  140. }
  141. public int Type
  142. {
  143. get
  144. {
  145. return treeNode.Type;
  146. }
  147. set
  148. {
  149. if (treeNode.Type == value)
  150. {
  151. return;
  152. }
  153. treeNode.Type = value;
  154. RaisePropertyChanged("Type");
  155. }
  156. }
  157. public TreeNodeViewModel Parent
  158. {
  159. get
  160. {
  161. return parent;
  162. }
  163. set
  164. {
  165. parent = value;
  166. }
  167. }
  168. public ObservableCollection<TreeNodeViewModel> Children
  169. {
  170. get
  171. {
  172. return children;
  173. }
  174. set
  175. {
  176. children = value;
  177. }
  178. }
  179. }
  180. }