ShapFillPropertyViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. using static Dropbox.Api.UsersCommon.AccountType;
  22. namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
  23. {
  24. public class ShapFillPropertyViewModel : BindableBase, INavigationAware
  25. {
  26. public AnnotAttribEvent AnnotEvent { get; set; }
  27. private AnnotHandlerEventArgs Annot;
  28. private AnnotPropertyPanel PropertyPanel;
  29. private FillAndSignContentViewModel fillAndSignContentViewModel;
  30. private Geometry dataPath = null;
  31. public Geometry DataPath
  32. {
  33. get { return dataPath; }
  34. set
  35. {
  36. SetProperty(ref dataPath, value);
  37. }
  38. }
  39. private Brush selectColor = new SolidColorBrush(Colors.GreenYellow);
  40. public Brush SelectColor
  41. {
  42. get { return selectColor; }
  43. set
  44. {
  45. SetProperty(ref selectColor, value);
  46. fillAndSignContentViewModel.SelectColor = value;
  47. if (FillAndSignContentViewModel.IsEdit)
  48. {
  49. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
  50. }
  51. else { fillAndSignContentViewModel.SetStamp(); }
  52. }
  53. }
  54. private double fillOpacity = 1;
  55. public double FillOpacity
  56. {
  57. get { return fillOpacity; }
  58. set
  59. {
  60. SetProperty(ref fillOpacity, value);
  61. fillAndSignContentViewModel.FillOpacity = value;
  62. if (FillAndSignContentViewModel.IsEdit) { PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, fillOpacity); }
  63. else { fillAndSignContentViewModel.SetStamp(); }
  64. }
  65. }
  66. private bool _isMultiSelected = false;
  67. public bool IsMultiSelected
  68. {
  69. get { return _isMultiSelected; }
  70. set => SetProperty(ref _isMultiSelected, value);
  71. }
  72. private double lineWidth = 1;
  73. public double LineWidth
  74. {
  75. get { return lineWidth; }
  76. set
  77. {
  78. SetProperty(ref lineWidth, value);
  79. fillAndSignContentViewModel.LineWidth = value;
  80. if (FillAndSignContentViewModel.IsEdit)
  81. {
  82. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, value);
  83. }
  84. else { fillAndSignContentViewModel.SetStamp(); }
  85. }
  86. }
  87. public DelegateCommand<object> SelectedThickCommand { get; set; }
  88. public DelegateCommand<object> SelectedColorCommand { get; set; }
  89. //public DelegateCommand<object> LineStyleCommand { get; set; }
  90. public DelegateCommand<object> SharpsTypeCommand { get; set; }
  91. public DelegateCommand<object> ThicknessChangedCommand { get; set; }
  92. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  93. public ShapFillPropertyViewModel()
  94. {
  95. SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
  96. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  97. //LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
  98. SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
  99. ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
  100. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  101. }
  102. private void SharpsType_Command(object obj)
  103. {
  104. if (obj != null)
  105. {
  106. var tag = (string)obj;
  107. SharpsType(tag, obj);
  108. }
  109. }
  110. private void SharpsType(string tag, object obj, bool isFromToolsBtn = false)
  111. {
  112. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  113. switch (tag)
  114. {
  115. case "HookShape":
  116. var hookShape = new PathGeometry();
  117. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  118. DataPath = hookShape;
  119. if (FillAndSignContentViewModel.IsEdit)
  120. {
  121. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } });
  122. }
  123. //PropertyPanel.UpdateAnnotAAttrib();
  124. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  125. //fillAndSignContentViewModel.SetStamp();
  126. //changeData[AnnotArgsType.AnnotLine] = tag;
  127. break;
  128. case "ForkShape":
  129. var forkShape = new PathGeometry();
  130. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  131. DataPath = forkShape;
  132. if (FillAndSignContentViewModel.IsEdit)
  133. {
  134. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } });
  135. }
  136. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
  137. //fillAndSignContentViewModel.SetStamp();
  138. //changeData[AnnotArgsType.AnnotLine] = tag;
  139. break;
  140. case "RectShape":
  141. {
  142. RectangleGeometry rectPath = new RectangleGeometry();
  143. rectPath.Rect = new Rect(0, 5, 28, 22);
  144. DataPath = rectPath;
  145. if (FillAndSignContentViewModel.IsEdit)
  146. {
  147. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, new List<List<Point>> { new List<Point> { new Point(0.19995, 5), new Point(28, 5), new Point(28, 27), new Point(0.19995, 27), new Point(0.19995, 5) } });
  148. }
  149. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.19995, 5), new Point(28, 5), new Point(28, 27), new Point(0.19995, 27), new Point(0.19995, 5) } };
  150. //fillAndSignContentViewModel.SetStamp();
  151. // changeData[AnnotArgsType.AnnotSquare] = tag;
  152. }
  153. break;
  154. case "LineShape":
  155. {
  156. var lineShape = new PathGeometry();
  157. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  158. DataPath = lineShape;
  159. if (FillAndSignContentViewModel.IsEdit)
  160. {
  161. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(36, 10) } });
  162. }
  163. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(36, 10) } };
  164. //fillAndSignContentViewModel.SetStamp();
  165. //changeData[AnnotArgsType.AnnotLine] = tag;
  166. }
  167. break;
  168. case "DotShape":
  169. {
  170. EllipseGeometry circlePath = new EllipseGeometry();
  171. circlePath.RadiusX = 2.4;
  172. circlePath.RadiusY = 2.4;
  173. circlePath.Center = new Point(2.4, 2.4);
  174. DataPath = circlePath;
  175. if (FillAndSignContentViewModel.IsEdit)
  176. {
  177. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, new List<List<Point>> { new List<Point> { new Point(0,1), new Point(0,0) }, new List<Point> { new Point(0.5, 0.86602), new Point(0, 0) }, new List<Point> { new Point(0.7071, 0.7071), new Point(0, 0) }, new List<Point> { new Point(0.86602, 0.5), new Point(0, 0) }, new List<Point> { new Point(1, 0), new Point(0, 0) }, new List<Point> { new Point(0.86602, -0.5), new Point(0, 0) }, new List<Point> { new Point(0.7071, -0.7071), new Point(0, 0) }, new List<Point> { new Point(0.5, -0.86602), new Point(0, 0) }, new List<Point> { new Point(0, -1), new Point(0, 0) }, new List<Point> { new Point(-0.5, 0.86602), new Point(0, 0) }, new List<Point> { new Point(-0.7071, 0.7071), new Point(0, 0) }, new List<Point> { new Point(-0.86602, 0.5), new Point(0, 0) }, new List<Point> { new Point(-1, 0), new Point(0, 0) }, new List<Point> { new Point(-0.86602, -0.5), new Point(0, 0) }, new List<Point> { new Point(-0.7071, -0.7071), new Point(0, 0) }, new List<Point> { new Point(-0.5, -0.86602), new Point(0, 0) } });
  178. }
  179. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.19995, 1.19995), new Point(0.19995, -1.19995) }, new List<Point> { new Point(-0.25995, 0.89995), new Point(0.25995, -0.89995) }, new List<Point> { new Point(-1.19995, 0.19995), new Point(0.19995, 1.19995) } };
  180. //fillAndSignContentViewModel.SetStamp();
  181. //changeData[AnnotArgsType.AnnotCircle] = tag;
  182. }
  183. break;
  184. }
  185. //if (isFromToolsBtn == false)
  186. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  187. }
  188. private void InitSharpsType(string tag)
  189. {
  190. switch (tag)
  191. {
  192. case "HookShape":
  193. var hookShape = new PathGeometry();
  194. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  195. DataPath = hookShape;
  196. break;
  197. case "ForkShape":
  198. var forkShape = new PathGeometry();
  199. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  200. DataPath = forkShape;
  201. break;
  202. case "RectShape":
  203. {
  204. RectangleGeometry rectPath = new RectangleGeometry();
  205. rectPath.Rect = new Rect(0, 5, 28, 22);
  206. DataPath = rectPath;
  207. }
  208. break;
  209. case "LineShape":
  210. {
  211. var lineShape = new PathGeometry();
  212. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  213. DataPath = lineShape;
  214. }
  215. break;
  216. case "DotShape":
  217. {
  218. EllipseGeometry circlePath = new EllipseGeometry();
  219. circlePath.RadiusX = 2.4;
  220. circlePath.RadiusY = 2.4;
  221. circlePath.Center = new Point(2.4, 2.4);
  222. DataPath = circlePath;
  223. }
  224. break;
  225. }
  226. //if (isFromToolsBtn == false)
  227. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  228. }
  229. private void SelectedThick_Command(object obj)
  230. {
  231. if (obj is double)
  232. {
  233. var tran = (double)obj;
  234. //BorderOpacity = tran;
  235. SelectColor.Opacity = tran;
  236. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
  237. //AnnotEvent?.UpdateAnnot();
  238. }
  239. }
  240. private void ThicknessChanged_Command(object obj)
  241. {
  242. if (obj != null)
  243. {
  244. var item = (ComboBoxItem)obj;
  245. var content = (string)item.Content;
  246. if (content != null)
  247. {
  248. var intData = int.Parse(content);
  249. LineWidth = intData;
  250. }
  251. }
  252. }
  253. private void SelectedColor_Command(object obj)
  254. {
  255. if (obj != null)
  256. {
  257. var colorValue = (Color)obj;
  258. if (colorValue != null)
  259. {
  260. SelectColor = new SolidColorBrush(colorValue);
  261. SelectColor.Opacity = FillOpacity;
  262. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  263. changeData[AnnotArgsType.AnnotFreehand] = obj;
  264. //PropertyPanel.DataChangedInvoke(this, changeData);
  265. }
  266. }
  267. }
  268. private void SelectedOpacityValue(object obj)
  269. {
  270. if (obj != null)
  271. {
  272. FillOpacity = (double)obj;
  273. SelectColor.Opacity = FillOpacity;
  274. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
  275. //AnnotEvent?.UpdateAnnot();
  276. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  277. changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
  278. //PropertyPanel.DataChangedInvoke(this, changeData);
  279. }
  280. }
  281. public bool IsNavigationTarget(NavigationContext navigationContext)
  282. {
  283. return true;
  284. }
  285. public void OnNavigatedFrom(NavigationContext navigationContext)
  286. {
  287. }
  288. public void OnNavigatedTo(NavigationContext navigationContext)
  289. {
  290. string shape = "";
  291. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  292. navigationContext.Parameters.TryGetValue<FillAndSignContentViewModel>("FillAndSignContentViewModel", out fillAndSignContentViewModel);
  293. navigationContext.Parameters.TryGetValue<string>("Shape", out shape);
  294. InitSharpsType(shape);
  295. //FillAndSignContentViewModel.IsEdit = false;
  296. if (PropertyPanel != null)
  297. {
  298. AnnotEvent = PropertyPanel.AnnotEvent;
  299. Annot = PropertyPanel.annot;
  300. var stampAnnotArgs = Annot as StampAnnotArgs;
  301. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count > 1)
  302. {
  303. IsMultiSelected = true;
  304. }
  305. else
  306. {
  307. IsMultiSelected = false;
  308. }
  309. if (IsMultiSelected)
  310. {
  311. }
  312. else
  313. {
  314. GetAnnotProperty();
  315. }
  316. }
  317. }
  318. private void GetAnnotProperty()
  319. {
  320. if (Annot is StickyAnnotArgs)
  321. {
  322. var annot = Annot as StickyAnnotArgs;
  323. if (annot != null)
  324. {
  325. SelectColor = new SolidColorBrush(annot.Color);
  326. FillOpacity = annot.Transparency;
  327. }
  328. }
  329. }
  330. }
  331. }