Ejemplo n.º 1
0
        public static HelixWatch3DNodeViewModel Start(Dynamo.Nodes.Watch3D node, Watch3DViewModelStartupParams parameters)
        {
            var vm = new HelixWatch3DNodeViewModel(node, parameters);

            vm.OnStartup();
            return(vm);
        }
Ejemplo n.º 2
0
        private HelixWatch3DNodeViewModel(Dynamo.Nodes.Watch3D node, Watch3DViewModelStartupParams parameters) :
            base(parameters)
        {
            watchNode   = node;
            IsResizable = true;

            RegisterPortEventHandlers(node);

            watchNode.Serialized   += SerializeCamera;
            watchNode.Deserialized += watchNode_Deserialized;
        }
Ejemplo n.º 3
0
        private HelixWatch3DNodeViewModel(Dynamo.Nodes.Watch3D node, Watch3DViewModelStartupParams parameters):
            base(parameters)
        {
            watchNode = node;
            IsResizable = true;

            RegisterPortEventHandlers(node);

            watchNode.Serialized += SerializeCamera;
            watchNode.Deserialized += watchNode_Deserialized;
        }
        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);
            var vm1 = new HelixWatch3DNodeViewModel(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 = new HelixWatch3DNodeViewModel(nodeFromFile, vmParams);

            var nodeFromUndo = new Watch3D();
            var vmUndo = new HelixWatch3DNodeViewModel(nodeFromUndo, vmParams);

            var nodeFromCopy = new Watch3D();
            var vmCopy = new HelixWatch3DNodeViewModel(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);
        }