ShapFillPropertyViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer;
  3. using Prism.Mvvm;
  4. using Prism.Regions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Media;
  12. using Prism.Commands;
  13. using System.Windows.Controls;
  14. using ComPDFKit.PDFAnnotation;
  15. using PDF_Office.Helper;
  16. using System.Diagnostics;
  17. using PDF_Office.Model;
  18. using PDF_Office.ViewModels.Tools;
  19. using Microsoft.Office.Interop.Excel;
  20. using Point = System.Windows.Point;
  21. namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
  22. {
  23. public class ShapFillPropertyViewModel : BindableBase, INavigationAware
  24. {
  25. public AnnotAttribEvent AnnotEvent { get; set; }
  26. private AnnotHandlerEventArgs Annot;
  27. private AnnotPropertyPanel PropertyPanel;
  28. private FillAndSignContentViewModel fillAndSignContentViewModel;
  29. private Geometry dataPath = null;
  30. public Geometry DataPath
  31. {
  32. get { return dataPath; }
  33. set
  34. {
  35. SetProperty(ref dataPath, value);
  36. }
  37. }
  38. private Brush selectColor = new SolidColorBrush(Colors.GreenYellow);
  39. public Brush SelectColor
  40. {
  41. get { return selectColor; }
  42. set
  43. {
  44. SetProperty(ref selectColor, value);
  45. fillAndSignContentViewModel.SelectColor = value;
  46. fillAndSignContentViewModel.SetStamp();
  47. }
  48. }
  49. private double fillOpacity = 1;
  50. public double FillOpacity
  51. {
  52. get { return fillOpacity; }
  53. set
  54. {
  55. SetProperty(ref fillOpacity, value);
  56. fillAndSignContentViewModel.FillOpacity = value;
  57. fillAndSignContentViewModel.SetStamp( );
  58. }
  59. }
  60. private bool _isMultiSelected = false;
  61. public bool IsMultiSelected
  62. {
  63. get { return _isMultiSelected; }
  64. set => SetProperty(ref _isMultiSelected, value);
  65. }
  66. private double lineWidth = 1;
  67. public double LineWidth
  68. {
  69. get { return lineWidth; }
  70. set
  71. {
  72. SetProperty(ref lineWidth, value);
  73. fillAndSignContentViewModel.LineWidth = value;
  74. fillAndSignContentViewModel.SetStamp();
  75. }
  76. }
  77. public DelegateCommand<object> SelectedThickCommand { get; set; }
  78. public DelegateCommand<object> SelectedColorCommand { get; set; }
  79. //public DelegateCommand<object> LineStyleCommand { get; set; }
  80. public DelegateCommand<object> SharpsTypeCommand { get; set; }
  81. public DelegateCommand<object> ThicknessChangedCommand { get; set; }
  82. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  83. public ShapFillPropertyViewModel()
  84. {
  85. SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
  86. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  87. //LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
  88. SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
  89. ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
  90. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  91. }
  92. private void SharpsType_Command(object obj)
  93. {
  94. if (obj != null)
  95. {
  96. var tag = (string)obj;
  97. SharpsType(tag,obj);
  98. }
  99. }
  100. private void SharpsType(string tag, object obj, bool isFromToolsBtn = false)
  101. {
  102. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  103. switch (tag)
  104. {
  105. case "HookShape":
  106. var hookShape = new PathGeometry();
  107. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  108. DataPath = hookShape;
  109. changeData[AnnotArgsType.AnnotLine] = tag;
  110. break;
  111. case "ForkShape":
  112. var forkShape = new PathGeometry();
  113. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  114. DataPath = forkShape;
  115. changeData[AnnotArgsType.AnnotLine] = tag;
  116. break;
  117. case "RectShape":
  118. {
  119. RectangleGeometry rectPath = new RectangleGeometry();
  120. rectPath.Rect = new Rect(0, 5, 28, 22);
  121. DataPath = rectPath;
  122. changeData[AnnotArgsType.AnnotSquare] = tag;
  123. }
  124. break;
  125. case "LineShape":
  126. {
  127. var lineShape = new PathGeometry();
  128. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  129. DataPath = lineShape;
  130. changeData[AnnotArgsType.AnnotLine] = tag;
  131. }
  132. break;
  133. case "DotShape":
  134. {
  135. EllipseGeometry circlePath = new EllipseGeometry();
  136. circlePath.RadiusX = 2.4;
  137. circlePath.RadiusY = 2.4;
  138. circlePath.Center = new Point(2.4,2.4);
  139. DataPath = circlePath;
  140. changeData[AnnotArgsType.AnnotCircle] = tag;
  141. }
  142. break;
  143. }
  144. //if (isFromToolsBtn == false)
  145. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  146. }
  147. private void InitSharpsType(string tag)
  148. {
  149. switch (tag)
  150. {
  151. case "HookShape":
  152. var hookShape = new PathGeometry();
  153. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  154. DataPath = hookShape;
  155. break;
  156. case "ForkShape":
  157. var forkShape = new PathGeometry();
  158. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  159. DataPath = forkShape;
  160. break;
  161. case "RectShape":
  162. {
  163. RectangleGeometry rectPath = new RectangleGeometry();
  164. rectPath.Rect = new Rect(0, 5, 28, 22);
  165. DataPath = rectPath;
  166. }
  167. break;
  168. case "LineShape":
  169. {
  170. var lineShape = new PathGeometry();
  171. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  172. DataPath = lineShape;
  173. }
  174. break;
  175. case "DotShape":
  176. {
  177. EllipseGeometry circlePath = new EllipseGeometry();
  178. circlePath.RadiusX = 2.4;
  179. circlePath.RadiusY = 2.4;
  180. circlePath.Center = new Point(2.4, 2.4);
  181. DataPath = circlePath;
  182. }
  183. break;
  184. }
  185. //if (isFromToolsBtn == false)
  186. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  187. }
  188. private void SelectedThick_Command(object obj)
  189. {
  190. if (obj is double)
  191. {
  192. var tran = (double)obj;
  193. //BorderOpacity = tran;
  194. SelectColor.Opacity = tran;
  195. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
  196. //AnnotEvent?.UpdateAnnot();
  197. }
  198. }
  199. private void ThicknessChanged_Command(object obj)
  200. {
  201. if (obj != null)
  202. {
  203. var item = (ComboBoxItem)obj;
  204. var content = (string)item.Content;
  205. if (content != null)
  206. {
  207. var intData = int.Parse(content);
  208. LineWidth = intData;
  209. }
  210. }
  211. }
  212. private void SelectedColor_Command(object obj)
  213. {
  214. if (obj != null)
  215. {
  216. var colorValue = (Color)obj;
  217. if (colorValue != null)
  218. {
  219. SelectColor = new SolidColorBrush(colorValue);
  220. SelectColor.Opacity = FillOpacity;
  221. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  222. changeData[AnnotArgsType.AnnotFreehand] = obj;
  223. //PropertyPanel.DataChangedInvoke(this, changeData);
  224. }
  225. }
  226. }
  227. private void SelectedOpacityValue(object obj)
  228. {
  229. if (obj != null)
  230. {
  231. FillOpacity = (double)obj;
  232. SelectColor.Opacity = FillOpacity;
  233. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
  234. //AnnotEvent?.UpdateAnnot();
  235. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  236. changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
  237. //PropertyPanel.DataChangedInvoke(this, changeData);
  238. }
  239. }
  240. public bool IsNavigationTarget(NavigationContext navigationContext)
  241. {
  242. return true;
  243. }
  244. public void OnNavigatedFrom(NavigationContext navigationContext)
  245. {
  246. }
  247. public void OnNavigatedTo(NavigationContext navigationContext)
  248. {
  249. string shape = "";
  250. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  251. navigationContext.Parameters.TryGetValue<FillAndSignContentViewModel>("FillAndSignContentViewModel", out fillAndSignContentViewModel);
  252. navigationContext.Parameters.TryGetValue<string>("Shape", out shape);
  253. InitSharpsType(shape);
  254. if (PropertyPanel != null)
  255. {
  256. AnnotEvent = PropertyPanel.AnnotEvent;
  257. Annot = PropertyPanel.annot;
  258. var stampAnnotArgs = Annot as StampAnnotArgs;
  259. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count > 1)
  260. {
  261. IsMultiSelected = true;
  262. }
  263. else
  264. {
  265. IsMultiSelected = false;
  266. }
  267. if (IsMultiSelected)
  268. {
  269. }
  270. else
  271. {
  272. GetAnnotProperty();
  273. }
  274. }
  275. }
  276. private void GetAnnotProperty()
  277. {
  278. if (Annot is StickyAnnotArgs)
  279. {
  280. var annot = Annot as StickyAnnotArgs;
  281. if (annot != null)
  282. {
  283. SelectColor = new SolidColorBrush(annot.Color);
  284. FillOpacity = annot.Transparency;
  285. }
  286. }
  287. }
  288. }
  289. }