Beispiel #1
0
        public override void RemoveConnections()
        {
            GraphEditorViewModel editor = (GraphEditorViewModel)((MainWindow)(App.Current.MainWindow)).VisualEditor.DataContext;
            List <NodePin>       pins   = new List <NodePin>();

            pins.AddRange(Inputs.Select(pin => pin.Pin));
            pins.AddRange(Outputs.Select(pin => pin.Pin));
            pins.AddRange(ExecutionInputs.Select(pin => pin.Pin));
            pins.AddRange(ExecutionOutputs.Select(pin => pin.Pin));

            List <ConnectionViewModel> connectionsToRemove = new List <ConnectionViewModel>();

            foreach (var connection in editor.Connections)
            {
                if (pins.Contains(connection.InputPinControl) || (pins.Contains(connection.OutputPinControl)))
                {
                    connectionsToRemove.Add(connection);
                }
            }

            foreach (var connection in connectionsToRemove)
            {
                editor.Connections.Remove(connection);
            }
        }
        protected void Clicked()
        {
            GraphEditorViewModel editor = (GraphEditorViewModel)((MainWindow)(App.Current.MainWindow)).VisualEditor.DataContext;

            foreach (VisualGraphComponentViewModel visualNode in editor.VisualNodes)
            {
                visualNode.IsSelected = false;
            }

            IsSelected = true;
        }
        protected void Delete()
        {
            GraphEditorViewModel graphViewModel = ((MainWindow)App.Current.MainWindow)
                                                  .VisualEditor
                                                  .DataContext as GraphEditorViewModel;

            if (graphViewModel.VisualNodes.Contains(this))
            {
                this.RemoveConnections();
                graphViewModel.VisualNodes.Remove(this);
            }
        }
        private void RemoveConnections()
        {
            GraphEditorViewModel       editor = (GraphEditorViewModel)((MainWindow)(App.Current.MainWindow)).VisualEditor.DataContext;
            List <ConnectionViewModel> connectionsToRemove = new List <ConnectionViewModel>();

            foreach (var connection in editor.Connections)
            {
                if (connection.InputPinControl == this.Pin || connection.OutputPinControl == this.Pin)
                {
                    connectionsToRemove.Add(connection);
                }
            }

            foreach (var connection in connectionsToRemove)
            {
                editor.Connections.Remove(connection);
            }
        }
        public MainWindowViewModel(GraphEditorViewModel graphViewModel)
        {
            this.graphViewModel = graphViewModel;

            InsertNodeCommand = new RelayCommand(InsertNode)
            {
                CanExecute = true
            };

            // Load in usable nodes
            string[]        dllFile    = Directory.GetFiles(App.PluginFolderPath, "*.dll");
            List <Assembly> assemblies = new List <Assembly>(dllFile.Length);

            foreach (string file in dllFile)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFrom(file);
                    Type[]   types    = assembly.GetTypes();

                    // Look for NodeBase types
                    foreach (Type type in types)
                    {
                        if (type.IsSubclassOf(typeof(NodeBase)))
                        {
                            // Get unique name
                            LoadedNodes.Add(type);

                            // If this is a conversion node tell our graph about it
                            ConversionRule conversionRule = type.GetCustomAttribute(typeof(ConversionRule)) as ConversionRule;

                            if (conversionRule != null)
                            {
                                graphViewModel.AddConversionRule(conversionRule.InputType, conversionRule.OutputType, type);
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Error loading nodes.\nPlease ensure there are libraries in the /NodePlugins folder and that they are unblocked.");
                }
            }
        }