DocumentView.cs 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375
  1. using Resources;
  2. using SmartCoalApplication.Annotation;
  3. using SmartCoalApplication.Annotation.Command;
  4. using SmartCoalApplication.Annotation.Enum;
  5. using SmartCoalApplication.Annotation.FieldView;
  6. using SmartCoalApplication.Annotation.Label;
  7. using SmartCoalApplication.Annotation.Measure;
  8. using SmartCoalApplication.Annotation.Other;
  9. using SmartCoalApplication.Base;
  10. using SmartCoalApplication.Base.Enum;
  11. using SmartCoalApplication.Base.SettingModel;
  12. using SmartCoalApplication.Core.DbOpreate.DbModel;
  13. using SmartCoalApplication.Core.Threading;
  14. using SmartCoalApplication.SystemLayer;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.ComponentModel;
  18. using System.Drawing;
  19. using System.Drawing.Drawing2D;
  20. using System.Linq;
  21. using System.Reflection;
  22. using System.Text;
  23. using System.Threading;
  24. using System.Windows.Forms;
  25. namespace SmartCoalApplication.Core
  26. {
  27. public class DocumentView : UserControl,ISurfaceBox, DocumentDirtyObserver
  28. {
  29. #region 控件
  30. /// <summary>
  31. /// 【标注、测量、视场、其它】当前激活的工具
  32. /// </summary>
  33. public DrawToolType activeTool;
  34. /// <summary>
  35. /// 【标注、测量】用于保存测量、标注等的历史记录,用于撤销
  36. /// </summary>
  37. public UndoManager undoManager;
  38. /// <summary>
  39. /// 【标注、测量】list of draw objects
  40. /// </summary>
  41. private GraphicsList graphicsList;
  42. private IContainer components = null;
  43. /// <summary>
  44. /// 左侧刻度标尺
  45. /// </summary>
  46. public Ruler leftRuler;
  47. /// <summary>
  48. /// 中心画布
  49. /// </summary>
  50. public PanelEx panel;
  51. /// <summary>
  52. /// 顶部刻度标尺
  53. /// </summary>
  54. public Ruler topRuler;
  55. /// <summary>
  56. /// 右键菜单
  57. /// </summary>
  58. private ContextMenuStrip contextMenuStrip1;
  59. private ToolStripMenuItem toolStripMenuItem1;
  60. private ToolStripMenuItem toolStripMenuItem2;
  61. private ToolStripMenuItem toolStripMenuItem3;
  62. private ToolStripMenuItem toolStripMenuItem4;
  63. #endregion
  64. private bool raiseFirstInputAfterGotFocus = false;
  65. private int refreshSuspended = 0;
  66. private bool hookedMouseEvents = false;
  67. public bool previewMeasure = false;
  68. private static Base.WeakReference<Surface> doubleBufferSurfaceWeakRef = null;
  69. private Surface doubleBufferSurface = null;
  70. /// <summary>
  71. /// 绘制线程
  72. /// </summary>
  73. private Threading.ThreadPool threadPool = new Threading.ThreadPool();
  74. private RenderContext renderContext;
  75. /// <summary>
  76. /// 换算完的标尺信息,包含所有系统内得单位
  77. /// </summary>
  78. public Dictionary<MeasurementUnit, double> rules = new Dictionary<MeasurementUnit, double>();
  79. public mic_rulers xmlSaveModel;//存储标尺信息(xml或者预览拍摄选中标尺)
  80. public bool existenceXML = false;//当前图片是否存在对应的xml
  81. /// <summary>
  82. /// AppWorkspace接口
  83. /// </summary>
  84. private IAppWorkspaceForSurfaceBox appWorkspace;
  85. /// <summary>
  86. /// 辅助线的横线和竖线
  87. /// </summary>
  88. GraphicsPath path, path1;
  89. /// <summary>
  90. /// 初始化标记
  91. /// </summary>
  92. private bool initialized;
  93. public bool auxiliaryLineEnabled = false;
  94. /// <summary>
  95. /// 为了保证图片绘制在画布中心
  96. /// 设置的偏移量
  97. /// </summary>
  98. private int offsetW = 0;
  99. private int offsetH = 0;
  100. private int offsetHalfW = 0;
  101. private int offsetHalfH = 0;
  102. /// <summary>
  103. /// 满屏网格是否显示,默认不显示
  104. /// </summary>
  105. private bool gridLineFullEnabled = false;
  106. /// <summary>
  107. /// 网格是否显示,默认不显示
  108. /// </summary>
  109. private bool gridLineEnabled = false;
  110. /// <summary>
  111. /// 矩形网格是否显示,默认不显示
  112. /// </summary>
  113. private bool gridRectangleEnabled = false;
  114. /// <summary>
  115. /// 圆形网格是否显示,默认不显示
  116. /// </summary>
  117. private bool gridRoundEnabled = false;
  118. /// <summary>
  119. /// 十字线是否显示,默认不显示
  120. /// </summary>
  121. private bool gridCrossCurveEnabled = false;
  122. /// <summary>
  123. /// 视图标尺是否显示,默认显示
  124. /// </summary>
  125. private bool rulersEnabled = false;
  126. /// <summary>
  127. /// 标记连续绘制
  128. /// </summary>
  129. private bool continuousDrawingLabel = false;
  130. /// <summary>
  131. /// 测量连续绘制
  132. /// </summary>
  133. private bool continuousDrawingMeasure = false;
  134. /// <summary>
  135. /// 视场连续绘制
  136. /// </summary>
  137. private bool continuousDrawingView = false;
  138. /// <summary>
  139. /// 二值提取\连续操作
  140. /// </summary>
  141. private bool continuousBinaryAction = false;
  142. /// <summary>
  143. /// 实际大小标记
  144. /// </summary>
  145. private bool actualsize = false;
  146. /// <summary>
  147. /// 合适大小标记
  148. /// </summary>
  149. private bool suitableSize = false;
  150. /// <summary>
  151. /// 合适高度标记
  152. /// </summary>
  153. private bool suitableHeight = false;
  154. /// <summary>
  155. /// 合适宽度标记
  156. /// </summary>
  157. private bool suitableWidth = false;
  158. /// <summary>
  159. /// 锁定扩缩
  160. /// </summary>
  161. private bool lockZoom = false;
  162. /// <summary>
  163. /// 定倍显示
  164. /// </summary>
  165. private bool fixedMultiple = false;
  166. /// <summary>
  167. /// 合并视场
  168. /// </summary>
  169. private bool mergeFieldOfView = false;
  170. /// <summary>
  171. /// 删除视场
  172. /// </summary>
  173. private bool deleteFieldOfView = false;
  174. /// <summary>
  175. /// 图层及文档信息
  176. /// </summary>
  177. private Document document;
  178. /// <summary>
  179. /// 图像内存块及其属性
  180. /// </summary>
  181. private Surface compositionSurface;
  182. ///// <summary>
  183. ///// 【标注、测量】用于保存测量、标注等的历史记录,用于撤销
  184. ///// </summary>
  185. //public UndoManager undoManager;
  186. ///// <summary>
  187. ///// 【标注、测量】list of draw objects
  188. ///// </summary>
  189. //private GraphicsList graphicsList;
  190. ///// <summary>
  191. ///// 【标注、测量、视场、其它】当前激活的工具
  192. ///// </summary>
  193. //public DrawToolType activeTool;
  194. /// <summary>
  195. /// 工具的集合
  196. /// </summary>
  197. public Type[] tools;
  198. /// <summary>
  199. /// 目前用于修改视场,如果是鼠标保持按下的状态,比如按下不抬起状态,
  200. /// 按下拖动状态,则不响应修改视场界面的相应numericUpDown等控件的值变化事件,
  201. /// 以避免事件的冲突
  202. /// </summary>
  203. public bool mouseStatus;
  204. /// <summary>
  205. /// 待渲染的列表
  206. /// </summary>
  207. private SurfaceBoxRendererList rendererList;
  208. private SurfaceBoxBaseRenderer baseRenderer;
  209. /// <summary>
  210. /// 窗体状态
  211. /// </summary>
  212. private FormWindowState oldWindowState = FormWindowState.Minimized;
  213. /// <summary>
  214. /// 缩放比例
  215. /// </summary>
  216. private ScaleFactor scaleFactor = new ScaleFactor(1, 1);
  217. /// <summary>
  218. /// 每像素多少微米
  219. /// </summary>
  220. private double micronRatio;
  221. /// <summary>
  222. /// 是否允许像素跟踪
  223. /// </summary>
  224. public bool pixelTrackingEnabled = true;
  225. /// <summary>
  226. /// 是否允许刷新公共的底部的放大缩小的进度条和值
  227. /// </summary>
  228. public bool refueshZoomTrackValue = true;
  229. private int toolNumber = -1;
  230. /// <summary>
  231. /// 如果是false,则是弹窗的DocumentWorkspaceWindow
  232. /// </summary>
  233. public bool rightDown = true;
  234. /// <summary>
  235. /// ctrl按下事件
  236. /// </summary>
  237. public bool controlPress = false;
  238. /// <summary>
  239. /// 在toolPointer的工具下,是否绘制鼠标划选的矩形
  240. /// </summary>
  241. public bool drawRectangle = false;
  242. /// <summary>
  243. /// 在toolPointer的工具下,鼠标划选的矩形
  244. /// </summary>
  245. public Rectangle rectangle;
  246. /// <summary>
  247. /// 当前的视场行为标记,合并或删除
  248. /// </summary>
  249. private CombineMode combineMode = CombineMode.Union;
  250. public bool keepDraw = true;
  251. /// <summary>
  252. /// 结果页面标尺信息
  253. /// </summary>
  254. public double unitNum = 1;
  255. public string aliasName;
  256. public int decimalPlaces = 2;
  257. #region 直方图操作数据缓存
  258. /// <summary>
  259. /// 亮度
  260. /// </summary>
  261. private double histogramBeta = -0.5;
  262. /// <summary>
  263. /// 对比度
  264. /// </summary>
  265. private double histogramAlpha = 1.0;
  266. /// <summary>
  267. /// gamma值
  268. /// </summary>
  269. private double histogramGamma = 1.0;
  270. /// <summary>
  271. /// 最佳算法的数值,范围0-499
  272. /// </summary>
  273. private int histogramPercent = 200;
  274. /// <summary>
  275. /// 是否选中了log
  276. /// </summary>
  277. private bool histogramLogEnabled;
  278. /// <summary>
  279. /// 是否选中了skip
  280. /// </summary>
  281. private bool histogramSkipEnabled;
  282. public Bitmap BoxBitmap;
  283. /// <summary>
  284. /// 辅助线线条样式
  285. /// </summary>
  286. public int girdLineStyle = 0;
  287. /// <summary>
  288. /// 辅助线颜色
  289. /// </summary>
  290. public int girdLineColour = 1;
  291. /// <summary>
  292. /// 辅助线线宽
  293. /// </summary>
  294. public int girdLineWidth = 5;
  295. #endregion
  296. #region 直方图操作数据缓存
  297. /// <summary>
  298. /// 亮度
  299. /// </summary>
  300. public double HistogramBeta
  301. {
  302. set
  303. {
  304. this.histogramBeta = value;
  305. }
  306. get
  307. {
  308. return this.histogramBeta;
  309. }
  310. }
  311. /// <summary>
  312. /// 对比度
  313. /// </summary>
  314. public double HistogramAlpha
  315. {
  316. set
  317. {
  318. this.histogramAlpha = value;
  319. }
  320. get
  321. {
  322. return this.histogramAlpha;
  323. }
  324. }
  325. public double HistogramGamma
  326. {
  327. set
  328. {
  329. this.histogramGamma = value;
  330. }
  331. get
  332. {
  333. return this.histogramGamma;
  334. }
  335. }
  336. public int HistogramPercent
  337. {
  338. set
  339. {
  340. this.histogramPercent = value;
  341. }
  342. get
  343. {
  344. return this.histogramPercent;
  345. }
  346. }
  347. public bool HistogramLogEnabled
  348. {
  349. set
  350. {
  351. this.histogramLogEnabled = value;
  352. }
  353. get
  354. {
  355. return this.histogramLogEnabled;
  356. }
  357. }
  358. public bool HistogramSkipEnabled
  359. {
  360. set
  361. {
  362. this.histogramSkipEnabled = value;
  363. }
  364. get
  365. {
  366. return this.histogramSkipEnabled;
  367. }
  368. }
  369. #endregion
  370. public DocumentView()
  371. {
  372. InitializeComponent();
  373. this.document = null;
  374. this.compositionSurface = null;
  375. this.panel.ScaleFactor = this.scaleFactor;
  376. this.panel.Paint += new PaintEventHandler(this.panelPaint);
  377. this.panel.MouseMove += new MouseEventHandler(this.MouseEvent_Move);
  378. this.panel.MouseDown += new MouseEventHandler(this.MouseEvent_Down);
  379. this.panel.MouseUp += new MouseEventHandler(this.MouseEvent_Up);
  380. this.panel.MouseClick += new MouseEventHandler(this.MouseEvent_Click);
  381. this.panel.MouseDoubleClick += new MouseEventHandler(this.MouseEvent_DoubleClick);
  382. this.rendererList = new SurfaceBoxRendererList(this.panel.Size, this.panel.Size);
  383. this.rendererList.Invalidated += new InvalidateEventHandler(Renderers_Invalidated);
  384. this.baseRenderer = new SurfaceBoxBaseRenderer(this.rendererList, null);
  385. this.rendererList.Add(this.baseRenderer, false);
  386. this.initialized = true;
  387. }
  388. public OpenCvSharp.Mat OldMat
  389. {
  390. get
  391. {
  392. //备注:待调试->>200827 add by scc
  393. if (this.CompositionSurface != null)
  394. return OpenCvSharp.Extensions.BitmapConverter.ToMat(this.CompositionSurface.Thumborigin/*CreateAliasedBitmap()*/);
  395. else
  396. return null;
  397. }
  398. }
  399. public OpenCvSharp.Mat BoxMat
  400. {
  401. get
  402. {
  403. //备注:待调试
  404. //if (this.AppWorkspace.ActiveDocumentWorkspace != null)
  405. //{
  406. return OpenCvSharp.Extensions.BitmapConverter.ToMat(this.BoxBitmap);
  407. //}
  408. }
  409. }
  410. public Rectangle DrawRectangle
  411. {
  412. get
  413. {
  414. return this.rectangle;
  415. }
  416. set
  417. {
  418. this.rectangle = value;
  419. }
  420. }
  421. public bool DrawRectangleFlag
  422. {
  423. get
  424. {
  425. return this.drawRectangle;
  426. }
  427. set
  428. {
  429. this.drawRectangle = value;
  430. }
  431. }
  432. void AdjustRendering()
  433. {
  434. Size docSize;
  435. if (this.GraphicsList != null)
  436. {
  437. docSize = this.GraphicsList.GetSize();
  438. //AutoScrollMinSize = docSize;
  439. }
  440. else
  441. {
  442. //AutoScrollMinSize = new Size(0, 0);
  443. }
  444. Invalidate();
  445. }
  446. public CombineMode CombineMode
  447. {
  448. get
  449. {
  450. return this.combineMode;
  451. }
  452. set
  453. {
  454. this.combineMode = value;
  455. }
  456. }
  457. public Surface CompositionSurface
  458. {
  459. get
  460. {
  461. return this.compositionSurface;
  462. }
  463. set
  464. {
  465. if (value != null)
  466. {
  467. this.compositionSurface = value;
  468. this.Refresh();
  469. }
  470. }
  471. }
  472. public void ResetBoxBitmap()
  473. {
  474. this.BoxBitmap = this.CompositionSurface.CreateAliasedBitmap();
  475. }
  476. public bool GridLineEnabled
  477. {
  478. get
  479. {
  480. return this.gridLineEnabled;
  481. }
  482. set
  483. {
  484. this.gridLineEnabled = value;
  485. }
  486. }
  487. public bool GridLineFullEnabled
  488. {
  489. get
  490. {
  491. return this.gridLineFullEnabled;
  492. }
  493. set
  494. {
  495. this.gridLineFullEnabled = value;
  496. }
  497. }
  498. public bool GridRectangleEnabled
  499. {
  500. get
  501. {
  502. return this.gridRectangleEnabled;
  503. }
  504. set
  505. {
  506. this.gridRectangleEnabled = value;
  507. }
  508. }
  509. public bool GridRoundEnabled
  510. {
  511. get
  512. {
  513. return this.gridRoundEnabled;
  514. }
  515. set
  516. {
  517. this.gridRoundEnabled = value;
  518. }
  519. }
  520. public bool GridCrossCurveEnabled
  521. {
  522. get
  523. {
  524. return this.gridCrossCurveEnabled;
  525. }
  526. set
  527. {
  528. this.gridCrossCurveEnabled = value;
  529. }
  530. }
  531. public double MicronRatio
  532. {
  533. get
  534. {
  535. return this.micronRatio;
  536. }
  537. set
  538. {
  539. this.micronRatio = value;
  540. }
  541. }
  542. public bool ContinuousDrawingLabel
  543. {
  544. get
  545. {
  546. return continuousDrawingLabel;
  547. }
  548. set
  549. {
  550. this.continuousDrawingLabel = value;
  551. }
  552. }
  553. public bool ContinuousDrawingMeasure
  554. {
  555. get
  556. {
  557. return continuousDrawingMeasure;
  558. }
  559. set
  560. {
  561. this.continuousDrawingMeasure = value;
  562. }
  563. }
  564. public bool ContinuousDrawingView
  565. {
  566. get
  567. {
  568. return continuousDrawingView;
  569. }
  570. set
  571. {
  572. this.continuousDrawingView = value;
  573. }
  574. }
  575. public bool ContinuousBinaryAction
  576. {
  577. get
  578. {
  579. return continuousBinaryAction;
  580. }
  581. set
  582. {
  583. this.continuousBinaryAction = value;
  584. }
  585. }
  586. public bool ActualSize
  587. {
  588. get
  589. {
  590. return actualsize;
  591. }
  592. set
  593. {
  594. this.actualsize = value;
  595. }
  596. }
  597. public bool SuitableSize
  598. {
  599. get
  600. {
  601. return suitableSize;
  602. }
  603. set
  604. {
  605. this.suitableSize = value;
  606. }
  607. }
  608. public bool SuitableWidth
  609. {
  610. get
  611. {
  612. return suitableWidth;
  613. }
  614. set
  615. {
  616. this.suitableWidth = value;
  617. }
  618. }
  619. public bool SuitableHeight
  620. {
  621. get
  622. {
  623. return suitableHeight;
  624. }
  625. set
  626. {
  627. this.suitableHeight = value;
  628. }
  629. }
  630. public bool LockZoom
  631. {
  632. get
  633. {
  634. return lockZoom;
  635. }
  636. set
  637. {
  638. this.lockZoom = value;
  639. }
  640. }
  641. public bool FixedMultiple
  642. {
  643. get
  644. {
  645. return fixedMultiple;
  646. }
  647. set
  648. {
  649. this.fixedMultiple = value;
  650. }
  651. }
  652. public bool MergeFieldOfView
  653. {
  654. get
  655. {
  656. return mergeFieldOfView;
  657. }
  658. set
  659. {
  660. this.mergeFieldOfView = value;
  661. }
  662. }
  663. public bool DeleteFieldOfView
  664. {
  665. get
  666. {
  667. return deleteFieldOfView;
  668. }
  669. set
  670. {
  671. this.deleteFieldOfView = value;
  672. }
  673. }
  674. public bool RulersEnabled
  675. {
  676. get
  677. {
  678. return rulersEnabled;
  679. }
  680. set
  681. {
  682. //if (this.rulersEnabled != value)
  683. {
  684. this.rulersEnabled = value;
  685. if (this.topRuler != null)
  686. {
  687. this.topRuler.Enabled = value;
  688. this.topRuler.Visible = value;
  689. }
  690. if (this.leftRuler != null)
  691. {
  692. this.leftRuler.Enabled = value;
  693. this.leftRuler.Visible = value;
  694. }
  695. this.OnResize(EventArgs.Empty);
  696. OnRulersEnabledChanged();
  697. }
  698. }
  699. }
  700. public SurfaceBoxRendererList RendererList
  701. {
  702. get
  703. {
  704. return this.rendererList;
  705. }
  706. }
  707. public IAppWorkspaceForSurfaceBox AppWorkspaceTop
  708. {
  709. set
  710. {
  711. this.appWorkspace = value;
  712. }
  713. get
  714. {
  715. return this.appWorkspace;
  716. }
  717. }
  718. /// <summary>
  719. /// 初始化工具
  720. /// </summary>
  721. protected void InitToolsAndManager()
  722. {
  723. //TODO 全局判断
  724. activeTool = appWorkspace.GetDrawToolType();
  725. // 创建graphic list
  726. // 一是用于存储,二是用于调整层级
  727. GraphicsList = new GraphicsList(this);
  728. // 创建管理器,用于前进后退
  729. undoManager = new UndoManager(GraphicsList);
  730. // init Tools
  731. //tools = new Tool[(int)DrawToolType.NumberOfDrawTools];
  732. tools = new Type[(int)DrawToolType.NumberOfDrawTools];
  733. tools[(int)DrawToolType.Pointer] = typeof(ToolPointer);
  734. //
  735. //测量
  736. //
  737. tools[(int)DrawToolType.MeasureLine] = typeof(ToolMeasureLine);
  738. tools[(int)DrawToolType.MeasureHLine] = typeof(ToolMeasureHLine);
  739. tools[(int)DrawToolType.MeasureVLine] = typeof(ToolMeasureVLine);
  740. tools[(int)DrawToolType.DrawLine] = typeof(ToolLine);
  741. //
  742. //视场
  743. //
  744. tools[(int)DrawToolType.ViewRectangle] = typeof(ToolViewRectangle);
  745. tools[(int)DrawToolType.MoveMode] = typeof(PanTool);
  746. }
  747. public DrawToolType ActiveTool
  748. {
  749. get => this.activeTool;
  750. set
  751. {
  752. tools[(int)activeTool].InvokeMember("beginWithNewObject",
  753. BindingFlags.Public |
  754. BindingFlags.Static |
  755. BindingFlags.InvokeMethod,
  756. null,
  757. null,
  758. new object[0] { });
  759. //tools[(int)this.activeTool].beginWithNewObject();
  760. this.activeTool = value;
  761. appWorkspace.SetDrawToolType(this.activeTool);
  762. }
  763. }
  764. public GraphicsList GraphicsList
  765. {
  766. get
  767. {
  768. return graphicsList;
  769. }
  770. set
  771. {
  772. graphicsList = value;
  773. if (this.GraphicsList != null)
  774. {
  775. this.AdjustRendering();
  776. //this.graphicsList.AddObserver(this);
  777. }
  778. }
  779. }
  780. /// <summary>
  781. /// 添加到标注测量历史
  782. /// </summary>
  783. /// <param name="c"></param>
  784. public void AddCommandToHistory(Command c)
  785. {
  786. this.undoManager.AddCommandToHistory(c);
  787. }
  788. /// <summary>
  789. /// 初始化标注测量管理
  790. /// </summary>
  791. public void ResetUndoManager()
  792. {
  793. this.undoManager = new UndoManager(this.GraphicsList);
  794. }
  795. public MeasurementUnit Units
  796. {
  797. get
  798. {
  799. return this.leftRuler.MeasurementUnit;
  800. }
  801. set
  802. {
  803. OnUnitsChanging();
  804. this.leftRuler.MeasurementUnit = value;
  805. this.topRuler.MeasurementUnit = value;
  806. DocumentMetaDataChangedHandler(this, EventArgs.Empty);
  807. OnUnitsChanged();
  808. }
  809. }
  810. protected virtual void OnUnitsChanging()
  811. {
  812. }
  813. protected virtual void OnUnitsChanged()
  814. {
  815. }
  816. public bool DrawGrid
  817. {
  818. get
  819. {
  820. return true;
  821. }
  822. set
  823. {
  824. /**
  825. if (this.gridRenderer.Visible != value)
  826. {
  827. this.gridRenderer.Visible = value;
  828. OnDrawGridChanged();
  829. }**/
  830. }
  831. }
  832. [Browsable(false)]
  833. public override bool Focused
  834. {
  835. get
  836. {
  837. return base.Focused || panel.Focused || leftRuler.Focused || topRuler.Focused;
  838. }
  839. }
  840. private void Renderers_Invalidated(object sender, InvalidateEventArgs e)
  841. {
  842. Rectangle rect = SurfaceToClient(e.InvalidRect);
  843. rect.Inflate(1, 1);
  844. Invalidate(rect);
  845. }
  846. /// <summary>
  847. /// 计算像素跟踪的点
  848. /// </summary>
  849. /// <param name="point"></param>
  850. /// <returns></returns>
  851. public Point CalcPixelPoint(Point point)
  852. {
  853. Rectangle rc = this.panel.ClientRectangle;
  854. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  855. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  856. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  857. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  858. point.X -= x;
  859. point.Y -= y;
  860. return this.ScaleFactor.UnscalePoint(point);
  861. }
  862. public Surface GetDoubleBuffer(Size size)
  863. {
  864. Surface localDBSurface = null;
  865. Size oldSize = new Size(0, 0);
  866. // If we already have a double buffer surface reference, but if that surface
  867. // is already disposed then don't worry about it.
  868. if (this.doubleBufferSurface != null && this.doubleBufferSurface.IsDisposed)
  869. {
  870. oldSize = this.doubleBufferSurface.Size;
  871. this.doubleBufferSurface = null;
  872. }
  873. // If we already have a double buffer surface reference, but if that surface
  874. // is too small, then nuke it.
  875. if (this.doubleBufferSurface != null &&
  876. (this.doubleBufferSurface.Width < size.Width || this.doubleBufferSurface.Height < size.Height))
  877. {
  878. oldSize = this.doubleBufferSurface.Size;
  879. this.doubleBufferSurface.Dispose();
  880. this.doubleBufferSurface = null;
  881. doubleBufferSurfaceWeakRef = null;
  882. }
  883. // If we don't have a double buffer, then we'd better get one.
  884. if (this.doubleBufferSurface != null)
  885. {
  886. // Got one!
  887. localDBSurface = this.doubleBufferSurface;
  888. }
  889. else if (doubleBufferSurfaceWeakRef != null)
  890. {
  891. // First, try to get the one that's already shared amongst all SurfaceBox instances.
  892. localDBSurface = doubleBufferSurfaceWeakRef.Target;
  893. // If it's disposed, then forget about it.
  894. if (localDBSurface != null && localDBSurface.IsDisposed)
  895. {
  896. oldSize = localDBSurface.Size;
  897. localDBSurface = null;
  898. doubleBufferSurfaceWeakRef = null;
  899. }
  900. }
  901. // Make sure the surface is big enough.
  902. if (localDBSurface != null && (localDBSurface.Width < size.Width || localDBSurface.Height < size.Height))
  903. {
  904. oldSize = localDBSurface.Size;
  905. localDBSurface.Dispose();
  906. localDBSurface = null;
  907. doubleBufferSurfaceWeakRef = null;
  908. }
  909. // So, do we have a surface? If not then we'd better make one.
  910. if (localDBSurface == null)
  911. {
  912. Size newSize = new Size(Math.Max(size.Width, oldSize.Width), Math.Max(size.Height, oldSize.Height));
  913. localDBSurface = new Surface(newSize.Width, newSize.Height);
  914. doubleBufferSurfaceWeakRef = new Base.WeakReference<Surface>(localDBSurface);
  915. }
  916. this.doubleBufferSurface = localDBSurface;
  917. Surface window = localDBSurface.CreateWindow(0, 0, size.Width, size.Height);
  918. return window;
  919. }
  920. private class RenderContext
  921. {
  922. public Surface[] windows;
  923. public Point[] offsets;
  924. public Rectangle[] rects;
  925. public DocumentView owner;
  926. public WaitCallback waitCallback;
  927. public void RenderThreadMethod(object indexObject)
  928. {
  929. int index = (int)indexObject;
  930. this.owner.rendererList.Render(windows[index], offsets[index]);
  931. this.windows[index].Dispose();
  932. this.windows[index] = null;
  933. }
  934. }
  935. public unsafe void DrawArea(RenderArgs ra, Point offset)
  936. {
  937. if (compositionSurface == null)
  938. {
  939. return;
  940. }
  941. if (renderContext == null || (renderContext.windows != null && renderContext.windows.Length != Processor.LogicalCpuCount))
  942. {
  943. renderContext = new RenderContext();
  944. //这里需要计算宽高
  945. renderContext.owner = this;
  946. renderContext.waitCallback = new WaitCallback(renderContext.RenderThreadMethod);
  947. renderContext.windows = new Surface[Processor.LogicalCpuCount];
  948. renderContext.offsets = new Point[Processor.LogicalCpuCount];
  949. renderContext.rects = new Rectangle[Processor.LogicalCpuCount];
  950. }
  951. Utility.SplitRectangle(ra.Bounds, renderContext.rects);
  952. for (int i = 0; i < renderContext.rects.Length; ++i)
  953. {
  954. if (renderContext.rects[i].Width > 0 && renderContext.rects[i].Height > 0)
  955. {
  956. renderContext.offsets[i] = new Point(renderContext.rects[i].X + offset.X, renderContext.rects[i].Y + offset.Y);
  957. renderContext.windows[i] = ra.Surface.CreateWindow(renderContext.rects[i]);
  958. //renderContext.windows[i] = ra.Surface.CreateWindow(new Rectangle(renderContext.offsets[i], renderContext.rects[i].Size));
  959. }
  960. else
  961. {
  962. renderContext.windows[i] = null;
  963. }
  964. }
  965. for (int i = 0; i < renderContext.windows.Length; ++i)
  966. {
  967. if (renderContext.windows[i] != null)
  968. {
  969. this.threadPool.QueueUserWorkItem(renderContext.waitCallback, BoxedConstants.GetInt32(i));
  970. }
  971. }
  972. this.threadPool.Drain();
  973. }
  974. protected override void OnLoad(EventArgs e)
  975. {
  976. base.OnLoad(e);
  977. // Sometimes OnLoad() gets called *twice* for some reason.
  978. // See bug #1415 for the symptoms.
  979. /**if (!this.hookedMouseEvents)
  980. {
  981. this.hookedMouseEvents = true;
  982. foreach (Control c in Controls)
  983. {
  984. HookMouseEvents(c);
  985. }
  986. }**/
  987. this.panel.Select();
  988. }
  989. public void HookMouseEvents()
  990. {
  991. if (!this.hookedMouseEvents)
  992. {
  993. this.hookedMouseEvents = true;
  994. foreach (Control c in Controls)
  995. {
  996. HookMouseEvents(c);
  997. }
  998. }
  999. }
  1000. public void PerformMouseWheel(Control sender, MouseEventArgs e)
  1001. {
  1002. HandleMouseWheel(sender, e);
  1003. }
  1004. protected override void OnMouseWheel(MouseEventArgs e)
  1005. {
  1006. HandleMouseWheel(this, e);
  1007. base.OnMouseWheel(e);
  1008. }
  1009. /// <summary>
  1010. /// 鼠标滚轮事件
  1011. /// </summary>
  1012. /// <param name="sender"></param>
  1013. /// <param name="e"></param>
  1014. protected virtual void HandleMouseWheel(Control sender, MouseEventArgs e)
  1015. {
  1016. double docDelta = (double)e.Delta / this.ScaleFactor.Ratio;
  1017. double oldX = this.DocumentScrollPositionF.X;
  1018. double oldY = this.DocumentScrollPositionF.Y;
  1019. double newX;
  1020. double newY;
  1021. if (Control.ModifierKeys == Keys.Shift)
  1022. {
  1023. this.panel.Response = false;
  1024. // scroll horizontally
  1025. newX = this.DocumentScrollPositionF.X - docDelta;
  1026. newY = this.DocumentScrollPositionF.Y;
  1027. }
  1028. else if (Control.ModifierKeys == Keys.None)
  1029. {
  1030. this.panel.Response = true;
  1031. // scroll vertically
  1032. newX = this.DocumentScrollPositionF.X;
  1033. newY = this.DocumentScrollPositionF.Y - docDelta;
  1034. }
  1035. else
  1036. {
  1037. this.panel.Response = false;
  1038. // no change
  1039. newX = this.DocumentScrollPositionF.X;
  1040. newY = this.DocumentScrollPositionF.Y;
  1041. }
  1042. if (newX != oldX || newY != oldY)
  1043. {
  1044. this.DocumentScrollPositionF = new PointF((float)newX, (float)newY);
  1045. UpdateRulerOffsets();
  1046. }
  1047. }
  1048. public bool IsMouseCaptured()
  1049. {
  1050. return panel.Capture || leftRuler.Capture || topRuler.Capture;//this.Capture ||
  1051. }
  1052. /// <summary>
  1053. /// Get or set upper left of scroll location in document coordinates.
  1054. /// </summary>
  1055. [Browsable(false)]
  1056. public PointF DocumentScrollPositionF
  1057. {
  1058. get
  1059. {
  1060. if (this.panel == null)
  1061. {
  1062. return PointF.Empty;
  1063. }
  1064. else
  1065. {
  1066. return this.panel.ScrollPosition;
  1067. //return VisibleDocumentRectangleF.Location;
  1068. }
  1069. }
  1070. set
  1071. {
  1072. if (panel == null)
  1073. {
  1074. return;
  1075. }
  1076. else
  1077. {
  1078. this.panel.ScrollPosition = new Point((int)value.X, (int)value.Y);
  1079. }
  1080. /**
  1081. PointF sbClientF = this.panel.SurfaceToClient(value);
  1082. Point sbClient = Point.Round(sbClientF);
  1083. if (this.panel.AutoScrollPosition != new Point(-sbClient.X, -sbClient.Y))
  1084. {
  1085. this.panel.AutoScrollPosition = sbClient;
  1086. UpdateRulerOffsets();
  1087. this.topRuler.Invalidate();
  1088. this.leftRuler.Invalidate();
  1089. }**/
  1090. }
  1091. }
  1092. public Point PanelScrollPosition
  1093. {
  1094. get
  1095. {
  1096. return this.panel.ScrollPosition;
  1097. }
  1098. set
  1099. {
  1100. this.panel.ScrollPosition = value;
  1101. }
  1102. }
  1103. [Browsable(false)]
  1104. public PointF DocumentCenterPointF
  1105. {
  1106. get
  1107. {
  1108. RectangleF vsb = VisibleDocumentRectangleF;
  1109. PointF centerPt = new PointF((vsb.Left + vsb.Right) / 2, (vsb.Top + vsb.Bottom) / 2);
  1110. return centerPt;
  1111. }
  1112. set
  1113. {
  1114. RectangleF vsb = VisibleDocumentRectangleF;
  1115. PointF newCornerPt = new PointF(value.X - (vsb.Width / 2), value.Y - (vsb.Height / 2));
  1116. this.DocumentScrollPositionF = newCornerPt;
  1117. }
  1118. }
  1119. /// <summary>
  1120. /// Clean up any resources being used.
  1121. /// </summary>
  1122. protected override void Dispose(bool disposing)
  1123. {
  1124. if (disposing)
  1125. {
  1126. if (this.components != null)
  1127. {
  1128. this.components.Dispose();
  1129. this.components = null;
  1130. }
  1131. if (this.compositionSurface != null)
  1132. {
  1133. this.compositionSurface.Dispose();
  1134. this.compositionSurface = null;
  1135. }
  1136. }
  1137. base.Dispose(disposing);
  1138. }
  1139. /// <summary>
  1140. /// 缩放比例改变事件
  1141. /// </summary>
  1142. public event EventHandler ScaleFactorChanged;
  1143. protected virtual void OnScaleFactorChanged()
  1144. {
  1145. if (ScaleFactorChanged != null)
  1146. {
  1147. ScaleFactorChanged(this, EventArgs.Empty);
  1148. }
  1149. }
  1150. /// <summary>
  1151. /// 像素网格是否绘制的bool标记改变事件
  1152. /// </summary>
  1153. public event EventHandler DrawGridChanged;
  1154. protected virtual void OnDrawGridChanged()
  1155. {
  1156. if (DrawGridChanged != null)
  1157. {
  1158. DrawGridChanged(this, EventArgs.Empty);
  1159. }
  1160. }
  1161. /// <summary>
  1162. /// 合适大小
  1163. /// </summary>
  1164. public void ZoomToWindow()
  1165. {
  1166. if (this.document != null)
  1167. {
  1168. Rectangle max = ClientRectangleMax;
  1169. ScaleFactor zoom = ScaleFactor.Min(max.Width - 10,
  1170. document.Width,
  1171. max.Height - 10,
  1172. document.Height,
  1173. ScaleFactor.MinValue);
  1174. ScaleFactor min = ScaleFactor.Min(zoom, ScaleFactor.OneToOne);
  1175. this.ScaleFactor = min;
  1176. }
  1177. }
  1178. /// <summary>
  1179. /// 合适宽度
  1180. /// </summary>
  1181. public void ZoomToWidth()
  1182. {
  1183. if (this.document != null)
  1184. {
  1185. Rectangle max = ClientRectangleMax;
  1186. ScaleFactor zoom = ScaleFactor.UseIfValid(max.Width - 40, document.Width, ScaleFactor.MinValue);
  1187. ScaleFactor min = ScaleFactor.Min(zoom, ScaleFactor.OneToOne);
  1188. this.ScaleFactor = min;
  1189. }
  1190. }
  1191. /// <summary>
  1192. /// 合适高度
  1193. /// </summary>
  1194. public void ZoomToHeight()
  1195. {
  1196. if (this.document != null)
  1197. {
  1198. Rectangle max = ClientRectangleMax;
  1199. ScaleFactor zoom = ScaleFactor.UseIfValid(max.Height - 20, document.Height, ScaleFactor.MinValue);
  1200. ScaleFactor min = ScaleFactor.Min(zoom, ScaleFactor.OneToOne);
  1201. this.ScaleFactor = min;
  1202. }
  1203. }
  1204. private double GetZoomInFactorEpsilon()
  1205. {
  1206. double ratio = this.ScaleFactor.Ratio;
  1207. return (ratio + 0.01) / ratio;
  1208. /**
  1209. // Increase ratio by 1 percentage point
  1210. double currentRatio = this.ScaleFactor.Ratio;
  1211. double factor1 = (currentRatio + 0.01) / currentRatio;
  1212. // Increase ratio so that we increase our view by 1 pixel
  1213. double ratioW = (double)(this.panel.Width + 1) / (double)this.compositionSurface.Width;
  1214. double ratioH = (double)(this.panel.Height + 1) / (double)this.compositionSurface.Height;
  1215. double ratio = Math.Max(ratioW, ratioH);
  1216. double factor2 = ratio / currentRatio;
  1217. double factor = Math.Max(factor1, factor2);
  1218. return factor;
  1219. **/
  1220. }
  1221. private double GetZoomOutFactorEpsilon()
  1222. {
  1223. double ratio = this.ScaleFactor.Ratio;
  1224. return (ratio - 0.01) / ratio;
  1225. }
  1226. public virtual void ZoomIn(double factor)
  1227. {
  1228. ZoomInImpl(factor);
  1229. }
  1230. private void ZoomInImpl(double factor)
  1231. {
  1232. PointF centerPt = this.DocumentCenterPointF;
  1233. ScaleFactor oldSF = this.ScaleFactor;
  1234. ScaleFactor newSF = this.ScaleFactor;
  1235. int countdown = 3;
  1236. // At a minimum we want to increase the size of visible document by 1 pixel
  1237. // Figure out what the ratio of ourSize : ourSize+1 is, and start out with that
  1238. double zoomInEps = GetZoomInFactorEpsilon();
  1239. double desiredFactor = Math.Max(factor, zoomInEps);
  1240. double newFactor = desiredFactor;
  1241. // Keep setting the ScaleFactor until it actually 'sticks'
  1242. // Important for certain image sizes where not all zoom levels create distinct
  1243. // screen sizes
  1244. do
  1245. {
  1246. newSF = ScaleFactor.FromDouble(newSF.Ratio * newFactor);
  1247. this.ScaleFactor = newSF;
  1248. --countdown;
  1249. newFactor *= 1.10;
  1250. } while (this.ScaleFactor == oldSF && countdown > 0);
  1251. this.DocumentCenterPointF = centerPt;
  1252. }
  1253. public virtual void ZoomIn()
  1254. {
  1255. ZoomInImpl();
  1256. }
  1257. private void ZoomInImpl()
  1258. {
  1259. PointF centerPt = this.DocumentCenterPointF;
  1260. ScaleFactor oldSF = this.ScaleFactor;
  1261. ScaleFactor newSF = this.ScaleFactor;
  1262. int countdown = ScaleFactor.PresetValues.Length;
  1263. // Keep setting the ScaleFactor until it actually 'sticks'
  1264. // Important for certain image sizes where not all zoom levels create distinct
  1265. // screen sizes
  1266. do
  1267. {
  1268. newSF = newSF.GetNextLarger();
  1269. this.ScaleFactor = newSF;
  1270. --countdown;
  1271. } while (this.ScaleFactor == oldSF && countdown > 0);
  1272. this.DocumentCenterPointF = centerPt;
  1273. }
  1274. public virtual void ZoomOut(double factor)
  1275. {
  1276. ZoomOutImpl(factor);
  1277. }
  1278. private void ZoomOutImpl(double factor)
  1279. {
  1280. PointF centerPt = this.DocumentCenterPointF;
  1281. ScaleFactor oldSF = this.ScaleFactor;
  1282. ScaleFactor newSF = this.ScaleFactor;
  1283. int countdown = 3;
  1284. // At a minimum we want to decrease the size of visible document by 1 pixel (without dividing by zero of course)
  1285. // Figure out what the ratio of ourSize : ourSize-1 is, and start out with that
  1286. double zoomOutEps = GetZoomOutFactorEpsilon();
  1287. double factorRecip = 1.0 / factor;
  1288. double desiredFactor = Math.Min(factorRecip, zoomOutEps);
  1289. double newFactor = desiredFactor;
  1290. // Keep setting the ScaleFactor until it actually 'sticks'
  1291. // Important for certain image sizes where not all zoom levels create distinct
  1292. // screen sizes
  1293. do
  1294. {
  1295. newSF = ScaleFactor.FromDouble(newSF.Ratio * newFactor);
  1296. this.ScaleFactor = newSF;
  1297. --countdown;
  1298. newFactor *= 0.9;
  1299. } while (this.ScaleFactor == oldSF && countdown > 0);
  1300. this.DocumentCenterPointF = centerPt;
  1301. }
  1302. public virtual void ZoomOut()
  1303. {
  1304. ZoomOutImpl();
  1305. }
  1306. private void ZoomOutImpl()
  1307. {
  1308. PointF centerPt = this.DocumentCenterPointF;
  1309. ScaleFactor oldSF = this.ScaleFactor;
  1310. ScaleFactor newSF = this.ScaleFactor;
  1311. int countdown = ScaleFactor.PresetValues.Length;
  1312. // Keep setting the ScaleFactor until it actually 'sticks'
  1313. // Important for certain image sizes where not all zoom levels create distinct
  1314. // screen sizes
  1315. do
  1316. {
  1317. newSF = newSF.GetNextSmaller();
  1318. this.ScaleFactor = newSF;
  1319. --countdown;
  1320. } while (this.ScaleFactor == oldSF && countdown > 0);
  1321. this.DocumentCenterPointF = centerPt;
  1322. }
  1323. [Browsable(false)]
  1324. public ScaleFactor ScaleFactor
  1325. {
  1326. get
  1327. {
  1328. return this.scaleFactor;
  1329. }
  1330. set
  1331. {
  1332. UI.SuspendControlPainting(this);
  1333. ScaleFactor newValue = ScaleFactor.Min(value, ScaleFactor.MaxValue);
  1334. if (newValue == this.scaleFactor &&
  1335. this.scaleFactor == ScaleFactor.OneToOne)
  1336. {
  1337. // this space intentionally left blank
  1338. }
  1339. else
  1340. {
  1341. RectangleF visibleRect = this.VisibleDocumentRectangleF;
  1342. ScaleFactor oldSF = scaleFactor;
  1343. scaleFactor = newValue;
  1344. // This value is used later below to re-center the document on screen
  1345. PointF centerPt = new PointF(visibleRect.X + visibleRect.Width / 2,
  1346. visibleRect.Y + visibleRect.Height / 2);
  1347. if (compositionSurface != null)
  1348. {
  1349. Rectangle rc = this.panel.ClientRectangle;
  1350. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  1351. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  1352. if (rc.Width < width || rc.Height < height)
  1353. {
  1354. this.panel.AutoScrollMinSize = new Size((int)(this.compositionSurface.Width * scaleFactor.Ratio) + offsetW, (int)(this.compositionSurface.Height * scaleFactor.Ratio) + offsetH);
  1355. //////求因缩放产生的位移,进行补偿,实现锚点缩放的效果
  1356. ////VX = (int)((double)x * (ow - pictureBox1.Width) / ow);
  1357. ////VY = (int)((double)y * (oh - pictureBox1.Height) / oh);
  1358. ////pictureBox1.Location = new Point(pictureBox1.Location.X + VX, pictureBox1.Location.Y + VY);
  1359. //this.panel.AutoScrollPosition = new Point((int)(width - rc.Width) / 2 + 150, (int)(height - rc.Height) / 2 + 75);
  1360. //////this.panel.AutoScrollPosition = sbClient;
  1361. ////UpdateRulerOffsets();
  1362. ////this.topRuler.Invalidate();
  1363. ////this.leftRuler.Invalidate();
  1364. }
  1365. else
  1366. {
  1367. this.panel.AutoScrollMinSize = new Size((int)(this.compositionSurface.Width * scaleFactor.Ratio), (int)(this.compositionSurface.Height * scaleFactor.Ratio));
  1368. //this.panel.AutoScrollPosition = new Point((int)(width - rc.Width) / 2 + 0, (int)(height - rc.Height) / 2 + 0);
  1369. ////UpdateRulerOffsets();
  1370. ////this.topRuler.Invalidate();
  1371. ////this.leftRuler.Invalidate();
  1372. }
  1373. this.panel.ScaleFactor = this.scaleFactor;
  1374. if (leftRuler != null)
  1375. {
  1376. this.leftRuler.ScaleFactor = scaleFactor;
  1377. }
  1378. if (topRuler != null)
  1379. {
  1380. this.topRuler.ScaleFactor = scaleFactor;
  1381. }
  1382. }
  1383. // re center ourself
  1384. RectangleF visibleRect2 = this.VisibleDocumentRectangleF;
  1385. RecenterView(centerPt);
  1386. }
  1387. this.OnResize(EventArgs.Empty);
  1388. this.OnScaleFactorChanged();
  1389. if (this.appWorkspace != null && refueshZoomTrackValue && this.rightDown)
  1390. {
  1391. this.appWorkspace.SetZoonTrackValue(newValue);
  1392. }
  1393. if (compositionSurface != null)
  1394. this.rendererList.DestinationSize = this.scaleFactor.ScaleSize(compositionSurface.Size);
  1395. UI.ResumeControlPainting(this);
  1396. Invalidate(true);
  1397. }
  1398. }
  1399. /// <summary>
  1400. /// Returns a rectangle for the bounding rectangle of what is currently visible on screen,
  1401. /// in document coordinates.
  1402. /// </summary>
  1403. [Browsable(false)]
  1404. public RectangleF VisibleDocumentRectangleF
  1405. {
  1406. get
  1407. {
  1408. Rectangle panelRect = this.panel.RectangleToScreen(this.panel.ClientRectangle); // screen coords coords
  1409. Rectangle docScreenRect = panelRect; // screen coords
  1410. Rectangle docClientRect = RectangleToClient(docScreenRect);
  1411. RectangleF docDocRectF = ClientToDocument(docClientRect);
  1412. return docDocRectF;
  1413. }
  1414. }
  1415. public Rectangle PanelClientRectangle
  1416. {
  1417. get
  1418. {
  1419. return panel.ClientRectangle;
  1420. }
  1421. }
  1422. public int SurfaceScrollableWidth
  1423. {
  1424. get
  1425. {
  1426. return (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  1427. }
  1428. }
  1429. public int SurfaceScrollableHeight
  1430. {
  1431. get
  1432. {
  1433. return (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  1434. }
  1435. }
  1436. public double ScaleRatio
  1437. {
  1438. get
  1439. {
  1440. return this.scaleFactor.Ratio;
  1441. }
  1442. }
  1443. /// <summary>
  1444. /// Returns a rectangle in <b>screen</b> coordinates that represents the space taken up
  1445. /// by the document that is visible on screen.
  1446. /// </summary>
  1447. [Browsable(false)]
  1448. public Rectangle VisibleDocumentBounds
  1449. {
  1450. get
  1451. {
  1452. // convert coordinates: document -> client -> screen
  1453. return RectangleToScreen(Utility.RoundRectangle(DocumentToClient(VisibleDocumentRectangleF)));
  1454. }
  1455. }
  1456. /// <summary>
  1457. /// Returns a rectangle in client coordinates that denotes the space that the document
  1458. /// may take up. This is essentially the ClientRectangle converted to screen coordinates
  1459. /// and then with the rulers and scrollbars subtracted out.
  1460. /// </summary>
  1461. public Rectangle VisibleViewRectangle
  1462. {
  1463. get
  1464. {
  1465. Rectangle clientRect = this.panel.ClientRectangle;
  1466. Rectangle screenRect = this.panel.RectangleToScreen(clientRect);
  1467. Rectangle ourClientRect = RectangleToClient(screenRect);
  1468. return ourClientRect;
  1469. }
  1470. }
  1471. public Rectangle ClientRectangleMax
  1472. {
  1473. get
  1474. {
  1475. return RectangleToClient(this.panel.RectangleToScreen(this.panel.Bounds));
  1476. }
  1477. }
  1478. public Rectangle ClientRectangleMin
  1479. {
  1480. get
  1481. {
  1482. Rectangle bounds = ClientRectangleMax;
  1483. bounds.Width -= SystemInformation.VerticalScrollBarWidth;
  1484. bounds.Height -= SystemInformation.HorizontalScrollBarHeight;
  1485. return bounds;
  1486. }
  1487. }
  1488. public void SetHighlightRectangle(RectangleF rectF)
  1489. {
  1490. if (rectF.Width == 0 || rectF.Height == 0)
  1491. {
  1492. this.leftRuler.HighlightEnabled = false;
  1493. this.topRuler.HighlightEnabled = false;
  1494. }
  1495. else
  1496. {
  1497. if (this.topRuler != null)
  1498. {
  1499. this.topRuler.HighlightEnabled = true;
  1500. this.topRuler.HighlightStart = rectF.Left;
  1501. this.topRuler.HighlightLength = rectF.Width;
  1502. }
  1503. if (this.leftRuler != null)
  1504. {
  1505. this.leftRuler.HighlightEnabled = true;
  1506. this.leftRuler.HighlightStart = rectF.Top;
  1507. this.leftRuler.HighlightLength = rectF.Height;
  1508. }
  1509. }
  1510. }
  1511. /// <summary>
  1512. /// Gets or sets the Document that is shown through this instance of DocumentView.
  1513. /// </summary>
  1514. /// <remarks>
  1515. /// This property is thread safe and may be called from a non-UI thread. However,
  1516. /// if the setter is called from a non-UI thread, then that thread will block as
  1517. /// the call is marshaled to the UI thread.
  1518. /// </remarks>
  1519. [Browsable(false)]
  1520. public Document Document
  1521. {
  1522. get
  1523. {
  1524. return document;
  1525. }
  1526. set
  1527. {
  1528. if (InvokeRequired)
  1529. {
  1530. this.Invoke(new Procedure<Document, bool>(DocumentSetImpl), new object[2] { value, true });
  1531. }
  1532. else
  1533. {
  1534. DocumentSetImpl(value, true);
  1535. }
  1536. }
  1537. }
  1538. private void DocumentSetImpl(Document value, bool toedit)
  1539. {
  1540. this.DoubleBuffered = true;
  1541. SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
  1542. PointF dspf = DocumentScrollPositionF;
  1543. OnDocumentChanging(value);
  1544. SuspendRefresh();
  1545. try
  1546. {
  1547. if (this.document != null)
  1548. {
  1549. this.document.Invalidated -= Document_Invalidated;
  1550. }
  1551. this.document = value;
  1552. if (document != null)
  1553. {
  1554. if (this.compositionSurface != null &&
  1555. this.compositionSurface.Size != document.Size)
  1556. {
  1557. this.compositionSurface.Dispose();
  1558. this.compositionSurface = null;
  1559. }
  1560. if (!toedit && this.compositionSurface.Thumborigin != null)
  1561. document.surface.Thumborigin = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.compositionSurface.Thumborigin));
  1562. this.compositionSurface = document.surface;
  1563. //生成缩略图
  1564. this.compositionSurface.CreateThumbnail();
  1565. //生成原图的备份
  1566. if (toedit)
  1567. this.compositionSurface.CreateThumborigin();
  1568. this.baseRenderer.Source = document.surface;
  1569. if (this.compositionSurface != null)
  1570. {
  1571. this.rendererList.SourceSize = this.compositionSurface.Size;
  1572. this.rendererList.DestinationSize = this.Size;
  1573. }
  1574. this.document.Invalidated += Document_Invalidated;
  1575. }
  1576. Invalidate(true);
  1577. DocumentMetaDataChangedHandler(this, EventArgs.Empty);
  1578. this.OnResize(EventArgs.Empty);
  1579. OnDocumentChanged();
  1580. }
  1581. finally
  1582. {
  1583. ResumeRefresh();
  1584. }
  1585. DocumentScrollPositionF = dspf;
  1586. }
  1587. public bool PanelAutoScroll
  1588. {
  1589. get
  1590. {
  1591. return panel.AutoScroll;
  1592. }
  1593. set
  1594. {
  1595. if (panel.AutoScroll != value)
  1596. {
  1597. panel.AutoScroll = value;
  1598. }
  1599. }
  1600. }
  1601. private void HookMouseEvents(Control c)
  1602. {
  1603. }
  1604. private void UpdateRulerOffsets()
  1605. {
  1606. this.topRuler.Offset = ScaleFactor.UnscaleScalar(UI.ScaleWidth(-16.0f) - this.panel.Location.X);
  1607. this.topRuler.Update();
  1608. this.leftRuler.Offset = ScaleFactor.UnscaleScalar(0.0f - this.panel.Location.Y);
  1609. this.leftRuler.Update();
  1610. }
  1611. private void DoLayout()
  1612. {
  1613. if (panel.ClientRectangle != new Rectangle(0, 0, 0, 0))
  1614. {
  1615. int newX = panel.AutoScrollPosition.X;
  1616. int newY = panel.AutoScrollPosition.Y;
  1617. if (panel.ClientRectangle.Width > this.panel.Width)
  1618. {
  1619. newX = panel.AutoScrollPosition.X + ((panel.ClientRectangle.Width) / 2);
  1620. }
  1621. if (panel.ClientRectangle.Height > this.panel.Height)
  1622. {
  1623. newY = panel.AutoScrollPosition.Y + ((panel.ClientRectangle.Height) / 2);
  1624. }
  1625. }
  1626. //暂时注释掉,因为在预览窗口、位置导航等显示标尺的时候,会闪烁,不知道会不会有啥问题
  1627. this.UpdateRulerOffsets();
  1628. this.UpdateImgLocation();
  1629. }
  1630. private void CheckForFirstInputAfterGotFocus()
  1631. {
  1632. if (this.raiseFirstInputAfterGotFocus)
  1633. {
  1634. this.raiseFirstInputAfterGotFocus = false;
  1635. OnFirstInputAfterGotFocus();
  1636. }
  1637. }
  1638. private void Document_Invalidated(object sender, InvalidateEventArgs e)
  1639. {
  1640. if (this.ScaleFactor == ScaleFactor.OneToOne)
  1641. {
  1642. this.panel.Invalidate(e.InvalidRect);
  1643. }
  1644. else
  1645. {
  1646. Rectangle inflatedInvalidRect = Rectangle.Inflate(e.InvalidRect, 1, 1);
  1647. Rectangle clientRect = this.panel.SurfaceToClient(inflatedInvalidRect);
  1648. Rectangle inflatedClientRect = Rectangle.Inflate(clientRect, 1, 1);
  1649. this.panel.Invalidate(inflatedClientRect);
  1650. }
  1651. }
  1652. public void SuspendRefresh()
  1653. {
  1654. ++this.refreshSuspended;
  1655. }
  1656. public void ResumeRefresh()
  1657. {
  1658. --this.refreshSuspended;
  1659. }
  1660. /// <summary>
  1661. /// 重新设置中心点
  1662. /// </summary>
  1663. /// <param name="newCenter"></param>
  1664. public void RecenterView(PointF newCenter)
  1665. {
  1666. RectangleF visibleRect = VisibleDocumentRectangleF;
  1667. PointF cornerPt = new PointF(
  1668. newCenter.X - (visibleRect.Width / 2),
  1669. newCenter.Y - (visibleRect.Height / 2));
  1670. this.DocumentScrollPositionF = cornerPt;
  1671. }
  1672. /// <summary>
  1673. /// 文档元数据改变事件
  1674. /// </summary>
  1675. /// <param name="sender"></param>
  1676. /// <param name="e"></param>
  1677. private void DocumentMetaDataChangedHandler(object sender, EventArgs e)
  1678. {
  1679. if (this.document != null)
  1680. {
  1681. this.leftRuler.Dpu = 1 / document.PixelToPhysicalY(1, this.leftRuler.MeasurementUnit);
  1682. this.topRuler.Dpu = 1 / document.PixelToPhysicalY(1, this.topRuler.MeasurementUnit);
  1683. }
  1684. }
  1685. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  1686. {
  1687. Keys keyCode = keyData & Keys.KeyCode;
  1688. if (Utility.IsArrowKey(keyData) ||
  1689. keyCode == Keys.Delete ||
  1690. keyCode == Keys.Tab)
  1691. {
  1692. KeyEventArgs kea = new KeyEventArgs(keyData);
  1693. // We only intercept WM_KEYDOWN because WM_KEYUP is not sent!
  1694. switch (msg.Msg)
  1695. {
  1696. case 0x100: //NativeMethods.WmConstants.WM_KEYDOWN:
  1697. if (this.ContainsFocus)
  1698. {
  1699. OnDocumentKeyDown(kea);
  1700. //OnDocumentKeyUp(kea);
  1701. if (Utility.IsArrowKey(keyData))
  1702. {
  1703. kea.Handled = true;
  1704. }
  1705. }
  1706. if (kea.Handled)
  1707. {
  1708. return true;
  1709. }
  1710. break;
  1711. }
  1712. }
  1713. return base.ProcessCmdKey(ref msg, keyData);
  1714. }
  1715. #region 对外的各种事件委托
  1716. public event EventHandler CompositionUpdated;
  1717. private void OnCompositionUpdated()
  1718. {
  1719. if (CompositionUpdated != null)
  1720. {
  1721. CompositionUpdated(this, EventArgs.Empty);
  1722. }
  1723. }
  1724. public event EventHandler RulersEnabledChanged;
  1725. protected void OnRulersEnabledChanged()
  1726. {
  1727. if (RulersEnabledChanged != null)
  1728. {
  1729. RulersEnabledChanged(this, EventArgs.Empty);
  1730. }
  1731. }
  1732. public event EventHandler<EventArgs<Document>> DocumentChanging;
  1733. protected virtual void OnDocumentChanging(Document newDocument)
  1734. {
  1735. if (DocumentChanging != null)
  1736. {
  1737. DocumentChanging(this, new EventArgs<Document>(newDocument));
  1738. }
  1739. }
  1740. public event EventHandler DocumentChanged;
  1741. protected virtual void OnDocumentChanged()
  1742. {
  1743. if (DocumentChanged != null)
  1744. {
  1745. DocumentChanged(this, EventArgs.Empty);
  1746. }
  1747. }
  1748. public event EventHandler FirstInputAfterGotFocus;
  1749. protected virtual void OnFirstInputAfterGotFocus()
  1750. {
  1751. if (FirstInputAfterGotFocus != null)
  1752. {
  1753. FirstInputAfterGotFocus(this, EventArgs.Empty);
  1754. }
  1755. }
  1756. /// <summary>
  1757. /// Occurs when the mouse enters an element of the UI that is considered to be part of
  1758. /// the document space.
  1759. /// </summary>
  1760. public event EventHandler DocumentMouseEnter;
  1761. protected virtual void OnDocumentMouseEnter(EventArgs e)
  1762. {
  1763. if (DocumentMouseEnter != null)
  1764. {
  1765. DocumentMouseEnter(this, e);
  1766. }
  1767. }
  1768. public event EventHandler DocumentMouseLeave;
  1769. protected virtual void OnDocumentMouseLeave(EventArgs e)
  1770. {
  1771. if (DocumentMouseLeave != null)
  1772. {
  1773. DocumentMouseLeave(this, e);
  1774. }
  1775. }
  1776. /// <summary>
  1777. /// Occurs when the mouse or stylus point is moved over the document.
  1778. /// </summary>
  1779. /// <remarks>
  1780. /// Note: This event will always be raised twice in succession. One will provide a
  1781. /// MouseEventArgs, and the other will provide a StylusEventArgs. It is up to consumers
  1782. /// of this event to decide which one is pertinent and to then filter out the other
  1783. /// type of event.
  1784. /// </remarks>
  1785. public event MouseEventHandler DocumentMouseMove;
  1786. protected virtual void OnDocumentMouseMove(MouseEventArgs e)
  1787. {
  1788. if (DocumentMouseMove != null)
  1789. {
  1790. DocumentMouseMove(this, e);
  1791. }
  1792. }
  1793. /// <summary>
  1794. /// Occurs when the mouse or stylus point is over the document and a mouse button is released
  1795. /// or the stylus is lifted.
  1796. /// </summary>
  1797. /// <remarks>
  1798. /// Note: This event will always be raised twice in succession. One will provide a
  1799. /// MouseEventArgs, and the other will provide a StylusEventArgs. It is up to consumers
  1800. /// of this event to decide which one is pertinent and to then filter out the other
  1801. /// type of event.
  1802. /// </remarks>
  1803. public event MouseEventHandler DocumentMouseUp;
  1804. protected virtual void OnDocumentMouseUp(MouseEventArgs e)
  1805. {
  1806. CheckForFirstInputAfterGotFocus();
  1807. if (DocumentMouseUp != null)
  1808. {
  1809. DocumentMouseUp(this, e);
  1810. }
  1811. }
  1812. /// <summary>
  1813. /// Occurs when the mouse or stylus point is over the document and a mouse button or
  1814. /// stylus is pressed.
  1815. /// </summary>
  1816. /// <remarks>
  1817. /// Note: This event will always be raised twice in succession. One will provide a
  1818. /// MouseEventArgs, and the other will provide a StylusEventArgs. It is up to consumers
  1819. /// of this event to decide which one is pertinent and to then filter out the other
  1820. /// type of event.
  1821. /// </remarks>
  1822. public event MouseEventHandler DocumentMouseDown;
  1823. protected virtual void OnDocumentMouseDown(MouseEventArgs e)
  1824. {
  1825. CheckForFirstInputAfterGotFocus();
  1826. if (DocumentMouseDown != null)
  1827. {
  1828. DocumentMouseDown(this, e);
  1829. }
  1830. }
  1831. public event EventHandler DocumentClick;
  1832. protected void OnDocumentClick()
  1833. {
  1834. CheckForFirstInputAfterGotFocus();
  1835. if (DocumentClick != null)
  1836. {
  1837. DocumentClick(this, EventArgs.Empty);
  1838. }
  1839. }
  1840. public event KeyPressEventHandler DocumentKeyPress;
  1841. protected void OnDocumentKeyPress(KeyPressEventArgs e)
  1842. {
  1843. CheckForFirstInputAfterGotFocus();
  1844. if (DocumentKeyPress != null)
  1845. {
  1846. DocumentKeyPress(this, e);
  1847. }
  1848. }
  1849. public event KeyEventHandler DocumentKeyDown;
  1850. protected void OnDocumentKeyDown(KeyEventArgs e)
  1851. {
  1852. CheckForFirstInputAfterGotFocus();
  1853. if (DocumentKeyDown != null)
  1854. {
  1855. DocumentKeyDown(this, e);
  1856. }
  1857. }
  1858. public event KeyEventHandler DocumentKeyUp;
  1859. protected void OnDocumentKeyUp(KeyEventArgs e)
  1860. {
  1861. CheckForFirstInputAfterGotFocus();
  1862. if (DocumentKeyUp != null)
  1863. {
  1864. DocumentKeyUp(this, e);
  1865. }
  1866. }
  1867. #endregion
  1868. #region DocimentView的子控件的事件
  1869. private void Panel_KeyPress(object sender, KeyPressEventArgs e)
  1870. {
  1871. OnDocumentKeyPress(e);
  1872. }
  1873. private void Panel_LostFocus(object sender, EventArgs e)
  1874. {
  1875. this.raiseFirstInputAfterGotFocus = false;
  1876. }
  1877. private void Panel_GotFocus(object sender, EventArgs e)
  1878. {
  1879. this.raiseFirstInputAfterGotFocus = true;
  1880. }
  1881. private void Panel_KeyDown(object sender, KeyEventArgs e)
  1882. {
  1883. if (e.KeyValue == 17)
  1884. {
  1885. this.controlPress = true;
  1886. }
  1887. CheckForFirstInputAfterGotFocus();
  1888. OnDocumentKeyDown(e);
  1889. if (!e.Handled)
  1890. {
  1891. PointF oldPt = this.DocumentScrollPositionF;
  1892. PointF newPt = oldPt;
  1893. RectangleF vdr = VisibleDocumentRectangleF;
  1894. switch (e.KeyData)
  1895. {
  1896. case Keys.Next:
  1897. newPt.Y += vdr.Height;
  1898. break;
  1899. case (Keys.Next | Keys.Shift):
  1900. newPt.X += vdr.Width;
  1901. break;
  1902. case Keys.Prior:
  1903. newPt.Y -= vdr.Height;
  1904. break;
  1905. case (Keys.Prior | Keys.Shift):
  1906. newPt.X -= vdr.Width;
  1907. break;
  1908. case Keys.Home:
  1909. if (oldPt.X == 0)
  1910. {
  1911. newPt.Y = 0;
  1912. }
  1913. else
  1914. {
  1915. newPt.X = 0;
  1916. }
  1917. break;
  1918. case Keys.End:
  1919. if (vdr.Right < this.document.Width - 1)
  1920. {
  1921. newPt.X = this.document.Width;
  1922. }
  1923. else
  1924. {
  1925. newPt.Y = this.document.Height;
  1926. }
  1927. break;
  1928. default:
  1929. break;
  1930. }
  1931. if (newPt != oldPt)
  1932. {
  1933. DocumentScrollPositionF = newPt;
  1934. e.Handled = true;
  1935. }
  1936. }
  1937. }
  1938. private void Panel_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
  1939. {
  1940. OnScroll(e);
  1941. UpdateRulerOffsets();
  1942. }
  1943. private void Panel_KeyUp(object sender, KeyEventArgs e)
  1944. {
  1945. this.controlPress = false;
  1946. OnDocumentKeyUp(e);
  1947. }
  1948. /// <summary>
  1949. /// 鼠标按下事件
  1950. /// </summary>
  1951. /// <param name="sender"></param>
  1952. /// <param name="e"></param>
  1953. private void MouseEvent_Down(object sender, MouseEventArgs e)
  1954. {
  1955. if(keepDraw)
  1956. {
  1957. //tools[(int)activeTool].OnMouseDown(this, e);
  1958. tools[(int)activeTool].InvokeMember("OnMouseDown",
  1959. BindingFlags.Public |
  1960. BindingFlags.Static |
  1961. BindingFlags.InvokeMethod,
  1962. null,
  1963. null,
  1964. new object[2] { this, e });
  1965. if (this.appWorkspace != null)
  1966. {
  1967. this.appWorkspace.SetDrawNodes();
  1968. //this.appWorkspace.RefreshCameraPriview();
  1969. }
  1970. }
  1971. }
  1972. //private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int a);
  1973. public void MouseEvent_Del(object sender, MouseEventArgs e)
  1974. {
  1975. try
  1976. {
  1977. tools[(int)activeTool].InvokeMember("beginWithNewObject",
  1978. BindingFlags.Public |
  1979. BindingFlags.Static |
  1980. BindingFlags.InvokeMethod,
  1981. null,
  1982. null,
  1983. new object[0] { });
  1984. }
  1985. catch (Exception ex)
  1986. {
  1987. }
  1988. tools[0].InvokeMember("OnDelKeyDown",
  1989. BindingFlags.Public |
  1990. BindingFlags.Static |
  1991. BindingFlags.InvokeMethod,
  1992. null,
  1993. null,
  1994. new object[2] { this, e });
  1995. //tools[(int)activeTool].OnDelKeyDown(this, e);
  1996. //if (this.appWorkspace != null)
  1997. // this.appWorkspace.RefreshLabelListDialog();
  1998. }
  1999. /// <summary>
  2000. /// 鼠标移动事件
  2001. /// </summary>
  2002. /// <param name="sender"></param>
  2003. /// <param name="e"></param>
  2004. private void MouseEvent_Move(object sender, MouseEventArgs e)
  2005. {
  2006. //
  2007. // 像素跟踪,如果AppWorkspace不等于null,坐标不超范围,则设置像素跟踪
  2008. //
  2009. if (this.AppWorkspaceTop != null && this.compositionSurface != null && this.pixelTrackingEnabled)
  2010. //&& e.Location.X>=0 && e.Location.Y>=0
  2011. //&& e.Location.X<=this.Surface.Width
  2012. //&& e.Location.Y <= this.Surface.Height)
  2013. {
  2014. //this.AppWorkspaceTop.SetImageAndData(this.ScaleFactor.UnscalePoint(e.Location));
  2015. this.AppWorkspaceTop.SetImageAndData(this.CalcPixelPoint(e.Location));
  2016. }
  2017. //
  2018. // 是否绘制辅助线
  2019. //
  2020. if (this.auxiliaryLineEnabled)
  2021. {
  2022. path = new GraphicsPath();
  2023. path.AddLine(new Point(0, e.Y), new Point(Width, e.Y));
  2024. path1 = new GraphicsPath();
  2025. path1.AddLine(new Point(e.X, 0), new Point(e.X, Height));
  2026. this.Refresh();
  2027. }
  2028. //
  2029. // 处理标注测量
  2030. //
  2031. //右键绘制 是个坑 以后须谨慎
  2032. if (!initialized)
  2033. return;
  2034. if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right || e.Button == MouseButtons.None)
  2035. tools[(int)activeTool].InvokeMember("OnMouseMove",
  2036. BindingFlags.Public |
  2037. BindingFlags.Static |
  2038. BindingFlags.InvokeMethod,
  2039. null,
  2040. null,
  2041. new object[2] { this, e });
  2042. //tools[(int)activeTool].OnMouseMove(this, e);
  2043. else
  2044. this.Cursor = Cursors.Default;
  2045. }
  2046. /// <summary>
  2047. /// 鼠标抬起事件
  2048. /// </summary>
  2049. /// <param name="sender"></param>
  2050. /// <param name="e"></param>
  2051. private void MouseEvent_Up(object sender, MouseEventArgs e)
  2052. {
  2053. if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
  2054. tools[(int)activeTool].InvokeMember("OnMouseUp",
  2055. BindingFlags.Public |
  2056. BindingFlags.Static |
  2057. BindingFlags.InvokeMethod,
  2058. null,
  2059. null,
  2060. new object[2] { this, e });
  2061. //tools[(int)activeTool].OnMouseUp(this, e);
  2062. if (this.appWorkspace != null)
  2063. {
  2064. //this.appWorkspace.RefreshLabelListDialog();
  2065. this.appWorkspace.RefreshListView();
  2066. //this.appWorkspace.RefreshOpticalDensity();
  2067. }
  2068. }
  2069. /// <summary>
  2070. /// 鼠标单击事件
  2071. /// </summary>
  2072. /// <param name="sender"></param>
  2073. /// <param name="e"></param>
  2074. private void MouseEvent_Click(object sender, MouseEventArgs e)
  2075. {
  2076. tools[(int)activeTool].InvokeMember("OnMouseClick",
  2077. BindingFlags.Public |
  2078. BindingFlags.Static |
  2079. BindingFlags.InvokeMethod,
  2080. null,
  2081. null,
  2082. new object[2] { this, e });
  2083. //tools[(int)activeTool].OnMouseClick(this, e);
  2084. }
  2085. /// <summary>
  2086. /// 鼠标双击事件
  2087. /// </summary>
  2088. /// <param name="sender"></param>
  2089. /// <param name="e"></param>
  2090. private void MouseEvent_DoubleClick(object sender, MouseEventArgs e)
  2091. {
  2092. if (e.Button == MouseButtons.Left && e.Clicks == 2)
  2093. {
  2094. if (this.controlPress)
  2095. {
  2096. List<DrawObject> list = this.graphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
  2097. if (list != null && list.Count > 0)
  2098. {
  2099. Point ene = GetScalePoint(e.Location);
  2100. RectangleF rect = list[0].Rectangle;
  2101. if (ene.X > rect.X && ene.X < (rect.X + rect.Width) && ene.Y > rect.Y && ene.Y < (rect.Y + rect.Height))
  2102. {
  2103. //this.appWorkspace.CopyAndPasteByControlAndDoubleClick();
  2104. }
  2105. }
  2106. this.controlPress = false;
  2107. }
  2108. else
  2109. {
  2110. tools[(int)activeTool].InvokeMember("OnMouseLeftDoubleClick",
  2111. BindingFlags.Public |
  2112. BindingFlags.Static |
  2113. BindingFlags.InvokeMethod,
  2114. null,
  2115. null,
  2116. new object[2] { this, e });
  2117. }
  2118. }
  2119. //tools[(int)activeTool].OnMouseLeftDoubleClick(this, e);
  2120. }
  2121. /// <summary>
  2122. /// 样式信息
  2123. /// </summary>
  2124. /// <summary>
  2125. /// 绘制事件
  2126. /// </summary>
  2127. /// <param name="sender"></param>
  2128. /// <param name="e"></param>
  2129. private void panelPaint(object sender, PaintEventArgs e)
  2130. {
  2131. if (compositionSurface != null)
  2132. {
  2133. //
  2134. // 以下是计算绘制图片的位置和大小并绘制图片
  2135. //
  2136. Rectangle rc = this.panel.ClientRectangle;
  2137. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  2138. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  2139. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  2140. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  2141. if (this.compositionSurface.CreateAliasedBitmap() != null)
  2142. {
  2143. using (Surface doubleBuffer = GetDoubleBuffer(new Size((rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height)))
  2144. {
  2145. using (RenderArgs renderArgs = new RenderArgs(doubleBuffer))
  2146. {
  2147. DrawArea(renderArgs, new Point((rc.Width < width) ? -x : 0, (rc.Height < height) ? -y : 0));
  2148. if (m_center)
  2149. {
  2150. e.Graphics.DrawImage(doubleBuffer.CreateAliasedBitmap(),
  2151. (rc.Width < width) ? 0 : (rc.Width - width) / 2,
  2152. (rc.Height < height) ? 0 : (rc.Height - height) / 2,
  2153. (rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height);
  2154. }
  2155. else
  2156. {
  2157. e.Graphics.DrawImage(doubleBuffer.CreateAliasedBitmap(),
  2158. m_pLeft,
  2159. m_pTop,
  2160. (rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height);
  2161. }
  2162. }
  2163. }
  2164. }
  2165. //
  2166. // 绘制选择的矩形
  2167. //
  2168. if (drawRectangle)
  2169. {
  2170. e.Graphics.DrawRectangle(new Pen(Color.Black), this.DrawRectangle);
  2171. }
  2172. //
  2173. // 以下是绘制辅助线
  2174. //
  2175. if (this.auxiliaryLineEnabled)
  2176. {
  2177. if (path != null && path1 != null)
  2178. {
  2179. Pen linePen = new Pen(Color.FromArgb(girdLineColour), girdLineWidth);
  2180. linePen.DashStyle = (DashStyle)this.girdLineStyle;
  2181. e.Graphics.DrawPath(linePen, path);
  2182. e.Graphics.DrawPath(linePen, path1);
  2183. }
  2184. }
  2185. //
  2186. // 以下是绘制网格、标注、测量、视场等开始
  2187. //
  2188. e.Graphics.TranslateTransform(x, y);
  2189. e.Graphics.ScaleTransform((float)this.scaleFactor.Ratio, (float)this.scaleFactor.Ratio);
  2190. //
  2191. // 以下是绘制标注、测量、视场
  2192. //
  2193. if (graphicsList != null)
  2194. {
  2195. graphicsList.Draw(e.Graphics);
  2196. }
  2197. e.Graphics.ScaleTransform(1 / (float)this.scaleFactor.Ratio, 1 / (float)this.scaleFactor.Ratio);
  2198. e.Graphics.TranslateTransform(-x, -y);
  2199. }
  2200. }
  2201. #endregion
  2202. /// <summary>
  2203. /// 获取panel可见位置的图片
  2204. /// </summary>
  2205. /// <returns></returns>
  2206. public Bitmap GetClientRangePic()
  2207. {
  2208. Rectangle rc = this.panel.ClientRectangle;
  2209. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  2210. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  2211. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  2212. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  2213. if (this.compositionSurface.CreateAliasedBitmap() != null)
  2214. {
  2215. using (Surface doubleBuffer = GetDoubleBuffer(new Size((rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height)))
  2216. {
  2217. using (RenderArgs renderArgs = new RenderArgs(doubleBuffer))
  2218. {
  2219. DrawArea(renderArgs, new Point((rc.Width < width) ? -x : 0, (rc.Height < height) ? -y : 0));
  2220. return doubleBuffer.CreateAliasedBitmap();
  2221. }
  2222. }
  2223. }
  2224. return this.compositionSurface.CreateAliasedBitmap();
  2225. }
  2226. #region DocumentView的事件
  2227. protected override void OnLayout(LayoutEventArgs e)
  2228. {
  2229. DoLayout();
  2230. base.OnLayout(e);
  2231. }
  2232. public new void Focus()
  2233. {
  2234. this.panel.Focus();
  2235. }
  2236. protected override void OnResize(EventArgs e)
  2237. {
  2238. Form parentForm = ParentForm;
  2239. if (parentForm != null)
  2240. {
  2241. if (parentForm.WindowState != this.oldWindowState)
  2242. {
  2243. PerformLayout();
  2244. }
  2245. this.oldWindowState = parentForm.WindowState;
  2246. }
  2247. base.OnResize(e);
  2248. DoLayout();
  2249. }
  2250. #endregion
  2251. #region 坐标转换相关方法
  2252. public PointF MouseToDocumentF(Control sender, Point mouse)
  2253. {
  2254. Point screenPoint = sender.PointToScreen(mouse);
  2255. Point sbClient = this.panel.PointToClient(screenPoint);
  2256. PointF docPoint = this.panel.ClientToSurface(new PointF(sbClient.X, sbClient.Y));
  2257. return docPoint;
  2258. }
  2259. public Point MouseToDocument(Control sender, Point mouse)
  2260. {
  2261. Point screenPoint = sender.PointToScreen(mouse);
  2262. Point sbClient = this.panel.PointToClient(screenPoint);
  2263. Point docPoint = Point.Truncate(this.panel.ClientToSurface(sbClient));
  2264. return docPoint;
  2265. }
  2266. public PointF ClientToDocument(Point clientPt)
  2267. {
  2268. Point screen = PointToScreen(clientPt);
  2269. Point sbClient = this.panel.PointToClient(screen);
  2270. return this.panel.ClientToSurface(sbClient);
  2271. }
  2272. public PointF ScreenToDocument(PointF screen)
  2273. {
  2274. Point offset = this.panel.PointToClient(new Point(0, 0));
  2275. return this.panel.ClientToSurface(new PointF(screen.X + (float)offset.X, screen.Y + (float)offset.Y));
  2276. }
  2277. public Point ScreenToDocument(Point screen)
  2278. {
  2279. Point offset = this.panel.PointToClient(new Point(0, 0));
  2280. return this.panel.ClientToSurface(new Point(screen.X + offset.X, screen.Y + offset.Y));
  2281. }
  2282. public PointF ClientToSurface(PointF clientPt)
  2283. {
  2284. return this.panel.ClientToSurface(clientPt);
  2285. }
  2286. public PointF DocumentToClient(PointF documentPt)
  2287. {
  2288. PointF sbClient = this.panel.SurfaceToClient(documentPt);
  2289. Point screen = this.panel.PointToScreen(Point.Round(sbClient));
  2290. return PointToClient(screen);
  2291. }
  2292. public RectangleF ClientToDocument(Rectangle clientRect)
  2293. {
  2294. Rectangle screen = RectangleToScreen(clientRect);
  2295. screen.X = screen.X + offsetW;
  2296. screen.Y = screen.Y + offsetH;
  2297. Rectangle sbClient = this.panel.RectangleToClient(screen);
  2298. return this.panel.ClientToSurface((RectangleF)sbClient);
  2299. }
  2300. public RectangleF DocumentToClient(RectangleF documentRect)
  2301. {
  2302. RectangleF sbClient = this.panel.SurfaceToClient(documentRect);
  2303. Rectangle screen = this.panel.RectangleToScreen(Utility.RoundRectangle(sbClient));
  2304. return RectangleToClient(screen);
  2305. }
  2306. public Rectangle SurfaceToClient(Rectangle surfaceRect)
  2307. {
  2308. return new Rectangle(SurfaceToClient(surfaceRect.Location), SurfaceToClient(surfaceRect.Size));
  2309. }
  2310. public Point SurfaceToClient(Point surfacePt)
  2311. {
  2312. return ScaleFactor.ScalePoint(surfacePt);
  2313. }
  2314. public Size SurfaceToClient(Size surfaceSize)
  2315. {
  2316. return Size.Round(SurfaceToClient((SizeF)surfaceSize));
  2317. }
  2318. public SizeF SurfaceToClient(SizeF surfaceSize)
  2319. {
  2320. return ScaleFactor.ScaleSize(surfaceSize);
  2321. }
  2322. #endregion
  2323. #region 接口实现
  2324. /// <summary>
  2325. /// 获取原始坐标点
  2326. /// </summary>
  2327. /// <returns></returns>
  2328. public Point GetCalcOriginPoint()
  2329. {
  2330. Rectangle rc = this.panel.ClientRectangle;
  2331. int width = (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  2332. int height = (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  2333. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  2334. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  2335. return new Point(x, y);
  2336. }
  2337. /// <summary>
  2338. /// 获取未缩放的坐标点
  2339. /// </summary>
  2340. /// <param name="point"></param>
  2341. /// <returns></returns>
  2342. public Point GetScalePoint(PointF point)
  2343. {
  2344. Rectangle rc = this.panel.ClientRectangle;
  2345. int width = this.compositionSurface == null ? 800 : (int)(this.compositionSurface.Width * this.scaleFactor.Ratio);
  2346. int height = this.compositionSurface == null ? 600 : (int)(this.compositionSurface.Height * this.scaleFactor.Ratio);
  2347. int x = (rc.Width < width) ? this.panel.AutoScrollPosition.X + offsetHalfW : (rc.Width - width) / 2;
  2348. int y = (rc.Height < height) ? this.panel.AutoScrollPosition.Y + offsetHalfH : (rc.Height - height) / 2;
  2349. return new Point(
  2350. (int)((point.X - x) / this.scaleFactor.Ratio),
  2351. (int)((point.Y - y) / this.scaleFactor.Ratio)
  2352. );
  2353. }
  2354. /// <summary>
  2355. /// 设置当前鼠标的状态
  2356. /// </summary>
  2357. /// <param name="status"></param>
  2358. public void SetMouseStatus(bool status)
  2359. {
  2360. this.mouseStatus = status;
  2361. }
  2362. /// <summary>
  2363. /// 获取当前鼠标的状态
  2364. /// </summary>
  2365. public bool GetMouseStatus()
  2366. {
  2367. return this.mouseStatus;
  2368. }
  2369. #endregion
  2370. #region 初始化控件
  2371. private void InitializeComponent()
  2372. {
  2373. this.components = new Container();
  2374. this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
  2375. this.topRuler = new Ruler();
  2376. this.leftRuler = new Ruler();
  2377. this.panel = new PanelEx();
  2378. this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  2379. this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
  2380. this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
  2381. this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
  2382. //this.panelBottom = new PanelBottom();
  2383. //this.panelBottom.SuspendLayout();
  2384. this.panel.SuspendLayout();
  2385. this.contextMenuStrip1.SuspendLayout();
  2386. this.SuspendLayout();
  2387. //
  2388. // topRuler
  2389. //
  2390. this.topRuler.BackColor = Color.White;
  2391. this.topRuler.Dock = DockStyle.Top;
  2392. this.topRuler.Location = new Point(0, 0);
  2393. this.topRuler.Name = "topRuler";
  2394. this.topRuler.Offset = -16;
  2395. this.topRuler.Size = UI.ScaleSize(new Size(384, 16));
  2396. this.topRuler.TabIndex = 3;
  2397. //
  2398. // leftRuler
  2399. //
  2400. this.leftRuler.BackColor = Color.White;
  2401. this.leftRuler.Dock = DockStyle.Left;
  2402. this.leftRuler.Location = new Point(0, 16);
  2403. this.leftRuler.Name = "leftRuler";
  2404. this.leftRuler.Orientation = Orientation.Vertical;
  2405. this.leftRuler.Size = UI.ScaleSize(new Size(16, 304));
  2406. this.leftRuler.TabIndex = 4;
  2407. //
  2408. // panel
  2409. //
  2410. this.panel.ContextMenuStrip = this.contextMenuStrip1;
  2411. this.panel.AutoScroll = true;
  2412. this.panel.Dock = DockStyle.Fill;
  2413. this.panel.Location = new Point(16, 16);
  2414. this.panel.Name = "panel";
  2415. this.panel.ScrollPosition = new Point(0, 0);
  2416. this.panel.Size = new Size(368, 304);
  2417. this.panel.TabIndex = 5;
  2418. this.panel.AllowDrop = false;
  2419. this.panel.Scroll += new ScrollEventHandler(this.Panel_Scroll);
  2420. this.panel.KeyDown += new KeyEventHandler(Panel_KeyDown);
  2421. this.panel.KeyUp += new KeyEventHandler(Panel_KeyUp);
  2422. this.panel.KeyPress += new KeyPressEventHandler(Panel_KeyPress);
  2423. this.panel.GotFocus += new EventHandler(Panel_GotFocus);
  2424. this.panel.LostFocus += new EventHandler(Panel_LostFocus);
  2425. //
  2426. // contextMenuStrip1
  2427. //
  2428. this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  2429. this.toolStripMenuItem1,
  2430. this.toolStripMenuItem2,
  2431. this.toolStripMenuItem3,
  2432. this.toolStripMenuItem4});
  2433. this.contextMenuStrip1.Name = "contextMenuStrip1";
  2434. this.contextMenuStrip1.Size = new System.Drawing.Size(69, 48);
  2435. //this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStrip1_Opening);
  2436. this.contextMenuStrip1.Visible = false;
  2437. //
  2438. //
  2439. // toolStripMenuItem1
  2440. //
  2441. this.toolStripMenuItem1.Name = "toolStripMenuItem1";
  2442. this.toolStripMenuItem1.Text = "测量线设置";
  2443. this.toolStripMenuItem1.Size = new System.Drawing.Size(68, 22);
  2444. this.toolStripMenuItem1.Click += new System.EventHandler(this.ToolStripMenuItem1_Click);
  2445. this.toolStripMenuItem1.Visible = false;
  2446. //
  2447. // toolStripMenuItem2
  2448. //
  2449. this.toolStripMenuItem2.Name = "toolStripMenuItem2";
  2450. this.toolStripMenuItem2.Text = "测量区域设置";
  2451. this.toolStripMenuItem2.Size = new System.Drawing.Size(68, 22);
  2452. this.toolStripMenuItem2.Click += new System.EventHandler(this.ToolStripMenuItem2_Click);
  2453. this.toolStripMenuItem2.Visible = false;
  2454. //
  2455. // toolStripMenuItem3
  2456. //
  2457. this.toolStripMenuItem3.Name = "toolStripMenuItem3";
  2458. this.toolStripMenuItem3.Text = PdnResources.GetString("Menu.3celaing.Text");
  2459. this.toolStripMenuItem3.Size = new System.Drawing.Size(68, 22);
  2460. this.toolStripMenuItem3.Click += new System.EventHandler(this.ToolStripMenuItem3_Click);
  2461. this.toolStripMenuItem3.Visible = false;
  2462. //
  2463. // toolStripMenuItem4
  2464. //
  2465. this.toolStripMenuItem4.Name = "toolStripMenuItem4";
  2466. this.toolStripMenuItem4.Text = PdnResources.GetString("Menu.biaozhushuxing.Text");
  2467. this.toolStripMenuItem4.Size = new System.Drawing.Size(68, 22);
  2468. this.toolStripMenuItem4.Click += new System.EventHandler(this.ToolStripMenuItem4_Click);
  2469. this.toolStripMenuItem4.Visible = false;
  2470. // 底部的panelBottom
  2471. //
  2472. /*this.panelBottom.Size = new Size(384, 30);
  2473. this.panelBottom.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
  2474. this.panelBottom.Dock = DockStyle.Bottom;
  2475. this.panelBottom.trackBar.ValueChanged += new EventHandler(this.PanelBottom_trackBar_ValueChanged);
  2476. this.panelBottom.BackColor = Color.FromArgb(240, 240, 240);*/
  2477. //
  2478. // DocumentView
  2479. //
  2480. this.Controls.Add(this.panel);
  2481. this.Controls.Add(this.leftRuler);
  2482. this.Controls.Add(this.topRuler);
  2483. //this.Controls.Add(this.panelBottom);
  2484. this.Name = "DocumentView";
  2485. this.Size = new System.Drawing.Size(384, 320);
  2486. this.panel.ResumeLayout(false);
  2487. //this.panelBottom.ResumeLayout(false);
  2488. this.contextMenuStrip1.ResumeLayout(false);
  2489. this.ResumeLayout(false);
  2490. }
  2491. public void ShowContextMenuStrip1()
  2492. {
  2493. if (toolNumber == 0)
  2494. {
  2495. contextMenuStrip1.Visible = false;
  2496. this.toolStripMenuItem1.Visible = false;
  2497. this.toolStripMenuItem2.Visible = false;
  2498. this.toolStripMenuItem3.Visible = false;
  2499. this.toolStripMenuItem4.Visible = false;
  2500. }
  2501. else if (toolNumber == 1)
  2502. {
  2503. contextMenuStrip1.Visible = true;
  2504. this.toolStripMenuItem1.Visible = true;
  2505. this.toolStripMenuItem2.Visible = false;
  2506. this.toolStripMenuItem3.Visible = false;
  2507. this.toolStripMenuItem4.Visible = false;
  2508. }
  2509. else if (toolNumber == 2)
  2510. {
  2511. contextMenuStrip1.Visible = true;
  2512. this.toolStripMenuItem1.Visible = false;
  2513. this.toolStripMenuItem2.Visible = true;
  2514. this.toolStripMenuItem3.Visible = false;
  2515. this.toolStripMenuItem4.Visible = false;
  2516. }
  2517. else
  2518. {
  2519. contextMenuStrip1.Visible = false;
  2520. this.toolStripMenuItem1.Visible = false;
  2521. this.toolStripMenuItem2.Visible = false;
  2522. this.toolStripMenuItem3.Visible = false;
  2523. this.toolStripMenuItem4.Visible = false;
  2524. }
  2525. }
  2526. #endregion
  2527. #region 设定图片位置
  2528. // add by maxb 20200716
  2529. /// <summary>
  2530. /// 图片位置坐标
  2531. /// </summary>
  2532. private bool m_center = true;
  2533. private int m_pTop = 0;
  2534. private int m_pLeft = 0;
  2535. private int m_initTop = 0;
  2536. private int m_initLeft = 0;
  2537. public void SetDocumentPoint(int x, int y)
  2538. {
  2539. m_center = false;
  2540. m_initLeft = x;
  2541. m_initTop = y;
  2542. UpdateImgLocation();
  2543. this.Refresh();
  2544. }
  2545. public void SetCenter(bool center)
  2546. {
  2547. m_center = center;
  2548. }
  2549. private void UpdateImgLocation()
  2550. {
  2551. if (!m_center)
  2552. {
  2553. //Console.WriteLine("m_pLeft: " + m_initLeft + " Ratio:" + this.scaleFactor.Ratio);
  2554. m_pLeft = 16 + (int)(m_initLeft * this.scaleFactor.Ratio);
  2555. m_pTop = 16 + (int)(m_initTop * this.scaleFactor.Ratio);
  2556. //Console.WriteLine("Location: " + m_pLeft + " " + m_pTop);
  2557. }
  2558. }
  2559. #endregion
  2560. #region 工艺图比照
  2561. private RectangleF m_artworkImageRectangle;
  2562. private Bitmap m_selectedBitmap;
  2563. /// <summary>
  2564. /// 工艺比照定位点图像绘制
  2565. /// </summary>
  2566. /// <param name="bitmap"></param>
  2567. /// <param name="rectangle"></param>
  2568. public void SetSelectedBitmap(Bitmap bitmap, RectangleF rectangle)
  2569. {
  2570. m_selectedBitmap = bitmap;
  2571. m_artworkImageRectangle = Rectangle.Ceiling(rectangle);
  2572. this.Refresh();
  2573. }
  2574. #endregion
  2575. #region 图像拼接
  2576. /// <summary>
  2577. /// 生成自定义拼图区域
  2578. /// </summary>
  2579. /// <param name="width"></param>
  2580. /// <param name="height"></param>
  2581. public void CreateStitchingRectangle(int width, int height)
  2582. {
  2583. int x = m_pLeft;
  2584. int y = m_pTop;
  2585. }
  2586. /// <summary>
  2587. /// 获取对应标尺上的坐标点
  2588. /// </summary>
  2589. /// <param name="point"></param>
  2590. /// <returns></returns>
  2591. public PointF GetRulerPointInPanel(PointF point)
  2592. {
  2593. return new PointF(
  2594. (float)((point.X - 16) / this.scaleFactor.Ratio),
  2595. (float)((point.Y - 16) / this.scaleFactor.Ratio)
  2596. );
  2597. }
  2598. public PointF ScalePointToRulerPoint(PointF point)
  2599. {
  2600. Point originPoint = GetCalcOriginPoint();
  2601. return new PointF(
  2602. (float)((point.X * this.scaleFactor.Ratio + originPoint.X - 16) / this.scaleFactor.Ratio),
  2603. (float)((point.Y * this.scaleFactor.Ratio + originPoint.Y - 16) / this.scaleFactor.Ratio)
  2604. );
  2605. }
  2606. /// <summary>
  2607. /// 是否开启鼠标左键双击移动视场
  2608. /// </summary>
  2609. public bool ViewMoveOnMouseLeftDoubleClickEnable
  2610. {
  2611. get; set;
  2612. }
  2613. #endregion
  2614. #region 右键属性
  2615. /// <summary>
  2616. /// 判断右键的工具
  2617. /// </summary>
  2618. public int ToolNumber
  2619. {
  2620. set
  2621. {
  2622. this.toolNumber = value;
  2623. }
  2624. }
  2625. public LabelStyleModel.DrawAnalysisModel AnalysisStyleModel { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  2626. /// <summary>
  2627. /// 设置右键菜单的选项
  2628. /// </summary>
  2629. /// <param name="sender"></param>
  2630. /// <param name="e"></param>
  2631. private void ContextMenuStrip1_Opening(object sender, CancelEventArgs e)
  2632. {
  2633. if (toolNumber == 0)
  2634. {
  2635. contextMenuStrip1.Visible = false;
  2636. this.toolStripMenuItem1.Visible = false;
  2637. this.toolStripMenuItem2.Visible = false;
  2638. this.toolStripMenuItem3.Visible = false;
  2639. this.toolStripMenuItem4.Visible = false;
  2640. }
  2641. else if (toolNumber == 1)
  2642. {
  2643. contextMenuStrip1.Visible = true;
  2644. this.toolStripMenuItem1.Visible = true;
  2645. this.toolStripMenuItem2.Visible = false;
  2646. this.toolStripMenuItem3.Visible = false;
  2647. this.toolStripMenuItem4.Visible = false;
  2648. }
  2649. else if (toolNumber == 2)
  2650. {
  2651. contextMenuStrip1.Visible = true;
  2652. this.toolStripMenuItem1.Visible = false;
  2653. this.toolStripMenuItem2.Visible = true;
  2654. this.toolStripMenuItem3.Visible = false;
  2655. this.toolStripMenuItem4.Visible = false;
  2656. }
  2657. else
  2658. {
  2659. contextMenuStrip1.Visible = false;
  2660. this.toolStripMenuItem1.Visible = false;
  2661. this.toolStripMenuItem2.Visible = false;
  2662. this.toolStripMenuItem3.Visible = false;
  2663. this.toolStripMenuItem4.Visible = false;
  2664. }
  2665. }
  2666. /// <summary>
  2667. /// 右键菜单(测量设置)
  2668. /// </summary>
  2669. /// <param name="sender"></param>
  2670. /// <param name="e"></param>
  2671. public virtual void ToolStripMenuItem1_Click(object sender, EventArgs e)
  2672. {
  2673. }
  2674. /// <summary>
  2675. /// 右键菜单(标注设置)
  2676. /// </summary>
  2677. /// <param name="sender"></param>
  2678. /// <param name="e"></param>
  2679. public virtual void ToolStripMenuItem2_Click(object sender, EventArgs e)
  2680. {
  2681. }
  2682. /// <summary>
  2683. /// 右键菜单(测量属性)
  2684. /// </summary>
  2685. /// <param name="sender"></param>
  2686. /// <param name="e"></param>
  2687. public virtual void ToolStripMenuItem3_Click(object sender, EventArgs e)
  2688. {
  2689. }
  2690. /// <summary>
  2691. /// 右键菜单(标注属性)
  2692. /// </summary>
  2693. /// <param name="sender"></param>
  2694. /// <param name="e"></param>
  2695. public virtual void ToolStripMenuItem4_Click(object sender, EventArgs e)
  2696. {
  2697. }
  2698. #endregion
  2699. /// <summary>
  2700. /// 初始化标尺信息,图片对应的xml中读取
  2701. /// 然后根据标尺的单位,换算出所有单位的数据
  2702. /// </summary>
  2703. public void InitRulerInfo()
  2704. {
  2705. this.rules.Clear();
  2706. if (this.xmlSaveModel != null && this.xmlSaveModel.pixel_length != 0)
  2707. {
  2708. //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
  2709. double unitLength = (double)(this.xmlSaveModel.physical_length / (decimal)this.xmlSaveModel.pixel_length);
  2710. switch (this.xmlSaveModel.ruler_units)
  2711. {
  2712. case (int)MeasurementUnit.Inch://英寸
  2713. this.rules.Add(MeasurementUnit.Inch, unitLength); //英寸
  2714. this.rules.Add(MeasurementUnit.Mil, 1000 * unitLength); //米尔
  2715. this.rules.Add(MeasurementUnit.Centimeter, 2.54 * unitLength); //厘米
  2716. this.rules.Add(MeasurementUnit.Millimeter, 25.4 * unitLength); //毫米
  2717. this.rules.Add(MeasurementUnit.Micron, 25400 * unitLength); //微米
  2718. this.rules.Add(MeasurementUnit.Nano, 25400000 * unitLength); //纳米
  2719. break;
  2720. case (int)MeasurementUnit.Mil://米尔
  2721. this.rules.Add(MeasurementUnit.Inch, 0.001 * unitLength); //英寸
  2722. this.rules.Add(MeasurementUnit.Mil, unitLength); //米尔
  2723. this.rules.Add(MeasurementUnit.Centimeter, 0.00254 * unitLength); //厘米
  2724. this.rules.Add(MeasurementUnit.Millimeter, 0.0254 * unitLength); //毫米
  2725. this.rules.Add(MeasurementUnit.Micron, 25.4 * unitLength); //微米
  2726. this.rules.Add(MeasurementUnit.Nano, 25400 * unitLength); //纳米
  2727. break;
  2728. case (int)MeasurementUnit.Centimeter://厘米
  2729. this.rules.Add(MeasurementUnit.Inch, 0.3937008 * unitLength); //英寸
  2730. this.rules.Add(MeasurementUnit.Mil, 393.7008 * unitLength); //米尔
  2731. this.rules.Add(MeasurementUnit.Centimeter, unitLength); //厘米
  2732. this.rules.Add(MeasurementUnit.Millimeter, 10 * unitLength); //毫米
  2733. this.rules.Add(MeasurementUnit.Micron, 10000 * unitLength); //微米
  2734. this.rules.Add(MeasurementUnit.Nano, 10000000 * unitLength); //纳米
  2735. break;
  2736. case (int)MeasurementUnit.Millimeter://毫米
  2737. this.rules.Add(MeasurementUnit.Inch, 0.0393701 * unitLength); //英寸
  2738. this.rules.Add(MeasurementUnit.Mil, 39.3701 * unitLength); //米尔
  2739. this.rules.Add(MeasurementUnit.Centimeter, 0.1 * unitLength); //厘米
  2740. this.rules.Add(MeasurementUnit.Millimeter, unitLength); //毫米
  2741. this.rules.Add(MeasurementUnit.Micron, 1000 * unitLength); //微米
  2742. this.rules.Add(MeasurementUnit.Nano, 1000000 * unitLength); //纳米
  2743. break;
  2744. case (int)MeasurementUnit.Micron://微米
  2745. this.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
  2746. this.rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔
  2747. this.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
  2748. this.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
  2749. this.rules.Add(MeasurementUnit.Micron, unitLength); //微米
  2750. this.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
  2751. break;
  2752. case (int)MeasurementUnit.Nano://纳米
  2753. this.rules.Add(MeasurementUnit.Inch, 3.9370e-8 * unitLength); //英寸
  2754. this.rules.Add(MeasurementUnit.Mil, 3.9370e-5 * unitLength); //米尔
  2755. this.rules.Add(MeasurementUnit.Centimeter, 1e-7 * unitLength); //厘米
  2756. this.rules.Add(MeasurementUnit.Millimeter, 1e-6 * unitLength); //毫米
  2757. this.rules.Add(MeasurementUnit.Micron, 0.001 * unitLength); //微米
  2758. this.rules.Add(MeasurementUnit.Nano, unitLength); //纳米
  2759. break;
  2760. default:
  2761. this.xmlSaveModel = null;
  2762. break;
  2763. }
  2764. }
  2765. if (this.xmlSaveModel == null || this.xmlSaveModel.physical_length == 0)
  2766. {
  2767. //如果没有标尺的时候,默认1微米/像素
  2768. this.rules.Add(MeasurementUnit.Inch, 0.0000394); //英寸
  2769. this.rules.Add(MeasurementUnit.Mil, 0.0394); //米尔
  2770. this.rules.Add(MeasurementUnit.Centimeter, 0.0001); //厘米
  2771. this.rules.Add(MeasurementUnit.Millimeter, 0.001); //毫米
  2772. this.rules.Add(MeasurementUnit.Micron, 1); //微米
  2773. this.rules.Add(MeasurementUnit.Nano, 1000); //纳米
  2774. this.xmlSaveModel = new mic_rulers();
  2775. this.xmlSaveModel.ruler_name = PdnResources.GetString("Menu.Unselectedruler.Text");
  2776. this.xmlSaveModel.gain_multiple = 1;
  2777. this.xmlSaveModel.physical_length = 100;
  2778. this.xmlSaveModel.pixel_length = 100;
  2779. this.xmlSaveModel.ruler_units = (int)((MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), this.getRulerList()[0]));
  2780. }
  2781. //设置文档标尺
  2782. Document.defaultDpi = 1 / rules[MeasurementUnit.Inch];
  2783. }
  2784. /// <summary>
  2785. /// 获取系统当前选中单位及每单位像素值
  2786. /// </summary>
  2787. /// <returns>3位字符串数组,
  2788. /// 0:系统选中单位枚举字符串
  2789. /// 1:系统选中单位名称字符串
  2790. /// 2:系统选中单位符号字符串
  2791. /// 3:系统选中单位每单位像素长度
  2792. /// 4:系统选中单位每单位物理长度
  2793. /// </returns>
  2794. protected virtual string[] startUpRules(Dictionary<MeasurementUnit, double> rules)
  2795. {
  2796. return new string[] { };
  2797. }
  2798. /// <summary>
  2799. /// 提供获取系统当前选中单位及每单位像素值公共方法
  2800. /// </summary>
  2801. /// <returns></returns>
  2802. public string[] getRulerList()
  2803. {
  2804. return startUpRules(this.rules.Count > 0 ? this.rules : null);
  2805. }
  2806. /// <summary>
  2807. /// 获取单位标尺
  2808. /// </summary>
  2809. /// <param name="measurementUnit">度量单位的枚举</param>
  2810. /// <returns></returns>
  2811. public double GetRuler(MeasurementUnit measurementUnit)
  2812. {
  2813. double unitLength = 0;
  2814. //判断当前图片是否有对应的标尺
  2815. if (this.rules.Count > 0)
  2816. {
  2817. this.rules.TryGetValue(measurementUnit, out unitLength);
  2818. }
  2819. else
  2820. {
  2821. this.appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
  2822. }
  2823. return unitLength;
  2824. }
  2825. /// <summary>
  2826. /// 获取放大倍数
  2827. /// </summary>
  2828. /// <returns></returns>
  2829. public double GetMultiple()
  2830. {
  2831. double multiple = 1;
  2832. if (this.xmlSaveModel != null)
  2833. {
  2834. multiple = (double)this.xmlSaveModel.gain_multiple;
  2835. }
  2836. return multiple;
  2837. }
  2838. /// <summary>
  2839. /// 获取单位标尺乘以放大倍数
  2840. /// </summary>
  2841. /// <param name="measurementUnit">度量单位的枚举</param>
  2842. /// <returns></returns>
  2843. public double GetRulerMultiple(MeasurementUnit measurementUnit)
  2844. {
  2845. double unitLength = 0;
  2846. double multiple = 0;
  2847. //判断当前图片是否有对应的标尺
  2848. if (this.rules.Count > 0)
  2849. {
  2850. this.rules.TryGetValue(measurementUnit, out unitLength);
  2851. }
  2852. else
  2853. {
  2854. this.appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
  2855. }
  2856. if (this.xmlSaveModel != null)
  2857. {
  2858. multiple = (double)this.xmlSaveModel.gain_multiple;
  2859. }
  2860. return unitLength * multiple;
  2861. }
  2862. public void IsDirty(GraphicsList gList)
  2863. {
  2864. this.AdjustRendering();
  2865. }
  2866. public RectangleF GetVisibleDocumentRectangleF()
  2867. {
  2868. return this.VisibleDocumentRectangleF;
  2869. //return this.AppWorkspaceTop.GetVisibleDocumentRectangleF();
  2870. }
  2871. public SizeF GetDocumentSize()
  2872. {
  2873. if (this.Document == null) {
  2874. return new SizeF(0, 0);
  2875. }
  2876. return this.Document.Size;
  2877. //return this.AppWorkspaceTop.GetDocumentSize();
  2878. }
  2879. public void SetDirty()
  2880. {
  2881. this.Document.Dirty = true;
  2882. }
  2883. public int UnscaleScalar(int deltaX)
  2884. {
  2885. return this.scaleFactor.UnscaleScalar(deltaX);
  2886. }
  2887. public PointF GetDocumentScrollPositionF()
  2888. {
  2889. return this.DocumentScrollPositionF;
  2890. }
  2891. public void SetDocumentScrollPositionF(PointF newScrollPos)
  2892. {
  2893. Point sbClient = Point.Round(newScrollPos);
  2894. if (this.panel.AutoScrollPosition != new Point(-sbClient.X, -sbClient.Y))
  2895. {
  2896. this.panel.AutoScrollPosition = sbClient;
  2897. UpdateRulerOffsets();
  2898. //this.panelBottom.Invalidate();
  2899. this.topRuler.Invalidate();
  2900. this.leftRuler.Invalidate();
  2901. }
  2902. }
  2903. public string[] GetPxPerUnit()
  2904. {
  2905. return this.AppWorkspaceTop.GetPxPerUnit();
  2906. }
  2907. public Dictionary<int, string> GetUnitsDictionary()
  2908. {
  2909. return InvariantData.unitsDictionary;
  2910. }
  2911. public Dictionary<int, string> GetUnitSymbolsDictionary()
  2912. {
  2913. return InvariantData.unitSymbolsDictionary;
  2914. }
  2915. public CombineMode GetCombineMode()
  2916. {
  2917. return this.AppWorkspaceTop.GetCombineMode();
  2918. }
  2919. bool ISurfaceBox.ContinuousDrawingMeasure()
  2920. {
  2921. return ContinuousDrawingMeasure;
  2922. }
  2923. bool ISurfaceBox.ContinuousDrawingView()
  2924. {
  2925. return ContinuousDrawingView;
  2926. }
  2927. public void SetContinuousDrawingVoid(bool v)
  2928. {
  2929. ContinuousDrawingView = v;
  2930. appWorkspace.SetContinuousDrawingView(v);
  2931. }
  2932. public void SetContinuousDrawingMeasure(bool v)
  2933. {
  2934. ContinuousDrawingMeasure = v;
  2935. appWorkspace.SetContinuousDrawingMeasure(v);
  2936. }
  2937. public LabelStyleModel GetLabelStyleModel()
  2938. {
  2939. throw new NotImplementedException();
  2940. }
  2941. public MeasureStyleModel GetMeasureStyleModel()
  2942. {
  2943. return this.AppWorkspaceTop.GetMeasureStyleModel();
  2944. }
  2945. public Dictionary<MeasurementUnit, double> getMeasureInfo()
  2946. {
  2947. if (this.rules.Count > 0)
  2948. return this.rules;
  2949. else
  2950. return this.AppWorkspaceTop.getMeasureInfo();
  2951. }
  2952. public void UpdateContinueNum()
  2953. {
  2954. this.AppWorkspaceTop.UpdateContinueNum();
  2955. }
  2956. bool ISurfaceBox.DeleteFieldOfView()
  2957. {
  2958. return DeleteFieldOfView;
  2959. }
  2960. public MeasureAreaModel GetMeasureAreaModel()
  2961. {
  2962. return this.AppWorkspaceTop.GetMeasureAreaModel();
  2963. }
  2964. public mic_rulers RuleAttribute(PicConfigModel PicConfigModel)
  2965. {
  2966. this.xmlSaveModel = new mic_rulers();
  2967. this.xmlSaveModel.ruler_name = PicConfigModel.rule.ruler_name;
  2968. this.xmlSaveModel.gain_multiple = PicConfigModel.rule.gain_multiple;
  2969. this.xmlSaveModel.pixel_length = PicConfigModel.rule.pixel_length;
  2970. this.xmlSaveModel.physical_length = PicConfigModel.rule.physical_length;
  2971. this.xmlSaveModel.ruler_units = PicConfigModel.rule.ruler_units;
  2972. InitRulerInfo();
  2973. this.existenceXML = true;
  2974. return this.xmlSaveModel;
  2975. }
  2976. public double getUnitNum()
  2977. {
  2978. this.unitNum = this.AppWorkspaceTop.getUnitNum();
  2979. return this.unitNum;
  2980. }
  2981. public string getAliasName()
  2982. {
  2983. this.aliasName = this.AppWorkspaceTop.getAliasName();
  2984. return this.aliasName;
  2985. }
  2986. public int getDecimalPlaces()
  2987. {
  2988. this.decimalPlaces = this.AppWorkspaceTop.getDecimalPlaces();
  2989. return this.decimalPlaces;
  2990. }
  2991. }
  2992. }