ShapFillPropertyViewModel.cs 24 KB

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