PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/nx09SitingTool/frmNewMain.cs

#
C# | 286 lines | 247 code | 37 blank | 2 comment | 23 complexity | 55c0f03ecd61bd6a13da9a6d8728fd32 MD5 | raw file
  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.Windows.Forms;
  9. using DotSpatial.Controls;
  10. using DotSpatial.Controls.Docking;
  11. using DotSpatial.Data;
  12. using DotSpatial.Symbology;
  13. using DotSpatial.Topology;
  14. using System.Reflection;
  15. using System.ComponentModel.Composition;
  16. using System.Deployment.Application;
  17. using DevExpress.XtraBars;
  18. using System.IO;
  19. namespace nx09SitingTool
  20. {
  21. public partial class frmNewMain : Form
  22. {
  23. [Export("Shell", typeof(ContainerControl))]
  24. private static ContainerControl Shell;
  25. public frmNewMain()
  26. {
  27. InitializeComponent();
  28. Shell = this;
  29. appManager1.LoadExtensions();
  30. mpMain.GeoMouseMove += mpMain_GeoMouseMove;
  31. }
  32. bool mouseUPBool = false;
  33. int seInt = 1;
  34. double startP = 0;
  35. double endP = 0;
  36. int endR = 0;
  37. int endC = 0;
  38. int startR = 0;
  39. int startC = 0;
  40. clsLCPCoords lc = new clsLCPCoords();
  41. string projSaveFile = null;
  42. private void qButAddLayer_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  43. {
  44. mpMain.AddLayer();
  45. }
  46. private void qButZoomIn_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  47. {
  48. mpMain.FunctionMode = DotSpatial.Controls.FunctionMode.ZoomIn;
  49. }
  50. private void qButZoomOut_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  51. {
  52. mpMain.FunctionMode = DotSpatial.Controls.FunctionMode.ZoomOut;
  53. }
  54. private void qButFixedZoomIn_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  55. {
  56. mpMain.ZoomIn();
  57. }
  58. private void qButFixedZoomOut_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  59. {
  60. mpMain.ZoomOut();
  61. }
  62. private void qButPan_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  63. {
  64. mpMain.FunctionMode = DotSpatial.Controls.FunctionMode.Pan;
  65. }
  66. private void qButMaxExtent_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  67. {
  68. mpMain.ZoomToMaxExtent();
  69. mpMain.FunctionMode = DotSpatial.Controls.FunctionMode.None;
  70. }
  71. private void qButInfo_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  72. {
  73. mpMain.FunctionMode = DotSpatial.Controls.FunctionMode.Info;
  74. }
  75. private void qButSelect_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  76. {
  77. mpMain.FunctionMode = DotSpatial.Controls.FunctionMode.Select;
  78. }
  79. private void qButLoadAtts_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  80. {
  81. if (mpMain.Layers.SelectedLayer as MapPolygonLayer == null)
  82. {
  83. MessageBox.Show("Please select a polygon layer for attributes.", "Improper Layer Selected", MessageBoxButtons.OK);
  84. return;
  85. }
  86. IMapPolygonLayer currentLayer = (IMapPolygonLayer)mpMain.Layers.SelectedLayer;
  87. DataTable curLay = null;
  88. curLay = currentLayer.DataSet.DataTable;
  89. dgAttributes.DataSource = curLay;
  90. }
  91. private void mpMain_GeoMouseMove(object sender, GeoMouseArgs e)
  92. {
  93. tsslXCoord.Text = "X: " + Math.Round(e.GeographicLocation.X, 4);
  94. tsslYCoord.Text = " Y: " + Math.Round(e.GeographicLocation.Y, 4);
  95. }
  96. private void frmNewMain_Load(object sender, EventArgs e)
  97. {
  98. this.Text = "Line Siter " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
  99. }
  100. private void qRbPgTools_Activated(object sender, EventArgs e)
  101. {
  102. }
  103. private void qButLCP_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  104. {
  105. if (!Directory.Exists(@"c:\temp\LineSiter"))
  106. {
  107. Directory.CreateDirectory(@"c:\temp\LineSiter");
  108. }
  109. frmToolExecute newExecute = new frmToolExecute(mpMain, lc);
  110. newExecute.ShowDialog();
  111. }
  112. private void qButReclass_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  113. {
  114. frmReclass rcls = new frmReclass();
  115. rcls.ShowDialog();
  116. }
  117. public void mpMain_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  118. {
  119. Coordinate xy = null;
  120. int seRow = 0;
  121. int seCol = 0;
  122. double seCellValue = 0;
  123. if (mouseUPBool == true)
  124. {
  125. if (mpMain.Layers.SelectedLayer as MapRasterLayer == null)
  126. {
  127. MessageBox.Show("Please select a raster layer to select start and end points.", "Wrong Layer Selected", MessageBoxButtons.OK);
  128. return;
  129. }
  130. IMapRasterLayer seLayer = (IMapRasterLayer)mpMain.Layers.SelectedLayer;
  131. if (seLayer == null)
  132. {
  133. MessageBox.Show("Please select a layer to set start and end points.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  134. return;
  135. }
  136. else
  137. {
  138. IRaster seRaster = seLayer.DataSet;
  139. xy = mpMain.PixelToProj(e.Location);
  140. RcIndex rasterXY = DotSpatial.Data.RasterExt.ProjToCell(seRaster, xy);
  141. seRow = rasterXY.Row;
  142. seCol = rasterXY.Column;
  143. int numCols = seRaster.NumColumns;
  144. int numRows = seRaster.NumRows;
  145. if (seCol > 0 & seCol < seRaster.NumColumns & seRow > 0 & seRow < seRaster.NumRows)
  146. {
  147. if (seInt == 1)
  148. {
  149. startR = seRow;
  150. startC = seCol;
  151. startP = seRaster.Value[seRow, seCol];
  152. tsslStart.Text = "Start- Row: " + Convert.ToString(seRow) + " Column: " + Convert.ToString(seCol);
  153. lc.startRow = rasterXY.Row;
  154. lc.startCol = rasterXY.Column;
  155. seInt++;
  156. }
  157. else if (seInt == 2)
  158. {
  159. endR = seRow;
  160. endC = seCol;
  161. endP = seRaster.Value[seRow, seCol];
  162. tsslEnd.Text = "End- Row: " + Convert.ToString(seRow) + " Column: " + Convert.ToString(seCol);
  163. seInt = 1;
  164. lc.EndRow = rasterXY.Row;
  165. lc.EndCol = rasterXY.Column;
  166. mouseUPBool = false;
  167. }
  168. //seCellValue= seRaster.Value[seRow,seCol];
  169. }
  170. else
  171. {
  172. MessageBox.Show("Value is outside raster bounds. Please select an area on the map.", "Error 120: Selection Out of Bounds", MessageBoxButtons.OK);
  173. }
  174. }
  175. //MessageBox.Show("Point \r\n X: " + seRow +" Y: " + seCol+ " with a value of: " + seCellValue +" was clicked.", "Info", MessageBoxButtons.OK);
  176. }
  177. }
  178. private void qButStartEnd_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  179. {
  180. mouseUPBool = true;
  181. mpMain.MouseUp += new MouseEventHandler(mpMain_MouseUp);
  182. }
  183. private void qRbPgFile_Activated(object sender, EventArgs e)
  184. {
  185. }
  186. private void qButOpen_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  187. {
  188. tsslOpen.Visible = true;
  189. tsslProjName.Text = "Project Loading Please Wait...";
  190. OpenFileDialog opProjFile = new OpenFileDialog();
  191. opProjFile.Filter = "DotSpatial Project Files (*.dspx)|*.dspx";
  192. if (opProjFile.ShowDialog() == DialogResult.OK)
  193. {
  194. appManager1.SerializationManager.OpenProject(opProjFile.FileName);
  195. projSaveFile = opProjFile.FileName;
  196. }
  197. else
  198. {
  199. tsslOpen.Visible = false;
  200. tsslProjName.Text = "No Project Loaded";
  201. return;
  202. }
  203. tsslProjName.Text = projSaveFile;
  204. mpMain.Refresh();
  205. mpMain.ZoomToMaxExtent();
  206. tsslOpen.Visible = false;
  207. }
  208. private void qButSave_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  209. {
  210. tsslSave.Visible = true;
  211. if (projSaveFile != null)
  212. {
  213. appManager1.SerializationManager.SaveProject(projSaveFile);
  214. }
  215. else
  216. {
  217. SaveFileDialog svProjFile = new SaveFileDialog();
  218. svProjFile.Filter = "DotSpatial Project Files (*.dspx)|*.dspx";
  219. if (svProjFile.ShowDialog() == DialogResult.OK)
  220. {
  221. appManager1.SerializationManager.SaveProject(svProjFile.FileName);
  222. projSaveFile = svProjFile.FileName;
  223. }
  224. tsslProjName.Text = projSaveFile;
  225. }
  226. tsslSave.Visible = false;
  227. }
  228. private void qButSaveAs_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  229. {
  230. tsslSave.Visible = true;
  231. SaveFileDialog svProjFile = new SaveFileDialog();
  232. svProjFile.Filter = "DotSpatial Project Files (*.dspx)|*.dspx";
  233. svProjFile.Title = "Save LineSiter Project File";
  234. svProjFile.CreatePrompt = true;
  235. svProjFile.OverwritePrompt = true;
  236. if (svProjFile.ShowDialog() == DialogResult.OK)
  237. {
  238. appManager1.SerializationManager.SaveProject(svProjFile.FileName);
  239. projSaveFile = svProjFile.FileName;
  240. }
  241. tsslProjName.Text = projSaveFile;
  242. tsslSave.Visible = false;
  243. }
  244. private void qButExit_ItemActivated(object sender, Qios.DevSuite.Components.QCompositeEventArgs e)
  245. {
  246. Application.Exit();
  247. }
  248. }
  249. }