private static void SetValueInSelectedNeurons(Neuron n, string property) { bool neuronInSelection = true; if (neuronInSelection) { List <int> theNeurons = theNeuronArrayView.theSelection.EnumSelectedNeurons(); //special case for label because they are auto-incremented, //clear all the labels first to avoid collisions if (property == "label") { for (int i = 0; i < theNeurons.Count; i++) { Neuron n1 = MainWindow.theNeuronArray.GetNeuron(theNeurons[i]); if (n1.id != n.id) { n1.Label = ""; n1.Update(); } } } for (int i = 0; i < theNeurons.Count; i++) { Neuron n1 = MainWindow.theNeuronArray.GetNeuron(theNeurons[i]); n1.AddUndoInfo(); switch (property) { case "currentCharge": if (n.model == Neuron.modelType.Color) { n1.SetValueInt(n.LastChargeInt); } else { n1.currentCharge = n.currentCharge; n1.lastCharge = n.currentCharge; } break; case "clear": n1.ClearWithUndo(); break; case "leakRate": n1.leakRate = n.leakRate; break; case "axonDelay": n1.axonDelay = n.axonDelay; break; case "model": n1.model = n.model; break; case "enable": n1.leakRate = n.leakRate; break; case "history": n1.RecordHistory = n.RecordHistory; break; case "synapses": n1.ShowSynapses = n.ShowSynapses; //if (MainWindow.arrayView.IsShowingSynapses(n.id)) //{ // MainWindow.arrayView.AddShowSynapses(n1.id); //} //else // MainWindow.arrayView.RemoveShowSynapses(n1.id); break; case "toolTip": n1.ToolTip = n.ToolTip; break; case "label": if (n.Label == "") { n1.Label = ""; } else if (n1.id != n.id) { string newLabel = n.Label; if (!Char.IsDigit(newLabel[newLabel.Length - 1])) { newLabel += "0"; } while (MainWindow.theNeuronArray.GetNeuron(newLabel) != null) { int num = 0; int digitCount = 0; while (Char.IsDigit(newLabel[newLabel.Length - 1])) { int.TryParse(newLabel[newLabel.Length - 1].ToString(), out int digit); num = num + (int)Math.Pow(10, digitCount) * digit; digitCount++; newLabel = newLabel.Substring(0, newLabel.Length - 1); } num++; newLabel = newLabel + num.ToString(); } n1.Label = newLabel; } break; } n1.Update(); } } }
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(); } }