MeasureControl.xaml.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using ComPDFKit.Measure;
  2. using Compdfkit_Tools.Helper;
  3. using Compdfkit_Tools.PDFControl;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. namespace Compdfkit_Tools.Measure
  22. {
  23. /// <summary>
  24. /// MeasureControl.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class MeasureControl : UserControl
  27. {
  28. public MeasurePropertyControl measurePropertyControl = new MeasurePropertyControl();
  29. private CPDFDisplaySettingsControl displaySettingsControl;
  30. private PDFViewControl PdfViewControl = new PDFViewControl();
  31. private PanelState panelState = PanelState.GetInstance();
  32. public MeasureControl()
  33. {
  34. InitializeComponent();
  35. MeasureSetting.MeasureChanged += MeasureSetting_MeasureChanged;
  36. }
  37. private void MeasureSetting_MeasureChanged(object sender, MeasureEventArgs e)
  38. {
  39. InfoPanel.SetMeasureInfo(e);
  40. }
  41. #region Init PDFViewer
  42. public void InitWithPDFViewer(PDFViewControl pdfViewControl, CPDFViewer pdfViewer)
  43. {
  44. PdfViewControl = pdfViewControl;
  45. PdfViewControl.PDFView = pdfViewer;
  46. PDFMeasureTool.InitWithPDFViewer(pdfViewer, measurePropertyControl, this);
  47. FloatPageTool.InitWithPDFViewer(pdfViewer);
  48. PDFGrid.Child = PdfViewControl;
  49. panelState.PropertyChanged -= PanelState_PropertyChanged;
  50. panelState.PropertyChanged += PanelState_PropertyChanged;
  51. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  52. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
  53. }
  54. private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  55. {
  56. if (e == null || e.IsAnnotCreateReset)
  57. {
  58. return;
  59. }
  60. else
  61. {
  62. switch (e.GetAnnotTypes())
  63. {
  64. case AnnotArgsType.LineMeasure:
  65. LineMeasureArgs LineArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.LineMeasure).First() as LineMeasureArgs;
  66. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  67. measurePropertyControl.SetPropertyForMeasureCreate(LineArgs);
  68. break;
  69. case AnnotArgsType.PolygonMeasure:
  70. PolygonMeasureArgs polygonArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.PolygonMeasure).First() as PolygonMeasureArgs;
  71. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  72. measurePropertyControl.SetPropertyForMeasureCreate(polygonArgs);
  73. break;
  74. case AnnotArgsType.PolyLineMeasure:
  75. PolyLineMeasureArgs polyLineArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.PolyLineMeasure).First() as PolyLineMeasureArgs;
  76. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  77. measurePropertyControl.SetPropertyForMeasureCreate(polyLineArgs);
  78. break;
  79. }
  80. }
  81. }
  82. public void SetSettingsControl(CPDFDisplaySettingsControl cPDFDisplaySettingsControl)
  83. {
  84. displaySettingsControl = cPDFDisplaySettingsControl;
  85. }
  86. public void ClearAllToolState()
  87. {
  88. PDFMeasureTool.ClearAllToolState();
  89. }
  90. public void ClearViewerControl()
  91. {
  92. PDFGrid.Child = null;
  93. BotaContainer.Child = null;
  94. PropertyContainer.Child = null;
  95. displaySettingsControl = null;
  96. }
  97. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  98. {
  99. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  100. {
  101. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  102. }
  103. else if (e.PropertyName == nameof(PanelState.RightPanel))
  104. {
  105. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  106. {
  107. ExpandRightPropertyPanel(measurePropertyControl, Visibility.Visible);
  108. }
  109. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  110. {
  111. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  112. }
  113. else
  114. {
  115. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  116. }
  117. }
  118. }
  119. #endregion
  120. #region Expand and collapse Panel
  121. public void ExpandRightPropertyPanel(Visibility visible)
  122. {
  123. ExpandRightPropertyPanel(measurePropertyControl, visible);
  124. }
  125. public void ExpandNullRightPropertyPanel(Visibility visible)
  126. {
  127. ExpandRightPropertyPanel(null, visible);
  128. }
  129. public void ExpandViewSettings(Visibility visible)
  130. {
  131. SetViewSettings(displaySettingsControl, visible);
  132. }
  133. private void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  134. {
  135. PropertyContainer.Width = 260;
  136. PropertyContainer.Child = propertytPanel;
  137. PropertyContainer.Visibility = visible;
  138. }
  139. private void SetViewSettings(CPDFDisplaySettingsControl displaySettingsControl, Visibility visibility)
  140. {
  141. PropertyContainer.Child = displaySettingsControl;
  142. PropertyContainer.Visibility = visibility;
  143. }
  144. public void ExpandLeftPanel(bool isExpand)
  145. {
  146. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  147. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  148. if (isExpand)
  149. {
  150. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  151. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  152. }
  153. else
  154. {
  155. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  156. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  157. }
  158. }
  159. #endregion
  160. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  161. {
  162. }
  163. private void MeasureInfoPanel_SettingClick(object sender, EventArgs e)
  164. {
  165. SetInfoPanelVisble(false, true);
  166. SettingPanel.BindMeasureSetting();
  167. }
  168. private void SettingPanel_CancelEvent(object sender, EventArgs e)
  169. {
  170. SetInfoPanelVisble(true, false);
  171. }
  172. private void SettingPanel_DoneEvent(object sender, EventArgs e)
  173. {
  174. SetInfoPanelVisble(true, false);
  175. }
  176. public void SetInfoPanelVisble(bool measureInfo, bool measureSetting)
  177. {
  178. if(measureInfo)
  179. {
  180. InfoPanel.ClearMeasureInfo();
  181. }
  182. InfoPanel.Visibility = measureInfo ? Visibility.Visible : Visibility.Collapsed;
  183. SettingPanel.Visibility = measureSetting ? Visibility.Visible : Visibility.Collapsed;
  184. }
  185. public void SetMeasureInfoType(CPDFMeasureType measureType)
  186. {
  187. InfoPanel?.SetMeasureType(measureType);
  188. }
  189. }
  190. }