private bool IsDestinationClear(List <int> neuronsToMove, int offset, bool flagOverlap = false)
        {
            bool retVal = true;

            foreach (int id in neuronsToMove)
            {
                if (flagOverlap || !neuronsToMove.Contains(id + offset))
                {
                    Neuron n = MainWindow.theNeuronArray.GetNeuron(id + offset);
                    if (n.InUse())
                    {
                        retVal = false;
                        break;
                    }
                }
            }
            return(retVal);
        }
Beispiel #2
0
        public static UIElement GetNeuronView(int i, NeuronArrayView theNeuronArrayViewI, out Label l)
        {
            l = null;
            theNeuronArrayView = theNeuronArrayViewI;
            //this hack makes the GameOfLife display bettern
            if (MainWindow.currentFileName.Contains("Life"))
            {
                int row = i % dp.NeuronRows;
                int col = i / dp.NeuronRows;
                if ((row + 1) % 2 != 0)
                {
                    return(null);
                }
                if (col % 2 != 0)
                {
                    return(null);
                }
            }

            Neuron n = MainWindow.theNeuronArray.GetNeuron(i);
            Point  p = dp.pointFromNeuron(i);

            //if (p.X < -dp.NeuronDisplaySize) return null;
            //if (p.Y < -dp.NeuronDisplaySize) return null;
            //if (p.X > theCanvas.ActualWidth + dp.NeuronDisplaySize) return null;
            //if (p.Y > theCanvas.ActualHeight + dp.NeuronDisplaySize) return null;

            // figure out which color to use
            float value = n.LastCharge;
            Color c     = Colors.Blue;

            if ((n.Model == Neuron.modelType.Std || n.Model == Neuron.modelType.LIF) && value > .99)
            {
                c = Colors.Orange;
            }
            else if ((n.Model == Neuron.modelType.Std || n.Model == Neuron.modelType.LIF) && value != -1)
            {
                c = MapRainbowColor(value, 1, 0);
            }
            else if (n.Model == Neuron.modelType.Color)
            {
                c = Utils.IntToColor((int)n.LastChargeInt);
            }
            SolidColorBrush s1 = new SolidColorBrush(c);

            //   if (n.Label != "" || !n.InUse()) s1.Opacity = .50;
            if (!n.InUse() && n.Model == Neuron.modelType.Std)
            {
                s1.Opacity = .50;
            }

            Shape r = null;

            if (dp.ShowNeuronCircles())
            {
                r        = new Ellipse();
                r.Width  = dp.NeuronDisplaySize * ellipseSize;
                r.Height = dp.NeuronDisplaySize * ellipseSize;
            }
            else
            {
                r        = new Rectangle();
                r.Width  = dp.NeuronDisplaySize;
                r.Height = dp.NeuronDisplaySize;
            }
            r.Fill = s1;
            if (dp.ShowNeuronOutlines())
            {
                r.Stroke          = Brushes.Black;
                r.StrokeThickness = 1;
            }

            r.MouseDown  += theNeuronArrayView.theCanvas_MouseDown;
            r.MouseUp    += theNeuronArrayView.theCanvas_MouseUp;
            r.MouseWheel += theNeuronArrayView.theCanvas_MouseWheel;

            float offset = (1 - ellipseSize) / 2f;

            Canvas.SetLeft(r, p.X + dp.NeuronDisplaySize * offset);
            Canvas.SetTop(r, p.Y + dp.NeuronDisplaySize * offset);
            if (dp.ShowNeuronArrowCursor())
            {
                r.MouseEnter += R_MouseEnter;
                r.MouseLeave += R_MouseLeave;
            }


            if (n.Label != "")
            {
                l            = new Label();
                l.Content    = n.Label;
                l.FontSize   = dp.NeuronDisplaySize * .25;
                l.Foreground = Brushes.White;
                Canvas.SetLeft(l, p.X + dp.NeuronDisplaySize * offset);
                Canvas.SetTop(l, p.Y + dp.NeuronDisplaySize * offset);
                Canvas.SetZIndex(l, 100);

                if (dp.ShowNeuronArrowCursor())
                {
                    l.MouseEnter += R_MouseEnter;
                    l.MouseLeave += R_MouseLeave;
                }
                l.MouseDown += theNeuronArrayView.theCanvas_MouseDown;
                l.MouseUp   += theNeuronArrayView.theCanvas_MouseUp;
                l.MouseMove += theNeuronArrayView.theCanvas_MouseMove;
                //theCanvas.Children.Add(l);
            }
            return(r);
        }