Beispiel #1
0
        //SYNAPSE
        private static void OpenSynapseContextMenu(FrameworkElement theShape)
        {
            int    source = (int)theShape.GetValue(SynapseView.SourceIDProperty);
            int    target = (int)theShape.GetValue(SynapseView.TargetIDProperty);
            float  weight = (float)theShape.GetValue(SynapseView.WeightValProperty);
            Neuron n1     = MainWindow.theNeuronArray.GetCompleteNeuron(source);

            n1 = MainWindow.theNeuronArray.AddSynapses(n1);
            Synapse s1 = n1.FindSynapse(target);

            theShape.ContextMenu = new ContextMenu();
            SynapseView.CreateContextMenu(source, s1, theShape.ContextMenu);
        }
Beispiel #2
0
        private static void SynapseMenuItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            MenuItem    mi       = sender as MenuItem;
            MenuItem    mi2      = mi.Parent as MenuItem;
            ContextMenu cm       = mi2.Parent as ContextMenu;
            int         sourceID = (int)cm.GetValue(NeuronIDProperty);
            ContextMenu newCm    = new ContextMenu();

            int.TryParse(mi.Header.ToString().Substring(0, 8), out int targetID);
            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;
            }
        }
        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);
            }
        }
 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;
     }
 }