AppWorkspace.cs 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  1. using Resources;
  2. using SmartCoalApplication.Actions;
  3. using SmartCoalApplication.Annotation.Enum;
  4. using SmartCoalApplication.Base;
  5. using SmartCoalApplication.Base.CommTool;
  6. using SmartCoalApplication.Base.Enum;
  7. using SmartCoalApplication.Base.MeasureModel;
  8. using SmartCoalApplication.Base.SettingModel;
  9. using SmartCoalApplication.Core;
  10. using SmartCoalApplication.Core.CustomControl;
  11. using SmartCoalApplication.Core.DbOpreate.DbModel;
  12. using SmartCoalApplication.Rule;
  13. using SmartCoalApplication.SystemLayer;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Drawing;
  18. using System.Drawing.Drawing2D;
  19. using System.Globalization;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Windows.Forms;
  23. namespace SmartCoalApplication
  24. {
  25. internal class AppWorkspace : UserControl, ISnapObstacleHost, IAppWorkspaceForSurfaceBox
  26. {
  27. /// <summary>
  28. /// 顶部菜单和工具栏
  29. /// </summary>
  30. public PdnToolBar toolBar;
  31. /// <summary>
  32. /// 底部公用工具栏
  33. /// </summary>
  34. private PanelBottom panelBottom;
  35. /// <summary>
  36. /// 主界面左侧的快捷工具栏
  37. /// </summary>
  38. public ToolsControl toolsPanel;
  39. /// <summary>
  40. /// 包含DocumentWorkspace集合的panel
  41. /// </summary>
  42. public Panel workspacePanel;
  43. /// <summary>
  44. /// 底部状态栏
  45. /// </summary>
  46. private PdnStatusBar statusBar;
  47. /// <summary>
  48. /// 当前激活的工作空间
  49. /// </summary>
  50. private DocumentWorkspace activeDocumentWorkspace;
  51. /// <summary>
  52. /// 如果添加了新的工作空间,并且该工作空间没有被修改,则将其删除
  53. /// </summary>
  54. private DocumentWorkspace initialWorkspace;
  55. /// <summary>
  56. /// 工作空间集合,打开的图像
  57. /// </summary>
  58. private List<DocumentWorkspace> documentWorkspaces = new List<DocumentWorkspace>();
  59. /// <summary>
  60. /// 保存了许多可浮动的窗口,为了统一管理,供外部调用
  61. /// </summary>
  62. private WorkspaceWidgets widgets;
  63. /// <summary>
  64. /// 最近打开的文件
  65. /// </summary>
  66. private MostRecentFiles mostRecentFiles = null;
  67. /// <summary>
  68. /// 最近打开的文件的最大默认数量
  69. /// </summary>
  70. private const int defaultMostRecentFilesMax = 8;
  71. /// <summary>
  72. /// 锁定扩缩标记
  73. /// </summary>
  74. public bool isLockZoom = false;
  75. /// <summary>
  76. /// 锁定扩缩的百分比
  77. /// </summary>
  78. public double lockScaleRatio = 0;
  79. /// <summary>
  80. /// 测量连续绘制
  81. /// </summary>
  82. public bool continuousDrawingMeasure = false;
  83. /// <summary>
  84. /// 标记连续绘制
  85. /// </summary>
  86. public bool continuousDrawingLabel = false;
  87. /// <summary>
  88. /// 测量连续绘制
  89. /// </summary>
  90. public bool continuousDrawingView = false;
  91. /// <summary>
  92. /// 要删除的工作空间位置(避免批量保存有修改的图片时关闭的工作空间位置与for循环顺序不一致)
  93. /// </summary>
  94. public int toRemoveDocumentWorkspaceIndex = -1;
  95. private SnapObstacleController snapObstacle;
  96. private bool addedToSnapManager = false;
  97. private int ignoreUpdateSnapObstacle = 0;
  98. public DrawToolType activeTool = DrawToolType.Pointer;
  99. /// <summary>
  100. /// 结果页面标尺信息
  101. /// </summary>
  102. public double unitNum = 1;
  103. public string aliasName;
  104. public int decimalPlaces = 2;
  105. /// <summary>
  106. /// 标尺标定窗口
  107. /// </summary>
  108. private RuleListForm ruleListForm;
  109. public void ResetFloatingForms()
  110. {
  111. ResetFloatingForm(Widgets.RuleListForm);
  112. }
  113. public void ResetFloatingForm(FloatingToolForm ftf)
  114. {
  115. SnapManager sm = SnapManager.FindMySnapManager(this);
  116. if (ftf == Widgets.RuleListForm)
  117. {
  118. sm.ParkObstacle(Widgets.RuleListForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  119. }
  120. else
  121. {
  122. throw new ArgumentException();
  123. }
  124. }
  125. public PanelBottom PanelBottom
  126. {
  127. get
  128. {
  129. return this.panelBottom;
  130. }
  131. }
  132. /// <summary>
  133. /// 单位改变事件
  134. /// </summary>
  135. public event EventHandler UnitsChanged;
  136. protected virtual void OnUnitsChanged()
  137. {
  138. if (UnitsChanged != null)
  139. {
  140. UnitsChanged(this, EventArgs.Empty);
  141. }
  142. }
  143. public MeasurementUnit Units
  144. {
  145. get
  146. {
  147. return Program.instance.measurementUnit;
  148. }
  149. set
  150. {
  151. //this.widgets.ViewConfigStrip.Units = value;
  152. }
  153. }
  154. protected override void OnLayout(LayoutEventArgs levent)
  155. {
  156. base.OnLayout(levent);
  157. }
  158. protected override void OnLocationChanged(EventArgs e)
  159. {
  160. base.OnLocationChanged(e);
  161. }
  162. protected override void OnSizeChanged(EventArgs e)
  163. {
  164. base.OnSizeChanged(e);
  165. }
  166. protected override void OnEnabledChanged(EventArgs e)
  167. {
  168. base.OnEnabledChanged(e);
  169. }
  170. protected override void OnVisibleChanged(EventArgs e)
  171. {
  172. base.OnVisibleChanged(e);
  173. }
  174. public PdnToolBar ToolBar
  175. {
  176. get
  177. {
  178. return this.toolBar;
  179. }
  180. }
  181. public MostRecentFiles MostRecentFiles
  182. {
  183. get
  184. {
  185. if (this.mostRecentFiles == null)
  186. {
  187. this.mostRecentFiles = new MostRecentFiles(defaultMostRecentFilesMax);
  188. }
  189. return this.mostRecentFiles;
  190. }
  191. }
  192. private void DocumentWorkspace_DocumentChanging(object sender, EventArgs<Document> e)
  193. {
  194. UI.SuspendControlPainting(this);
  195. }
  196. private void DocumentWorkspace_DocumentChanged(object sender, EventArgs e)
  197. {
  198. UpdateDocInfoInStatusBar();
  199. this.UpdatePixelTracking();
  200. UI.ResumeControlPainting(this);
  201. Invalidate(true);
  202. }
  203. private void CoordinatesToStrings(int x, int y, out string xString, out string yString, out string unitsString)
  204. {
  205. this.activeDocumentWorkspace.Document.CoordinatesToStrings(this.Units, x, y, out xString, out yString, out unitsString);
  206. }
  207. /// <summary>
  208. /// 更新右下角坐标信息
  209. /// </summary>
  210. /// <param name="cursorX"></param>
  211. /// <param name="cursorY"></param>
  212. private void UpdateCursorInfoInStatusBar(int cursorX, int cursorY)
  213. {
  214. SuspendLayout();
  215. if (this.activeDocumentWorkspace == null ||
  216. this.activeDocumentWorkspace.Document == null)
  217. {
  218. this.statusBar.CursorInfoText = string.Empty;
  219. }
  220. else
  221. {
  222. string xString;
  223. string yString;
  224. string units;
  225. CoordinatesToStrings(cursorX, cursorY, out xString, out yString, out units);
  226. string cursorText = string.Format(
  227. CultureInfo.InvariantCulture,
  228. PdnResources.GetString("StatusBar.CursorInfo.Format"),
  229. xString,
  230. units,
  231. yString,
  232. units);
  233. //this.statusBar.CursorInfoText = cursorText;
  234. }
  235. ResumeLayout(false);
  236. }
  237. /// <summary>
  238. /// 更新底部状态栏的文字等
  239. /// 需要修改为显示标尺相关的信息
  240. /// </summary>
  241. public void UpdateDocInfoInStatusBar()
  242. {
  243. if (this.activeDocumentWorkspace != null)
  244. {
  245. if (this.activeDocumentWorkspace.xmlSaveModel == null)
  246. {
  247. if (Program.instance.ruleDB != null)
  248. {
  249. this.statusBar.ImageInfoStatusText = Program.instance.ruleDB.ruler_name;
  250. this.statusBar.CursorInfoText = Math.Round(Program.instance.rules[(MeasurementUnit)Program.instance.ruleDB.ruler_units], 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), Program.instance.ruleDB.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
  251. }
  252. else {
  253. this.statusBar.ImageInfoStatusText = PdnResources.GetString("Menu.Unselectedruler.Text");
  254. this.statusBar.CursorInfoText = PdnResources.GetString("Menu.Defaultis1micron/pixel.Text");
  255. }
  256. }
  257. else
  258. {
  259. //选中图片是否有配置文件
  260. if ((ExistenceXML() && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0) || (this.activeDocumentWorkspace != null && this.activeDocumentWorkspace.xmlSaveModel != null && this.activeDocumentWorkspace.xmlSaveModel.pixel_length != 0))
  261. {
  262. this.statusBar.ImageInfoStatusText = this.activeDocumentWorkspace.xmlSaveModel.ruler_name;
  263. double unitLength = (double)(this.activeDocumentWorkspace.xmlSaveModel.physical_length / (decimal)this.activeDocumentWorkspace.xmlSaveModel.pixel_length);
  264. this.statusBar.CursorInfoText = Math.Round(unitLength, 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), this.activeDocumentWorkspace.xmlSaveModel.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
  265. }
  266. else
  267. {
  268. this.statusBar.ImageInfoStatusText = Program.instance.ruleDB.ruler_name;
  269. this.statusBar.CursorInfoText = Math.Round(Program.instance.rules[(MeasurementUnit)Program.instance.ruleDB.ruler_units], 4) + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), Program.instance.ruleDB.ruler_units)))].ToString() + "/" + PdnResources.GetString("Menu.Pixel.text");
  270. }
  271. }
  272. }
  273. }
  274. /// <summary>
  275. /// 更新像素跟踪的图像
  276. /// </summary>
  277. private void UpdatePixelTracking()
  278. {
  279. }
  280. [Browsable(false)]
  281. public WorkspaceWidgets Widgets
  282. {
  283. get
  284. {
  285. return this.widgets;
  286. }
  287. }
  288. public DocumentWorkspace ActiveDocumentWorkspace
  289. {
  290. get
  291. {
  292. return this.activeDocumentWorkspace;
  293. }
  294. set
  295. {
  296. if (value != this.activeDocumentWorkspace)
  297. {
  298. if (value != null &&
  299. this.documentWorkspaces.IndexOf(value) == -1)
  300. {
  301. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  302. }
  303. bool focused = false;
  304. if (this.activeDocumentWorkspace != null)
  305. {
  306. focused = this.activeDocumentWorkspace.Focused;
  307. }
  308. UI.SuspendControlPainting(this);
  309. OnActiveDocumentWorkspaceChanging();
  310. this.activeDocumentWorkspace = value;
  311. OnActiveDocumentWorkspaceChanged();
  312. UI.ResumeControlPainting(this);
  313. Refresh();
  314. if (value != null)
  315. {
  316. value.Focus();
  317. }
  318. }
  319. }
  320. }
  321. private void ActiveDocumentWorkspace_FirstInputAfterGotFocus(object sender, EventArgs e)
  322. {
  323. //this.toolBar.DocumentStrip.EnsureItemFullyVisible(this.toolBar.DocumentStrip.SelectedDocumentIndex);
  324. }
  325. public DocumentWorkspace[] DocumentWorkspaces
  326. {
  327. get
  328. {
  329. return this.documentWorkspaces.ToArray();
  330. }
  331. }
  332. public SnapObstacle SnapObstacle
  333. {
  334. get
  335. {
  336. if (this.snapObstacle == null)
  337. {
  338. this.snapObstacle = new SnapObstacleController(
  339. this.Name,
  340. Rectangle.Empty,
  341. SnapRegion.Interior,
  342. true);
  343. this.snapObstacle.EnableSave = false;
  344. PdnBaseForm pdbForm = FindForm() as PdnBaseForm;
  345. pdbForm.Moving += new MovingEventHandler(ParentForm_Moving);
  346. pdbForm.Move += new EventHandler(ParentForm_Move);
  347. pdbForm.ResizeEnd += new EventHandler(ParentForm_ResizeEnd);
  348. pdbForm.Layout += new LayoutEventHandler(ParentForm_Layout);
  349. pdbForm.SizeChanged += new EventHandler(ParentForm_SizeChanged);
  350. UpdateSnapObstacle();
  351. }
  352. return this.snapObstacle;
  353. }
  354. }
  355. private void ParentForm_Move(object sender, EventArgs e)
  356. {
  357. UpdateSnapObstacle();
  358. }
  359. private void ParentForm_SizeChanged(object sender, EventArgs e)
  360. {
  361. UpdateSnapObstacle();
  362. }
  363. private void ParentForm_Layout(object sender, LayoutEventArgs e)
  364. {
  365. UpdateSnapObstacle();
  366. }
  367. private void ParentForm_ResizeEnd(object sender, EventArgs e)
  368. {
  369. UpdateSnapObstacle();
  370. }
  371. private void ParentForm_Moving(object sender, MovingEventArgs e)
  372. {
  373. UpdateSnapObstacle();
  374. }
  375. private void AppWorkspace_Shown(object sender, EventArgs e)
  376. {
  377. UpdateSnapObstacle();
  378. }
  379. private void SuspendUpdateSnapObstacle()
  380. {
  381. ++this.ignoreUpdateSnapObstacle;
  382. }
  383. private void ResumeUpdateSnapObstacle()
  384. {
  385. --this.ignoreUpdateSnapObstacle;
  386. }
  387. /// <summary>
  388. /// 更新快照
  389. /// </summary>
  390. private void UpdateSnapObstacle()
  391. {
  392. if (this.ignoreUpdateSnapObstacle > 0)
  393. {
  394. return;
  395. }
  396. if (this.snapObstacle == null)
  397. {
  398. return;
  399. }
  400. if (!this.addedToSnapManager)
  401. {
  402. SnapManager sm = SnapManager.FindMySnapManager(this);
  403. if (sm != null)
  404. {
  405. SnapObstacle so = this.SnapObstacle;
  406. if (!this.addedToSnapManager)
  407. {
  408. sm.AddSnapObstacle(this.SnapObstacle);
  409. this.addedToSnapManager = true;
  410. FindForm().Shown += new EventHandler(AppWorkspace_Shown);
  411. }
  412. }
  413. }
  414. if (this.snapObstacle != null)
  415. {
  416. Rectangle clientRect;
  417. if (ActiveDocumentWorkspace != null)
  418. {
  419. clientRect = ActiveDocumentWorkspace.VisibleViewRectangle;
  420. }
  421. else
  422. {
  423. clientRect = this.workspacePanel.ClientRectangle;
  424. }
  425. Rectangle screenRect = this.workspacePanel.RectangleToScreen(clientRect);
  426. this.snapObstacle.SetBounds(screenRect);
  427. this.snapObstacle.Enabled = this.Visible && this.Enabled;
  428. try
  429. {
  430. //this.ActiveDocumentWorkspace.PanelBottom.documentStrip.Width = screenRect.Width - this.ActiveDocumentWorkspace.PanelBottom.locationX;
  431. }
  432. catch (Exception)
  433. {
  434. // throw;
  435. }
  436. }
  437. }
  438. public DocumentWorkspace AddNewDocumentWorkspace()
  439. {
  440. if (this.initialWorkspace != null)
  441. {
  442. if (this.initialWorkspace.Document == null || !this.initialWorkspace.Document.Dirty)
  443. {
  444. RemoveDocumentWorkspace(this.initialWorkspace);
  445. this.initialWorkspace = null;
  446. }
  447. }
  448. DocumentWorkspace dw = new DocumentWorkspace(this);
  449. dw.AppWorkspace = this;
  450. dw.activeTool = this.activeTool;
  451. this.documentWorkspaces.Add(dw);
  452. this.toolBar.DocumentStrip.AddDocumentWorkspace(dw);
  453. return dw;
  454. }
  455. public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace)
  456. {
  457. int dwIndex = this.documentWorkspaces.IndexOf(documentWorkspace);
  458. if (dwIndex == -1)
  459. {
  460. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  461. }
  462. bool removingCurrentDW;
  463. if (this.ActiveDocumentWorkspace == documentWorkspace)
  464. {
  465. removingCurrentDW = true;
  466. }
  467. else
  468. {
  469. removingCurrentDW = false;
  470. }
  471. if (removingCurrentDW)
  472. {
  473. if (this.documentWorkspaces.Count == 1)
  474. {
  475. this.ActiveDocumentWorkspace = null;
  476. }
  477. else if (dwIndex == 0)
  478. {
  479. this.ActiveDocumentWorkspace = this.documentWorkspaces[1];
  480. }
  481. else
  482. {
  483. this.ActiveDocumentWorkspace = this.documentWorkspaces[dwIndex - 1];
  484. }
  485. }
  486. this.documentWorkspaces.Remove(documentWorkspace);
  487. this.toolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
  488. if (this.initialWorkspace == documentWorkspace)
  489. {
  490. this.initialWorkspace = null;
  491. }
  492. // Clean up the DocumentWorkspace
  493. Document document = documentWorkspace.Document;
  494. documentWorkspace.Document = null;
  495. document.Dispose();
  496. documentWorkspace.Dispose();
  497. documentWorkspace = null;
  498. }
  499. public event EventHandler ActiveDocumentWorkspaceChanging;
  500. protected virtual void OnActiveDocumentWorkspaceChanging()
  501. {
  502. SuspendUpdateSnapObstacle();
  503. if (ActiveDocumentWorkspaceChanging != null)
  504. {
  505. ActiveDocumentWorkspaceChanging(this, EventArgs.Empty);
  506. }
  507. if (this.activeDocumentWorkspace != null)
  508. {
  509. this.activeDocumentWorkspace.FirstInputAfterGotFocus +=
  510. ActiveDocumentWorkspace_FirstInputAfterGotFocus;
  511. this.activeDocumentWorkspace.RulersEnabledChanged -= this.DocumentWorkspace_RulersEnabledChanged;
  512. this.activeDocumentWorkspace.DocumentMouseEnter -= this.DocumentMouseEnterHandler;
  513. this.activeDocumentWorkspace.DocumentMouseLeave -= this.DocumentMouseLeaveHandler;
  514. this.activeDocumentWorkspace.DocumentMouseMove -= this.DocumentMouseMoveHandler;
  515. this.activeDocumentWorkspace.DocumentMouseDown -= this.DocumentMouseDownHandler;
  516. this.activeDocumentWorkspace.Scroll -= this.DocumentWorkspace_Scroll;
  517. this.activeDocumentWorkspace.Layout -= this.DocumentWorkspace_Layout;
  518. this.activeDocumentWorkspace.DocumentClick -= this.DocumentClick;
  519. this.activeDocumentWorkspace.DocumentMouseUp -= this.DocumentMouseUpHandler;
  520. this.activeDocumentWorkspace.DocumentKeyPress -= this.DocumentKeyPress;
  521. this.activeDocumentWorkspace.DocumentKeyUp -= this.DocumenKeyUp;
  522. this.activeDocumentWorkspace.DocumentKeyDown -= this.DocumentKeyDown;
  523. this.activeDocumentWorkspace.StatusChanged -= OnDocumentWorkspaceStatusChanged;
  524. this.activeDocumentWorkspace.DocumentChanging -= DocumentWorkspace_DocumentChanging;
  525. this.activeDocumentWorkspace.DocumentChanged -= DocumentWorkspace_DocumentChanged;
  526. this.activeDocumentWorkspace.Visible = false;
  527. this.activeDocumentWorkspace.ToolChanging -= this.ToolChangingHandler;
  528. this.activeDocumentWorkspace.ToolChanged -= this.ToolChangedHandler;
  529. this.activeDocumentWorkspace.ActiveTool = this.activeTool;
  530. }
  531. ResumeUpdateSnapObstacle();
  532. UpdateSnapObstacle();
  533. //if (this.activeDocumentWorkspace != null)
  534. //{
  535. // if (!this.activeDocumentWorkspace.ContinuousDrawingMeasure
  536. // && this.activeDocumentWorkspace.activeTool >= DrawToolType.MeasureLine && this.activeDocumentWorkspace.activeTool <= DrawToolType.MeasureThreePointArc)
  537. // this.activeDocumentWorkspace.activeTool = DrawToolType.Pointer;
  538. // if (!this.activeDocumentWorkspace.ContinuousDrawingLabel
  539. // && this.activeDocumentWorkspace.activeTool >= DrawToolType.DrawRectangle && this.activeDocumentWorkspace.activeTool <= DrawToolType.DrawPrestoredRuler)
  540. // this.activeDocumentWorkspace.activeTool = DrawToolType.Pointer;
  541. // this.SetTopLeftCheckState();
  542. // this.UpdateBottomButtonSelectionStatus();
  543. //}
  544. }
  545. public event EventHandler ActiveDocumentWorkspaceChanged;
  546. protected virtual void OnActiveDocumentWorkspaceChanged()
  547. {
  548. SuspendUpdateSnapObstacle();
  549. if (this.activeDocumentWorkspace != null)
  550. {
  551. this.activeDocumentWorkspace.SuspendLayout();
  552. this.activeDocumentWorkspace.BackColor = System.Drawing.SystemColors.ControlDark;
  553. this.activeDocumentWorkspace.Dock = System.Windows.Forms.DockStyle.Fill;
  554. this.activeDocumentWorkspace.PanelAutoScroll = true;
  555. this.activeDocumentWorkspace.RulersEnabled = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, true);
  556. this.activeDocumentWorkspace.TabIndex = 0;
  557. this.activeDocumentWorkspace.TabStop = false;
  558. this.activeDocumentWorkspace.RulersEnabledChanged += this.DocumentWorkspace_RulersEnabledChanged;
  559. this.activeDocumentWorkspace.DocumentMouseEnter += this.DocumentMouseEnterHandler;
  560. this.activeDocumentWorkspace.DocumentMouseLeave += this.DocumentMouseLeaveHandler;
  561. this.activeDocumentWorkspace.DocumentMouseMove += this.DocumentMouseMoveHandler;
  562. this.activeDocumentWorkspace.DocumentMouseDown += this.DocumentMouseDownHandler;
  563. this.activeDocumentWorkspace.Scroll += this.DocumentWorkspace_Scroll;
  564. this.activeDocumentWorkspace.DocumentClick += this.DocumentClick;
  565. this.activeDocumentWorkspace.DocumentMouseUp += this.DocumentMouseUpHandler;
  566. this.activeDocumentWorkspace.DocumentKeyPress += this.DocumentKeyPress;
  567. this.activeDocumentWorkspace.DocumentKeyUp += this.DocumenKeyUp;
  568. this.activeDocumentWorkspace.DocumentKeyDown += this.DocumentKeyDown;
  569. if (this.workspacePanel.Controls.Contains(this.activeDocumentWorkspace))
  570. {
  571. this.activeDocumentWorkspace.Visible = true;
  572. }
  573. else
  574. {
  575. this.activeDocumentWorkspace.Dock = DockStyle.Fill;
  576. this.workspacePanel.Controls.Add(this.activeDocumentWorkspace);
  577. }
  578. this.activeDocumentWorkspace.Layout += this.DocumentWorkspace_Layout;
  579. this.activeDocumentWorkspace.AppWorkspace = this;
  580. this.activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
  581. this.activeDocumentWorkspace.DocumentChanging += DocumentWorkspace_DocumentChanging;
  582. this.activeDocumentWorkspace.DocumentChanged += DocumentWorkspace_DocumentChanged;
  583. this.activeDocumentWorkspace.ToolChanging += this.ToolChangingHandler;
  584. this.activeDocumentWorkspace.ToolChanged += this.ToolChangedHandler;
  585. this.toolBar.DocumentStrip.SelectDocumentWorkspace(this.activeDocumentWorkspace);
  586. //处理底部缩放百分比的trackbar和textbox
  587. this.SetZoonTrackValue(this.activeDocumentWorkspace.ScaleFactor);
  588. this.activeDocumentWorkspace.ResumeLayout();
  589. this.activeDocumentWorkspace.PerformLayout();
  590. this.activeDocumentWorkspace.FirstInputAfterGotFocus += ActiveDocumentWorkspace_FirstInputAfterGotFocus;
  591. //更新信息
  592. this.UpdateDocInfoInStatusBar();
  593. }
  594. if (ActiveDocumentWorkspaceChanged != null)
  595. {
  596. ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
  597. }
  598. ResumeUpdateSnapObstacle();
  599. UpdateSnapObstacle();
  600. UpdateStatusBarContextStatus();
  601. }
  602. public void SetTopLeftCheckState()
  603. {
  604. if (this.toolBar != null && this.activeDocumentWorkspace != null)
  605. {
  606. this.toolBar.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
  607. this.toolsPanel.RefreshBtnSelect(this.Widgets.RuleListForm.Visible, "SubRulerCalibration");
  608. this.activeDocumentWorkspace.ContinuousDrawingMeasure = this.continuousDrawingMeasure;
  609. this.activeDocumentWorkspace.ContinuousDrawingLabel = this.continuousDrawingLabel;
  610. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
  611. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingMeasure, "ContinuousDrawingMeasure");
  612. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
  613. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousDrawingLabel, "ContinuousDrawingLabel");
  614. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
  615. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.GridLineEnabled, "GridLine");
  616. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
  617. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.RulersEnabled, "ViewRuler");
  618. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
  619. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ContinuousBinaryAction, "ContinuousOperation");
  620. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
  621. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.ActualSize, "ActualSize");
  622. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
  623. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableSize, "ZoomToWindow");
  624. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  625. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableWidth, "ZoomToWidth");
  626. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  627. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.SuitableHeight, "ZoomToHeight");
  628. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
  629. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.LockZoom, "LockZoom");
  630. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
  631. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.FixedMultiple, "FixedMultiple");
  632. if (!this.activeDocumentWorkspace.DeleteFieldOfView)
  633. this.activeDocumentWorkspace.MergeFieldOfView = true;
  634. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  635. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.MergeFieldOfView, "MergeFieldOfView");
  636. this.toolBar.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  637. this.toolsPanel.RefreshBtnSelect(this.activeDocumentWorkspace.DeleteFieldOfView, "DeleteFieldOfView");
  638. }
  639. }
  640. public AppWorkspace(Form form)
  641. {
  642. SuspendLayout();
  643. InitializeComponent();
  644. InitializeFloatingForms();
  645. this.toolBar.AppWorkspace = this;
  646. this.widgets = new WorkspaceWidgets(this);
  647. this.widgets.StatusBarProgress = this.statusBar;
  648. this.widgets.DocumentStrip = this.toolBar.DocumentStrip;
  649. this.Widgets.RuleListForm = this.ruleListForm;
  650. this.toolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
  651. this.toolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  652. this.toolBar.DocumentStrip.DocumentClicked += DocumentStrip_DocumentTabClicked;
  653. this.toolBar.DocumentStrip.DocumentListChanged += DocumentStrip_DocumentListChanged;
  654. ResumeLayout();
  655. PerformLayout();
  656. this.InitializeBottomEvent();
  657. }
  658. private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
  659. {
  660. bool enableThem = (this.widgets.DocumentStrip.DocumentCount != 0);
  661. this.widgets.RuleListForm.Enabled = enableThem;
  662. UpdateDocInfoInStatusBar();
  663. UpdateCursorInfoInStatusBar(0, 0);
  664. }
  665. private void InitializeFloatingForms()
  666. {
  667. // RuleListForm
  668. ruleListForm = new RuleListForm(this);
  669. ruleListForm.RelinquishFocus += RelinquishFocusHandler;
  670. ruleListForm.ProcessCmdKeyEvent += OnToolFormProcessCmdKeyEvent;
  671. }
  672. public event CmdKeysEventHandler ProcessCmdKeyEvent;
  673. private bool OnToolFormProcessCmdKeyEvent(object sender, ref Message msg, Keys keyData)
  674. {
  675. if (ProcessCmdKeyEvent != null)
  676. {
  677. return ProcessCmdKeyEvent(sender, ref msg, keyData);
  678. }
  679. else
  680. {
  681. return false;
  682. }
  683. }
  684. public void SaveSettings()
  685. {
  686. this.MostRecentFiles.SaveMruList();
  687. }
  688. protected override void OnLoad(EventArgs e)
  689. {
  690. if (this.ActiveDocumentWorkspace != null)
  691. {
  692. this.ActiveDocumentWorkspace.Select();
  693. }
  694. base.OnLoad(e);
  695. }
  696. private void RelinquishFocusHandler(object sender, EventArgs e)
  697. {
  698. this.Focus();
  699. }
  700. private void InitializeComponent()
  701. {
  702. this.panelBottom = new PanelBottom();
  703. this.toolBar = new PdnToolBar(this);
  704. this.statusBar = new PdnStatusBar();
  705. this.toolsPanel = new ToolsControl(this);
  706. this.workspacePanel = new Panel();
  707. this.workspacePanel.SuspendLayout();
  708. this.statusBar.SuspendLayout();
  709. this.SuspendLayout();
  710. //
  711. // panelBottom
  712. //
  713. this.panelBottom.Height = 30;
  714. this.panelBottom.Dock = DockStyle.Bottom;
  715. //
  716. // toolBar
  717. //
  718. this.toolBar.Name = "toolBar";
  719. this.toolBar.Dock = DockStyle.Top;
  720. //
  721. // statusBar
  722. //
  723. this.statusBar.Name = "statusBar";
  724. //
  725. // toolsPanel
  726. //
  727. this.toolsPanel.Width = 50;
  728. this.toolsPanel.Dock = DockStyle.Left;
  729. //
  730. // workspacePanel
  731. //
  732. this.workspacePanel.Name = "workspacePanel";
  733. this.workspacePanel.Dock = DockStyle.Fill;
  734. //
  735. // AppWorkspace
  736. //
  737. this.Controls.Add(this.workspacePanel);
  738. this.Controls.Add(this.panelBottom);
  739. this.Controls.Add(this.toolsPanel);
  740. this.Controls.Add(this.statusBar);
  741. this.Controls.Add(this.toolBar);
  742. this.Name = "AppWorkspace";
  743. this.Size = new System.Drawing.Size(872, 640);
  744. this.workspacePanel.ResumeLayout(false);
  745. this.statusBar.ResumeLayout(false);
  746. this.statusBar.PerformLayout();
  747. this.ResumeLayout(false);
  748. }
  749. private void DocumentStrip_DocumentTabClicked(
  750. object sender,
  751. EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
  752. {
  753. switch (e.Data.Second)
  754. {
  755. case DocumentClickAction.Select:
  756. this.ActiveDocumentWorkspace = e.Data.First;
  757. break;
  758. case DocumentClickAction.Close:
  759. CloseWorkspaceAction cwa = new CloseWorkspaceAction(e.Data.First);
  760. PerformAction(cwa);
  761. break;
  762. default:
  763. throw new NotImplementedException("Code for DocumentClickAction." + e.Data.Second.ToString() + " not implemented");
  764. }
  765. Update();
  766. }
  767. private void OnToolStripMouseWheel(object sender, MouseEventArgs e)
  768. {
  769. if (this.activeDocumentWorkspace != null)
  770. {
  771. this.activeDocumentWorkspace.PerformMouseWheel((Control)sender, e);
  772. }
  773. }
  774. private void OnToolStripRelinquishFocus(object sender, EventArgs e)
  775. {
  776. if (this.activeDocumentWorkspace != null)
  777. {
  778. this.activeDocumentWorkspace.Focus();
  779. }
  780. }
  781. private void DocumentMouseEnterHandler(object sender, EventArgs e)
  782. {
  783. }
  784. private void DocumentMouseLeaveHandler(object sender, EventArgs e)
  785. {
  786. }
  787. private void DocumentMouseUpHandler(object sender, MouseEventArgs e)
  788. {
  789. }
  790. private void DocumentMouseDownHandler(object sender, MouseEventArgs e)
  791. {
  792. }
  793. private void DocumentMouseMoveHandler(object sender, MouseEventArgs e)
  794. {
  795. UpdateCursorInfoInStatusBar(e.X, e.Y);
  796. }
  797. private void DocumentClick(object sender, EventArgs e)
  798. {
  799. }
  800. private void DocumentKeyPress(object sender, KeyPressEventArgs e)
  801. {
  802. }
  803. private void DocumentKeyDown(object sender, KeyEventArgs e)
  804. {
  805. }
  806. private void DocumenKeyUp(object sender, KeyEventArgs e)
  807. {
  808. }
  809. public void PerformAction(AppWorkspaceAction performMe)
  810. {
  811. Update();
  812. using (new WaitCursorChanger(this))
  813. {
  814. performMe.PerformAction(this);
  815. }
  816. Update();
  817. }
  818. private void ToolChangingHandler(object sender, EventArgs e)
  819. {
  820. UI.SuspendControlPainting(this.toolBar);
  821. }
  822. private void ToolChangedHandler(object sender, EventArgs e)
  823. {
  824. UpdateStatusBarContextStatus();
  825. UI.ResumeControlPainting(this.toolBar);
  826. this.toolBar.Refresh();
  827. }
  828. protected override void OnResize(EventArgs e)
  829. {
  830. base.OnResize(e);
  831. }
  832. private void DocumentWorkspace_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
  833. {
  834. OnScroll(e);
  835. }
  836. private void DocumentWorkspace_Layout(object sender, LayoutEventArgs e)
  837. {
  838. }
  839. /*private void DocumentWorkspace_ZoomBasisChanged(object sender, EventArgs e)
  840. {
  841. if (this.toolBar.ViewConfigStrip.ZoomBasis != this.ActiveDocumentWorkspace.ZoomBasis)
  842. {
  843. this.toolBar.ViewConfigStrip.ZoomBasis = this.ActiveDocumentWorkspace.ZoomBasis;
  844. }
  845. }*/
  846. private void DocumentWorkspace_RulersEnabledChanged(object sender, EventArgs e)
  847. {
  848. PerformLayout();
  849. }
  850. public void ViewConfigStrip_UnitsChanged(object sender, EventArgs e)
  851. {
  852. if (this.activeDocumentWorkspace != null)
  853. {
  854. this.activeDocumentWorkspace.Units = this.Units;
  855. }
  856. UpdateDocInfoInStatusBar();
  857. this.statusBar.CursorInfoText = string.Empty;
  858. OnUnitsChanged();
  859. }
  860. public event EventHandler StatusChanged;
  861. private void OnStatusChanged()
  862. {
  863. if (StatusChanged != null)
  864. {
  865. StatusChanged(this, EventArgs.Empty);
  866. }
  867. }
  868. private void OnDocumentWorkspaceStatusChanged(object sender, EventArgs e)
  869. {
  870. OnStatusChanged();
  871. UpdateStatusBarContextStatus();
  872. }
  873. private void UpdateStatusBarContextStatus()
  874. {
  875. if (ActiveDocumentWorkspace != null)
  876. {
  877. this.statusBar.ContextStatusText = this.activeDocumentWorkspace.StatusText;
  878. this.statusBar.ContextStatusImage = this.activeDocumentWorkspace.StatusIcon;
  879. }
  880. else
  881. {
  882. this.statusBar.ContextStatusText = string.Empty;
  883. this.statusBar.ContextStatusImage = null;
  884. }
  885. }
  886. public bool CreateBlankDocumentInNewWorkspace(Size size, MeasurementUnit dpuUnit, double dpu, bool isInitial)
  887. {
  888. DocumentWorkspace dw1 = this.activeDocumentWorkspace;
  889. if (dw1 != null)
  890. {
  891. dw1.SuspendRefresh();
  892. }
  893. try
  894. {
  895. Document untitled = new Document(size.Width, size.Height);
  896. untitled.DpuUnit = dpuUnit;
  897. untitled.DpuX = dpu;
  898. untitled.DpuY = dpu;
  899. using (new WaitCursorChanger(this))
  900. {
  901. bool focused = false;
  902. if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Focused)
  903. {
  904. focused = true;
  905. }
  906. untitled.surface = new Surface(new Size(size.Width, size.Height));
  907. untitled.surface.Clear(ColorBgra.FromBgra(255, 255, 255, 255));
  908. DocumentWorkspace dw = this.AddNewDocumentWorkspace();
  909. this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
  910. dw.SuspendRefresh();
  911. try
  912. {
  913. dw.Document = untitled;
  914. }
  915. catch (OutOfMemoryException)
  916. {
  917. Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
  918. RemoveDocumentWorkspace(dw);
  919. untitled.Dispose();
  920. return false;
  921. }
  922. this.ActiveDocumentWorkspace = dw;
  923. dw.SetDocumentSaveOptions(null);
  924. dw.Document.Dirty = false;
  925. dw.ResumeRefresh();
  926. if (isInitial)
  927. {
  928. this.initialWorkspace = dw;
  929. }
  930. if (focused)
  931. {
  932. this.ActiveDocumentWorkspace.Focus();
  933. }
  934. this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
  935. }
  936. }
  937. finally
  938. {
  939. if (dw1 != null)
  940. {
  941. dw1.ResumeRefresh();
  942. }
  943. }
  944. return true;
  945. }
  946. public bool OpenFilesInNewWorkspace(string[] fileNames)
  947. {
  948. if (IsDisposed)
  949. {
  950. return false;
  951. }
  952. bool result = true;
  953. foreach (string fileName in fileNames)
  954. {
  955. result &= OpenFileInNewWorkspace(fileName);
  956. if (!result)
  957. {
  958. break;
  959. }
  960. }
  961. return result;
  962. }
  963. #region 标尺相关
  964. /// <summary>
  965. /// 刷新标尺列表
  966. /// </summary>
  967. public void RefueshRuleList()
  968. {
  969. if (this.widgets.RuleListForm != null)
  970. {
  971. this.widgets.RuleListForm.InitListViewData();
  972. }
  973. }
  974. /// <summary>
  975. /// 激活理论比例尺
  976. /// </summary>
  977. public void ActivateTemporaryRuler()
  978. {
  979. if (this.widgets.RuleListForm != null)
  980. {
  981. this.widgets.RuleListForm.ActivateTemporaryRuler();
  982. }
  983. }
  984. /// <summary>
  985. /// 设置当前选中标尺
  986. /// </summary>
  987. /// <param name="index"></param>
  988. public void SetActiveRulerIndex(int index)
  989. {
  990. if (this.widgets.RuleListForm != null)
  991. {
  992. this.widgets.RuleListForm.SetActiveRulerIndex(index);
  993. }
  994. }
  995. /// <summary>
  996. /// 刷新当前选中的标尺-编辑后使用
  997. /// </summary>
  998. public void RefreshActiveRuler()
  999. {
  1000. if (this.widgets.RuleListForm != null)
  1001. {
  1002. this.widgets.RuleListForm.RefreshActiveRuler();
  1003. }
  1004. }
  1005. #endregion
  1006. public bool OpenFileInNewWorkspace(string fileName)
  1007. {
  1008. return OpenFileInNewWorkspace(fileName, true);
  1009. }
  1010. /// <summary>
  1011. /// 需要修改
  1012. /// (1)判断是否有同名的xml文件,有则读取并处理
  1013. /// (2)判断是否识别其它标尺,有则读取
  1014. /// </summary>
  1015. /// <param name="fileName"></param>
  1016. /// <param name="addToMruList"></param>
  1017. /// <returns></returns>
  1018. public bool OpenFileInNewWorkspace(string fileName, bool addToMruList)
  1019. {
  1020. if (fileName == null)
  1021. {
  1022. throw new ArgumentNullException("fileName");
  1023. }
  1024. if (fileName.Length == 0)
  1025. {
  1026. throw new ArgumentOutOfRangeException("fileName.Length == 0");
  1027. }
  1028. PdnBaseForm.UpdateAllForms();
  1029. Document document;
  1030. this.widgets.StatusBarProgress.ResetProgressStatusBar();
  1031. ProgressEventHandler progressCallback =
  1032. delegate (object sender, ProgressEventArgs e)
  1033. {
  1034. this.widgets.StatusBarProgress.SetProgressStatusBar(e.Percent);
  1035. };
  1036. document = DocumentWorkspace.LoadDocument(this, fileName, progressCallback);
  1037. this.widgets.StatusBarProgress.EraseProgressStatusBar();
  1038. if (document == null)
  1039. {
  1040. this.Cursor = Cursors.Default;
  1041. }
  1042. else
  1043. {
  1044. using (new WaitCursorChanger(this))
  1045. {
  1046. DocumentWorkspace dw = AddNewDocumentWorkspace();
  1047. Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
  1048. try
  1049. {
  1050. dw.Document = document;
  1051. }
  1052. catch (OutOfMemoryException)
  1053. {
  1054. Utility.ErrorBox(this, PdnResources.GetString("LoadImage.Error.OutOfMemoryException"));
  1055. RemoveDocumentWorkspace(dw);
  1056. document.Dispose();
  1057. return false;
  1058. }
  1059. //判断是否存在xml,进行读取
  1060. PicConfigModel configModel = null;
  1061. try
  1062. {
  1063. string path = Path.GetDirectoryName(fileName);
  1064. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  1065. //如果xml存在
  1066. if (System.IO.File.Exists(xmlPath))
  1067. {
  1068. configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  1069. dw.RuleAttribute(configModel);
  1070. }
  1071. //如果不存在,则判断
  1072. //(1)是否自动添加ZEN标尺
  1073. //(2)是否自动添加AxioVision标尺
  1074. else
  1075. {
  1076. dw.xmlSaveModel = Program.instance.ruleDB;
  1077. dw.InitRulerInfo();
  1078. }
  1079. }
  1080. catch (Exception)
  1081. {
  1082. }
  1083. dw.SetDocumentSaveOptions(fileName);
  1084. this.ActiveDocumentWorkspace = dw;
  1085. document.Dirty = false;
  1086. Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
  1087. }
  1088. if (document != null)
  1089. {
  1090. if (isLockZoom && lockScaleRatio > 0)
  1091. {
  1092. ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1093. ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(lockScaleRatio);
  1094. }
  1095. else
  1096. {
  1097. ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1098. }
  1099. }
  1100. if (addToMruList)
  1101. {
  1102. ActiveDocumentWorkspace.AddToMruList();
  1103. }
  1104. }
  1105. if (ActiveDocumentWorkspace != null)
  1106. {
  1107. ActiveDocumentWorkspace.Focus();
  1108. }
  1109. return document != null;
  1110. }
  1111. #region 底部公共按钮
  1112. /// <summary>
  1113. /// 初始化底部按钮的各种事件
  1114. /// </summary>
  1115. private void InitializeBottomEvent()
  1116. {
  1117. //缩小按钮
  1118. this.PanelBottom.zoomOutButton.Click += new EventHandler(ZoomOutButton_Click);
  1119. //放大按钮
  1120. this.PanelBottom.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  1121. //放大缩小拖动条事件
  1122. this.PanelBottom.trackBar.ValueChanged += new EventHandler(PanelBottom_trackBar_ValueChanged);
  1123. //缩放缩小倍数的改变事件
  1124. this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
  1125. }
  1126. public void SetZoonTrackValue(ScaleFactor newValue)
  1127. {
  1128. this.panelBottom.trackBar.Maximum = 6200;// (int)(ScaleFactor.MaxValue.Ratio * 100);
  1129. if (newValue != null)
  1130. {
  1131. this.PanelBottom.trackBar.ValueChanged -= this.PanelBottom_trackBar_ValueChanged;
  1132. double v = newValue.Ratio * 100;
  1133. if (v <= 100)
  1134. {
  1135. this.PanelBottom.trackBar.Value = (int)(31 * v);
  1136. }
  1137. else
  1138. {
  1139. double x = 3100 + newValue.Ratio * 100;
  1140. if (x > 6200) x = 6200;
  1141. this.PanelBottom.trackBar.Value = (int)x;
  1142. }
  1143. this.PanelBottom.trackBar.ValueChanged += new EventHandler(this.PanelBottom_trackBar_ValueChanged);
  1144. }
  1145. //设置底部缩放比例的百分比textbox的值
  1146. this.PanelBottom.textBox.TextChanged -= new EventHandler(PanelBottom_textBox_ValueChanged);
  1147. this.PanelBottom.textBox.Text = newValue.ToString();
  1148. this.PanelBottom.textBox.TextChanged += new EventHandler(PanelBottom_textBox_ValueChanged);
  1149. }
  1150. /// <summary>
  1151. /// 最佳
  1152. /// </summary>
  1153. /// <param name="sender"></param>
  1154. /// <param name="e"></param>
  1155. private void BestButton_Click(object sender, MouseEventArgs e)
  1156. {
  1157. }
  1158. /// <summary>
  1159. /// 从直方图更新选中状态
  1160. /// </summary>
  1161. /// <param name="selected"></param>
  1162. public void MaxMinBest(bool best, bool maxMin, bool origin, bool gamma45)
  1163. {
  1164. this.activeDocumentWorkspace.best = best;
  1165. this.activeDocumentWorkspace.maxMin = maxMin;
  1166. this.activeDocumentWorkspace.origin = origin;
  1167. this.activeDocumentWorkspace.gamma45 = gamma45;
  1168. }
  1169. /// <summary>
  1170. /// 最大最小
  1171. /// </summary>
  1172. /// <param name="sender"></param>
  1173. /// <param name="e"></param>
  1174. private void MaxMinButton_Click(object sender, MouseEventArgs e)
  1175. {
  1176. }
  1177. /// <summary>
  1178. /// 原始状态
  1179. /// </summary>
  1180. /// <param name="sender"></param>
  1181. /// <param name="e"></param>
  1182. private void OriginButton_Click(object sender, MouseEventArgs e)
  1183. {
  1184. }
  1185. /// <summary>
  1186. /// 伽马0.45
  1187. /// </summary>
  1188. /// <param name="sender"></param>
  1189. /// <param name="e"></param>
  1190. private void Gamma45Button_Click(object sender, MouseEventArgs e)
  1191. {
  1192. }
  1193. /// <summary>
  1194. /// 更新底部按钮选中状态
  1195. /// </summary>
  1196. public void UpdateBottomButtonSelectionStatus()
  1197. {
  1198. if (this.ActiveDocumentWorkspace == null)
  1199. return;
  1200. }
  1201. /// <summary>
  1202. /// 底部快捷栏 辅助线
  1203. /// </summary>
  1204. /// <param name="sender"></param>
  1205. /// <param name="e"></param>
  1206. private void AuxiliaryLineButton_Click(object sender, MouseEventArgs e)
  1207. {
  1208. }
  1209. /// <summary>
  1210. /// 水平镜像
  1211. /// </summary>
  1212. /// <param name="sender"></param>
  1213. /// <param name="e"></param>
  1214. public void HorizontalMirroringButton_Click(object sender, EventArgs e)
  1215. {
  1216. }
  1217. /// <summary>
  1218. /// 垂直镜像
  1219. /// </summary>
  1220. /// <param name="sender"></param>
  1221. /// <param name="e"></param>
  1222. public void VerticalMirrorButton_Click(object sender, EventArgs e)
  1223. {
  1224. }
  1225. /// <summary>
  1226. /// 中心镜像
  1227. /// </summary>
  1228. /// <param name="sender"></param>
  1229. /// <param name="e"></param>
  1230. public void CenterMirrorButton_Click(object sender, EventArgs e)
  1231. {
  1232. }
  1233. /// <summary>
  1234. /// 底部快捷栏 缩小事件
  1235. /// </summary>
  1236. /// <param name="sender"></param>
  1237. /// <param name="e"></param>
  1238. private void ZoomOutButton_Click(object sender, EventArgs e)
  1239. {
  1240. if (this.ActiveDocumentWorkspace != null)
  1241. {
  1242. this.ActiveDocumentWorkspace.ZoomOut();
  1243. this.activeDocumentWorkspace.ActualSize = false;
  1244. this.activeDocumentWorkspace.SuitableSize = false;
  1245. this.activeDocumentWorkspace.SuitableHeight = false;
  1246. this.activeDocumentWorkspace.SuitableWidth = false;
  1247. this.SetTopLeftCheckState();
  1248. this.UpdateBottomButtonSelectionStatus();
  1249. }
  1250. }
  1251. /// <summary>
  1252. /// 底部快捷栏 放大事件
  1253. /// </summary>
  1254. /// <param name="sender"></param>
  1255. /// <param name="e"></param>
  1256. private void zoomInButton_Click(object sender, EventArgs e)
  1257. {
  1258. if (this.ActiveDocumentWorkspace != null)
  1259. {
  1260. this.ActiveDocumentWorkspace.ZoomIn();
  1261. this.activeDocumentWorkspace.ActualSize = false;
  1262. this.activeDocumentWorkspace.SuitableSize = false;
  1263. this.activeDocumentWorkspace.SuitableHeight = false;
  1264. this.activeDocumentWorkspace.SuitableWidth = false;
  1265. this.SetTopLeftCheckState();
  1266. this.UpdateBottomButtonSelectionStatus();
  1267. }
  1268. }
  1269. /// <summary>
  1270. /// 底部方法缩小拖动条事件
  1271. /// </summary>
  1272. /// <param name="sender"></param>
  1273. /// <param name="e"></param>
  1274. private void PanelBottom_trackBar_ValueChanged(object sender, EventArgs e)
  1275. {
  1276. if (this.activeDocumentWorkspace != null)
  1277. {
  1278. this.activeDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1279. if (this.PanelBottom.trackBar.Tag == null)
  1280. {
  1281. int v = this.PanelBottom.trackBar.Value;
  1282. if (this.PanelBottom.trackBar.Value <= 3100)
  1283. {
  1284. this.PanelBottom.trackBar.SmallChange = 31;
  1285. v = this.PanelBottom.trackBar.Value / 31;
  1286. }
  1287. else
  1288. {
  1289. this.PanelBottom.trackBar.SmallChange = 100;
  1290. v = 100 + this.PanelBottom.trackBar.Value - 3100;
  1291. }
  1292. this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
  1293. this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
  1294. }
  1295. else
  1296. {
  1297. int oldValue = (int)this.PanelBottom.trackBar.Tag;
  1298. if (oldValue != this.PanelBottom.trackBar.Value)
  1299. {
  1300. int v = this.PanelBottom.trackBar.Value;
  1301. if (this.PanelBottom.trackBar.Value <= 3100)
  1302. {
  1303. this.PanelBottom.trackBar.SmallChange = 31;
  1304. v = this.PanelBottom.trackBar.Value / 31;
  1305. }
  1306. else
  1307. {
  1308. this.PanelBottom.trackBar.SmallChange = 100;
  1309. v = 100 + this.PanelBottom.trackBar.Value - 3100;
  1310. }
  1311. this.activeDocumentWorkspace.ScaleFactor = new ScaleFactor(v, 100);
  1312. this.PanelBottom.trackBar.Tag = this.PanelBottom.trackBar.Value;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. private void PanelBottom_textBox_ValueChanged(object sender, EventArgs e)
  1318. {
  1319. int v;
  1320. if (!string.IsNullOrEmpty(this.PanelBottom.textBox.Text) &&
  1321. !this.PanelBottom.textBox.Text.Equals("%") &&
  1322. int.TryParse(this.PanelBottom.textBox.Text.Replace("%", ""), out v))
  1323. {
  1324. if (v > this.PanelBottom.trackBar.Maximum) v = this.PanelBottom.trackBar.Maximum;
  1325. if (v < this.PanelBottom.trackBar.Minimum) v = this.PanelBottom.trackBar.Minimum;
  1326. if (v <= 100)
  1327. {
  1328. this.PanelBottom.trackBar.Value = v;
  1329. }
  1330. else
  1331. {
  1332. int x = 3000 + v;
  1333. if (x > 6100) x = 6200;
  1334. this.PanelBottom.trackBar.Value = x;
  1335. }
  1336. }
  1337. }
  1338. private bool ExistenceXML()
  1339. {
  1340. if (this.activeDocumentWorkspace != null)
  1341. {
  1342. return true;
  1343. }
  1344. //获取图片路径
  1345. bool existenceXML = false;
  1346. if (this.activeDocumentWorkspace != null)
  1347. {
  1348. string fileName;
  1349. this.activeDocumentWorkspace.GetDocumentSaveOptions(out fileName);
  1350. if (fileName != null)
  1351. {
  1352. string path = Path.GetDirectoryName(fileName);
  1353. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  1354. existenceXML = System.IO.File.Exists(xmlPath);
  1355. if (existenceXML)
  1356. {
  1357. }
  1358. }
  1359. }
  1360. return existenceXML;
  1361. }
  1362. public Dictionary<MeasurementUnit, double> getMeasureInfo()
  1363. {
  1364. if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.rules != null && this.ActiveDocumentWorkspace.rules.Count > 0)
  1365. return this.ActiveDocumentWorkspace.rules;
  1366. else
  1367. return Program.instance.rules;
  1368. }
  1369. #endregion
  1370. #region [测量相关]
  1371. public DrawToolType GetDrawToolType()
  1372. {
  1373. return activeTool;
  1374. }
  1375. public void SetDrawToolType(DrawToolType t)
  1376. {
  1377. activeTool = t;
  1378. }
  1379. public void SetDrawNodes()
  1380. {
  1381. //if (this.measureListDialog != null)
  1382. // this.measureListDialog.SetDrawNodes(null, null);
  1383. }
  1384. public void RefreshListView()
  1385. {
  1386. //if (this.measureListDialog != null)
  1387. // this.measureListDialog.RefreshListView(null, null);
  1388. //this.Refresh();
  1389. }
  1390. /// <summary>
  1391. /// 像素跟踪
  1392. /// 需要增加标记,在进行比如图像旋转等直接在当前
  1393. /// 面板进行图像大小变化操作的,需要停止像素跟踪,
  1394. /// 处理完成之后在恢复,否则可能会导致读取内存异常
  1395. /// </summary>
  1396. /// <param name="location"></param>
  1397. public void SetImageAndData(Point location)
  1398. {
  1399. //if (this.pixelTrackingDialog != null)
  1400. //{
  1401. // this.pixelTrackingDialog.SetImageAndData(location);
  1402. //}
  1403. }
  1404. /// <summary>
  1405. /// 获取系统当前选中单位及每单位像素值
  1406. /// </summary>
  1407. /// <returns>3位字符串数组,
  1408. /// 0:系统选中单位枚举字符串
  1409. /// 1:系统选中单位名称字符串
  1410. /// 2:系统选中单位符号字符串
  1411. /// 3:系统选中单位每单位像素长度
  1412. /// 4:系统选中单位每单位物理长度
  1413. /// </returns>
  1414. public string[] GetPxPerUnit()
  1415. {
  1416. if (this.activeDocumentWorkspace != null)
  1417. return this.activeDocumentWorkspace.getRulerList();
  1418. else
  1419. {
  1420. string[] result = new string[5];
  1421. result[0] = Program.instance.measurementUnit.ToString();
  1422. result[1] = InvariantData.unitsDictionary[(int)Program.instance.measurementUnit];
  1423. result[2] = InvariantData.unitSymbolsDictionary[(int)Program.instance.measurementUnit];
  1424. result[3] = (Program.instance.rules[Program.instance.measurementUnit]).ToString();
  1425. result[4] = (Program.instance.rules[MeasurementUnit.Micron]).ToString();
  1426. return result;
  1427. }
  1428. }
  1429. /// <summary>
  1430. /// 获取测量样式配置
  1431. /// </summary>
  1432. /// <returns></returns>
  1433. public MeasureStyleModel GetMeasureStyleModel()
  1434. {
  1435. return Program.instance.measureStyleModel;
  1436. }
  1437. public void SetContinuousDrawingMeasure(bool value)
  1438. {
  1439. this.continuousDrawingMeasure = value;
  1440. SetTopLeftCheckState();
  1441. }
  1442. public void SetContinuousDrawingView(bool value)
  1443. {
  1444. this.continuousDrawingView = value;
  1445. }
  1446. /// <summary>
  1447. /// 获取当前激活的图像工作空间的视场行为
  1448. /// 合并/剪切
  1449. /// </summary>
  1450. /// <returns></returns>
  1451. public CombineMode GetCombineMode()
  1452. {
  1453. return this.ActiveDocumentWorkspace.CombineMode;
  1454. }
  1455. public RectangleF GetVisibleDocumentRectangleF()
  1456. {
  1457. return this.activeDocumentWorkspace.VisibleDocumentRectangleF;
  1458. }
  1459. public SizeF GetDocumentSize()
  1460. {
  1461. return this.activeDocumentWorkspace.Document.Size;
  1462. }
  1463. /// <summary>
  1464. /// 更新命名的延续数字
  1465. /// </summary>
  1466. public void UpdateContinueNum()
  1467. {
  1468. if (Program.instance.configModel != null)
  1469. {
  1470. ConfigModel configModel = Program.instance.configModel;
  1471. configModel.ContinueNum++;
  1472. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  1473. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  1474. FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  1475. }
  1476. }
  1477. /// <summary>
  1478. /// 获取测量区域样式配置
  1479. /// </summary>
  1480. /// <returns></returns>
  1481. public MeasureAreaModel GetMeasureAreaModel()
  1482. {
  1483. return Program.instance.measureAreaModel;
  1484. }
  1485. #endregion
  1486. /// <summary>
  1487. /// 递归查询树状数据
  1488. /// </summary>
  1489. /// <param name="id"></param>
  1490. /// <param name="originalData"></param>
  1491. /// <param name="data"></param>
  1492. public void RecursionGetData(string id, List<MeasureMaintenanceTreeSpecificData> originalData, out MeasureMaintenanceTreeSpecificData data)
  1493. {
  1494. data = originalData.Where(m => m.MeasureMaintenanceTreeSpecificDataId.Equals(id)).FirstOrDefault();
  1495. if (data == null)
  1496. {
  1497. foreach (var item in originalData)
  1498. {
  1499. if (id.Equals("0")) {
  1500. break;
  1501. }
  1502. RecursionGetData(id, item.MeasureMaintenanceTreeSpecificSonDataList, out data);
  1503. if (data != null)
  1504. {
  1505. break;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. /// <summary>
  1511. /// 根据别名查询实际名称
  1512. /// </summary>
  1513. /// <param name="id"></param>
  1514. /// <param name="originalData"></param>
  1515. /// <param name="data"></param>
  1516. public string getRealName(List<MeasureMaintenanceTreeSpecificData> originalData,string aliasName)
  1517. {
  1518. foreach (var item in originalData)
  1519. {
  1520. foreach (var item2 in item.MeasureMaintenanceTreeSpecificSonDataList)
  1521. {
  1522. var data = item2.MeasureMaintenanceTreeSpecificFormulaDataList.Where(m => m.FormulaParameterAliasName == aliasName).FirstOrDefault();
  1523. if (data == null)
  1524. {
  1525. continue;
  1526. }
  1527. return data.FormulaParameterName;
  1528. }
  1529. }
  1530. return string.Empty;
  1531. }
  1532. public void setUnitNum(double unit)
  1533. {
  1534. this.unitNum = unit;
  1535. }
  1536. public double getUnitNum()
  1537. {
  1538. return this.unitNum;
  1539. }
  1540. public string getAliasName()
  1541. {
  1542. return this.aliasName;
  1543. }
  1544. public void setAliasName(string name)
  1545. {
  1546. this.aliasName = name;
  1547. }
  1548. public int getDecimalPlaces()
  1549. {
  1550. return Program.instance.decimalPlaces;
  1551. }
  1552. }
  1553. }