Beispiel #1
0
 /// <summary>
 /// Zoom in on the object with the given GUID.
 /// </summary>
 public void ZoomToObject(string guid)
 {
     GeneralUtils.ClearSelection();
     viewModel.CurrentSpaceViewModel.ResetFitViewToggleCommand.Execute(null);
     if (viewModel.Model.CurrentWorkspace.Nodes.Count(x => x.GUID.ToString() == guid) > 0)
     {
         var zoomObject = viewModel.Model.CurrentWorkspace.Nodes.First(x => x.GUID.ToString() == guid);
         viewModel.AddToSelectionCommand.Execute(zoomObject);
     }
     else if (viewModel.Model.CurrentWorkspace.Notes.Count(x => x.GUID.ToString() == guid) > 0)
     {
         var zoomObject = viewModel.Model.CurrentWorkspace.Notes.First(x => x.GUID.ToString() == guid);
         viewModel.AddToSelectionCommand.Execute(zoomObject);
     }
     else if (viewModel.Model.CurrentWorkspace.Annotations.Count(x => x.GUID.ToString() == guid) > 0)
     {
         var zoomObject = viewModel.Model.CurrentWorkspace.Annotations.First(x => x.GUID.ToString() == guid);
         viewModel.AddToSelectionCommand.Execute(zoomObject);
     }
     viewModel.FitViewCommand.Execute(null);
     GeneralUtils.ClearSelection();
 }
        public void UnfancifyGraph()
        {
            // Create a list for storing guids of groups, nodes and text notes that we want to keep
            var stuffToKeep = new List <string>();

            GeneralUtils.ClearSelection();
            // Identify all groups to keep/ungroup
            if (ungroupAll)
            {
                var groupIgnoreList = ignoreGroupPrefixes.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var anno in viewModel.CurrentSpaceViewModel.Annotations)
                {
                    foreach (var ignoreTerm in groupIgnoreList)
                    {
                        // Identify keepers
                        if (anno.AnnotationText.StartsWith(ignoreTerm) && !stuffToKeep.Contains(anno.AnnotationModel.GUID.ToString()))
                        {
                            stuffToKeep.Add(anno.AnnotationModel.GUID.ToString());
                            // Identify all nodes and text notes within those groups
                            foreach (var element in anno.SelectedModels)
                            {
                                stuffToKeep.Add(element.GUID.ToString());
                            }
                        }
                    }
                    // Add all obsolete groups to selection
                    if (!stuffToKeep.Contains(anno.AnnotationModel.GUID.ToString()))
                    {
                        viewModel.AddToSelectionCommand.Execute(anno.AnnotationModel);
                    }
                }
                // Ungroup all obsolete groups
                viewModel.UngroupAnnotationCommand.Execute(null);
            }
            // Identify all text notes to keep/delete
            if (deleteTextNotes)
            {
                var textNoteIgnoreList = ignoreTextNotePrefixes.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var note in viewModel.Model.CurrentWorkspace.Notes)
                {
                    foreach (var ignoreTerm in textNoteIgnoreList)
                    {
                        // Identify keepers
                        if (note.Text.StartsWith(ignoreTerm) && !stuffToKeep.Contains(note.GUID.ToString()))
                        {
                            stuffToKeep.Add(note.GUID.ToString());
                        }
                    }
                    // Add all obsolete text notes to selection
                    if (!stuffToKeep.Contains(note.GUID.ToString()))
                    {
                        viewModel.AddToSelectionCommand.Execute(note);
                    }
                }
                // Delete all obsolete text notes
                viewModel.DeleteCommand.Execute(null);
            }
            // Process nodes
            foreach (var node in viewModel.Model.CurrentWorkspace.Nodes)
            {
                // Select all obsolete nodes and pre-process string nodes
                if (!stuffToKeep.Contains(node.GUID.ToString()))
                {
                    // Pre-Processing
                    // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9117 (Escape backslashes in string nodes)
                    // Temporary fix for https://github.com/DynamoDS/Dynamo/issues/9120 (Escape double quotes in string nodes)
                    if (node.GetType() == typeof(StringInput))
                    {
                        StringInput inputNode = (StringInput)node;
                        string      nodeVal   = inputNode.Value;
                        nodeVal = nodeVal.Replace("\\", "\\\\").Replace("\"", "\\\"");
                        var updateVal = new UpdateValueParams("Value", nodeVal);
                        node.UpdateValue(updateVal);
                    }
                    viewModel.AddToSelectionCommand.Execute(node);
                }
            }
            // Node to code
            viewModel.CurrentSpaceViewModel.NodeToCodeCommand.Execute(null);
            GeneralUtils.ClearSelection();
            // Process remaining nodes
            var nodesToDelete = new List <NodeModel>();

            if (disableGeometryPreview || disablePreviewBubbles || deleteWatchNodes)
            {
                foreach (var node in viewModel.CurrentSpaceViewModel.Nodes)
                {
                    // Turn off geometry preview
                    if (disableGeometryPreview)
                    {
                        if (node.IsVisible)
                        {
                            node.ToggleIsVisibleCommand.Execute(null);
                        }
                    }
                    // Turn off preview bubbles (only works after file has been saved and re-opened)
                    if (disablePreviewBubbles)
                    {
                        if (node.PreviewPinned)
                        {
                            node.PreviewPinned = false;
                        }
                    }
                    // Identify Watch nodes
                    if (deleteWatchNodes)
                    {
                        string nodeType = node.NodeModel.GetType().ToString();
                        if (nodeType == "CoreNodeModels.Watch" || nodeType == "Watch3DNodeModels.Watch3D" || nodeType == "CoreNodeModels.WatchImageCore")
                        {
                            if (node.NodeModel.OutputNodes.Count == 0)
                            {
                                viewModel.AddToSelectionCommand.Execute(node.NodeModel);
                            }
                        }
                    }
                }
            }
            // Delete Watch nodes
            if (deleteWatchNodes)
            {
                viewModel.DeleteCommand.Execute(null);
            }
            // Auto layout
            dynWindow.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
            {
                viewModel.CurrentSpaceViewModel.GraphAutoLayoutCommand.Execute(null);
            }));
        }
        public void Loaded(ViewLoadedParams p)
        {
            var monitoMenuItem = new MenuItem {
                Header = "DynaMonito"
            };
            var      VM = p.DynamoWindow.DataContext as DynamoViewModel;
            MenuItem subMenuItem;

            #region FIND_UNGROUPED
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnableFindUngrouped"))
            {
                subMenuItem = new MenuItem {
                    Header = "Find and Fix Ungrouped"
                };
                subMenuItem.ToolTip = new ToolTip {
                    Content = "Identify nodes and notes that don't belong to a group.."
                };
                subMenuItem.Click += (sender, args) =>
                {
                    var viewModel = new FindUngroupedViewModel(p, VM);
                    var window    = new FindUngroupedWindow
                    {
                        findUngroupedPanel = { DataContext = viewModel },
                        Owner = p.DynamoWindow
                    };
                    window.Left = window.Owner.Left + 400;
                    window.Top  = window.Owner.Top + 200;
                    window.Show();
                };
                monitoMenuItem.Items.Add(subMenuItem);
            }
            #endregion FIND_UNGROUPED

            #region ISOLATE_IN_GEOMETRY_PREVIEW
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnableIsolateInGeometryPreview"))
            {
                subMenuItem = new MenuItem {
                    Header = "Isolate in Geometry Preview"
                };
                subMenuItem.ToolTip = new ToolTip {
                    Content = "Quickly isolate the current selection in geometry preview..."
                };
                subMenuItem.Click += (sender, args) =>
                {
                    var viewModel = new IsolateInPreviewViewModel(p, VM, p.DynamoWindow);
                    var window    = new IsolateInPreviewWindow
                    {
                        isolatePreviewPanel = { DataContext = viewModel },
                        Owner = p.DynamoWindow
                    };
                    window.Left = window.Owner.Left + 400;
                    window.Top  = window.Owner.Top + 200;
                    window.Show();
                };
                monitoMenuItem.Items.Add(subMenuItem);
            }
            #endregion ISOLATE_IN_GEOMETRY_PREVIEW

            #region PLAYER_INPUTS
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnablePlayerInputs"))
            {
                subMenuItem = new MenuItem {
                    Header = "Manage Dynamo Player Inputs"
                };
                subMenuItem.ToolTip = new ToolTip {
                    Content = "Manage which input nodes should be displayed by Dynamo Player..."
                };
                subMenuItem.Click += (sender, args) =>
                {
                    var viewModel = new PlayerInputsViewModel(p, VM);
                    var window    = new PlayerInputsWindow
                    {
                        playerInputsPanel = { DataContext = viewModel },
                        Owner             = p.DynamoWindow
                    };
                    window.Left = window.Owner.Left + 400;
                    window.Top  = window.Owner.Top + 200;
                    window.Show();
                };
                monitoMenuItem.Items.Add(subMenuItem);
            }
            #endregion PLAYER INPUTS

            #region MY_GRAPHS
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnableMyGraphs"))
            {
                // Read list of graph directories from config
                var topDirs = monitoSettings["MyGraphsDirectoryPaths"].Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (topDirs.Length > 0)
                {
                    subMenuItem = new MenuItem {
                        Header = "My Graphs"
                    };
                    subMenuItem.ToolTip = new ToolTip {
                        Content = "Quick access to all your graphs..."
                    };
                    if (topDirs.Length == 1)
                    {
                        subMenuItem = BuildMyGraphsMenu(topDirs[0], subMenuItem, VM);
                    }
                    else
                    {
                        foreach (string topDir in topDirs)
                        {
                            string   topDirName     = Path.GetFileName(topDir);
                            MenuItem topDirMenuItem = new MenuItem {
                                Header = topDirName
                            };
                            topDirMenuItem.ToolTip = new ToolTip {
                                Content = topDir
                            };
                            topDirMenuItem = BuildMyGraphsMenu(topDir, topDirMenuItem, VM);
                            subMenuItem.Items.Add(topDirMenuItem);
                        }
                    }
                    if (subMenuItem != null)
                    {
                        monitoMenuItem.Items.Add(subMenuItem);
                    }
                }
            }
            #endregion MY_GRAPHS

            #region MY_TEMPLATES
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnableMyTemplates"))
            {
                var tplDir = monitoSettings["MyTemplatesDirectoryPath"].Value;
                if (Directory.Exists(tplDir))
                {
                    // Create a menu item for each template
                    List <MenuItem> tempMenuItems = new List <MenuItem>();
                    var             templates     = Directory.GetFiles(tplDir, "*.dyn");
                    foreach (string t in templates)
                    {
                        string   tplName = Path.GetFileNameWithoutExtension(t);
                        MenuItem tplMenu = new MenuItem {
                            Header = tplName
                        };
                        tplMenu.ToolTip = new ToolTip {
                            Content = t
                        };
                        tplMenu.Click += (sender, args) =>
                        {
                            if (File.Exists(t))
                            {
                                // Close current home workspace, open template and set to manual mode
                                VM.CloseHomeWorkspaceCommand.Execute(null);
                                VM.OpenCommand.Execute(t);
                                VM.CurrentSpaceViewModel.RunSettingsViewModel.Model.RunType = RunType.Manual;
                                // Select all nodes and notes as well as annotations and copy everything
                                VM.SelectAllCommand.Execute(null);
                                foreach (var anno in VM.HomeSpaceViewModel.Model.Annotations)
                                {
                                    VM.AddToSelectionCommand.Execute(anno);
                                }
                                VM.CopyCommand.Execute(null);
                                // Create new home workspace, set to manual mode and paste template content
                                VM.NewHomeWorkspaceCommand.Execute(null);
                                VM.CurrentSpaceViewModel.RunSettingsViewModel.Model.RunType = RunType.Manual;
                                VM.Model.Paste();
                                GeneralUtils.ClearSelection();
                                VM.CurrentSpaceViewModel.ResetFitViewToggleCommand.Execute(null);
                                VM.FitViewCommand.Execute(null);
                            }
                            else
                            {
                                MessageBox.Show("Template " + tplName + " has been moved, renamed or deleted...");
                            }
                        };
                        tempMenuItems.Add(tplMenu);
                    }
                    // Only show the templates menu item if templates exist
                    if (tempMenuItems.Count > 0)
                    {
                        subMenuItem = new MenuItem {
                            Header = "New Workspace from Template"
                        };
                        subMenuItem.ToolTip = new ToolTip {
                            Content = "Quick access to all your templates..."
                        };
                        foreach (MenuItem tempMenuItem in tempMenuItems)
                        {
                            subMenuItem.Items.Add(tempMenuItem);
                        }
                        monitoMenuItem.Items.Add(subMenuItem);
                    }
                }
            }
            #endregion MY_TEMPLATES

            #region PACKAGE_DIRECTORIES
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnablePackageDirectories"))
            {
                subMenuItem = new MenuItem {
                    Header = "Package Directories"
                };
                subMenuItem.ToolTip = new ToolTip {
                    Content = "Quick access to all your package directories..."
                };
                foreach (string packageDir in startupParams.Preferences.CustomPackageFolders)
                {
                    if (Directory.Exists(packageDir))
                    {
                        MenuItem monitoPackageDirMenuItem = new MenuItem {
                            Header = packageDir
                        };
                        monitoPackageDirMenuItem.ToolTip = new ToolTip {
                            Content = "Show contents of " + packageDir + " ..."
                        };
                        monitoPackageDirMenuItem.Click += (sender, args) =>
                        {
                            if (Directory.Exists(packageDir))
                            {
                                Process.Start(@"" + packageDir);
                            }
                            else
                            {
                                MessageBox.Show("Directory " + packageDir + " has been moved, renamed or deleted...");
                            }
                        };
                        subMenuItem.Items.Add(monitoPackageDirMenuItem);
                    }
                }
                monitoMenuItem.Items.Add(subMenuItem);
            }
            #endregion PACKAGE_DIRECTORIES

            #region SEARCH_IN_WORKSPACE
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnableSearchInWorkspace"))
            {
                subMenuItem = new MenuItem {
                    Header = "Search in Workspace"
                };
                subMenuItem.ToolTip = new ToolTip {
                    Content = "Search for nodes, notes and groups in the current workspace..."
                };
                subMenuItem.Click += (sender, args) =>
                {
                    var viewModel = new SearchInWorkspaceViewModel(p, VM, monitoSettings);
                    var window    = new SearchInWorkspaceWindow
                    {
                        searchPanel = { DataContext = viewModel },
                        Owner       = p.DynamoWindow
                    };
                    window.Left = window.Owner.Left + 400;
                    window.Top  = window.Owner.Top + 200;
                    window.Show();
                };
                monitoMenuItem.Items.Add(subMenuItem);
            }
            #endregion SEARCH_IN_WORKSPACE

            #region UNFANCIFY
            if (monitoSettingsLoaded && monitoSettings.GetLoadedSettingAsBoolean("EnableUnfancify"))
            {
                subMenuItem = new MenuItem {
                    Header = "Unfancify"
                };
                subMenuItem.ToolTip = new ToolTip {
                    Content = "Simplify your graph..."
                };
                subMenuItem.Click += (sender, args) =>
                {
                    var viewModel = new UnfancifyViewModel(p, VM, monitoSettings, p.DynamoWindow);
                    var window    = new UnfancifyWindow
                    {
                        unfancifyPanel = { DataContext = viewModel },
                        Owner          = p.DynamoWindow
                    };
                    window.Left = window.Owner.Left + 400;
                    window.Top  = window.Owner.Top + 200;
                    window.Show();
                };
                monitoMenuItem.Items.Add(subMenuItem);
            }
            #endregion UNFANCIFY

            #region ABOUT
            subMenuItem = new MenuItem {
                Header = "About DynaMonito"
            };
            subMenuItem.Click += (sender, args) =>
            {
                var window = new AboutWindow
                {
                    aboutPanel = { DataContext = this },
                    Owner      = p.DynamoWindow
                };
                window.Left = window.Owner.Left + 400;
                window.Top  = window.Owner.Top + 200;
                window.Show();
            };
            if (monitoMenuItem.Items.Count > 0)
            {
                monitoMenuItem.Items.Add(new Separator());
            }
            monitoMenuItem.Items.Add(subMenuItem);
            #endregion ABOUT

            p.dynamoMenu.Items.Add(monitoMenuItem);
        }