/// <summary> /// Reacts to selection of the OK button in the dialog. /// </summary> /// <param name="wnd">The dialog window. If this matches the dialog that /// this command knows about, the command will be executed (and, on success, /// the dialog will be destroyed). If it's some other window, it must /// be a sub-dialog created by our guy, so let it handle the request.</param> /// <returns></returns> internal override bool DialFinish(Control wnd) { if (m_Dialog == null) { MessageBox.Show("NewCircleUI.DialFinish - No dialog!"); return(false); } // Get info from the dialog. PointFeature center = m_Dialog.Center; Observation radius = m_Dialog.Radius; // Both items must be defined (the dialog should have confirmed // this in its OnOK handler). if (center == null || radius == null) { MessageBox.Show("NewCircleUI.DialFinish - Insufficient data to add circle."); return(false); } // If we are doing an update, alter the original operation. UpdateUI pup = this.Update; if (pup != null) { // Get the original operation. NewCircleOperation pop = (pup.GetOp() as NewCircleOperation); if (pop == null) { MessageBox.Show("NewCircleUI.DialFinish - Unexpected edit type."); return(false); } pop.Correct(center, radius); } else { // Create empty persistent object (adds to current session) NewCircleOperation op = null; try { op = new NewCircleOperation(center, radius); op.Execute(); } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message); return(false); } } // Get the base class to finish up. return(FinishCommand()); }
void ShowUpdate() { // Get the operation that created the update object (if // we're doing an update). NewCircleOperation creator = GetUpdateOp(); if (creator != null) { InitOp(creator, true); } }
/// <summary> /// Creates a <c>NewCircleForm</c> for a circle, based on a previously /// defined circle. /// </summary> /// <param name="cmd">The command creating this dialog</param> /// <param name="recall">The editing operation that's being recalled (null /// if not doing a recall)</param> internal NewCircleForm(CommandUI cmd, Operation recall) { InitializeComponent(); m_Cmd = cmd; m_Recall = (NewCircleOperation)recall; m_Center = null; m_Radius = null; m_Circle = null; m_RadiusPoint = null; m_RadiusDistance = null; m_Focus = null; }
void InitOp(NewCircleOperation op, bool isUpdate) { // Get the center point and display its ID, preceded by a "+" char. m_Center = op.Center; centerTextBox.Text = String.Format("+{0}", m_Center.FormattedKey); // Get the observation that was used to specify the radius. Observation radius = op.Radius; // Make a copy of the relevant info, depending on whether the // radius was entered, or specified as an offset point. if (radius is OffsetPoint) { // Radius was specified as an offset point. OffsetPoint offset = (radius as OffsetPoint); m_RadiusPoint = offset.Point; m_RadiusDistance = null; // Display the ID of the offset point, preceded with a "+" char. radiusTextBox.Text = String.Format("+{0}", m_RadiusPoint.FormattedKey); if (isUpdate) { // If there are any incident arcs that were added using // a NewLineOperation (on the same circle), disallow the // ability to change the offset point. // @devnote Long story. In short, if the offset point // gets changed, the user could move it anywhere, so quite // a sophisticated UI could be needed to re-define where // the curves should go (failing that, if you let the user // change things, one end of the curve moves, but not the // end that met the offset point => looks bent). This is a // problem even if the curves have subsequently been // de-activated. LineFeature line = op.Line; Circle circle = line.Circle; Debug.Assert(circle != null); if (circle.HasArcsAt(m_RadiusPoint)) { radiusTextBox.Enabled = false; } } } else { // Radius is (or should be) an entered distance. m_RadiusPoint = null; Distance dist = (radius as Distance); if (dist == null) { MessageBox.Show("NewCircleForm.InitOp - Unexpected radius observation."); return; } m_RadiusDistance = new Distance(dist); // Display the radius (will call OnChangeRadius). radiusTextBox.Text = m_RadiusDistance.Format(); } // Ensure points are drawn ok. PaintAll(); }