Example #1
0
        public InterceptForm(UnitShape unit, UnitShape target, UnitSystem unitSystem, bool disableControls) : this()
        {
            if (target != null)
            {
                if (unit != null)
                {
                    txtBearing.Text    = ManeuveringBoard.GetAngleString(ManeuveringBoard.AngleBetween(unit.Position, target.Position));
                    txtRange.Text      = ManeuveringBoard.GetDistanceString((target.Position - unit.Position).Length, unitSystem);
                    txtBearing.Enabled = txtRange.Enabled = !disableControls;
                    txtSpeed.Select();
                }

                txtCourse.Text      = ManeuveringBoard.GetAngleString(target.Direction);
                txtTargetSpeed.Text = ManeuveringBoard.GetSpeedString(target.Speed, unitSystem);
                txtCourse.Enabled   = txtTargetSpeed.Enabled = !disableControls;
            }

            if (unit == null)
            {
                radVector.Enabled = radWaypoint.Enabled = btnOK.Enabled = false;
            }

            this.unit       = unit;
            this.target     = target;
            this.unitSystem = unitSystem;
            UpdateSolution();
        }
Example #2
0
            public override void Update(Shape shape, BoardPoint dragStart, BoardPoint dragPoint)
            {
                UnitShape unit   = (UnitShape)shape;
                Vector2   vector = dragPoint - dragStart;

                unit.Direction = ManeuveringBoard.SwapBearing(vector.Angle);
                unit.Speed     = vector.Length * (1.0 / ManeuveringBoard.VectorTime);
            }
Example #3
0
        public TDCForm(UnitShape unit, UnitShape target, UnitSystem unitSystem, bool disableControls) : this()
        {
            if (unit == null)
            {
                btnOKTDC.Enabled = false;
            }

            this.unit       = unit;
            this.target     = target;
            this.unitSystem = unitSystem;
            UpdateSolution();
        }
Example #4
0
        private void miTDC_Click(object sender, EventArgs e)
        {
            UnitShape reference = board.ReferenceShape as UnitShape, selected = board.SelectedShape as UnitShape;

            using (TDCForm form = new TDCForm(reference, selected, board.UnitSystem, false))
            {
                if (form.ShowDialog() == DialogResult.OK && reference != null)
                {
                    board.ApplyTDC(reference, form);
                }
            }
        }
Example #5
0
        void miQuickInterceptTool_Click(object sender, EventArgs e)
        {
            UnitShape reference = board.ReferenceShape as UnitShape, selected = board.SelectedShape as UnitShape;

            using (InterceptForm form = new InterceptForm(reference, selected, board.UnitSystem, false))
            {
                if (form.ShowDialog() == DialogResult.OK && reference != null)
                {
                    board.ApplyIntercept(reference, form);
                }
            }
        }
Example #6
0
 void NewBoard()
 {
     if (CloseBoard())
     {
         UnitShape ownShip = new UnitShape()
         {
             Name = "Own ship", Type = UnitShapeType.OwnShip
         };
         board.Center     = AdamMil.Mathematics.Geometry.Point2.Empty;
         board.ZoomFactor = 1.0 / 32;
         board.RootShapes.Add(ownShip);
         board.ReferenceShape = ownShip;
         board.SelectedShape  = ownShip;
         board.WasChanged     = false;
     }
 }
Example #7
0
        public static new UnitShape Load(XmlReader reader, Dictionary <Observation, string> observers, Dictionary <string, UnitShape> unitsById)
        {
            UnitShape shape = new UnitShape();

            shape.Name      = reader.GetAttribute("name");
            shape.Position  = ManeuveringBoard.ParseXmlPoint(reader.GetStringAttribute("position"));
            shape.Direction = reader.GetDoubleAttribute("course");
            shape.Speed     = reader.GetDoubleAttribute("speed");
            shape.Type      = Utility.ParseEnum <UnitShapeType>(reader.GetStringAttribute("type", "unknown"), true);

            string id = reader.GetAttribute("id");

            if (!string.IsNullOrEmpty(id))
            {
                unitsById.Add(id, shape);
            }

            if (!reader.IsEmptyElement)
            {
                reader.Read();
                while (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.LocalName == "tmaSolution")
                    {
                        shape.TMASolution = TMASolution.Load(reader);
                    }
                    else if (reader.LocalName == "children" && !reader.IsEmptyElement)
                    {
                        reader.Read(); // move to either the first child or the end element
                        while (reader.NodeType == XmlNodeType.Element)
                        {
                            shape.Children.Add(Shape.Load(reader, observers, unitsById));
                        }
                        reader.ReadEndElement();
                    }
                    else
                    {
                        throw new InvalidDataException("Expected element " + reader.LocalName);
                    }
                }
            }

            return(shape);
        }
Example #8
0
        public static Shape Load(XmlReader reader, Dictionary <Observation, string> observers, Dictionary <string, UnitShape> unitsById)
        {
            Shape shape;

            switch (reader.LocalName)
            {
            case "circle": shape = CircleShape.Load(reader); break;

            case "line": shape = LineShape.Load(reader); break;

            case "unit": shape = UnitShape.Load(reader, observers, unitsById); break;

            case "bearingObservation": shape = BearingObservation.Load(reader, observers); break;

            case "pointObservation": shape = PointObservation.Load(reader, observers); break;

            case "waypoint": shape = Waypoint.Load(reader); break;

            default: throw new System.IO.InvalidDataException("Unknown shape tag: " + reader.LocalName);
            }

            reader.Read();
            return(shape);
        }
Example #9
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();
                }
            }
        }
Example #10
0
            public override string GetStatusText(Shape shape)
            {
                UnitShape unit = (UnitShape)shape;

                return(ManeuveringBoard.GetAngleString(unit.Direction) + ", " + unit.Board.GetSpeedString(unit.Speed));
            }
Example #11
0
        public ShapeDataForm(Shape shape, UnitSystem unitSystem) : this()
        {
            if (shape == null)
            {
                throw new ArgumentNullException();
            }

            this.unitSystem = unitSystem;

            txtName.Text   = shape.Name;
            lblParent.Text = shape.Parent == null ? "<none>" : string.IsNullOrEmpty(shape.Parent.Name) ? "<unnamed shape>" : shape.Parent.Name;

            UnitShape unit = shape as UnitShape;

            if (unit != null)
            {
                txtSize.Enabled = false;

                txtDirection.Tag      = unit.Direction;
                txtDirection.Text     = (unit.Direction * MathConst.RadiansToDegrees).ToString("0.##");
                txtSpeed.Tag          = unit.Speed;
                txtSpeed.Text         = ManeuveringBoard.GetSpeedString(unit.Speed, unitSystem);
                cmbType.SelectedIndex = (int)unit.Type;

                if (unit.Parent == null)
                {
                    chkRelative.Enabled = false;
                }
                else
                {
                    chkRelative.Checked = unit.IsMotionRelative;
                }
            }
            else
            {
                txtSpeed.Enabled    = false;
                chkRelative.Enabled = false;
                cmbType.Enabled     = false;

                LineShape line = shape as LineShape;
                if (line != null)
                {
                    double angle = ManeuveringBoard.AngleBetween(line.Start, line.End), length = line.Length;
                    txtDirection.Text = (angle * MathConst.RadiansToDegrees).ToString("0.##");
                    txtDirection.Tag  = angle;
                    txtSize.Text      = ManeuveringBoard.GetDistanceString(length, unitSystem);
                    txtSize.Tag       = length;
                }
                else
                {
                    CircleShape circle = shape as CircleShape;
                    if (circle != null)
                    {
                        txtDirection.Enabled = false;
                        txtSize.Text         = ManeuveringBoard.GetDistanceString(circle.Radius, unitSystem);
                        txtSize.Tag          = circle.Radius;
                        lblSize.Text         = "Radius";
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }

            // set these to false, since they may have been set to true by the programmatic changes above
            directionTextChanged = sizeTextChanged = speedTextChanged = false;
        }