ShapFillPropertyViewModel.cs 17 KB

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