CPDFViewerTool.MultiSelectedRect.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using ComPDFKit.Tool.DrawTool;
  2. using ComPDFKit.Tool.Help;
  3. using ComPDFKit.Viewer.Layer;
  4. using ComPDFKitViewer.Layer;
  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.Input;
  12. namespace ComPDFKit.Tool
  13. {
  14. public class MultiSelectedData
  15. {
  16. public int PageIndex { get; set; }
  17. public List<int> MultiObjectIndex { get; set; }
  18. /// <summary>
  19. /// Current multi-select type
  20. /// </summary>
  21. public SelectedType ObjectType { get; set; }
  22. /// <summary>
  23. /// Move offset value of the whole
  24. /// </summary>
  25. public Point MoveOffset { get; set; }
  26. public float ZoomX { get; set; }
  27. public float ZoomY { get; set; }
  28. }
  29. public partial class CPDFViewerTool
  30. {
  31. int multiSelectedRectViewTag = -1;
  32. List<int> editAreaMultiIndex = new List<int>();
  33. int multiPage = -1;
  34. public event EventHandler<MultiSelectedData> MultiDataChanging;
  35. public event EventHandler<MultiSelectedData> MultiDataChanged;
  36. private void InsertMultiSelectedRectView()
  37. {
  38. int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
  39. CustomizeLayer customizeLayer = new CustomizeLayer();
  40. MultiSelectedRect multiSelectedRect = new MultiSelectedRect(GetDefaultDrawParam(), SelectedType.None);
  41. multiSelectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
  42. customizeLayer.Children.Add(multiSelectedRect);
  43. multiSelectedRect.DataChanged += MultiSelectedRect_DataChanged;
  44. multiSelectedRect.DataChanging += MultiSelectedRect_DataChanging;
  45. PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
  46. multiSelectedRectViewTag = customizeLayer.GetResTag();
  47. //multiSelectedRect.Children.Add(multiSelectedRect);
  48. }
  49. private void MultiSelectedRect_DataChanging(object sender, Point e)
  50. {
  51. MultiSelectedData multiSelectedAnnotData = new MultiSelectedData();
  52. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  53. if (isOpen && multiSelectedRect != null)
  54. {
  55. multiSelectedAnnotData.ZoomX = multiSelectedRect.GetZoomX();
  56. multiSelectedAnnotData.ZoomY = multiSelectedRect.GetZoomY();
  57. multiSelectedAnnotData.MoveOffset = e;
  58. multiSelectedAnnotData.ObjectType = multiSelectedRect.GetSelectedType();
  59. multiSelectedAnnotData.MultiObjectIndex = new List<int>();
  60. multiSelectedAnnotData.MultiObjectIndex.AddRange(editAreaMultiIndex);
  61. multiSelectedAnnotData.PageIndex = multiPage;
  62. MultiDataChanging?.Invoke(this, multiSelectedAnnotData);
  63. }
  64. }
  65. private void MultiSelectedRect_DataChanged(object sender, Point e)
  66. {
  67. MultiSelectedData multiSelectedAnnotData = new MultiSelectedData();
  68. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  69. if (isOpen && multiSelectedRect != null)
  70. {
  71. multiSelectedAnnotData.ZoomX = multiSelectedRect.GetZoomX();
  72. multiSelectedAnnotData.ZoomY = multiSelectedRect.GetZoomY();
  73. multiSelectedAnnotData.MoveOffset = e;
  74. multiSelectedAnnotData.ObjectType = multiSelectedRect.GetSelectedType();
  75. multiSelectedAnnotData.MultiObjectIndex = new List<int>();
  76. multiSelectedAnnotData.MultiObjectIndex.AddRange(editAreaMultiIndex);
  77. multiSelectedAnnotData.PageIndex = multiPage;
  78. MultiDataChanged?.Invoke(this, multiSelectedAnnotData);
  79. }
  80. }
  81. bool isOpen = false;
  82. public void OpenSelectedMulti(bool open)
  83. {
  84. if (!open)
  85. {
  86. CleanSelectedMultiRect();
  87. }
  88. isOpen = open;
  89. }
  90. public bool HitTestMultiSelectedRect()
  91. {
  92. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  93. if (isOpen && multiSelectedRect != null)
  94. {
  95. if (multiSelectedRect.GetHitControlIndex(Mouse.GetPosition(this)) != PointControlType.None)
  96. {
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. public void SelectedMultiRect(Rect selectedRects, Rect MaxRect, SelectedType type)
  103. {
  104. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  105. if (isOpen && multiSelectedRect != null)
  106. {
  107. GetSelectedEditAreaForIndex(out int pageIndex, out int editAreaIndex);
  108. if (multiPage != pageIndex && editAreaMultiIndex.Count > 0)
  109. {
  110. foreach (int item in editAreaMultiIndex)
  111. {
  112. SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
  113. if (OldRect != null)
  114. {
  115. OldRect.Draw();
  116. }
  117. }
  118. editAreaMultiIndex.Clear();
  119. multiSelectedRect.ClearDraw();
  120. multiSelectedRect.CleanMulitSelectedRect();
  121. multiPage = pageIndex;
  122. }
  123. multiPage = pageIndex;
  124. editAreaMultiIndex.Add(editAreaIndex);
  125. multiSelectedRect.SetSelectedType(type);
  126. SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), type);
  127. selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
  128. selectedRect.SetRect(selectedRects,currentZoom);
  129. selectedRect.SetMaxRect(MaxRect);
  130. multiSelectedRect.Children.Add(selectedRect);
  131. multiSelectedRect.SetMulitSelectedRect(selectedRect);
  132. multiSelectedRect.SetRect(selectedRects);
  133. multiSelectedRect.SetMaxRect(MaxRect);
  134. multiSelectedRect.Draw();
  135. }
  136. }
  137. public void HideDrawSelectedMultiRect()
  138. {
  139. foreach (int item in editAreaMultiIndex)
  140. {
  141. SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
  142. if (OldRect != null)
  143. {
  144. OldRect.HideDraw();
  145. }
  146. }
  147. }
  148. public void CleanSelectedMultiRect()
  149. {
  150. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  151. if (multiSelectedRect != null)
  152. {
  153. multiSelectedRect.Children.Clear();
  154. multiSelectedRect.CleanMulitSelectedRect();
  155. editAreaMultiIndex.Clear();
  156. }
  157. }
  158. public void DrawStartSelectedMultiRect()
  159. {
  160. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  161. if (multiSelectedRect != null)
  162. {
  163. Point point = Mouse.GetPosition(this);
  164. multiSelectedRect.Draw();
  165. multiSelectedRect.OnMouseLeftButtonDown(point);
  166. }
  167. }
  168. public void DrawMoveSelectedMultiRect()
  169. {
  170. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  171. if (multiSelectedRect != null)
  172. {
  173. Point point = Mouse.GetPosition(this);
  174. multiSelectedRect.OnMouseMove(point, out bool Tag, PDFViewer.ActualWidth, PDFViewer.ActualHeight);
  175. }
  176. }
  177. public void DrawEndSelectedMultiRect()
  178. {
  179. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  180. if (multiSelectedRect != null)
  181. {
  182. Point point = Mouse.GetPosition(this);
  183. multiSelectedRect.OnMouseLeftButtonUp(point);
  184. }
  185. }
  186. public void ReDrawSelectedMultiRect()
  187. {
  188. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
  189. if (multiSelectedRect != null)
  190. {
  191. multiSelectedRect.ClearDraw();
  192. multiSelectedRect.CleanMulitSelectedRect();
  193. Point point = Mouse.GetPosition(this);
  194. switch (multiSelectedRect.GetSelectedType())
  195. {
  196. case SelectedType.Annot:
  197. SelectAnnot();
  198. break;
  199. case SelectedType.PDFEdit:
  200. SelectPDFEdit(multiSelectedRect);
  201. break;
  202. default:
  203. break;
  204. }
  205. multiSelectedRect.Draw();
  206. }
  207. }
  208. private void SelectAnnot()
  209. {
  210. CleanSelectedRect();
  211. }
  212. private void SelectPDFEdit(MultiSelectedRect multiSelectedRect)
  213. {
  214. foreach (int item in editAreaMultiIndex)
  215. {
  216. SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
  217. if (OldRect != null)
  218. {
  219. multiSelectedRect.SetSelectedType(SelectedType.PDFEdit);
  220. SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.PDFEdit);
  221. selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
  222. selectedRect.SetRect(OldRect.GetRect(),currentZoom);
  223. selectedRect.SetMaxRect(OldRect.GetMaxRect());
  224. multiSelectedRect.Children.Add(selectedRect);
  225. multiSelectedRect.SetMulitSelectedRect(selectedRect);
  226. multiSelectedRect.SetRect(OldRect.GetRect());
  227. multiSelectedRect.SetMaxRect(OldRect.GetMaxRect());
  228. OldRect.HideDraw();
  229. }
  230. }
  231. }
  232. }
  233. }