ShapFillPropertyViewModel.cs 36 KB

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