MeasureInfoPanel.xaml.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using ComPDFKit.Measure;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing.Drawing2D;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace Compdfkit_Tools.Measure
  19. {
  20. /// <summary>
  21. /// MeasureInfoPanel.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class MeasureInfoPanel : UserControl
  24. {
  25. public event EventHandler SettingClick;
  26. public CPDFMeasureType MeasureType { get; private set; }
  27. internal Dictionary<string, string> IconsDict { get; private set; } = new Dictionary<string, string>()
  28. {
  29. {
  30. "Distance Measurement",
  31. "M17.7782 5.75646L14.2427 2.22093L13.0052 3.45837L15.4802 5.93333L14.4195 6.99399L11.9446 4.51903L10.1768 " +
  32. "6.28679L12.6518 8.76175L11.5911 9.82241L9.11615 7.34745L7.34838 9.11522L9.82334 11.5902L8.76268 " +
  33. "12.6508L6.28772 10.1759L4.51996 11.9436L6.99492 14.4186L5.93426 15.4793L3.4593 13.0043L2.22186 " +
  34. "14.2417L5.75739 17.7773L17.7782 5.75646ZM15.3033 1.16027L14.2427 0.0996094L13.182 1.16027L1.1612 " +
  35. "13.1811L0.100539 14.2417L1.1612 15.3024L4.69673 18.8379L5.75739 19.8986L6.81805 18.8379L18.8389 " +
  36. "6.81712L19.8995 5.75646L18.8389 4.6958L15.3033 1.16027Z"
  37. },
  38. {
  39. "Multiline",
  40. "M0.5 3C0.5 1.89543 1.39543 1 2.5 1C3.33934 1 4.05793 1.51704 4.35462 2.25H15.6454C15.9421 1.51704 16.6607 1 " +
  41. "17.5 1C18.6046 1 19.5 1.89543 19.5 3C19.5 3.83934 18.983 4.55793 18.25 4.85462V17V17.75H17.5H13.7011L14.5167 " +
  42. "18.5765L13.5138 19.5928L11.4986 17.5505L10.9972 17.0423L11.4986 16.5342L13.5138 14.4918L14.5167 15.5082L13.7847 " +
  43. "16.25H16.75V4.85462C16.2487 4.65168 15.8483 4.25135 15.6454 3.75H4.35462C4.15168 4.25135 3.75135 4.65168 3.25 " +
  44. "4.85462V16.25H6.25V15H7.75V19H6.25V17.75H2.5H1.75V17V4.85462C1.01704 4.55793 0.5 3.83934 0.5 3Z"
  45. },
  46. {
  47. "Polygonal",
  48. "M1.37111 7.6963L10 1.42705L18.6289 7.6963L15.3329 17.8402H4.66705L1.37111 7.6963Z"
  49. }
  50. };
  51. public MeasureInfoPanel()
  52. {
  53. InitializeComponent();
  54. }
  55. internal void SetMeasureScale(CPDFMeasureType measureType, string scale)
  56. {
  57. switch (measureType)
  58. {
  59. case CPDFMeasureType.CPDF_DISTANCE_MEASURE:
  60. ScaleText.Text = scale;
  61. break;
  62. case CPDFMeasureType.CPDF_PERIMETER_MEASURE:
  63. ScalePolyLineText.Text = scale;
  64. break;
  65. case CPDFMeasureType.CPDF_AREA_MEASURE:
  66. ScalePolygonText.Text = scale;
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. public void SetMeasureType(CPDFMeasureType newType)
  73. {
  74. MeasureType=newType;
  75. int iconIndex = (int)newType;
  76. LinePanel.Visibility = Visibility.Collapsed;
  77. PolyLinePanel.Visibility = Visibility.Collapsed;
  78. PolygonPanel.Visibility = Visibility.Collapsed;
  79. if (iconIndex>=0 && iconIndex< IconsDict.Count)
  80. {
  81. TypeConverter typeCovert = TypeDescriptor.GetConverter(typeof(Geometry));
  82. MeasureIcon.Data = PathGeometry.CreateFromGeometry((Geometry)typeCovert.ConvertFrom(IconsDict.ElementAt(iconIndex).Value));
  83. MeasureTitelText.Text = IconsDict.ElementAt(iconIndex).Key;
  84. switch(newType)
  85. {
  86. case CPDFMeasureType.CPDF_DISTANCE_MEASURE:
  87. LinePanel.Visibility = Visibility.Visible;
  88. MeasureIcon.Fill = new SolidColorBrush(Color.FromRgb(0x43, 0x47, 0x4D));
  89. MeasureIcon.Stroke = null;
  90. break;
  91. case CPDFMeasureType.CPDF_PERIMETER_MEASURE:
  92. PolyLinePanel.Visibility = Visibility.Visible;
  93. MeasureIcon.Fill = new SolidColorBrush(Color.FromRgb(0x43, 0x47, 0x4D));
  94. MeasureIcon.Stroke = null;
  95. break;
  96. case CPDFMeasureType.CPDF_AREA_MEASURE:
  97. PolygonPanel.Visibility = Visibility.Visible;
  98. MeasureIcon.Fill = null;
  99. MeasureIcon.Stroke=new SolidColorBrush(Color.FromRgb(0x43,0x47,0x4D));
  100. break;
  101. default:
  102. break;
  103. }
  104. }
  105. }
  106. public void ClearMeasureInfo()
  107. {
  108. DistanceText.Text = string.Empty;
  109. PrecisionText.Text = string.Empty;
  110. AngleText.Text = string.Empty;
  111. XText.Text = string.Empty;
  112. YText.Text = string.Empty;
  113. ScaleText.Text= string.Empty;
  114. DistancePolyLineText.Text = string.Empty;
  115. PrecisionPolyLineText.Text = string.Empty;
  116. AnglePolyLineText.Text = string.Empty;
  117. ScalePolyLineText.Text = string.Empty;
  118. ScalePolygonText.Text=string.Empty;
  119. RoundPolygonText.Text = string.Empty;
  120. PrecisionPolygonText.Text = string.Empty;
  121. AnglePolygonText.Text = string.Empty;
  122. }
  123. //public void SetMeasureInfo(MeasureEventArgs info)
  124. //{
  125. // switch(info.Type)
  126. // {
  127. // case CPDFMeasureType.CPDF_DISTANCE_MEASURE:
  128. // {
  129. // DistanceText.Text=info.Distance;
  130. // PrecisionText.Text= ((decimal)info.Precision).ToString();
  131. // AngleText.Text = info.Angle.ToString()+"°";
  132. // XText.Text=info.MousePos.X.ToString();
  133. // YText.Text=info.MousePos.Y.ToString();
  134. // ScaleText.Text = string.Format("{0} {1} = {2} {3}",
  135. // info.RulerBase,
  136. // info.RulerBaseUnit,
  137. // info.RulerTranslate,
  138. // info.RulerTranslateUnit);
  139. // }
  140. // break;
  141. // case CPDFMeasureType.CPDF_PERIMETER_MEASURE:
  142. // {
  143. // DistancePolyLineText.Text = info.Distance;
  144. // PrecisionPolyLineText.Text = ((decimal)info.Precision).ToString();
  145. // AnglePolyLineText.Text = info.Angle.ToString() + "°";
  146. // ScalePolyLineText.Text = string.Format("{0} {1} = {2} {3}",
  147. // info.RulerBase,
  148. // info.RulerBaseUnit,
  149. // info.RulerTranslate,
  150. // info.RulerTranslateUnit);
  151. // }
  152. // break;
  153. // case CPDFMeasureType.CPDF_AREA_MEASURE:
  154. // {
  155. // RoundPolygonText.Text = info.Area;
  156. // PrecisionPolygonText.Text = ((decimal)info.Precision).ToString();
  157. // AnglePolygonText.Text = info.Angle.ToString() + "°";
  158. // ScalePolygonText.Text = string.Format("{0} {1} = {2} {3}",
  159. // info.RulerBase,
  160. // info.RulerBaseUnit,
  161. // info.RulerTranslate,
  162. // info.RulerTranslateUnit);
  163. // }
  164. // break;
  165. // default:
  166. // break;
  167. // }
  168. //}
  169. private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  170. {
  171. SettingClick?.Invoke(this, e);
  172. }
  173. }
  174. }