public void SetLocationTest() { Setup(); // Set up a device PairableDevice device = new PairableDevice { Identifier = "myPad", Location = new Point(1, 1) }; Server.Locator.Devices.Add(device); Server.Start(); Client.Start(); WaitForConnections(); // Build a request to set the device's orientation IARequest request = new IARequest(Routes.SetOrientationRoute); request.Parameters["identifier"] = "myPad"; Point newLocation = new Point(2, 2); request.SetBodyWith(new IntermediatePoint(newLocation)); // Send the request, and test Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception) { Assert.AreEqual(newLocation, device.Location.Value); }); Teardown(); }
protected override void OnDrop(DragEventArgs e) { string DataType = e.Data.GetFormats(true)[0]; //if the object dropped is a tracker if (DataType == "trackerControl") { base.OnDrop(e); Point mouseLocation = e.GetPosition(sharedCanvas); // Grab the data we packed into the DataObject TrackerControl trackerControl = (TrackerControl)e.Data.GetData("trackerControl"); // Hide the Ghost and Text since a Drop has been made MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; // Return the Opacity of the TrackerControl trackerControl.Opacity = 1; trackerControl.Tracker.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); // Check if the TrackerControl is already a child of Shared Canvas Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); if (!trackerControl.IsDescendantOf(SharedCanvas)) { trackerControl.formatForCanvas(); kinectWrapPanel.Children.Remove(trackerControl); SharedCanvas.Children.Add(trackerControl); if (trackerControl.Tracker.Orientation == null) { trackerControl.Tracker.Orientation = 270; } } // if the cursor is outside the canvas, put the tracker back in stackpanel. else if (!(mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y)) { trackerControl.Tracker.StopStreaming(); cleanUpKinectPersons(trackerControl.Tracker.Identifier); trackerControl.formatForStackPanel(); SharedCanvas.Children.Remove(trackerControl); kinectWrapPanel.Children.Add(trackerControl); } } //if the objet dropped is a device. else if (DataType == "deviceControl") { base.OnDrop(e); Point mouseLocation = e.GetPosition(sharedCanvas); // Grab the data we packed into the DataObject DeviceControl deviceControl = (DeviceControl)e.Data.GetData("deviceControl"); // Hide the Ghost and Text since a Drop has been made MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; // Return the Opacity of the DeviceControl deviceControl.Opacity = 1; PairableDevice device = deviceControl.PairableDevice; IADevice iaDevice = deviceControl.IADevice; IARequest request = new IARequest(Routes.SetLocationRoute); request.Parameters["identifier"] = iaDevice.Name; Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); //if the dragged device is a pairable device (i.e iPad) if (!iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { Point mouseLocationOnCanvas = mouseLocation = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); bool pairedToNewDevice = false; foreach (KeyValuePair <PairablePerson, PersonControl> keyPair in PersonControlDictionary) { Point personLocation = keyPair.Key.Location.Value; double distance = Math.Sqrt(Math.Pow(mouseLocationOnCanvas.X - personLocation.X, 2) + Math.Pow(mouseLocationOnCanvas.Y - personLocation.Y, 2)); //if the mouse drop is close to a person, pair the device with that person. if (distance < 0.3 && (device.HeldByPersonIdentifier == keyPair.Key.Identifier || keyPair.Key.PairingState != PairingState.Paired)) { if (device.PairingState == PairingState.Paired || device.PairingState == PairingState.PairedButOccluded) { kinectManager.PairingRecognizer.UnpairDevice(device); } kinectManager.PairingRecognizer.Pair(device, keyPair.Key); pairedToNewDevice = true; break; } } //if the mouse drop is not close to a person then unpair the device. if (!pairedToNewDevice) { kinectManager.PairingRecognizer.UnpairDevice(device); } } //if the dragged device is not a pairable device (i.e table-top) else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y) { // Dropped within Canvas, so we want to place it on the canvas device.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); request.SetBodyWith(new IntermediatePoint(device.Location.Value)); } else { // Not dropped within Canvas, so we want to put it back on the stack panel device.Location = null; request.SetBodyWith(null); } // Send a request to the Device that their location has changed kinectManager.IntAirAct.SendRequest(request, iaDevice); } } }