public static Scenario3D[] Load(XDocument doc) { var result = new List <Scenario3D>(); // Assume the XML is well-formatted for now. Error handling should be added. foreach (var scenarioNode in doc.Descendants("Scenario3D")) { var scenario = new Scenario3D(); var calibrationNode = scenarioNode.Descendants("CalibrationTriangle").First(); // Read size of calibration triangle foreach (Scenario3D.CalibrationTriangleSide triangleSide in Enum.GetValues(typeof(Scenario3D.CalibrationTriangleSide))) { scenario.SetCalibrationTriangleSize(triangleSide, int.Parse(calibrationNode.Attribute(triangleSide.ToString()).Value)); } // Load receivers and their distances to the calibration triangle foreach (var receiverNode in scenarioNode.Descendants("Receiver")) { var receiverAddress = new GOTAddress(int.Parse(receiverNode.Attribute("Id").Value)); scenario.Receivers.Add(receiverAddress); scenario.SetDistanceFromReceiverToCalibrationTriangle(receiverAddress, Scenario3D.CalibrationTrianglePosition.Pos00, int.Parse(receiverNode.Attribute("DistanceTo00").Value)); scenario.SetDistanceFromReceiverToCalibrationTriangle(receiverAddress, Scenario3D.CalibrationTrianglePosition.PosX0, int.Parse(receiverNode.Attribute("DistanceToX0").Value)); scenario.SetDistanceFromReceiverToCalibrationTriangle(receiverAddress, Scenario3D.CalibrationTrianglePosition.PosXY, int.Parse(receiverNode.Attribute("DistanceToXY").Value)); } // Load merge information var mergeTranslation = scenarioNode.Descendants("MergeTranslation").FirstOrDefault(); if (mergeTranslation != null) { scenario.ScenarioTranslation = new Vector3D(int.Parse(mergeTranslation.Attribute("X").Value), int.Parse(mergeTranslation.Attribute("Y").Value), int.Parse(mergeTranslation.Attribute("Z").Value)); } var mergeRotationAxis = scenarioNode.Descendants("MergeRotationAxis").FirstOrDefault(); if (mergeRotationAxis != null) { scenario.ScenarioRotationAxis = new Vector3D(int.Parse(mergeRotationAxis.Attribute("X").Value), int.Parse(mergeRotationAxis.Attribute("Y").Value), int.Parse(mergeRotationAxis.Attribute("Z").Value)); } var mergeRotationAngle = scenarioNode.Descendants("MergeRotationAngle").FirstOrDefault(); if (mergeRotationAngle != null) { scenario.ScenarioRotationAngle = int.Parse(mergeRotationAngle.Attribute("Degrees").Value); } scenario.IsMainScenario = scenarioNode.Attribute("Main") != null && scenarioNode.Attribute("Main").Value.ToLower() == "true"; // Important! Always call UpdateConfigurations after setting all values. Scenario3D.ScenarioStatus status = scenario.UpdateConfigurations(); // TODO: status should also be checked, in case invalid data was saved. result.Add(scenario); } return(result.ToArray()); }
public void AddNewMeasurement(Measurement measurement) { if (this.isCalibrating) { this.calibrator.AddMeasurement(measurement); double progress; if (this.calibrator.IsCalibrationFinished(out progress)) { // Get the finished scenario and close this form. this.isCalibrating = false; this.CalibratedScenario = calibrator.CreateScenario(); this.Close(); } else { calibrationProgress.Value = (int)(progress * 100); } } }