public void CustomizeView(Watch3D model, NodeView nodeView) { var dynamoViewModel = nodeView.ViewModel.DynamoViewModel; watch3dModel = model; var renderingTier = (RenderCapability.Tier >> 16); if (renderingTier < 2) { return; } var dynamoModel = dynamoViewModel.Model; var vmParams = new Watch3DViewModelStartupParams(dynamoModel, dynamoViewModel, string.Format("{0} Preview", watch3dModel.GUID)); watch3DViewModel = HelixWatch3DNodeViewModel.Start(watch3dModel, vmParams); if (model.initialCameraData != null) { try { // The deserialization logic is unified between the view model and this node model. // For the node model, we need to supply the deserialization method with the camera node. var cameraNode = model.initialCameraData.ChildNodes.Cast <XmlNode>().FirstOrDefault(innerNode => innerNode.Name.Equals("camera", StringComparison.OrdinalIgnoreCase)); var cameraData = watch3DViewModel.DeserializeCamera(cameraNode); watch3DViewModel.SetCameraData(cameraData); } catch { watch3DViewModel.SetCameraData(new CameraData()); } } model.Serialized += model_Serialized; watch3DView = new Watch3DView() { Width = model.WatchWidth, Height = model.WatchHeight, DataContext = watch3DViewModel }; // When user sizes a watch node, only view gets resized. The actual // NodeModel does not get updated. This is where the view updates the // model whenever its size is updated. // Updated from (Watch3d)View.SizeChanged to nodeView.SizeChanged - height // and width should correspond to node model and not watch3Dview nodeView.SizeChanged += (sender, args) => model.SetSize(args.NewSize.Width, args.NewSize.Height); // set WatchSize in model watch3DView.View.SizeChanged += (sender, args) => model.SetWatchSize(args.NewSize.Width, args.NewSize.Height); var mi = new MenuItem { Header = Resources.ZoomToFit }; mi.Click += mi_Click; nodeView.MainContextMenu.Items.Add(mi); var backgroundRect = new Rectangle { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, IsHitTestVisible = false, }; var bc = new BrushConverter(); var strokeBrush = (Brush)bc.ConvertFrom("#313131"); backgroundRect.Stroke = strokeBrush; backgroundRect.StrokeThickness = 1; var backgroundBrush = new SolidColorBrush(Color.FromRgb(240, 240, 240)); backgroundRect.Fill = backgroundBrush; nodeView.PresentationGrid.Children.Add(backgroundRect); nodeView.PresentationGrid.Children.Add(watch3DView); nodeView.PresentationGrid.Visibility = Visibility.Visible; DataBridge.Instance.RegisterCallback( model.GUID.ToString(), obj => nodeView.Dispatcher.Invoke( new Action <object>(RenderData), DispatcherPriority.Render, obj)); }
public void Watch3D_Reopened_SizeRemainsTheSame() { var random = new Random(); var original = new Watch3D(); // Update the original node instance. var width = original.Width * (1.0 + random.NextDouble()); var height = original.Height * (1.0 + random.NextDouble()); original.SetSize(Math.Floor(width), Math.Floor(height)); var vmParams = new Watch3DViewModelStartupParams(ViewModel.Model, ViewModel, "Test"); var vm1 = HelixWatch3DNodeViewModel.Start(original, vmParams); var cam = vm1.Camera; cam.Position = new Point3D(10, 20, 30); cam.LookDirection = new Vector3D(15, 25, 35); // Ensure the serialization survives through file, undo, and copy. var document = new XmlDocument(); var fileElement = original.Serialize(document, SaveContext.File); var undoElement = original.Serialize(document, SaveContext.Undo); var copyElement = original.Serialize(document, SaveContext.Copy); // Duplicate the node in various save context. var nodeFromFile = new Watch3D(); var vmFile = HelixWatch3DNodeViewModel.Start(nodeFromFile, vmParams); var nodeFromUndo = new Watch3D(); var vmUndo = HelixWatch3DNodeViewModel.Start(nodeFromUndo, vmParams); var nodeFromCopy = new Watch3D(); var vmCopy = HelixWatch3DNodeViewModel.Start(nodeFromCopy, vmParams); nodeFromFile.Deserialize(fileElement, SaveContext.File); nodeFromUndo.Deserialize(undoElement, SaveContext.Undo); nodeFromCopy.Deserialize(copyElement, SaveContext.Copy); var newCam = vmFile.Camera; // Making sure we have properties preserved through file operation. Assert.AreEqual(original.WatchWidth, nodeFromFile.WatchWidth); Assert.AreEqual(original.WatchHeight, nodeFromFile.WatchHeight); Assert.AreEqual(cam.Position.X, newCam.Position.X); Assert.AreEqual(cam.Position.Y, newCam.Position.Y); Assert.AreEqual(cam.Position.Z, newCam.Position.Z); Assert.AreEqual(cam.LookDirection.X, newCam.LookDirection.X); Assert.AreEqual(cam.LookDirection.Y, newCam.LookDirection.Y); Assert.AreEqual(cam.LookDirection.Z, newCam.LookDirection.Z); newCam = vmUndo.Camera; // Making sure we have properties preserved through undo operation. Assert.AreEqual(original.WatchWidth, nodeFromUndo.WatchWidth); Assert.AreEqual(original.WatchHeight, nodeFromUndo.WatchHeight); Assert.AreEqual(cam.Position.X, newCam.Position.X); Assert.AreEqual(cam.Position.Y, newCam.Position.Y); Assert.AreEqual(cam.Position.Z, newCam.Position.Z); Assert.AreEqual(cam.LookDirection.X, newCam.LookDirection.X); Assert.AreEqual(cam.LookDirection.Y, newCam.LookDirection.Y); Assert.AreEqual(cam.LookDirection.Z, newCam.LookDirection.Z); newCam = vmCopy.Camera; // Making sure we have properties preserved through copy operation. Assert.AreEqual(original.WatchWidth, nodeFromCopy.WatchWidth); Assert.AreEqual(original.WatchHeight, nodeFromCopy.WatchHeight); Assert.AreEqual(cam.Position.X, newCam.Position.X); Assert.AreEqual(cam.Position.Y, newCam.Position.Y); Assert.AreEqual(cam.Position.Z, newCam.Position.Z); Assert.AreEqual(cam.LookDirection.X, newCam.LookDirection.X); Assert.AreEqual(cam.LookDirection.Y, newCam.LookDirection.Y); Assert.AreEqual(cam.LookDirection.Z, newCam.LookDirection.Z); }