123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.Tool;
- using ComPDFKit.Controls.Measure.Property;
- using ComPDFKit.Controls.PDFControl;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using ComPDFKitViewer;
- namespace ComPDFKit.Controls.Measure
- {
- public partial class MeasurePropertyControl : UserControl
- {
- StraightnessProperty straightnessProperty = new StraightnessProperty();
- MultilineProperty multilineProperty = new MultilineProperty();
- PolygonalProperty polygonProperty = new PolygonalProperty();
- AnnotParam currentParam = null;
- public event EventHandler<LineMeasureParam> LineMeasureParamChanged;
- public event EventHandler<PolyLineMeasureParam> PolyLineMeasureParamChanged;
- public event EventHandler<PolygonMeasureParam> PolygonMeasureParamChanged;
- public C_ANNOTATION_TYPE CurrentCreateType
- {
- get;
- set;
- } = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
- private UIElement currentPanel = null;
- PDFViewControl pdfViewerControl;
- public MeasurePropertyControl()
- {
- InitializeComponent();
- straightnessProperty.LineMeasureParamChanged -= StraightnessProperty_LineMeasureParamChanged;
- multilineProperty.PolyLineMeasureParamChanged -= MultilineProperty_PolyLineMeasureParamChanged;
- polygonProperty.PolygonMeasureParamChanged -= PolygonProperty_PolygonMeasureParamChanged;
- multilineProperty.PolyLineMeasureParamChanged += MultilineProperty_PolyLineMeasureParamChanged;
- straightnessProperty.LineMeasureParamChanged += StraightnessProperty_LineMeasureParamChanged;
- polygonProperty.PolygonMeasureParamChanged += PolygonProperty_PolygonMeasureParamChanged;
- }
- private void PolygonProperty_PolygonMeasureParamChanged(object sender, PolygonMeasureParam e)
- {
- PolygonMeasureParamChanged?.Invoke(this, e);
- }
- private void MultilineProperty_PolyLineMeasureParamChanged(object sender, PolyLineMeasureParam e)
- {
- PolyLineMeasureParamChanged?.Invoke(this, e);
- }
- public void SetPropertyForMeasureCreate(AnnotParam param, CPDFAnnotation annot, PDFViewControl viewControl)
- {
- if (param == null)
- {
- ClearMeasurePanel();
- return;
- }
-
- if(annot == null)
- {
- CurrentCreateType = param.CurrentType;
- currentParam = param;
- }
- switch (param.CurrentType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- {
- if (param is LineMeasureParam lineMeasureParam)
- {
- straightnessProperty.SetAnnotParam(lineMeasureParam, annot, viewControl);
- SetMeasurePanel(straightnessProperty);
- return;
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- if (param is PolyLineMeasureParam polyLineMeasureParam)
- {
- multilineProperty.SetAnnotParam(polyLineMeasureParam, annot, viewControl);
- SetMeasurePanel(multilineProperty);
- return;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- if (param is PolygonMeasureParam polygonMeasureParam && (annot ==null || (annot as CPDFPolygonAnnotation).IsMeasured()))
- {
- polygonProperty.SetAnnotParam(polygonMeasureParam, annot, viewControl);
- SetMeasurePanel(polygonProperty);
- return;
- }
- break;
- default:
- break;
- }
- ClearMeasurePanel();
- }
- private void StraightnessProperty_LineMeasureParamChanged(object sender, LineMeasureParam e)
- {
- LineMeasureParamChanged?.Invoke(this, e);
- }
- private void SetMeasurePanel(UIElement newChild)
- {
- currentPanel = newChild;
- MeasurePropertyPanel.Child = newChild;
- }
- public void ClearMeasurePanel()
- {
- currentPanel = null;
- MeasurePropertyPanel.Child = null;
- }
- internal void InitWithPDFViewer(PDFViewControl pdfViewControl)
- {
- if (this.pdfViewerControl != null)
- {
- UnLoadPDFViewHandler();
- }
- this.pdfViewerControl = pdfViewControl;
- LoadPDFViewHandler();
- }
- private void LoadPDFViewHandler()
- {
- if (pdfViewerControl != null)
- {
- pdfViewerControl.MouseLeftButtonDown -= PdfViewerControl_MouseLeftButtonDown;
- pdfViewerControl.MouseLeftButtonDown += PdfViewerControl_MouseLeftButtonDown;
- }
- }
- private void PdfViewerControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- SetAnnotEventData();
- }
- private void SetAnnotEventData()
- {
- if (pdfViewerControl.GetCacheHitTestAnnot() == null)
- {
- if (pdfViewerControl != null && (pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot))
- {
- switch (CurrentCreateType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- straightnessProperty.Annotation = null;
- straightnessProperty.SetAnnotParam(currentParam as LineMeasureParam, null, pdfViewerControl);
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- multilineProperty.Annotation = null;
- multilineProperty.SetAnnotParam(currentParam as PolyLineMeasureParam, null, pdfViewerControl);
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- polygonProperty.Annotation = null;
- polygonProperty.SetAnnotParam(currentParam as PolygonMeasureParam, null, pdfViewerControl);
- break;
- }
- ShowCreateAnnotPanel();
- }
- else
- {
- ClearMeasurePanel();
- }
- }
- }
- private void ShowCreateAnnotPanel()
- {
- switch (CurrentCreateType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_NONE:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- currentPanel = straightnessProperty;
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- currentPanel = polygonProperty;
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- currentPanel = multilineProperty;
- break;
- }
- SetMeasurePanel(currentPanel);
- }
- private void UnLoadPDFViewHandler()
- {
- }
- //public void SetPorpertyForMeasureModify(AnnotAttribEvent annotEvent)
- //{
- //}
- }
- }
|