MeasurePropertyControl.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.Tool;
  3. using ComPDFKit.Controls.Measure.Property;
  4. using ComPDFKit.Controls.PDFControl;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using ComPDFKitViewer;
  20. namespace ComPDFKit.Controls.Measure
  21. {
  22. public partial class MeasurePropertyControl : UserControl
  23. {
  24. StraightnessProperty straightnessProperty = new StraightnessProperty();
  25. MultilineProperty multilineProperty = new MultilineProperty();
  26. PolygonalProperty polygonProperty = new PolygonalProperty();
  27. AnnotParam currentParam = null;
  28. public event EventHandler<LineMeasureParam> LineMeasureParamChanged;
  29. public event EventHandler<PolyLineMeasureParam> PolyLineMeasureParamChanged;
  30. public event EventHandler<PolygonMeasureParam> PolygonMeasureParamChanged;
  31. public C_ANNOTATION_TYPE CurrentCreateType
  32. {
  33. get;
  34. set;
  35. } = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
  36. private UIElement currentPanel = null;
  37. PDFViewControl pdfViewerControl;
  38. public MeasurePropertyControl()
  39. {
  40. InitializeComponent();
  41. straightnessProperty.LineMeasureParamChanged -= StraightnessProperty_LineMeasureParamChanged;
  42. multilineProperty.PolyLineMeasureParamChanged -= MultilineProperty_PolyLineMeasureParamChanged;
  43. polygonProperty.PolygonMeasureParamChanged -= PolygonProperty_PolygonMeasureParamChanged;
  44. multilineProperty.PolyLineMeasureParamChanged += MultilineProperty_PolyLineMeasureParamChanged;
  45. straightnessProperty.LineMeasureParamChanged += StraightnessProperty_LineMeasureParamChanged;
  46. polygonProperty.PolygonMeasureParamChanged += PolygonProperty_PolygonMeasureParamChanged;
  47. }
  48. private void PolygonProperty_PolygonMeasureParamChanged(object sender, PolygonMeasureParam e)
  49. {
  50. PolygonMeasureParamChanged?.Invoke(this, e);
  51. }
  52. private void MultilineProperty_PolyLineMeasureParamChanged(object sender, PolyLineMeasureParam e)
  53. {
  54. PolyLineMeasureParamChanged?.Invoke(this, e);
  55. }
  56. public void SetPropertyForMeasureCreate(AnnotParam param, CPDFAnnotation annot, PDFViewControl viewControl)
  57. {
  58. if (param == null)
  59. {
  60. ClearMeasurePanel();
  61. return;
  62. }
  63. if(annot == null)
  64. {
  65. CurrentCreateType = param.CurrentType;
  66. currentParam = param;
  67. }
  68. switch (param.CurrentType)
  69. {
  70. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  71. if (param is LineMeasureParam lineMeasureParam)
  72. {
  73. straightnessProperty.SetAnnotParam(lineMeasureParam, annot, viewControl);
  74. }
  75. currentPanel = straightnessProperty;
  76. break;
  77. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  78. if (param is PolyLineMeasureParam polyLineMeasureParam)
  79. {
  80. multilineProperty.SetAnnotParam(polyLineMeasureParam, annot, viewControl);
  81. }
  82. currentPanel = multilineProperty;
  83. break;
  84. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  85. if (param is PolygonMeasureParam polygonMeasureParam)
  86. {
  87. polygonProperty.SetAnnotParam(polygonMeasureParam, annot, viewControl);
  88. }
  89. currentPanel = polygonProperty;
  90. break;
  91. default:
  92. break;
  93. }
  94. SetMeasurePanel(currentPanel);
  95. }
  96. private void StraightnessProperty_LineMeasureParamChanged(object sender, LineMeasureParam e)
  97. {
  98. LineMeasureParamChanged?.Invoke(this, e);
  99. }
  100. private void SetMeasurePanel(UIElement newChild)
  101. {
  102. MeasurePropertyPanel.Child = newChild;
  103. }
  104. public void ClearMeasurePanel()
  105. {
  106. currentPanel = null;
  107. MeasurePropertyPanel.Child = null;
  108. }
  109. internal void InitWithPDFViewer(PDFViewControl pdfViewControl)
  110. {
  111. if (this.pdfViewerControl != null)
  112. {
  113. UnLoadPDFViewHandler();
  114. }
  115. this.pdfViewerControl = pdfViewControl;
  116. LoadPDFViewHandler();
  117. }
  118. private void LoadPDFViewHandler()
  119. {
  120. if (pdfViewerControl != null)
  121. {
  122. pdfViewerControl.MouseLeftButtonDown -= PdfViewerControl_MouseLeftButtonDown;
  123. pdfViewerControl.MouseLeftButtonDown += PdfViewerControl_MouseLeftButtonDown;
  124. }
  125. }
  126. private void PdfViewerControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  127. {
  128. SetAnnotEventData();
  129. }
  130. private void SetAnnotEventData()
  131. {
  132. if (pdfViewerControl.GetCacheHitTestAnnot() == null)
  133. {
  134. if (pdfViewerControl != null && (pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot))
  135. {
  136. switch (CurrentCreateType)
  137. {
  138. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  139. straightnessProperty.Annotation = null;
  140. straightnessProperty.SetAnnotParam(currentParam as LineMeasureParam, null, pdfViewerControl);
  141. break;
  142. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  143. multilineProperty.Annotation = null;
  144. multilineProperty.SetAnnotParam(currentParam as PolyLineMeasureParam, null, pdfViewerControl);
  145. break;
  146. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  147. polygonProperty.Annotation = null;
  148. polygonProperty.SetAnnotParam(currentParam as PolygonMeasureParam, null, pdfViewerControl);
  149. break;
  150. }
  151. ShowCreateAnnotPanel();
  152. }
  153. else
  154. {
  155. ClearMeasurePanel();
  156. }
  157. }
  158. }
  159. private void ShowCreateAnnotPanel()
  160. {
  161. switch (CurrentCreateType)
  162. {
  163. case C_ANNOTATION_TYPE.C_ANNOTATION_NONE:
  164. break;
  165. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  166. currentPanel = straightnessProperty;
  167. break;
  168. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  169. currentPanel = polygonProperty;
  170. break;
  171. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  172. currentPanel = multilineProperty;
  173. break;
  174. }
  175. SetMeasurePanel(currentPanel);
  176. }
  177. private void UnLoadPDFViewHandler()
  178. {
  179. }
  180. //public void SetPorpertyForMeasureModify(AnnotAttribEvent annotEvent)
  181. //{
  182. //}
  183. }
  184. }