ShapFillPropertyViewModel.cs 37 KB

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