public void StepAndRepeat(int source, int target, float weight, Synapse.modelType model) { int distance = target - source; theSelection.EnumSelectedNeurons(); for (Neuron n = theSelection.GetSelectedNeuron(); n != null; n = theSelection.GetSelectedNeuron()) { n.AddSynapseWithUndo(theSelection.selectedNeuronIndex + distance, weight, model); } Update(); }
public void AddSynapseUndo(int source, int target, float weight, Synapse.modelType model, bool newSynapse, bool delSynapse) { SynapseUndo s; s = new SynapseUndo { source = source, target = target, weight = weight, model = model, newSynapse = newSynapse, delSynapse = delSynapse, }; synapseUndoInfo.Add(s); }
public static void AddSynapse(int src, int dest, float weight, Synapse.modelType model, bool noBackPtr) { string command = "AddSynapse "; command += src + " "; command += dest + " "; command += weight + " "; command += model + " "; int srcServer = GetServerIndex(src); SendToServer(serverList[srcServer].ipAddress, command); int destServer = GetServerIndex(dest); if (srcServer != destServer) { SendToServer(serverList[destServer].ipAddress, command); } }
public static Shape GetSynapseShape(Point p1, Point p2, Synapse.modelType model) { //returns a line from the source to the destination (with a link arrow at larger zooms //unless the source and destination are the same in which it returns an arc Shape s; if (p1 != p2) { Line l = new Line(); l.X1 = p1.X + dp.NeuronDisplaySize / 2; l.X2 = p2.X + dp.NeuronDisplaySize / 2; l.Y1 = p1.Y + dp.NeuronDisplaySize / 2; l.Y2 = p2.Y + dp.NeuronDisplaySize / 2; s = l; if (dp.ShowSynapseArrows()) { Vector offset = new Vector(dp.NeuronDisplaySize / 2, dp.NeuronDisplaySize / 2); s = DrawLinkArrow(p1 + offset, p2 + offset, model != Synapse.modelType.Fixed); } } else { s = new Ellipse(); s.Height = s.Width = dp.NeuronDisplaySize * .6; Canvas.SetTop(s, p1.Y + dp.NeuronDisplaySize / 4); Canvas.SetLeft(s, p1.X + dp.NeuronDisplaySize / 2); } s.Stroke = Brushes.Red; s.StrokeThickness = 1; if (dp.ShowSynapseWideLines()) { s.StrokeThickness = Math.Min(4, dp.NeuronDisplaySize / 15); } return(s); }
private static void Cm_Closed(object sender, RoutedEventArgs e) { if (sender is ContextMenu cm) { if (cmCancelled || (Keyboard.GetKeyStates(Key.Escape) & KeyStates.Down) > 0) { cm.IsOpen = false; MainWindow.Update(); return; } int sourceID = (int)cm.GetValue(SourceIDProperty); int targetID = (int)cm.GetValue(TargetIDProperty); Neuron nSource = MainWindow.theNeuronArray.GetNeuron(sourceID); Neuron nTarget = MainWindow.theNeuronArray.GetNeuron(targetID); int newSourceID = sourceID; int newTargetID = targetID; Control cc = Utils.FindByName(cm, "Target"); if (cc is TextBox tb) { string targetLabel = tb.Text; if (nTarget.label != targetLabel) { if (!int.TryParse(tb.Text, out newTargetID)) { newTargetID = targetID; Neuron n = MainWindow.theNeuronArray.GetNeuron(targetLabel); if (n != null) { newTargetID = n.id; } } } } cc = Utils.FindByName(cm, "Source"); if (cc is TextBox tb1) { string sourceLabel = tb1.Text; if (nSource.label != sourceLabel) { if (!int.TryParse(tb1.Text, out newSourceID)) { newSourceID = sourceID; Neuron n = MainWindow.theNeuronArray.GetNeuron(sourceLabel); if (n != null) { newSourceID = n.id; } } } } if (newSourceID < 0 || newSourceID >= MainWindow.theNeuronArray.arraySize || newTargetID < 0 || newTargetID >= MainWindow.theNeuronArray.arraySize ) { MessageBox.Show("Neuron outside array boundary!"); return; } cc = Utils.FindByName(cm, "SynapseWeight"); if (cc is ComboBox tb2) { float.TryParse(tb2.Text, out float newWeight); if (weightChanged) { theNeuronArrayView.lastSynapseWeight = newWeight; Utils.AddToValues(newWeight, synapseWeightValues); } } cc = Utils.FindByName(cm, "Model"); if (cc is ComboBox cb0) { ListBoxItem lbi = (ListBoxItem)cb0.SelectedItem; Synapse.modelType sm = (Synapse.modelType)System.Enum.Parse(typeof(Synapse.modelType), lbi.Content.ToString()); theNeuronArrayView.lastSynapseModel = sm; } if (newSourceID != sourceID || newTargetID != targetID) { MainWindow.theNeuronArray.SetUndoPoint(); MainWindow.theNeuronArray.GetNeuron((int)cm.GetValue(SourceIDProperty)).DeleteSynapseWithUndo((int)cm.GetValue(TargetIDProperty)); } Neuron nNewSource = MainWindow.theNeuronArray.GetNeuron(newSourceID); nNewSource.AddSynapseWithUndo(newTargetID, theNeuronArrayView.lastSynapseWeight, theNeuronArrayView.lastSynapseModel); cm.IsOpen = false; MainWindow.Update(); } }
//these aren't added to synapses (for performance) but are built on the fly if the user right-clicks public static void CreateContextMenu(int i, Synapse s, ContextMenu cm) { cmCancelled = false; weightChanged = false; //set defaults for next synapse add theNeuronArrayView.lastSynapseModel = s.model; theNeuronArrayView.lastSynapseWeight = s.weight; cm.SetValue(SourceIDProperty, i); cm.SetValue(TargetIDProperty, s.TargetNeuron); cm.SetValue(WeightValProperty, s.Weight); cm.SetValue(ModelProperty, s.model); cm.Closed += Cm_Closed; cm.PreviewKeyDown += Cm_PreviewKeyDown; cm.Opened += Cm_Opened; Neuron nSource = MainWindow.theNeuronArray.GetNeuron(i); Neuron nTarget = MainWindow.theNeuronArray.GetNeuron(s.targetNeuron); StackPanel sp = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 3, 3) }; sp.Children.Add(new Label { Content = "Source: ", Padding = new Thickness(0) }); string source = nSource.id.ToString(); if (nSource.label != "") { source = nSource.Label; } TextBox t0 = Utils.ContextMenuTextBox(source, "Source", 150); t0.TextChanged += TextChanged; sp.Children.Add(t0); cm.Items.Add(new MenuItem { Header = sp, StaysOpenOnClick = true }); sp = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 3, 3) }; sp.Children.Add(new Label { Content = "Target: ", Padding = new Thickness(0) }); string target = nTarget.id.ToString(); if (nTarget.label != "") { target = nTarget.Label; } TextBox t1 = Utils.ContextMenuTextBox(target, "Target", 150); t1.TextChanged += TextChanged; sp.Children.Add(t1); cm.Items.Add(new MenuItem { Header = sp, StaysOpenOnClick = true }); //The Synapse model sp = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 3, 3) }; sp.Children.Add(new Label { Content = "Model: ", Padding = new Thickness(0) }); ComboBox cb = new ComboBox() { Width = 100, Name = "Model" }; for (int index = 0; index < Enum.GetValues(typeof(Synapse.modelType)).Length; index++) { Synapse.modelType model = (Synapse.modelType)index; cb.Items.Add(new ListBoxItem() { Content = model.ToString(), ToolTip = Synapse.modelToolTip[index], Width = 100, }); } cb.SelectedIndex = (int)s.model; sp.Children.Add(cb); cm.Items.Add(new MenuItem { Header = sp, StaysOpenOnClick = true }); cm.Items.Add(Utils.CreateComboBoxMenuItem("SynapseWeight", s.weight, synapseWeightValues, "F3", "Weight: ", 100, ComboBox_ContentChanged)); MenuItem mi = new MenuItem(); mi.Header = "Delete"; mi.Click += DeleteSynapse_Click; cm.Items.Add(mi); sp = new StackPanel { Orientation = Orientation.Horizontal }; Button b0 = new Button { Content = "OK", Width = 100, Height = 25, Margin = new Thickness(10), IsDefault = true }; b0.Click += B0_Click; sp.Children.Add(b0); b0 = new Button { Content = "Cancel", Width = 100, Height = 25, Margin = new Thickness(10), IsCancel = true }; b0.Click += B0_Click; sp.Children.Add(b0); cm.Items.Add(new MenuItem { Header = sp, StaysOpenOnClick = true }); }