ShapFillPropertyViewModel.cs 17 KB

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