SharpsAnnotPropertyViewModel.cs 35 KB

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