ShapFillPropertyViewModel.cs 19 KB

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