Beispiel #1
0
        protected void StartDynamo()
        {
            var assemblyPath = Assembly.GetExecutingAssembly().Location;

            preloader = new Preloader(Path.GetDirectoryName(assemblyPath));
            preloader.Preload();

            TestPathResolver pathResolver = null;
            var preloadedLibraries        = new List <string>();

            GetLibrariesToPreload(preloadedLibraries);

            if (preloadedLibraries.Any())
            {
                // Only when any library needs preloading will a path resolver be
                // created, otherwise DynamoModel gets created without preloading
                // any library.
                //

                var pathResolverParams = new TestPathResolverParams()
                {
                    UserDataRootFolder   = GetUserUserDataRootFolder(),
                    CommonDataRootFolder = GetCommonDataRootFolder()
                };

                pathResolver = new TestPathResolver(pathResolverParams);
                foreach (var preloadedLibrary in preloadedLibraries.Distinct())
                {
                    pathResolver.AddPreloadLibraryPath(preloadedLibrary);
                }
            }

            var model = DynamoModel.Start(
                new DynamoModel.DefaultStartConfiguration()
            {
                PathResolver        = pathResolver,
                StartInTestMode     = true,
                GeometryFactoryPath = preloader.GeometryFactoryPath,
                ProcessMode         = TaskProcessMode.Synchronous
            });

            var watch3DViewParams = new Watch3DViewModelStartupParams(model);

            this.ViewModel = DynamoViewModel.Start(
                new DynamoViewModel.StartConfiguration()
            {
                DynamoModel      = model,
                Watch3DViewModel = new DefaultWatch3DViewModel(null, watch3DViewParams)
            });

            Assert.AreEqual(ViewModel.Model.State, DynamoModel.DynamoModelState.StartedUIless);

            this.ViewModel.RequestUserSaveWorkflow += RequestUserSaveWorkflow;
        }
        public HelixWatch3DNodeViewModel(Watch3D node, Watch3DViewModelStartupParams parameters)
            : base(node, parameters)
        {
            IsResizable = true;

            RegisterPortEventHandlers(node);

            node.Serialized   += SerializeCamera;
            node.Deserialized += watchNode_Deserialized;

            Name = string.Format("{0} Preview", node.GUID);
        }
        private DynamoRevitViewModel(StartConfiguration startConfiguration) :
            base(startConfiguration)
        {
            var model = (RevitDynamoModel)Model;

            model.RevitDocumentChanged          += model_RevitDocumentChanged;
            model.RevitContextAvailable         += model_RevitContextAvailable;
            model.RevitContextUnavailable       += model_RevitContextUnavailable;
            model.RevitDocumentLost             += model_RevitDocumentLost;
            model.RevitViewChanged              += model_RevitViewChanged;
            model.InvalidRevitDocumentActivated += model_InvalidRevitDocumentActivated;

            if (RevitWatch3DViewModel.GetTransientDisplayMethod() == null)
            {
                return;
            }

            var watch3DParams = new Watch3DViewModelStartupParams(model);
            var watch3DVm     = new RevitWatch3DViewModel(watch3DParams);

            RegisterWatch3DViewModel(watch3DVm, new DefaultRenderPackageFactory());
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);

            watch3DViewModel = new HelixWatch3DNodeViewModel(watch3dModel, vmParams);
            watch3DViewModel.Setup(dynamoViewModel,
                                   dynamoViewModel.RenderPackageFactoryViewModel.Factory);

            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;
            watch3DViewModel.ViewCameraChanged += (s, args) =>
            {
                var camera = watch3DViewModel.GetCameraInformation();
                watch3dModel.Camera.Name  = camera.Name;
                watch3dModel.Camera.EyeX  = camera.EyePosition.X;
                watch3dModel.Camera.EyeY  = camera.EyePosition.Y;
                watch3dModel.Camera.EyeZ  = camera.EyePosition.Z;
                watch3dModel.Camera.LookX = camera.LookDirection.X;
                watch3dModel.Camera.LookY = camera.LookDirection.Y;
                watch3dModel.Camera.LookZ = camera.LookDirection.Z;
                watch3dModel.Camera.UpX   = camera.UpDirection.X;
                watch3dModel.Camera.UpY   = camera.UpDirection.Y;
                watch3dModel.Camera.UpZ   = camera.UpDirection.Z;
            };

            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));
        }
Beispiel #6
0
 public RevitWatch3DViewModel(Watch3DViewModelStartupParams parameters) : base(parameters)
 {
     Name = Resources.BackgroundPreviewName;
     Draw();
 }