public static LineShape Load(XmlReader reader) { LineShape line = new LineShape(); line.Start = ManeuveringBoard.ParseXmlPoint(reader.GetStringAttribute("start")); line.End = ManeuveringBoard.ParseXmlPoint(reader.GetStringAttribute("end")); return(line); }
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); }
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; }