Esempio n. 1
0
        public PositionalDataForm(PositionalDataShape posData, UnitSystem unitSystem) : this()
        {
            this.unitSystem = unitSystem;

            txtTime.Text = ManeuveringBoard.GetTimeString(posData.Time);
            txtTime.Focus();
            txtTime.SelectAll();

            Text = grpObservation.Text = (posData is Waypoint ? "Waypoint" : "Observation") + " Data";

            PositionalDataShape previousPosition = null;
            UnitShape           observer         = posData is Observation ? ((Observation)posData).Observer : null;

            for (int index = posData.Parent.Children.IndexOf(posData) - 1; index >= 0; index--)
            {
                previousPosition = posData.Parent.Children[index] as PositionalDataShape;
                if (previousPosition != null && previousPosition.GetType() == posData.GetType() &&
                    (!(previousPosition is Observation) || ((Observation)previousPosition).Observer == observer))
                {
                    break;
                }
                else
                {
                    previousPosition = null;
                }
            }
            if (previousPosition != null)
            {
                previousTime = previousPosition.Time;
            }

            if (posData is BearingObservation)
            {
                double bearing = ((BearingObservation)posData).Bearing;
                grpPrevious.Enabled           = false;
                grpObserved.Enabled           = false;
                txtObserverDistance.Enabled   = false;
                txtObserverBearing.Text       = (bearing * MathConst.RadiansToDegrees).ToString("0.##");
                txtObserverBearing.Tag        = bearing;
                txtObservedBearing.WasChanged = false; // ignore programmatic change
            }
            else
            {
                this.posDataPoint = posData.Position;
                FillRelativeTo((UnitShape)posData.Parent, txtObservedBearing, txtObservedDistance, out observedPoint);

                if (posData is PointObservation)
                {
                    FillRelativeTo(observer, txtObserverBearing, txtObserverDistance, out observerPoint);
                }
                else
                {
                    grpObserver.Enabled = false;
                    grpObserved.Text    = "Relative to Unit";
                }

                if (previousPosition == null)
                {
                    grpPrevious.Enabled = false;
                }
                else
                {
                    FillRelativeTo(previousPosition, txtPreviousBearing, txtPreviousDistance, out previousPoint);
                }

                waypoint = posData is Waypoint;
                if (waypoint)
                {
                    waypointTimes = posData.Parent.Children.OfType <Waypoint>().Where(w => w != posData).Select(w => w.Time).ToList();
                }
            }
        }