AnnotToolContentViewModel.Function.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using Microsoft.Win32;
  5. using PDF_Office.CustomControl;
  6. using PDF_Office.Helper;
  7. using PDF_Office.Properties;
  8. using PDFSettings;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Media;
  18. namespace PDF_Office.ViewModels.Tools
  19. {
  20. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  21. {
  22. #region 初始化
  23. private void BindingEvent()
  24. {
  25. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  26. propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
  27. }
  28. private void InitDefaultValue()
  29. {
  30. InitAnnotHighlight();
  31. InitAnnotUnderline();
  32. InitAnnotSquiggly();
  33. InitAnnotStrikeout();
  34. }
  35. private void InitAnnotHighlight()
  36. {
  37. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  38. if (annotProperty == null)
  39. {
  40. annotProperty = new DefaultAnnotProperty();
  41. annotProperty.AnnotToolType = AnnotArgsType.AnnotHighlight;
  42. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  43. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  44. annotProperty.Opacity = 0.5;
  45. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  46. }
  47. else
  48. {
  49. HighLightColor = new SolidColorBrush(annotProperty.BackgroundColor);
  50. HighLightOpacity = annotProperty.Opacity;
  51. }
  52. }
  53. private void InitAnnotUnderline()
  54. {
  55. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  56. if (annotProperty == null)
  57. {
  58. annotProperty = new DefaultAnnotProperty();
  59. annotProperty.AnnotToolType = AnnotArgsType.AnnotUnderline;
  60. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  61. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  62. annotProperty.Opacity = 0.5;
  63. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  64. }
  65. else
  66. {
  67. UnderLineColor = new SolidColorBrush(annotProperty.BackgroundColor);
  68. UnderLineOpacity = annotProperty.Opacity;
  69. }
  70. }
  71. private void InitAnnotSquiggly()
  72. {
  73. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  74. if (annotProperty == null)
  75. {
  76. annotProperty = new DefaultAnnotProperty();
  77. annotProperty.AnnotToolType = AnnotArgsType.AnnotSquiggly;
  78. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  79. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  80. annotProperty.Opacity = 0.5;
  81. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  82. }
  83. else
  84. {
  85. SquigglyColor = new SolidColorBrush(annotProperty.BackgroundColor);
  86. SquigglyOpacity = annotProperty.Opacity;
  87. }
  88. }
  89. private void InitAnnotStrikeout()
  90. {
  91. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  92. if (annotProperty == null)
  93. {
  94. annotProperty = new DefaultAnnotProperty();
  95. annotProperty.AnnotToolType = AnnotArgsType.AnnotStrikeout;
  96. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  97. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  98. annotProperty.Opacity = 0.5;
  99. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  100. }
  101. else
  102. {
  103. StrikeoutColor = new SolidColorBrush(annotProperty.BackgroundColor);
  104. StrikeoutOpacity = annotProperty.Opacity;
  105. }
  106. }
  107. #endregion
  108. #region 注释工具
  109. /// <summary>
  110. /// 高亮注释
  111. /// </summary>
  112. /// <returns></returns>
  113. private AnnotHandlerEventArgs GetHighLight(TextHighlightAnnotArgs selectedhighlightArgs = null)
  114. {
  115. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  116. TextHighlightAnnotArgs highlightArgs = null;
  117. if(selectedhighlightArgs == null)
  118. {
  119. highlightArgs = new TextHighlightAnnotArgs();
  120. highlightArgs.Color = Color.FromRgb(0xFF, 0xBB, 0x00);
  121. highlightArgs.Transparency = 0.5;
  122. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  123. if (annotProperty != null)
  124. {
  125. highlightArgs.Color = annotProperty.ForgoundColor;
  126. highlightArgs.Transparency = annotProperty.Opacity;
  127. highlightArgs.Content = annotProperty.NoteText;
  128. }
  129. }
  130. else
  131. {
  132. highlightArgs = selectedhighlightArgs;
  133. }
  134. annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
  135. annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
  136. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  137. AddToPropertyPanel(highlightArgs, "HighLight", "TextAnnotProperty", annotAttribsList);
  138. return highlightArgs;
  139. }
  140. private AnnotHandlerEventArgs GetUnderLine(TextUnderlineAnnotArgs selectedunderlineArgs = null)
  141. {
  142. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  143. TextUnderlineAnnotArgs underlineArgs = null;
  144. if (selectedunderlineArgs == null)
  145. {
  146. underlineArgs = new TextUnderlineAnnotArgs();
  147. underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
  148. underlineArgs.Transparency = 1;
  149. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  150. if (annotProperty != null)
  151. {
  152. underlineArgs.Color = annotProperty.ForgoundColor;
  153. underlineArgs.Transparency = annotProperty.Opacity;
  154. underlineArgs.Content = annotProperty.NoteText;
  155. }
  156. }
  157. else
  158. {
  159. underlineArgs = selectedunderlineArgs;
  160. }
  161. annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
  162. annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
  163. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  164. AddToPropertyPanel(underlineArgs, "UnderLine", "TextAnnotProperty", annotAttribsList);
  165. return underlineArgs;
  166. }
  167. private AnnotHandlerEventArgs GetSquiggly(TextSquigglyAnnotArgs selectedsquigglyArgs = null)
  168. {
  169. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  170. TextSquigglyAnnotArgs squigglyArgs = null;
  171. if (selectedsquigglyArgs == null)
  172. {
  173. squigglyArgs = new TextSquigglyAnnotArgs();
  174. squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
  175. squigglyArgs.Transparency = 1;
  176. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  177. if (annotProperty != null)
  178. {
  179. squigglyArgs.Color = annotProperty.ForgoundColor;
  180. squigglyArgs.Transparency = annotProperty.Opacity;
  181. squigglyArgs.Content = annotProperty.NoteText;
  182. }
  183. }
  184. else
  185. {
  186. squigglyArgs = selectedsquigglyArgs;
  187. }
  188. annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
  189. annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
  190. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  191. AddToPropertyPanel(squigglyArgs, "Squiggly", "TextAnnotProperty", annotAttribsList);
  192. return squigglyArgs;
  193. }
  194. private AnnotHandlerEventArgs GetStrikeout(TextStrikeoutAnnotArgs selectedstrikeoutArgs = null)
  195. {
  196. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  197. TextStrikeoutAnnotArgs strikeoutArgs = null;
  198. if(selectedstrikeoutArgs == null)
  199. {
  200. strikeoutArgs = new TextStrikeoutAnnotArgs();
  201. strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
  202. strikeoutArgs.Transparency = 1;
  203. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  204. if (annotProperty != null)
  205. {
  206. strikeoutArgs.Color = annotProperty.ForgoundColor;
  207. strikeoutArgs.Transparency = annotProperty.Opacity;
  208. strikeoutArgs.Content = annotProperty.NoteText;
  209. }
  210. }
  211. else
  212. {
  213. strikeoutArgs = selectedstrikeoutArgs;
  214. }
  215. annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
  216. annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
  217. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  218. AddToPropertyPanel(strikeoutArgs, "Strikeout", "TextAnnotProperty", annotAttribsList);
  219. return strikeoutArgs;
  220. }
  221. private AnnotHandlerEventArgs GetFreehand(FreehandAnnotArgs selectedfreehandArgs = null)
  222. {
  223. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  224. FreehandAnnotArgs freehandArgs = null;
  225. if(selectedfreehandArgs == null)
  226. {
  227. freehandArgs = new FreehandAnnotArgs();
  228. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  229. freehandArgs.Transparency = 1;
  230. freehandArgs.LineWidth = 1;
  231. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
  232. if (annotProperty != null)
  233. {
  234. freehandArgs.InkColor = annotProperty.ForgoundColor;
  235. freehandArgs.Transparency = annotProperty.Opacity;
  236. freehandArgs.LineWidth = annotProperty.Thickness;
  237. freehandArgs.Content = annotProperty.NoteText;
  238. }
  239. }
  240. else
  241. {
  242. freehandArgs = selectedfreehandArgs;
  243. }
  244. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  245. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  246. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  247. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  248. AddToPropertyPanel(freehandArgs, "Freehand", "FreehandAnnotProperty", annotAttribsList);
  249. return freehandArgs;
  250. }
  251. private AnnotHandlerEventArgs GetFreetext(FreeTextAnnotArgs selectedfreetextArgs = null)
  252. {
  253. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  254. FreeTextAnnotArgs freetextArgs = null;
  255. TextAlignment textAlignment;
  256. if (selectedfreetextArgs == null)
  257. {
  258. freetextArgs = new FreeTextAnnotArgs();
  259. freetextArgs.Align = TextAlignment.Left;
  260. freetextArgs.BgColor = Colors.Transparent;
  261. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  262. freetextArgs.FontColor = Colors.Black;
  263. freetextArgs.FontSize = 14;
  264. freetextArgs.Transparency = 1;
  265. freetextArgs.LineColor = Colors.Black;
  266. freetextArgs.LineWidth = 0;
  267. freetextArgs.TextContent = string.Empty;
  268. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  269. if (annotProperty != null)
  270. {
  271. freetextArgs.Align = annotProperty.TextAlign;
  272. freetextArgs.BgColor = annotProperty.BackgroundColor;
  273. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  274. freetextArgs.FontColor = annotProperty.ForgoundColor;
  275. freetextArgs.FontSize = annotProperty.FontSize;
  276. freetextArgs.Transparency = annotProperty.Opacity;
  277. freetextArgs.LineColor = annotProperty.BorderColor;
  278. freetextArgs.LineWidth = annotProperty.Thickness;
  279. freetextArgs.TextContent = annotProperty.NoteText;
  280. freetextArgs.FontWeight = annotProperty.FontWeight;
  281. freetextArgs.FontStyle = annotProperty.FontStyle;
  282. }
  283. int align = Settings.Default.AppProperties.Annotate.TextAlign;
  284. if (align == 0)
  285. textAlignment = TextAlignment.Left;
  286. else if (align == 1)
  287. textAlignment = TextAlignment.Center;
  288. else
  289. textAlignment = TextAlignment.Right;
  290. }
  291. else
  292. {
  293. freetextArgs = selectedfreetextArgs;
  294. textAlignment = freetextArgs.Align;
  295. }
  296. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  297. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  298. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  299. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  300. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  301. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  302. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  303. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  304. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  305. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  306. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  307. AddToPropertyPanel(freetextArgs, "Freetext", "FreetextAnnotProperty", annotAttribsList);
  308. return freetextArgs;
  309. }
  310. private AnnotHandlerEventArgs GetStickyNote()
  311. {
  312. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  313. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  314. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  315. stickyAnnotArgs.StickyNote = string.Empty;
  316. stickyAnnotArgs.Transparency = 1;
  317. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
  318. if (annotProperty != null)
  319. {
  320. stickyAnnotArgs.Color = annotProperty.ForgoundColor;
  321. stickyAnnotArgs.StickyNote = annotProperty.NoteText;
  322. stickyAnnotArgs.Transparency = annotProperty.Opacity;
  323. }
  324. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  325. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  326. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  327. AddToPropertyPanel(stickyAnnotArgs, "StickyNote", "FreetextAnnotProperty", annotAttribsList);
  328. return stickyAnnotArgs;
  329. }
  330. private AnnotHandlerEventArgs GetRect(SquareAnnotArgs selectedsquareArgs = null)
  331. {
  332. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  333. SquareAnnotArgs squareArgs = null;
  334. if(selectedsquareArgs == null)
  335. {
  336. squareArgs = new SquareAnnotArgs();
  337. squareArgs.LineColor = Colors.Red;
  338. squareArgs.BgColor = Colors.Transparent;
  339. squareArgs.LineWidth = 1;
  340. squareArgs.Transparency = 1;
  341. squareArgs.LineDash = DashStyles.Solid;
  342. squareArgs.Content = string.Empty;
  343. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
  344. if (annotProperty != null)
  345. {
  346. squareArgs.LineColor = annotProperty.BorderColor;
  347. squareArgs.BgColor = annotProperty.BackgroundColor;
  348. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  349. {
  350. squareArgs.LineDash = DashStyles.Solid;
  351. }
  352. else
  353. {
  354. DashStyle dash = new DashStyle();
  355. foreach (var offset in annotProperty.DashArray)
  356. {
  357. dash.Dashes.Add(offset);
  358. }
  359. squareArgs.LineDash = dash;
  360. }
  361. squareArgs.LineWidth = annotProperty.Thickness;
  362. squareArgs.Transparency = annotProperty.Opacity;
  363. squareArgs.Content = annotProperty.NoteText;
  364. }
  365. }
  366. else
  367. {
  368. squareArgs = selectedsquareArgs;
  369. }
  370. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  371. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  372. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  373. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  374. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  375. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  376. AddToPropertyPanel(squareArgs, "Rect", "SharpsAnnotProperty", annotAttribsList);
  377. return squareArgs;
  378. }
  379. private AnnotHandlerEventArgs GetCircle(CircleAnnotArgs selectedcircleAnnotArgs = null)
  380. {
  381. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  382. CircleAnnotArgs circleAnnotArgs = null;
  383. if(selectedcircleAnnotArgs == null)
  384. {
  385. circleAnnotArgs = new CircleAnnotArgs();
  386. circleAnnotArgs.LineColor = Colors.Red;
  387. circleAnnotArgs.BgColor = Colors.Transparent;
  388. circleAnnotArgs.LineWidth = 1;
  389. circleAnnotArgs.Transparency = 1;
  390. circleAnnotArgs.LineDash = DashStyles.Solid;
  391. circleAnnotArgs.Content = string.Empty;
  392. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
  393. if (annotProperty != null)
  394. {
  395. circleAnnotArgs.LineColor = annotProperty.BorderColor;
  396. circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
  397. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  398. {
  399. circleAnnotArgs.LineDash = DashStyles.Solid;
  400. }
  401. else
  402. {
  403. DashStyle dash = new DashStyle();
  404. foreach (var offset in annotProperty.DashArray)
  405. {
  406. dash.Dashes.Add(offset);
  407. }
  408. circleAnnotArgs.LineDash = dash;
  409. }
  410. circleAnnotArgs.LineWidth = annotProperty.Thickness;
  411. circleAnnotArgs.Transparency = annotProperty.Opacity;
  412. circleAnnotArgs.Content = annotProperty.NoteText;
  413. }
  414. }
  415. else
  416. {
  417. circleAnnotArgs = selectedcircleAnnotArgs;
  418. }
  419. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  420. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  421. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  422. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  423. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  424. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  425. AddToPropertyPanel(circleAnnotArgs, "Circle", "SharpsAnnotProperty", annotAttribsList);
  426. return circleAnnotArgs;
  427. }
  428. private AnnotHandlerEventArgs GetArrowLine(string TagStr)
  429. {
  430. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  431. LineAnnotArgs lineArgs = new LineAnnotArgs();
  432. lineArgs.LineColor = Colors.Red;
  433. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  434. if (TagStr == "Line")
  435. {
  436. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  437. }
  438. else
  439. {
  440. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  441. }
  442. lineArgs.LineDash = DashStyles.Solid;
  443. lineArgs.LineWidth = 1;
  444. lineArgs.Transparency = 1;
  445. lineArgs.Content = string.Empty;
  446. DefaultAnnotProperty annotProperty = null;
  447. if (TagStr == "Line")
  448. {
  449. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
  450. if (annotProperty != null)
  451. {
  452. annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  453. annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  454. }
  455. }
  456. else
  457. {
  458. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
  459. }
  460. if (annotProperty != null)
  461. {
  462. lineArgs.LineColor = annotProperty.BorderColor;
  463. lineArgs.HeadLineType = annotProperty.HeadLineType;
  464. lineArgs.TailLineType = annotProperty.TailLineType;
  465. DashStyle dash = new DashStyle();
  466. foreach (var offset in annotProperty.DashArray)
  467. {
  468. dash.Dashes.Add(offset);
  469. }
  470. lineArgs.LineDash = dash;
  471. lineArgs.LineWidth = annotProperty.Thickness;
  472. lineArgs.Transparency = annotProperty.Opacity;
  473. lineArgs.Content = annotProperty.NoteText;
  474. }
  475. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  476. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  477. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  478. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  479. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  480. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  481. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  482. AddToPropertyPanel(lineArgs, TagStr, "SharpsAnnotProperty", annotAttribsList);
  483. return lineArgs;
  484. }
  485. private AnnotHandlerEventArgs GetStamp()
  486. {
  487. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  488. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  489. stampAnnotArgs.Opacity = 1;
  490. stampAnnotArgs.StampText = "APPROVED";
  491. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  492. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  493. AddToPropertyPanel(stampAnnotArgs, null, "StampAnnotProperty", annotAttribsList);
  494. return stampAnnotArgs;
  495. }
  496. private AnnotHandlerEventArgs GetImage(CustomIconToggleBtn annotBtn)
  497. {
  498. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  499. annotBtn.IsChecked = false;
  500. StampAnnotArgs stampArgs = new StampAnnotArgs();
  501. stampArgs.Opacity = 1;
  502. stampArgs.Type = StampType.IMAGE_STAMP;
  503. OpenFileDialog openFileDialog = new OpenFileDialog();
  504. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  505. if (openFileDialog.ShowDialog() == true)
  506. {
  507. stampArgs.ImagePath = openFileDialog.FileName;
  508. }
  509. AddToPropertyPanel(stampArgs, null, "ImageAnnotProperty", annotAttribsList);
  510. return stampArgs;
  511. }
  512. private void AddToPropertyPanel(AnnotHandlerEventArgs annot, string toolTag, string viewContent, Dictionary<AnnotAttrib, object> annotAttribsList)
  513. {
  514. if (string.IsNullOrEmpty(toolTag) == false)
  515. {
  516. if (!ToolExpandDict.ContainsKey(toolTag))
  517. {
  518. ToolExpandDict[toolTag] = true;
  519. }
  520. }
  521. if (annot != null)
  522. propertyPanel.annot = annot;
  523. if (annotAttribsList != null)
  524. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
  525. if (string.IsNullOrEmpty(viewContent) == false)
  526. {
  527. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  528. }
  529. }
  530. #endregion
  531. }
  532. }