private void MouseRepeatTimer_Tick(object sender, EventArgs e)
        {
            if (mouseDownNeuronIndex < 0)
            {
                return;
            }
            Neuron n = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex);

            n.SetValue(1);
            mouseRepeatTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
        }
Example #2
0
        private static void Cm_Closed(object sender, RoutedEventArgs e)
        {
            if (sender is ContextMenu cm)
            {
                if (!cm.IsOpen)
                {
                    return;
                }
                cm.IsOpen = false;
                if (cmCancelled)
                {
                    MainWindow.Update();
                    return;
                }
                MainWindow.theNeuronArray.SetUndoPoint();
                int    neuronID = (int)cm.GetValue(NeuronIDProperty);
                Neuron n        = MainWindow.theNeuronArray.GetNeuron(neuronID);
                n.AddUndoInfo();

                bool    applyToAll = false;
                Control cc         = Utils.FindByName(cm, "ApplyToSelection");
                if (cc is CheckBox cb)
                {
                    if (cb.IsChecked == true)
                    {
                        applyToAll = true;
                    }
                }

                cc = Utils.FindByName(cm, "Label");
                if (cc is TextBox tb)
                {
                    string newLabel = tb.Text;
                    if (int.TryParse(newLabel, out int dummy))
                    {
                        newLabel = "_" + newLabel;
                    }
                    if (labelChanged)
                    {
                        MainWindow.theNeuronArray.SetUndoPoint();
                        n.Label = newLabel;
                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "label");
                        }
                    }
                }
                cc = Utils.FindByName(cm, "Model");
                if (cc is ComboBox cb0)
                {
                    ListBoxItem      lbi = (ListBoxItem)cb0.SelectedItem;
                    Neuron.modelType nm  = (Neuron.modelType)System.Enum.Parse(typeof(Neuron.modelType), lbi.Content.ToString());
                    if (modelChanged)
                    {
                        n.model = nm;
                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "model");
                        }
                    }
                }
                cc = Utils.FindByName(cm, "CurrentCharge");
                if (cc is ComboBox tb1)
                {
                    if (n.model == Neuron.modelType.Color)
                    {
                        try
                        {
                            uint newCharge = Convert.ToUInt32(tb1.Text, 16);
                            if (chargeChanged)
                            {
                                n.SetValueInt((int)newCharge);
                                n.lastCharge = newCharge;
                                if (applyToAll)
                                {
                                    SetValueInSelectedNeurons(n, "currentCharge");
                                }
                                Utils.AddToValues(newCharge, colorValues);
                            }
                        }
                        catch { };
                    }
                    else
                    {
                        float.TryParse(tb1.Text, out float newCharge);
                        if (chargeChanged)
                        {
                            n.SetValue(newCharge);
                            n.lastCharge = newCharge;
                            if (applyToAll)
                            {
                                SetValueInSelectedNeurons(n, "currentCharge");
                            }
                            Utils.AddToValues(newCharge, currentChargeValues);
                        }
                    }
                }
                cc = Utils.FindByName(cm, "LeakRate");
                if (cc is ComboBox tb2)
                {
                    float.TryParse(tb2.Text, out float leakRate);
                    if (leakRateChanged)
                    {
                        n.LeakRate = leakRate;
                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "leakRate");
                        }
                        if (n.model == Neuron.modelType.LIF)
                        {
                            Utils.AddToValues(leakRate, leakRateValues);
                        }
                        if (n.model == Neuron.modelType.Random)
                        {
                            Utils.AddToValues(leakRate, stdDevValues);
                        }
                        if (n.model == Neuron.modelType.Burst)
                        {
                            Utils.AddToValues(leakRate, axonDelayValues);
                        }
                    }
                }
                else
                {
                    n.leakRate = 0;
                }
                cc = Utils.FindByName(cm, "AxonDelay");
                if (cc is ComboBox tb3)
                {
                    int.TryParse(tb3.Text, out int axonDelay);
                    if (axonDelayChanged)
                    {
                        n.axonDelay = axonDelay;
                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "axonDelay");
                        }
                        if (n.model == Neuron.modelType.Random)
                        {
                            Utils.AddToValues(axonDelay, meanValues);
                        }
                        else if (n.model == Neuron.modelType.Always)
                        {
                            Utils.AddToValues(axonDelay, alwaysDelayValues);
                        }
                        else if (n.model == Neuron.modelType.Burst)
                        {
                            Utils.AddToValues(axonDelay, alwaysDelayValues);
                        }
                        else
                        {
                            Utils.AddToValues(axonDelay, axonDelayValues);
                        }
                    }
                }
                cc = Utils.FindByName(cm, "Synapses");
                if (cc is CheckBox cb2)
                {
                    if (synapsesChanged)
                    {
                        if (cb2.IsChecked == true)
                        {
                            MainWindow.arrayView.AddShowSynapses(n.id);
                        }
                        else
                        {
                            MainWindow.arrayView.RemoveShowSynapses(n.id);
                        }
                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "synapses");
                        }
                    }
                }

                cc = Utils.FindByName(cm, "Enabled");
                if (cc is CheckBox cb1)
                {
                    if (enabledChanged)
                    {
                        if (cb1.IsChecked == true)
                        {
                            n.leakRate = Math.Abs(n.leakRate);
                        }
                        else
                        {
                            n.leakRate = Math.Abs(n.leakRate) * -1.0f;
                        }

                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "enable");
                        }
                    }
                }

                cc = Utils.FindByName(cm, "History");
                if (cc is CheckBox cb3)
                {
                    if (historyChanged)
                    {
                        if (cb3.IsChecked == true)
                        {
                            FiringHistory.AddNeuronToHistoryWindow(n.id);
                            OpenHistoryWindow();
                        }
                        else
                        {
                            FiringHistory.RemoveNeuronFromHistoryWindow(n.id);
                        }
                        if (applyToAll)
                        {
                            SetValueInSelectedNeurons(n, "history");
                        }
                    }
                }
                n.Update();
            }
            MainWindow.Update();
        }
Example #3
0
 private static void Cm_Closed(object sender, RoutedEventArgs e)
 {
     if ((Keyboard.GetKeyStates(Key.Escape) & KeyStates.Down) > 0)
     {
         return;
     }
     if (cmCancelled)
     {
         cmCancelled = false;
         return;
     }
     if (sender is ContextMenu cm)
     {
         int     neuronID = (int)cm.GetValue(NeuronIDProperty);
         Neuron  n        = MainWindow.theNeuronArray.GetNeuron(neuronID);
         Control cc       = Utils.FindByName(cm, "Label");
         if (cc is TextBox tb)
         {
             n.Label = tb.Text;
         }
         cc = Utils.FindByName(cm, "CurrentCharge");
         if (cc is TextBox tb1)
         {
             float.TryParse(tb1.Text, out float newCharge);
             n.SetValue(newCharge);
         }
         cc = Utils.FindByName(cm, "LeakRate");
         if (cc is TextBox tb2)
         {
             float.TryParse(tb2.Text, out float leakRate);
             if (n.LeakRate != leakRate)
             {
                 n.LeakRate = leakRate;
                 SetModelAndLeakrate(n);
             }
             n.LeakRate = leakRate;
         }
         cc = Utils.FindByName(cm, "History");
         if (cc is CheckBox cb1)
         {
             bool KeepHistory = (bool)cb1.IsChecked;
             if (!KeepHistory)
             {
                 FiringHistory.RemoveNeuronFromHistoryWindow(n.Id);
                 if (FiringHistory.history.Count == 0 && MainWindow.fwWindow != null && MainWindow.fwWindow.IsVisible)
                 {
                     MainWindow.fwWindow.Close();
                     MainWindow.fwWindow = null;
                 }
             }
             else  //make sure a window is open
             {
                 FiringHistory.AddNeuronToHistoryWindow(n.id);
                 OpenHistoryWindow();
             }
             //if there is a selection, set all the keepHistory values to match
             bool neuronInSelection = false;
             foreach (NeuronSelectionRectangle sr in theNeuronArrayView.theSelection.selectedRectangles)
             {
                 if (sr.NeuronIsInSelection(neuronID))
                 {
                     neuronInSelection = true;
                     break;
                 }
             }
             if (neuronInSelection)
             {
                 theNeuronArrayView.theSelection.EnumSelectedNeurons();
                 for (Neuron n1 = theNeuronArrayView.theSelection.GetSelectedNeuron(); n1 != null; n1 = theNeuronArrayView.theSelection.GetSelectedNeuron())
                 {
                     if (KeepHistory)
                     {
                         FiringHistory.AddNeuronToHistoryWindow(n1.id);
                     }
                     else
                     {
                         FiringHistory.RemoveNeuronFromHistoryWindow(n1.id);
                     }
                 }
                 //n1.KeepHistory = (bool)cb1.IsChecked;
             }
         }
     }
     MainWindow.Update();
 }