Esempio n. 1
0
        private void lengthTextBox_TextChanged(object sender, EventArgs e)
        {
            // Return if OnChange handlers have been disabled.
            if (m_IsStatic)
                return;

            if (lengthTextBox.Text.Trim().Length==0)
            {
                // If we already had length info, reset it.
                if (m_LengthOffset!=null)
                    SetNormalColour(m_LengthOffset.Point);

                m_Length = new Distance();
                m_LengthOffset = null;
            }
            else
            {
                // The length could have been specified by the
                // user, or it could have been set as the result of
                // a pointing operation. In the latter case,
                // m_LengthOffset will be defined.

                if (m_LengthOffset==null)
                    ParseLength();
                else
                {
                    // Confirm that the displayed text is the text that was
                    // added by OnSelectPoint. If not, the user may be trying
                    // to type in a length. Permit fewer chars, in case the
                    // user is erasing.
                    string keystr = String.Format("+{0}", m_LengthOffset.Point.FormattedKey);
                    string curstr = lengthTextBox.Text.Trim();

                    if (curstr.Length > keystr.Length)
                    {
                        string msg = "What are you trying to do? If you want to type in a" + System.Environment.NewLine +
                                     "new length, you must initially delete the point ID" + System.Environment.NewLine +
                                     "that is currently displayed.";

                        MessageBox.Show(msg);
                        return;
                    }
                }
            }

            OnChange();
        }
Esempio n. 2
0
        void HandleSelectPoint(PointFeature point)
        {
            if (m_Focus == backsightTextBox)
            {
                // If the user has checked the "use centre" checkbox, how
                // come the user is trying to select another backsight.

                // Ensure that any previously selected backsight reverts
                // to its normal colour.
                SetNormalColour(m_Backsight);

                // Save the specified backsight.
                m_Backsight = point;

                // Display it (causes a call to OnChangeBacksight).
                backsightTextBox.Text = String.Format("+{0}", point.FormattedKey);

                // Move focus to the angle field.
                angleTextBox.Focus();

                return;
            }

            if (m_Focus == angleTextBox)
            {
                // The direction must be getting specified by pointing
                // to two parallel points.

                // Disable the backsight and "use centre" fields.
                backsightTextBox.Enabled = false;
                centreOfCurveCheckBox.Enabled = false;

                // Define either the first or the second parallel point.
                if (m_Par1!=null)
                {
                    SetNormalColour(m_Par2);
                    m_Par2 = point;
                }
                else
                {
                    SetNormalColour(m_Par1);
                    m_Par1 = point;
                }

                // Figure out the window text.

                if (m_Par1!=null && m_Par2!=null)
                    angleTextBox.Text = String.Format("+{0}->{1}", m_Par1.FormattedKey, m_Par2.FormattedKey);
                else
                    angleTextBox.Text = String.Format("+{0} & ...", m_Par1.FormattedKey);

                // Move focus to the length field if we have both parallel points.
                if (m_Par2!=null)
                    lengthTextBox.Focus();

                return;
            }

            if (m_Focus == lengthTextBox)
            {
                // The length is being specified as an offset point.

                // Hold on to the offset point & ensure distance is null.
                if (m_LengthOffset!=null)
                    SetNormalColour(m_LengthOffset.Point);

                m_LengthOffset = new OffsetPoint(point);
                m_Length = new Distance();

                // Display the window text.
                lengthTextBox.Text = String.Format("+{0}", point.FormattedKey);

                // Move focus to the point type.
                entityTypeComboBox.Focus();
                return;
            }
        }
Esempio n. 3
0
        bool InitOp(RadialOperation pop)
        {
            if (pop==null)
                return false;

            // Get the point the sideshot was observed from (unless
            // it is already defined).
            if (m_From==null)
                m_From = pop.From;

            // Was a backsight specified?
            Direction dir = pop.Direction;
            if (dir is AngleDirection)
            {
                AngleDirection angle = (AngleDirection)dir;
                m_Backsight = angle.Backsight;
                m_Radians = angle.ObservationInRadians;
                if (m_Radians < 0.0)
                {
                    m_Radians = Math.Abs(m_Radians);
                    m_IsClockwise = false;
                }
                else
                    m_IsClockwise = true;

                // Is it a deflection?
                m_IsDeflection = (dir is DeflectionDirection);
            }

            // Was direction specified using 2 points (not possible
            // if we've already picked up a backsight).
            if (m_Backsight==null)
            {
                ParallelDirection par = (dir as ParallelDirection);
                if (par!=null)
                {
                    m_Par1 = par.Start;
                    m_Par2 = par.End;
                }
            }
            else
            {
                // Does the backsight point correspond to the centre of a
                // circle that passes through the from-point?

                double radius = Geom.Distance(m_Backsight, m_From);
                if (m_Backsight.GetCircle(radius)!=null)
                    m_WantCentre = true;
            }

            // If we don't have a backsight or a parallel point, it must be a bearing.
            if (!(m_Backsight!=null || m_Par1!=null))
                m_Radians = dir.Bearing.Radians;

            // Did the direction have an offset? If so, make a transient
            // copy (specifying m_Length since it's transient).
            Offset offset = dir.Offset;
            if (offset!=null)
                m_Offset = offset;
                //m_Offset = offset.MakeNewCopy(m_Length);

            // The length was either entered explicitly, or via an offset point.
            Observation length = pop.Length;
            Distance dist = (length as Distance);

            if (dist!=null)
            {
                m_Length = new Distance(dist);
            }
            else
            {
                // It SHOULD be an offset point.
                OffsetPoint offsetPoint = (OffsetPoint)length;
                if (offsetPoint!=null)
                    m_LengthOffset = new OffsetPoint(offsetPoint);
            }

            // Remember whether a line was added.
            if (pop.Line!=null)
                m_WantLine = true;

            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// Parses an explicitly entered sideshot length.
        /// </summary>
        /// <returns>True if length parses ok.</returns>
        bool ParseLength()
        {
            // Get the entered string.
            string str = lengthTextBox.Text.Trim();

            // Try to parse it.
            Distance length = new Distance(str);
            if (!length.IsDefined)
            {
                MessageBox.Show("Invalid length");
                return false;
            }

            // Hold on to the parsed length (and ensure that any previously
            // defined offset point is null -- should really be null already).
            m_Length = length;
            m_LengthOffset = null;

            return true;
        }
Esempio n. 5
0
 private void Zero()
 {
     m_Cmd = null;
     m_Recall = null;
     m_From = null;
     m_Backsight = null;
     m_Par1 = null;
     m_Par2 = null;
     m_Radians = 0.0;
     m_IsClockwise = true;
     m_IsDeflection = false;
     m_Length = new Distance();
     m_LengthOffset = null;
     m_DialOff = null;
     m_Offset = null;
     m_Dir = null;
     m_To = null;
     m_Circles = new List<Circle>();
     m_Focus = null;
     m_WantLine = false;
     m_WantCentre = false;
     m_IsStatic = false;
     m_PointId = null;
 }
Esempio n. 6
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="copy">The offset to copy</param>
 internal OffsetPoint(OffsetPoint copy)
 {
     m_Point = copy.m_Point;
 }
        /// <summary>
        /// Uses the currently displayed information to try to construct a
        /// direction object.
        /// </summary>
        /// <returns>The constructed direction (null if a direction cannot be created
        /// based on the information that's currently displayed)</returns>
        Direction GetCurrentDirection()
        {
            Direction result = null;

            // Get signed direction
            double srad = (m_IsClockwise ? m_Radians : -m_Radians);
            IAngle dir = new RadianValue(srad);

            if (m_Backsight!=null)
            {
                // If we have a backsight, we could either have a regular
                // angle or a deflection. To construct either, we need a
                // from-point as well.

                // Note that an angle of zero (passing through the backsight
                // or foresight) is fine.

                if (m_From!=null)
                {
                    if (m_IsDeflection)
                        result = new DeflectionDirection(m_Backsight, m_From, dir);
                    else
                        result = new AngleDirection(m_Backsight, m_From, dir);
                }
            }
            else if (m_From!=null)
            {
                // No backsight, so we could have either a bearing,
                // or a direction defined using 2 parallel points.
                // Since a bearing of zero is quite valid, we check
                // the dialog field to see if this is an entered value,
                // or just the initial value.

                if (m_Par1!=null && m_Par2!=null)
                    result = new ParallelDirection(m_From, m_Par1, m_Par2);
                else if (m_Radians > Constants.TINY || directionTextBox.Text.Length>0)
                    result = new BearingDirection(m_From, dir);
            }

            // If we haven't formed a direction, ignore any offset
            if (result==null)
                return null;

            // An offset could have been specified by a point, or by
            // entering a distance left or right of the direction.

            Offset offset = null;

            if (m_OffsetPoint!=null)
                offset = new OffsetPoint(m_OffsetPoint);
            else if (m_OffsetDistance!=null)
                offset = new OffsetDistance(m_OffsetDistance, !m_IsRight);

            // If we got an offset, include it in the direction.
            if (offset!=null)
                result.Offset = offset;

            return result;
        }
Esempio n. 8
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="copy">The offset to copy</param>
 internal OffsetPoint(OffsetPoint copy)
 {
     m_Point = copy.m_Point;
 }
Esempio n. 9
0
        /// <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>True if command finished ok</returns>
        internal override bool DialFinish(Control wnd)
        {
            // If it's the offset dialog that's just finished, grab info
            // from it, delete it, and go to the dialog for the first
            // terminal line.

            ISpatialDisplay view = ActiveDisplay;
            UpdateUI up = this.Update;

            if (m_ParDial!=null)
            {
                // Get info from dialog (it'll be ONE of the two). The dialog
                // should only call this function after validating that one
                // of them is defined.
                m_OffsetPoint = m_ParDial.OffsetPoint;
                if (m_OffsetPoint==null)
                    m_Offset = m_ParDial.OffsetDistance;

                // Destroy the dialog.
                KillDialogs();

                // Calculate the positions for the parallel points.
                Calculate();

                // Repaint what we know about.
                Draw();

                // And start the dialog for the first terminal line.
                if (up!=null)
                    m_TermDial1 = new TerminalControl(up, false);
                else
                    m_TermDial1 = new TerminalControl(this, false);

                //m_TermDial1.Show();
                this.Container.Display(m_TermDial1);
                return true;
            }

            if (m_TermDial1!=null)
            {
                // Get the first terminal line (if any). And the position.
                m_TermLine1 = m_TermDial1.TerminalLine;
                m_Term1 = m_TermDial1.TerminalPosition;

                // And move on to the 2nd terminal dialog.
                KillDialogs();

                // Repaint what we know about.

                Draw();
                // And start the dialog for the first terminal line.
                if (up!=null)
                    m_TermDial2 = new TerminalControl(up, true);
                else
                    m_TermDial2 = new TerminalControl(this, true);

                this.Container.Display(m_TermDial2);
                //m_TermDial2.Show();
                return true;
            }

            if (m_TermDial2==null)
                throw new Exception("ParallelLineUI.DialFinish - No dialog!");

            // Get the nortthern terminal line (if any). And the position.
            m_TermLine2 = m_TermDial2.TerminalLine;
            m_Term2 = m_TermDial2.TerminalPosition;

            // Erase everything special that we've drawn.
            ErasePainting();

            // And ensure the view has nothing selected (sometimes the line
            // last selected had been unhighlighted, although it's end points
            // stay highlighted for some reason).
            EditingController.Current.ClearSelection();

            // If we are doing an update, remember the changes
            if (up!=null)
            {
                // Get the original operation.
                ParallelLineOperation op = (ParallelLineOperation)up.GetOp();
                if (op==null)
                    throw new Exception("ParallelLineUI.DialFinish - Unexpected edit type.");

                // Note the offset (it SHOULD be defined)
                Observation offset = null;

                if (m_Offset != null)
                    offset = m_Offset;
                else if (m_OffsetPoint != null)
                    offset = new OffsetPoint(m_OffsetPoint);

                Debug.Assert(offset != null);

                // Remember the changes as part of the UI object (the original edit remains
                // unchanged for now)

                UpdateItemCollection changes = op.GetUpdateItems(m_Line, offset, m_TermLine1, m_TermLine2, m_IsReversed);
                if (!up.AddUpdate(op, changes))
                    return false;
            }
            else
            {
                Observation offset = m_Offset;
                if (offset == null && m_OffsetPoint != null)
                    offset = new OffsetPoint(m_OffsetPoint);
                Debug.Assert(offset!= null);

                // Execute the edit
                ParallelLineOperation op = null;

                try
                {
                    op = new ParallelLineOperation(m_Line, offset, m_TermLine1, m_TermLine2, m_IsReversed);
                    op.Execute();
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.StackTrace, ex.Message);
                    return false;
                }
            }

            // Destroy the dialog(s).
            KillDialogs();

            // Get the base class to finish up.
            return FinishCommand();
        }
        public GetDistanceControl()
        {
            InitializeComponent();

            m_From = null;
            m_ObservedDistance = null;
            m_LineType = null;
            m_Circle = null;
            m_DistancePoint = null;
            m_Distance = null;
            m_OffsetPoint = null;
            m_Focus = null;
        }
        /// <summary>
        /// Displays info for a specific distance observation.
        /// </summary>
        /// <param name="from">The point the distance was observed from.</param>
        /// <param name="obsv">The distance observation (either a <see cref="Distance"/>,
        /// or an <see cref="OffsetPoint"/>)</param>
        /// <param name="line">The line to show (null if no line).</param>
        void ShowDistance(PointFeature from, Observation obsv, LineFeature line)
        {
            // If we have an arc, define its entity type and scroll the
            // entity combo box to that type. Note that when the string
            // is selected, it is important that m_From and m_Distance
            // are null; otherwise <mf CdGetDist::OnSelChangeLineType>
            // may automatically move on to the next page of the wizard
            // dialog.

            m_From = null;
            m_Distance = null;
            m_LineType = null;

            if (line!=null)
            {
                m_LineType = line.EntityType;
                lineTypeComboBox.SelectEntity(m_LineType);
            }

            // Define the from-point of the distance
            m_From = from;
            fromPointTextBox.Text = m_From.FormattedKey;

            // What sort of distance observation do we have?
            m_ObservedDistance = null; // m_pDistance
            m_DistancePoint = null;
            m_Distance = null;

            if (obsv is Distance)
            {
                // Display the distance in the original data entry units.
                Distance dist = (obsv as Distance);
                m_Distance = new Distance(dist);
                distanceTextBox.Text = m_Distance.Format();

                // Create the appropriate distance observation (this is what
                // gets picked up when we actually go to work out the intersection.
                // (was on the last page of the property sheet -- see CdIntersectTwo)
                m_ObservedDistance = m_Distance;
            }
            else
            {
                // It SHOULD be an offset point.
                OffsetPoint off = (obsv as OffsetPoint);
                if (off==null)
                    throw new Exception("GetDistanceControl.ShowDistance - Unexpected type of distance.");

                // Get the point involved & display it's ID.
                m_DistancePoint = off.Point;
                distanceTextBox.Text = m_DistancePoint.FormattedKey;

                // Create the appropriate distance observation
                m_OffsetPoint = new OffsetPoint(m_DistancePoint);
                m_ObservedDistance = m_OffsetPoint;
            }
        }
        /// <summary>
        /// Uses the currently displayed information to try to construct a
        /// circle representing the distance.
        /// </summary>
        /// <returns>The constructed circle (null if a circle cannot be created
        /// based on the information that's currently displayed)</returns>
        Circle GetCurrentCircle()
        {
            Circle result = null;

            // Undefine the address of the relevant distance observation.
            m_ObservedDistance = null;

            if (m_From==null)
                return null;

            if (m_DistancePoint!=null || (m_Distance!=null && m_Distance.Meters>Constants.TINY))
            {
                double radius;

                // If we have an offset point, get the radius.
                if (m_DistancePoint!=null)
                    radius = Geom.Distance(m_From, m_DistancePoint);
                else
                    radius = m_Distance.Meters;

                // Construct the circle
                result = new Circle(m_From, radius);

                // Create the appropriate distance observation (this is what
                // gets picked up when we actually go to work out the
                // intersection on the last page of the intersect dialog.

                if (m_DistancePoint!=null)
                {
                    m_OffsetPoint = new OffsetPoint(m_DistancePoint);
                    m_ObservedDistance = m_OffsetPoint;
                }
                else
                    m_ObservedDistance = m_Distance;
            }

            return result;
        }