MeasurePropertyControl.xaml.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. {
  72. if (param is LineMeasureParam lineMeasureParam)
  73. {
  74. straightnessProperty.SetAnnotParam(lineMeasureParam, annot, viewControl);
  75. SetMeasurePanel(straightnessProperty);
  76. return;
  77. }
  78. }
  79. break;
  80. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  81. if (param is PolyLineMeasureParam polyLineMeasureParam)
  82. {
  83. multilineProperty.SetAnnotParam(polyLineMeasureParam, annot, viewControl);
  84. SetMeasurePanel(multilineProperty);
  85. return;
  86. }
  87. break;
  88. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  89. if (param is PolygonMeasureParam polygonMeasureParam && (annot ==null || (annot as CPDFPolygonAnnotation).IsMeasured()))
  90. {
  91. polygonProperty.SetAnnotParam(polygonMeasureParam, annot, viewControl);
  92. SetMeasurePanel(polygonProperty);
  93. return;
  94. }
  95. break;
  96. default:
  97. break;
  98. }
  99. ClearMeasurePanel();
  100. }
  101. private void StraightnessProperty_LineMeasureParamChanged(object sender, LineMeasureParam e)
  102. {
  103. LineMeasureParamChanged?.Invoke(this, e);
  104. }
  105. private void SetMeasurePanel(UIElement newChild)
  106. {
  107. currentPanel = newChild;
  108. MeasurePropertyPanel.Child = newChild;
  109. }
  110. public void ClearMeasurePanel()
  111. {
  112. currentPanel = null;
  113. MeasurePropertyPanel.Child = null;
  114. }
  115. internal void InitWithPDFViewer(PDFViewControl pdfViewControl)
  116. {
  117. if (this.pdfViewerControl != null)
  118. {
  119. UnLoadPDFViewHandler();
  120. }
  121. this.pdfViewerControl = pdfViewControl;
  122. LoadPDFViewHandler();
  123. }
  124. private void LoadPDFViewHandler()
  125. {
  126. if (pdfViewerControl != null)
  127. {
  128. pdfViewerControl.MouseLeftButtonDown -= PdfViewerControl_MouseLeftButtonDown;
  129. pdfViewerControl.MouseLeftButtonDown += PdfViewerControl_MouseLeftButtonDown;
  130. }
  131. }
  132. private void PdfViewerControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  133. {
  134. SetAnnotEventData();
  135. }
  136. private void SetAnnotEventData()
  137. {
  138. if (pdfViewerControl.GetCacheHitTestAnnot() == null)
  139. {
  140. if (pdfViewerControl != null && (pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot))
  141. {
  142. switch (CurrentCreateType)
  143. {
  144. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  145. straightnessProperty.Annotation = null;
  146. straightnessProperty.SetAnnotParam(currentParam as LineMeasureParam, null, pdfViewerControl);
  147. break;
  148. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  149. multilineProperty.Annotation = null;
  150. multilineProperty.SetAnnotParam(currentParam as PolyLineMeasureParam, null, pdfViewerControl);
  151. break;
  152. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  153. polygonProperty.Annotation = null;
  154. polygonProperty.SetAnnotParam(currentParam as PolygonMeasureParam, null, pdfViewerControl);
  155. break;
  156. }
  157. ShowCreateAnnotPanel();
  158. }
  159. else
  160. {
  161. ClearMeasurePanel();
  162. }
  163. }
  164. }
  165. private void ShowCreateAnnotPanel()
  166. {
  167. switch (CurrentCreateType)
  168. {
  169. case C_ANNOTATION_TYPE.C_ANNOTATION_NONE:
  170. break;
  171. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  172. currentPanel = straightnessProperty;
  173. break;
  174. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  175. currentPanel = polygonProperty;
  176. break;
  177. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  178. currentPanel = multilineProperty;
  179. break;
  180. }
  181. SetMeasurePanel(currentPanel);
  182. }
  183. private void UnLoadPDFViewHandler()
  184. {
  185. }
  186. //public void SetPorpertyForMeasureModify(AnnotAttribEvent annotEvent)
  187. //{
  188. //}
  189. }
  190. }