DocumentStitchView.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  1. using PaintDotNet.Annotation;
  2. using PaintDotNet.Annotation.Command;
  3. using PaintDotNet.Annotation.Enum;
  4. using PaintDotNet.Annotation.Label;
  5. using PaintDotNet.Annotation.Measure;
  6. using PaintDotNet.Annotation.Other;
  7. using PaintDotNet.Base.DedicatedAnalysis.Inclusions.Model;
  8. using PaintDotNet.Base.SettingModel;
  9. using PaintDotNet.SystemLayer;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Drawing;
  14. using System.Drawing.Drawing2D;
  15. using System.Reflection;
  16. using System.Threading;
  17. using System.Windows.Forms;
  18. namespace PaintDotNet
  19. {
  20. /// <summary>
  21. /// 主面板
  22. /// </summary>
  23. public class DocumentStitchView : UserControl, ISurfaceBox
  24. {
  25. private IContainer components = null;
  26. // 中心画布
  27. public PanelEx panel;
  28. private static WeakReference<StitchSurface> doubleBufferSurfaceWeakRef = null;
  29. private StitchSurface doubleBufferSurface = null;
  30. /// <summary>
  31. /// 绘制线程
  32. /// </summary>
  33. private Threading.ThreadPool threadPool = new Threading.ThreadPool();
  34. private RenderContext renderContext;
  35. /// <summary>
  36. /// 为了保证图片绘制在画布中心
  37. /// 设置的偏移量
  38. /// </summary>
  39. private int offsetW = 0;
  40. private int offsetH = 0;
  41. private int offsetHalfW = 0;
  42. private int offsetHalfH = 0;
  43. /*private int offsetW = 300;
  44. private int offsetH = 150;
  45. private int offsetHalfW = 150;
  46. private int offsetHalfH = 75;*/
  47. /// <summary>
  48. /// 图层及文档信息
  49. /// </summary>
  50. private StitchDocument document;
  51. /// <summary>
  52. /// 图像内存块及其属性
  53. /// </summary>
  54. protected StitchSurface compositionSurface;
  55. /// <summary>
  56. /// 【标注、测量】list of draw objects
  57. /// </summary>
  58. private GraphicsList graphicsList;
  59. /// <summary>
  60. /// 【标注、测量、视场、其它】当前激活的工具
  61. /// </summary>
  62. public DrawToolType _activeTool;
  63. /// <summary>
  64. /// 工具的集合
  65. /// </summary>
  66. protected static Dictionary<DrawToolType, Type> tools;
  67. /// <summary>
  68. /// 初始化标记
  69. /// </summary>
  70. private bool initialized;
  71. /// <summary>
  72. /// 待渲染的列表
  73. /// </summary>
  74. private StitchSurfaceBoxRendererList rendererList;
  75. private StitchSurfaceBoxBaseRenderer baseRenderer;
  76. /// <summary>
  77. /// 窗体状态
  78. /// </summary>
  79. private FormWindowState oldWindowState = FormWindowState.Minimized;
  80. /// <summary>
  81. /// 缩放比例
  82. /// </summary>
  83. private ScaleFactor scaleFactor = new ScaleFactor(1, 1);
  84. /// <summary>
  85. /// 在toolPointer的工具下,是否绘制鼠标划选的矩形
  86. /// </summary>
  87. public bool drawRectangle = false;
  88. /// <summary>
  89. /// 在toolPointer的工具下,鼠标划选的矩形
  90. /// </summary>
  91. public Rectangle rectangle;
  92. public DocumentStitchView()
  93. {
  94. InitializeComponent();
  95. this.document = null;
  96. this.compositionSurface = null;
  97. this.panel.ScaleFactor = this.scaleFactor;
  98. this.panel.Paint += new PaintEventHandler(this.panelPaint);
  99. this.panel.MouseMove += new MouseEventHandler(this.MouseEvent_Move);
  100. this.panel.MouseDown += new MouseEventHandler(this.MouseEvent_Down);
  101. this.panel.MouseUp += new MouseEventHandler(this.MouseEvent_Up);
  102. this.panel.MouseClick += new MouseEventHandler(this.MouseEvent_Click);
  103. this.rendererList = new StitchSurfaceBoxRendererList(this.panel.Size, this.panel.Size);
  104. this.rendererList.Invalidated += new InvalidateEventHandler(Renderers_Invalidated);
  105. this.baseRenderer = new StitchSurfaceBoxBaseRenderer(this.rendererList);
  106. this.rendererList.Add(this.baseRenderer, false);
  107. this.initialized = true;
  108. }
  109. public new void Refresh()
  110. {
  111. base.Refresh();
  112. }
  113. //public OpenCvSharp.Mat OldMat
  114. //{
  115. // get
  116. // {
  117. // //备注:待调试->>200827 add by scc
  118. // if (this.CompositionSurface != null && CompositionSurface != null && CompositionSurface.mat != null)
  119. // return this.CompositionSurface.mat/*.Clone()*/;
  120. // //备注:待调试->>200827 add by scc
  121. // else if (this.CompositionSurface != null && CompositionSurface != null && CompositionSurface.Thumborigin != null)
  122. // return OpenCvSharp.Extensions.BitmapConverter.ToMat(this.CompositionSurface.Thumborigin/*CreateAliasedBitmap()*/);
  123. // else
  124. // return null;
  125. // }
  126. //}
  127. //public OpenCvSharp.Mat BoxMat
  128. //{
  129. // get
  130. // {
  131. // //备注:待调试
  132. // //if (this.AppWorkspace.ActiveDocumentWorkspace != null)
  133. // //{
  134. // return OpenCvSharp.Extensions.BitmapConverter.ToMat(this.BoxBitmap);
  135. // //}
  136. // }
  137. //}
  138. /// <summary>
  139. /// 初始化工具
  140. /// </summary>
  141. protected void InitToolsAndManager()
  142. {
  143. // 一是用于存储,二是用于调整层级
  144. GraphicsList = new GraphicsList(this);
  145. // init Tools
  146. //tools = new Tool[(int)DrawToolType.NumberOfDrawTools];
  147. if (tools != null) return;
  148. tools = new Dictionary<DrawToolType, Type>();
  149. tools.Add(DrawToolType.Pointer, typeof(ToolPointer));
  150. //其它
  151. //手型工具
  152. tools.Add(DrawToolType.MoveMode, typeof(PanTool));
  153. //图片裁剪
  154. tools.Add(DrawToolType.ImageCut, typeof(ImageCutTool));
  155. //null
  156. tools.Add(DrawToolType.NullTool, typeof(ToolNull));
  157. }
  158. [Browsable(false)]
  159. public override bool Focused
  160. {
  161. get
  162. {
  163. return base.Focused || panel.Focused;
  164. }
  165. }
  166. private void Renderers_Invalidated(object sender, InvalidateEventArgs e)
  167. {
  168. Rectangle rect = SurfaceToClient(e.InvalidRect);
  169. rect.Inflate(1, 1);
  170. Invalidate(rect);
  171. }
  172. public StitchSurface GetDoubleBuffer(Size size)
  173. {
  174. StitchSurface localDBSurface = null;
  175. Size oldSize = new Size(0, 0);
  176. // If we already have a double buffer surface reference, but if that surface
  177. // is already disposed then don't worry about it.
  178. if (this.doubleBufferSurface != null && this.doubleBufferSurface.IsDisposed)
  179. {
  180. oldSize = this.doubleBufferSurface.Size;
  181. this.doubleBufferSurface = null;
  182. }
  183. // If we already have a double buffer surface reference, but if that surface
  184. // is too small, then nuke it.
  185. if (this.doubleBufferSurface != null &&
  186. (this.doubleBufferSurface.Width < size.Width || this.doubleBufferSurface.Height < size.Height))
  187. {
  188. oldSize = this.doubleBufferSurface.Size;
  189. this.doubleBufferSurface.Dispose();
  190. this.doubleBufferSurface = null;
  191. doubleBufferSurfaceWeakRef = null;
  192. }
  193. // If we don't have a double buffer, then we'd better get one.
  194. if (this.doubleBufferSurface != null)
  195. {
  196. // Got one!
  197. localDBSurface = this.doubleBufferSurface;
  198. }
  199. else if (doubleBufferSurfaceWeakRef != null)
  200. {
  201. // First, try to get the one that's already shared amongst all SurfaceBox instances.
  202. localDBSurface = doubleBufferSurfaceWeakRef.Target;
  203. // If it's disposed, then forget about it.
  204. if (localDBSurface != null && localDBSurface.IsDisposed)
  205. {
  206. oldSize = localDBSurface.Size;
  207. localDBSurface = null;
  208. doubleBufferSurfaceWeakRef = null;
  209. }
  210. }
  211. // Make sure the surface is big enough.
  212. if (localDBSurface != null && (localDBSurface.Width < size.Width || localDBSurface.Height < size.Height))
  213. {
  214. oldSize = localDBSurface.Size;
  215. localDBSurface.Dispose();
  216. localDBSurface = null;
  217. doubleBufferSurfaceWeakRef = null;
  218. }
  219. // So, do we have a surface? If not then we'd better make one.
  220. if (localDBSurface == null)
  221. {
  222. Size newSize = new Size(Math.Max(size.Width, oldSize.Width), Math.Max(size.Height, oldSize.Height));
  223. localDBSurface = new StitchSurface(newSize, this.compositionSurface.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb ? 3 : 4);
  224. doubleBufferSurfaceWeakRef = new WeakReference<StitchSurface>(localDBSurface);
  225. }
  226. this.doubleBufferSurface = localDBSurface;
  227. StitchSurface window = localDBSurface.CreateWindow(0, 0, size.Width, size.Height);
  228. return window;
  229. }
  230. private class RenderContext
  231. {
  232. public StitchSurface[] windows;
  233. public Point[] offsets;
  234. public Rectangle[] rects;
  235. public DocumentStitchView owner;
  236. public WaitCallback waitCallback;
  237. public int TopIndex = 0;
  238. public void RenderThreadMethod1(object indexObject)
  239. {
  240. int index = (int)indexObject;
  241. this.owner.rendererList.topList[TopIndex].Render(windows[index], offsets[index]);
  242. //this.owner.rendererList.RenderTop(windows[index], offsets[index]);
  243. this.windows[index].Dispose();
  244. this.windows[index] = null;
  245. }
  246. public void RenderThreadMethod(object indexObject)
  247. {
  248. int index = (int)indexObject;
  249. this.owner.rendererList.list[0].Render(windows[index], offsets[index]);
  250. this.windows[index].Dispose();
  251. this.windows[index] = null;
  252. }
  253. }
  254. public unsafe void DrawArea(StitchRenderArgs ra, Point offset)
  255. {
  256. if (compositionSurface == null)
  257. {
  258. return;
  259. }
  260. if (renderContext == null || (renderContext.windows != null && renderContext.windows.Length != Processor.LogicalCpuCount))
  261. {
  262. renderContext = new RenderContext();
  263. //这里需要计算宽高
  264. renderContext.owner = this;
  265. renderContext.waitCallback = new WaitCallback(renderContext.RenderThreadMethod);
  266. renderContext.windows = new StitchSurface[Processor.LogicalCpuCount];
  267. renderContext.offsets = new Point[Processor.LogicalCpuCount];
  268. renderContext.rects = new Rectangle[Processor.LogicalCpuCount];
  269. //renderContext.owner = this;
  270. //renderContext.waitCallback = new WaitCallback(renderContext.RenderThreadMethod);
  271. //renderContext.windows = new StitchSurface[1];//Processor.LogicalCpuCount
  272. //renderContext.offsets = new Point[1];
  273. //renderContext.rects = new Rectangle[1];
  274. }
  275. Utility.SplitRectangle(ra.Bounds, renderContext.rects);
  276. for (int i = 0; i < renderContext.rects.Length; ++i)
  277. {
  278. if (renderContext.rects[i].Width > 0 && renderContext.rects[i].Height > 0)
  279. {
  280. renderContext.offsets[i] = new Point(renderContext.rects[i].X + offset.X, renderContext.rects[i].Y + offset.Y);
  281. renderContext.windows[i] = ra.Surface.CreateWindow(renderContext.rects[i]);
  282. }
  283. else
  284. {
  285. renderContext.windows[i] = null;
  286. }
  287. }
  288. for (int i = 0; i < renderContext.windows.Length; ++i)
  289. {
  290. if (renderContext.windows[i] != null)
  291. {
  292. this.threadPool.QueueUserWorkItem(renderContext.waitCallback, BoxedConstants.GetInt32(i));
  293. }
  294. }
  295. try
  296. {
  297. this.threadPool.Drain();
  298. }
  299. catch { }
  300. }
  301. protected override void OnLoad(EventArgs e)
  302. {
  303. base.OnLoad(e);
  304. this.panel.Select();
  305. }
  306. protected override void OnMouseWheel(MouseEventArgs e)
  307. {
  308. HandleMouseWheel(this, e);
  309. base.OnMouseWheel(e);
  310. }
  311. /// <summary>
  312. /// 鼠标滚轮事件
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. protected virtual void HandleMouseWheel(Control sender, MouseEventArgs e)
  317. {
  318. double docDelta = (double)e.Delta / this.ScaleFactor.Ratio;
  319. double oldX = this.DocumentScrollPositionF.X;
  320. double oldY = this.DocumentScrollPositionF.Y;
  321. double newX;
  322. double newY;
  323. if (Control.ModifierKeys == Keys.Shift)
  324. {
  325. this.panel.Response = false;
  326. // scroll horizontally
  327. newX = this.DocumentScrollPositionF.X - docDelta;
  328. newY = this.DocumentScrollPositionF.Y;
  329. }
  330. else if (Control.ModifierKeys == Keys.None)
  331. {
  332. this.panel.Response = true;
  333. // scroll vertically
  334. newX = this.DocumentScrollPositionF.X;
  335. newY = this.DocumentScrollPositionF.Y - docDelta;
  336. }
  337. else
  338. {
  339. this.panel.Response = false;
  340. // no change
  341. newX = this.DocumentScrollPositionF.X;
  342. newY = this.DocumentScrollPositionF.Y;
  343. }
  344. if (newX != oldX || newY != oldY)
  345. this.DocumentScrollPositionF = new PointF((float)newX, (float)newY);
  346. }
  347. /// <summary>
  348. /// Get or set upper left of scroll location in document coordinates.
  349. /// </summary>
  350. [Browsable(false)]
  351. public PointF DocumentScrollPositionF
  352. {
  353. get
  354. {
  355. if (this.panel == null)
  356. {
  357. return PointF.Empty;
  358. }
  359. else
  360. {
  361. return this.panel.ScrollPosition;
  362. //return VisibleDocumentRectangleF.Location;
  363. }
  364. }
  365. set
  366. {
  367. if (panel == null)
  368. {
  369. return;
  370. }
  371. else
  372. {
  373. this.panel.ScrollPosition = new Point((int)value.X, (int)value.Y);
  374. }
  375. }
  376. }
  377. public Point PanelScrollPosition
  378. {
  379. get
  380. {
  381. return this.panel.ScrollPosition;
  382. }
  383. set
  384. {
  385. this.panel.ScrollPosition = value;
  386. }
  387. }
  388. [Browsable(false)]
  389. public PointF DocumentCenterPointF
  390. {
  391. get
  392. {
  393. RectangleF vsb = VisibleDocumentRectangleF;
  394. PointF centerPt = new PointF((vsb.Left + vsb.Right) / 2, (vsb.Top + vsb.Bottom) / 2);
  395. return centerPt;
  396. }
  397. set
  398. {
  399. RectangleF vsb = VisibleDocumentRectangleF;
  400. PointF newCornerPt = new PointF(value.X - (vsb.Width / 2), value.Y - (vsb.Height / 2));
  401. this.DocumentScrollPositionF = newCornerPt;
  402. }
  403. }
  404. /// <summary>
  405. /// Clean up any resources being used.
  406. /// </summary>
  407. protected override void Dispose(bool disposing)
  408. {
  409. if (disposing)
  410. {
  411. if (this.components != null)
  412. {
  413. this.components.Dispose();
  414. this.components = null;
  415. }
  416. if (this.compositionSurface != null)
  417. {
  418. this.compositionSurface.Dispose();
  419. this.compositionSurface = null;
  420. }
  421. }
  422. base.Dispose(disposing);
  423. }
  424. /// <summary>
  425. /// 缩放比例改变事件
  426. /// </summary>
  427. public event EventHandler ScaleFactorChanged;
  428. protected virtual void OnScaleFactorChanged()
  429. {
  430. if (ScaleFactorChanged != null)
  431. {
  432. ScaleFactorChanged(this, EventArgs.Empty);
  433. }
  434. }
  435. private double GetZoomInFactorEpsilon()
  436. {
  437. double ratio = this.ScaleFactor.Ratio;
  438. return (ratio + 0.01) / ratio;
  439. }
  440. private double GetZoomOutFactorEpsilon()
  441. {
  442. double ratio = this.ScaleFactor.Ratio;
  443. return (ratio - 0.01) / ratio;
  444. }
  445. public virtual void ZoomIn(double factor)
  446. {
  447. Do.TryBool(() => ZoomInImpl(factor));
  448. }
  449. private void ZoomInImpl(double factor)
  450. {
  451. PointF centerPt = this.DocumentCenterPointF;
  452. ScaleFactor oldSF = this.ScaleFactor;
  453. ScaleFactor newSF = this.ScaleFactor;
  454. int countdown = 3;
  455. // At a minimum we want to increase the size of visible document by 1 pixel
  456. // Figure out what the ratio of ourSize : ourSize+1 is, and start out with that
  457. double zoomInEps = GetZoomInFactorEpsilon();
  458. double desiredFactor = Math.Max(factor, zoomInEps);
  459. double newFactor = desiredFactor;
  460. // Keep setting the ScaleFactor until it actually 'sticks'
  461. // Important for certain image sizes where not all zoom levels create distinct
  462. // screen sizes
  463. do
  464. {
  465. newSF = ScaleFactor.FromDouble(newSF.Ratio * newFactor);
  466. this.ScaleFactor = newSF;
  467. --countdown;
  468. newFactor *= 1.10;
  469. } while (this.ScaleFactor == oldSF && countdown > 0);
  470. this.DocumentCenterPointF = centerPt;
  471. }
  472. public virtual void ZoomIn()
  473. {
  474. Do.TryBool(ZoomInImpl);
  475. }
  476. private void ZoomInImpl()
  477. {
  478. PointF centerPt = this.DocumentCenterPointF;
  479. ScaleFactor oldSF = this.ScaleFactor;
  480. ScaleFactor newSF = this.ScaleFactor;
  481. int countdown = ScaleFactor.PresetValues.Length;
  482. // Keep setting the ScaleFactor until it actually 'sticks'
  483. // Important for certain image sizes where not all zoom levels create distinct
  484. // screen sizes
  485. do
  486. {
  487. newSF = newSF.GetNextLarger();
  488. this.ScaleFactor = newSF;
  489. --countdown;
  490. } while (this.ScaleFactor == oldSF && countdown > 0);
  491. this.DocumentCenterPointF = centerPt;
  492. }
  493. public virtual void ZoomOut(double factor)
  494. {
  495. Do.TryBool(() => ZoomOutImpl(factor));
  496. }
  497. private void ZoomOutImpl(double factor)
  498. {
  499. PointF centerPt = this.DocumentCenterPointF;
  500. ScaleFactor oldSF = this.ScaleFactor;
  501. ScaleFactor newSF = this.ScaleFactor;
  502. int countdown = 3;
  503. // At a minimum we want to decrease the size of visible document by 1 pixel (without dividing by zero of course)
  504. // Figure out what the ratio of ourSize : ourSize-1 is, and start out with that
  505. double zoomOutEps = GetZoomOutFactorEpsilon();
  506. double factorRecip = 1.0 / factor;
  507. double desiredFactor = Math.Min(factorRecip, zoomOutEps);
  508. double newFactor = desiredFactor;
  509. // Keep setting the ScaleFactor until it actually 'sticks'
  510. // Important for certain image sizes where not all zoom levels create distinct
  511. // screen sizes
  512. do
  513. {
  514. newSF = ScaleFactor.FromDouble(newSF.Ratio * newFactor);
  515. this.ScaleFactor = newSF;
  516. --countdown;
  517. newFactor *= 0.9;
  518. } while (this.ScaleFactor == oldSF && countdown > 0);
  519. this.DocumentCenterPointF = centerPt;
  520. }
  521. public virtual void ZoomOut()
  522. {
  523. Do.TryBool(ZoomOutImpl);
  524. }
  525. private void ZoomOutImpl()
  526. {
  527. PointF centerPt = this.DocumentCenterPointF;
  528. ScaleFactor oldSF = this.ScaleFactor;
  529. ScaleFactor newSF = this.ScaleFactor;
  530. int countdown = ScaleFactor.PresetValues.Length;
  531. // Keep setting the ScaleFactor until it actually 'sticks'
  532. // Important for certain image sizes where not all zoom levels create distinct
  533. // screen sizes
  534. do
  535. {
  536. newSF = newSF.GetNextSmaller();
  537. this.ScaleFactor = newSF;
  538. --countdown;
  539. } while (this.ScaleFactor == oldSF && countdown > 0);
  540. this.DocumentCenterPointF = centerPt;
  541. }
  542. [Browsable(false)]
  543. public ScaleFactor ScaleFactor
  544. {
  545. get
  546. {
  547. return this.scaleFactor;
  548. }
  549. set
  550. {
  551. UI.SuspendControlPainting(this);
  552. ScaleFactor newValue = ScaleFactor.Min(value, ScaleFactor.MaxValue);
  553. if (newValue == this.scaleFactor &&
  554. this.scaleFactor == ScaleFactor.OneToOne)
  555. {
  556. // this space intentionally left blank
  557. }
  558. else
  559. {
  560. //RectangleF visibleRect = this.VisibleDocumentRectangleF;
  561. //ScaleFactor oldSF = scaleFactor;
  562. scaleFactor = newValue;
  563. //// This value is used later below to re-center the document on screen
  564. //PointF centerPt = new PointF(visibleRect.X + visibleRect.Width / 2,
  565. // visibleRect.Y + visibleRect.Height / 2);
  566. if (compositionSurface != null)
  567. {
  568. Rectangle rc = this.panel.ClientRectangle;
  569. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  570. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  571. if (rc.Width < width || rc.Height < height)
  572. this.panel.AutoScrollMinSize = new Size((int)((this.compositionSurface.StitchWidth) * scaleFactor.Ratio) + offsetW, (int)((this.compositionSurface.StitchHeight) * scaleFactor.Ratio) + offsetH);
  573. else
  574. this.panel.AutoScrollMinSize = new Size((int)((this.compositionSurface.StitchWidth) * scaleFactor.Ratio), (int)((this.compositionSurface.StitchHeight) * scaleFactor.Ratio));
  575. this.panel.ScaleFactor = this.scaleFactor;
  576. }
  577. //// re center ourself
  578. //RectangleF visibleRect2 = this.VisibleDocumentRectangleF;
  579. //RecenterView(centerPt);
  580. }
  581. this.OnResize(EventArgs.Empty);
  582. this.OnScaleFactorChanged();
  583. if (compositionSurface != null)
  584. this.rendererList.DestinationSize = this.scaleFactor.ScaleSize(compositionSurface.Size);
  585. UI.ResumeControlPainting(this);
  586. Invalidate(true);
  587. }
  588. }
  589. /// <summary>
  590. /// Returns a rectangle for the bounding rectangle of what is currently visible on screen,
  591. /// in document coordinates.
  592. /// </summary>
  593. [Browsable(false)]
  594. public RectangleF VisibleDocumentRectangleF
  595. {
  596. get
  597. {
  598. Rectangle panelRect = this.panel.RectangleToScreen(this.panel.ClientRectangle); // screen coords coords
  599. Rectangle docScreenRect = panelRect; // screen coords
  600. Rectangle docClientRect = RectangleToClient(docScreenRect);
  601. RectangleF docDocRectF = ClientToDocument(docClientRect);
  602. return docDocRectF;
  603. }
  604. }
  605. public Rectangle PanelClientRectangle
  606. {
  607. get
  608. {
  609. return panel.ClientRectangle;
  610. }
  611. }
  612. public int SurfaceScrollableWidth
  613. {
  614. get
  615. {
  616. return (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  617. }
  618. }
  619. public int SurfaceScrollableHeight
  620. {
  621. get
  622. {
  623. return (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  624. }
  625. }
  626. public double ScaleRatio
  627. {
  628. get
  629. {
  630. return this.scaleFactor.Ratio;
  631. }
  632. }
  633. /// <summary>
  634. /// Returns a rectangle in <b>screen</b> coordinates that represents the space taken up
  635. /// by the document that is visible on screen.
  636. /// </summary>
  637. [Browsable(false)]
  638. public Rectangle VisibleDocumentBounds
  639. {
  640. get
  641. {
  642. // convert coordinates: document -> client -> screen
  643. return RectangleToScreen(Utility.RoundRectangle(DocumentToClient(VisibleDocumentRectangleF)));
  644. }
  645. }
  646. public Rectangle ClientRectangleMax
  647. {
  648. get
  649. {
  650. return RectangleToClient(this.panel.RectangleToScreen(this.panel.Bounds));
  651. }
  652. }
  653. /// <summary>
  654. /// Gets or sets the Document that is shown through this instance of DocumentStitchView.
  655. /// </summary>
  656. /// <remarks>
  657. /// This property is thread safe and may be called from a non-UI thread. However,
  658. /// if the setter is called from a non-UI thread, then that thread will block as
  659. /// the call is marshaled to the UI thread.
  660. /// </remarks>
  661. [Browsable(false)]
  662. public StitchDocument StitchDocument
  663. {
  664. get
  665. {
  666. return document;
  667. }
  668. set
  669. {
  670. if (InvokeRequired)
  671. {
  672. this.Invoke(new Procedure<StitchDocument, bool>(DocumentSetImpl), new object[2] { value, true });
  673. }
  674. else
  675. {
  676. DocumentSetImpl(value, true);
  677. }
  678. }
  679. }
  680. private void DocumentSetImpl(StitchDocument value, bool toedit)
  681. {
  682. this.DoubleBuffered = true;
  683. SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
  684. PointF dspf = DocumentScrollPositionF;
  685. try
  686. {
  687. if (this.document != null)
  688. {
  689. this.document.Invalidated -= Document_Invalidated;
  690. }
  691. this.document = value;
  692. if (document != null)
  693. {
  694. if (this.compositionSurface != null &&
  695. this.compositionSurface.Size != document.Size)
  696. {
  697. this.compositionSurface.Dispose();
  698. this.compositionSurface = null;
  699. }
  700. //if (this.compositionSurface == null)
  701. //{
  702. //this.compositionSurface = new StitchSurface(Document.Size);
  703. this.compositionSurface = document.surface;//((BitmapLayer)(document.Layers[0])).Surface;
  704. this.baseRenderer.Source = document.surface; //((BitmapLayer)(document.Layers[0])).Surface;
  705. if (this.compositionSurface != null)
  706. {
  707. // Maintain the scalefactor
  708. /*this.Size = this.scaleFactor.ScaleSize(compositionSurface.Size);*/
  709. this.rendererList.SourceSize = this.compositionSurface.Size;
  710. this.rendererList.DestinationSize = this.Size;
  711. }
  712. this.document.Invalidated += Document_Invalidated;
  713. }
  714. Invalidate(true);
  715. this.OnResize(EventArgs.Empty);
  716. }
  717. finally
  718. {
  719. }
  720. DocumentScrollPositionF = dspf;
  721. }
  722. public bool PanelAutoScroll
  723. {
  724. get
  725. {
  726. return panel.AutoScroll;
  727. }
  728. set
  729. {
  730. if (panel.AutoScroll != value)
  731. {
  732. panel.AutoScroll = value;
  733. }
  734. }
  735. }
  736. public DrawToolType ActiveTool
  737. {
  738. get => _activeTool;
  739. set
  740. {
  741. if (!tools.ContainsKey(value)) return;
  742. tools[_activeTool].InvokeMember("beginWithNewObject",
  743. BindingFlags.Public |
  744. BindingFlags.Static |
  745. BindingFlags.InvokeMethod,
  746. null,
  747. null,
  748. new object[0] { });
  749. _activeTool = value;
  750. }
  751. }
  752. public GraphicsList GraphicsList
  753. {
  754. get
  755. {
  756. return graphicsList;
  757. }
  758. set
  759. {
  760. graphicsList = value;
  761. if (this.GraphicsList != null)
  762. {
  763. this.Invalidate();
  764. }
  765. }
  766. }
  767. public bool DrawRectangleFlag
  768. {
  769. get
  770. {
  771. return this.drawRectangle;
  772. }
  773. set
  774. {
  775. this.drawRectangle = value;
  776. }
  777. }
  778. public Rectangle DrawRectangle
  779. {
  780. get
  781. {
  782. return this.rectangle;
  783. }
  784. set
  785. {
  786. this.rectangle = value;
  787. }
  788. }
  789. public bool ViewMoveOnMouseLeftDoubleClickEnable { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  790. public int ToolNumber { set => throw new NotImplementedException(); }
  791. public LabelStyleModel.DrawAnalysisModel AnalysisStyleModel { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  792. private void DoLayout()
  793. {
  794. this.UpdateImgLocation();
  795. }
  796. private void Document_Invalidated(object sender, InvalidateEventArgs e)
  797. {
  798. if (this.ScaleFactor == ScaleFactor.OneToOne)
  799. {
  800. this.panel.Invalidate(e.InvalidRect);
  801. }
  802. else
  803. {
  804. Rectangle inflatedInvalidRect = Rectangle.Inflate(e.InvalidRect, 1, 1);
  805. Rectangle clientRect = this.panel.SurfaceToClient(inflatedInvalidRect);
  806. Rectangle inflatedClientRect = Rectangle.Inflate(clientRect, 1, 1);
  807. this.panel.Invalidate(inflatedClientRect);
  808. }
  809. }
  810. ///// <summary>
  811. ///// 重新设置中心点
  812. ///// </summary>
  813. ///// <param name="newCenter"></param>
  814. //public void RecenterView(PointF newCenter)
  815. //{
  816. // RectangleF visibleRect = VisibleDocumentRectangleF;
  817. // PointF cornerPt = new PointF(
  818. // newCenter.X - (visibleRect.Width / 2),
  819. // newCenter.Y - (visibleRect.Height / 2));
  820. // this.DocumentScrollPositionF = cornerPt;
  821. //}
  822. #region DocimentView的子控件的事件
  823. private void Panel_KeyDown(object sender, KeyEventArgs e)
  824. {
  825. if (!e.Handled)
  826. {
  827. PointF oldPt = this.DocumentScrollPositionF;
  828. PointF newPt = oldPt;
  829. RectangleF vdr = VisibleDocumentRectangleF;
  830. switch (e.KeyData)
  831. {
  832. case Keys.Next:
  833. newPt.Y += vdr.Height;
  834. break;
  835. case (Keys.Next | Keys.Shift):
  836. newPt.X += vdr.Width;
  837. break;
  838. case Keys.Prior:
  839. newPt.Y -= vdr.Height;
  840. break;
  841. case (Keys.Prior | Keys.Shift):
  842. newPt.X -= vdr.Width;
  843. break;
  844. case Keys.Home:
  845. if (oldPt.X == 0)
  846. {
  847. newPt.Y = 0;
  848. }
  849. else
  850. {
  851. newPt.X = 0;
  852. }
  853. break;
  854. case Keys.End:
  855. if (vdr.Right < this.document.Width - 1)
  856. {
  857. newPt.X = this.document.Width;
  858. }
  859. else
  860. {
  861. newPt.Y = this.document.Height;
  862. }
  863. break;
  864. default:
  865. break;
  866. }
  867. if (newPt != oldPt)
  868. {
  869. DocumentScrollPositionF = newPt;
  870. e.Handled = true;
  871. }
  872. }
  873. }
  874. private void Panel_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
  875. {
  876. OnScroll(e);
  877. }
  878. /// <summary>
  879. /// 鼠标按下事件
  880. /// </summary>
  881. /// <param name="sender"></param>
  882. /// <param name="e"></param>
  883. protected virtual void MouseEvent_Down(object sender, MouseEventArgs e)
  884. {
  885. if (tools != null)
  886. {
  887. //tools[activeTool].OnMouseDown(this, e);
  888. tools[_activeTool].InvokeMember("OnMouseDown",
  889. BindingFlags.Public |
  890. BindingFlags.Static |
  891. BindingFlags.InvokeMethod,
  892. null,
  893. null,
  894. new object[2] { this, e });
  895. }
  896. }
  897. public void MouseEvent_Del(object sender, MouseEventArgs e)
  898. {
  899. try
  900. {
  901. tools[_activeTool].InvokeMember("beginWithNewObject",
  902. BindingFlags.Public |
  903. BindingFlags.Static |
  904. BindingFlags.InvokeMethod,
  905. null,
  906. null,
  907. new object[0] { });
  908. tools[0].InvokeMember("OnDelKeyDown",
  909. BindingFlags.Public |
  910. BindingFlags.Static |
  911. BindingFlags.InvokeMethod,
  912. null,
  913. null,
  914. new object[2] { this, e });
  915. }
  916. catch
  917. {
  918. }
  919. }
  920. /// <summary>
  921. /// 鼠标移动事件
  922. /// </summary>
  923. /// <param name="sender"></param>
  924. /// <param name="e"></param>
  925. protected virtual void MouseEvent_Move(object sender, MouseEventArgs e)
  926. {
  927. //
  928. // 处理标注测量
  929. //
  930. if (!initialized)
  931. return;
  932. if (e.Button == MouseButtons.Left || e.Button == MouseButtons.None)
  933. if (tools != null)
  934. {
  935. tools[_activeTool].InvokeMember("OnMouseMove",
  936. BindingFlags.Public |
  937. BindingFlags.Static |
  938. BindingFlags.InvokeMethod,
  939. null,
  940. null,
  941. new object[2] { this, e });
  942. }
  943. else
  944. this.Cursor = Cursors.Default;
  945. }
  946. /// <summary>
  947. /// 鼠标抬起事件
  948. /// </summary>
  949. /// <param name="sender"></param>
  950. /// <param name="e"></param>
  951. private void MouseEvent_Up(object sender, MouseEventArgs e)
  952. {
  953. if (tools != null)
  954. {
  955. if (e.Button == MouseButtons.Left)
  956. tools[_activeTool].InvokeMember("OnMouseUp",
  957. BindingFlags.Public |
  958. BindingFlags.Static |
  959. BindingFlags.InvokeMethod,
  960. null,
  961. null,
  962. new object[2] { this, e });
  963. }
  964. }
  965. /// <summary>
  966. /// 鼠标单击事件
  967. /// </summary>
  968. /// <param name="sender"></param>
  969. /// <param name="e"></param>
  970. private void MouseEvent_Click(object sender, MouseEventArgs e)
  971. {
  972. if (tools != null)
  973. {
  974. tools[_activeTool].InvokeMember("OnMouseClick",
  975. BindingFlags.Public |
  976. BindingFlags.Static |
  977. BindingFlags.InvokeMethod,
  978. null,
  979. null,
  980. new object[2] { this, e });
  981. }
  982. }
  983. /// 绘制事件
  984. /// </summary>
  985. /// <param name="sender"></param>
  986. /// <param name="e"></param>
  987. private unsafe void panelPaint(object sender, PaintEventArgs e)
  988. {
  989. if (compositionSurface != null)
  990. {
  991. // 以下是计算绘制图片的位置和大小并绘制图片
  992. Rectangle rc = this.panel.ClientRectangle;
  993. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  994. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  995. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  996. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  997. //第四个版本,只绘制当前需要显示的大小的图片
  998. //if (this.compositionSurface.Bitmap != null)
  999. if (this.compositionSurface.CreateAliasedBitmap() != null)
  1000. {
  1001. using (StitchSurface doubleBuffer = GetDoubleBuffer(new Size((rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height)))
  1002. {
  1003. try
  1004. {
  1005. using (StitchRenderArgs renderArgs = new StitchRenderArgs(doubleBuffer))
  1006. {
  1007. DrawArea(renderArgs, new Point((rc.Width < width) ? -x : 0, (rc.Height < height) ? -y : 0));
  1008. if (m_center)
  1009. {
  1010. e.Graphics.DrawImage(doubleBuffer.CreateAliasedBitmap(),
  1011. (rc.Width < width) ? 0 : (rc.Width - width) / 2,
  1012. (rc.Height < height) ? 0 : (rc.Height - height) / 2,
  1013. (rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height);
  1014. }
  1015. else
  1016. {
  1017. e.Graphics.DrawImage(doubleBuffer.CreateAliasedBitmap(),
  1018. m_pLeft,
  1019. m_pTop,
  1020. (rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height);
  1021. }
  1022. }
  1023. }
  1024. catch { }
  1025. }
  1026. }
  1027. //
  1028. // 以下是绘制网格、标注、测量、视场等开始
  1029. //
  1030. e.Graphics.TranslateTransform(x, y);
  1031. e.Graphics.ScaleTransform((float)this.scaleFactor.Ratio, (float)this.scaleFactor.Ratio);
  1032. //
  1033. // 以下是绘制标注、测量、视场
  1034. //
  1035. if (graphicsList != null)
  1036. {
  1037. var drawObject = graphicsList[0];
  1038. if (!(drawObject is MeasureRectangle))
  1039. { }//graphicsList.Draw(e.Graphics);
  1040. else//pen.DashStyle = DashStyle.Solid;
  1041. e.Graphics.DrawRectangle(new Pen(Color.Green, 14), drawObject.Rectangle.X, drawObject.Rectangle.Y, drawObject.Rectangle.Width, drawObject.Rectangle.Height);
  1042. }
  1043. e.Graphics.ScaleTransform(1 / (float)this.scaleFactor.Ratio, 1 / (float)this.scaleFactor.Ratio);
  1044. e.Graphics.TranslateTransform(-x, -y);
  1045. }
  1046. }
  1047. #endregion
  1048. ///// <summary>
  1049. ///// 获取panel可见位置的图片
  1050. ///// </summary>
  1051. ///// <returns></returns>
  1052. //public Bitmap GetClientRangePic()
  1053. //{
  1054. #region DocumentStitchView的事件
  1055. protected override void OnLayout(LayoutEventArgs e)
  1056. {
  1057. DoLayout();
  1058. base.OnLayout(e);
  1059. }
  1060. /// <summary>
  1061. /// 让画布获取焦点
  1062. /// </summary>
  1063. public new void Focus()
  1064. {
  1065. this.panel.Focus();
  1066. }
  1067. protected override void OnResize(EventArgs e)
  1068. {
  1069. // enable or disable timer: no sense drawing selection if we're minimized
  1070. Form parentForm = ParentForm;
  1071. if (parentForm != null)
  1072. {
  1073. if (parentForm.WindowState != this.oldWindowState)
  1074. {
  1075. PerformLayout();
  1076. }
  1077. this.oldWindowState = parentForm.WindowState;
  1078. }
  1079. base.OnResize(e);
  1080. DoLayout();
  1081. }
  1082. #endregion
  1083. #region 坐标转换相关方法
  1084. public Point MouseToDocument(Control sender, Point mouse)
  1085. {
  1086. Point screenPoint = sender.PointToScreen(mouse);
  1087. Point sbClient = this.panel.PointToClient(screenPoint);
  1088. Point docPoint = Point.Truncate(this.panel.ClientToSurface(sbClient));
  1089. return docPoint;
  1090. }
  1091. /// <summary>
  1092. /// Converts a rectangle from the Windows Forms "client" coordinate space into the Document
  1093. /// coordinate space.
  1094. /// </summary>
  1095. /// <param name="clientPt">A Rectangle that is in client coordinates.</param>
  1096. /// <returns>A Rectangle that is in Document coordinates.</returns>
  1097. public RectangleF ClientToDocument(Rectangle clientRect)
  1098. {
  1099. Rectangle screen = RectangleToScreen(clientRect);
  1100. screen.X = screen.X + offsetW;
  1101. screen.Y = screen.Y + offsetH;
  1102. Rectangle sbClient = this.panel.RectangleToClient(screen);
  1103. return this.panel.ClientToSurface((RectangleF)sbClient);
  1104. }
  1105. /// <summary>
  1106. /// Converts a rectangle from Document coordinate space into the Windows Forms "client"
  1107. /// coordinate space.
  1108. /// </summary>
  1109. /// <param name="clientPt">A Rectangle that is in Document coordinates.</param>
  1110. /// <returns>A Rectangle that is in client coordinates.</returns>
  1111. public RectangleF DocumentToClient(RectangleF documentRect)
  1112. {
  1113. RectangleF sbClient = this.panel.SurfaceToClient(documentRect);
  1114. Rectangle screen = this.panel.RectangleToScreen(Utility.RoundRectangle(sbClient));
  1115. return RectangleToClient(screen);
  1116. }
  1117. public Rectangle SurfaceToClient(Rectangle surfaceRect)
  1118. {
  1119. return new Rectangle(SurfaceToClient(surfaceRect.Location), SurfaceToClient(surfaceRect.Size));
  1120. }
  1121. public Point SurfaceToClient(Point surfacePt)
  1122. {
  1123. return ScaleFactor.ScalePoint(surfacePt);
  1124. }
  1125. public Size SurfaceToClient(Size surfaceSize)
  1126. {
  1127. return Size.Round(SurfaceToClient((SizeF)surfaceSize));
  1128. }
  1129. public SizeF SurfaceToClient(SizeF surfaceSize)
  1130. {
  1131. return ScaleFactor.ScaleSize(surfaceSize);
  1132. }
  1133. #endregion
  1134. #region 初始化控件
  1135. private void InitializeComponent()
  1136. {
  1137. this.components = new Container();
  1138. this.panel = new PanelEx();
  1139. this.panel.SuspendLayout();
  1140. this.SuspendLayout();
  1141. //
  1142. // panel
  1143. //
  1144. this.panel.AutoScroll = true;
  1145. this.panel.Dock = DockStyle.Fill;
  1146. this.panel.HideHScroll = false;
  1147. this.panel.HideVScroll = false;
  1148. this.panel.Location = new Point(16, 16);
  1149. this.panel.Name = "panel";
  1150. this.panel.ScrollPosition = new Point(0, 0);
  1151. this.panel.Size = new Size(368, 304);
  1152. this.panel.TabIndex = 5;
  1153. this.panel.AllowDrop = false;
  1154. this.panel.Scroll += new ScrollEventHandler(this.Panel_Scroll);
  1155. this.panel.KeyDown += new KeyEventHandler(Panel_KeyDown);
  1156. //
  1157. // DocumentStitchView
  1158. //
  1159. this.Controls.Add(this.panel);
  1160. this.Name = "DocumentStitchView";
  1161. this.Size = new System.Drawing.Size(384, 320);
  1162. this.panel.ResumeLayout(false);
  1163. this.ResumeLayout(false);
  1164. }
  1165. #endregion
  1166. #region 设定图片位置
  1167. // add by maxb 20200716
  1168. /// <summary>
  1169. /// 图片位置坐标
  1170. /// </summary>
  1171. private bool m_center = true;
  1172. private int m_pTop = 0;
  1173. private int m_pLeft = 0;
  1174. private int m_initTop = 0;
  1175. private int m_initLeft = 0;
  1176. private void UpdateImgLocation()
  1177. {
  1178. if (!m_center)
  1179. {
  1180. //Console.WriteLine("m_pLeft: " + m_initLeft + " Ratio:" + this.scaleFactor.Ratio);
  1181. m_pLeft = 16 + (int)(m_initLeft * this.scaleFactor.Ratio);
  1182. m_pTop = 16 + (int)(m_initTop * this.scaleFactor.Ratio);
  1183. //Console.WriteLine("Location: " + m_pLeft + " " + m_pTop);
  1184. }
  1185. }
  1186. public RectangleF GetVisibleDocumentRectangleF()
  1187. {
  1188. return this.VisibleDocumentRectangleF;
  1189. //return this.AppWorkspaceTop.GetVisibleDocumentRectangleF();
  1190. }
  1191. public SizeF GetDocumentSize()
  1192. {
  1193. if (this.document != null)
  1194. return this.document.Size;
  1195. else
  1196. return new SizeF(0, 0);
  1197. //return this.AppWorkspaceTop.GetDocumentSize();
  1198. }
  1199. public void AddCommandToHistory(Command c)
  1200. {
  1201. throw new NotImplementedException();
  1202. }
  1203. public void SetDirty()
  1204. {
  1205. throw new NotImplementedException();
  1206. }
  1207. /// <summary>
  1208. /// 获取未缩放的坐标点
  1209. /// </summary>
  1210. /// <param name="point"></param>
  1211. /// <returns></returns>
  1212. public Point GetScalePoint(PointF point)
  1213. {
  1214. Rectangle rc = this.panel.ClientRectangle;
  1215. int width = this.compositionSurface == null ? 800 : (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  1216. int height = this.compositionSurface == null ? 600 : (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  1217. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  1218. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  1219. return new Point(
  1220. (int)((point.X - x) / this.scaleFactor.Ratio),
  1221. (int)((point.Y - y) / this.scaleFactor.Ratio)
  1222. );
  1223. //return this.scaleFactor.UnscalePoint(location);
  1224. }
  1225. public Point GetCalcOriginPoint()
  1226. {
  1227. throw new NotImplementedException();
  1228. }
  1229. public int UnscaleScalar(int deltaX)
  1230. {
  1231. throw new NotImplementedException();
  1232. }
  1233. public PointF GetDocumentScrollPositionF()
  1234. {
  1235. return this.DocumentScrollPositionF;
  1236. //return this.AppWorkspaceTop.GetDocumentScrollPositionF();
  1237. }
  1238. public void SetDocumentScrollPositionF(PointF newScrollPos)
  1239. {
  1240. Point sbClient = Point.Round(newScrollPos);
  1241. if (this.panel.AutoScrollPosition != new Point(-sbClient.X, -sbClient.Y))
  1242. {
  1243. this.panel.AutoScrollPosition = sbClient;
  1244. }
  1245. }
  1246. public PointF DocumentToClient(PointF pointF)
  1247. {
  1248. throw new NotImplementedException();
  1249. }
  1250. public string[] GetPxPerUnit()
  1251. {
  1252. throw new NotImplementedException();
  1253. }
  1254. public Dictionary<int, string> GetUnitsDictionary()
  1255. {
  1256. throw new NotImplementedException();
  1257. }
  1258. public Dictionary<int, string> GetUnitSymbolsDictionary()
  1259. {
  1260. throw new NotImplementedException();
  1261. }
  1262. public CombineMode GetCombineMode()
  1263. {
  1264. throw new NotImplementedException();
  1265. }
  1266. public void SetMouseStatus(bool status)
  1267. {
  1268. throw new NotImplementedException();
  1269. }
  1270. public bool GetMouseStatus()
  1271. {
  1272. throw new NotImplementedException();
  1273. }
  1274. public Dictionary<DrawToolType, Type> GetTools()
  1275. {
  1276. throw new NotImplementedException();
  1277. }
  1278. public bool ContinuousDrawingLabel()
  1279. {
  1280. throw new NotImplementedException();
  1281. }
  1282. public void SetContinuousDrawingLabel(bool v)
  1283. {
  1284. throw new NotImplementedException();
  1285. }
  1286. public bool ContinuousDrawingMeasure()
  1287. {
  1288. throw new NotImplementedException();
  1289. }
  1290. public void SetContinuousDrawingMeasure(bool v)
  1291. {
  1292. throw new NotImplementedException();
  1293. }
  1294. public void ResetUndoManager()
  1295. {
  1296. throw new NotImplementedException();
  1297. }
  1298. public LabelStyleModel GetLabelStyleModel()
  1299. {
  1300. throw new NotImplementedException();
  1301. }
  1302. public MeasureStyleModel GetMeasureStyleModel()
  1303. {
  1304. return new MeasureStyleModel();// throw new NotImplementedException();
  1305. }
  1306. public WatermarkModel GetWatermarkModel()
  1307. {
  1308. throw new NotImplementedException();
  1309. }
  1310. public WorkTypeStyleModel GetWorkTypeStyleModel()
  1311. {
  1312. throw new NotImplementedException();
  1313. }
  1314. public RulerModel GetRulerStyleModel()
  1315. {
  1316. throw new NotImplementedException();
  1317. }
  1318. public Dictionary<MeasurementUnit, double> getMeasureInfo()
  1319. {
  1320. throw new NotImplementedException();
  1321. }
  1322. public MeasurementUnit GetMeasurementUnit()
  1323. {
  1324. throw new NotImplementedException();
  1325. }
  1326. public decimal GetGainMultiple()
  1327. {
  1328. throw new NotImplementedException();
  1329. }
  1330. public decimal GetMic_Rulers()
  1331. {
  1332. throw new NotImplementedException();
  1333. }
  1334. public void RefreshLabelListDialog()
  1335. {
  1336. throw new NotImplementedException();
  1337. }
  1338. public void UpdateContinueNum()
  1339. {
  1340. throw new NotImplementedException();
  1341. }
  1342. public bool ContinuousBinaryAction()
  1343. {
  1344. throw new NotImplementedException();
  1345. }
  1346. public void BinaryActionExtract(PointF point)
  1347. {
  1348. throw new NotImplementedException();
  1349. }
  1350. public void BinaryActionChoise(PointF point)
  1351. {
  1352. throw new NotImplementedException();
  1353. }
  1354. public void BinaryActionChoiseRectangle(RectangleF rectangle)
  1355. {
  1356. throw new NotImplementedException();
  1357. }
  1358. public void BinaryActionChoiseOval(RectangleF rectangle)
  1359. {
  1360. throw new NotImplementedException();
  1361. }
  1362. public void BinaryActionChoisePolygon(List<PointF> points)
  1363. {
  1364. throw new NotImplementedException();
  1365. }
  1366. public int GetSegmentationWidth()
  1367. {
  1368. throw new NotImplementedException();
  1369. }
  1370. public void BinaryActionSplitLine(PointF start, PointF end)
  1371. {
  1372. throw new NotImplementedException();
  1373. }
  1374. public void BinaryActionSplitOval(RectangleF rect)
  1375. {
  1376. throw new NotImplementedException();
  1377. }
  1378. public int GetConnectionWidth()
  1379. {
  1380. throw new NotImplementedException();
  1381. }
  1382. public void BinaryActionConnectionLine(PointF start, PointF end)
  1383. {
  1384. throw new NotImplementedException();
  1385. }
  1386. public void BinaryConnectionOval(RectangleF rect)
  1387. {
  1388. throw new NotImplementedException();
  1389. }
  1390. public void BinaryActionDelete(PointF point)
  1391. {
  1392. throw new NotImplementedException();
  1393. }
  1394. public void BinaryActionDelete(RectangleF rect)
  1395. {
  1396. throw new NotImplementedException();
  1397. }
  1398. public void BinaryActionDelete(List<PointF> points)
  1399. {
  1400. throw new NotImplementedException();
  1401. }
  1402. public void BinaryActionDeleteOval(RectangleF rect)
  1403. {
  1404. throw new NotImplementedException();
  1405. }
  1406. public void BinaryActionAddOval(RectangleF rect)
  1407. {
  1408. throw new NotImplementedException();
  1409. }
  1410. public void BinaryActionAddRectangle(RectangleF rect)
  1411. {
  1412. throw new NotImplementedException();
  1413. }
  1414. public void BinaryActionAddPolygon(List<PointF> points)
  1415. {
  1416. throw new NotImplementedException();
  1417. }
  1418. public void PPhaseActionRectangle(RectangleF rect)
  1419. {
  1420. throw new NotImplementedException();
  1421. }
  1422. public void PPhaseActionPolygon(List<PointF> points)
  1423. {
  1424. throw new NotImplementedException();
  1425. }
  1426. public void PPhaseActionOval(RectangleF rect)
  1427. {
  1428. throw new NotImplementedException();
  1429. }
  1430. public PointF GetRulerPointInPanel(PointF point)
  1431. {
  1432. throw new NotImplementedException();
  1433. }
  1434. public PointF ScalePointToRulerPoint(PointF point)
  1435. {
  1436. throw new NotImplementedException();
  1437. }
  1438. public bool ActualSize()
  1439. {
  1440. throw new NotImplementedException();
  1441. }
  1442. public bool SuitableSize()
  1443. {
  1444. throw new NotImplementedException();
  1445. }
  1446. public bool SuitableWidth()
  1447. {
  1448. throw new NotImplementedException();
  1449. }
  1450. public bool SuitableHeight()
  1451. {
  1452. throw new NotImplementedException();
  1453. }
  1454. public bool LockZoom()
  1455. {
  1456. throw new NotImplementedException();
  1457. }
  1458. public bool FixedMultiple()
  1459. {
  1460. throw new NotImplementedException();
  1461. }
  1462. public bool MergeFieldOfView()
  1463. {
  1464. throw new NotImplementedException();
  1465. }
  1466. public bool DeleteFieldOfView()
  1467. {
  1468. throw new NotImplementedException();
  1469. }
  1470. public Inclusion GetInclusion()
  1471. {
  1472. throw new NotImplementedException();
  1473. }
  1474. #endregion
  1475. }
  1476. }