ShapFillPropertyViewModel.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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. using ComPDFKitViewer.PdfViewer;
  27. using PDF_Master.CustomControl.CompositeControl;
  28. using Microsoft.Office.Interop.Word;
  29. namespace PDF_Master.ViewModels.FillAndSign.PropertyPanel
  30. {
  31. public class ShapFillPropertyViewModel : BindableBase, INavigationAware
  32. {
  33. public AnnotAttribEvent AnnotEvent { get; set; }
  34. private AnnotHandlerEventArgs Annot;
  35. private AnnotTransfer PropertyPanel;
  36. private FillAndSignContentViewModel fillAndSignContentViewModel;
  37. public List<List<Point>> updatapath = new List<List<Point>>();
  38. private Geometry dataPath = null;
  39. private bool IsFillAndSign = false;
  40. public string shape = "";
  41. public string Shape
  42. {
  43. get { return shape; }
  44. set
  45. {
  46. SetProperty(ref shape, value);
  47. }
  48. }
  49. public string shapeType = "";
  50. public string ShapeType
  51. {
  52. get { return shapeType; }
  53. set
  54. {
  55. SetProperty(ref shapeType, value);
  56. }
  57. }
  58. public Geometry DataPath
  59. {
  60. get { return dataPath; }
  61. set
  62. {
  63. SetProperty(ref dataPath, value);
  64. }
  65. }
  66. private void InitColorItems()
  67. {
  68. }
  69. private Brush selectColor = new SolidColorBrush(Color.FromArgb(0xff, 0x26, 0x25, 0x29));
  70. public Brush SelectColor
  71. {
  72. get { return selectColor; }
  73. set
  74. {
  75. SetProperty(ref selectColor, value);
  76. UPDataColor();
  77. }
  78. }
  79. private double fillOpacity = 1;
  80. public double FillOpacity
  81. {
  82. get { return fillOpacity; }
  83. set
  84. {
  85. SetProperty(ref fillOpacity, value);
  86. //if (!fillAndSignContentViewModel.isFirst)
  87. //{
  88. // fillAndSignContentViewModel.FillOpacity = value;
  89. // //if (FillAndSignContentViewModel.IsEdit)
  90. // {
  91. // PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, fillOpacity);
  92. // }
  93. // //else
  94. // {
  95. // if (IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  96. // }
  97. //}
  98. }
  99. }
  100. private bool _hookIsChecked = false;
  101. public bool HookIsChecked
  102. {
  103. get { return _hookIsChecked; }
  104. set
  105. {
  106. SetProperty(ref _hookIsChecked, value);
  107. }
  108. }
  109. private bool _forkIsChecked = false;
  110. public bool ForkIsChecked
  111. {
  112. get { return _forkIsChecked; }
  113. set
  114. {
  115. SetProperty(ref _forkIsChecked, value);
  116. }
  117. }
  118. private bool _rectIsChecked = false;
  119. public bool RectIsChecked
  120. {
  121. get { return _rectIsChecked; }
  122. set
  123. {
  124. SetProperty(ref _rectIsChecked, value);
  125. }
  126. }
  127. private bool _lineIsChecked = false;
  128. public bool LineIsChecked
  129. {
  130. get { return _lineIsChecked; }
  131. set
  132. {
  133. SetProperty(ref _lineIsChecked, value);
  134. }
  135. }
  136. private bool _dotIsChecked = false;
  137. public bool DotIsChecked
  138. {
  139. get { return _dotIsChecked; }
  140. set
  141. {
  142. SetProperty(ref _dotIsChecked, value);
  143. }
  144. }
  145. private bool _isMultiSelected = false;
  146. public bool IsMultiSelected
  147. {
  148. get { return _isMultiSelected; }
  149. set
  150. {
  151. SetProperty(ref _isMultiSelected, value);
  152. if (value) { ShapeType = "General Properties"; }
  153. }
  154. }
  155. private bool _isSelected = false;
  156. public bool IsSelected
  157. {
  158. get { return _isSelected; }
  159. set => SetProperty(ref _isSelected, value);
  160. }
  161. private double lineWidthMultiple = 1;
  162. private double lineWidth = 1;
  163. public double LineWidth
  164. {
  165. get { return lineWidth; }
  166. set
  167. {
  168. SetProperty(ref lineWidth, value);
  169. }
  170. }
  171. private Brush _shapeColortColor = new SolidColorBrush(Color.FromArgb(0xff, 0x26, 0x25, 0x29));
  172. public Brush ShapeColorColor
  173. {
  174. get { return _shapeColortColor; }
  175. set { SetProperty(ref _shapeColortColor, value); }
  176. }
  177. List<ColorItem> shapeColorItems = new List<ColorItem>();
  178. public List<ColorItem> ShapeColorItems
  179. {
  180. get { return shapeColorItems; }
  181. set
  182. {
  183. SetProperty(ref shapeColorItems, value);
  184. }
  185. }
  186. private void InitShapeColorList()
  187. {
  188. ShapeColorItems = new List<ColorItem>();
  189. ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xfc, 0x1f, 0x1f), 0);
  190. ShapeColorItems.Add(colorItem);
  191. colorItem = new ColorItem(Color.FromArgb(0xff, 0x26, 0x25, 0x29), 1);
  192. ShapeColorItems.Add(colorItem);
  193. colorItem = new ColorItem(Color.FromArgb(0xff, 0x29, 0x53, 0x93), 2);
  194. ShapeColorItems.Add(colorItem);
  195. colorItem = new ColorItem(Color.FromArgb(0xff, 0x1e, 0x89, 0x56), 3);
  196. ShapeColorItems.Add(colorItem);
  197. }
  198. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType, string savaKey = "")
  199. {
  200. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, savaKey);
  201. if (Annot == null)
  202. {
  203. Annot = new DefaultAnnotProperty();
  204. Annot.AnnotToolType = annotArgsType;
  205. }
  206. return Annot;
  207. }
  208. public DelegateCommand<object> SelectedThickCommand { get; set; }
  209. public DelegateCommand<object> SelectedColorCommand { get; set; }
  210. //public DelegateCommand<object> LineStyleCommand { get; set; }
  211. public DelegateCommand<object> SelectedLineWidthValueCommand { get; set; }
  212. public DelegateCommand<object> SharpsTypeCommand { get; set; }
  213. public DelegateCommand<object> ThicknessChangedCommand { get; set; }
  214. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  215. public ShapFillPropertyViewModel()
  216. {
  217. InitShapeColorList();
  218. SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
  219. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  220. SelectedLineWidthValueCommand = new DelegateCommand<object>(SelectedLineWitdh_Command);
  221. //LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
  222. SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
  223. ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
  224. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  225. }
  226. private void InitFillAndSignProperty()
  227. {
  228. if (fillAndSignContentViewModel.isFirst)
  229. {
  230. SelectColor = fillAndSignContentViewModel.SelectColor;
  231. FillOpacity = fillAndSignContentViewModel.FillOpacity;
  232. LineWidth = fillAndSignContentViewModel.LineWidth;
  233. }
  234. fillAndSignContentViewModel.isFirst = false;
  235. }
  236. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  237. {
  238. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, "FillAndSign");
  239. if (Annot == null)
  240. {
  241. Annot = new DefaultAnnotProperty();
  242. Annot.AnnotToolType = annotArgsType;
  243. }
  244. return Annot;
  245. }
  246. private void SharpsType_Command(object obj)
  247. {
  248. if (obj != null)
  249. {
  250. var tag = (string)obj;
  251. SharpsType(tag, obj);
  252. }
  253. }
  254. private void SharpsType(string tag, object obj, bool isFromToolsBtn = false)
  255. {
  256. fillAndSignContentViewModel.LineWidthMultiple = 1;
  257. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  258. lineWidthMultiple = 1;
  259. //PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Width, 60);
  260. //PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Height, 60);
  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. //if (FillAndSignContentViewModel.IsEdit)
  268. {
  269. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  270. updatapath = fillAndSignContentViewModel.keyShape[tag];
  271. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  272. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  273. {
  274. foreach (var annot in PropertyPanel.annotlists)
  275. {
  276. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  277. {
  278. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  279. {
  280. point.Shape = "HookShape";
  281. }
  282. }
  283. }
  284. }
  285. }
  286. //PropertyPanel.UpdateAnnotAAttrib();
  287. //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) } };
  288. //fillAndSignContentViewModel.SetStamp();
  289. //changeData[AnnotArgsType.AnnotLine] = tag;
  290. break;
  291. case "ForkShape":
  292. var forkShape = new PathGeometry();
  293. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  294. DataPath = forkShape;
  295. // if (FillAndSignContentViewModel.IsEdit)
  296. {
  297. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  298. updatapath = fillAndSignContentViewModel.keyShape[tag];
  299. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  300. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  301. {
  302. foreach (var annot in PropertyPanel.annotlists)
  303. {
  304. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  305. {
  306. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  307. {
  308. point.Shape = "ForkShape";
  309. }
  310. }
  311. }
  312. }
  313. }
  314. //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) } };
  315. //fillAndSignContentViewModel.SetStamp();
  316. //changeData[AnnotArgsType.AnnotLine] = tag;
  317. break;
  318. case "RectShape":
  319. {
  320. RectangleGeometry rectPath = new RectangleGeometry();
  321. rectPath.Rect = new Rect(0, 5, 28, 22);
  322. DataPath = rectPath;
  323. //if (FillAndSignContentViewModel.IsEdit)
  324. {
  325. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  326. updatapath = fillAndSignContentViewModel.keyShape[tag];
  327. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  328. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  329. {
  330. foreach (var annot in PropertyPanel.annotlists)
  331. {
  332. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  333. {
  334. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  335. {
  336. point.Shape = "RectShape";
  337. }
  338. }
  339. }
  340. }
  341. }
  342. //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) } };
  343. //fillAndSignContentViewModel.SetStamp();
  344. // changeData[AnnotArgsType.AnnotSquare] = tag;
  345. }
  346. break;
  347. case "LineShape":
  348. {
  349. var lineShape = new PathGeometry();
  350. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  351. DataPath = lineShape;
  352. // if (FillAndSignContentViewModel.IsEdit)
  353. {
  354. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
  355. updatapath = fillAndSignContentViewModel.keyShape[tag];
  356. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  357. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  358. {
  359. foreach (var annot in PropertyPanel.annotlists)
  360. {
  361. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  362. {
  363. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  364. {
  365. point.Shape = "LineShape";
  366. }
  367. }
  368. }
  369. }
  370. }
  371. //fillAndSignContentViewModel.ShapePoints = new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(36, 10) } };
  372. //fillAndSignContentViewModel.SetStamp();
  373. //changeData[AnnotArgsType.AnnotLine] = tag;
  374. }
  375. break;
  376. case "DotShape":
  377. {
  378. //fillAndSignContentViewModel.LineWidthMultiple = 5;
  379. EllipseGeometry circlePath = new EllipseGeometry();
  380. circlePath.RadiusX = 2.4;
  381. circlePath.RadiusY = 2.4;
  382. circlePath.Center = new Point(2.4, 2.4);
  383. DataPath = circlePath;
  384. // if (FillAndSignContentViewModel.IsEdit)
  385. {
  386. lineWidthMultiple = 5;
  387. updatapath = fillAndSignContentViewModel.keyShape[tag];
  388. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, 10);
  389. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
  390. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count >= 1)
  391. {
  392. foreach (var annot in PropertyPanel.annotlists)
  393. {
  394. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  395. {
  396. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  397. {
  398. point.Shape = "DotShape";
  399. }
  400. }
  401. }
  402. }
  403. }
  404. //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) } };
  405. //fillAndSignContentViewModel.SetStamp();
  406. //changeData[AnnotArgsType.AnnotCircle] = tag;
  407. }
  408. break;
  409. }
  410. //if (isFromToolsBtn == false)
  411. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  412. }
  413. private string UPDateShapeType(string tag)
  414. {
  415. switch (tag)
  416. {
  417. case "DotShape":
  418. return "Dot";
  419. case "LineShape":
  420. return "Line";
  421. case "RectShape":
  422. return "Rectangle";
  423. case "ForkShape":
  424. return "Fork";
  425. case "HookShape":
  426. return "Hook";
  427. default:
  428. return "General Properties";
  429. }
  430. }
  431. private void InitShapesType(string tag)
  432. {
  433. ShapeType = UPDateShapeType(tag);
  434. fillAndSignContentViewModel.LineWidthMultiple = 1;
  435. switch (tag)
  436. {
  437. case "HookShape":
  438. var hookShape = new PathGeometry();
  439. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  440. DataPath = hookShape;
  441. break;
  442. case "ForkShape":
  443. var forkShape = new PathGeometry();
  444. forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  445. DataPath = forkShape;
  446. break;
  447. case "RectShape":
  448. {
  449. RectangleGeometry rectPath = new RectangleGeometry();
  450. rectPath.Rect = new Rect(0, 5, 28, 22);
  451. DataPath = rectPath;
  452. }
  453. break;
  454. case "LineShape":
  455. {
  456. var lineShape = new PathGeometry();
  457. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  458. DataPath = lineShape;
  459. }
  460. break;
  461. case "DotShape":
  462. {
  463. //fillAndSignContentViewModel.LineWidthMultiple = 5;
  464. EllipseGeometry circlePath = new EllipseGeometry();
  465. circlePath.RadiusX = 2.4;
  466. circlePath.RadiusY = 2.4;
  467. circlePath.Center = new Point(2.4, 2.4);
  468. DataPath = circlePath;
  469. }
  470. break;
  471. }
  472. //if (isFromToolsBtn == false)
  473. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  474. }
  475. private void SelectedThick_Command(object obj)
  476. {
  477. if (obj is double)
  478. {
  479. var tran = (double)obj;
  480. //BorderOpacity = tran;
  481. SelectColor.Opacity = tran;
  482. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
  483. //AnnotEvent?.UpdateAnnot();
  484. }
  485. }
  486. private void ThicknessChanged_Command(object obj)
  487. {
  488. if (obj != null)
  489. {
  490. var item = (ComboBoxItem)obj;
  491. var content = (string)item.Content;
  492. if (content != null)
  493. {
  494. var intData = int.Parse(content);
  495. LineWidth = intData;
  496. UPDataLineWidth();
  497. }
  498. }
  499. }
  500. private void UPDataLineWidth()
  501. {
  502. if (!fillAndSignContentViewModel.isFirst)
  503. {
  504. fillAndSignContentViewModel.LineWidth = LineWidth;
  505. //if (FillAndSignContentViewModel.IsEdit)
  506. {
  507. if (!fillAndSignContentViewModel.IsClickNull)
  508. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * lineWidthMultiple);
  509. }
  510. // else
  511. {
  512. if (IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  513. }
  514. }
  515. }
  516. private void UPDataColor()
  517. {
  518. if (!fillAndSignContentViewModel.isFirst)
  519. {
  520. var newColor = (ShapeColorColor as SolidColorBrush).Color;
  521. var oldColor = (SelectColor as SolidColorBrush).Color;
  522. if (newColor.A != oldColor.A || newColor.B != oldColor.B || newColor.R != oldColor.R || newColor.G != oldColor.G)
  523. {
  524. ShapeColorColor = SelectColor;
  525. fillAndSignContentViewModel.SelectColor = SelectColor;
  526. //if (FillAndSignContentViewModel.IsEdit)
  527. {
  528. // PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * lineWidthMultiple);
  529. if (!fillAndSignContentViewModel.IsClickNull)
  530. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
  531. }
  532. //else
  533. {
  534. if (IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  535. }
  536. }
  537. }
  538. }
  539. private void UPDataOpacity()
  540. {
  541. if (!fillAndSignContentViewModel.isFirst)
  542. {
  543. fillAndSignContentViewModel.FillOpacity = FillOpacity;
  544. //if (FillAndSignContentViewModel.IsEdit)
  545. {
  546. if (!fillAndSignContentViewModel.IsClickNull)
  547. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, fillOpacity);
  548. }
  549. //else
  550. {
  551. if (IsFillAndSign) { fillAndSignContentViewModel.SetStamp(); }
  552. }
  553. }
  554. }
  555. private void SelectedColor_Command(object obj)
  556. {
  557. if (obj != null)
  558. {
  559. var colorValue = (Color)obj;
  560. if (colorValue != null)
  561. {
  562. SelectColor = new SolidColorBrush(colorValue);
  563. UPDataColor();
  564. SelectColor.Opacity = FillOpacity;
  565. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  566. changeData[AnnotArgsType.AnnotFreehand] = obj;
  567. //PropertyPanel.DataChangedInvoke(this, changeData);
  568. }
  569. }
  570. }
  571. private void SelectedLineWitdh_Command(object obj)
  572. {
  573. if (obj != null)
  574. {
  575. double colorValue = (double)obj;
  576. UPDataLineWidth();
  577. }
  578. }
  579. private void SelectedOpacityValue(object obj)
  580. {
  581. if (obj != null)
  582. {
  583. FillOpacity = (double)obj;
  584. SelectColor.Opacity = FillOpacity;
  585. UPDataOpacity();
  586. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
  587. //AnnotEvent?.UpdateAnnot();
  588. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  589. changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
  590. //PropertyPanel.DataChangedInvoke(this, changeData);
  591. }
  592. }
  593. private void BindingPDFViewerHandler()
  594. {
  595. //来自PDFViewer的响应事件
  596. if (fillAndSignContentViewModel.PDFViewer != null)
  597. {
  598. fillAndSignContentViewModel.PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  599. fillAndSignContentViewModel.PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  600. }
  601. }
  602. private void UnBindingPDFViewerHandler()
  603. {
  604. if (fillAndSignContentViewModel.PDFViewer != null)
  605. {
  606. fillAndSignContentViewModel.PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  607. }
  608. }
  609. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  610. {
  611. if (e != null) { }
  612. else
  613. {
  614. if (fillAndSignContentViewModel.PDFViewer.MouseMode == MouseModes.AnnotCreate) { IsSelected = true; }
  615. }
  616. }
  617. public bool IsNavigationTarget(NavigationContext navigationContext)
  618. {
  619. return true;
  620. }
  621. public void OnNavigatedFrom(NavigationContext navigationContext)
  622. {
  623. UnBindingPDFViewerHandler();
  624. }
  625. public void OnNavigatedTo(NavigationContext navigationContext)
  626. {
  627. string shape = "";
  628. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  629. navigationContext.Parameters.TryGetValue<FillAndSignContentViewModel>("FillAndSignContentViewModel", out fillAndSignContentViewModel);
  630. navigationContext.Parameters.TryGetValue<string>("Shape", out shape);
  631. bool isFillAndSign = false;
  632. navigationContext.Parameters.TryGetValue<bool>("IsFillAndSign", out isFillAndSign);
  633. IsFillAndSign = isFillAndSign;
  634. InitShapesType(shape);
  635. InitIsCheck();
  636. //FillAndSignContentViewModel.IsEdit = false;
  637. if (PropertyPanel != null)
  638. {
  639. AnnotEvent = PropertyPanel.AnnotEvent;
  640. Annot = PropertyPanel.annot;
  641. var stampAnnotArgs = Annot as StampAnnotArgs;
  642. if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count > 1)
  643. {
  644. IsMultiSelected = true;
  645. }
  646. else
  647. {
  648. IsMultiSelected = false;
  649. }
  650. IsSelected = !FillAndSignContentViewModel.IsEdit;
  651. InitFillAndSignProperty();
  652. if (IsMultiSelected)
  653. {
  654. IsAttributeEquals();
  655. }
  656. else
  657. {
  658. GetAnnotProperty(shape);
  659. }
  660. BindingPDFViewerHandler();
  661. }
  662. }
  663. private void InitIsCheck()
  664. {
  665. LineIsChecked = false;
  666. DotIsChecked = false;
  667. RectIsChecked = false;
  668. HookIsChecked = false;
  669. ForkIsChecked = false;
  670. }
  671. private List<FreehandAnnotArgs> ConvertLists()
  672. {
  673. List<FreehandAnnotArgs> Lists = new List<FreehandAnnotArgs>();
  674. foreach (var item in PropertyPanel.annotlists)
  675. {
  676. var selecteditem = item as FreehandAnnotArgs;
  677. if (selecteditem != null)
  678. {
  679. Lists.Add(selecteditem);
  680. }
  681. }
  682. if (Lists.Count != PropertyPanel.annotlists.Count)
  683. return null;
  684. else
  685. return Lists;
  686. }
  687. private void IsAttributeEquals()
  688. {
  689. var list = ConvertLists();
  690. if (list != null)
  691. {
  692. var temp = list[0];
  693. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  694. isNoEqualsDir.Add("Color", false);
  695. isNoEqualsDir.Add("Shape", false);
  696. string tempShape = "";
  697. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  698. {
  699. if (temp.PageIndex == point.PageIndex && temp.AnnotIndex == point.AnnotIndex)
  700. {
  701. tempShape = point.Shape;
  702. }
  703. }
  704. foreach (var item in list)
  705. {
  706. if (item == list[0])
  707. continue;
  708. if (isNoEqualsDir["Shape"] == false)
  709. {
  710. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  711. {
  712. if (item.PageIndex == point.PageIndex && item.AnnotIndex == point.AnnotIndex)
  713. {
  714. lineWidthMultiple = 1;
  715. if (point.Shape != tempShape)
  716. {
  717. isNoEqualsDir["Shape"] = true;
  718. }
  719. }
  720. }
  721. }
  722. if (isNoEqualsDir["Color"] == false)
  723. {
  724. if (temp.InkColor.A != item.InkColor.A || temp.InkColor.R != item.InkColor.R || temp.InkColor.G != item.InkColor.G || temp.InkColor.B != item.InkColor.B)
  725. {
  726. ShapeColorColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  727. isNoEqualsDir["Color"] = true;
  728. }
  729. }
  730. }
  731. if (isNoEqualsDir["Shape"] == false)
  732. {
  733. if (tempShape == "DotShape")
  734. {
  735. DotIsChecked = true;
  736. }
  737. if (tempShape == "LineShape")
  738. {
  739. LineIsChecked = true;
  740. }
  741. if (tempShape == "HookShape")
  742. {
  743. HookIsChecked = true;
  744. }
  745. if (tempShape == "RectShape")
  746. {
  747. RectIsChecked = true;
  748. }
  749. if (tempShape == "ForkShape")
  750. {
  751. ForkIsChecked = true;
  752. }
  753. }
  754. if (isNoEqualsDir["Color"] == false)
  755. {
  756. ShapeColorColor = new SolidColorBrush(temp.InkColor);
  757. }
  758. }
  759. }
  760. private void GetAnnotProperty(string shape)
  761. {
  762. if (Annot is FreehandAnnotArgs)
  763. {
  764. var annot = Annot as FreehandAnnotArgs;
  765. if (annot != null)
  766. {
  767. try
  768. {
  769. foreach (var point in fillAndSignContentViewModel.viewContentViewModel.FillAndSign)
  770. {
  771. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  772. {
  773. lineWidthMultiple = 1;
  774. if (point.Shape == "DotShape")
  775. {
  776. DotIsChecked = true;
  777. lineWidthMultiple = 5;
  778. LineWidth = annot.LineWidth / 5;
  779. }
  780. else { LineWidth = annot.LineWidth; }
  781. if (point.Shape == "LineShape")
  782. {
  783. LineIsChecked = true;
  784. }
  785. if (point.Shape == "HookShape")
  786. {
  787. HookIsChecked = true;
  788. }
  789. if (point.Shape == "RectShape")
  790. {
  791. RectIsChecked = true;
  792. }
  793. if (point.Shape == "ForkShape")
  794. {
  795. ForkIsChecked = true;
  796. }
  797. SelectColor = new SolidColorBrush(annot.InkColor);
  798. FillOpacity = annot.Transparency;
  799. InitShapesType(point.Shape);
  800. Shape = point.Shape;
  801. }
  802. }
  803. }
  804. catch
  805. {
  806. }
  807. }
  808. }
  809. }
  810. }
  811. }