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