ShapFillPropertyViewModel.cs 16 KB

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