private void btnDialogOk_Click(object sender, RoutedEventArgs e) { int.TryParse(txtColumns.Text, out int newCols); int.TryParse(txtRows.Text, out int newRows); int oldCols = MainWindow.theNeuronArray.arraySize / MainWindow.theNeuronArray.rows; int oldRows = MainWindow.theNeuronArray.rows; if (newCols < oldCols || newRows < oldRows) { MessageBox.Show("Can only make neuron array bigger."); return; } if (newCols != oldCols || newRows != oldRows) { MainWindow.arrayView.ClearSelection(); SelectionRectangle rr = new SelectionRectangle(0, oldCols, oldRows); MainWindow.arrayView.theSelection.selectedRectangles.Add(rr); MainWindow.arrayView.CopyNeurons(); MainWindow.arrayView.ClearSelection(); MainWindow.theNeuronArray = new NeuronArray(); MainWindow.theNeuronArray.Initialize(newRows * newCols, newRows); MainWindow.theNeuronArray.rows = newRows; MainWindow.arrayView.targetNeuronIndex = 0; MainWindow.arrayView.PasteNeurons(); MainWindow.theNeuronArray.ShowSynapses = true; MainWindow.thisWindow.SetShowSynapsesCheckBox(true); MainWindow.arrayView.ClearShowingSynapses(); FiringHistory.ClearAll(); MainWindow.CloseHistoryWindow(); } this.Close(); }
private void MenuItem_SelectAll(object sender, RoutedEventArgs e) { arrayView.ClearSelection(); SelectionRectangle rr = new SelectionRectangle(0, theNeuronArray.Cols, theNeuronArray.rows); arrayView.theSelection.selectedRectangles.Add(rr); Update(); }
private static void Cm_Closed(object sender, RoutedEventArgs e) { if ((Keyboard.GetKeyStates(Key.Escape) & KeyStates.Down) > 0) { MainWindow.Update(); return; } if (deleted) { deleted = false; } else if (sender is ContextMenu cm) { if (!cm.IsOpen) { return; } cm.IsOpen = false; if (cmCancelled) { return; } int i = (int)cm.GetValue(SelectionNumberProperty); string label = ""; string commandLine = ""; Color color = Colors.Wheat; int width = 1, height = 1; Control cc = Utils.FindByName(cm, "AreaType"); if (cc is ComboBox cb && cb.SelectedValue != null) { string moduleType = (string)((Label)cb.SelectedValue).Content; commandLine = "Module" + moduleType; if (commandLine == "") { return; //something went wrong } label = moduleType; } if (label == "" && commandLine == "") { return; } //convert a selection rectangle to a module MainWindow.theNeuronArray.SetUndoPoint(); MainWindow.arrayView.DeleteSelection(true); MainWindow.theNeuronArray.AddModuleUndo(MainWindow.theNeuronArray.modules.Count, null); width = MainWindow.arrayView.theSelection.selectedRectangles[i].Width; height = MainWindow.arrayView.theSelection.selectedRectangles[i].Height; SelectionRectangle nsr = MainWindow.arrayView.theSelection.selectedRectangles[i]; MainWindow.arrayView.theSelection.selectedRectangles.RemoveAt(i); CreateModule(label, commandLine, color, nsr.FirstSelectedNeuron, width, height); } MainWindow.Update(); }
private void UndoSelection() { MainWindow.arrayView.theSelection.selectedRectangles.Clear(); foreach (SelectionRectangle nsr in selectionUndoInfo.Last().selectionState.selectedRectangles) { SelectionRectangle nsr1 = new SelectionRectangle(nsr.FirstSelectedNeuron, nsr.Height, nsr.Width); MainWindow.arrayView.theSelection.selectedRectangles.Add(nsr1); } selectionUndoInfo.RemoveAt(selectionUndoInfo.Count - 1); }
public void AddSelectionUndo() { SelectUndo s1 = new SelectUndo(); s1.selectionState = new Selection(); foreach (SelectionRectangle nsr in MainWindow.arrayView.theSelection.selectedRectangles) { SelectionRectangle nsr1 = new SelectionRectangle(nsr.FirstSelectedNeuron, nsr.Height, nsr.Width); s1.selectionState.selectedRectangles.Add(nsr1); } selectionUndoInfo.Add(s1); }
private void FinishSelection() { if (dragRectangle != null) { try { //get the neuron pointers from the drag rectangle and save in the selection array int w = 1 + (lastSelectedNeuron - firstSelectedNeuron) / Rows; int h = 1 + (lastSelectedNeuron - firstSelectedNeuron) % Rows; //Debug.Write(firstSelectedNeuron + ", " + lastSelectedNeuron); SelectionRectangle rr = new SelectionRectangle(firstSelectedNeuron, w, h); theSelection.selectedRectangles.Add(rr); } catch { dragRectangle = null; } dragRectangle = null; } }
private static void Cm_Closed(object sender, RoutedEventArgs e) { if ((Keyboard.GetKeyStates(Key.Escape) & KeyStates.Down) > 0) { MainWindow.Update(); return; } if (deleted) { deleted = false; } else if (sender is ContextMenu cm) { if (!cm.IsOpen) { return; } cm.IsOpen = false; if (cmCancelled) { return; } int i = (int)cm.GetValue(SelectionNumberProperty); string label = ""; string commandLine = ""; Color color = Colors.LightBlue; int width = 1, height = 1; Control cc = Utils.FindByName(cm, "AreaType"); if (cc is ComboBox cb && cb.SelectedValue != null) { string moduleType = (string)((Label)cb.SelectedValue).Content; commandLine = "Module" + moduleType; if (commandLine == "") { return; //something went wrong } label = moduleType; } if (label == "" && commandLine == "") { return; } //check to see if the module will fit in the array Type t = Type.GetType("BrainSimulator.Modules." + commandLine); Modules.ModuleBase tempModule = (Modules.ModuleBase)Activator.CreateInstance(t); SelectionRectangle nsr = MainWindow.arrayView.theSelection.selectedRectangles[i]; MainWindow.theNeuronArray.GetNeuronLocation(nsr.FirstSelectedNeuron, out int col, out int row); if (row + tempModule.MinHeight > MainWindow.theNeuronArray.rows || col + tempModule.MinWidth > MainWindow.theNeuronArray.Cols) { MessageBox.Show("Minimum size would exceed neuron array boundary."); return; } //convert a selection rectangle to a module MainWindow.theNeuronArray.SetUndoPoint(); //clear out the underlying neurons //TODO: take care of this hack if (commandLine != "ModuleNull") { MainWindow.arrayView.DeleteSelection(true); } MainWindow.theNeuronArray.AddModuleUndo(MainWindow.theNeuronArray.modules.Count, null); width = MainWindow.arrayView.theSelection.selectedRectangles[i].Width; height = MainWindow.arrayView.theSelection.selectedRectangles[i].Height; if (width < tempModule.MinWidth) { width = tempModule.MinWidth; } if (width > tempModule.MaxWidth) { width = tempModule.MaxWidth; } if (height < tempModule.MinHeight) { height = tempModule.MinHeight; } if (height > tempModule.MaxHeight) { height = tempModule.MaxHeight; } CreateModule(label, commandLine, color, nsr.FirstSelectedNeuron, width, height); MainWindow.arrayView.theSelection.selectedRectangles.RemoveAt(i); } MainWindow.Update(); }