Example #1
0
        /// <summary>
        /// Implements the MouseMove event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        protected virtual void MouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            var clickRay = BackgroundPreviewViewModel.GetClickRay(mouseEventArgs);

            if (clickRay == null)
            {
                return;
            }

            if (GizmoInAction == null)
            {
                HighlightGizmoOnRollOver(clickRay);
                return;
            }

            if (!CanMoveGizmo(GizmoInAction))
            {
                return;
            }

            var offset = GizmoInAction.GetOffset(clickRay.GetOriginPoint(), clickRay.GetDirectionVector());

            if (offset.Length < 0.01)
            {
                return;
            }

            newPosition = OnGizmoMoved(GizmoInAction, offset);
        }
Example #2
0
 private void Redraw()
 {
     if (manipulator.IsEnabled())
     {
         BackgroundPreviewViewModel.AddGeometryForRenderPackages(GetDrawables());
     }
 }
Example #3
0
        /// <summary>
        /// Generates render packages for all the drawables of this manipulator.
        /// Before actually generating the render packages it ensures that this
        /// object is properly updated. This method is called when the output
        /// of the node is rendered.
        /// This function can only be called on the UI thread if there's a node selection OR
        /// called on the scheduler thread if there's a node update
        /// </summary>
        /// <returns>List of render packages</returns>
        private IEnumerable <IRenderPackage> GenerateRenderPackages()
        {
            var packages = new List <IRenderPackage>();

            // This can happen only when the node is updating along with the manipulator
            // and meanwhile it is deselected in the UI before the manipulator is killed
            if (!Node.IsSelected)
            {
                return(packages);
            }

            AssignInputNodes();

            active = UpdatePosition();

            if (!IsEnabled())
            {
                return(packages);
            }

            // Blocking call to build render packages only in UI thread
            // to avoid race condition with gizmo members b/w scheduler and UI threads.
            // Race condition can occur if say one gizmo is moving due to another gizmo
            // and it is highlighted when it comes near the mouse pointer.
            IEnumerable <IRenderPackage> result = null;

            BackgroundPreviewViewModel.Invoke(() => result = BuildRenderPackage());
            return(result);
        }
Example #4
0
        /// <summary>
        /// Implements the MouseDown event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseButtonEventArgs"></param>
        protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            UpdatePosition();
            GizmoInAction = null; //Reset Drag.

            var gizmos = GetGizmos(false);

            if (!Active || !IsEnabled() || null == gizmos || !gizmos.Any())
            {
                return;
            }

            var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs);

            if (ray == null)
            {
                return;
            }

            foreach (var item in gizmos)
            {
                object hitObject;
                if (item.HitTest(ray.GetOriginPoint(), ray.GetDirectionVector(), out hitObject))
                {
                    GizmoInAction = item;
                    var nodes = OnGizmoClick(item, hitObject);
                    if (null != nodes && nodes.Any())
                    {
                        WorkspaceModel.RecordModelsForModification(nodes);
                    }
                    newPosition = GizmoInAction.Origin;
                    return;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Removes Gizmos from background preview.
        /// </summary>
        private void HideGizmos()
        {
            var gizmos = GetGizmos(false);

            foreach (var item in gizmos)
            {
                BackgroundPreviewViewModel.DeleteGeometryForIdentifier(item.Name);
            }
        }
Example #6
0
        /// <summary>
        /// Method to draw manipulator.
        /// It's always called on the UI thread
        /// </summary>
        private void DrawManipulator()
        {
            Debug.Assert(IsMainThread());

            var packages = GenerateRenderPackages();

            // Add manipulator geometry to view asynchronously
            // since it has to be queued up in UI dispatcher after drawing node geometry
            BackgroundPreviewViewModel.AddGeometryForRenderPackages(packages, true);
        }
Example #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="node">Node for which manipulator is created.</param>
        /// <param name="manipulatorContext">Context for manipulator</param>
        protected NodeManipulator(NodeModel node, DynamoManipulationExtension manipulatorContext)
        {
            this.manipulatorContext = manipulatorContext;
            Node = node;

            AttachBaseHandlers();

            CameraPosition = BackgroundPreviewViewModel.GetCameraPosition();

            DrawManipulator();
        }
Example #8
0
        /// <summary>
        /// Removes Gizmos from background preview.
        /// </summary>
        private void DeleteGizmos()
        {
            var gizmos = GetGizmos(false);

            foreach (var item in gizmos)
            {
                // Unsubscribe gizmos from camera-change events before updating the scene
                item.Dispose();
                BackgroundPreviewViewModel.DeleteGeometryForIdentifier(item.Name);
            }
        }
Example #9
0
        /// <summary>
        /// Implements the MouseDown event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseButtonEventArgs"></param>
        protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            if (!IsValidNode)
            {
                return;
            }

            active = UpdatePosition();
            if (Origin != null)
            {
                originBeforeMove = Point.ByCoordinates(Origin.X, Origin.Y, Origin.Z);
                originAfterMove  = Point.ByCoordinates(Origin.X, Origin.Y, Origin.Z);
            }

            GizmoInAction = null; //Reset Drag.

            var gizmos = GetGizmos(false);

            if (!IsEnabled() || null == gizmos || !gizmos.Any())
            {
                return;
            }

            var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs);

            if (ray == null)
            {
                return;
            }

            foreach (var item in gizmos)
            {
                using (var originPt = ray.GetOriginPoint())
                    using (var dirVec = ray.GetDirectionVector())
                    {
                        object hitObject;
                        if (item.HitTest(originPt, dirVec, out hitObject))
                        {
                            GizmoInAction = item;

                            var nodes = OnGizmoClick(item, hitObject).ToList();
                            if (nodes.Any())
                            {
                                WorkspaceModel.RecordModelsForModification(nodes);
                            }
                            return;
                        }
                    }
            }
        }
        private void Watch3DViewModelNavigateBackgroundPropertyChanged(bool canNavigateBackground)
        {
            if (canNavigateBackground)
            {
                // if switching to geometry view
                // Get the Model3D objects corresponding to the nodes and highlight them
                var nodes = GetZeroTouchNodesForMatchingNames();
                manipulatorNodes = nodes.Where(InspectInputsForNode);

                BackgroundPreviewViewModel.HighlightNodeGraphics(manipulatorNodes);
            }
            else
            {
                // if switching to node view
                BackgroundPreviewViewModel.UnHighlightNodeGraphics(manipulatorNodes);
            }
        }
Example #11
0
        /// <summary>
        /// Implements the MouseMove event handler for the manipulator
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        protected virtual void MouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (!IsEnabled())
            {
                return;
            }

            var clickRay = BackgroundPreviewViewModel.GetClickRay(mouseEventArgs);

            if (clickRay == null)
            {
                return;
            }

            if (GizmoInAction == null)
            {
                HighlightGizmoOnRollOver(clickRay);
                return;
            }

            var offset = GizmoInAction.GetOffset(clickRay.GetOriginPoint(), clickRay.GetDirectionVector());

            if (offset.Length < 0.01)
            {
                return;
            }

            if (originAfterMove != null)
            {
                var offsetPos = originAfterMove.Add(offset);
                originAfterMove.Dispose();
                originAfterMove = offsetPos;
            }

            // Update input nodes attached to manipulator node
            // Doing this triggers a graph update on scheduler thread
            OnGizmoMoved(GizmoInAction, offset);

            // redraw manipulator at new position synchronously
            var packages = BuildRenderPackage();

            BackgroundPreviewViewModel.AddGeometryForRenderPackages(packages);
        }
Example #12
0
        /// <summary>
        /// Generates render packages for all the drawables of this manipulator.
        /// Before actually generating the render packages it ensures that this
        /// object is properly updated. This method is called when the output
        /// of the node is rendered.
        /// </summary>
        /// <returns>List of render packages</returns>
        private IEnumerable <IRenderPackage> GenerateRenderPackages()
        {
            var packages = new List <IRenderPackage>();

            AssignInputNodes();

            if (!Node.IsSelected)
            {
                return(packages);
            }

            UpdatePosition();

            if (!IsEnabled())
            {
                return(packages);
            }

            IEnumerable <IRenderPackage> result = null;

            BackgroundPreviewViewModel.Invoke(() => result = BuildRenderPackage());
            return(result);
        }
Example #13
0
        /// <summary>
        /// Generates render packages for all the drawables of this manipulator.
        /// Before actually generating the render packages it ensures that this
        /// object is properly updated. This method is called when the output
        /// of the node is rendered.
        /// This function can only be called on the UI thread if there's a node selection OR
        /// called on the scheduler thread if there's a node update
        /// </summary>
        /// <returns>List of render packages</returns>
        private RenderPackageCache GenerateRenderPackages()
        {
            var packages = new RenderPackageCache();

            // This can happen only when the node is updating along with the manipulator
            // and meanwhile it is deselected in the UI before the manipulator is killed
            if (!Node.IsSelected)
            {
                return(packages);
            }

            // This check is required as for some reason LibG fails to load, geometry nodes are null
            // and we must return immediately before proceeding with further calls to ProtoGeometry
            if (IsNodeNull(Node.CachedValue))
            {
                return(packages);
            }

            AssignInputNodes();

            active = UpdatePosition();

            if (!IsEnabled())
            {
                return(packages);
            }

            // Blocking call to build render packages only in UI thread
            // to avoid race condition with gizmo members b/w scheduler and UI threads.
            // Race condition can occur if say one gizmo is moving due to another gizmo
            // and it is highlighted when it comes near the mouse pointer.
            RenderPackageCache result = null;

            BackgroundPreviewViewModel.Invoke(() => result = BuildRenderPackage());
            return(result);
        }
Example #14
0
 private void Redraw()
 {
     BackgroundPreviewViewModel.AddGeometryForRenderPackages(GetDrawables());
 }
Example #15
0
        public override void DeleteTransientGraphics()
        {
            var identifier = string.Format("{0}_{1}", RenderDescriptions.AxisLine, Name);

            BackgroundPreviewViewModel.DeleteGeometryForIdentifier(identifier);
        }
 private void Watch3DViewModelOnViewMouseDown(object o, MouseButtonEventArgs mouseButtonEventArgs)
 {
     BackgroundPreviewViewModel.HighlightNodeGraphics(manipulatorNodes);
 }
Example #17
0
        /// <summary>
        /// Method to draw manipulator
        /// </summary>
        private void DrawManipulator()
        {
            var packages = GenerateRenderPackages();

            BackgroundPreviewViewModel.AddGeometryForRenderPackages(packages);
        }
Example #18
0
        public void HighlightGizmo()
        {
            var drawables = GetDrawablesForTransientGraphics();

            BackgroundPreviewViewModel.AddGeometryForRenderPackages(drawables);
        }
Example #19
0
 /// <summary>
 /// Implements the MouseUp event handler for the manipulator
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void MouseUp(object sender, MouseButtonEventArgs e)
 {
     GizmoInAction = null;
     //Delete all transient axis line geometry
     BackgroundPreviewViewModel.DeleteGeometryForIdentifier(RenderDescriptions.AxisLine);
 }