ShapFillPropertyViewModel.cs 17 KB

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