SharpsAnnotPropertyViewModel.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using ComPDFKitViewer.PdfViewer;
  5. using ImTools;
  6. using PDF_Master.CustomControl.CompositeControl;
  7. using PDF_Master.Helper;
  8. using PDF_Master.Model;
  9. using PDF_Master.Model.AnnotPanel;
  10. using PDF_Master.Properties;
  11. using PDF_Master.ViewModels.Tools;
  12. using PDF_Master.ViewModels.Tools.AnnotManager;
  13. using PDF_Master.Views.Tools;
  14. using PDFSettings;
  15. using Prism.Commands;
  16. using Prism.Mvvm;
  17. using Prism.Regions;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Drawing;
  21. using System.Globalization;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using System.Windows;
  26. using System.Windows.Controls;
  27. using System.Windows.Data;
  28. using System.Windows.Media;
  29. using static Dropbox.Api.UsersCommon.AccountType;
  30. using Color = System.Windows.Media.Color;
  31. using Point = System.Windows.Point;
  32. namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
  33. {
  34. public class DashStyleConverter : IValueConverter
  35. {
  36. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  37. {
  38. if (value is DashStyle)
  39. {
  40. var dash = value as DashStyle;
  41. if (dash.Dashes == null || dash.Dashes.Count == 0 || dash.Dashes[0] == 0)
  42. {
  43. return DashStyles.Solid.Dashes;
  44. }
  45. else
  46. {
  47. DashStyle dashx = new DashStyle();
  48. dashx.Dashes.Add(1);
  49. dashx.Dashes.Add(1);
  50. return dashx.Dashes;
  51. }
  52. }
  53. return value;
  54. }
  55. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  56. {
  57. throw new NotImplementedException();
  58. }
  59. }
  60. public class SharpsAnnotPropertyViewModel : BindableBase, INavigationAware
  61. {
  62. #region 属性
  63. private bool isRect = false;
  64. public bool IsRect
  65. {
  66. get { return isRect; }
  67. set => SetProperty(ref isRect, value);
  68. }
  69. private bool isCircle = false;
  70. public bool IsCircle
  71. {
  72. get { return isCircle; }
  73. set => SetProperty(ref isCircle, value);
  74. }
  75. private bool isArrow = false;
  76. public bool IsArrow
  77. {
  78. get { return isArrow; }
  79. set => SetProperty(ref isArrow, value);
  80. }
  81. private bool isLine = false;
  82. public bool IsLine
  83. {
  84. get { return isLine; }
  85. set => SetProperty(ref isLine, value);
  86. }
  87. private string _strShapeChecked = "";
  88. public string StrShapeChecked
  89. {
  90. get { return _strShapeChecked; }
  91. set
  92. {
  93. SetProperty(ref _strShapeChecked, value);
  94. }
  95. }
  96. public List<ComboDataItem> ThicknessItems { get; protected set; }
  97. private AnnotCommon _basicVm = new AnnotCommon();
  98. public AnnotCommon BasicVm
  99. {
  100. get { return _basicVm; }
  101. set => SetProperty(ref _basicVm, value);
  102. }
  103. private Geometry dataPath = null;
  104. public Geometry DataPath
  105. {
  106. get { return dataPath; }
  107. set
  108. {
  109. SetProperty(ref dataPath, value);
  110. }
  111. }
  112. private DashStyle dash = new DashStyle();
  113. public DashStyle Dash
  114. {
  115. get { return dash; }
  116. set
  117. {
  118. SetProperty(ref dash, value);
  119. }
  120. }
  121. private bool _isLineAnnot = false;
  122. public bool IsLineAnnot
  123. {
  124. get { return _isLineAnnot; }
  125. set
  126. {
  127. SetProperty(ref _isLineAnnot, value);
  128. }
  129. }
  130. #endregion 属性
  131. private string RectangleTitle = App.MainPageLoader.GetString("ViewRightMenuBlankSpaceAddComment_Rectangle");
  132. private string CircleTitle = App.MainPageLoader.GetString("ViewRightMenuSelection_Oval");
  133. private string ArrowTitle = App.MainPageLoader.GetString("ViewRightMenu_Arrow");
  134. private string LineTitle = App.MainPageLoader.GetString("ViewRightMenuBlankSpaceAddComment_StraightLine");
  135. public DelegateCommand<object> SelectedThickCommand { get; set; }
  136. public DelegateCommand<object> SelectedBorderColorCommand { get; set; }
  137. public DelegateCommand<object> SelectedFillOpacityCommand { get; set; }
  138. public DelegateCommand<object> SelectedFillColorCommand { get; set; }
  139. public DelegateCommand<object> LineStyleCommand { get; set; }
  140. public DelegateCommand<object> SharpsTypeCommand { get; set; }
  141. public DelegateCommand<object> ThicknessChangedCommand { get; set; }
  142. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  143. public event EventHandler<object> LoadPropertyHandler;
  144. public IRegionManager region;
  145. public SharpsAnnotPropertyViewModel(IRegionManager regionManager)
  146. {
  147. region = regionManager;
  148. InitColorItems();
  149. InitFillColorItems();
  150. InitThicknessItems();
  151. SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
  152. SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity_Command);
  153. SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColor_Command);
  154. SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
  155. SelectedBorderColorCommand = new DelegateCommand<object>(SelectedBorderColor);
  156. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  157. ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
  158. LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
  159. }
  160. private void InitThicknessItems()
  161. {
  162. ThicknessItems = new List<ComboDataItem>();
  163. ComboDataItem item = new ComboDataItem(1, "pt");
  164. ThicknessItems.Add(item);
  165. item = new ComboDataItem(2, "pt");
  166. ThicknessItems.Add(item);
  167. item = new ComboDataItem(4, "pt");
  168. ThicknessItems.Add(item);
  169. item = new ComboDataItem(6, "pt");
  170. ThicknessItems.Add(item);
  171. item = new ComboDataItem(8, "pt");
  172. ThicknessItems.Add(item);
  173. }
  174. private void InitColorItems()
  175. {
  176. BasicVm.ColorItems = AnnotColorList.GetColorList(ColorSelectorType.Border);
  177. }
  178. private void InitFillColorItems()
  179. {
  180. BasicVm.FillColorItems = AnnotColorList.GetColorList(ColorSelectorType.Fill);
  181. }
  182. private void ThicknessChanged_Command(object obj)
  183. {
  184. if (obj != null)
  185. {
  186. var item = (ComboBoxItem)obj;
  187. var content = (string)item.Content;
  188. if (content != null)
  189. {
  190. var intData = int.Parse(content);
  191. BasicVm.AnnotThickness = intData;
  192. }
  193. }
  194. }
  195. private void SharpsType_Command(object obj)
  196. {
  197. if (obj != null)
  198. {
  199. var tag = (string)obj;
  200. SharpsType(tag, true);
  201. }
  202. }
  203. private void SharpsType(string tag, bool isFromToolsBtn = false)
  204. {
  205. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  206. switch (tag)
  207. {
  208. case "Rect":
  209. RectangleGeometry rectPath = new RectangleGeometry();
  210. rectPath.Rect = new Rect(0, 5, 28, 22);
  211. DataPath = rectPath;
  212. changeData[AnnotArgsType.AnnotSquare] = tag;
  213. IsLineAnnot = false;
  214. break;
  215. case "Circle":
  216. EllipseGeometry circlePath = new EllipseGeometry();
  217. circlePath.RadiusX = 14;
  218. circlePath.RadiusY = 14;
  219. circlePath.Center = new Point(14, 14);
  220. DataPath = circlePath;
  221. changeData[AnnotArgsType.AnnotCircle] = tag;
  222. IsLineAnnot = false;
  223. break;
  224. case "Arrow":
  225. {
  226. ArrowHelper arrowLine = new ArrowHelper();
  227. arrowLine.ArrowLength = 8;
  228. arrowLine.LineStart = new Point(8, 24);
  229. arrowLine.LineEnd = new Point(24, 8);
  230. arrowLine.StartSharp = C_LINE_TYPE.LINETYPE_NONE;
  231. arrowLine.EndSharp = C_LINE_TYPE.LINETYPE_ARROW;
  232. DataPath = arrowLine.BuildArrowBody();
  233. changeData[AnnotArgsType.AnnotLine] = tag;
  234. if (IsLineAnnot == false)
  235. IsLineAnnot = true;
  236. }
  237. break;
  238. case "Line":
  239. {
  240. ArrowHelper arrowLine = new ArrowHelper();
  241. arrowLine.LineStart = new Point(0, 32);
  242. arrowLine.LineEnd = new Point(32, 0);
  243. DataPath = arrowLine.BuildArrowBody();
  244. changeData[AnnotArgsType.AnnotLine] = tag;
  245. if (IsLineAnnot == false)
  246. IsLineAnnot = true;
  247. }
  248. break;
  249. }
  250. if (isFromToolsBtn)
  251. PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  252. StrShapeChecked = tag;
  253. PropertyPanel.SharpsAnnot = tag;
  254. BasicVm.SetOtherTag(tag);
  255. }
  256. private void LineStyle_Command(object obj)
  257. {
  258. if (obj != null)
  259. {
  260. var tag = obj as string;
  261. if (tag == "Solid")
  262. {
  263. DashStyle dashAnnot = new DashStyle();
  264. dashAnnot.Dashes.Add(0);
  265. dashAnnot.Dashes.Add(0);
  266. Dash = dashAnnot;
  267. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
  268. }
  269. else
  270. {
  271. DashStyle dashAnnot = new DashStyle();
  272. dashAnnot.Dashes.Add(1);
  273. dashAnnot.Dashes.Add(1);
  274. Dash = dashAnnot;
  275. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.LineStyle, dash);
  276. }
  277. if (BasicVm.IsMultiSelected == false)
  278. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  279. }
  280. }
  281. private void SelectedFillColor_Command(object obj)
  282. {
  283. if (obj != null && PropertyPanel != null)
  284. {
  285. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  286. GetLastAnnot();
  287. var colorValue = (Color)obj;
  288. if (colorValue != null)
  289. {
  290. BasicVm.FillColor = new SolidColorBrush(colorValue);
  291. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  292. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue);
  293. if (BasicVm.IsMultiSelected == false)
  294. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  295. }
  296. }
  297. }
  298. private void GetLastAnnot()
  299. {
  300. if (PropertyPanel.annot == null)
  301. {
  302. AnnotHandlerEventArgs annotArgs = null;
  303. bool isLastAnnot = (PropertyPanel.LastArrowAnnot != null ? true : false);
  304. switch (PropertyPanel.SharpsAnnot)
  305. {
  306. case "Rect":
  307. annotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare];
  308. break;
  309. case "Circle":
  310. annotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle];
  311. break;
  312. case "Arrow":
  313. if (isLastAnnot)
  314. {
  315. annotArgs = PropertyPanel.LastArrowAnnot;
  316. }
  317. break;
  318. case "Line":
  319. annotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine];
  320. break;
  321. }
  322. annotArgs.PageIndex = -1;
  323. annotArgs.AnnotIndex = -1;
  324. annotArgs.ClientRect = Rect.Empty;
  325. PropertyPanel.annot = annotArgs;
  326. Annot = annotArgs;
  327. PropertyPanel.annotlists = new List<AnnotHandlerEventArgs>();
  328. PropertyPanel.annotlists.Add(PropertyPanel.annot);
  329. PropertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(Annot, Annot.GetAnnotAttrib());
  330. }
  331. }
  332. private void SelectedFillOpacity_Command(object obj)
  333. {
  334. if (obj != null)
  335. {
  336. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  337. GetLastAnnot();
  338. BasicVm.FillOpacity = (double)obj;
  339. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  340. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  341. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  342. }
  343. }
  344. private void SelectedOpacityValue(object obj)
  345. {
  346. if (obj != null)
  347. {
  348. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  349. GetLastAnnot();
  350. BasicVm.FillOpacity = (double)obj;
  351. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  352. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  353. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  354. }
  355. }
  356. private void SelectedBorderColor(object obj)
  357. {
  358. if (obj != null && PropertyPanel != null)
  359. {
  360. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  361. GetLastAnnot();
  362. var colorValue = (Color)obj;
  363. if (colorValue != null)
  364. {
  365. BasicVm.BorderColor = new SolidColorBrush(colorValue);
  366. BasicVm.BorderColor.Opacity = BasicVm.BorderOpacity;
  367. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
  368. if (BasicVm.IsMultiSelected == false)
  369. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  370. }
  371. }
  372. }
  373. private void SelectedThick_Command(object obj)
  374. {
  375. if (obj is double)
  376. {
  377. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  378. //GetLastAnnot();
  379. var tran = (double)obj;
  380. AnnotArgsType argsType = AnnotArgsType.AnnotSquare;
  381. bool isLine = false;
  382. switch (BasicVm.strOtherTag)
  383. {
  384. case "Rect":
  385. argsType = AnnotArgsType.AnnotSquare;
  386. break;
  387. case "Circle":
  388. argsType = AnnotArgsType.AnnotCircle;
  389. break;
  390. case "Line":
  391. argsType = AnnotArgsType.AnnotLine;
  392. isLine = true;
  393. break;
  394. case "Arrow":
  395. argsType = AnnotArgsType.AnnotLine;
  396. isLine = false;
  397. break;
  398. }
  399. if (BasicVm.IsMultiSelected == false)
  400. {
  401. if (argsType == BasicVm.AnnotType)
  402. {
  403. //if(argsType== AnnotArgsType.AnnotLine && isLine)
  404. BasicVm.AnnotThickness = tran;
  405. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, tran);
  406. }
  407. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  408. }
  409. else
  410. {
  411. BasicVm.AnnotThickness = tran;
  412. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, tran);
  413. }
  414. }
  415. }
  416. public bool IsNavigationTarget(NavigationContext navigationContext)
  417. {
  418. return true;
  419. }
  420. public void OnNavigatedFrom(NavigationContext navigationContext)
  421. {
  422. BasicVm.IsMultiSelected = false;
  423. //PropertyPanel.annot = null;
  424. //PropertyPanel.AnnotEvents = null;
  425. //PropertyPanel.AnnotEvent = null;
  426. //PropertyPanel.annotlists = null;
  427. //AnnotEvent = null;
  428. //Annot = null;
  429. }
  430. private void SetAnnotType()
  431. {
  432. switch (BasicVm.AnnotType)
  433. {
  434. case AnnotArgsType.AnnotCircle:
  435. BasicVm.AnnotTypeTitle = CircleTitle;
  436. break;
  437. case AnnotArgsType.AnnotSquare:
  438. BasicVm.AnnotTypeTitle = RectangleTitle;
  439. break;
  440. case AnnotArgsType.AnnotLine:
  441. var annotLine = Annot as LineAnnotArgs;
  442. if (annotLine != null)
  443. {
  444. if (annotLine.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annotLine.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
  445. BasicVm.AnnotTypeTitle = ArrowTitle;
  446. else
  447. BasicVm.AnnotTypeTitle =LineTitle;
  448. }
  449. break;
  450. }
  451. }
  452. public AnnotAttribEvent AnnotEvent { get; set; }
  453. public AnnotHandlerEventArgs Annot;
  454. public AnnotTransfer PropertyPanel;
  455. public ViewContentViewModel ViewContentViewModel;
  456. public void OnNavigatedTo(NavigationContext navigationContext)
  457. {
  458. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  459. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out ViewContentViewModel);
  460. if (PropertyPanel != null)
  461. {
  462. AnnotEvent = PropertyPanel.AnnotEvent;
  463. BasicVm.AnnotType = PropertyPanel.annot.EventType;
  464. Annot = PropertyPanel.annot;
  465. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  466. if (BasicVm.IsMultiSelected)
  467. {
  468. BasicVm.IsSharpAnnotSelected = !BasicVm.IsMultiSelected;
  469. IsAttributeEquals();
  470. }
  471. else
  472. {
  473. BasicVm.IsSharpAnnotSelected = PropertyPanel.IsSharpAnnotSelected;
  474. GetAnnotProperty();
  475. }
  476. LoadPropertyHandler?.Invoke(null, Annot);
  477. }
  478. }
  479. private List<AnnotHandlerEventArgs> ConvertLists()
  480. {
  481. List<AnnotHandlerEventArgs> FreeTextLists = new List<AnnotHandlerEventArgs>();
  482. foreach (var item in PropertyPanel.annotlists)
  483. {
  484. var itemFreeText = item as AnnotHandlerEventArgs;
  485. if (itemFreeText != null)
  486. {
  487. FreeTextLists.Add(itemFreeText);
  488. }
  489. }
  490. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  491. return null;
  492. else
  493. return FreeTextLists;
  494. }
  495. private void IsAttributeEquals()
  496. {
  497. int isAnnotArgs = 0;
  498. CircleAnnotArgs args = new CircleAnnotArgs();
  499. SquareAnnotArgs argsSquare = new SquareAnnotArgs();
  500. LineAnnotArgs argsLine = new LineAnnotArgs();
  501. var list = ConvertLists();
  502. Color LineColor = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  503. Color BgColor = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  504. double LineWidth = 2;
  505. DashStyle LineDash = new DashStyle();
  506. Color LineColoritem = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  507. Color BgColoritem = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  508. double LineWidthitem = 2;
  509. DashStyle LineDashitem = new DashStyle();
  510. if (list != null)
  511. {
  512. var temp = list[0];
  513. switch (temp.EventType)
  514. {
  515. case AnnotArgsType.AnnotCircle:
  516. args = temp as CircleAnnotArgs;
  517. LineColor = args.LineColor;
  518. BgColor = args.BgColor;
  519. LineWidth = args.LineWidth;
  520. LineDash = args.LineDash;
  521. break;
  522. case AnnotArgsType.AnnotSquare:
  523. argsSquare = temp as SquareAnnotArgs;
  524. LineColor = argsSquare.LineColor;
  525. BgColor = argsSquare.BgColor;
  526. LineWidth = argsSquare.LineWidth;
  527. LineDash = argsSquare.LineDash;
  528. break;
  529. case AnnotArgsType.AnnotLine:
  530. argsLine = temp as LineAnnotArgs;
  531. IsLineAnnot = true;
  532. LineColor = argsLine.LineColor;
  533. LineWidth = argsLine.LineWidth;
  534. LineDash = argsLine.LineDash;
  535. break;
  536. }
  537. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  538. isNoEqualsDir.Add("FillColor", false);
  539. isNoEqualsDir.Add("LineColor", false);
  540. isNoEqualsDir.Add("Thickness", false);
  541. isNoEqualsDir.Add("ThickSolidDashStyle", false);
  542. isNoEqualsDir.Add("AnnotTypeTitle", false);
  543. foreach (var item in list)
  544. {
  545. if (item is SquareAnnotArgs)
  546. {
  547. argsSquare = item as SquareAnnotArgs;
  548. LineColoritem = argsSquare.LineColor;
  549. BgColoritem = argsSquare.BgColor;
  550. LineWidthitem = argsSquare.LineWidth;
  551. LineDashitem = argsSquare.LineDash;
  552. }
  553. if (item is CircleAnnotArgs)
  554. {
  555. args = item as CircleAnnotArgs;
  556. LineColoritem = args.LineColor;
  557. BgColoritem = args.BgColor;
  558. LineWidthitem = args.LineWidth;
  559. LineDashitem = args.LineDash;
  560. }
  561. if (item is LineAnnotArgs)
  562. {
  563. argsLine = item as LineAnnotArgs;
  564. IsLineAnnot = true;
  565. LineColoritem = argsLine.LineColor;
  566. LineWidthitem = argsLine.LineWidth;
  567. LineDashitem = argsLine.LineDash;
  568. }
  569. if (item == list[0])
  570. continue;
  571. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  572. {
  573. if (temp.EventType != item.EventType)
  574. {
  575. BasicVm.AnnotTypeTitle = "Other";
  576. isNoEqualsDir["AnnotTypeTitle"] = true;
  577. }
  578. else
  579. {
  580. var annotLinetemp = temp as LineAnnotArgs;
  581. var annotLineitem = item as LineAnnotArgs;
  582. if (annotLineitem != null && annotLinetemp != null)
  583. {
  584. if (annotLinetemp.TailLineType != annotLineitem.TailLineType)
  585. {
  586. BasicVm.AnnotTypeTitle = "Other";
  587. isNoEqualsDir["AnnotTypeTitle"] = true;
  588. }
  589. }
  590. }
  591. }
  592. if (isNoEqualsDir["FillColor"] == false)
  593. {
  594. if (BgColor.A != BgColoritem.A || BgColor.R != BgColoritem.R || BgColor.G != BgColoritem.G || BgColor.B != BgColoritem.B)
  595. {
  596. BasicVm.FillColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  597. isNoEqualsDir["FillColor"] = true;
  598. }
  599. }
  600. if (isNoEqualsDir["LineColor"] == false)
  601. {
  602. if (LineColor.A != LineColoritem.A || LineColor.R != LineColoritem.R || LineColor.G != LineColoritem.G || LineColor.B != LineColoritem.B)
  603. {
  604. BasicVm.BorderColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  605. isNoEqualsDir["LineColor"] = true;
  606. }
  607. }
  608. if (isNoEqualsDir["Thickness"] == false)
  609. {
  610. isNoEqualsDir["Thickness"] = true;
  611. if (LineWidth > LineWidthitem)
  612. {
  613. BasicVm.AnnotThickness = LineWidth;
  614. }
  615. else
  616. {
  617. BasicVm.AnnotThickness = LineWidthitem;
  618. }
  619. }
  620. if (isNoEqualsDir["ThickSolidDashStyle"] == false)
  621. {
  622. if (AnnotTransfer.IsSolidStyle(LineDash) != AnnotTransfer.IsSolidStyle(LineDashitem))
  623. {
  624. isNoEqualsDir["ThickSolidDashStyle"] = true;
  625. }
  626. }
  627. }
  628. ////以下是多选注释的属性相等时
  629. if (isNoEqualsDir["FillColor"] == false)
  630. {
  631. BasicVm.FillColor = new SolidColorBrush(BgColor);
  632. }
  633. if (isNoEqualsDir["LineColor"] == false)
  634. {
  635. BasicVm.BorderColor = new SolidColorBrush(LineColor);
  636. }
  637. if (isNoEqualsDir["Thickness"] == false)
  638. {
  639. BasicVm.AnnotThickness = LineWidth;
  640. }
  641. if (isNoEqualsDir["ThickSolidDashStyle"] == true)
  642. {
  643. BasicVm.IsSolidLine = BasicVm.IsDashLine = false;
  644. }
  645. else
  646. {
  647. var isSolid = AnnotTransfer.IsSolidStyle(LineDash);
  648. BasicVm.IsSolidLine = isSolid;
  649. BasicVm.IsDashLine = !isSolid;
  650. }
  651. }
  652. }
  653. private bool IsSolidStyle(AnnotHandlerEventArgs annot)
  654. {
  655. bool isSolid = true;
  656. if (annot is SquareAnnotArgs)
  657. {
  658. var Square = Annot as SquareAnnotArgs;
  659. isSolid = AnnotTransfer.IsSolidStyle(Square.LineDash);
  660. }
  661. else if (annot is CircleAnnotArgs)
  662. {
  663. var Circle = Annot as CircleAnnotArgs;
  664. isSolid = AnnotTransfer.IsSolidStyle(Circle.LineDash);
  665. }
  666. else if (annot is LineAnnotArgs)
  667. {
  668. var line = Annot as LineAnnotArgs;
  669. isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
  670. }
  671. return isSolid;
  672. }
  673. private void GetAnnotProperty()
  674. {
  675. if (Annot != null)
  676. {
  677. bool isSolid = true;
  678. switch (Annot.EventType)
  679. {
  680. case AnnotArgsType.AnnotSquare:
  681. if (Annot is SquareAnnotArgs)
  682. {
  683. var Square = Annot as SquareAnnotArgs;
  684. BasicVm.BorderColor = new SolidColorBrush(Square.LineColor);
  685. BasicVm.FillColor = new SolidColorBrush(Square.BgColor);
  686. BasicVm.BorderOpacity = Square.Transparency;
  687. BasicVm.FillOpacity = Square.Transparency;
  688. BasicVm.AnnotThickness = Square.LineWidth;
  689. Dash = Square.LineDash;
  690. SharpsType("Rect", false);
  691. BasicVm.AnnotTypeTitle = RectangleTitle;
  692. IsLineAnnot = false;
  693. IsRect = true;
  694. }
  695. break;
  696. case AnnotArgsType.AnnotCircle:
  697. if (Annot is CircleAnnotArgs)
  698. {
  699. var Circle = Annot as CircleAnnotArgs;
  700. BasicVm.BorderColor = new SolidColorBrush(Circle.LineColor);
  701. BasicVm.FillColor = new SolidColorBrush(Circle.BgColor);
  702. BasicVm.BorderOpacity = Circle.Transparency;
  703. BasicVm.FillOpacity = Circle.Transparency;
  704. BasicVm.AnnotThickness = Circle.LineWidth;
  705. Dash = Circle.LineDash;
  706. SharpsType("Circle", false);
  707. BasicVm.AnnotTypeTitle = CircleTitle;
  708. IsLineAnnot = false;
  709. IsCircle = true;
  710. }
  711. break;
  712. case AnnotArgsType.AnnotLine:
  713. if (Annot is LineAnnotArgs)
  714. {
  715. var line = Annot as LineAnnotArgs;
  716. BasicVm.BorderColor = new SolidColorBrush(line.LineColor);
  717. BasicVm.FillColor = new SolidColorBrush(line.LineColor);
  718. BasicVm.BorderOpacity = line.Transparency;
  719. BasicVm.FillOpacity = line.Transparency;
  720. BasicVm.AnnotThickness = line.LineWidth;
  721. Dash = line.LineDash;
  722. if (line.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && line.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
  723. {
  724. SharpsType("Arrow", false);
  725. BasicVm.AnnotTypeTitle = ArrowTitle;
  726. IsArrow = true;
  727. }
  728. else
  729. {
  730. SharpsType("Line", false);
  731. BasicVm.AnnotTypeTitle = LineTitle;
  732. IsLine = true;
  733. }
  734. IsLineAnnot = true;
  735. }
  736. break;
  737. }
  738. isSolid = IsSolidStyle(Annot);
  739. BasicVm.IsSolidLine = isSolid;
  740. BasicVm.IsDashLine = !isSolid;
  741. }
  742. }
  743. }
  744. }