SharpsAnnotPropertyViewModel.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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("Annotation-Circle");
  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. if (annotArgs != null)
  323. {
  324. annotArgs.PageIndex = -1;
  325. annotArgs.AnnotIndex = -1;
  326. annotArgs.ClientRect = Rect.Empty;
  327. PropertyPanel.annot = annotArgs;
  328. Annot = annotArgs;
  329. PropertyPanel.annotlists = new List<AnnotHandlerEventArgs>();
  330. PropertyPanel.annotlists.Add(PropertyPanel.annot);
  331. PropertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(Annot, Annot.GetAnnotAttrib());
  332. }
  333. }
  334. }
  335. private void SelectedFillOpacity_Command(object obj)
  336. {
  337. if (obj != null)
  338. {
  339. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  340. GetLastAnnot();
  341. BasicVm.FillOpacity = (double)obj;
  342. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  343. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  344. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  345. }
  346. }
  347. private void SelectedOpacityValue(object obj)
  348. {
  349. if (obj != null)
  350. {
  351. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  352. GetLastAnnot();
  353. BasicVm.FillOpacity = (double)obj;
  354. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  355. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  356. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  357. }
  358. }
  359. private void SelectedBorderColor(object obj)
  360. {
  361. if (obj != null && PropertyPanel != null)
  362. {
  363. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  364. GetLastAnnot();
  365. var colorValue = (Color)obj;
  366. if (colorValue != null)
  367. {
  368. BasicVm.BorderColor = new SolidColorBrush(colorValue);
  369. BasicVm.BorderColor.Opacity = BasicVm.BorderOpacity;
  370. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
  371. if (BasicVm.IsMultiSelected == false)
  372. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  373. }
  374. }
  375. }
  376. private void SelectedThick_Command(object obj)
  377. {
  378. if (obj is double)
  379. {
  380. //点击空白处 后 会 清空当前的注释对象 ,此操作为了修改属性后,添加
  381. //GetLastAnnot();
  382. var tran = (double)obj;
  383. AnnotArgsType argsType = AnnotArgsType.AnnotSquare;
  384. bool isLine = false;
  385. switch (BasicVm.strOtherTag)
  386. {
  387. case "Rect":
  388. argsType = AnnotArgsType.AnnotSquare;
  389. break;
  390. case "Circle":
  391. argsType = AnnotArgsType.AnnotCircle;
  392. break;
  393. case "Line":
  394. argsType = AnnotArgsType.AnnotLine;
  395. isLine = true;
  396. break;
  397. case "Arrow":
  398. argsType = AnnotArgsType.AnnotLine;
  399. isLine = false;
  400. break;
  401. }
  402. if (BasicVm.IsMultiSelected == false)
  403. {
  404. if (argsType == BasicVm.AnnotType)
  405. {
  406. //if(argsType== AnnotArgsType.AnnotLine && isLine)
  407. BasicVm.AnnotThickness = tran;
  408. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, tran);
  409. }
  410. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  411. }
  412. else
  413. {
  414. BasicVm.AnnotThickness = tran;
  415. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, tran);
  416. }
  417. }
  418. }
  419. public bool IsNavigationTarget(NavigationContext navigationContext)
  420. {
  421. return true;
  422. }
  423. public void OnNavigatedFrom(NavigationContext navigationContext)
  424. {
  425. BasicVm.IsMultiSelected = false;
  426. //PropertyPanel.annot = null;
  427. //PropertyPanel.AnnotEvents = null;
  428. //PropertyPanel.AnnotEvent = null;
  429. //PropertyPanel.annotlists = null;
  430. //AnnotEvent = null;
  431. //Annot = null;
  432. }
  433. private void SetAnnotType()
  434. {
  435. switch (BasicVm.AnnotType)
  436. {
  437. case AnnotArgsType.AnnotCircle:
  438. BasicVm.AnnotTypeTitle = CircleTitle;
  439. break;
  440. case AnnotArgsType.AnnotSquare:
  441. BasicVm.AnnotTypeTitle = RectangleTitle;
  442. break;
  443. case AnnotArgsType.AnnotLine:
  444. var annotLine = Annot as LineAnnotArgs;
  445. if (annotLine != null)
  446. {
  447. if (annotLine.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annotLine.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
  448. BasicVm.AnnotTypeTitle = ArrowTitle;
  449. else
  450. BasicVm.AnnotTypeTitle = LineTitle;
  451. }
  452. break;
  453. }
  454. }
  455. public AnnotAttribEvent AnnotEvent { get; set; }
  456. public AnnotHandlerEventArgs Annot;
  457. public AnnotTransfer PropertyPanel;
  458. public ViewContentViewModel ViewContentViewModel;
  459. public void OnNavigatedTo(NavigationContext navigationContext)
  460. {
  461. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  462. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out ViewContentViewModel);
  463. if (PropertyPanel != null)
  464. {
  465. AnnotEvent = PropertyPanel.AnnotEvent;
  466. BasicVm.AnnotType = PropertyPanel.annot.EventType;
  467. Annot = PropertyPanel.annot;
  468. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  469. if (BasicVm.IsMultiSelected)
  470. {
  471. BasicVm.IsSharpAnnotSelected = !BasicVm.IsMultiSelected;
  472. IsAttributeEquals();
  473. }
  474. else
  475. {
  476. BasicVm.IsSharpAnnotSelected = PropertyPanel.IsSharpAnnotSelected;
  477. GetAnnotProperty();
  478. }
  479. LoadPropertyHandler?.Invoke(null, Annot);
  480. }
  481. }
  482. private List<AnnotHandlerEventArgs> ConvertLists()
  483. {
  484. List<AnnotHandlerEventArgs> FreeTextLists = new List<AnnotHandlerEventArgs>();
  485. foreach (var item in PropertyPanel.annotlists)
  486. {
  487. var itemFreeText = item as AnnotHandlerEventArgs;
  488. if (itemFreeText != null)
  489. {
  490. FreeTextLists.Add(itemFreeText);
  491. }
  492. }
  493. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  494. return null;
  495. else
  496. return FreeTextLists;
  497. }
  498. private void IsAttributeEquals()
  499. {
  500. //初始化填充颜色面板显示
  501. IsLineAnnot = false;
  502. int isAnnotArgs = 0;
  503. CircleAnnotArgs args = new CircleAnnotArgs();
  504. SquareAnnotArgs argsSquare = new SquareAnnotArgs();
  505. LineAnnotArgs argsLine = new LineAnnotArgs();
  506. var list = ConvertLists();
  507. Color LineColor = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  508. Color BgColor = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  509. double LineWidth = 2;
  510. DashStyle LineDash = new DashStyle();
  511. Color LineColoritem = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  512. Color BgColoritem = Color.FromArgb(0x01, 0xff, 0xff, 0xff);
  513. double LineWidthitem = 2;
  514. DashStyle LineDashitem = new DashStyle();
  515. if (list != null)
  516. {
  517. var temp = list[0];
  518. switch (temp.EventType)
  519. {
  520. case AnnotArgsType.AnnotCircle:
  521. args = temp as CircleAnnotArgs;
  522. LineColor = args.LineColor;
  523. BgColor = args.BgColor;
  524. LineWidth = args.LineWidth;
  525. LineDash = args.LineDash;
  526. break;
  527. case AnnotArgsType.AnnotSquare:
  528. argsSquare = temp as SquareAnnotArgs;
  529. LineColor = argsSquare.LineColor;
  530. BgColor = argsSquare.BgColor;
  531. LineWidth = argsSquare.LineWidth;
  532. LineDash = argsSquare.LineDash;
  533. break;
  534. case AnnotArgsType.AnnotLine:
  535. argsLine = temp as LineAnnotArgs;
  536. IsLineAnnot = true;
  537. LineColor = argsLine.LineColor;
  538. LineWidth = argsLine.LineWidth;
  539. LineDash = argsLine.LineDash;
  540. break;
  541. }
  542. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  543. isNoEqualsDir.Add("FillColor", false);
  544. isNoEqualsDir.Add("LineColor", false);
  545. isNoEqualsDir.Add("Thickness", false);
  546. isNoEqualsDir.Add("ThickSolidDashStyle", false);
  547. isNoEqualsDir.Add("AnnotTypeTitle", false);
  548. var annots = list.FindAll(u => u.EventType == AnnotArgsType.AnnotSquare);
  549. if (annots.Count == list.Count)
  550. {
  551. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  552. {
  553. BasicVm.AnnotTypeTitle = RectangleTitle;
  554. isNoEqualsDir["AnnotTypeTitle"] = true;
  555. }
  556. }
  557. annots = list.FindAll(u => u.EventType == AnnotArgsType.AnnotCircle);
  558. if (annots.Count == list.Count)
  559. {
  560. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  561. {
  562. BasicVm.AnnotTypeTitle = CircleTitle;
  563. isNoEqualsDir["AnnotTypeTitle"] = true;
  564. }
  565. }
  566. annots = list.FindAll(u => u.EventType == AnnotArgsType.AnnotLine);
  567. if (annots.Count == list.Count)
  568. {
  569. var annotsArrow = list.FindAll(u => (u as LineAnnotArgs).TailLineType == C_LINE_TYPE.LINETYPE_ARROW && (u as LineAnnotArgs).HeadLineType == C_LINE_TYPE.LINETYPE_NONE);
  570. if (annots.Count == annotsArrow.Count)
  571. {
  572. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  573. {
  574. BasicVm.AnnotTypeTitle = ArrowTitle;
  575. isNoEqualsDir["AnnotTypeTitle"] = true;
  576. }
  577. }
  578. var annotsLine = list.FindAll(u => (u as LineAnnotArgs).TailLineType == C_LINE_TYPE.LINETYPE_NONE && (u as LineAnnotArgs).HeadLineType == C_LINE_TYPE.LINETYPE_NONE);
  579. if (annots.Count == annotsLine.Count)
  580. {
  581. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  582. {
  583. BasicVm.AnnotTypeTitle = LineTitle;
  584. isNoEqualsDir["AnnotTypeTitle"] = true;
  585. }
  586. }
  587. else
  588. {
  589. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  590. {
  591. BasicVm.AnnotTypeTitle = "Other";
  592. isNoEqualsDir["AnnotTypeTitle"] = true;
  593. }
  594. }
  595. }
  596. else
  597. {
  598. if (isNoEqualsDir["AnnotTypeTitle"] == false)
  599. {
  600. BasicVm.AnnotTypeTitle = "Other";
  601. isNoEqualsDir["AnnotTypeTitle"] = true;
  602. }
  603. }
  604. foreach (var item in list)
  605. {
  606. if (item is SquareAnnotArgs)
  607. {
  608. argsSquare = item as SquareAnnotArgs;
  609. LineColoritem = argsSquare.LineColor;
  610. BgColoritem = argsSquare.BgColor;
  611. LineWidthitem = argsSquare.LineWidth;
  612. LineDashitem = argsSquare.LineDash;
  613. }
  614. if (item is CircleAnnotArgs)
  615. {
  616. args = item as CircleAnnotArgs;
  617. LineColoritem = args.LineColor;
  618. BgColoritem = args.BgColor;
  619. LineWidthitem = args.LineWidth;
  620. LineDashitem = args.LineDash;
  621. }
  622. if (item is LineAnnotArgs)
  623. {
  624. argsLine = item as LineAnnotArgs;
  625. IsLineAnnot = true;
  626. LineColoritem = argsLine.LineColor;
  627. LineWidthitem = argsLine.LineWidth;
  628. LineDashitem = argsLine.LineDash;
  629. }
  630. if (item == list[0])
  631. {
  632. continue;
  633. }
  634. //if (isNoEqualsDir["AnnotTypeTitle"] == false)
  635. //{
  636. // if (temp.EventType != item.EventType)
  637. // {
  638. // BasicVm.AnnotTypeTitle = "Other";
  639. // isNoEqualsDir["AnnotTypeTitle"] = true;
  640. // }
  641. // else
  642. // {
  643. // var annotLinetemp = temp as LineAnnotArgs;
  644. // var annotLineitem = item as LineAnnotArgs;
  645. // if (annotLineitem != null && annotLinetemp != null)
  646. // {
  647. // if (annotLinetemp.TailLineType != annotLineitem.TailLineType)
  648. // {
  649. // BasicVm.AnnotTypeTitle = "Other";
  650. // isNoEqualsDir["AnnotTypeTitle"] = true;
  651. // }
  652. // }
  653. // }
  654. //}
  655. if (isNoEqualsDir["FillColor"] == false)
  656. {
  657. if (BgColor.A != BgColoritem.A || BgColor.R != BgColoritem.R || BgColor.G != BgColoritem.G || BgColor.B != BgColoritem.B)
  658. {
  659. BasicVm.FillColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  660. isNoEqualsDir["FillColor"] = true;
  661. }
  662. }
  663. if (isNoEqualsDir["LineColor"] == false)
  664. {
  665. if (LineColor.A != LineColoritem.A || LineColor.R != LineColoritem.R || LineColor.G != LineColoritem.G || LineColor.B != LineColoritem.B)
  666. {
  667. BasicVm.BorderColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  668. isNoEqualsDir["LineColor"] = true;
  669. }
  670. }
  671. if (isNoEqualsDir["Thickness"] == false)
  672. {
  673. isNoEqualsDir["Thickness"] = true;
  674. if (LineWidth > LineWidthitem)
  675. {
  676. BasicVm.AnnotThickness = LineWidth;
  677. }
  678. else
  679. {
  680. BasicVm.AnnotThickness = LineWidthitem;
  681. }
  682. }
  683. if (isNoEqualsDir["ThickSolidDashStyle"] == false)
  684. {
  685. if (AnnotTransfer.IsSolidStyle(LineDash) != AnnotTransfer.IsSolidStyle(LineDashitem))
  686. {
  687. isNoEqualsDir["ThickSolidDashStyle"] = true;
  688. }
  689. }
  690. }
  691. ////以下是多选注释的属性相等时
  692. if (isNoEqualsDir["FillColor"] == false)
  693. {
  694. BasicVm.FillColor = new SolidColorBrush(BgColor);
  695. }
  696. if (isNoEqualsDir["LineColor"] == false)
  697. {
  698. BasicVm.BorderColor = new SolidColorBrush(LineColor);
  699. }
  700. if (isNoEqualsDir["Thickness"] == false)
  701. {
  702. BasicVm.AnnotThickness = LineWidth;
  703. }
  704. if (isNoEqualsDir["ThickSolidDashStyle"] == true)
  705. {
  706. BasicVm.IsSolidLine = BasicVm.IsDashLine = false;
  707. }
  708. else
  709. {
  710. var isSolid = AnnotTransfer.IsSolidStyle(LineDash);
  711. BasicVm.IsSolidLine = isSolid;
  712. BasicVm.IsDashLine = !isSolid;
  713. }
  714. }
  715. }
  716. private bool IsSolidStyle(AnnotHandlerEventArgs annot)
  717. {
  718. bool isSolid = true;
  719. if (annot is SquareAnnotArgs)
  720. {
  721. var Square = Annot as SquareAnnotArgs;
  722. isSolid = AnnotTransfer.IsSolidStyle(Square.LineDash);
  723. }
  724. else if (annot is CircleAnnotArgs)
  725. {
  726. var Circle = Annot as CircleAnnotArgs;
  727. isSolid = AnnotTransfer.IsSolidStyle(Circle.LineDash);
  728. }
  729. else if (annot is LineAnnotArgs)
  730. {
  731. var line = Annot as LineAnnotArgs;
  732. isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
  733. }
  734. return isSolid;
  735. }
  736. private void GetAnnotProperty()
  737. {
  738. if (Annot != null)
  739. {
  740. bool isSolid = true;
  741. switch (Annot.EventType)
  742. {
  743. case AnnotArgsType.AnnotSquare:
  744. if (Annot is SquareAnnotArgs)
  745. {
  746. var Square = Annot as SquareAnnotArgs;
  747. BasicVm.BorderColor = new SolidColorBrush(Square.LineColor);
  748. BasicVm.FillColor = new SolidColorBrush(Square.BgColor);
  749. BasicVm.BorderOpacity = Square.Transparency;
  750. BasicVm.FillOpacity = Square.Transparency;
  751. BasicVm.AnnotThickness = Square.LineWidth;
  752. Dash = Square.LineDash;
  753. SharpsType("Rect", false);
  754. BasicVm.AnnotTypeTitle = RectangleTitle;
  755. IsLineAnnot = false;
  756. IsRect = true;
  757. }
  758. break;
  759. case AnnotArgsType.AnnotCircle:
  760. if (Annot is CircleAnnotArgs)
  761. {
  762. var Circle = Annot as CircleAnnotArgs;
  763. BasicVm.BorderColor = new SolidColorBrush(Circle.LineColor);
  764. BasicVm.FillColor = new SolidColorBrush(Circle.BgColor);
  765. BasicVm.BorderOpacity = Circle.Transparency;
  766. BasicVm.FillOpacity = Circle.Transparency;
  767. BasicVm.AnnotThickness = Circle.LineWidth;
  768. Dash = Circle.LineDash;
  769. SharpsType("Circle", false);
  770. BasicVm.AnnotTypeTitle = CircleTitle;
  771. IsLineAnnot = false;
  772. IsCircle = true;
  773. }
  774. break;
  775. case AnnotArgsType.AnnotLine:
  776. if (Annot is LineAnnotArgs)
  777. {
  778. var line = Annot as LineAnnotArgs;
  779. BasicVm.BorderColor = new SolidColorBrush(line.LineColor);
  780. BasicVm.FillColor = new SolidColorBrush(line.LineColor);
  781. BasicVm.BorderOpacity = line.Transparency;
  782. BasicVm.FillOpacity = line.Transparency;
  783. BasicVm.AnnotThickness = line.LineWidth;
  784. Dash = line.LineDash;
  785. if (line.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && line.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
  786. {
  787. SharpsType("Arrow", false);
  788. BasicVm.AnnotTypeTitle = ArrowTitle;
  789. IsArrow = true;
  790. }
  791. else
  792. {
  793. SharpsType("Line", false);
  794. BasicVm.AnnotTypeTitle = LineTitle;
  795. IsLine = true;
  796. }
  797. IsLineAnnot = true;
  798. }
  799. break;
  800. }
  801. isSolid = IsSolidStyle(Annot);
  802. BasicVm.IsSolidLine = isSolid;
  803. BasicVm.IsDashLine = !isSolid;
  804. }
  805. }
  806. }
  807. }