コード例 #1
0
 public void Run_ithGraphLayout(int i)
 {
     if (i >= GraphLayoutAlgorithms.Count)
     {
         MessageBox.Show("There are only " + GraphLayoutAlgorithms.Count +
                         "graph layout algorithms found; none at position " + i + ".");
     }
     else if (i >= 0)
     {
         var newLayAlgo = GraphLayoutController.Make(GraphLayoutAlgorithms[i]);
         newLayAlgo.Run(windowsMgr.activeGraphCanvas);
     }
 }
コード例 #2
0
        /// <summary>
        ///   Sets up graph layout menu. It would have been better to use the .NET 3.5 pipeline approach
        ///   to add-ins. Was I just lazy? I tried to figure it out for 2 whole weeks. It involves up to 7
        ///   projects and would require GraphGUI to be serialized. However, my view of graph layout is
        ///   to make quick changes to postion of nodes (perhaps specific ones may change shapes and back-
        ///   ground but these will be few). Seeing as how XamlWriter and XamlReader are slow and bottleneck
        ///   the entire application, I thought simply to take this approach. All graph layouts will need
        ///   to be in the GraphSynth.GraphLayout assembly and be derived from the GraphLayoutBaseClass. Each
        ///   one found will be given a slot on the layout menu.
        /// </summary>
        public void setUpGraphLayoutMenu()
        {
            SearchIO.output("Setting Up Graph Layout Algorithms");
            var keyNumOffset = (int)Key.D0;
            var k            = 0;

            GraphLayoutAlgorithms = new List <Type>();
            GraphLayoutCommands   = new List <RoutedUICommand>();
            GraphLayoutSubMenu.Items.Clear();
            var potentialAssemblies = getPotentialAssemblies(GSApp.settings.GraphLayoutDirAbs);

            if (potentialAssemblies.Count == 0)
            {
                return;
            }
            foreach (string filepath in potentialAssemblies)
            {
                Assembly GraphLayoutAssembly = null;
                try
                {
                    GraphLayoutAssembly = Assembly.LoadFrom(filepath);
                    var layouts = GraphLayoutAssembly.GetTypes();
                    foreach (Type lt in layouts)
                    {
                        if (!lt.IsAbstract && GraphLayoutController.IsInheritedType(lt) &&
                            !GraphLayoutAlgorithms.Any(w => w.FullName.Equals(lt.FullName)))
                        {
                            var newLayAlgo = GraphLayoutController.Make(lt);
                            if (newLayAlgo != null)
                            {
                                try
                                {
                                    KeyGesture kg = null;
                                    if (k < 10)
                                    {
                                        kg = new KeyGesture((Key)(k + keyNumOffset), ModifierKeys.Alt);
                                    }
                                    else if (k < 20)
                                    {
                                        kg = new KeyGesture((Key)(k + keyNumOffset - 10),
                                                            ModifierKeys.Alt | ModifierKeys.Shift);
                                    }
                                    else if (k < 30)
                                    {
                                        kg = new KeyGesture((Key)(k + keyNumOffset - 20),
                                                            ModifierKeys.Control | ModifierKeys.Alt |
                                                            ModifierKeys.Shift);
                                    }
                                    else
                                    {
                                        MessageBox.Show(
                                            "No shortcut has been assigned to " + newLayAlgo.text +
                                            ". That sure is an awful lot "
                                            +
                                            " of graph layout algorithms! Consider reducing the number included in the plugins directory",
                                            "No ShortCut Assigned", MessageBoxButton.OK);
                                    }
                                    GraphLayoutAlgorithms.Add(lt);
                                    var newGLCommand = new RoutedUICommand(newLayAlgo.text, lt.Name,
                                                                           GetType(),
                                                                           new InputGestureCollection {
                                        kg
                                    });
                                    GraphLayoutCommands.Add(newGLCommand);
                                    CommandBindings.Add(new CommandBinding(newGLCommand, GraphLayoutOnExecuted,
                                                                           GraphLayoutCanExecute));
                                    GraphLayoutSubMenu.Items.Add(new MenuItem {
                                        Command = newGLCommand
                                    });
                                    SearchIO.output("\t" + lt.Name + " loaded successfully.");
                                    k++;
                                }
                                catch (Exception exc)
                                {
                                    SearchIO.output("Unable to load " + lt.Name + ": " + exc.Message);
                                }
                            }
                        }
                    }
                }
                catch
                {
                    // File was either not found are not of the right type.
                }
            }
            if (Directory.Exists(GSApp.settings.GraphLayoutDirAbs))
            {
                glWatcher                       = new FileSystemWatcher(GSApp.settings.GraphLayoutDirAbs, "*.dll");
                glWatcher.Changed              += GraphLayoutDir_Changed;
                glWatcher.Created              += GraphLayoutDir_Changed;
                glWatcher.Deleted              += GraphLayoutDir_Changed;
                glWatcher.Renamed              += GraphLayoutDir_Changed;
                glWatcher.EnableRaisingEvents   = true;
                glWatcher.IncludeSubdirectories = true;
                glWatcher.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                                  | NotifyFilters.FileName;
            }
        }