123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- using ComPDFKit.Tool.DrawTool;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Viewer.Layer;
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Input;
- namespace ComPDFKit.Tool
- {
- public class MultiSelectedData
- {
- public int PageIndex { get; set; }
- public List<int> MultiObjectIndex { get; set; }
- /// <summary>
- /// Current multi-select type
- /// </summary>
- public SelectedType ObjectType { get; set; }
- /// <summary>
- /// Move offset value of the whole
- /// </summary>
- public Point MoveOffset { get; set; }
- public float ZoomX { get; set; }
- public float ZoomY { get; set; }
- /// <summary>
- /// Multiple selection of movement distance
- /// </summary>
- public float ChangeX { get; set; }
- /// <summary>
- /// Multiple selection of movement distance
- /// </summary>
- public float ChangeY { get; set; }
- }
- public partial class CPDFViewerTool
- {
- public event EventHandler<MultiSelectedData> MultiDataChanging;
- public event EventHandler<MultiSelectedData> MultiDataChanged;
- public int MultiSelectedRectViewTag { get; set; } = -1;
- private List<int> editAreaMultiIndex = new List<int>();
- private int multiPage = -1;
- private bool isOpen = false;
- private Key multiKey = Key.LeftCtrl;
- private void InsertMultiSelectedRectView()
- {
- int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
- CustomizeLayer customizeLayer = new CustomizeLayer();
- MultiSelectedRect multiSelectedRect = new MultiSelectedRect(GetDefaultDrawParam(), SelectedType.None);
- multiSelectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- customizeLayer.Children.Add(multiSelectedRect);
- multiSelectedRect.DataChanged += MultiSelectedRect_DataChanged;
- multiSelectedRect.DataChanging += MultiSelectedRect_DataChanging;
- PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
- MultiSelectedRectViewTag = customizeLayer.GetResTag();
- //multiSelectedRect.Children.Add(multiSelectedRect);
- }
- private void MultiSelectedRect_DataChanging(object sender, Point e)
- {
- MultiSelectedData multiSelectedAnnotData = new MultiSelectedData();
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- multiSelectedAnnotData.ZoomX = multiSelectedRect.GetZoomX();
- multiSelectedAnnotData.ZoomY = multiSelectedRect.GetZoomY();
- multiSelectedAnnotData.ChangeX = multiSelectedRect.GetChangeX();
- multiSelectedAnnotData.ChangeY = multiSelectedRect.GetChangeY();
- multiSelectedAnnotData.MoveOffset = e;
- multiSelectedAnnotData.ObjectType = multiSelectedRect.GetSelectedType();
- multiSelectedAnnotData.MultiObjectIndex = new List<int>();
- multiSelectedAnnotData.MultiObjectIndex.AddRange(editAreaMultiIndex);
- multiSelectedAnnotData.PageIndex = multiPage;
- MultiDataChanging?.Invoke(this, multiSelectedAnnotData);
- }
- }
- private void MultiSelectedRect_DataChanged(object sender, Point e)
- {
- MultiSelectedData multiSelectedAnnotData = new MultiSelectedData();
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- multiSelectedAnnotData.ZoomX = multiSelectedRect.GetZoomX();
- multiSelectedAnnotData.ZoomY = multiSelectedRect.GetZoomY();
- multiSelectedAnnotData.ChangeX = multiSelectedRect.GetChangeX();
- multiSelectedAnnotData.ChangeY = multiSelectedRect.GetChangeY();
- multiSelectedAnnotData.MoveOffset = e;
- multiSelectedAnnotData.ObjectType = multiSelectedRect.GetSelectedType();
- multiSelectedAnnotData.MultiObjectIndex = new List<int>();
- multiSelectedAnnotData.MultiObjectIndex.AddRange(editAreaMultiIndex);
- multiSelectedAnnotData.PageIndex = multiPage;
- MultiDataChanged?.Invoke(this, multiSelectedAnnotData);
- }
- }
- /// <summary>
- /// Set multiple selection shortcut keys
- /// </summary>
- /// <param name="multikey"></param>
- public void SetMultiSelectKey(Key multikey)
- {
- multiKey = multikey;
- }
- private void OpenSelectedMulti(bool open)
- {
- isOpen = open;
- }
- public bool HitTestMultiSelectedRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- if (multiSelectedRect.GetHitControlIndex(Mouse.GetPosition(this)) != PointControlType.None)
- {
- return true;
- }
- }
- return false;
- }
- public void SelectedMultiRect(Rect selectedRects, Rect MaxRect, SelectedType type)
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- bool open = isOpen;
- if (!Keyboard.IsKeyDown(multiKey))
- {
- open = false;
- }
- if (open && multiSelectedRect != null)
- {
- lastSelectedRect.ClearDraw();
- lastSelectedRect.HideDraw();
- GetSelectedEditAreaForIndex(out int pageIndex, out int editAreaIndex);
- if (multiPage != pageIndex && editAreaMultiIndex.Count > 0)
- {
- foreach (int item in editAreaMultiIndex)
- {
- SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
- if (OldRect != null)
- {
- OldRect.Draw();
- }
- }
- editAreaMultiIndex.Clear();
- multiSelectedRect.ClearDraw();
- multiSelectedRect.CleanMulitSelectedRect();
- multiPage = pageIndex;
- }
- multiPage = pageIndex;
- if (startSelectedRect != null && startSelectedPageIndex == multiPage && !editAreaMultiIndex.Contains(startSelectedIndex))
- {
- //Add the first selected object
- editAreaMultiIndex.Add(startSelectedIndex);
- SelectedRect startselectedrect = new SelectedRect(GetDefaultDrawParam(), type);
- startselectedrect.SetEditPen(editPen, editHoverPen);
- startselectedrect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- startselectedrect.SetRect(startSelectedRect.GetRect(), currentZoom);
- startselectedrect.SetMaxRect(MaxRect);
- editAreaList.Add(startselectedrect, startSelectedEditAreaObject);
- multiSelectedRect.Children.Add(startselectedrect);
- multiSelectedRect.SetMulitSelectedRect(startselectedrect, startSelectedEditAreaObject.PageIndex, startSelectedEditAreaObject.EditAreaIndex);
- multiSelectedRect.SetRect(startselectedrect.GetRect());
- multiSelectedRect.SetMaxRect(startselectedrect.GetMaxRect());
- multiSelectedRect.Draw();
- }
- startSelectedRect = null;
- startSelectedIndex = -1;
- startSelectedPageIndex = -1;
- startSelectedEditAreaObject = null;
- editAreaMultiIndex.Add(editAreaIndex);
- multiSelectedRect.SetSelectedType(type);
- SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), type);
- selectedRect.SetEditPen(editPen, editHoverPen);
- selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- selectedRect.SetRect(selectedRects, currentZoom);
- selectedRect.SetMaxRect(MaxRect);
- EditAreaObject editAreaObject = GetEditAreaObjectForRect(lastSelectedRect);
- editAreaList.Add(selectedRect, editAreaObject);
- multiSelectedRect.Children.Add(selectedRect);
- multiSelectedRect.SetMulitSelectedRect(selectedRect, editAreaObject.PageIndex, editAreaObject.EditAreaIndex);
- multiSelectedRect.SetRect(selectedRects);
- multiSelectedRect.SetMaxRect(MaxRect);
- multiSelectedRect.Draw();
- }
- else
- {
- //Remember the first selected object
- isOpen = false;
- GetSelectedEditAreaForIndex(out int pageIndex, out int editAreaIndex);
- SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), type);
- selectedRect.SetEditPen(editPen, editHoverPen);
- selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- selectedRect.SetRect(selectedRects, currentZoom);
- selectedRect.SetMaxRect(MaxRect);
- EditAreaObject editAreaObject = GetEditAreaObjectForRect(lastSelectedRect);
- if (startSelectedIndex != editAreaIndex || startSelectedPageIndex != pageIndex)
- {
- startSelectedIndex = editAreaIndex;
- startSelectedPageIndex = pageIndex;
- startSelectedEditAreaObject = editAreaObject;
- startSelectedRect = selectedRect;
- editAreaList.Add(startSelectedRect, editAreaObject);
- }
- }
- }
- public void HideDrawSelectedMultiRect()
- {
- foreach (int item in editAreaMultiIndex)
- {
- SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
- if (OldRect != null)
- {
- OldRect.HideDraw();
- }
- }
- }
- public void CleanSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- multiSelectedRect.Children.Clear();
- multiSelectedRect.CleanMulitSelectedRect();
- editAreaMultiIndex.Clear();
- //Delete Multiple Selection Record List
- editAreaList.Clear();
- }
- }
- public void DrawStartSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- Point point = Mouse.GetPosition(this);
- multiSelectedRect.Draw();
- multiSelectedRect.OnMouseLeftButtonDown(point);
- }
- }
- public void DrawMoveSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null&& multiSelectedRect.Children.Count>0)
- {
- Point point = Mouse.GetPosition(this);
- multiSelectedRect.OnMouseMove(point, out bool Tag, PDFViewer.ActualWidth, PDFViewer.ActualHeight);
- }
- }
- public void DrawEndSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- Point point = Mouse.GetPosition(this);
- multiSelectedRect.OnMouseLeftButtonUp(point);
- }
- }
- public void ReDrawSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
- DrawEndFrameSelect();
- if (multiSelectedRect != null)
- {
- multiSelectedRect.ClearDraw();
- multiSelectedRect.CleanMulitSelectedRect();
- Point point = Mouse.GetPosition(this);
- switch (multiSelectedRect.GetSelectedType())
- {
- case SelectedType.Annot:
- SelectAnnot();
- break;
- case SelectedType.PDFEdit:
- SelectPDFEdit(multiSelectedRect);
- break;
- default:
- break;
- }
- multiSelectedRect.Draw();
- }
- }
- private void SelectAnnot()
- {
- CleanSelectedRect();
- }
- private void SelectPDFEdit(MultiSelectedRect multiSelectedRect)
- {
- //Delete Multiple Selection Box
- foreach (int item in editAreaMultiIndex)
- {
- SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
- if (OldRect != null)
- {
- multiSelectedRect.SetSelectedType(SelectedType.PDFEdit);
- //Optimize logic to prevent overlapping of multiple selected objects
- //SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.PDFEdit);
- //selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- //selectedRect.SetRect(OldRect.GetRect(), currentZoom);
- //selectedRect.SetMaxRect(OldRect.GetMaxRect());
- //multiSelectedRect.Children.Add(selectedRect);
- multiSelectedRect.SetMulitSelectedRect(OldRect, multiPage,item);
- multiSelectedRect.SetRect(OldRect.GetRect());
- multiSelectedRect.SetMaxRect(OldRect.GetMaxRect());
- OldRect.HideDraw();
- }
- }
- }
- }
- }
|