Ejemplo n.º 1
0
        private static void Mi_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            //find out which neuron this context menu is from
            ContextMenu cm = mi.Parent as ContextMenu;

            if (cm == null)
            {
                MenuItem mi2 = mi.Parent as MenuItem;
                if (mi2.Header.ToString().IndexOf("Synapses") == 0)
                {
                    int.TryParse(mi.Header.ToString().Substring(0, 8), out int newID);
                    Neuron n1 = MainWindow.theNeuronArray.GetNeuron(newID);
                    NeuronView.CreateContextMenu(n1.id, n1, new ContextMenu()
                    {
                        IsOpen = true,
                    });
                    return;
                }
                cm = mi2.Parent as ContextMenu;
            }
            int    i = (int)cm.GetValue(NeuronIDProperty);
            Neuron n = MainWindow.theNeuronArray.GetNeuron(i);

            if ((string)mi.Header == "Paste Here")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.PasteNeurons();
                theNeuronArrayView.targetNeuronIndex = -1;
                cmCancelled = true;
            }
            if ((string)mi.Header == "Move Here")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.MoveNeurons();
                cmCancelled = true;
            }
            if ((string)mi.Header == "From Selection to Here")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.ConnectToHere();
            }
            if ((string)mi.Header == "From Here to Selection")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.ConnectFromHere();
            }
            if ((string)mi.Header == "Mutual Suppression")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.MutualSuppression();
            }
        }
        //this reloads the file which was being used on the previous run of the program
        //or creates a new one
        private void Window_ContentRendered(object sender, EventArgs e)
        {
            progressDialog            = new ProgressDialog();
            progressDialog.Visibility = Visibility.Collapsed;
            progressDialog.Top        = 100;
            progressDialog.Left       = 100;
            progressDialog.Owner      = this;
            progressDialog.Show();
            progressDialog.Hide();
            progressDialog.SetProgress(100, "");

            //if the left shift key is pressed, don't load the file
            if (Keyboard.IsKeyUp(Key.LeftShift))
            {
                try
                {
                    string fileName = ""; //if the load is successful, currentfile will be set by the load process
                    if (App.StartupString != "")
                    {
                        fileName = App.StartupString;
                    }
                    if (fileName == "")
                    {
                        fileName = (string)Properties.Settings.Default["CurrentFile"];
                    }
                    if (fileName != "")
                    {
                        LoadFile(fileName);
                        NeuronView.OpenHistoryWindow();
                    }
                    else //force a new file creation on startup if no file name set
                    {
                        CreateEmptyNetwork();
                        SetPlayPauseButtonImage(false);
                    }
                }
                //various errors might have happened so we'll just ignore them all and start with a fresh file
                catch (Exception e1)
                {
                    e1.GetType();
                    MessageBox.Show("Error encountered in file load: " + e1.Message);
                    CreateEmptyNetwork();
                }
            }
            LoadModuleTypeMenu();
        }
Ejemplo n.º 3
0
        //NEURON

        private void OpenNeuronContextMenu(FrameworkElement theShape)
        {
            if (theShape is Label l)
            {
                l.ContextMenu = new ContextMenu();
                Neuron n1 = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex);
                NeuronView.CreateContextMenu(mouseDownNeuronIndex, n1, l.ContextMenu);
                l.ContextMenu.IsOpen = true;
            }
            else
            {
                theShape.ContextMenu = new ContextMenu();
                Neuron n1 = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex);
                NeuronView.CreateContextMenu(mouseDownNeuronIndex, n1, theShape.ContextMenu);
                targetNeuronIndex           = mouseDownNeuronIndex;
                theShape.ContextMenu.IsOpen = true;
            }
        }
Ejemplo n.º 4
0
 private void OpenHistoryWindow()
 {
     if (Application.Current.MainWindow != this)
     {
         return;
     }
     if (theNeuronArray != null)
     {
         bool history = false;
         foreach (Neuron n in theNeuronArray.Neurons())
         {
             if (n.KeepHistory)
             {
                 history = true;
             }
         }
         if (history)
         {
             NeuronView.OpenHistoryWindow();
         }
     }
 }
Ejemplo n.º 5
0
        public void theCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (MainWindow.theNeuronArray == null)
            {
                return;
            }
            Debug.WriteLine("theCanvas_MouseDown" + MainWindow.theNeuronArray.Generation);
            Point currentPosition = e.GetPosition(theCanvas);

            LimitMousePostion(ref currentPosition);
            mouseDownNeuronIndex = dp.NeuronFromPoint(currentPosition);

            if (e.RightButton == MouseButtonState.Pressed)
            {
                if (sender is Image img)
                {
                    int        i  = (int)img.GetValue(ModuleView.AreaNumberProperty);
                    int        i1 = -i - 1;
                    ModuleView nr = new ModuleView
                    {
                        Label       = "new",
                        Width       = theSelection.selectedRectangles[i1].Width,
                        Height      = theSelection.selectedRectangles[i1].Height,
                        Color       = Utils.ColorToInt(Colors.Aquamarine),
                        CommandLine = ""
                    };
                    img.ContextMenu = new ContextMenu();
                    ModuleView.CreateContextMenu(i, nr, img, img.ContextMenu);
                    img.ContextMenu.IsOpen = true;
                    e.Handled = true;
                }
                else if (sender is Rectangle r)
                {
                    int i = (int)r.GetValue(ModuleView.AreaNumberProperty);
                    if (i >= 0)
                    {
                        ModuleView nr = MainWindow.theNeuronArray.Modules[i];
                        r.ContextMenu = new ContextMenu();
                        ModuleView.CreateContextMenu(i, nr, r, r.ContextMenu);
                        r.ContextMenu.IsOpen = true;
                        e.Handled            = true;
                    }
                    if (i < 0)
                    {
                        int        i1 = -i - 1;
                        ModuleView nr = new ModuleView
                        {
                            Label       = "new",
                            Width       = theSelection.selectedRectangles[i1].Width,
                            Height      = theSelection.selectedRectangles[i1].Height,
                            Color       = Utils.ColorToInt(Colors.Aquamarine),
                            CommandLine = ""
                        };
                        r.ContextMenu = new ContextMenu();
                        ModuleView.CreateContextMenu(i, nr, r, r.ContextMenu);
                        r.ContextMenu.IsOpen = true;
                        e.Handled            = true;
                    }
                }
                else if (sender is Label l)
                {
                    l.ContextMenu = new ContextMenu();
                    Neuron n1 = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex);
                    NeuronView.CreateContextMenu(mouseDownNeuronIndex, n1, l.ContextMenu);
                    l.ContextMenu.IsOpen = true;
                    e.Handled            = true;
                }
                else if (sender is Shape s)
                {
                    if ((s is Path || s is Line ||
                         (s is Ellipse && (int)s.GetValue(SynapseView.SourceIDProperty) != 0))) // a synapse
                    {
                        int    source = (int)s.GetValue(SynapseView.SourceIDProperty);
                        int    target = (int)s.GetValue(SynapseView.TargetIDProperty);
                        float  weight = (float)s.GetValue(SynapseView.WeightValProperty);
                        Neuron n1     = MainWindow.theNeuronArray.GetCompleteNeuron(source);
                        n1 = MainWindow.theNeuronArray.AddSynapses(n1);
                        Synapse s1 = n1.FindSynapse(target);
                        s.ContextMenu = new ContextMenu();
                        SynapseView.CreateContextMenu(source, s1, s.ContextMenu);
                    }
                    else if (s is Ellipse) // a neuron
                    {
                        s.ContextMenu = new ContextMenu();
                        Neuron n1 = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex);
                        NeuronView.CreateContextMenu(mouseDownNeuronIndex, n1, s.ContextMenu);
                        targetNeuronIndex = mouseDownNeuronIndex;
                    }
                    if (s.ContextMenu != null)
                    {
                        s.ContextMenu.IsOpen = true;
                    }
                    e.Handled = true;
                }
                else
                {
                }
                return;
            }

            Neuron n = null;

            if (mouseDownNeuronIndex >= 0 && mouseDownNeuronIndex < MainWindow.theNeuronArray.arraySize)
            {
                n = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex) as Neuron;
            }

            if (theCanvas.Cursor == Cursors.Cross)
            {
                //          Debug.WriteLine("dragStart" + MainWindow.theNeuronArray.Generation);
                if (dragRectangle != null)
                {
                    theCanvas.Children.Remove(dragRectangle);
                }

                MainWindow.theNeuronArray.SetUndoPoint();
                MainWindow.theNeuronArray.AddSelectionUndo();
                if (!MainWindow.ctrlPressed)
                {
                    theSelection.selectedRectangles.Clear();
                }
                else
                {
                    Update();
                }

                //snap to neuron point
                currentPosition = dp.pointFromNeuron(mouseDownNeuronIndex);

                //build the draggable selection rectangle
                dragRectangle              = new Rectangle();
                dragRectangle.Width        = dragRectangle.Height = dp.NeuronDisplaySize;
                dragRectangle.Stroke       = new SolidColorBrush(Colors.Red);
                dragRectangle.Fill         = new SolidColorBrush(Colors.Red);
                dragRectangle.Fill.Opacity = 0.5;
                Canvas.SetLeft(dragRectangle, currentPosition.X);
                Canvas.SetTop(dragRectangle, currentPosition.Y);
                theCanvas.Children.Add(dragRectangle);
                firstSelectedNeuron = mouseDownNeuronIndex;
                lastSelectedNeuron  = mouseDownNeuronIndex;
                Mouse.Capture(theCanvas);
            }

            if (theCanvas.Cursor == Cursors.ScrollAll)
            {
                dragging = true;
                MainWindow.theNeuronArray.SetUndoPoint();
            }
            if (theCanvas.Cursor == Cursors.UpArrow)
            {
                if (e.ClickCount == 2 && sender is Canvas)
                {
                    //double-click detected
                    n          = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex);
                    n.leakRate = -n.leakRate;
                    n.Update();
                }

                Mouse.Capture(theCanvas);
                if (mouseRepeatTimer == null)
                {
                    mouseRepeatTimer = new DispatcherTimer();
                }
                if (mouseRepeatTimer.IsEnabled)
                {
                    mouseRepeatTimer.Stop();
                }
                mouseRepeatTimer.Interval = new TimeSpan(0, 0, 0, 0, 250);
                mouseRepeatTimer.Tick    += MouseRepeatTimer_Tick;
                mouseRepeatTimer.Start();
                dragging          = true;
                targetNeuronIndex = mouseDownNeuronIndex;
            }
            if (theCanvas.Cursor == Cursors.Hand)
            {
                StartPan(e.GetPosition((UIElement)theCanvas.Parent));
                Mouse.Capture(theCanvas);
            }
        }
Ejemplo n.º 6
0
 private static void SynapseEntry_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (sender is TextBlock tb0)
     {
         if (tb0.Parent is StackPanel sp)
         {
             if (sp.Parent is MenuItem mi)
             {
                 if (mi.Parent is ContextMenu cm)
                 {
                     if (tb0.Name == "weight")
                     {
                         int sourceID = (int)cm.GetValue(NeuronIDProperty);
                         if (sp.Children.Count > 1 && sp.Children[1] is TextBlock tb1)
                         {
                             int.TryParse(tb1.Text.Substring(0, 8), out int targetID);
                             if (mi.Header.ToString().Contains("In"))
                             {
                                 int temp = targetID;
                                 targetID = sourceID;
                                 sourceID = temp;
                             }
                             ContextMenu newCm = new ContextMenu();
                             Neuron      n     = MainWindow.theNeuronArray.GetNeuron(sourceID);
                             Synapse     s     = n.FindSynapse(targetID);
                             if (s != null)
                             {
                                 SynapseView.CreateContextMenu(sourceID, s, newCm);
                                 newCm.IsOpen = true;
                                 e.Handled    = true;
                             }
                         }
                     }
                     if (tb0.Name == "neuron")
                     {
                         int.TryParse(tb0.Text.Substring(0, 8), out int targetID);
                         Neuron      n1  = MainWindow.theNeuronArray.GetNeuron(targetID);
                         ContextMenu cm1 = NeuronView.CreateContextMenu(n1.id, n1, new ContextMenu()
                         {
                             IsOpen = true,
                         });
                         MainWindow.arrayView.targetNeuronIndex = targetID;
                         Point loc = dp.pointFromNeuron(targetID);
                         if (loc.X < 0 || loc.X > theCanvas.ActualWidth - cm.ActualWidth ||
                             loc.Y < 0 || loc.Y > theCanvas.ActualHeight - cm.ActualHeight)
                         {
                             MainWindow.arrayView.PanToNeuron(targetID);
                             loc = dp.pointFromNeuron(targetID);
                         }
                         loc.X += dp.NeuronDisplaySize / 2;
                         loc.Y += dp.NeuronDisplaySize / 2;
                         loc    = MainWindow.arrayView.theCanvas.PointToScreen(loc);
                         cm1.PlacementRectangle = new Rect(loc.X, loc.Y, 0, 0);
                         cm1.Placement          = System.Windows.Controls.Primitives.PlacementMode.AbsolutePoint;
                     }
                 }
             }
         }
         e.Handled = true;
     }
 }
Ejemplo n.º 7
0
        private static void Mi_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            //find out which neuron this context menu is from
            ContextMenu cm = mi.Parent as ContextMenu;

            if (cm == null)
            {
                MenuItem mi2 = mi.Parent as MenuItem;
                if (mi2.Header.ToString().IndexOf("Synapses") == 0)
                {
                    int.TryParse(mi.Header.ToString().Substring(0, 8), out int newID);
                    Neuron n1 = MainWindow.theNeuronArray.GetNeuron(newID);
                    NeuronView.CreateContextMenu(n1.id, n1, new ContextMenu()
                    {
                        IsOpen = true,
                    });
                    return;
                }
                cm = mi2.Parent as ContextMenu;
            }
            int    i = (int)cm.GetValue(NeuronIDProperty);
            Neuron n = MainWindow.theNeuronArray.GetNeuron(i);

            if ((string)mi.Header == "Paste Here")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.PasteNeurons();
                theNeuronArrayView.targetNeuronIndex = -1;
                cmCancelled = true;
            }
            if ((string)mi.Header == "Clear Synapses")
            {
                MainWindow.theNeuronArray.SetUndoPoint();
                n.ClearWithUndo();
                Control cc = Utils.FindByName(cm, "ApplyToSelection");
                if (cc is CheckBox cb)
                {
                    if (cb.IsChecked == true)
                    {
                        SetValueInSelectedNeurons(n, "clear");
                    }
                }
                cmCancelled = true;
                MainWindow.Update();
            }
            if ((string)mi.Header == "Move Here")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.MoveNeurons();
                cmCancelled = true;
            }
            if ((string)mi.Header == "From Selection to Here")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.ConnectToHere();
            }
            if ((string)mi.Header == "From Here to Selection")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.ConnectFromHere();
            }
            if ((string)mi.Header == "Mutual Suppression")
            {
                theNeuronArrayView.targetNeuronIndex = i;
                theNeuronArrayView.MutualSuppression();
            }
        }