ShapFillPropertyViewModel.cs 19 KB

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