DocumentWorkspaceWindow.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. using Metis.Measuring;
  2. using PaintDotNet.Annotation.Enum;
  3. using PaintDotNet.Annotation.Measure;
  4. using PaintDotNet.Base.DedicatedAnalysis.Inclusions.Model;
  5. using PaintDotNet.SystemLayer;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Drawing;
  11. using System.Drawing.Imaging;
  12. using System.Reflection;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. namespace PaintDotNet
  16. {
  17. /// <summary>
  18. /// 抽出来在各种弹窗里面使用
  19. /// </summary>
  20. internal class DocumentWorkspaceWindow : DocumentView
  21. {
  22. private ZoomBasis zoomBasis;
  23. private ZoomBasis savedZb;
  24. private ScaleFactor savedSf;
  25. protected override void OnSizeChanged(EventArgs e)
  26. {
  27. PerformLayout();
  28. base.OnSizeChanged(e);
  29. }
  30. protected override void OnLayout(LayoutEventArgs e)
  31. {
  32. if (this.zoomBasis == ZoomBasis.FitToWindow)
  33. {
  34. ZoomToWindow();
  35. // This bizarre ordering of setting PanelAutoScroll prevents some very weird layout/scroll-without-scrollbars stuff.
  36. PanelAutoScroll = true;
  37. PanelAutoScroll = false;
  38. }
  39. base.OnLayout(e);
  40. }
  41. protected override void OnResize(EventArgs e)
  42. {
  43. if (this.zoomBasis == ZoomBasis.FitToWindow)
  44. {
  45. PerformLayout();
  46. }
  47. base.OnResize(e);
  48. }
  49. public DocumentWorkspaceWindow(AppWorkspace appWorkspace)
  50. {
  51. this.AppWorkspaceTop = appWorkspace;
  52. this.InitToolsAndManager();
  53. this.RulersEnabled = false;
  54. this.rightDown = false;
  55. InitializeComponent();
  56. this.zoomBasis = ZoomBasis.FitToWindow;
  57. InitializeBottomEvent();
  58. this.MouseEvent_Del(null, null);
  59. }
  60. public DocumentWorkspaceWindow()
  61. {
  62. this.RulersEnabled = false;
  63. this.rightDown = false;
  64. InitializeComponent();
  65. this.zoomBasis = ZoomBasis.FitToWindow;
  66. InitializeBottomEvent();
  67. this.MouseEvent_Del(null, null);
  68. }
  69. protected override void OnUnitsChanged()
  70. {
  71. base.OnUnitsChanged();
  72. }
  73. private void InitializeComponent()
  74. {
  75. }
  76. protected override void Dispose(bool disposing)
  77. {
  78. base.Dispose(disposing);
  79. }
  80. public override void ZoomIn()
  81. {
  82. this.ZoomBasis = ZoomBasis.ScaleFactor;
  83. base.ZoomIn();
  84. }
  85. public override void ZoomIn(double factor)
  86. {
  87. this.ZoomBasis = ZoomBasis.ScaleFactor;
  88. base.ZoomIn(factor);
  89. }
  90. public override void ZoomOut()
  91. {
  92. this.ZoomBasis = ZoomBasis.ScaleFactor;
  93. base.ZoomOut();
  94. }
  95. public override void ZoomOut(double factor)
  96. {
  97. this.ZoomBasis = ZoomBasis.ScaleFactor;
  98. base.ZoomOut(factor);
  99. }
  100. public event EventHandler ZoomBasisChanging;
  101. protected virtual void OnZoomBasisChanging()
  102. {
  103. if (ZoomBasisChanging != null)
  104. {
  105. ZoomBasisChanging(this, EventArgs.Empty);
  106. }
  107. }
  108. public event EventHandler ZoomBasisChanged;
  109. protected virtual void OnZoomBasisChanged()
  110. {
  111. if (ZoomBasisChanged != null)
  112. {
  113. ZoomBasisChanged(this, EventArgs.Empty);
  114. }
  115. }
  116. public ZoomBasis ZoomBasis
  117. {
  118. get
  119. {
  120. return this.zoomBasis;
  121. }
  122. set
  123. {
  124. if (this.zoomBasis != value)
  125. {
  126. OnZoomBasisChanging();
  127. this.zoomBasis = value;
  128. switch (this.zoomBasis)
  129. {
  130. case ZoomBasis.FitToWindow:
  131. ZoomToWindow();
  132. // Enable PanelAutoScroll only long enough to recenter the view
  133. PanelAutoScroll = true;
  134. PanelAutoScroll = false;
  135. // this would be unset by the scalefactor changes in ZoomToWindow
  136. this.zoomBasis = ZoomBasis.FitToWindow;
  137. break;
  138. case ZoomBasis.ScaleFactor:
  139. PanelAutoScroll = true;
  140. break;
  141. default:
  142. throw new InvalidEnumArgumentException();
  143. }
  144. OnZoomBasisChanged();
  145. }
  146. }
  147. }
  148. protected override void HandleMouseWheel(Control sender, MouseEventArgs e)
  149. {
  150. if (Control.ModifierKeys == Keys.Control && !disableWheel)
  151. {
  152. double mouseDelta = (double)e.Delta / 120.0f;
  153. Rectangle visibleDocBoundsStart = this.VisibleDocumentBounds;
  154. System.Drawing.Point mouseDocPt = this.MouseToDocument(sender, new System.Drawing.Point(e.X, e.Y));
  155. RectangleF visibleDocDocRect1 = this.VisibleDocumentRectangleF;
  156. PointF mouseNPt = new PointF(
  157. (mouseDocPt.X - visibleDocDocRect1.X) / visibleDocDocRect1.Width,
  158. (mouseDocPt.Y - visibleDocDocRect1.Y) / visibleDocDocRect1.Height);
  159. Rectangle rc = this.PanelClientRectangle;
  160. int width = this.SurfaceScrollableWidth;
  161. int height = this.SurfaceScrollableHeight;
  162. //获取鼠标在图像中的坐标定位
  163. double originX = 0.5;
  164. double originY = 0.5;
  165. double ptxInDoc = mouseDocPt.X * this.ScaleRatio;
  166. double ptyInDoc = mouseDocPt.Y * this.ScaleRatio;
  167. if (rc.Width < width)
  168. {
  169. originX = (ptxInDoc + this.PanelScrollPosition.X - 0.0) / width;
  170. }
  171. if (rc.Height < height)
  172. {
  173. originY = (ptyInDoc + this.PanelScrollPosition.Y - 0.0) / height;
  174. }
  175. const double factor = 1.12;
  176. double mouseFactor = Math.Pow(factor, Math.Abs(mouseDelta));
  177. if (e.Delta > 0)
  178. {
  179. this.ZoomIn(mouseFactor);
  180. }
  181. else if (e.Delta < 0)
  182. {
  183. this.ZoomOut(mouseFactor);
  184. }
  185. RectangleF visibleDocDocRect2 = this.VisibleDocumentRectangleF;
  186. PointF scrollPt2 = new PointF(
  187. mouseDocPt.X - visibleDocDocRect2.Width * mouseNPt.X,
  188. mouseDocPt.Y - visibleDocDocRect2.Height * mouseNPt.Y);
  189. this.DocumentScrollPositionF = scrollPt2;
  190. int width2 = this.SurfaceScrollableWidth;
  191. int height2 = this.SurfaceScrollableHeight;
  192. if ((rc.Width < width2 || rc.Height < height2) && (rc.Width < width || rc.Height < height))
  193. {
  194. //根据鼠标在图像中的坐标重新定位放大后的图像
  195. this.PanelScrollPosition = new System.Drawing.Point(
  196. (int)(width2 * originX - ptxInDoc + 0),
  197. (int)(height2 * originY - ptyInDoc + 0));
  198. }
  199. else if (rc.Width < width2 || rc.Height < height2)
  200. {
  201. this.PanelScrollPosition = new System.Drawing.Point((int)(width2 - rc.Width) / 2 + 0, (int)(height2 - rc.Height) / 2 + 0);
  202. }
  203. else
  204. {
  205. this.PanelScrollPosition = new System.Drawing.Point((int)(width2 - rc.Width) / 2 + 0, (int)(height2 - rc.Height) / 2 + 0);
  206. }
  207. Rectangle visibleDocBoundsEnd = this.VisibleDocumentBounds;
  208. if (visibleDocBoundsEnd != visibleDocBoundsStart)
  209. {
  210. // Make sure the screen updates, otherwise it can get a little funky looking
  211. this.Update();
  212. }
  213. }
  214. base.HandleMouseWheel(sender, e);
  215. }
  216. protected override void OnLoad(EventArgs e)
  217. {
  218. base.OnLoad(e);
  219. }
  220. public event EventHandler ActiveLayerChanged;
  221. protected void OnLayerChanged()
  222. {
  223. this.Focus();
  224. if (ActiveLayerChanged != null)
  225. {
  226. ActiveLayerChanged(this, EventArgs.Empty);
  227. }
  228. }
  229. /// <summary>
  230. /// 初始化底部按钮的各种事件
  231. /// </summary>
  232. private void InitializeBottomEvent()
  233. {
  234. /*//缩小按钮
  235. this.PanelBottom.zoomOutButton.Click += new EventHandler(ZoomOutButton_Click);
  236. //放大按钮
  237. this.PanelBottom.zoomInButton.Click += new EventHandler(zoomInButton_Click);*/
  238. }
  239. private void ZoomOutButton_Click(object sender, EventArgs e)
  240. {
  241. this.ZoomOut();
  242. }
  243. private void zoomInButton_Click(object sender, EventArgs e)
  244. {
  245. this.ZoomIn();
  246. }
  247. public event EventHandler ToolChanging;
  248. protected void OnToolChanging()
  249. {
  250. if (ToolChanging != null)
  251. {
  252. ToolChanging(this, EventArgs.Empty);
  253. }
  254. }
  255. public event EventHandler ToolChanged;
  256. protected void OnToolChanged()
  257. {
  258. if (ToolChanged != null)
  259. {
  260. ToolChanged(this, EventArgs.Empty);
  261. }
  262. }
  263. /// <summary>
  264. /// Updates any pertinent EXIF tags, such as "Creation Software", to be
  265. /// relevant or up-to-date.
  266. /// </summary>
  267. /// <param name="document"></param>
  268. private void UpdateExifTags(Document document)
  269. {
  270. PropertyItem pi = Exif.CreateAscii(ExifTagID.Software, PdnInfo.GetProductName(false));
  271. document.Metadata.ReplaceExifValues(ExifTagID.Software, new PropertyItem[1] { pi });
  272. }
  273. public void SetInclusion(Inclusion Inclusion)
  274. {
  275. this.inclusion = Inclusion;
  276. }
  277. protected override void OnDocumentChanging(Document newDocument)
  278. {
  279. base.OnDocumentChanging(newDocument);
  280. this.savedZb = this.ZoomBasis;
  281. this.savedSf = ScaleFactor;
  282. if (newDocument != null)
  283. {
  284. UpdateExifTags(newDocument);
  285. }
  286. }
  287. protected override void OnDocumentChanged()
  288. {
  289. bool oldDirty = this.Document.Dirty;
  290. this.Document.Invalidate();
  291. this.Document.Dirty = oldDirty;
  292. this.ZoomBasis = this.savedZb;
  293. if (this.savedZb == ZoomBasis.ScaleFactor)
  294. {
  295. ScaleFactor = this.savedSf;
  296. }
  297. AutoScrollPosition = new Point(0, 0);
  298. base.OnDocumentChanged();
  299. }
  300. private sealed class OurProgressEvents : IFileTransferProgressEvents
  301. {
  302. private TransferProgressDialog progressDialog;
  303. private ICancelable cancelSink;
  304. private int itemCount = 0;
  305. private int itemOrdinal = 0;
  306. private string itemName = string.Empty;
  307. private long totalWork;
  308. private long totalProgress;
  309. private const int maxPBValue = 200; // granularity of progress bar. 100 means 1%, 200 means 0.5%, etc.
  310. private bool cancelRequested = false;
  311. private ManualResetEvent operationEnded = new ManualResetEvent(false);
  312. public OurProgressEvents()
  313. {
  314. }
  315. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "cancelSink")]
  316. public void BeginOperation(IWin32Window owner, EventHandler callWhenUIShown, ICancelable cancelSink)
  317. {
  318. if (this.progressDialog != null)
  319. {
  320. throw new InvalidOperationException("Operation already in progress");
  321. }
  322. this.progressDialog = new TransferProgressDialog();
  323. this.progressDialog.Text = PdnResources.GetString("ShowFileDialog.TransferProgress.Title");
  324. this.progressDialog.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuFileOpenIcon.png").Reference);
  325. this.progressDialog.Title = PdnResources.GetString("ShowFileDialog.ItemText.Initializing");
  326. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Marquee;
  327. this.progressDialog.ProgressBar.Maximum = maxPBValue;
  328. this.progressDialog.CancelClicked +=
  329. delegate (object sender, EventArgs e)
  330. {
  331. this.cancelRequested = true;
  332. this.cancelSink.RequestCancel();
  333. UpdateUI();
  334. };
  335. EventHandler progressDialog_Shown =
  336. delegate (object sender, EventArgs e)
  337. {
  338. callWhenUIShown(this, EventArgs.Empty);
  339. };
  340. this.cancelSink = cancelSink;
  341. this.itemOrdinal = 0;
  342. this.cancelRequested = false;
  343. this.itemName = string.Empty;
  344. this.itemCount = 0;
  345. this.itemOrdinal = 0;
  346. this.totalProgress = 0;
  347. this.totalWork = 0;
  348. this.progressDialog.Shown += progressDialog_Shown;
  349. this.progressDialog.ShowDialog(owner);
  350. this.progressDialog.Shown -= progressDialog_Shown;
  351. this.progressDialog.Dispose();
  352. this.progressDialog = null;
  353. this.cancelSink = null;
  354. }
  355. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "itemCount")]
  356. public void SetItemCount(int itemCount)
  357. {
  358. if (this.progressDialog.InvokeRequired)
  359. {
  360. this.progressDialog.BeginInvoke(new Procedure<int>(SetItemCount), new object[] { itemCount });
  361. }
  362. else
  363. {
  364. this.itemCount = itemCount;
  365. UpdateUI();
  366. }
  367. }
  368. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "itemOrdinal")]
  369. public void SetItemOrdinal(int itemOrdinal)
  370. {
  371. if (this.progressDialog.InvokeRequired)
  372. {
  373. this.progressDialog.BeginInvoke(new Procedure<int>(SetItemOrdinal), new object[] { itemOrdinal });
  374. }
  375. else
  376. {
  377. this.itemOrdinal = itemOrdinal;
  378. this.totalWork = 0;
  379. this.totalProgress = 0;
  380. UpdateUI();
  381. }
  382. }
  383. public void SetItemInfo(string itemInfo)
  384. {
  385. if (this.progressDialog.InvokeRequired)
  386. {
  387. this.progressDialog.BeginInvoke(new Procedure<string>(SetItemInfo), new object[] { itemInfo });
  388. }
  389. else
  390. {
  391. this.itemName = itemInfo;
  392. UpdateUI();
  393. }
  394. }
  395. public void BeginItem()
  396. {
  397. if (this.progressDialog.InvokeRequired)
  398. {
  399. this.progressDialog.BeginInvoke(new Procedure(BeginItem), null);
  400. }
  401. else
  402. {
  403. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Continuous;
  404. }
  405. }
  406. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "totalWork")]
  407. public void SetItemWorkTotal(long totalWork)
  408. {
  409. if (this.progressDialog.InvokeRequired)
  410. {
  411. this.progressDialog.BeginInvoke(new Procedure<long>(SetItemWorkTotal), new object[] { totalWork });
  412. }
  413. else
  414. {
  415. this.totalWork = totalWork;
  416. UpdateUI();
  417. }
  418. }
  419. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "totalProgress")]
  420. public void SetItemWorkProgress(long totalProgress)
  421. {
  422. if (this.progressDialog.InvokeRequired)
  423. {
  424. this.progressDialog.BeginInvoke(new Procedure<long>(SetItemWorkProgress), new object[] { totalProgress });
  425. }
  426. else
  427. {
  428. this.totalProgress = totalProgress;
  429. UpdateUI();
  430. }
  431. }
  432. public void EndItem(WorkItemResult result)
  433. {
  434. if (this.progressDialog.InvokeRequired)
  435. {
  436. this.progressDialog.BeginInvoke(new Procedure<WorkItemResult>(EndItem), new object[] { result });
  437. }
  438. else
  439. {
  440. }
  441. }
  442. public void EndOperation(OperationResult result)
  443. {
  444. if (this.progressDialog.InvokeRequired)
  445. {
  446. this.progressDialog.BeginInvoke(new Procedure<OperationResult>(EndOperation), new object[] { result });
  447. }
  448. else
  449. {
  450. this.progressDialog.Close();
  451. }
  452. }
  453. public WorkItemFailureAction ReportItemFailure(Exception ex)
  454. {
  455. if (this.progressDialog.InvokeRequired)
  456. {
  457. object result = this.progressDialog.Invoke(
  458. new Function<WorkItemFailureAction, Exception>(ReportItemFailure),
  459. new object[] { ex });
  460. return (WorkItemFailureAction)result;
  461. }
  462. else
  463. {
  464. WorkItemFailureAction result;
  465. result = ShowFileTransferFailedDialog(ex);
  466. return result;
  467. }
  468. }
  469. private WorkItemFailureAction ShowFileTransferFailedDialog(Exception ex)
  470. {
  471. WorkItemFailureAction result;
  472. Icon formIcon = this.progressDialog.Icon;
  473. string formTitle = PdnResources.GetString("ShowFileDialog.ItemFailureDialog.Title");
  474. Image taskImage = PdnResources.GetImageResource("Icons.WarningIcon.png").Reference;
  475. string introTextFormat = PdnResources.GetString("ShowFileDialog.ItemFailureDialog.IntroText.Format");
  476. string introText = string.Format(introTextFormat, ex.Message);
  477. TaskButton retryTB = new TaskButton(
  478. PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference,
  479. PdnResources.GetString("ShowFileDialog.RetryTB.ActionText"),
  480. PdnResources.GetString("ShowFileDialog.RetryTB.ExplanationText"));
  481. TaskButton skipTB = new TaskButton(
  482. PdnResources.GetImageResource("Icons.HistoryFastForwardIcon.png").Reference,
  483. PdnResources.GetString("ShowFileDialog.SkipTB.ActionText"),
  484. PdnResources.GetString("ShowFileDialog.SkipTB.ExplanationText"));
  485. TaskButton cancelTB = new TaskButton(
  486. PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
  487. PdnResources.GetString("ShowFileDialog.CancelTB.ActionText"),
  488. PdnResources.GetString("ShowFileDialog.CancelTB.ExplanationText"));
  489. List<TaskButton> taskButtons = new List<TaskButton>();
  490. taskButtons.Add(retryTB);
  491. // Only have the Skip button if there is more than 1 item being transferred.
  492. // If only 1 item is begin transferred, Skip and Cancel are essentially synonymous.
  493. if (this.itemCount > 1)
  494. {
  495. taskButtons.Add(skipTB);
  496. }
  497. taskButtons.Add(cancelTB);
  498. int width96 = (TaskDialog.DefaultPixelWidth96Dpi * 4) / 3; // 33% wider
  499. TaskButton clickedTB = TaskDialog.Show(
  500. this.progressDialog,
  501. formIcon,
  502. formTitle,
  503. taskImage,
  504. true,
  505. introText,
  506. taskButtons.ToArray(),
  507. retryTB,
  508. cancelTB,
  509. width96,
  510. false,
  511. 0,
  512. out bool unuse);
  513. if (clickedTB == retryTB)
  514. {
  515. result = WorkItemFailureAction.RetryItem;
  516. }
  517. else if (clickedTB == skipTB)
  518. {
  519. result = WorkItemFailureAction.SkipItem;
  520. }
  521. else
  522. {
  523. result = WorkItemFailureAction.CancelOperation;
  524. }
  525. return result;
  526. }
  527. private void UpdateUI()
  528. {
  529. int itemCount2 = Math.Max(1, this.itemCount);
  530. double startValue = (double)this.itemOrdinal / (double)itemCount2;
  531. double endValue = (double)(this.itemOrdinal + 1) / (double)itemCount2;
  532. long totalWork2 = Math.Max(1, this.totalWork);
  533. double lerp = (double)this.totalProgress / (double)totalWork2;
  534. double newValue = Utility.Lerp(startValue, endValue, lerp);
  535. int newValueInt = (int)Math.Ceiling(maxPBValue * newValue);
  536. if (this.cancelRequested)
  537. {
  538. this.progressDialog.CancelEnabled = false;
  539. this.progressDialog.Title = PdnResources.GetString("ShowFileDialog.ItemText.Canceling");
  540. this.progressDialog.ProcessMsg = string.Empty;
  541. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Marquee;
  542. }
  543. else
  544. {
  545. this.progressDialog.CancelEnabled = true;
  546. this.progressDialog.Title = this.itemName;
  547. string progressFormat = PdnResources.GetString("ShowFileDialog.ProgressText.Format");
  548. string progressText = string.Format(progressFormat, this.itemOrdinal + 1, this.itemCount);
  549. this.progressDialog.ProcessMsg = progressText;
  550. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Continuous;
  551. this.progressDialog.ProgressBar.Value = newValueInt;
  552. }
  553. }
  554. }
  555. /// <summary>
  556. /// 更新测量单位,刷新UI
  557. /// </summary>
  558. /// <param name="measurementUnit"></param>
  559. public void UpdateMeasureUnit(MeasurementUnit measurementUnit)
  560. {
  561. //循环所有测量,更新单位
  562. if (this.GraphicsList != null
  563. && this.GraphicsList.Count > 0)
  564. {
  565. int count = this.GraphicsList.Count;
  566. for (int i = 0; i < count; i++)
  567. {
  568. if (this.GraphicsList[i].objectType == DrawClass.Measure)
  569. {
  570. ((MeasureDrawObject)(this.GraphicsList[i])).MeasurementUnit = measurementUnit;
  571. }
  572. }
  573. }
  574. this.Refresh();
  575. }
  576. /// <summary>
  577. /// 分栏显示禁止滚动改变图片大小
  578. /// </summary>
  579. bool disableWheel = false;
  580. public void removeEvent()
  581. {
  582. disableWheel = true;
  583. }
  584. DateTime _time;
  585. protected override void MouseEvent_Move(object sender, MouseEventArgs e)
  586. {
  587. if (this.AppWorkspaceTop != null && this.compositionSurface != null && this.pixelTrackingEnabled)
  588. //&& e.Location.X>=0 && e.Location.Y>=0
  589. //&& e.Location.X<=this.Surface.Width
  590. //&& e.Location.Y <= this.Surface.Height)
  591. {
  592. if ((DateTime.Now - _time).TotalMilliseconds > 20)
  593. {
  594. //this.AppWorkspaceTop.SetImageAndData(this.ScaleFactor.UnscalePoint(e.Location));
  595. (this.AppWorkspaceTop as AppWorkspace).SetImageAndData(this.CalcPixelPoint(e.Location), this);
  596. _time = DateTime.Now;
  597. base.MouseEvent_Move(sender, e);
  598. }
  599. }
  600. }
  601. protected override void MouseEvent_Down(object sender, MouseEventArgs e)
  602. {
  603. if (tools != null)
  604. {
  605. //tools[activeTool].OnMouseDown(this, e);
  606. tools[_activeTool].InvokeMember("OnMouseDown",
  607. BindingFlags.Public |
  608. BindingFlags.Static |
  609. BindingFlags.InvokeMethod,
  610. null,
  611. null,
  612. new object[2] { this, e });
  613. }
  614. RefreshDrawNodes();
  615. if (e.Button == MouseButtons.Right)
  616. {
  617. ShowContextMenuStrip1();
  618. }
  619. }
  620. public void RefreshDrawNodes()
  621. {
  622. TreeView drawTreeView = this.oldDrawTreeView;
  623. if (drawTreeView != null)
  624. {
  625. for (int i = 0; i < this.GraphicsList.Count; i++)
  626. {
  627. if (this.GraphicsList[i].objectType == DrawClass.Measure)
  628. {
  629. int count1 = drawTreeView.Nodes.Count;
  630. ((MeasureDrawObject)(this.GraphicsList[i])).drawingProperties.Clear();
  631. ((MeasureDrawObject)(this.GraphicsList[i])).pointChangeObject.Clear();
  632. for (int k = 0; k < count1; k++)
  633. {
  634. int count2 = drawTreeView.Nodes[k].Nodes.Count;
  635. for (int j = 0; j < count2; j++)
  636. {
  637. if (this.GraphicsList[i].drawToolType == (DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name))
  638. {
  639. bool drawb = false;
  640. if (drawTreeView.Nodes[k].Nodes[j].Nodes.Count == 0)
  641. {
  642. ((MeasureDrawObject)(this.GraphicsList[i])).drawingProperties.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), new string[] { "nothing" });
  643. if (this.oldDrawTreeView != null)
  644. {
  645. if (this.oldDrawTreeView.Nodes[k].Nodes[j].Nodes.Count != 0)
  646. ((MeasureDrawObject)(this.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
  647. }
  648. else
  649. {
  650. ((MeasureDrawObject)(this.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
  651. }
  652. }
  653. else
  654. {
  655. int a = 0;
  656. string[] arr = new string[drawTreeView.Nodes[k].Nodes[j].Nodes.Count];
  657. foreach (TreeNode node2 in drawTreeView.Nodes[k].Nodes[j].Nodes)
  658. {
  659. arr[a] = node2.Name;
  660. a++;
  661. }
  662. ((MeasureDrawObject)(this.GraphicsList[i])).drawingProperties.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), arr);
  663. if (this.oldDrawTreeView != null)
  664. {
  665. if (drawTreeView.Nodes[k].Nodes[j].Nodes.Count != this.oldDrawTreeView.Nodes[k].Nodes[j].Nodes.Count)
  666. {
  667. ((MeasureDrawObject)(this.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
  668. }
  669. else
  670. {
  671. foreach (TreeNode oldNode in this.oldDrawTreeView.Nodes[k].Nodes[j].Nodes)
  672. {
  673. /*if (!arr.Contains(oldNode.Name))
  674. {
  675. drawb = true;
  676. }*/
  677. }
  678. if (drawb)
  679. ((MeasureDrawObject)(this.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), drawb);
  680. }
  681. }
  682. else
  683. {
  684. ((MeasureDrawObject)(this.GraphicsList[i])).pointChangeObject.Add((DrawToolType)Enum.Parse(typeof(DrawToolType), drawTreeView.Nodes[k].Nodes[j].Name), true);
  685. }
  686. }
  687. }
  688. }
  689. }
  690. }
  691. }
  692. this.Refresh();
  693. }
  694. }
  695. public override void ShowContextMenuStrip1()
  696. {
  697. if (toolNumber == 1)
  698. {
  699. contextMenuStrip1.Visible = true;
  700. toolStripMenuItem1.Visible = false;
  701. toolStripMenuItem2.Visible = false;
  702. toolStripMenuItem3.Visible = true;
  703. toolStripMenuItem4.Visible = false;
  704. }
  705. else
  706. {
  707. toolStripMenuItem1.Visible = false;
  708. toolStripMenuItem2.Visible = false;
  709. toolStripMenuItem3.Visible = false;
  710. toolStripMenuItem4.Visible = false;
  711. }
  712. }
  713. public override void ToolStripMenuItem3_Click(object sender, EventArgs e)
  714. {
  715. for (int i = 0; i < this.GraphicsList.Count; i++)
  716. {
  717. if (GraphicsList[i].Selected)
  718. {
  719. MeasurementPropertiesDialog measurementPropertiesDialog = new MeasurementPropertiesDialog(AppWorkspaceTop as AppWorkspace, this.GraphicsList[i]);
  720. measurementPropertiesDialog.StartPosition = FormStartPosition.CenterScreen;
  721. measurementPropertiesDialog.ShowDialog();
  722. this.Refresh();
  723. }
  724. }
  725. }
  726. }
  727. }