private void UndoSynapse() { if (synapseUndoInfo.Count == 0) { return; } SynapseUndo s = synapseUndoInfo.Last(); synapseUndoInfo.RemoveAt(synapseUndoInfo.Count - 1); Neuron n = GetNeuron(s.source); if (s.newSynapse) //the synapse was added so delete it { n.DeleteSynapse(s.target); } else if (s.delSynapse) //the synapse was deleted so add it back { n.AddSynapse(s.target, s.weight, s.model); } else //weight/type changed { n.AddSynapse(s.target, s.weight, s.model); } n.Update(); }
public void MoveOneNeuron(Neuron n, Neuron nNewLocation) { //copy the neuron attributes and delete them from the old neuron. n.Copy(nNewLocation); MainWindow.theNeuronArray.SetCompleteNeuron(nNewLocation); //for all the synapses going out this neuron, change to going from new location //don't use a foreach here because the body of the loop may delete a list entry for (int k = 0; k < n.Synapses.Count; k++) { Synapse s = n.Synapses[k]; nNewLocation.AddSynapse(s.targetNeuron, s.weight, s.isHebbian); } //for all the synapses coming into this neuron, change the synapse target to new location for (int k = 0; k < n.SynapsesFrom.Count; k++) { Synapse reverseSynapse = n.SynapsesFrom[k]; //(from synapses are sort-of backward if (reverseSynapse.targetNeuron != -1) { Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(reverseSynapse.targetNeuron); sourceNeuron.DeleteSynapse(n.id); sourceNeuron.AddSynapse(nNewLocation.id, reverseSynapse.weight, reverseSynapse.isHebbian); } } n.Clear(); }
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; cm = mi2.Parent as ContextMenu; } int i = (int)cm.GetValue(NeuronIDProperty); Neuron n = MainWindow.theNeuronArray.GetNeuron(i); if ((string)mi.Header == "Always Fire") { if (n.FindSynapse(i) == null) { n.AddSynapse(i, 1, MainWindow.theNeuronArray, true); } else { n.DeleteSynapse(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 == "Connect to Here") { theNeuronArrayView.targetNeuronIndex = i; theNeuronArrayView.ConnectToHere(); } if ((string)mi.Header == "Connect from Here") { theNeuronArrayView.targetNeuronIndex = i; theNeuronArrayView.ConnectFromHere(); } if ((string)mi.Header == "Select as Target") { theNeuronArrayView.targetNeuronIndex = i; } }
private void StartSynapseDragging(FrameworkElement theShape) { int source = (int)theShape.GetValue(SynapseView.SourceIDProperty); int target = (int)theShape.GetValue(SynapseView.TargetIDProperty); lastSynapseWeight = (float)theShape.GetValue(SynapseView.WeightValProperty); lastSynapseModel = (Synapse.modelType)theShape.GetValue(SynapseView.ModelProperty); Neuron n = MainWindow.theNeuronArray.GetNeuron(source); n.DeleteSynapse(target); mouseDownNeuronIndex = source; currentOperation = CurrentOperation.draggingSynapse; Canvas parentCanvas = (Canvas)theShape.Parent; parentCanvas.Children.Remove(theShape); }
public void MoveOneNeuron(Neuron n, Neuron nNewLocation, bool addUndo = true) { if (addUndo) { n.AddUndoInfo(); nNewLocation.AddUndoInfo(); } if (MainWindow.useServers) { n.synapses = NeuronClient.GetSynapses(n.id); n.synapsesFrom = NeuronClient.GetSynapsesFrom(n.id); } //copy the neuron attributes and delete them from the old neuron. n.Copy(nNewLocation); MainWindow.theNeuronArray.SetCompleteNeuron(nNewLocation); if (FiringHistory.NeuronIsInFiringHistory(n.id)) { FiringHistory.RemoveNeuronFromHistoryWindow(n.id); FiringHistory.AddNeuronToHistoryWindow(nNewLocation.id); } //for all the synapses going out this neuron, change to going from new location //don't use a foreach here because the body of the loop may delete a list entry for (int k = 0; k < n.Synapses.Count; k++) { Synapse s = n.Synapses[k]; if (addUndo) { if (s.targetNeuron != n.id) { nNewLocation.AddSynapseWithUndo(s.targetNeuron, s.weight, s.model); } else { nNewLocation.AddSynapseWithUndo(nNewLocation.id, s.weight, s.model); } n.DeleteSynapseWithUndo(n.synapses[k].targetNeuron); } else { if (s.targetNeuron != n.id) { nNewLocation.AddSynapse(s.targetNeuron, s.weight, s.model); } else { nNewLocation.AddSynapse(nNewLocation.id, s.weight, s.model); } n.DeleteSynapse(n.synapses[k].targetNeuron); } } //for all the synapses coming into this neuron, change the synapse target to new location for (int k = 0; k < n.SynapsesFrom.Count; k++) { Synapse reverseSynapse = n.SynapsesFrom[k]; //(from synapses are sort-of backward if (reverseSynapse.targetNeuron != -1) //? { Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(reverseSynapse.targetNeuron); sourceNeuron.DeleteSynapseWithUndo(n.id); if (sourceNeuron.id != n.id) { if (addUndo) { sourceNeuron.AddSynapseWithUndo(nNewLocation.id, reverseSynapse.weight, reverseSynapse.model); } else { sourceNeuron.AddSynapse(nNewLocation.id, reverseSynapse.weight, reverseSynapse.model); } } } } n.Clear(); }
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 == "Always Fire") { if (n.FindSynapse(i) == null) { n.AddSynapse(i, 1, MainWindow.theNeuronArray, true); } else { n.DeleteSynapse(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 == "Connect to Here") { theNeuronArrayView.targetNeuronIndex = i; theNeuronArrayView.ConnectToHere(); } if ((string)mi.Header == "Connect from Here") { theNeuronArrayView.targetNeuronIndex = i; theNeuronArrayView.ConnectFromHere(); } if ((string)mi.Header == "Select as Target") { theNeuronArrayView.targetNeuronIndex = i; } }