ShapFillPropertyViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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_Master.Helper;
  16. using System.Diagnostics;
  17. using PDF_Master.Model;
  18. using PDF_Master.ViewModels.Tools;
  19. using Microsoft.Office.Interop.Excel;
  20. using Point = System.Windows.Point;
  21. using static Dropbox.Api.UsersCommon.AccountType;
  22. using PDF_Master.Model.AnnotPanel;
  23. using PDFSettings;
  24. using PDF_Master.ViewModels.Tools.AnnotManager;
  25. using Prism.Common;
  26. namespace PDF_Master.ViewModels.FillAndSign.PropertyPanel
  27. {
  28. public class ShapFillPropertyViewModel : BindableBase, INavigationAware
  29. {
  30. public AnnotAttribEvent AnnotEvent { get; set; }
  31. private AnnotHandlerEventArgs Annot;
  32. private AnnotTransfer PropertyPanel;
  33. private FillAndSignContentViewModel fillAndSignContentViewModel;
  34. public List<List<Point>> updatapath = new List<List<Point>>();
  35. private Geometry dataPath = null;
  36. private bool IsFillAndSign = false;
  37. public string Shape = "";
  38. public Geometry DataPath
  39. {
  40. get { return dataPath; }
  41. set
  42. {
  43. SetProperty(ref dataPath, value);
  44. }
  45. }
  46. private void InitColorItems()
  47. {
  48. }
  49. private Brush selectColor = new SolidColorBrush(Colors.GreenYellow);
  50. public Brush SelectColor
  51. {
  52. get { return selectColor; }
  53. set
  54. {
  55. SetProperty(ref selectColor, value);
  56. if (!fillAndSignContentViewModel.isFirst)
  57. {
  58. fillAndSignContentViewModel.SelectColor = value;
  59. //if (FillAndSignContentViewModel.IsEdit)
  60. {
  61. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * lineWidthMultiple);
  62. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
  63. }
  64. //else
  65. {
  66. if(IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  67. }
  68. }
  69. }
  70. }
  71. private double fillOpacity = 1;
  72. public double FillOpacity
  73. {
  74. get { return fillOpacity; }
  75. set
  76. {
  77. SetProperty(ref fillOpacity, value);
  78. if (!fillAndSignContentViewModel.isFirst)
  79. {
  80. fillAndSignContentViewModel.FillOpacity = value;
  81. //if (FillAndSignContentViewModel.IsEdit)
  82. {
  83. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, fillOpacity);
  84. }
  85. //else
  86. {
  87. if (IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  88. }
  89. }
  90. }
  91. }
  92. private bool _isMultiSelected = false;
  93. public bool IsMultiSelected
  94. {
  95. get { return _isMultiSelected; }
  96. set => SetProperty(ref _isMultiSelected, value);
  97. }
  98. private bool _isSelected = false;
  99. public bool IsSelected
  100. {
  101. get { return _isSelected; }
  102. set => SetProperty(ref _isSelected, value);
  103. }
  104. private double lineWidthMultiple=1;
  105. private double lineWidth = 1;
  106. public double LineWidth
  107. {
  108. get { return lineWidth; }
  109. set
  110. {
  111. SetProperty(ref lineWidth, value);
  112. if (!fillAndSignContentViewModel.isFirst)
  113. {
  114. fillAndSignContentViewModel.LineWidth = value;
  115. //if (FillAndSignContentViewModel.IsEdit)
  116. {
  117. //PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Height, 60);
  118. //PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Width, 60);
  119. //if (Shape == "DotShape") { lineWidthMultiple = 5; }
  120. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * lineWidthMultiple);
  121. //fillAndSignContentViewModel.LineWidthMultiple = lineWidthMultiple;
  122. //PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  123. }
  124. // else
  125. {
  126. if (IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  127. }
  128. }
  129. }
  130. }
  131. public DelegateCommand<object> SelectedThickCommand { get; set; }
  132. public DelegateCommand<object> SelectedColorCommand { get; set; }
  133. //public DelegateCommand<object> LineStyleCommand { get; set; }
  134. public DelegateCommand<object> SharpsTypeCommand { get; set; }
  135. public DelegateCommand<object> ThicknessChangedCommand { get; set; }
  136. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  137. public ShapFillPropertyViewModel()
  138. {
  139. SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
  140. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  141. //LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
  142. SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
  143. ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
  144. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  145. }
  146. private void InitFillAndSignProperty()
  147. {
  148. if (fillAndSignContentViewModel.isFirst)
  149. {
  150. SelectColor = fillAndSignContentViewModel.SelectColor;
  151. FillOpacity = fillAndSignContentViewModel.FillOpacity;
  152. LineWidth = fillAndSignContentViewModel.LineWidth;
  153. }
  154. fillAndSignContentViewModel.isFirst = false;
  155. }
  156. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  157. {
  158. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, "FillAndSign");
  159. if (Annot == null)
  160. {
  161. Annot = new DefaultAnnotProperty();
  162. Annot.AnnotToolType = annotArgsType;
  163. }
  164. return Annot;
  165. }
  166. private void SharpsType_Command(object obj)
  167. {
  168. if (obj != null)
  169. {
  170. var tag = (string)obj;
  171. SharpsType(tag, obj);
  172. }
  173. }
  174. private void SharpsType(string tag, object obj, bool isFromToolsBtn = false)
  175. {
  176. fillAndSignContentViewModel.LineWidthMultiple = 1;
  177. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  178. lineWidthMultiple = 1;
  179. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Width, 60);
  180. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Height, 60);
  181. switch (tag)
  182. {
  183. case "HookShape":
  184. var hookShape = new PathGeometry();
  185. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  186. DataPath = hookShape;
  187. //if (FillAndSignContentViewModel.IsEdit)
  188. {
  189. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  190. 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) } };
  191. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  192. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  193. {
  194. foreach (var annot in PropertyPanel.annotlists)
  195. {
  196. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  197. {
  198. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  199. {
  200. point.Shape = "HookShape";
  201. }
  202. }
  203. }
  204. }
  205. }
  206. //PropertyPanel.UpdateAnnotAAttrib();
  207. //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) } };
  208. //fillAndSignContentViewModel.SetStamp();
  209. //changeData[AnnotArgsType.AnnotLine] = tag;
  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. // if (FillAndSignContentViewModel.IsEdit)
  216. {
  217. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  218. 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) } };
  219. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  220. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  221. {
  222. foreach (var annot in PropertyPanel.annotlists)
  223. {
  224. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  225. {
  226. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  227. {
  228. point.Shape = "ForkShape";
  229. }
  230. }
  231. }
  232. }
  233. }
  234. //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) } };
  235. //fillAndSignContentViewModel.SetStamp();
  236. //changeData[AnnotArgsType.AnnotLine] = tag;
  237. break;
  238. case "RectShape":
  239. {
  240. RectangleGeometry rectPath = new RectangleGeometry();
  241. rectPath.Rect = new Rect(0, 5, 28, 22);
  242. DataPath = rectPath;
  243. //if (FillAndSignContentViewModel.IsEdit)
  244. {
  245. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  246. 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) } };
  247. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  248. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  249. {
  250. foreach (var annot in PropertyPanel.annotlists)
  251. {
  252. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  253. {
  254. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  255. {
  256. point.Shape = "RectShape";
  257. }
  258. }
  259. }
  260. }
  261. }
  262. //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) } };
  263. //fillAndSignContentViewModel.SetStamp();
  264. // changeData[AnnotArgsType.AnnotSquare] = tag;
  265. }
  266. break;
  267. case "LineShape":
  268. {
  269. var lineShape = new PathGeometry();
  270. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  271. DataPath = lineShape;
  272. // if (FillAndSignContentViewModel.IsEdit)
  273. {
  274. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  275. updatapath = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
  276. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  277. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  278. {
  279. foreach (var annot in PropertyPanel.annotlists)
  280. {
  281. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  282. {
  283. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  284. {
  285. point.Shape = "LineShape";
  286. }
  287. }
  288. }
  289. }
  290. }
  291. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(36, 10) } };
  292. //fillAndSignContentViewModel.SetStamp();
  293. //changeData[AnnotArgsType.AnnotLine] = tag;
  294. }
  295. break;
  296. case "DotShape":
  297. {
  298. fillAndSignContentViewModel.LineWidthMultiple = 5;
  299. EllipseGeometry circlePath = new EllipseGeometry();
  300. circlePath.RadiusX = 2.4;
  301. circlePath.RadiusY = 2.4;
  302. circlePath.Center = new Point(2.4, 2.4);
  303. DataPath = circlePath;
  304. // if (FillAndSignContentViewModel.IsEdit)
  305. {
  306. lineWidthMultiple = 5;
  307. updatapath = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  308. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * 5);
  309. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  310. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  311. {
  312. foreach (var annot in PropertyPanel.annotlists)
  313. {
  314. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  315. {
  316. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  317. {
  318. point.Shape = "DotShape";
  319. }
  320. }
  321. }
  322. }
  323. }
  324. //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) } };
  325. //fillAndSignContentViewModel.SetStamp();
  326. //changeData[AnnotArgsType.AnnotCircle] = tag;
  327. }
  328. break;
  329. }
  330. //if (isFromToolsBtn == false)
  331. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  332. }
  333. private void InitSharpsType(string tag)
  334. {
  335. fillAndSignContentViewModel.LineWidthMultiple = 1;
  336. switch (tag)
  337. {
  338. case "HookShape":
  339. var hookShape = new PathGeometry();
  340. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  341. DataPath = hookShape;
  342. break;
  343. case "ForkShape":
  344. var forkShape = new PathGeometry();
  345. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  346. DataPath = forkShape;
  347. break;
  348. case "RectShape":
  349. {
  350. RectangleGeometry rectPath = new RectangleGeometry();
  351. rectPath.Rect = new Rect(0, 5, 28, 22);
  352. DataPath = rectPath;
  353. }
  354. break;
  355. case "LineShape":
  356. {
  357. var lineShape = new PathGeometry();
  358. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  359. DataPath = lineShape;
  360. }
  361. break;
  362. case "DotShape":
  363. {
  364. fillAndSignContentViewModel.LineWidthMultiple = 5;
  365. EllipseGeometry circlePath = new EllipseGeometry();
  366. circlePath.RadiusX = 2.4;
  367. circlePath.RadiusY = 2.4;
  368. circlePath.Center = new Point(2.4, 2.4);
  369. DataPath = circlePath;
  370. }
  371. break;
  372. }
  373. //if (isFromToolsBtn == false)
  374. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  375. }
  376. private void SelectedThick_Command(object obj)
  377. {
  378. if (obj is double)
  379. {
  380. var tran = (double)obj;
  381. //BorderOpacity = tran;
  382. SelectColor.Opacity = tran;
  383. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
  384. //AnnotEvent?.UpdateAnnot();
  385. }
  386. }
  387. private void ThicknessChanged_Command(object obj)
  388. {
  389. if (obj != null)
  390. {
  391. var item = (ComboBoxItem)obj;
  392. var content = (string)item.Content;
  393. if (content != null)
  394. {
  395. var intData = int.Parse(content);
  396. LineWidth = intData;
  397. }
  398. }
  399. }
  400. private void SelectedColor_Command(object obj)
  401. {
  402. if (obj != null)
  403. {
  404. var colorValue = (Color)obj;
  405. if (colorValue != null)
  406. {
  407. SelectColor = new SolidColorBrush(colorValue);
  408. SelectColor.Opacity = FillOpacity;
  409. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  410. changeData[AnnotArgsType.AnnotFreehand] = obj;
  411. //PropertyPanel.DataChangedInvoke(this, changeData);
  412. }
  413. }
  414. }
  415. private void SelectedOpacityValue(object obj)
  416. {
  417. if (obj != null)
  418. {
  419. FillOpacity = (double)obj;
  420. SelectColor.Opacity = FillOpacity;
  421. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
  422. //AnnotEvent?.UpdateAnnot();
  423. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  424. changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
  425. //PropertyPanel.DataChangedInvoke(this, changeData);
  426. }
  427. }
  428. public bool IsNavigationTarget(NavigationContext navigationContext)
  429. {
  430. return true;
  431. }
  432. public void OnNavigatedFrom(NavigationContext navigationContext)
  433. {
  434. }
  435. public void OnNavigatedTo(NavigationContext navigationContext)
  436. {
  437. string shape = "";
  438. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  439. navigationContext.Parameters.TryGetValue<FillAndSignContentViewModel>("FillAndSignContentViewModel", out fillAndSignContentViewModel);
  440. navigationContext.Parameters.TryGetValue<string>("Shape", out shape);
  441. bool isFillAndSign = false;
  442. navigationContext.Parameters.TryGetValue<bool>("IsFillAndSign", out isFillAndSign);
  443. IsFillAndSign = isFillAndSign;
  444. InitSharpsType(shape);
  445. //FillAndSignContentViewModel.IsEdit = false;
  446. if (PropertyPanel != null)
  447. {
  448. AnnotEvent = PropertyPanel.AnnotEvent;
  449. Annot = PropertyPanel.annot;
  450. var stampAnnotArgs = Annot as StampAnnotArgs;
  451. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count > 1)
  452. {
  453. IsMultiSelected = true;
  454. }
  455. else
  456. {
  457. IsMultiSelected = false;
  458. }
  459. IsSelected = !FillAndSignContentViewModel.IsEdit;
  460. InitFillAndSignProperty();
  461. if (IsMultiSelected)
  462. {
  463. }
  464. else
  465. {
  466. GetAnnotProperty(shape);
  467. }
  468. }
  469. }
  470. private void GetAnnotProperty(string shape)
  471. {
  472. if (Annot is FreehandAnnotArgs)
  473. {
  474. var annot = Annot as FreehandAnnotArgs;
  475. if (annot != null)
  476. {
  477. //SelectColor = new SolidColorBrush(annot.InkColor);
  478. //FillOpacity = annot.Transparency;
  479. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  480. {
  481. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  482. {
  483. lineWidthMultiple = 1;
  484. if (point.Shape == "DotShape") {
  485. lineWidthMultiple = 5;
  486. }
  487. InitSharpsType(point.Shape);
  488. Shape=point.Shape;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }