SampleXYSearchUI.cs
Copy Code
|
|
---|---|
using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; using Miner.ComCategories; using Miner.Framework.Search; using Miner.Interop; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geodatabase; namespace Miner.Samples.Search.Strategies { [ClassInterface(ClassInterfaceType.None)] [Guid("5F24275E-9A43-4adc-B462-4DD6170C2FB6")] [ProgId("MinerDeveloperSamples.SampleXYSearchUI")] [ComponentCategory(ComCategory.MMLocatorSearchStrategyUI)] public class XYSearchUI : System.Windows.Forms.UserControl, IMMSearchStrategyUI { private IMap _map; private IActiveView _activeView; private IScreenDisplay _screenDisplay; private DecimalConverter _converter = new DecimalConverter(); private IObjectClass _classFilter = null; private string _caption = "Sample XY Search"; private int _priority = 0; private System.Windows.Forms.TextBox txtXCoord; private System.Windows.Forms.TextBox txtYCoord; private System.Windows.Forms.TextBox txtDistance; private System.Windows.Forms.Label lblX; private System.Windows.Forms.Label lblY; private System.Windows.Forms.Button btnXYTool; private System.Windows.Forms.Label lblDistance; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public XYSearchUI() { try { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); SetXYToolImage(); } catch (Exception xcp) { MessageBox.Show("Failure in Ctor: " + xcp.ToString()); } } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.txtXCoord = new System.Windows.Forms.TextBox(); this.txtYCoord = new System.Windows.Forms.TextBox(); this.txtDistance = new System.Windows.Forms.TextBox(); this.lblX = new System.Windows.Forms.Label(); this.lblY = new System.Windows.Forms.Label(); this.lblDistance = new System.Windows.Forms.Label(); this.btnXYTool = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtXCoord // this.txtXCoord.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtXCoord.Location = new System.Drawing.Point(56, 8); this.txtXCoord.Name = "txtXCoord"; this.txtXCoord.Size = new System.Drawing.Size(100, 20); this.txtXCoord.TabIndex = 0; this.txtXCoord.Text = "000000"; // // txtYCoord // this.txtYCoord.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtYCoord.Location = new System.Drawing.Point(56, 40); this.txtYCoord.Name = "txtYCoord"; this.txtYCoord.Size = new System.Drawing.Size(100, 20); this.txtYCoord.TabIndex = 1; this.txtYCoord.Text = "111111"; this.txtYCoord.WordWrap = false; // // txtDistance // this.txtDistance.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtDistance.Location = new System.Drawing.Point(16, 96); this.txtDistance.Name = "txtDistance"; this.txtDistance.Size = new System.Drawing.Size(100, 20); this.txtDistance.TabIndex = 2; this.txtDistance.Text = "22222"; // // lblX // this.lblX.Location = new System.Drawing.Point(8, 8); this.lblX.Name = "lblX"; this.lblX.Size = new System.Drawing.Size(40, 16); this.lblX.TabIndex = 3; this.lblX.Text = "X:"; this.lblX.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // lblY // this.lblY.Location = new System.Drawing.Point(8, 40); this.lblY.Name = "lblY"; this.lblY.Size = new System.Drawing.Size(40, 16); this.lblY.TabIndex = 2; this.lblY.Text = "Y:"; this.lblY.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // lblDistance // this.lblDistance.Location = new System.Drawing.Point(16, 72); this.lblDistance.Name = "lblDistance"; this.lblDistance.Size = new System.Drawing.Size(144, 16); this.lblDistance.TabIndex = 1; this.lblDistance.Text = "Search Distance:"; this.lblDistance.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // btnXYTool // this.btnXYTool.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnXYTool.Location = new System.Drawing.Point(168, 16); this.btnXYTool.Name = "btnXYTool"; this.btnXYTool.Size = new System.Drawing.Size(32, 32); this.btnXYTool.TabIndex = 0; this.btnXYTool.TabStop = false; this.btnXYTool.Click += new System.EventHandler(this.btnXYTool_Click); // // XYSearchUI // this.Controls.Add(this.btnXYTool); this.Controls.Add(this.lblDistance); this.Controls.Add(this.lblY); this.Controls.Add(this.lblX); this.Controls.Add(this.txtDistance); this.Controls.Add(this.txtYCoord); this.Controls.Add(this.txtXCoord); this.Name = "XYSearchUI"; this.Size = new System.Drawing.Size(216, 128); this.Load += new System.EventHandler(this.XYSearchUI_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion #region Private Methods private void SetXYToolImage() { try { Bitmap xyBmp = new Bitmap(GetType().Assembly.GetManifestResourceStream("Miner.Samples.XYSearchStrategy.XYPointerTool.bmp")); xyBmp.MakeTransparent(xyBmp.GetPixel(0,0)); btnXYTool.Image = xyBmp; } catch (Exception xcp) { MessageBox.Show("Failed to set image" + xcp.ToString()); } } private IMMSearchConfiguration GetUserSettings() { Decimal x = (Decimal) _converter.ConvertFromString(txtXCoord.Text); Decimal y = (Decimal) _converter.ConvertFromString(txtYCoord.Text); Decimal d = (Decimal) _converter.ConvertFromString(txtDistance.Text); double X = (double) Convert.ToDouble(x); double Y = (double) Convert.ToDouble(y); double D = (double) Convert.ToDouble(d); if (D <= 1) D = 1; IPropertySet properties = new PropertySetClass(); properties.SetProperty("Map", _map); properties.SetProperty("XCoord", X); properties.SetProperty("YCoord", Y); properties.SetProperty("Distance", D); properties.SetProperty("ObjectClass", _classFilter); IMMSearchConfiguration config = new SearchConfiguration(); if (null == config) return null; config.SearchParameters = properties; return config; } private void GetCoordsFromXYTool() { IPoint point = null; IGeometry geom = new PointClass(); IRubberBand rb = new RubberPointClass(); if (rb.TrackExisting(_screenDisplay, null, geom)) { point = rb.TrackNew(_screenDisplay, null) as IPoint; } if (point != null) { txtXCoord.Text = point.X.ToString(); txtYCoord.Text = point.Y.ToString(); txtDistance.Focus(); } } #endregion #region IMMSearchStrategyUI Members public void InitializeStrategyUI(ESRI.ArcGIS.Carto.IMap pMap, ESRI.ArcGIS.Geodatabase.IObjectClass pClassFilter) { _map = pMap; _activeView = pMap as IActiveView; _screenDisplay = _activeView.ScreenDisplay; _classFilter = pClassFilter; } public void Deactivated() { } public int Priority { get { return _priority; } } public void Reset() { txtXCoord.Text = ""; txtYCoord.Text = ""; txtDistance.Text = ""; } public IMMSearchStrategy SearchStrategy { get { IMMSearchStrategy strategy = new XYSearch() as IMMSearchStrategy; if (null == strategy) { throw new Exception("Failed to create new SampleXYSearch"); } return strategy; } } public string Caption { get { return _caption; } } public IMMSearchConfiguration GetSearchConfiguration(mmSearchOptionFlags optionFlags) { return GetUserSettings(); } public void Shutdown() { //do nothing } public string COMProgID { get { return null; } } public IMMResultsProcessor ResultsProcessor { get { return null; } } #endregion #region User Interface Events private void btnXYTool_Click(object sender, System.EventArgs e) { try { System.Windows.Forms.Cursor xyCursor = new System.Windows.Forms.Cursor(GetType().Assembly.GetManifestResourceStream("Miner.Samples.XYSearchStrategy.XYSearchCursor.cur")); this.Cursor = xyCursor; GetCoordsFromXYTool(); } catch (Exception xcp) { MessageBox.Show("Failed to process XYTool click" + xcp.ToString()); // dont throw! } finally { this.Cursor = Cursors.Default; } } #endregion private void XYSearchUI_Load(object sender, EventArgs e) { } } } |