LinkBase.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. using System.ComponentModel;
  5. using System.Windows.Documents;
  6. namespace SHJX.Service.WorkFlowEdit
  7. {
  8. public abstract class LinkBase : DiagramItem, ILink, INotifyPropertyChanged
  9. {
  10. #region Properties
  11. #region CanRelink Property
  12. public bool CanRelink
  13. {
  14. get { return (bool)GetValue(CanRelinkProperty); }
  15. set { SetValue(CanRelinkProperty, value); }
  16. }
  17. public static readonly DependencyProperty CanRelinkProperty =
  18. DependencyProperty.Register("CanRelink", typeof(bool), typeof(LinkBase), new FrameworkPropertyMetadata(true));
  19. #endregion
  20. private IPort _source;
  21. public IPort Source
  22. {
  23. get { return _source; }
  24. set
  25. {
  26. if (_source != null)
  27. _source.Links.Remove(this);
  28. _source = value;
  29. if (_source != null)
  30. _source.Links.Add(this);
  31. }
  32. }
  33. private IPort _target;
  34. public IPort Target
  35. {
  36. get { return _target; }
  37. set
  38. {
  39. if (_target != null)
  40. _target.Links.Remove(this);
  41. _target = value;
  42. if (_target != null)
  43. _target.Links.Add(this);
  44. }
  45. }
  46. public Point? SourcePoint { get; set; }
  47. public Point? TargetPoint { get; set; }
  48. private bool _startCap;
  49. public bool StartCap
  50. {
  51. get { return _startCap; }
  52. set
  53. {
  54. _startCap = value;
  55. OnPropertyChanged("StartCap");
  56. }
  57. }
  58. private bool _endCap;
  59. public bool EndCap
  60. {
  61. get { return _endCap; }
  62. set
  63. {
  64. _endCap = value;
  65. OnPropertyChanged("EndCap");
  66. }
  67. }
  68. private Brush _brush = new SolidColorBrush(Colors.Black);
  69. public Brush Brush
  70. {
  71. get { return _brush; }
  72. set { _brush = value; }
  73. }
  74. private Point _startPoint;
  75. public Point StartPoint
  76. {
  77. get { return _startPoint; }
  78. protected set
  79. {
  80. _startPoint = value;
  81. OnPropertyChanged("StartPoint");
  82. }
  83. }
  84. private Point _endPoint;
  85. public Point EndPoint
  86. {
  87. get { return _endPoint; }
  88. protected set
  89. {
  90. _endPoint = value;
  91. OnPropertyChanged("EndPoint");
  92. }
  93. }
  94. private double _startCapAngle;
  95. public double StartCapAngle
  96. {
  97. get { return _startCapAngle; }
  98. protected set
  99. {
  100. _startCapAngle = value;
  101. OnPropertyChanged("StartCapAngle");
  102. }
  103. }
  104. private double _endCapAngle;
  105. public double EndCapAngle
  106. {
  107. get { return _endCapAngle; }
  108. protected set
  109. {
  110. _endCapAngle = value;
  111. OnPropertyChanged("EndCapAngle");
  112. }
  113. }
  114. private PathGeometry _pathGeomtry;
  115. public PathGeometry PathGeometry
  116. {
  117. get { return _pathGeomtry; }
  118. protected set
  119. {
  120. _pathGeomtry = value;
  121. OnPropertyChanged("PathGeometry");
  122. }
  123. }
  124. private Point _labelPosition;
  125. public Point LabelPosition
  126. {
  127. get { return _labelPosition; }
  128. set
  129. {
  130. _labelPosition = value;
  131. OnPropertyChanged("LabelPosition");
  132. }
  133. }
  134. #region Label Property
  135. public string Label
  136. {
  137. get { return (string)GetValue(LabelProperty); }
  138. set { SetValue(LabelProperty, value); }
  139. }
  140. public static readonly DependencyProperty LabelProperty =
  141. DependencyProperty.Register("Label", typeof(string), typeof(LinkBase));
  142. #endregion
  143. public override Rect Bounds
  144. {
  145. get
  146. {
  147. var x = Math.Min(StartPoint.X, EndPoint.X);
  148. var y = Math.Min(StartPoint.Y, EndPoint.Y);
  149. var mx = Math.Max(StartPoint.X, EndPoint.X);
  150. var my = Math.Max(StartPoint.Y, EndPoint.Y);
  151. return new Rect(x, y, mx - x, my - y);
  152. }
  153. }
  154. #endregion
  155. protected LinkBase()
  156. {
  157. UpdatePath();
  158. }
  159. protected override Adorner CreateSelectionAdorner()
  160. {
  161. return new SelectionAdorner(this, new RelinkControl());
  162. }
  163. public abstract void UpdatePath();
  164. #region INotifyPropertyChanged Members
  165. public event PropertyChangedEventHandler PropertyChanged;
  166. protected void OnPropertyChanged(string name)
  167. {
  168. PropertyChangedEventHandler handler = PropertyChanged;
  169. if (handler != null)
  170. handler(this, new PropertyChangedEventArgs(name));
  171. }
  172. #endregion
  173. }
  174. }