/// <summary> /// Gets another control range /// </summary> /// <returns>The newly created range (with everything set to null)</returns> ControlRange AddRange() { ControlRange r = new ControlRange(); m_Ranges.Add(r); return(r); }
/// <summary> /// Asks the user if they want to load control inside current draw window. If so, /// the control file is scanned to obtain all points inside the window. /// </summary> /// <returns>True if process ran to completion. False if the user indicated that /// they don't want to load points inside the current window, or some error /// was reported during the scan.</returns> bool GetInsideWindow() { // Ask the user whether they want the data inside the current draw window. if (MessageBox.Show("Load control inside current map window?", "No range specified", MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false); } // Get the current display window. IWindow drawin = EditingController.Current.ActiveDisplay.Extent; try { // Scan the control file. For each line, try to form a control object. If // successful, see if it falls within the current draw window. string fspec = controlFileTextBox.Text; ControlRange range = null; ControlPoint control; int nfound = 0; using (StreamReader sr = File.OpenText(fspec)) { string str; while ((str = sr.ReadLine()) != null) { if (ControlPoint.TryParse(str, out control) && drawin.IsOverlap(control)) { nfound++; // If a control range is currently defined, but the // control point cannot be appended, close the range. if (range != null && !range.CanAppend(control)) { range = null; } // If there is no control range, create a new one. if (range == null) { range = AddRange(); } // Append the control point to the current range. range.Append(control); } } } // Show the results ShowRanges(drawin); if (nfound == 0) { MessageBox.Show("No control in current window"); } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(false); }
/// <summary> /// Displays all ranges. /// </summary> /// <param name="win"></param> void ShowRanges(IWindow win) { // Erase whatever's currently in the list controlTextBox.Text = String.Empty; // Return if there are no ranges. if (m_Ranges.Count == 0) { return; } // If the map doesn't have a defined extent, we'll need to initialize // the display with the window we've got if (m_NewMap) { ISpatialDisplay display = m_Cmd.ActiveDisplay; display.ReplaceMapModel(win); // Tell the user the draw scale that has been defined, and ensure points are drawn // at that scale. ProjectSettings ps = EditingController.Current.Project.Settings; double scale = GetSensibleScale(display.MapScale); display.MapScale = scale; if (!m_Cmd.ArePointsDrawn()) { ps.ShowPointScale = (scale + 1); Debug.Assert(m_Cmd.ArePointsDrawn()); } // Ensure the point size isn't TOO small (2mm at the display scale should be fine) ps.PointHeight = 0.002 * scale; string scalemsg = String.Format("Draw scale has been set to 1:{0}", (uint)scale); MessageBox.Show(scalemsg); } // Only show the first 100 ranges (any more, and the string // might get too long to display). StringBuilder sb = new StringBuilder(1000); for (int i = 0; i < Math.Min(100, m_Ranges.Count); i++) { ControlRange r = m_Ranges[i]; // Get the range uint minkey = r.Min; uint maxkey = r.Max; // Form status string string status; int nfound = r.NumDefined; int ncontr = r.NumControl; if (nfound == ncontr) { if (nfound == 1) { status = "found"; } else { status = "all found"; } } else { status = String.Format("found {0} out of {1}", nfound, ncontr); } string output; if (minkey == maxkey) { output = String.Format("{0} ({1})", minkey, status); } else { output = String.Format("{0}-{1} ({2})", minkey, maxkey, status); } sb.Append(output); sb.Append(System.Environment.NewLine); } controlTextBox.Text = sb.ToString(); // Message if all the ranges could not be shown. if (m_Ranges.Count > 100) { string msg = String.Format("Only the first 100 ranges (of {0}) have been listed.", m_Ranges.Count); MessageBox.Show(msg); } }
private void getDataButton_Click(object sender, EventArgs e) { // Get rid of any control list previously loaded. m_Ranges.Clear(); // Go through each line in the edit box, to confirm that the control ranges // are valid. While at it, get a count of the number of ranges. int nrange = 0; int nc = 0; foreach (string line in controlTextBox.Lines) { // Skip empty lines if (line.Length == 0) { continue; } // Confirm the text is valid. If not, select the current line, // issue message, & return. uint minid, maxid; if (GetRange(line, out minid, out maxid) == 0) { controlTextBox.SelectionStart = nc; controlTextBox.SelectionLength = line.Length; string msg = String.Format("Bad range '{0}'", line); MessageBox.Show(msg); return; } // Increment the number of valid ranges. nrange++; // Update the number of characters processed (in case we later need to // select problem text) nc += (line.Length + System.Environment.NewLine.Length); } // If no control has been specified, see if we can do things // using the current display window. if (nrange == 0) { if (m_NewMap) { MessageBox.Show("No control points have been specified."); } else { GetInsideWindow(); } return; } // Define each range (same sort of loop as above). m_Ranges.Capacity = nrange; foreach (string line in controlTextBox.Lines) { // Skip empty lines if (line.Length == 0) { continue; } uint minid, maxid; GetRange(line, out minid, out maxid); ControlRange r = new ControlRange(minid, maxid); m_Ranges.Add(r); } // Load array of control data. IWindow win = LoadControl(); if (win == null || win.IsEmpty) { return; } // Display the results. ShowRanges(win); }
/// <summary> /// Gets another control range /// </summary> /// <returns>The newly created range (with everything set to null)</returns> ControlRange AddRange() { ControlRange r = new ControlRange(); m_Ranges.Add(r); return r; }
private void getDataButton_Click(object sender, EventArgs e) { // Get rid of any control list previously loaded. m_Ranges.Clear(); // Go through each line in the edit box, to confirm that the control ranges // are valid. While at it, get a count of the number of ranges. int nrange = 0; int nc = 0; foreach (string line in controlTextBox.Lines) { // Skip empty lines if (line.Length==0) continue; // Confirm the text is valid. If not, select the current line, // issue message, & return. uint minid, maxid; if (GetRange(line, out minid, out maxid)==0) { controlTextBox.SelectionStart = nc; controlTextBox.SelectionLength = line.Length; string msg = String.Format("Bad range '{0}'", line); MessageBox.Show(msg); return; } // Increment the number of valid ranges. nrange++; // Update the number of characters processed (in case we later need to // select problem text) nc += (line.Length + System.Environment.NewLine.Length); } // If no control has been specified, see if we can do things // using the current display window. if (nrange==0) { if (m_NewMap) MessageBox.Show("No control points have been specified."); else GetInsideWindow(); return; } // Define each range (same sort of loop as above). m_Ranges.Capacity = nrange; foreach (string line in controlTextBox.Lines) { // Skip empty lines if (line.Length==0) continue; uint minid, maxid; GetRange(line, out minid, out maxid); ControlRange r = new ControlRange(minid, maxid); m_Ranges.Add(r); } // Load array of control data. IWindow win = LoadControl(); if (win==null || win.IsEmpty) return; // Display the results. ShowRanges(win); }