MeasureSettingDialog.xaml.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. using ComPDFKit.Measure;
  2. using ComPDFKit.PDFAnnotation;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace Compdfkit_Tools.Measure
  17. {
  18. /// <summary>
  19. /// MeasureSettingDialog.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class MeasureSettingDialog : Window
  22. {
  23. public MeasureSettingDialog()
  24. {
  25. InitializeComponent();
  26. }
  27. public event EventHandler CancelEvent;
  28. public event EventHandler DoneEvent;
  29. public bool ReturnToInfoPanel { get; set; }
  30. //public List<AnnotHandlerEventArgs> UpdateArgsList { get; set; } = new List<AnnotHandlerEventArgs>();
  31. private void ButtonCancel_Click(object sender, RoutedEventArgs e)
  32. {
  33. //if (UpdateArgsList != null && UpdateArgsList.Count > 0)
  34. //{
  35. // ReturnToInfoPanel = false;
  36. //}
  37. //UpdateArgsList?.Clear();
  38. CancelEvent?.Invoke(this, e);
  39. ReturnToInfoPanel = false;
  40. Close();
  41. }
  42. private void ButtonDone_Click(object sender, RoutedEventArgs e)
  43. {
  44. SaveMeasureSetting();
  45. //if (UpdateArgsList != null && UpdateArgsList.Count > 0)
  46. //{
  47. // List<AnnotArgsType> allowTypeList = new List<AnnotArgsType>()
  48. // {
  49. // AnnotArgsType.LineMeasure,
  50. // AnnotArgsType.PolyLineMeasure,
  51. // AnnotArgsType.PolygonMeasure
  52. // };
  53. // foreach (AnnotHandlerEventArgs args in UpdateArgsList)
  54. // {
  55. // if (allowTypeList.Contains(args.EventType))
  56. // {
  57. // CPDFAnnotation pdfAnnot = args.GetPDFAnnot();
  58. // switch (pdfAnnot.Type)
  59. // {
  60. // case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  61. // {
  62. // CPDFLineAnnotation lineAnnot = (CPDFLineAnnotation)pdfAnnot;
  63. // if (lineAnnot.IsMersured())
  64. // {
  65. // CPDFDistanceMeasure lineMeasure = lineAnnot.GetDistanceMeasure();
  66. // CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
  67. // measureInfo.Precision = MeasureSetting.GetMeasureSavePrecision();
  68. // measureInfo.RulerBase = (float)MeasureSetting.RulerBase;
  69. // measureInfo.RulerBaseUnit = MeasureSetting.RulerBaseUnit;
  70. // measureInfo.RulerTranslate = (float)MeasureSetting.RulerTranslate;
  71. // measureInfo.RulerTranslateUnit = MeasureSetting.RulerTranslateUnit;
  72. // lineMeasure.SetMeasureInfo(measureInfo);
  73. // lineMeasure.SetMeasureScale(
  74. // measureInfo.RulerBase,
  75. // measureInfo.RulerBaseUnit,
  76. // measureInfo.RulerTranslate,
  77. // measureInfo.RulerTranslateUnit);
  78. // lineMeasure.UpdateAnnotMeasure();
  79. // lineAnnot.UpdateAp();
  80. // args.Draw();
  81. // }
  82. // }
  83. // break;
  84. // case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  85. // {
  86. // CPDFPolylineAnnotation polylineAnnot = (CPDFPolylineAnnotation)pdfAnnot;
  87. // if (polylineAnnot.IsMersured())
  88. // {
  89. // CPDFPerimeterMeasure polylineMeasure = polylineAnnot.GetPerimeterMeasure();
  90. // CPDFMeasureInfo measureInfo = polylineMeasure.MeasureInfo;
  91. // measureInfo.Precision = MeasureSetting.GetMeasureSavePrecision();
  92. // measureInfo.RulerBase = (float)MeasureSetting.RulerBase;
  93. // measureInfo.RulerBaseUnit = MeasureSetting.RulerBaseUnit;
  94. // measureInfo.RulerTranslate = (float)MeasureSetting.RulerTranslate;
  95. // measureInfo.RulerTranslateUnit = MeasureSetting.RulerTranslateUnit;
  96. // polylineMeasure.SetMeasureInfo(measureInfo);
  97. // polylineMeasure.SetMeasureScale(
  98. // measureInfo.RulerBase,
  99. // measureInfo.RulerBaseUnit,
  100. // measureInfo.RulerTranslate,
  101. // measureInfo.RulerTranslateUnit);
  102. // polylineMeasure.UpdateAnnotMeasure();
  103. // polylineAnnot.UpdateAp();
  104. // args.Draw();
  105. // }
  106. // }
  107. // break;
  108. // case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  109. // {
  110. // CPDFPolygonAnnotation areaAnnot = (CPDFPolygonAnnotation)pdfAnnot;
  111. // if (areaAnnot.IsMersured())
  112. // {
  113. // CPDFAreaMeasure areaMeasure = areaAnnot.GetAreaMeasure();
  114. // CPDFMeasureInfo measureInfo = areaMeasure.MeasureInfo;
  115. // measureInfo.Precision = MeasureSetting.GetMeasureSavePrecision();
  116. // measureInfo.RulerBase = (float)MeasureSetting.RulerBase;
  117. // measureInfo.RulerBaseUnit = MeasureSetting.RulerBaseUnit;
  118. // measureInfo.RulerTranslate = (float)MeasureSetting.RulerTranslate;
  119. // measureInfo.RulerTranslateUnit = MeasureSetting.RulerTranslateUnit;
  120. // measureInfo.CaptionType = CPDFCaptionType.CPDF_CAPTION_NONE;
  121. // if (MeasureSetting.IsShowArea)
  122. // {
  123. // measureInfo.CaptionType |= CPDFCaptionType.CPDF_CAPTION_AREA;
  124. // }
  125. // if (MeasureSetting.IsShowLength)
  126. // {
  127. // measureInfo.CaptionType |= CPDFCaptionType.CPDF_CAPTION_LENGTH;
  128. // }
  129. // areaMeasure.SetMeasureInfo(measureInfo);
  130. // areaMeasure.SetMeasureScale(
  131. // measureInfo.RulerBase,
  132. // measureInfo.RulerBaseUnit,
  133. // measureInfo.RulerTranslate,
  134. // measureInfo.RulerTranslateUnit);
  135. // areaMeasure.UpdateAnnotMeasure();
  136. // areaAnnot.UpdateAp();
  137. // args.Draw();
  138. // }
  139. // }
  140. // break;
  141. // default:
  142. // break;
  143. // }
  144. // }
  145. // }
  146. // ReturnToInfoPanel = false;
  147. //}
  148. //UpdateArgsList?.Clear();
  149. DoneEvent?.Invoke(this, e);
  150. ReturnToInfoPanel = false;
  151. Close();
  152. }
  153. private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
  154. {
  155. List<Key> allowKeys = new List<Key>()
  156. {
  157. Key.Delete, Key.Back, Key.Enter, Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3,
  158. Key.NumPad4, Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9, Key.D0,
  159. Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9, Key.Left, Key.Right,
  160. Key.OemPeriod,Key.Decimal
  161. };
  162. if (allowKeys.Contains(e.Key) == false)
  163. {
  164. e.Handled = true;
  165. }
  166. }
  167. private void TextBox_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  168. {
  169. try
  170. {
  171. if (e.Command == ApplicationCommands.Paste && Clipboard.ContainsText())
  172. {
  173. string checkText = Clipboard.GetText();
  174. if (int.TryParse(checkText, out int value))
  175. {
  176. e.CanExecute = true;
  177. }
  178. e.Handled = true;
  179. }
  180. }
  181. catch (Exception ex)
  182. {
  183. }
  184. }
  185. public void BindMeasureSetting()
  186. {
  187. //RulerBaseText.Text = MeasureSetting.RulerBase.ToString();
  188. //RulerTranslateText.Text = MeasureSetting.RulerTranslate.ToString();
  189. //RulerTranslateCombo.SelectedIndex = -1;
  190. //RulerBaseUnitCombo.SelectedIndex = -1;
  191. //PrecisionBox.SelectedIndex = -1;
  192. //if (MeasureSetting.RulerBaseUnit == "in")
  193. //{
  194. // RulerBaseUnitCombo.SelectedIndex = 0;
  195. //}
  196. //if (MeasureSetting.RulerBaseUnit == "cm")
  197. //{
  198. // RulerBaseUnitCombo.SelectedIndex = 1;
  199. //}
  200. //if (MeasureSetting.RulerBaseUnit == "mm")
  201. //{
  202. // RulerBaseUnitCombo.SelectedIndex = 2;
  203. //}
  204. //for (int i = 0; i < RulerTranslateCombo.Items.Count; i++)
  205. //{
  206. // ComboBoxItem checkItem = RulerTranslateCombo.Items[i] as ComboBoxItem;
  207. // if (checkItem != null && checkItem.Content.ToString() == MeasureSetting.RulerTranslateUnit.ToString())
  208. // {
  209. // RulerTranslateCombo.SelectedIndex = i;
  210. // }
  211. //}
  212. //for (int i = 0; i < PrecisionBox.Items.Count; i++)
  213. //{
  214. // ComboBoxItem checkItem = PrecisionBox.Items[i] as ComboBoxItem;
  215. // if (checkItem != null && checkItem.Content.ToString() == ((decimal)MeasureSetting.Precision).ToString())
  216. // {
  217. // PrecisionBox.SelectedIndex = i;
  218. // }
  219. //}
  220. }
  221. private void SaveMeasureSetting()
  222. {
  223. //if (double.TryParse(RulerBaseText.Text, out double ruleBase))
  224. //{
  225. // MeasureSetting.RulerBase = ruleBase;
  226. //}
  227. //if (RulerBaseUnitCombo.SelectedItem != null)
  228. //{
  229. // ComboBoxItem checkItem = RulerBaseUnitCombo.SelectedItem as ComboBoxItem;
  230. // MeasureSetting.RulerBaseUnit = checkItem.Content.ToString();
  231. //}
  232. //if (double.TryParse(RulerTranslateText.Text, out double ruletranBase))
  233. //{
  234. // MeasureSetting.RulerTranslate = ruletranBase;
  235. //}
  236. //if (RulerTranslateCombo.SelectedItem != null)
  237. //{
  238. // ComboBoxItem checkItem = RulerTranslateCombo.SelectedItem as ComboBoxItem;
  239. // MeasureSetting.RulerTranslateUnit = checkItem.Content.ToString();
  240. //}
  241. //if (PrecisionBox.SelectedValue != null)
  242. //{
  243. // ComboBoxItem checkItem = PrecisionBox.SelectedValue as ComboBoxItem;
  244. // if (double.TryParse(checkItem.Content.ToString(), out double precision))
  245. // {
  246. // MeasureSetting.Precision = precision;
  247. // }
  248. //}
  249. //MeasureSetting.IsShowArea = (bool)AreaCheckBox.IsChecked;
  250. //MeasureSetting.IsShowLength = (bool)LengthCheckBox.IsChecked;
  251. }
  252. public void ChangedCheckBoxIsChecked(bool Area, bool Lenght)
  253. {
  254. AreaCheckBox.IsChecked = Area;
  255. LengthCheckBox.IsChecked = Lenght;
  256. }
  257. }
  258. }