Ejemplo n.º 1
0
        private void HandleItemChanged (TreeViewItem tvi, WatchViewModel node)
        {
            if (tvi == null || node == null)
                return;

            // checks to see if the node to be selected is the same as the currently selected node
            // if so, then de-select the currently selected node.

            if (node == prevWatchViewModel)
            {
                this.prevWatchViewModel = null;
                if (tvi.IsSelected)
                {
                    tvi.IsSelected = false;
                    tvi.Focus();
                }
            }
            else
            {
                this.prevWatchViewModel = node;
            }

            if (_vm.FindNodeForPathCommand.CanExecute(node.Path))
            {
                _vm.FindNodeForPathCommand.Execute(node.Path);
            }
        }
Ejemplo n.º 2
0
        private Tuple <int, int> GetMaximumDepthAndItemNumber(WatchViewModel wvm)
        {
            if (wvm.Children.Count == 0)
            {
                if (wvm.NodeLabel == WatchViewModel.EMPTY_LIST)
                {
                    return(new Tuple <int, int>(0, 0));
                }
                else
                {
                    return(new Tuple <int, int>(1, 1));
                }
            }

            // If its a top level WatchViewModel, call function on child
            if (wvm.Path == null)
            {
                return(GetMaximumDepthAndItemNumber(wvm.Children[0]));
            }

            // if it's a list, recurse
            if (wvm.NodeLabel == LIST)
            {
                var depthAndNumbers = wvm.Children.Select(GetMaximumDepthAndItemNumber);
                var maxDepth        = depthAndNumbers.Select(t => t.Item1).DefaultIfEmpty(1).Max() + 1;
                var itemNumber      = depthAndNumbers.Select(t => t.Item2).Sum();
                return(new Tuple <int, int>(maxDepth, itemNumber));
            }

            return(new Tuple <int, int>(1, 1));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Validates the watch content with the source nodes output.
 /// </summary>
 /// <param name="watch">WatchViewModel of the watch node</param>
 /// <param name="sourceNode">NodeModel for source to watch node</param>
 public void AssertWatchContent(WatchViewModel watch, NodeModel sourceNode)
 {
     string var = sourceNode.GetAstIdentifierForOutputIndex(0).Name;
     RuntimeMirror mirror = null;
     Assert.DoesNotThrow(() => mirror = ViewModel.Model.EngineController.GetMirror(var));
     Assert.IsNotNull(mirror);
     AssertWatchContent(watch, mirror.GetData());
 }
Ejemplo n.º 4
0
        internal WatchViewModel ProcessThing(Element element, string tag, bool showRawData = true)
        {
            var id = element.Id;

            var node = new WatchViewModel(element.ToString(dynSettings.Controller.PreferenceSettings.NumberFormat, CultureInfo.InvariantCulture), tag);
            node.Clicked += () => DocumentManager.Instance.CurrentUIDocument.ShowElements(element.InternalElement);
            node.Link = id.ToString(CultureInfo.InvariantCulture);

            return node;
        }
Ejemplo n.º 5
0
        internal WatchViewModel ProcessThing(Element element, string tag, bool showRawData = true)
        {
            var id = element.Id;

            var node = new WatchViewModel(element.Name, tag);
            node.Clicked += () => DocumentManager.Instance.CurrentUIDocument.ShowElements(element.InternalElement);
            node.Link = id.ToString(CultureInfo.InvariantCulture);

            return node;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Validates the watch content with given mirror data.
 /// </summary>
 /// <param name="watch">WatchViewModel of the watch node</param>
 /// <param name="mirrorData">MirrorData to be shown in watch</param>
 private void AssertWatchContent(WatchViewModel watch, MirrorData mirrorData)
 {
     Assert.IsNotNull(mirrorData);
     if (mirrorData.IsCollection)
         AssertWatchTreeBranchContent(watch.Children, mirrorData.GetElements());
     else if (mirrorData.IsNull)
         Assert.AreEqual("null", watch.NodeLabel);
     else
     {
         string nodeLabel = string.Format("{0}", mirrorData.Data);
         Assert.AreEqual(nodeLabel, watch.NodeLabel);
     }
 }
Ejemplo n.º 7
0
        internal WatchViewModel ProcessThing(Element element, string tag, bool showRawData)
        {
            var id = element.Id;

            var node = new WatchViewModel(visualizationManager, 
                element.ToString(preferences.NumberFormat, CultureInfo.InvariantCulture), tag);

            node.Clicked += () =>
            {
                if (element.InternalElement.IsValidObject)
                    DocumentManager.Instance.CurrentUIDocument.ShowElements(element.InternalElement);
            };
            node.Link = id.ToString(CultureInfo.InvariantCulture);

            return node;
        }
Ejemplo n.º 8
0
        private WatchViewModel ProcessThing(object value, ProtoCore.RuntimeCore runtimeCore, string tag, bool showRawData, WatchHandlerCallback callback)
        {
            WatchViewModel node;

            if (value is IEnumerable)
            {
                var list = (value as IEnumerable).Cast<dynamic>().ToList();

                node = new WatchViewModel(list.Count == 0 ? "Empty List" : "List", tag, RequestSelectGeometry, true);
                foreach (var e in list.Select((element, idx) => new { element, idx }))
                {
                    node.Children.Add(callback(e.element, runtimeCore, tag + ":" + e.idx, showRawData));
                }
            }
            else if (runtimeCore != null && value is StackValue)
            {
                StackValue stackValue = (StackValue)value;
                string stringValue = string.Empty;

                if (stackValue.IsFunctionPointer)
                {
                    stringValue = StringUtils.GetStringValue(stackValue, runtimeCore);
                }
                else
                {
                    int typeId = runtimeCore.DSExecutable.TypeSystem.GetType(stackValue);
                    stringValue = runtimeCore.DSExecutable.classTable.ClassNodes[typeId].Name;
                }
                node = new WatchViewModel(stringValue, tag, RequestSelectGeometry);
            }
            else if (value is Enum)
            {
                return new WatchViewModel(((Enum)value).GetDescription(), tag, RequestSelectGeometry);
            }
            else
            {
                node = new WatchViewModel(ToString(value), tag, RequestSelectGeometry);
            }

            return node;
        }
Ejemplo n.º 9
0
        private WatchViewModel ProcessThing(object value, string tag, bool showRawData, WatchHandlerCallback callback)
        {
            WatchViewModel node;

            if (value is IEnumerable)
            {
                var list = (value as IEnumerable).Cast<dynamic>().ToList();

                node = new WatchViewModel(visualizationManager, list.Count == 0 ? "Empty List" : "List", tag, true);
                foreach (var e in list.Select((element, idx) => new { element, idx }))
                {
                    node.Children.Add(callback(e.element, tag + ":" + e.idx, showRawData));
                }
            }
            else
            {
                node = new WatchViewModel(visualizationManager, ToString(value), tag);
            }

            return node;
        }
Ejemplo n.º 10
0
        internal WatchViewModel ProcessThing(object value, string tag, bool showRawData = true)
        {
            WatchViewModel node;

            if (value is IEnumerable)
            {
                node = new WatchViewModel("List", tag);

                var enumerable = value as IEnumerable;
                foreach (var obj in enumerable)
                {
                    node.Children.Add(ProcessThing(obj, tag));
                }
            }
            else
            {
                node = new WatchViewModel(ToString(value), tag);
            }

            return node;
        }
Ejemplo n.º 11
0
        internal WatchViewModel ProcessThing(Element element, string tag, bool showRawData = true)
        {
            var id = element.Id;

            // Do not process element for watch which have been removed
            // from the Revit database.
            if (!element.InternalElement.IsValidObject)
            {
                return null;
            }

            var elementString =
                element.ToString(
                    dynSettings.Controller.PreferenceSettings.NumberFormat,
                    CultureInfo.InvariantCulture);

            var node = new WatchViewModel(elementString, tag);
            node.Clicked += () => DocumentManager.Instance.CurrentUIDocument.ShowElements(element.InternalElement);
            node.Link = id.ToString(CultureInfo.InvariantCulture);

            return node;
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Obtain the expanded preview values for this control.  Must not be called from 
        ///     Scheduler thread or this could cause a live-lock.
        /// </summary>
        /// 
        private void RefreshExpandedDisplay(Action refreshDisplay)
        {
            // The preview control will not have its content refreshed unless 
            // the content is null. In order to perform real refresh, new data 
            // source needs to be rebound to the preview control by calling 
            // BindToDataSource method.
            // 
            if (this.cachedLargeContent != null)
            {
                // If there are cached contents, simply update the UI and return
                if (refreshDisplay != null)
                {
                    refreshDisplay();
                }
                return;
            }

            WatchViewModel newViewModel = null;

            RunOnSchedulerSync(
                () =>
                {
                    newViewModel = nodeViewModel.DynamoViewModel.WatchHandler.GenerateWatchViewModelForData(
                        mirrorData, null, string.Empty, false);
                },
                (m) =>
                {
                    if (largeContentGrid.Children.Count == 0)
                    {
                        var tree = new WatchTree
                        {
                            DataContext = new WatchViewModel()
                        };
                        tree.treeView1.ItemContainerGenerator.StatusChanged += WatchContainer_StatusChanged;

                        largeContentGrid.Children.Add(tree);
                    }

                    var watchTree = largeContentGrid.Children[0] as WatchTree;
                    var rootDataContext = watchTree.DataContext as WatchViewModel;


                    cachedLargeContent = newViewModel;

                    rootDataContext.IsOneRowContent = cachedLargeContent.Children.Count == 0;
                    rootDataContext.Children.Clear();
                    rootDataContext.Children.Add(cachedLargeContent);

                    watchTree.treeView1.SetBinding(ItemsControl.ItemsSourceProperty,
                        new Binding("Children")
                        {
                            Mode = BindingMode.TwoWay,
                            Source = rootDataContext
                        });
                    if (refreshDisplay != null)
                    {
                        refreshDisplay();
                    }
                }
            );
        }
Ejemplo n.º 13
0
        private Tuple<int, int> GetMaximumDepthAndItemNumber(WatchViewModel wvm)
        {
            if (wvm.Children.Count == 0)
            {
                if (wvm.NodeLabel == WatchViewModel.EMPTY_LIST)
                    return new Tuple<int, int>(0, 0);
                else
                    return new Tuple<int, int>(1, 1);
            }

            // If its a top level WatchViewModel, call function on child
            if (wvm.Path == null) 
            {
                return GetMaximumDepthAndItemNumber(wvm.Children[0]);
            }
            else
            {
                var depthAndNumbers = wvm.Children.Select(GetMaximumDepthAndItemNumber);
                var maxDepth = depthAndNumbers.Select(t => t.Item1).DefaultIfEmpty(1).Max() + 1;
                var itemNumber = depthAndNumbers.Select(t => t.Item2).Sum();
                return new Tuple<int, int>(maxDepth, itemNumber);
            }
        }
Ejemplo n.º 14
0
        private void RefreshExpandedDisplay()
        {
            // The preview control will not have its content refreshed unless 
            // the content is null. In order to perform real refresh, new data 
            // source needs to be rebound to the preview control by calling 
            // BindToDataSource method.
            // 
            if (this.cachedLargeContent != null)
                return;

            if (largeContentGrid.Children.Count <= 0)
            {
                var newWatchTree = new WatchTree();
                newWatchTree.DataContext = new WatchViewModel();
                largeContentGrid.Children.Add(newWatchTree);
            }

            var watchTree = largeContentGrid.Children[0] as WatchTree;
            var rootDataContext = watchTree.DataContext as WatchViewModel;

            // Associate the data context to the view before binding.
            cachedLargeContent = Watch.Process(mirrorData, string.Empty, false);
            rootDataContext.Children.Add(cachedLargeContent);

            // Establish data binding between data context and the view.
            watchTree.treeView1.SetBinding(ItemsControl.ItemsSourceProperty,
                new Binding("Children")
                {
                    Mode = BindingMode.TwoWay,
                    Source = rootDataContext
                });
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Bind a mirror data to the preview control for display, this call 
        /// unbinds the internal data structure from the view that it was 
        /// originally bound to and resets the data structure. If this call is 
        /// made while the preview control is in condensed or expanded state,
        /// the display will immediately be refreshed. Since this method deals 
        /// with UI elements internally, it must be called from the UI thread.
        /// </summary>
        /// <param name="mirrorData">The mirror data to bind the preview control
        /// to. This value can be null to reset the preview control to its 
        /// initial state.</param>
        /// 
        internal void BindToDataSource(MirrorData mirrorData)
        {
            // First detach the bound data from its view.
            ResetContentViews();

            this.mirrorData = mirrorData;
            this.cachedLargeContent = null; // Reset expanded content.
            this.cachedSmallContent = null; // Reset condensed content.

            // If at the time of data binding the preview control is within the 
            // following states, then its contents need to be updated immediately.
            if (this.IsCondensed)
            {
                RefreshCondensedDisplay();
                BeginViewSizeTransition(ComputeSmallContentSize());
            }
            else if (this.IsExpanded)
            {
                RefreshExpandedDisplay();
                BeginViewSizeTransition(ComputeLargeContentSize());
            }
        }
Ejemplo n.º 16
0
        private WatchViewModel ProcessThing(MirrorData data, ProtoCore.RuntimeCore runtimeCore, string tag, bool showRawData, WatchHandlerCallback callback)
        {
            if (data.IsCollection)
            {
                var list = data.GetElements();

                var node = new WatchViewModel(list.Count == 0 ? "Empty List" : "List", tag, RequestSelectGeometry, true);
                foreach (var e in list.Select((element, idx) => new { element, idx }))
                {
                    node.Children.Add(ProcessThing(e.element, runtimeCore, tag + ":" + e.idx, showRawData, callback));
                }

                return node;
            }
            if (data.Data is Enum)
            {
                return new WatchViewModel(((Enum)data.Data).GetDescription(), tag, RequestSelectGeometry);
            }

            if (data.Data == null)
            {
                // MAGN-3494: If "data.Data" is null, then return a "null" string 
                // representation instead of casting it as dynamic (that leads to 
                // a crash).
                if (data.IsNull)
                    return new WatchViewModel(NULL_STRING, tag, RequestSelectGeometry);
                
                //If the input data is an instance of a class, create a watch node
                //with the class name and let WatchHandler process the underlying CLR data
                var classMirror = data.Class;
                if (null != classMirror)
                {
                    //just show the class name.
                    return ProcessThing(classMirror.ClassName, runtimeCore, tag, showRawData, callback);
                }
            }

            //Finally for all else get the string representation of data as watch content.
            return callback(data.Data, runtimeCore, tag, showRawData);
        }
Ejemplo n.º 17
0
 internal WatchViewModel ProcessThing(object value, string tag, bool showRawData = true)
 {
     var node = new WatchViewModel(ToString(value), tag);
     return node;
 }
Ejemplo n.º 18
0
        /// <summary>
        ///     Obtain the expanded preview values for this control.  Must not be called from 
        ///     Scheduler thread or this could cause a live-lock.
        /// </summary> 
        private void RefreshExpandedDisplay(Action refreshDisplay)
        {
            // The preview control will not have its content refreshed unless 
            // the content is null. In order to perform real refresh, new data 
            // source needs to be rebound to the preview control by calling 
            // BindToDataSource method.
            // 
            if (this.cachedLargeContent != null)
            {
                // If there are cached contents, simply update the UI and return
                if (refreshDisplay != null)
                {
                    refreshDisplay();
                }
                return;
            }

            WatchViewModel newViewModel = null;

            RunOnSchedulerSync(
                () =>
                {
                    newViewModel = nodeViewModel.DynamoViewModel.WatchHandler.GenerateWatchViewModelForData(
                        nodeViewModel.NodeModel.CachedValue, null, nodeViewModel.NodeModel.AstIdentifierForPreview.Name, false);

                },
                (m) =>
                {
                    //If newViewModel is not set then no point continuing.
                    if (newViewModel == null) return;

                    if (largeContentGrid.Children.Count == 0)
                    {
                        var tree = new WatchTree
                        {
                            DataContext = new WatchViewModel(nodeViewModel.DynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath)
                        };
                        tree.treeView1.ItemContainerGenerator.StatusChanged += WatchContainer_StatusChanged;
                        largeContentGrid.Children.Add(tree);
                    }

                    var watchTree = largeContentGrid.Children[0] as WatchTree;
                    if (watchTree != null)
                    {
                        var rootDataContext = watchTree.DataContext as WatchViewModel;

                        cachedLargeContent = newViewModel;

                        if (rootDataContext != null)
                        {
                            rootDataContext.IsOneRowContent = cachedLargeContent.Children.Count == 0;
                            rootDataContext.Children.Clear();
                            rootDataContext.Children.Add(cachedLargeContent);
                            rootDataContext.CountNumberOfItems(); //count the total number of items in the list
                            if (!rootDataContext.IsOneRowContent)
                            {
                                rootDataContext.CountLevels();
                                watchTree.listLevelsView.ItemsSource = rootDataContext.Levels; // add listLevelList to the ItemsSource of listlevelsView in WatchTree
                                rootDataContext.Children[0].IsTopLevel = true;
                            }

                            watchTree.treeView1.SetBinding(ItemsControl.ItemsSourceProperty,
                                new Binding("Children")
                                {
                                    Mode = BindingMode.TwoWay,
                                    Source = rootDataContext
                                });

                        }
                    }
                    if (refreshDisplay != null)
                    {
                        refreshDisplay();
                    }
                }
            );
        }
Ejemplo n.º 19
0
 void WatchTree_Loaded(object sender, RoutedEventArgs e)
 {
     _vm = this.DataContext as WatchViewModel;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Bind a mirror data to the preview control for display, this call 
        /// unbinds the internal data structure from the view that it was 
        /// originally bound to and resets the data structure. If this call is 
        /// made while the preview control is in condensed or expanded state,
        /// the display will immediately be refreshed. Since this method deals 
        /// with UI elements internally, it must be called from the UI thread.
        /// </summary>
        internal void BindToDataSource()
        {
            // First detach the bound data from its view.
            ResetContentViews();
            
            // Reset expanded content.
            cachedLargeContent = null;
            // Reset condensed content.
            cachedSmallContent = null;

            // If at the time of data binding the preview control is within the 
            // following states, then its contents need to be updated immediately.
            if (IsCondensed)
            {
                RefreshCondensedDisplay(null);
            }
            else if (IsExpanded)
            {
                RefreshExpandedDisplay(RefreshExpandedDisplayAction);
            }

            IsDataBound = true;
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Obtain the expanded preview values for this control.  Must not be called from 
        ///     Scheduler thread or this could cause a live-lock.
        /// </summary>
        private void RefreshExpandedDisplay()
        {
            // The preview control will not have its content refreshed unless 
            // the content is null. In order to perform real refresh, new data 
            // source needs to be rebound to the preview control by calling 
            // BindToDataSource method.
            // 
            if (this.cachedLargeContent != null)
                return;

            WatchViewModel newViewModel = null;

            RunOnSchedulerSync(() =>
            {
                newViewModel = nodeViewModel.DynamoViewModel.WatchHandler.GenerateWatchViewModelForData(
                    mirrorData, null, string.Empty, false);
            });

            if (largeContentGrid.Children.Count == 0)
            {
                var tree = new WatchTree();
                tree.DataContext = new WatchViewModel(nodeViewModel.DynamoViewModel.VisualizationManager);
                largeContentGrid.Children.Add(tree);
            }

            var watchTree = largeContentGrid.Children[0] as WatchTree;
            var rootDataContext = watchTree.DataContext as WatchViewModel;

            cachedLargeContent = newViewModel;

            rootDataContext.Children.Clear();
            rootDataContext.Children.Add(cachedLargeContent);

            watchTree.treeView1.SetBinding(ItemsControl.ItemsSourceProperty,
                new Binding("Children")
                {
                    Mode = BindingMode.TwoWay,
                    Source = rootDataContext
                }); 
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Update the watch content from the given MirrorData and returns WatchNode.
        /// </summary>
        /// <param name="data">The Mirror data for which watch content is needed.</param>
        /// <param name="prefix">Prefix string used for formatting the content.</param>
        /// <param name="index">Index of input data if it is a part of a collection.</param>
        /// <param name="isListMember">Specifies if this data belongs to a collection.</param>
        /// <returns>WatchNode</returns>
        public static WatchViewModel Process(MirrorData data, string path, bool showRawData = true)
        {
            WatchViewModel node = null;

            if (data == null || data.IsNull)
            {
                node = new WatchViewModel(nullString, path);
            }
            else if (data.IsCollection)
            {
                var list = data.GetElements();

                node = new WatchViewModel(list.Count == 0 ? "Empty List" : "List", path, true);

                foreach (var e in list.Select((x, i) => new { Element = x, Index = i }))
                {
                    node.Children.Add(Process(e.Element, path + ":" + e.Index, showRawData));
                }
            }
            else
            {
                node = dynSettings.Controller.WatchHandler.Process(data as dynamic, path, showRawData);
            }

            return node ?? (new WatchViewModel("null", path));
        }
Ejemplo n.º 23
0
        internal WatchViewModel ProcessThing(MirrorData data, string tag, bool showRawData)
        {
            if (data.IsCollection)
            {
                var list = data.GetElements();

                var node = new WatchViewModel(visualizationManager, list.Count == 0 ? "Empty List" : "List", tag, true);
                foreach (var e in list.Select((element, idx) => new { element, idx }))
                {
                    node.Children.Add(ProcessThing(e.element, tag + ":" + e.idx, showRawData));
                }

                return node;
            }
            
            // MAGN-3494: If "data.Data" is null, then return a "null" string 
            // representation instead of casting it as dynamic (that leads to 
            // a crash).
            if (data.IsNull || data.Data == null)
                return new WatchViewModel(visualizationManager, NULL_STRING, tag);

            //If the input data is an instance of a class, create a watch node
            //with the class name and let WatchHandler process the underlying CLR data
            var classMirror = data.Class;
            if (null != classMirror)
            {
                if (data.Data == null && !data.IsNull) //Must be a DS Class instance.
                    return ProcessThing(classMirror.ClassName, tag, showRawData); //just show the class name.
                return Process(data.Data, tag, showRawData);
            }

            //Finally for all else get the string representation of data as watch content.
            return Process(data.Data, tag, showRawData);
        }