SRWindow.cs 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Diagnostics;
  11. using System.Runtime.InteropServices;
  12. using Tao.OpenGl;
  13. using Tao.Platform.Windows;
  14. using OpenCvSharp;
  15. using System.Xml;
  16. using Size = System.Drawing.Size;
  17. using PaintDotNet.Base.CommTool;
  18. namespace PaintDotNet.Instrument
  19. {
  20. public partial class SRWindow : PdnBaseForm
  21. {
  22. private GroupBox groupBox1;
  23. private GroupBox groupBox2;
  24. private Button button9;
  25. private Button button8;
  26. private Button button2;
  27. private Button button1;
  28. private Button button6;
  29. private Button button5;
  30. private Button button4;
  31. // --- Fields ---
  32. private static IntPtr hDC; // Private GDI Device Context
  33. private static IntPtr hRC; // Permanent Rendering Context
  34. private static SRWindow form; // Our Current Windows Form
  35. //private static bool[] keys = new bool[256]; // Array Used For The Keyboard Routine
  36. private static bool active = true; // Window Active Flag, Set To True By Default
  37. private static bool done = false; // Bool Variable To Exit Main Loop
  38. private AppWorkspace appWorkspace;
  39. /// <summary>
  40. /// 三维数据
  41. /// </summary>
  42. private Base.SettingModel.ThreeDataDemoModel threeDataDemo;
  43. //for XML
  44. int m_iWidth;
  45. int m_iHeight;
  46. int m_iDLevel;
  47. double[] m_adDZ;
  48. double[,] m_adDC;
  49. double[,] m_adZV;
  50. double[,] m_adOverTurnZV;
  51. double m_dMaxZV;
  52. double m_dMinZV;
  53. float[, ,] m_afNewClr;
  54. //bmp
  55. float[, ,] m_afOrgClr;
  56. //new platform
  57. private System.Windows.Forms.PictureBox pictureBox1;
  58. int m_iMusDown = 0;
  59. //zzz
  60. public static/* const*/ int LINE_PNTS = 100;
  61. //Glfw.GLFWkeyfun m_funKeyCallBak;
  62. //Glfw.GLFWmousebuttonfun m_funMsBtnCallBak;
  63. //Glfw.GLFWmouseposfun m_funMsPosCallBak;
  64. int m_iMusMod = 0;
  65. int m_iLastmouseX, m_iLastmouseY;
  66. int m_iLastMusDown = 0;
  67. float[] m_fR_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
  68. float[] m_fT_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
  69. bool m_bOverTurn = false;
  70. bool m_bRulerColor = true;
  71. float[] m_afPonitA = new float[2] { 1.0F, 1.0F };
  72. float[] m_afPonitB = new float[2] { 1.0F, 1.0F };
  73. float[] m_afLineStep = new float[2] { 0.0F, 0.0F };
  74. float[,] m_afLineXY = new float[/*LINE_PNTS - 2*/98, 2];
  75. double[] m_adLineZV = new double[/*LINE_PNTS*/100];
  76. double[] m_adLineOverTurnZV = new double[/*LINE_PNTS*/100];
  77. //SRLinesForm m_fmLine;
  78. float[, ,] m_afThisClr;
  79. double[,] m_adThisZV;
  80. private GroupBox groupBox3;
  81. private TrackBar trackBar1;
  82. private Panel panel2;
  83. private Panel panel1;
  84. private Label label3;
  85. private Label label2;
  86. private Label label1;
  87. private GroupBox groupBox4;
  88. private GroupBox groupBox5;
  89. private Button button3;
  90. private Button button7;
  91. private PictureBox pictureBox2;
  92. private Label label5;
  93. private Label label4;
  94. private Panel panel7;
  95. private Panel panel9;
  96. private Panel panel8;
  97. private Panel panel6;
  98. private Panel panel5;
  99. private Panel panel4;
  100. private Panel panel3;
  101. private Label label10;
  102. private Label label9;
  103. private Label label8;
  104. private Label label7;
  105. private Label label6;
  106. private RadioButton radioButton2;
  107. private RadioButton radioButton1;
  108. double[] m_adThisLineZV;
  109. internal SRWindow(AppWorkspace appWorkspace)
  110. {
  111. this.appWorkspace = appWorkspace;
  112. //
  113. //初始化色板
  114. //
  115. this.colorsFormGrid = new ColorsForm();
  116. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  117. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  118. InitializeComponent();
  119. InitializeLanguageText();
  120. this.CreateParams.ClassStyle = this.CreateParams.ClassStyle | // Redraw On Size, And Own DC For Window.
  121. User.CS_HREDRAW | User.CS_VREDRAW | User.CS_OWNDC;
  122. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // No Need To Erase Form Background
  123. this.SetStyle(ControlStyles.DoubleBuffer, true); // Buffer Control
  124. //zzz this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
  125. this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
  126. this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
  127. this.Activated += new EventHandler(this.Form_Activated); // On Activate Event Call Form_Activated
  128. this.Closing += new CancelEventHandler(this.Form_Closing); // On Closing Event Call Form_Closing
  129. this.Deactivate += new EventHandler(this.Form_Deactivate); // On Deactivate Event Call Form_Deactivate
  130. this.KeyDown += new KeyEventHandler(this.Form_KeyDown); // On KeyDown Event Call Form_KeyDown
  131. //this.KeyUp += new KeyEventHandler(this.Form_KeyUp); // On KeyUp Event Call Form_KeyUp
  132. this.Resize += new EventHandler(this.Form_Resize);
  133. //this.Close();
  134. ReadPar();
  135. }
  136. private void InitializeLanguageText()
  137. {
  138. this.groupBox1.Text = "三维图像";
  139. this.groupBox2.Text = "操作";// PdnResources.GetString("Menu.operation.text");
  140. this.button6.Text = "导出图片所有坐标对应的高度值";// PdnResources.GetString("Menu.Currentsoftware.text");
  141. this.button5.Text = "操作点A";// "添加测量线";// PdnResources.GetString("Menu.Theharddiskimage.Text");
  142. this.button4.Text = "操作点B";// "添加测量线";
  143. this.button2.Text = "平移图像";
  144. this.button1.Text = "旋转图像";
  145. this.button9.Text = "图像翻转";
  146. this.button8.Text = "高度彩虹色填充";
  147. //this.groupBox3.Text = "三维图像";
  148. this.Text = PdnResources.GetString("Menu.Tools.SurfacePlotShow.Text");
  149. }
  150. /// <summary>
  151. /// 初始化基础控件
  152. /// </summary>
  153. public void InitializeComponent()
  154. {
  155. this.groupBox1 = new System.Windows.Forms.GroupBox();
  156. this.button2 = new System.Windows.Forms.Button();
  157. this.button1 = new System.Windows.Forms.Button();
  158. this.button9 = new System.Windows.Forms.Button();
  159. this.button8 = new System.Windows.Forms.Button();
  160. this.groupBox2 = new System.Windows.Forms.GroupBox();
  161. this.button6 = new System.Windows.Forms.Button();
  162. this.button5 = new System.Windows.Forms.Button();
  163. this.button4 = new System.Windows.Forms.Button();
  164. this.groupBox3 = new System.Windows.Forms.GroupBox();
  165. this.trackBar1 = new System.Windows.Forms.TrackBar();
  166. this.panel2 = new System.Windows.Forms.Panel();
  167. this.panel1 = new System.Windows.Forms.Panel();
  168. this.label3 = new System.Windows.Forms.Label();
  169. this.label2 = new System.Windows.Forms.Label();
  170. this.label1 = new System.Windows.Forms.Label();
  171. this.groupBox4 = new System.Windows.Forms.GroupBox();
  172. this.radioButton2 = new System.Windows.Forms.RadioButton();
  173. this.radioButton1 = new System.Windows.Forms.RadioButton();
  174. this.panel3 = new System.Windows.Forms.Panel();
  175. this.panel4 = new System.Windows.Forms.Panel();
  176. this.label10 = new System.Windows.Forms.Label();
  177. this.label9 = new System.Windows.Forms.Label();
  178. this.label8 = new System.Windows.Forms.Label();
  179. this.label7 = new System.Windows.Forms.Label();
  180. this.label6 = new System.Windows.Forms.Label();
  181. this.label5 = new System.Windows.Forms.Label();
  182. this.label4 = new System.Windows.Forms.Label();
  183. this.panel7 = new System.Windows.Forms.Panel();
  184. this.panel9 = new System.Windows.Forms.Panel();
  185. this.panel8 = new System.Windows.Forms.Panel();
  186. this.panel6 = new System.Windows.Forms.Panel();
  187. this.panel5 = new System.Windows.Forms.Panel();
  188. this.groupBox5 = new System.Windows.Forms.GroupBox();
  189. this.pictureBox2 = new System.Windows.Forms.PictureBox();
  190. this.button3 = new System.Windows.Forms.Button();
  191. this.button7 = new System.Windows.Forms.Button();
  192. this.groupBox1.SuspendLayout();
  193. this.groupBox2.SuspendLayout();
  194. this.groupBox3.SuspendLayout();
  195. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  196. this.groupBox4.SuspendLayout();
  197. this.groupBox5.SuspendLayout();
  198. ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
  199. this.SuspendLayout();
  200. //
  201. // groupBox1
  202. //
  203. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  204. | System.Windows.Forms.AnchorStyles.Left)));
  205. this.groupBox1.Controls.Add(this.button2);
  206. this.groupBox1.Controls.Add(this.button1);
  207. this.groupBox1.Controls.Add(this.button9);
  208. this.groupBox1.Controls.Add(this.button8);
  209. this.groupBox1.Location = new System.Drawing.Point(20, 70);
  210. this.groupBox1.Margin = new System.Windows.Forms.Padding(4);
  211. this.groupBox1.Name = "groupBox1";
  212. this.groupBox1.Padding = new System.Windows.Forms.Padding(4);
  213. this.groupBox1.Size = new System.Drawing.Size(588, 424);
  214. this.groupBox1.TabIndex = 1;
  215. this.groupBox1.TabStop = false;
  216. //
  217. // button2
  218. //
  219. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  220. this.button2.Location = new System.Drawing.Point(407, 385);
  221. this.button2.Margin = new System.Windows.Forms.Padding(4);
  222. this.button2.Name = "button2";
  223. this.button2.Size = new System.Drawing.Size(84, 23);
  224. this.button2.TabIndex = 0;
  225. this.button2.Text = "平移图像";
  226. this.button2.UseVisualStyleBackColor = true;
  227. this.button2.Click += new System.EventHandler(this.button2_Click);
  228. //
  229. // button1
  230. //
  231. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  232. this.button1.Location = new System.Drawing.Point(315, 385);
  233. this.button1.Margin = new System.Windows.Forms.Padding(4);
  234. this.button1.Name = "button1";
  235. this.button1.Size = new System.Drawing.Size(84, 23);
  236. this.button1.TabIndex = 0;
  237. this.button1.Text = "旋转图像";
  238. this.button1.UseVisualStyleBackColor = true;
  239. this.button1.Click += new System.EventHandler(this.button1_Click);
  240. //
  241. // button9
  242. //
  243. this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  244. this.button9.Location = new System.Drawing.Point(98, 385);
  245. this.button9.Margin = new System.Windows.Forms.Padding(4);
  246. this.button9.Name = "button9";
  247. this.button9.Size = new System.Drawing.Size(84, 23);
  248. this.button9.TabIndex = 0;
  249. this.button9.Text = "图像翻转";
  250. this.button9.UseVisualStyleBackColor = true;
  251. this.button9.Click += new System.EventHandler(this.button9_Click);
  252. //
  253. // button8
  254. //
  255. this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  256. this.button8.Location = new System.Drawing.Point(190, 385);
  257. this.button8.Margin = new System.Windows.Forms.Padding(4);
  258. this.button8.Name = "button8";
  259. this.button8.Size = new System.Drawing.Size(117, 23);
  260. this.button8.TabIndex = 0;
  261. this.button8.Text = "高度彩虹色填充";
  262. this.button8.UseVisualStyleBackColor = true;
  263. this.button8.Click += new System.EventHandler(this.button8_Click);
  264. //
  265. // groupBox2
  266. //
  267. this.groupBox2.Controls.Add(this.button6);
  268. this.groupBox2.Controls.Add(this.button5);
  269. this.groupBox2.Controls.Add(this.button4);
  270. this.groupBox2.Location = new System.Drawing.Point(20, 13);
  271. this.groupBox2.Margin = new System.Windows.Forms.Padding(4);
  272. this.groupBox2.Name = "groupBox2";
  273. this.groupBox2.Padding = new System.Windows.Forms.Padding(4);
  274. this.groupBox2.Size = new System.Drawing.Size(853, 49);
  275. this.groupBox2.TabIndex = 1;
  276. this.groupBox2.TabStop = false;
  277. //
  278. // button6
  279. //
  280. this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  281. this.button6.Location = new System.Drawing.Point(470, 16);
  282. this.button6.Margin = new System.Windows.Forms.Padding(4);
  283. this.button6.Name = "button6";
  284. this.button6.Size = new System.Drawing.Size(191, 23);
  285. this.button6.TabIndex = 1;
  286. this.button6.Text = "导出图片所有坐标对应的高度值";
  287. this.button6.UseVisualStyleBackColor = true;
  288. this.button6.Click += new System.EventHandler(this.button6_Click);
  289. //
  290. // button5
  291. //
  292. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  293. this.button5.Location = new System.Drawing.Point(669, 16);
  294. this.button5.Margin = new System.Windows.Forms.Padding(4);
  295. this.button5.Name = "button5";
  296. this.button5.Size = new System.Drawing.Size(84, 23);
  297. this.button5.TabIndex = 0;
  298. this.button5.Text = "操作点A";
  299. this.button5.UseVisualStyleBackColor = true;
  300. this.button5.Click += new System.EventHandler(this.button5_Click);
  301. //
  302. // button4
  303. //
  304. this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  305. this.button4.Location = new System.Drawing.Point(761, 16);
  306. this.button4.Margin = new System.Windows.Forms.Padding(4);
  307. this.button4.Name = "button4";
  308. this.button4.Size = new System.Drawing.Size(84, 23);
  309. this.button4.TabIndex = 0;
  310. this.button4.Text = "操作点B";
  311. this.button4.UseVisualStyleBackColor = true;
  312. this.button4.Click += new System.EventHandler(this.button4_Click);
  313. //
  314. // groupBox3
  315. //
  316. this.groupBox3.Controls.Add(this.trackBar1);
  317. this.groupBox3.Controls.Add(this.panel2);
  318. this.groupBox3.Controls.Add(this.panel1);
  319. this.groupBox3.Controls.Add(this.label3);
  320. this.groupBox3.Controls.Add(this.label2);
  321. this.groupBox3.Controls.Add(this.label1);
  322. this.groupBox3.Location = new System.Drawing.Point(617, 71);
  323. this.groupBox3.Margin = new System.Windows.Forms.Padding(4);
  324. this.groupBox3.Name = "groupBox3";
  325. this.groupBox3.Padding = new System.Windows.Forms.Padding(4);
  326. this.groupBox3.Size = new System.Drawing.Size(257, 68);
  327. this.groupBox3.TabIndex = 2;
  328. this.groupBox3.TabStop = false;
  329. this.groupBox3.Text = "设置";
  330. //
  331. // trackBar1
  332. //
  333. this.trackBar1.AutoSize = false;
  334. this.trackBar1.Location = new System.Drawing.Point(79, 65);
  335. this.trackBar1.Name = "trackBar1";
  336. this.trackBar1.Size = new System.Drawing.Size(125, 24);
  337. this.trackBar1.TabIndex = 5;
  338. this.trackBar1.Visible = false;
  339. //
  340. // panel2
  341. //
  342. this.panel2.BackColor = System.Drawing.Color.Red;
  343. this.panel2.Location = new System.Drawing.Point(79, 44);
  344. this.panel2.Name = "panel2";
  345. this.panel2.Size = new System.Drawing.Size(125, 15);
  346. this.panel2.TabIndex = 4;
  347. //
  348. // panel1
  349. //
  350. this.panel1.BackColor = System.Drawing.Color.Black;
  351. this.panel1.Location = new System.Drawing.Point(79, 18);
  352. this.panel1.Name = "panel1";
  353. this.panel1.Size = new System.Drawing.Size(125, 15);
  354. this.panel1.TabIndex = 3;
  355. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  356. //
  357. // label3
  358. //
  359. this.label3.AutoSize = true;
  360. this.label3.Location = new System.Drawing.Point(8, 69);
  361. this.label3.Name = "label3";
  362. this.label3.Size = new System.Drawing.Size(65, 12);
  363. this.label3.TabIndex = 2;
  364. this.label3.Text = "调整滤波:";
  365. this.label3.Visible = false;
  366. //
  367. // label2
  368. //
  369. this.label2.AutoSize = true;
  370. this.label2.Location = new System.Drawing.Point(8, 45);
  371. this.label2.Name = "label2";
  372. this.label2.Size = new System.Drawing.Size(65, 12);
  373. this.label2.TabIndex = 1;
  374. this.label2.Text = "坐标颜色:";
  375. //
  376. // label1
  377. //
  378. this.label1.AutoSize = true;
  379. this.label1.Location = new System.Drawing.Point(8, 21);
  380. this.label1.Name = "label1";
  381. this.label1.Size = new System.Drawing.Size(65, 12);
  382. this.label1.TabIndex = 0;
  383. this.label1.Text = "背景颜色:";
  384. //
  385. // groupBox4
  386. //
  387. this.groupBox4.Controls.Add(this.radioButton2);
  388. this.groupBox4.Controls.Add(this.radioButton1);
  389. this.groupBox4.Controls.Add(this.panel3);
  390. this.groupBox4.Controls.Add(this.panel4);
  391. this.groupBox4.Controls.Add(this.label10);
  392. this.groupBox4.Controls.Add(this.label9);
  393. this.groupBox4.Controls.Add(this.label8);
  394. this.groupBox4.Controls.Add(this.label7);
  395. this.groupBox4.Controls.Add(this.label6);
  396. this.groupBox4.Controls.Add(this.label5);
  397. this.groupBox4.Controls.Add(this.label4);
  398. this.groupBox4.Controls.Add(this.panel7);
  399. this.groupBox4.Controls.Add(this.panel9);
  400. this.groupBox4.Controls.Add(this.panel8);
  401. this.groupBox4.Controls.Add(this.panel6);
  402. this.groupBox4.Controls.Add(this.panel5);
  403. this.groupBox4.Location = new System.Drawing.Point(617, 149);
  404. this.groupBox4.Margin = new System.Windows.Forms.Padding(4);
  405. this.groupBox4.Name = "groupBox4";
  406. this.groupBox4.Padding = new System.Windows.Forms.Padding(4);
  407. this.groupBox4.Size = new System.Drawing.Size(255, 138);
  408. this.groupBox4.TabIndex = 6;
  409. this.groupBox4.TabStop = false;
  410. this.groupBox4.Text = "彩虹色范围设置";
  411. //
  412. // radioButton2
  413. //
  414. this.radioButton2.AutoSize = true;
  415. this.radioButton2.Location = new System.Drawing.Point(114, 22);
  416. this.radioButton2.Name = "radioButton2";
  417. this.radioButton2.Size = new System.Drawing.Size(53, 16);
  418. this.radioButton2.TabIndex = 17;
  419. this.radioButton2.Text = "主题2";
  420. this.radioButton2.UseVisualStyleBackColor = true;
  421. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
  422. //
  423. // radioButton1
  424. //
  425. this.radioButton1.AutoSize = true;
  426. this.radioButton1.Checked = true;
  427. this.radioButton1.Location = new System.Drawing.Point(12, 22);
  428. this.radioButton1.Name = "radioButton1";
  429. this.radioButton1.Size = new System.Drawing.Size(53, 16);
  430. this.radioButton1.TabIndex = 0;
  431. this.radioButton1.TabStop = true;
  432. this.radioButton1.Text = "主题1";
  433. this.radioButton1.UseVisualStyleBackColor = true;
  434. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  435. //
  436. // panel3
  437. //
  438. this.panel3.BackColor = System.Drawing.Color.Lime;
  439. this.panel3.Location = new System.Drawing.Point(45, 44);
  440. this.panel3.Name = "panel3";
  441. this.panel3.Size = new System.Drawing.Size(58, 15);
  442. this.panel3.TabIndex = 4;
  443. this.panel3.Click += new System.EventHandler(this.panel1_Click);
  444. //
  445. // panel4
  446. //
  447. this.panel4.BackColor = System.Drawing.Color.Red;
  448. this.panel4.Location = new System.Drawing.Point(45, 66);
  449. this.panel4.Name = "panel4";
  450. this.panel4.Size = new System.Drawing.Size(58, 15);
  451. this.panel4.TabIndex = 5;
  452. this.panel4.Click += new System.EventHandler(this.panel1_Click);
  453. //
  454. // label10
  455. //
  456. this.label10.AutoSize = true;
  457. this.label10.Location = new System.Drawing.Point(114, 116);
  458. this.label10.Name = "label10";
  459. this.label10.Size = new System.Drawing.Size(53, 12);
  460. this.label10.TabIndex = 16;
  461. this.label10.Text = "Range5:";
  462. //
  463. // label9
  464. //
  465. this.label9.AutoSize = true;
  466. this.label9.Location = new System.Drawing.Point(114, 99);
  467. this.label9.Name = "label9";
  468. this.label9.Size = new System.Drawing.Size(53, 12);
  469. this.label9.TabIndex = 15;
  470. this.label9.Text = "Range4:";
  471. //
  472. // label8
  473. //
  474. this.label8.AutoSize = true;
  475. this.label8.Location = new System.Drawing.Point(114, 80);
  476. this.label8.Name = "label8";
  477. this.label8.Size = new System.Drawing.Size(53, 12);
  478. this.label8.TabIndex = 14;
  479. this.label8.Text = "Range3:";
  480. //
  481. // label7
  482. //
  483. this.label7.AutoSize = true;
  484. this.label7.Location = new System.Drawing.Point(114, 60);
  485. this.label7.Name = "label7";
  486. this.label7.Size = new System.Drawing.Size(53, 12);
  487. this.label7.TabIndex = 13;
  488. this.label7.Text = "Range2:";
  489. //
  490. // label6
  491. //
  492. this.label6.AutoSize = true;
  493. this.label6.Location = new System.Drawing.Point(114, 41);
  494. this.label6.Name = "label6";
  495. this.label6.Size = new System.Drawing.Size(53, 12);
  496. this.label6.TabIndex = 12;
  497. this.label6.Text = "Range1:";
  498. //
  499. // label5
  500. //
  501. this.label5.AutoSize = true;
  502. this.label5.Location = new System.Drawing.Point(11, 68);
  503. this.label5.Name = "label5";
  504. this.label5.Size = new System.Drawing.Size(35, 12);
  505. this.label5.TabIndex = 11;
  506. this.label5.Text = "Max:";
  507. //
  508. // label4
  509. //
  510. this.label4.AutoSize = true;
  511. this.label4.Location = new System.Drawing.Point(11, 47);
  512. this.label4.Name = "label4";
  513. this.label4.Size = new System.Drawing.Size(35, 12);
  514. this.label4.TabIndex = 6;
  515. this.label4.Text = "Min:";
  516. //
  517. // panel7
  518. //
  519. this.panel7.BackColor = System.Drawing.Color.Yellow;
  520. this.panel7.Location = new System.Drawing.Point(167, 78);
  521. this.panel7.Name = "panel7";
  522. this.panel7.Size = new System.Drawing.Size(58, 15);
  523. this.panel7.TabIndex = 6;
  524. this.panel7.Click += new System.EventHandler(this.panel1_Click);
  525. //
  526. // panel9
  527. //
  528. this.panel9.BackColor = System.Drawing.Color.Maroon;
  529. this.panel9.Location = new System.Drawing.Point(167, 116);
  530. this.panel9.Name = "panel9";
  531. this.panel9.Size = new System.Drawing.Size(58, 15);
  532. this.panel9.TabIndex = 10;
  533. this.panel9.Click += new System.EventHandler(this.panel1_Click);
  534. //
  535. // panel8
  536. //
  537. this.panel8.BackColor = System.Drawing.Color.Red;
  538. this.panel8.Location = new System.Drawing.Point(167, 97);
  539. this.panel8.Name = "panel8";
  540. this.panel8.Size = new System.Drawing.Size(58, 15);
  541. this.panel8.TabIndex = 6;
  542. this.panel8.Click += new System.EventHandler(this.panel1_Click);
  543. //
  544. // panel6
  545. //
  546. this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
  547. this.panel6.Location = new System.Drawing.Point(167, 59);
  548. this.panel6.Name = "panel6";
  549. this.panel6.Size = new System.Drawing.Size(58, 15);
  550. this.panel6.TabIndex = 6;
  551. this.panel6.Click += new System.EventHandler(this.panel1_Click);
  552. //
  553. // panel5
  554. //
  555. this.panel5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
  556. this.panel5.Location = new System.Drawing.Point(167, 40);
  557. this.panel5.Name = "panel5";
  558. this.panel5.Size = new System.Drawing.Size(58, 15);
  559. this.panel5.TabIndex = 5;
  560. this.panel5.Click += new System.EventHandler(this.panel1_Click);
  561. //
  562. // groupBox5
  563. //
  564. this.groupBox5.Controls.Add(this.pictureBox2);
  565. this.groupBox5.Controls.Add(this.button3);
  566. this.groupBox5.Controls.Add(this.button7);
  567. this.groupBox5.Location = new System.Drawing.Point(616, 293);
  568. this.groupBox5.Margin = new System.Windows.Forms.Padding(4);
  569. this.groupBox5.Name = "groupBox5";
  570. this.groupBox5.Padding = new System.Windows.Forms.Padding(4);
  571. this.groupBox5.Size = new System.Drawing.Size(257, 201);
  572. this.groupBox5.TabIndex = 7;
  573. this.groupBox5.TabStop = false;
  574. this.groupBox5.Text = "测量线高度图";
  575. //
  576. // pictureBox2
  577. //
  578. this.pictureBox2.Location = new System.Drawing.Point(7, 52);
  579. this.pictureBox2.Name = "pictureBox2";
  580. this.pictureBox2.Size = new System.Drawing.Size(242, 142);
  581. this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
  582. this.pictureBox2.TabIndex = 2;
  583. this.pictureBox2.TabStop = false;
  584. //
  585. // button3
  586. //
  587. this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  588. this.button3.Location = new System.Drawing.Point(165, 22);
  589. this.button3.Margin = new System.Windows.Forms.Padding(4);
  590. this.button3.Name = "button3";
  591. this.button3.Size = new System.Drawing.Size(84, 23);
  592. this.button3.TabIndex = 1;
  593. this.button3.Text = "导出数据";
  594. this.button3.UseVisualStyleBackColor = true;
  595. this.button3.Click += new System.EventHandler(this.button3_Click);
  596. //
  597. // button7
  598. //
  599. this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  600. this.button7.Location = new System.Drawing.Point(73, 22);
  601. this.button7.Margin = new System.Windows.Forms.Padding(4);
  602. this.button7.Name = "button7";
  603. this.button7.Size = new System.Drawing.Size(84, 23);
  604. this.button7.TabIndex = 2;
  605. this.button7.Text = "导出图片";
  606. this.button7.UseVisualStyleBackColor = true;
  607. this.button7.Click += new System.EventHandler(this.button7_Click);
  608. //
  609. // SRWindow
  610. //
  611. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  612. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  613. this.ClientSize = new System.Drawing.Size(891, 507);
  614. this.Controls.Add(this.groupBox5);
  615. this.Controls.Add(this.groupBox4);
  616. this.Controls.Add(this.groupBox3);
  617. this.Controls.Add(this.groupBox2);
  618. this.Controls.Add(this.groupBox1);
  619. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  620. this.Margin = new System.Windows.Forms.Padding(4);
  621. this.MaximizeBox = false;
  622. this.MaximumSize = new System.Drawing.Size(907, 546);
  623. this.MinimizeBox = false;
  624. this.MinimumSize = new System.Drawing.Size(907, 546);
  625. this.Name = "SRWindow";
  626. this.Text = "SRWindow";
  627. this.Controls.SetChildIndex(this.groupBox1, 0);
  628. this.Controls.SetChildIndex(this.groupBox2, 0);
  629. this.Controls.SetChildIndex(this.groupBox3, 0);
  630. this.Controls.SetChildIndex(this.groupBox4, 0);
  631. this.Controls.SetChildIndex(this.groupBox5, 0);
  632. this.groupBox1.ResumeLayout(false);
  633. this.groupBox2.ResumeLayout(false);
  634. this.groupBox3.ResumeLayout(false);
  635. this.groupBox3.PerformLayout();
  636. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  637. this.groupBox4.ResumeLayout(false);
  638. this.groupBox4.PerformLayout();
  639. this.groupBox5.ResumeLayout(false);
  640. ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
  641. this.ResumeLayout(false);
  642. }
  643. /// <summary>
  644. /// 操作点A按钮
  645. /// </summary>
  646. /// <param name="sender"></param>
  647. /// <param name="e"></param>
  648. private void button5_Click(object sender, EventArgs e)
  649. {
  650. m_iMusMod = 5;//操作点A
  651. }
  652. /// <summary>
  653. /// 操作点B按钮
  654. /// </summary>
  655. /// <param name="sender"></param>
  656. /// <param name="e"></param>
  657. private void button4_Click(object sender, EventArgs e)
  658. {
  659. m_iMusMod = 6;//操作点B
  660. }
  661. /// <summary>
  662. /// 图像翻转按钮
  663. /// </summary>
  664. /// <param name="sender"></param>
  665. /// <param name="e"></param>
  666. private void button9_Click(object sender, EventArgs e)
  667. {
  668. overturn();
  669. }
  670. /// <summary>
  671. /// 高度彩虹色填充按钮
  672. /// </summary>
  673. /// <param name="sender"></param>
  674. /// <param name="e"></param>
  675. private void button8_Click(object sender, EventArgs e)
  676. {
  677. ChangeColor();
  678. }
  679. /// <summary>
  680. /// 平移图片按钮
  681. /// </summary>
  682. /// <param name="sender"></param>
  683. /// <param name="e"></param>
  684. private void button2_Click(object sender, EventArgs e)
  685. {
  686. m_iMusMod = 2;//平移
  687. }
  688. /// <summary>
  689. /// 旋转图像按钮
  690. /// </summary>
  691. /// <param name="sender"></param>
  692. /// <param name="e"></param>
  693. private void button1_Click(object sender, EventArgs e)
  694. {
  695. m_iMusMod = 1;//旋转
  696. }
  697. public void ReadPar()
  698. {
  699. string fileName = System.Windows.Forms.Application.StartupPath/* + "\\Config\\" + "Default"*//*SettingPrefix*/ + "\\ThreeDataDemo_temp.xml";
  700. threeDataDemo = Base.CommTool.XmlSerializeHelper.DESerializer<Base.SettingModel.ThreeDataDemoModel>(Base.CommTool.FileOperationHelper.ReadStringFromFile(fileName, System.IO.FileMode.Open));
  701. //XmlDocument xd = new XmlDocument();
  702. //string fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDDemo20201029\ThreeDataDemo_00.xml";
  703. ////string fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDSR20201108\ThreeDSR\ThreeDData.xml";
  704. //xd.Load(fileName);
  705. string str;
  706. string[] strarr;
  707. ////XmlElement oneitem = (XmlElement)(xd.SelectSingleNode("Size"));
  708. ////str = oneitem.GetAttribute("width");
  709. ////m_iWidth = int.Parse(str);
  710. ////str = oneitem.GetAttribute("height");
  711. ////m_iHeight = int.Parse(str);
  712. //XmlNodeList xmlNoteList = xd.GetElementsByTagName("Size");
  713. if (threeDataDemo.size.Width < 1)
  714. //if (xmlNoteList.Count < 1)
  715. {
  716. MessageBox.Show("XML文件错");
  717. return;
  718. }
  719. str = threeDataDemo.size.Width.ToString();
  720. m_iWidth = int.Parse(str);
  721. str = threeDataDemo.size.Height.ToString();
  722. m_iHeight = int.Parse(str);
  723. //foreach (XmlElement item in xmlNoteList)
  724. //{
  725. // str = item.GetAttribute("width");
  726. // m_iWidth = int.Parse(str);
  727. // str = item.GetAttribute("height");
  728. // m_iHeight = int.Parse(str);
  729. // break;
  730. //}
  731. /*
  732. XmlNode onenode = xd.SelectSingleNode("Z_level");
  733. str = onenode.InnerXml;
  734. string[] strarr = str.Split(',');
  735. m_iDLevel = strarr.Length;
  736. m_adDZ = new double[m_iDLevel];
  737. m_adDC = new double[m_iDLevel,3];
  738. for(int i = 0; i < m_iDLevel; i++)
  739.             {
  740. m_adDZ[i] = double.Parse(strarr[i]);
  741.             }
  742. */
  743. //xmlNoteList = xd.GetElementsByTagName("Z_level");
  744. if (threeDataDemo.Z_level == null)
  745. //if (xmlNoteList.Count < 1)
  746. {
  747. MessageBox.Show("XML文件错");
  748. //return;
  749. }
  750. else
  751. {
  752. str = threeDataDemo.Z_level.ToString();
  753. strarr = str.Split(',');
  754. m_iDLevel = strarr.Length;
  755. m_adDZ = new double[m_iDLevel];
  756. m_adDC = new double[m_iDLevel, 3];
  757. for (int i = 0; i < m_iDLevel; i++)
  758. {
  759. m_adDZ[i] = double.Parse(strarr[i]);
  760. }
  761. }
  762. //foreach (XmlElement item in xmlNoteList)
  763. //{
  764. // str = item.InnerXml;
  765. // strarr = str.Split(',');
  766. // m_iDLevel = strarr.Length;
  767. // m_adDZ = new double[m_iDLevel];
  768. // m_adDC = new double[m_iDLevel, 3];
  769. // for (int i = 0; i < m_iDLevel; i++)
  770. // {
  771. // m_adDZ[i] = double.Parse(strarr[i]);
  772. // }
  773. // break;
  774. //}
  775. //xmlNoteList = xd.GetElementsByTagName("colour");
  776. if (threeDataDemo.Dyeing.Count < m_iDLevel)
  777. //if (xmlNoteList.Count < m_iDLevel)
  778. {
  779. MessageBox.Show("XML文件错");
  780. return;
  781. }
  782. int iX = 0;
  783. for (int dyeingIndex = 0; dyeingIndex < threeDataDemo.Dyeing.Count; dyeingIndex++)
  784. //foreach (XmlElement item in xmlNoteList)
  785. {
  786. str = threeDataDemo.Dyeing[dyeingIndex].ToString();
  787. //str = item.InnerXml;
  788. strarr = str.Split(',');
  789. if (strarr.Length < 3)
  790. {
  791. MessageBox.Show("XML文件错");
  792. return;
  793. }
  794. m_adDC[iX, 0] = double.Parse(strarr[0]);
  795. m_adDC[iX, 1] = double.Parse(strarr[1]);
  796. m_adDC[iX, 2] = double.Parse(strarr[2]);
  797. iX++;
  798. }
  799. //xmlNoteList = xd.GetElementsByTagName("Column");
  800. if (threeDataDemo.Z_value.Count < m_iWidth)
  801. //if (xmlNoteList.Count < m_iWidth)
  802. {
  803. MessageBox.Show("XML文件错");
  804. return;
  805. }
  806. m_adZV = new double[m_iWidth, m_iHeight];
  807. bool bFirst = true;
  808. iX = 0;
  809. for (int Z_valueIndex = 0; Z_valueIndex < threeDataDemo.Z_value.Count; Z_valueIndex++)
  810. //foreach (XmlElement item in xmlNoteList)
  811. {
  812. str = threeDataDemo.Z_value[Z_valueIndex].ToString();
  813. //str = item.InnerXml;
  814. strarr = str.Split(',');
  815. if (strarr.Length < m_iHeight)
  816. {
  817. MessageBox.Show("XML文件错");
  818. return;
  819. }
  820. for (int iY = 0; iY < m_iHeight; iY++)
  821. {
  822. m_adZV[iX, m_iHeight - 1 - iY] = double.Parse(strarr[iY]);
  823. if ((bFirst) || (m_adZV[iX, m_iHeight - 1 - iY] > m_dMaxZV))
  824. {
  825. m_dMaxZV = m_adZV[iX, m_iHeight - 1 - iY];
  826. }
  827. if ((bFirst) || (m_adZV[iX, m_iHeight - 1 - iY] < m_dMinZV))
  828. {
  829. m_dMinZV = m_adZV[iX, m_iHeight - 1 - iY];
  830. bFirst = false;
  831. }
  832. }
  833. iX++;
  834. }
  835. //处理剖面线参数
  836. m_afPonitB[0] = m_iWidth - 1;
  837. m_afPonitB[1] = m_iHeight - 1;
  838. CalculationIne();
  839. //处理颜色和翻转参数
  840. m_afNewClr = new float[m_iWidth, m_iHeight, 3];
  841. m_adOverTurnZV = new double[m_iWidth, m_iHeight];
  842. for (iX = 0; iX < m_iWidth; iX++)
  843. {
  844. for (int iY = 0; iY < m_iHeight; iY++)
  845. {
  846. float[] fColor = CalculationColorf(m_adZV[iX, iY]);
  847. m_afNewClr[iX, iY, 0] = fColor[0];
  848. m_afNewClr[iX, iY, 1] = fColor[1];
  849. m_afNewClr[iX, iY, 2] = fColor[2];
  850. m_adOverTurnZV[iX, iY] = m_dMinZV + (m_dMaxZV - m_adZV[iX, iY]);
  851. }
  852. }
  853. fileName = System.Windows.Forms.Application.StartupPath/* + "\\Config\\" + "Default"*//*SettingPrefix*/ + "\\ThreeDataDemo_temp.bmp";
  854. //fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDDemo20201029\d2.bmp";
  855. //fileName = @"C:\Users\win10SSD\Desktop\工作目录\ThreeDDemo\ThreeDSR20201108\ThreeDSR\d1.bmp";
  856. Mat OrgImg = OpenCvSharp.Cv2.ImRead(fileName);
  857. if ((m_iWidth != OrgImg.Cols) || (m_iHeight != OrgImg.Rows))//行数Rows是Y,列数是X
  858. {
  859. MessageBox.Show("图像尺寸和XML文件矛盾");
  860. return;
  861. }
  862. m_afOrgClr = new float[m_iWidth, m_iHeight, 3];
  863. int[] point = new int[2];
  864. Vec3b OrgClr;
  865. for (point[0] = 0; point[0] < m_iHeight; point[0]++)
  866. {
  867. for (point[1] = 0; point[1] < m_iWidth; point[1]++)
  868. {
  869. OrgClr = OrgImg.At<Vec3b>(point[0], point[1]);
  870. m_afOrgClr[point[1], m_iHeight - 1 - point[0], 0] = OrgClr.Item2 / 255.0F;
  871. m_afOrgClr[point[1], m_iHeight - 1 - point[0], 1] = OrgClr.Item1 / 255.0F;
  872. m_afOrgClr[point[1], m_iHeight - 1 - point[0], 2] = OrgClr.Item0 / 255.0F;
  873. }
  874. }
  875. m_bRulerColor = false;
  876. m_afThisClr = m_afOrgClr;
  877. m_bOverTurn = false;
  878. m_adThisZV = m_adZV;
  879. m_adThisLineZV = m_adLineZV;
  880. }
  881. public float[] CalculationColorf(double dZ)
  882. {
  883. float[] fColor = new float[3];
  884. if (dZ <= m_adDZ[m_iDLevel - 1])
  885. {
  886. fColor[0] = (float)m_adDC[m_iDLevel - 1, 0];
  887. fColor[1] = (float)m_adDC[m_iDLevel - 1, 1];
  888. fColor[2] = (float)m_adDC[m_iDLevel - 1, 2];
  889. return fColor;
  890. }
  891. if (dZ >= m_adDZ[0])
  892. {
  893. fColor[0] = (float)m_adDC[0, 0];
  894. fColor[1] = (float)m_adDC[0, 1];
  895. fColor[2] = (float)m_adDC[0, 2];
  896. return fColor;
  897. }
  898. int i, j;
  899. for (j = 1; j < m_iDLevel; j++)
  900. {
  901. if (dZ > m_adDZ[j])
  902. {
  903. break;
  904. }
  905. }
  906. i = j - 1;
  907. double dIJ = Math.Abs(m_adDZ[i] - m_adDZ[j]);
  908. double dWI = Math.Abs(dZ - m_adDZ[j]) / dIJ;
  909. double dWJ = Math.Abs(m_adDZ[i] - dZ) / dIJ;
  910. fColor[0] = (float)((m_adDC[i, 0] * dWI + m_adDC[j, 0] * dWJ) / 255.0);
  911. fColor[1] = (float)((m_adDC[i, 1] * dWI + m_adDC[j, 1] * dWJ) / 255.0);
  912. fColor[2] = (float)((m_adDC[i, 2] * dWI + m_adDC[j, 2] * dWJ) / 255.0);
  913. return fColor;
  914. }
  915. private void CalculationIne()
  916. {
  917. LINE_PNTS = (int)Math.Sqrt((m_afPonitB[0] - m_afPonitA[0]) * (m_afPonitB[0] - m_afPonitA[0]) + (m_afPonitB[1] - m_afPonitA[1]) * (m_afPonitB[1] - m_afPonitA[1]));
  918. if (LINE_PNTS < 3)
  919. LINE_PNTS = 3;
  920. m_afLineStep[0] = (m_afPonitB[0] - m_afPonitA[0]) / (LINE_PNTS - 1);
  921. m_afLineStep[1] = (m_afPonitB[1] - m_afPonitA[1]) / (LINE_PNTS - 1);
  922. m_afLineXY = new float[LINE_PNTS - 2, 2];
  923. m_adLineZV = new double[LINE_PNTS];
  924. m_adLineOverTurnZV = new double[LINE_PNTS];
  925. if (!m_bOverTurn)
  926. m_adThisLineZV = m_adLineZV;
  927. else
  928. m_adThisLineZV = m_adLineOverTurnZV;
  929. m_adLineZV[0] = CalculationInterpolation(m_afPonitA[0], m_afPonitA[1]);
  930. m_adLineOverTurnZV[0] = m_dMinZV + (m_dMaxZV - m_adLineZV[0]);
  931. for (int i = 0; i < (LINE_PNTS - 2); i++)
  932. {
  933. m_afLineXY[i, 0] = m_afPonitA[0] + (i + 1) * m_afLineStep[0];
  934. m_afLineXY[i, 1] = m_afPonitA[1] + (i + 1) * m_afLineStep[1];
  935. m_adLineZV[i + 1] = CalculationInterpolation(m_afLineXY[i, 0], m_afLineXY[i, 1]);
  936. m_adLineOverTurnZV[i + 1] = m_dMinZV + (m_dMaxZV - m_adLineZV[i + 1]);
  937. }
  938. m_adLineZV[LINE_PNTS - 1] = CalculationInterpolation(m_afPonitB[0], m_afPonitB[1]);
  939. m_adLineOverTurnZV[LINE_PNTS - 1] = m_dMinZV + (m_dMaxZV - m_adLineZV[LINE_PNTS - 1]);
  940. ShowSectionLine();
  941. }
  942. private double CalculationInterpolation(float fX, float fY)
  943. {
  944. int iXS = Math.Min(Math.Max((int)(fX), 0), m_iWidth - 1);
  945. int iYS = Math.Min(Math.Max((int)(fY), 0), m_iHeight - 1);
  946. int iXB = Math.Min(Math.Max((int)(fX + 1.0), 0), m_iWidth - 1);
  947. int iYB = Math.Min(Math.Max((int)(fY + 1.0), 0), m_iHeight - 1);
  948. double dWXB = Math.Min(Math.Max((fX - (double)iXS), 0.0), 1.0);
  949. double dWXS = 1.0 - dWXB;
  950. double dWYB = Math.Min(Math.Max((fY - (double)iYS), 0.0), 1.0);
  951. double dWYS = 1.0 - dWYB;
  952. double dTempA = m_adZV[iXS, iYS];
  953. double dTempB = m_adZV[iXS, iYB];
  954. double dTempC = m_adZV[iXB, iYS];
  955. double dTempD = m_adZV[iXB, iYB];
  956. double dTempAB = dTempA * dWYS + dTempB * dWYB;
  957. double dTempCD = dTempC * dWYS + dTempD * dWYB;
  958. double dRtn = dTempAB * dWXS + dTempCD * dWXB;
  959. return dRtn;// dTempA;//
  960. }
  961. private static void PictureBox1_Paint(object sender, PaintEventArgs e)
  962. {
  963. //Application.DoEvents(); // Process Events
  964. //// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
  965. //if ((active && (form != null) && !DrawGLScene()) /*|| keys[(int) Keys.Escape]*/)
  966. //{ // Active? Was There A Quit Received?
  967. // done = true; // ESC Or DrawGLScene Signalled A Quit
  968. //}
  969. //else
  970. //{ // Not Time To Quit, Update Screen
  971. // Gdi.SwapBuffers(hDC); // Swap Buffers (Double Buffering)
  972. //}
  973. }
  974. internal static void Run(AppWorkspace appWorkspace) {
  975. done = false;
  976. // Create Our OpenGL Window
  977. if (!CreateGLWindow(appWorkspace, PdnResources.GetString("Menu.Tools.SurfacePlotShow.Text"), 990, 690, 16)) {
  978. return; // Quit If Window Was Not Created
  979. }
  980. while (!done)
  981. { // Loop That Runs While done = false
  982. Application.DoEvents(); // Process Events
  983. // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
  984. if ((active && (form != null) && !DrawGLScene()) /*|| keys[(int) Keys.Escape]*/)
  985. { // Active? Was There A Quit Received?
  986. done = true; // ESC Or DrawGLScene Signalled A Quit
  987. }
  988. else
  989. { // Not Time To Quit, Update Screen
  990. Gdi.SwapBuffers(hDC); // Swap Buffers (Double Buffering)
  991. }
  992. /*
  993. if(keys[(int) Keys.F1]) { // Is F1 Being Pressed?
  994. keys[(int) Keys.F1] = false; // If So Make Key false
  995. KillGLWindow(); // Kill Our Current Window
  996. // Recreate Our OpenGL Window
  997. if(!CreateGLWindow("三维面绘制", 640, 480, 16)) {
  998. return; // Quit If Window Was Not Created
  999. }
  1000. done = false; // We're Not Done Yet
  1001. }
  1002. */
  1003. }
  1004. // Shutdown
  1005. KillGLWindow(); // Kill The Window
  1006. return; // Exit The Program
  1007. }
  1008. private static bool CreateGLWindow(AppWorkspace appWorkspace, string title, int width, int height, int bits)
  1009. {
  1010. int pixelFormat; // Holds The Results After Searching For A Match
  1011. form = null; // Null The Form
  1012. GC.Collect(); // Request A Collection
  1013. // This Forces A Swap
  1014. Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
  1015. form = new SRWindow(appWorkspace); // Create The Window
  1016. form.FormBorderStyle = FormBorderStyle.Sizable; // Sizable
  1017. Cursor.Show(); // Show Mouse Pointer
  1018. form.Width = width; // Set Window Width
  1019. form.Height = height; // Set Window Height
  1020. form.Text = title; // Set Window Title
  1021. Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR(); // pfd Tells Windows How We Want Things To Be
  1022. pfd.nSize = (short) Marshal.SizeOf(pfd); // Size Of This Pixel Format Descriptor
  1023. pfd.nVersion = 1; // Version Number
  1024. pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW | // Format Must Support Window
  1025. Gdi.PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
  1026. Gdi.PFD_DOUBLEBUFFER; // Format Must Support Double Buffering
  1027. pfd.iPixelType = (byte) Gdi.PFD_TYPE_RGBA; // Request An RGBA Format
  1028. pfd.cColorBits = (byte) bits; // Select Our Color Depth
  1029. pfd.cRedBits = 0; // Color Bits Ignored
  1030. pfd.cRedShift = 0;
  1031. pfd.cGreenBits = 0;
  1032. pfd.cGreenShift = 0;
  1033. pfd.cBlueBits = 0;
  1034. pfd.cBlueShift = 0;
  1035. pfd.cAlphaBits = 0; // No Alpha Buffer
  1036. pfd.cAlphaShift = 0; // Shift Bit Ignored
  1037. pfd.cAccumBits = 0; // No Accumulation Buffer
  1038. pfd.cAccumRedBits = 0; // Accumulation Bits Ignored
  1039. pfd.cAccumGreenBits = 0;
  1040. pfd.cAccumBlueBits = 0;
  1041. pfd.cAccumAlphaBits = 0;
  1042. pfd.cDepthBits = 16; // 16Bit Z-Buffer (Depth Buffer)
  1043. pfd.cStencilBits = 0; // No Stencil Buffer
  1044. pfd.cAuxBuffers = 0; // No Auxiliary Buffer
  1045. pfd.iLayerType = (byte) Gdi.PFD_MAIN_PLANE; // Main Drawing Layer
  1046. pfd.bReserved = 0; // Reserved
  1047. pfd.dwLayerMask = 0; // Layer Masks Ignored
  1048. pfd.dwVisibleMask = 0;
  1049. pfd.dwDamageMask = 0;
  1050. //hDC = User.GetDC(form.Handle); // Attempt To Get A Device Context
  1051. form.pictureBox1 = new PictureBox();
  1052. ((System.ComponentModel.ISupportInitialize)(form.pictureBox1)).BeginInit();
  1053. //form.pictureBox1.Location = new System.Drawing.Point(22, 40);
  1054. //form.pictureBox1.Location = new System.Drawing.Point(20, 180);
  1055. form.pictureBox1.Location = new System.Drawing.Point(15, 18);
  1056. form.pictureBox1.Name = "pictureBox1";
  1057. form.pictureBox1.Size = new System.Drawing.Size(560, 400);
  1058. //form.pictureBox1.Size = new System.Drawing.Size(1272, 651);
  1059. form.pictureBox1.TabIndex = 0;
  1060. form.pictureBox1.TabStop = false;
  1061. /*form*/form.groupBox1.Controls.Add(form.pictureBox1);
  1062. ((System.ComponentModel.ISupportInitialize)(form.pictureBox1)).EndInit();
  1063. form.pictureBox1.Paint += PictureBox1_Paint;
  1064. form.pictureBox1.MouseMove += new MouseEventHandler(form.pictureBox1_MouseMove);
  1065. form.pictureBox1.MouseDown += new MouseEventHandler(form.pictureBox1_MouseDown);
  1066. form.pictureBox1.MouseUp += new MouseEventHandler(form.pictureBox1_MouseUp);
  1067. form.pictureBox1.MouseLeave += new EventHandler(form.pictureBox1_MouseLeave);
  1068. hDC = User.GetDC(form.pictureBox1.Handle);
  1069. if(hDC == IntPtr.Zero) { // Did We Get A Device Context?
  1070. KillGLWindow(); // Reset The Display
  1071. MessageBox.Show("Can't Create A GL Device Context.", "ERROR",
  1072. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1073. return false;
  1074. }
  1075. pixelFormat = Gdi.ChoosePixelFormat(hDC, ref pfd); // Attempt To Find An Appropriate Pixel Format
  1076. if(pixelFormat == 0) { // Did Windows Find A Matching Pixel Format?
  1077. KillGLWindow(); // Reset The Display
  1078. MessageBox.Show("Can't Find A Suitable PixelFormat.", "ERROR",
  1079. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1080. return false;
  1081. }
  1082. if(!Gdi.SetPixelFormat(hDC, pixelFormat, ref pfd)) { // Are We Able To Set The Pixel Format?
  1083. KillGLWindow(); // Reset The Display
  1084. MessageBox.Show("Can't Set The PixelFormat.", "ERROR",
  1085. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1086. return false;
  1087. }
  1088. hRC = Wgl.wglCreateContext(hDC); // Attempt To Get The Rendering Context
  1089. if(hRC == IntPtr.Zero) { // Are We Able To Get A Rendering Context?
  1090. KillGLWindow(); // Reset The Display
  1091. MessageBox.Show("Can't Create A GL Rendering Context.", "ERROR",
  1092. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1093. return false;
  1094. }
  1095. if(!Wgl.wglMakeCurrent(hDC, hRC)) { // Try To Activate The Rendering Context
  1096. KillGLWindow(); // Reset The Display
  1097. MessageBox.Show("Can't Activate The GL Rendering Context.", "ERROR",
  1098. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1099. return false;
  1100. }
  1101. form.Show(); // Show The Window
  1102. //zzz form.TopMost = true; // Topmost Window
  1103. form.Focus(); // Focus The Window
  1104. //form.BackColor = Color.Gray;
  1105. ////form.WindowState = FormWindowState.Maximized;
  1106. //ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
  1107. if (!InitGL())
  1108. { // Initialize Our Newly Created GL Window
  1109. KillGLWindow(); // Reset The Display
  1110. MessageBox.Show("Initialization Failed.", "ERROR",
  1111. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1112. return false;
  1113. }
  1114. return true; // Success
  1115. }
  1116. private static bool DrawGLScene()
  1117. {
  1118. //new platform
  1119. iniView();
  1120. Gl.glTranslatef(0, 0, 0);
  1121. myRotate();
  1122. //错了 Gl.glTranslatef(m_fT_xyz[0],m_fT_xyz[1],0);
  1123. for (int i = 0; i < form.m_iWidth - 1; i++)
  1124. {
  1125. Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
  1126. for (int j = 0; j < form.m_iHeight; j++)
  1127. {
  1128. DrowOnePnt(i, j);
  1129. DrowOnePnt(i + 1, j);
  1130. }
  1131. Gl.glEnd();
  1132. }
  1133. if ((form.m_iMusMod >= 5) && (form.m_iMusMod <= 7) || true)
  1134. {
  1135. Gl.glBegin(Gl.GL_QUADS);
  1136. Gl.glColor3f(1.0F, 1.0F, 0.0F);
  1137. Gl.glVertex3d(form.m_afPonitA[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1138. Gl.glVertex3d(form.m_afPonitA[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1139. Gl.glVertex3d(form.m_afPonitA[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1140. Gl.glVertex3d(form.m_afPonitA[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1141. Gl.glEnd();
  1142. Gl.glBegin(Gl.GL_LINE_STRIP);
  1143. Gl.glColor3f(0.0F, 1.0F, 0.0F);
  1144. Gl.glVertex3d(form.m_afPonitA[0] - form.m_iWidth / 2.0, form.m_afPonitA[1] - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1145. for (int i = 0; i < (LINE_PNTS - 2); i++)
  1146. {
  1147. Gl.glVertex3d(form.m_afLineXY[i, 0] - form.m_iWidth / 2.0, form.m_afLineXY[i, 1] - form.m_iHeight / 2.0, 1.0 + /*form.m_adThisZV[(int)form.m_afLineXY[i, 0], (int)form.m_afLineXY[i, 1]]*/form.m_adThisLineZV[i + 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1148. }
  1149. Gl.glVertex3d(form.m_afPonitB[0] - form.m_iWidth / 2.0, form.m_afPonitB[1] - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1150. Gl.glEnd();
  1151. Gl.glBegin(Gl.GL_QUADS);
  1152. Gl.glColor3f(0.0F, 1.0F, 01.0F);
  1153. Gl.glVertex3d(form.m_afPonitB[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1154. Gl.glVertex3d(form.m_afPonitB[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1155. Gl.glVertex3d(form.m_afPonitB[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1156. Gl.glVertex3d(form.m_afPonitB[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1157. Gl.glEnd();
  1158. }
  1159. Gl.glLoadIdentity();
  1160. return true;
  1161. }
  1162. private static void myRotate()
  1163. {
  1164. int[,] vec = new int[3, 3] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
  1165. for (int i = 0; i <= 2; i++)
  1166. {
  1167. Gl.glRotatef(form.m_fR_xyz[i], vec[i, 0], vec[i, 1], vec[i, 2]);
  1168. }
  1169. }
  1170. public static void DrowOnePnt(int i, int j)
  1171. {
  1172. Gl.glColor3f(form.m_afThisClr[i, j, 0], form.m_afThisClr[i, j, 1], form.m_afThisClr[i, j, 2]);
  1173. Gl.glVertex3d(i - form.m_iWidth / 2.0, j - form.m_iHeight / 2.0, form.m_adThisZV[i, j] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  1174. }
  1175. private static bool InitGL()
  1176. {
  1177. //Gl.glShadeModel(Gl.GL_SMOOTH); // Enable Smooth Shading
  1178. //Gl.glClearColor(0, 0, 0, 0.5f); // Black Background
  1179. //Gl.glClearDepth(1); // Depth Buffer Setup
  1180. Gl.glEnable(Gl.GL_DEPTH_TEST); // Enables Depth Testing
  1181. //Gl.glDepthFunc(Gl.GL_LEQUAL); // The Type Of Depth Testing To Do
  1182. //Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST); // Really Nice Perspective Calculations
  1183. // 设置视口 viewport
  1184. Gl.glViewport(0, 0, form.pictureBox1.Width, form.pictureBox1.Height);
  1185. //启用阴影平滑
  1186. Gl.glShadeModel(Gl.GL_SMOOTH);
  1187. //启用反走样
  1188. Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
  1189. // 设置投影模式 projection matrix
  1190. Gl.glMatrixMode(Gl.GL_PROJECTION);
  1191. Gl.glLoadIdentity();
  1192. iniView();
  1193. return true;
  1194. }
  1195. public static void iniView(bool clearColor = true)
  1196. {
  1197. // 重置黑色背景
  1198. if (clearColor)
  1199. {
  1200. Gl.glClearColor((float)(form.panel1.BackColor.R / 255.0), (float)(form.panel1.BackColor.G / 255.0), (float)(form.panel1.BackColor.B / 255.0), (float)(form.panel1.BackColor.A / 255.0));
  1201. Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
  1202. }
  1203. else
  1204. return;
  1205. form.m_fT_xyz[2] = (float)Math.Max(form.m_dMaxZV, Math.Abs(form.m_dMinZV));
  1206. form.m_fT_xyz[2] = (float)(-1.0 * Math.Max(Math.Max(form.m_iWidth * 0.8, form.m_iHeight * 0.8), form.m_fT_xyz[2]));
  1207. ////form.m_fT_xyz[2] = (float)(1.2 * form.m_fT_xyz[2]);
  1208. ////Glu.gluPerspective(85, form.pictureBox1.Width / (double)form.pictureBox1.Height, 1, -4.0/*-2.0*/ * form.m_fT_xyz[2]);//距离裁减
  1209. //Gl.glOrtho(0, form.pictureBox1.Width, form.pictureBox1.Height, 0, 1, -4.0/*-2.0*/ * form.m_fT_xyz[2]);
  1210. double size1 = form.m_iHeight / 1.0;
  1211. Gl.glOrtho(-size1 * form.pictureBox1.Width / (double)form.pictureBox1.Height, size1 * form.pictureBox1.Width / (double)form.pictureBox1.Height, -size1, size1, 2.4 * form.m_fT_xyz[2], -12.4 * form.m_fT_xyz[2]);
  1212. // 选择模型观察矩阵 modelview matrix
  1213. Gl.glMatrixMode(Gl.GL_MODELVIEW);
  1214. //重置模型观察矩阵
  1215. Gl.glLoadIdentity();
  1216. Glu.gluLookAt(-1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], -1.2/*-1.0*/ * form.m_fT_xyz[2], // 眼睛位置
  1217. -1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], 0, // 观察点
  1218. 0, 1, 0);
  1219. }
  1220. private static void KillGLWindow() {
  1221. if(hRC != IntPtr.Zero) { // Do We Have A Rendering Context?
  1222. if(!Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero)) { // Are We Able To Release The DC and RC Contexts?
  1223. MessageBox.Show("Release Of DC And RC Failed.", "SHUTDOWN ERROR",
  1224. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1225. }
  1226. if(!Wgl.wglDeleteContext(hRC)) { // Are We Able To Delete The RC?
  1227. MessageBox.Show("Release Rendering Context Failed.", "SHUTDOWN ERROR",
  1228. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1229. }
  1230. hRC = IntPtr.Zero; // Set RC To Null
  1231. }
  1232. if(hDC != IntPtr.Zero) { // Do We Have A Device Context?
  1233. if(form != null && !form.IsDisposed) { // Do We Have A Window?
  1234. if(form.Handle != IntPtr.Zero) { // Do We Have A Window Handle?
  1235. if(!User.ReleaseDC(form.Handle, hDC)) { // Are We Able To Release The DC?
  1236. MessageBox.Show("Release Device Context Failed.", "SHUTDOWN ERROR",
  1237. MessageBoxButtons.OK, MessageBoxIcon.Error);
  1238. }
  1239. }
  1240. }
  1241. hDC = IntPtr.Zero; // Set DC To Null
  1242. }
  1243. if(form != null) { // Do We Have A Windows Form?
  1244. form.Hide(); // Hide The Window
  1245. form.Close(); // Close The Form
  1246. form = null; // Set form To Null
  1247. }
  1248. }
  1249. private static void ReSizeGLScene(int width, int height) {
  1250. if(height == 0) { // Prevent A Divide By Zero...
  1251. height = 1; // By Making Height Equal To One
  1252. }
  1253. Gl.glViewport(0, 0, width, height); // Reset The Current Viewport
  1254. Gl.glMatrixMode(Gl.GL_PROJECTION); // Select The Projection Matrix
  1255. Gl.glLoadIdentity(); // Reset The Projection Matrix
  1256. Glu.gluPerspective(45, width / (double) height, 0.1, 100); // Calculate The Aspect Ratio Of The Window
  1257. Gl.glMatrixMode(Gl.GL_MODELVIEW); // Select The Modelview Matrix
  1258. Gl.glLoadIdentity(); // Reset The Modelview Matrix
  1259. }
  1260. private void Form_Activated(object sender, EventArgs e)
  1261. {
  1262. active = true; // Program Is Active
  1263. }
  1264. private void Form_Closing(object sender, CancelEventArgs e)
  1265. {
  1266. done = true; // Send A Quit Message
  1267. }
  1268. private void Form_Deactivate(object sender, EventArgs e)
  1269. {
  1270. active = false; // Program Is No Longer Active
  1271. }
  1272. private void Form_KeyDown(object sender, KeyEventArgs e)
  1273. {
  1274. //keys[e.KeyValue] = true; // Key Has Been Pressed, Mark It As true
  1275. switch (e.KeyValue)
  1276. {
  1277. case (int) Keys.Escape://退出
  1278. done = true;
  1279. break;
  1280. case 49://'1'
  1281. m_iMusMod = 1;//旋转图像
  1282. break;
  1283. case 50://'2'
  1284. m_iMusMod = 2;//平移图像
  1285. break;
  1286. case 53://'5'
  1287. m_iMusMod = 5;//操作点A
  1288. break;
  1289. case 54://'6'
  1290. m_iMusMod = 6;//操作点B
  1291. break;
  1292. case 55://'7'
  1293. m_iMusMod = 7;//看剖面线
  1294. ShowSectionLine();
  1295. break;
  1296. case 56://'8'
  1297. overturn();
  1298. break;
  1299. case 57://'9'
  1300. ChangeColor();
  1301. break;
  1302. default:
  1303. m_iMusMod = 0;//no meaning
  1304. break;
  1305. }
  1306. }
  1307. private void ShowSectionLine()
  1308. {
  1309. //m_fmLine = new SRLinesForm();
  1310. //m_fmLine.Show();
  1311. this.m_adValue = new double[LINE_PNTS];
  1312. this.m_dYVMax = m_dMaxZV + 1.0;
  1313. this.m_dYVMin = m_dMinZV - 1.0;
  1314. for (int i = 0; i < LINE_PNTS; i++)
  1315. {
  1316. this.m_adValue[i] = m_adLineZV[i];
  1317. }
  1318. this.draw(0);
  1319. }
  1320. //zzz
  1321. public int m_iYVCount = 10;
  1322. public double m_dYVMax = 51;
  1323. public double m_dYVMin = -51;
  1324. /// <summary>
  1325. /// Z轴高度集合,从A到B按照均匀取到了100个点
  1326. /// </summary>
  1327. private double[] m_adValue = new double[LINE_PNTS];
  1328. public int m_iYPixelMax = 350;
  1329. public int m_iYPixelMin = 40;
  1330. public int m_iXPixelMax = 1100;
  1331. public int m_iXPixelMin = 60;
  1332. // x1,y1为鼠标移动的坐标,画十字线用,xbuf,ybuf绘制点坐标数组
  1333. void draw(int x1/*, int y1, int[] xbuf, int[] ybuf*/)
  1334. {
  1335. //定义画布大小
  1336. int height = m_iYPixelMax, width = m_iXPixelMax;
  1337. int showLINE_PNTS = 100;
  1338. //创建位图
  1339. System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
  1340. //创建Graphics类对象
  1341. Graphics g = Graphics.FromImage(image);
  1342. //清空图片背景色
  1343. g.Clear(Color.White);
  1344. Font font = new System.Drawing.Font("Arial", 16, FontStyle.Regular);
  1345. Font font1 = new System.Drawing.Font("宋体", 14, FontStyle.Regular);
  1346. Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
  1347. System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
  1348. g.FillRectangle(Brushes.SeaGreen, 0, 0, width, height);
  1349. Brush brush1 = new SolidBrush(Color.Blue);
  1350. Brush brush2 = new SolidBrush(Color.SaddleBrown);
  1351. //画图片的边框线
  1352. g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin, (showLINE_PNTS - 1) * 10, 270);
  1353. g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin - 5, (showLINE_PNTS - 1) * 10, 275);
  1354. System.Drawing.Pen mypen = new Pen(brush, 1);
  1355. System.Drawing.Pen mypen2 = new Pen(Color.Red, 2);
  1356. System.Drawing.Pen mypen3 = new Pen(Color.Yellow, 1);
  1357. //绘制线条
  1358. //绘制纵向线条
  1359. double x = 0.0 + m_iXPixelMin;
  1360. for (int i = 0; i < 9; i++)
  1361. {
  1362. x = x + 100;
  1363. g.DrawLine(mypen, (float)x, 40, (float)x, m_iYPixelMax - 40);
  1364. }
  1365. //Pen mypen1 = new Pen(Color.Blue, 2);
  1366. //g.DrawLine(mypen1, x - 480, 80, x - 480, 340);
  1367. //绘制横向线条
  1368. int y = m_iYPixelMin + 30;
  1369. for (int i = 0; i < 8; i++)
  1370. {
  1371. g.DrawLine(mypen, m_iXPixelMin, y, m_iXPixelMin + (showLINE_PNTS - 1) * 10, y);
  1372. y = y + 30;
  1373. }
  1374. //x轴上对应的标记
  1375. /*
  1376. String[] n = { " 10", " 20", " 30", " 40", " 50", " 60", " 70",
  1377. " 80", " 90", " 100", "110", "120", "130", "140", "150", "160", "170"};
  1378. */
  1379. x = m_iXPixelMin - 5;
  1380. g.DrawString("A", font, Brushes.Red, (float)x, m_iYPixelMax - 35);
  1381. x += 10;
  1382. for (int i = 1; i < showLINE_PNTS - 1; i++)
  1383. {
  1384. g.DrawString(".", font, Brushes.Red, (float)x, m_iYPixelMax - 35); //设置文字内容及输出位置
  1385. x = x + 10;
  1386. }
  1387. g.DrawString("B", font, Brushes.Red, (float)x, m_iYPixelMax - 35);
  1388. //y轴上对应的标记
  1389. /*
  1390. String[] m = {"40", "35", "30", "25", "20", "15", "10",
  1391. " 5"};
  1392. */
  1393. double dYStep = (m_dYVMax - m_dYVMin) / 9.0;
  1394. y = m_iYPixelMin - 5;
  1395. for (int i = 0; i < 10; i++)
  1396. {
  1397. double dTemp = m_dYVMax - i * dYStep;
  1398. string str = dTemp.ToString("f1");
  1399. g.DrawString(str, font1, Brushes.Red, 1, y); //设置文字内容及输出位置
  1400. y = y + 30;
  1401. }
  1402. x = m_iXPixelMin;
  1403. y = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[0]) / (m_dYVMax - m_dYVMin)) + 0.5);
  1404. double dXStep = 10.0 * showLINE_PNTS / LINE_PNTS;
  1405. for (int i = 1; i < LINE_PNTS; i++)//##################################showLINE_PNTS
  1406. {
  1407. int yNext = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[Math.Min(i, LINE_PNTS - 1)]) / (m_dYVMax - m_dYVMin)) + 0.5);
  1408. g.DrawLine(mypen3, (int)x, y, (int)(x + dXStep), yNext);
  1409. x += dXStep;
  1410. y = yNext;
  1411. }
  1412. /*
  1413. if (drawflag == 1)
  1414. {
  1415. for (int i = 0; i < readlen / 2; i++)
  1416. {
  1417. g.DrawEllipse(mypen2, xbuf[i] - 2, ybuf[i] - 2, 4, 4);
  1418. if (i < readlen / 2 - 1)
  1419. g.DrawLine(mypen3, xbuf[i], ybuf[i], xbuf[i + 1], ybuf[i + 1]);
  1420. }
  1421. }
  1422. if (flag == true)
  1423. {
  1424. g.DrawLine(mypen2, x1, 41, x1, 310);
  1425. g.DrawLine(mypen2, 41, y1, 760, y1);
  1426. }
  1427. g.Dispose();
  1428. */
  1429. this.pictureBox2.Image = image;
  1430. }
  1431. private void overturn()
  1432. {
  1433. if (m_bOverTurn)
  1434. {
  1435. m_bOverTurn = false;
  1436. m_adThisZV = m_adZV;
  1437. m_adThisLineZV = m_adLineZV;
  1438. }
  1439. else
  1440. {
  1441. m_bOverTurn = true;
  1442. m_adThisZV = m_adOverTurnZV;
  1443. m_adThisLineZV = m_adLineOverTurnZV;
  1444. }
  1445. RefreshColorAction();
  1446. }
  1447. private void ChangeColor()
  1448. {
  1449. if (m_bRulerColor)
  1450. m_bRulerColor = false;
  1451. else
  1452. m_bRulerColor = true;
  1453. if (m_bRulerColor)
  1454. RefreshColorAction();
  1455. else
  1456. m_afThisClr = m_afOrgClr;
  1457. }
  1458. private void RefreshColorAction()
  1459. {
  1460. if (m_bRulerColor)
  1461. {
  1462. colorStyle1 = this.radioButton1.Checked;
  1463. if (colorStyle1)
  1464. {
  1465. style1Color1 = this.panel3.BackColor;//.ToArgb();
  1466. style1Color2 = this.panel4.BackColor;//.ToArgb();
  1467. }
  1468. else
  1469. {
  1470. style2ColorList.Clear();
  1471. style2ColorList.Add(this.panel5.BackColor/*.ToArgb()*/);
  1472. style2ColorList.Add(this.panel6.BackColor/*.ToArgb()*/);
  1473. style2ColorList.Add(this.panel7.BackColor/*.ToArgb()*/);
  1474. style2ColorList.Add(this.panel8.BackColor/*.ToArgb()*/);
  1475. style2ColorList.Add(this.panel9.BackColor/*.ToArgb()*/);
  1476. }
  1477. double adZVRange = m_dMaxZV - m_dMinZV;
  1478. //处理颜色和翻转参数
  1479. m_afNewClr = new float[m_iWidth, m_iHeight, 3];
  1480. //m_adOverTurnZV = new double[m_iWidth, m_iHeight];
  1481. for (int iX = 0; iX < m_iWidth; iX++)
  1482. {
  1483. for (int iY = 0; iY < m_iHeight; iY++)
  1484. {
  1485. Color fColor = /*Color.FromArgb(*/CalculationColorfRange(((m_bOverTurn ? m_adOverTurnZV[iX, iY] : m_adZV[iX, iY]) - m_dMinZV) / adZVRange)/*)*/;
  1486. m_afNewClr[iX, iY, 0] = (float)(fColor.R / 255.0);
  1487. m_afNewClr[iX, iY, 1] = (float)(fColor.G / 255.0);
  1488. m_afNewClr[iX, iY, 2] = (float)(fColor.B / 255.0);
  1489. //m_adOverTurnZV[iX, iY] = m_dMinZV + (m_dMaxZV - m_adZV[iX, iY]);
  1490. }
  1491. }
  1492. m_afThisClr = m_afNewClr;
  1493. }
  1494. }
  1495. private bool colorStyle1 = true;
  1496. private Color style1Color1;
  1497. private Color style1Color2;
  1498. private List<Color> style2ColorList = new List<Color>();
  1499. /// <summary>
  1500. /// 根据设置计算彩虹色的变化
  1501. /// </summary>
  1502. /// <param name="dZ"></param>
  1503. /// <returns></returns>
  1504. public Color CalculationColorfRange(double dZ)
  1505. {
  1506. if (dZ < 0)
  1507. dZ = 0;
  1508. if (dZ > 1)
  1509. dZ = 1;
  1510. if (colorStyle1)
  1511. return Color.FromArgb(255, (int)(style1Color1.R + (style1Color2.R - style1Color1.R) * dZ), (int)(style1Color1.G + (style1Color2.G - style1Color1.G) * dZ), (int)(style1Color1.B + (style1Color2.B - style1Color1.B) * dZ));// (int)(style1Color1 + (style1Color2 - style1Color1) * dZ);
  1512. int color_index = Math.Min(3, (int)(dZ / 0.2));
  1513. //for (color_index = 0; color_index < style2ColorList.Count - 1; color_index++)
  1514. //{
  1515. // if ((style2ColorList[color_index] - dZ) * (style2ColorList[color_index + 1] - dZ) <= 0)
  1516. // break;
  1517. //}
  1518. return Color.FromArgb(255, (int)(style2ColorList[color_index].R + (style2ColorList[color_index + 1].R - style2ColorList[color_index].R) * (dZ - color_index * 0.2)), (int)(style2ColorList[color_index].G + (style2ColorList[color_index + 1].G - style2ColorList[color_index].G) * (dZ - color_index * 0.2)), (int)(style2ColorList[color_index].B + (style2ColorList[color_index + 1].B - style2ColorList[color_index].B) * (dZ - color_index * 0.2)));// (int)(style2ColorList[color_index] + (style2ColorList[color_index + 1] - style2ColorList[color_index]) * (dZ - color_index * 0.2));
  1519. //float[] fColor = new float[3];
  1520. //if (dZ < m_adDZ[m_iDLevel - 1])
  1521. //{
  1522. // fColor[0] = (float)m_adDC[m_iDLevel - 1, 0];
  1523. // fColor[1] = (float)m_adDC[m_iDLevel - 1, 1];
  1524. // fColor[2] = (float)m_adDC[m_iDLevel - 1, 2];
  1525. // return fColor;
  1526. //}
  1527. //if (dZ > m_adDZ[0])
  1528. //{
  1529. // fColor[0] = (float)m_adDC[0, 0];
  1530. // fColor[1] = (float)m_adDC[0, 1];
  1531. // fColor[2] = (float)m_adDC[0, 2];
  1532. // return fColor;
  1533. //}
  1534. //int i, j;
  1535. //for (j = 1; j < m_iDLevel; j++)
  1536. //{
  1537. // if (dZ > m_adDZ[j])
  1538. // {
  1539. // break;
  1540. // }
  1541. //}
  1542. //i = j - 1;
  1543. //double dIJ = Math.Abs(m_adDZ[i] - m_adDZ[j]);
  1544. //double dWI = Math.Abs(dZ - m_adDZ[j]) / dIJ;
  1545. //double dWJ = Math.Abs(m_adDZ[i] - dZ) / dIJ;
  1546. //fColor[0] = (float)((m_adDC[i, 0] * dWI + m_adDC[j, 0] * dWJ) / 255.0);
  1547. //fColor[1] = (float)((m_adDC[i, 1] * dWI + m_adDC[j, 1] * dWJ) / 255.0);
  1548. //fColor[2] = (float)((m_adDC[i, 2] * dWI + m_adDC[j, 2] * dWJ) / 255.0);
  1549. //return fColor;
  1550. }
  1551. /*
  1552. private void Form_KeyUp(object sender, KeyEventArgs e) {
  1553. keys[e.KeyValue] = false; // Key Has Been Released, Mark It As false
  1554. }
  1555. */
  1556. private void Form_Resize(object sender, EventArgs e)
  1557. {
  1558. //ReSizeGLScene(form.Width, form.Height); // Resize The OpenGL Window
  1559. }
  1560. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  1561. {
  1562. if ((m_iMusMod <= 0) || (m_iMusMod >= 7))
  1563. {
  1564. return;
  1565. }
  1566. //int iBtnDwn = Glfw.glfwGetMouseButton(Glfw.GLFW_MOUSE_BUTTON_LEFT);
  1567. if (0 == m_iMusDown)
  1568. {
  1569. m_iLastMusDown = 0;
  1570. return;
  1571. }
  1572. else if (0 == m_iLastMusDown)
  1573. {
  1574. m_iLastMusDown = 1;
  1575. m_iLastmouseX = e.X;
  1576. m_iLastmouseY = e.Y;
  1577. return;
  1578. }
  1579. float fXChange = e.X - m_iLastmouseX;
  1580. float fYChange = e.Y - m_iLastmouseY;
  1581. m_fR_xyz[0] = AngleNormalization(m_fR_xyz[0]);
  1582. m_fR_xyz[1] = AngleNormalization(m_fR_xyz[1]);
  1583. if (1 == m_iMusMod)
  1584. {
  1585. if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
  1586. {
  1587. fXChange *= -1.0F;
  1588. }
  1589. m_fR_xyz[0] += fYChange;
  1590. m_fR_xyz[1] += fXChange;
  1591. //m_fR_xyz[2] = 0.0F;
  1592. }
  1593. else if (2 == m_iMusMod)
  1594. {
  1595. m_fT_xyz[0] += fXChange * 0.91F;
  1596. m_fT_xyz[1] += fYChange * -0.91F;
  1597. }
  1598. else if (5 == m_iMusMod)
  1599. {
  1600. if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
  1601. {
  1602. fYChange *= -1.0F;
  1603. }
  1604. if ((m_fR_xyz[1] > 90.0) && (m_fR_xyz[1] < 270.0))//先绕X轴转完了
  1605. {
  1606. fXChange *= -1.0F;
  1607. }
  1608. m_afPonitA[0] += fXChange * 0.95F;
  1609. m_afPonitA[0] = (float)Math.Min(Math.Max(m_afPonitA[0], 1.0), m_iWidth - 1);
  1610. m_afPonitA[1] += fYChange * -0.95F;
  1611. m_afPonitA[1] = (float)Math.Min(Math.Max(m_afPonitA[1], 1.0), m_iHeight - 1);
  1612. CalculationIne();
  1613. }
  1614. else if (6 == m_iMusMod)
  1615. {
  1616. if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
  1617. {
  1618. fYChange *= -1.0F;
  1619. }
  1620. if ((m_fR_xyz[1] > 90.0) && (m_fR_xyz[1] < 270.0))//先绕X轴转完了
  1621. {
  1622. fXChange *= -1.0F;
  1623. }
  1624. m_afPonitB[0] += fXChange * 0.95F;
  1625. m_afPonitB[0] = (float)Math.Min(Math.Max(m_afPonitB[0], 1.0), m_iWidth - 1);
  1626. m_afPonitB[1] += fYChange * -0.95F;
  1627. m_afPonitB[1] = (float)Math.Min(Math.Max(m_afPonitB[1], 1.0), m_iHeight - 1);
  1628. CalculationIne();
  1629. }
  1630. m_iLastmouseX = e.X;
  1631. m_iLastmouseY = e.Y;
  1632. }
  1633. private float AngleNormalization(float fOldAngle)
  1634. {
  1635. float fNewAngle = fOldAngle % 360.0F;
  1636. if (fNewAngle < 0)
  1637. {
  1638. fNewAngle += 360.0F;
  1639. }
  1640. return fNewAngle;
  1641. }
  1642. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  1643. {
  1644. if (e.Button == MouseButtons.Left)
  1645. {
  1646. m_iMusDown = 1;
  1647. }
  1648. }
  1649. private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  1650. {
  1651. if (e.Button == MouseButtons.Left)
  1652. {
  1653. m_iMusDown = 0;
  1654. }
  1655. }
  1656. /// <summary>
  1657. /// 导出图片所有坐标对应的高度值
  1658. /// </summary>
  1659. /// <param name="sender"></param>
  1660. /// <param name="e"></param>
  1661. private void button6_Click(object sender, EventArgs e)
  1662. {
  1663. SaveFileDialog exe = new SaveFileDialog();
  1664. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1665. exe.FilterIndex = 0;
  1666. exe.RestoreDirectory = true;
  1667. exe.Title = "Export Excel File";
  1668. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1669. exe.FileName = this.Text + "-" + "图片高度数据" + DateTime.Now.ToString("yyyyMMddHHmmss");
  1670. DialogResult dr = exe.ShowDialog();
  1671. if (dr != DialogResult.OK)
  1672. return;
  1673. //m_adZV = new double[m_iWidth, m_iHeight];
  1674. List<DataTable> list = new List<DataTable>();
  1675. DataTable dt = new DataTable("tag");
  1676. dt.Columns.Add(new DataColumn(@"Y\X", typeof(string)));
  1677. for (int iX = 0; iX < m_iWidth; iX++)
  1678. dt.Columns.Add(new DataColumn(iX + "", typeof(string)));//这里是X坐标
  1679. for (int itemIndex = 0; itemIndex < m_iHeight; itemIndex++)
  1680. {
  1681. DataRow dataRow = dt.NewRow();
  1682. dataRow[@"Y\X"] = itemIndex.ToString();//这里是Y坐标
  1683. for (int iX = 0; iX < m_iWidth; iX++)
  1684. {
  1685. dataRow[iX + ""] = form.m_adThisZV[iX, m_iHeight - 1 - itemIndex].ToString();
  1686. ////m_adZV[iX, iY] = double.Parse(strarr[iY]);
  1687. //form.m_adThisZV[iX, iY]
  1688. }
  1689. dt.Rows.Add(dataRow);
  1690. }
  1691. OfficeFileHandleHelper.ExporeToExcel(exe.FileName, dt);
  1692. //list.Add(dt);
  1693. //this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName/*, true, true, this, PdnResources.GetString("Menu.ExportdatatoEXECLtable.Text")*/);
  1694. //MessageBox.Show(PdnResources.GetString("Menu.ResultsExportedsuccessfully.Text"));
  1695. //System.IO.Stream ms;
  1696. //ms = exe.OpenFile();
  1697. //System.IO.StreamWriter sw = new System.IO.StreamWriter(ms, System.Text.Encoding.GetEncoding(-0));
  1698. //string str = "";
  1699. //try
  1700. //{
  1701. // for (int i = 0; i < dt.Columns.Count; i++)
  1702. // {
  1703. // if (i > 0)
  1704. // {
  1705. // str += "\t";
  1706. // }
  1707. // str += dt.Columns[i].ColumnName;
  1708. // }
  1709. // sw.WriteLine(str);
  1710. // for (int j = 0; j < dt.Rows.Count; j++)
  1711. // {
  1712. // string temp = "";
  1713. // for (int k = 0; k < dt.Columns.Count; k++)
  1714. // {
  1715. // if (k > 0)
  1716. // {
  1717. // temp += "\t";
  1718. // }
  1719. // string cell = dt.Rows[j][k].ToString();
  1720. // cell = cell.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\r\n", "");
  1721. // temp += cell;
  1722. // }
  1723. // sw.WriteLine(temp);
  1724. // }
  1725. // sw.Close();
  1726. // ms.Close();
  1727. //}
  1728. //catch (Exception ex)
  1729. //{
  1730. // MessageBox.Show(ex.Message);
  1731. // return;
  1732. //}
  1733. //finally
  1734. //{
  1735. // sw.Close();
  1736. // ms.Close();
  1737. //}
  1738. //Base.CommTool.OfficeFileHandleHelper.ExportDataToExcel(exe.FileName, list);
  1739. //测试说不要提示结果
  1740. //MessageBox.Show(PdnResources.GetString("Menu.ResultsExportedsuccessfully.Text"));
  1741. //if (this.m_adValue.Length > 0)
  1742. //{
  1743. // if (dr == DialogResult.OK)
  1744. // {
  1745. // if (this.m_adValue.Length > 0)
  1746. // {
  1747. // List<DataTable> list = new List<DataTable>();
  1748. // DataTable dt = new DataTable("tag");
  1749. // dt.Columns.Add(new DataColumn("序号", typeof(string)));
  1750. // dt.Columns.Add(new DataColumn("高度", typeof(string)));
  1751. // int itemIndex = 0;
  1752. // foreach (var item in this.m_adValue)
  1753. // {
  1754. // DataRow dataRow = dt.NewRow();
  1755. // dataRow["序号"] = itemIndex.ToString();
  1756. // dataRow["高度"] = item.ToString();
  1757. // dt.Rows.Add(dataRow);
  1758. // itemIndex++;
  1759. // }
  1760. // list.Add(dt);
  1761. // ///#########################################
  1762. // Base.CommTool.OfficeFileHandleHelper.ExportDataToExcel(exe.FileName, list);
  1763. // MessageBox.Show(PdnResources.GetString("Menu.ResultsExportedsuccessfully.Text"));
  1764. // }
  1765. // else
  1766. // {
  1767. // MessageBox.Show(PdnResources.GetString("Menu.Selecttheresultstoexport.Text"));
  1768. // return;
  1769. // }
  1770. // }
  1771. //}
  1772. //else
  1773. //{
  1774. // MessageBox.Show("没有获取到测量线高度数据"/*PdnResources.GetString("Menu.Noanalysineratereport.text")*/ + "!");
  1775. //}
  1776. //m_iMusMod = 7;//看剖面线
  1777. //ShowSectionLine();
  1778. }
  1779. /// <summary>
  1780. /// 测量线高度图-导出图片
  1781. /// </summary>
  1782. /// <param name="sender"></param>
  1783. /// <param name="e"></param>
  1784. private void button7_Click(object sender, EventArgs e)
  1785. {
  1786. OpenFileImpl((Bitmap)this.pictureBox2.Image);
  1787. }
  1788. ///// <summary>
  1789. ///// 步长
  1790. ///// </summary>
  1791. //string stepLength = "001";
  1792. /// <summary>
  1793. /// 创建新图片
  1794. /// </summary>
  1795. /// <param name="mat"></param>
  1796. private void OpenFileImpl(Bitmap bitmap)
  1797. {
  1798. if (bitmap != null)
  1799. {
  1800. DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();
  1801. dw.Document = Document.FromImageMat(Camera.Tools.ToMat(bitmap));
  1802. // TODO ZYH 这里的图像名称,需要走系统的配置
  1803. dw.fileText = this.Text + "-" + Startup.instance.step_length/*stepLength*/;
  1804. this.appWorkspace.ActiveDocumentWorkspace = dw;
  1805. //this.appWorkspace.ActiveDocumentWorkspace.PanelBottom.documentStrip.ShowPictures = false;
  1806. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  1807. Startup.instance.step_length += 1;
  1808. }
  1809. }
  1810. /// <summary>
  1811. /// 测量线高度图-导出数据
  1812. /// </summary>
  1813. /// <param name="sender"></param>
  1814. /// <param name="e"></param>
  1815. private void button3_Click(object sender, EventArgs e)
  1816. {
  1817. if (this.m_adValue.Length > 0)
  1818. {
  1819. SaveFileDialog exe = new SaveFileDialog();
  1820. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1821. exe.FilterIndex = 0;
  1822. exe.RestoreDirectory = true;
  1823. exe.Title = "Export Excel File";
  1824. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1825. exe.FileName = this.Text + "-" + "测量线高度数据" + DateTime.Now.ToString("yyyyMMddHHmmss");
  1826. DialogResult dr = exe.ShowDialog();
  1827. if (dr == DialogResult.OK)
  1828. {
  1829. if (this.m_adValue.Length > 0)
  1830. {
  1831. List<DataTable> list = new List<DataTable>();
  1832. DataTable dt = new DataTable("tag");
  1833. dt.Columns.Add(new DataColumn("序号", typeof(string)));
  1834. dt.Columns.Add(new DataColumn("高度", typeof(string)));
  1835. int itemIndex = 0;
  1836. foreach (var item in this.m_adValue)
  1837. {
  1838. DataRow dataRow = dt.NewRow();
  1839. dataRow["序号"] = itemIndex.ToString();
  1840. dataRow["高度"] = item.ToString();
  1841. dt.Rows.Add(dataRow);
  1842. itemIndex++;
  1843. }
  1844. list.Add(dt);
  1845. ///#########################################
  1846. Base.CommTool.OfficeFileHandleHelper.ExportDataToExcel(exe.FileName, list);
  1847. }
  1848. else
  1849. {
  1850. MessageBox.Show(PdnResources.GetString("Menu.Selecttheresultstoexport.Text"));
  1851. return;
  1852. }
  1853. }
  1854. }
  1855. else
  1856. {
  1857. MessageBox.Show("没有获取到测量线高度数据"/*PdnResources.GetString("Menu.Noanalysineratereport.text")*/ + "!");
  1858. }
  1859. }
  1860. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  1861. {
  1862. RefreshColorAction();
  1863. }
  1864. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  1865. {
  1866. RefreshColorAction();
  1867. }
  1868. private Panel panelC;
  1869. /// <summary>
  1870. /// 调色板
  1871. /// </summary>
  1872. private ColorsForm colorsFormGrid;
  1873. /// <summary>
  1874. /// 颜色点击事件
  1875. /// </summary>
  1876. /// <param name="sender"></param>
  1877. /// <param name="e"></param>
  1878. private void panel1_Click(object sender, EventArgs e)
  1879. {
  1880. this.panelC = (Panel)sender;
  1881. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
  1882. this.colorsFormGrid.ShowDialog();
  1883. }
  1884. /// <summary>
  1885. /// PanelC的调色板颜色改变
  1886. /// </summary>
  1887. /// <param name="sender"></param>
  1888. /// <param name="e"></param>
  1889. private void gridColorChanged(object sender, EventArgs e)
  1890. {
  1891. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  1892. //更改背景色,触发事件
  1893. this.panelC.BackColor = color;
  1894. if (this.panelC == this.panel3 || this.panelC == this.panel4)
  1895. {
  1896. if (this.radioButton1.Checked)
  1897. RefreshColorAction();
  1898. }
  1899. else if (!this.radioButton1.Checked && (this.panelC == this.panel5 || this.panelC == this.panel6 || this.panelC == this.panel7 || this.panelC == this.panel8 || this.panelC == this.panel9))
  1900. RefreshColorAction();
  1901. //// 重置黑色背景
  1902. //if (this.panelC == this.panel5)
  1903. //{
  1904. // Gl.glClearColor(color.R, color.G, color.B, color.A);
  1905. // Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
  1906. // //重置模型观察矩阵
  1907. // Gl.glLoadIdentity();
  1908. //}
  1909. //关闭色板
  1910. this.colorsFormGrid.Close();
  1911. }
  1912. private void pictureBox1_MouseLeave(object sender, EventArgs e)
  1913. {
  1914. m_iMusDown = 0;
  1915. }
  1916. }
  1917. }