Ejemplo n.º 1
0
        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();
                NeuronSelectionRectangle rr = new NeuronSelectionRectangle(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();
        }
Ejemplo n.º 2
0
        private void MenuItem_SelectAll(object sender, RoutedEventArgs e)
        {
            arrayView.ClearSelection();
            NeuronSelectionRectangle rr = new NeuronSelectionRectangle(0, theNeuronArray.Cols, theNeuronArray.rows);

            arrayView.theSelection.selectedRectangles.Add(rr);
            Update();
        }
Ejemplo n.º 3
0
 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);
             NeuronSelectionRectangle rr = new NeuronSelectionRectangle(firstSelectedNeuron, w, h);
             theSelection.selectedRectangles.Add(rr);
         }
         catch
         {
             dragRectangle = null;
         }
         dragRectangle = null;
     }
 }
Ejemplo n.º 4
0
        private static void Cm_Closed(object sender, RoutedEventArgs e)
        {
            if ((Keyboard.GetKeyStates(Key.Escape) & KeyStates.Down) > 0)
            {
                return;
            }
            if (deleted)
            {
                deleted = false;
            }
            else if (sender is ContextMenu cm)
            {
                int    i = (int)cm.GetValue(AreaNumberProperty);
                string label = "";
                string commandLine = "";
                Color  color = Colors.Wheat;
                int    width = 1, height = 1;

                Control cc = Utils.FindByName(cm, "AreaName");
                if (cc is TextBox tb)
                {
                    label = tb.Text;
                }
                cc = Utils.FindByName(cm, "AreaWidth");
                if (cc is TextBox tb1)
                {
                    int.TryParse(tb1.Text, out width);
                }
                cc = Utils.FindByName(cm, "AreaHeight");
                if (cc is TextBox tb2)
                {
                    int.TryParse(tb2.Text, out height);
                }
                cc = Utils.FindByName(cm, "AreaType");
                if (cc is ComboBox cb && cb.SelectedValue != null)
                {
                    commandLine = (string)cb.SelectedValue;
                }
                if (commandLine == "")
                {
                    return;                   //something went wrong
                }
                cc = Utils.FindByName(cm, "CommandParams");
                if (cc is TextBox tb3)
                {
                    commandLine += " " + tb3.Text;
                }
                if ((label == "new" || label == "") && commandLine != "")
                {
                    label = commandLine;
                }
                cc = Utils.FindByName(cm, "AreaColor");
                if (cc is ComboBox cb1)
                {
                    color = ((SolidColorBrush)((ComboBoxItem)cb1.SelectedValue).Background).Color;
                }
                if (label == " " && commandLine == " ")
                {
                    return;
                }
                if (i >= 0)
                {
                    ModuleView theModuleView = MainWindow.theNeuronArray.modules[i];
                    //update the existing module
                    theModuleView.Label       = label;
                    theModuleView.CommandLine = commandLine;
                    theModuleView.Color       = Utils.ColorToInt(color);

                    //did we change the module type?
                    string[] Params = commandLine.Split(' ');
                    Type     t1x    = Type.GetType("BrainSimulator.Modules." + Params[0]);
                    if (t1x != null && (MainWindow.theNeuronArray.modules[i].TheModule == null || MainWindow.theNeuronArray.modules[i].TheModule.GetType() != t1x))
                    {
                        MainWindow.theNeuronArray.modules[i].TheModule = (ModuleBase)Activator.CreateInstance(t1x);
                        MainWindow.theNeuronArray.modules[i].label     = Params[0];
                    }

                    MainWindow.theNeuronArray.GetNeuronLocation(MainWindow.theNeuronArray.modules[i].firstNeuron, out int col, out int row);
                    if (width < theModuleView.TheModule.MinWidth)
                    {
                        width = theModuleView.TheModule.MinWidth;
                    }
                    if (height < theModuleView.TheModule.MinHeight)
                    {
                        height = theModuleView.TheModule.MinHeight;
                    }

                    bool dimsChanged = false;

                    if (width + col >= MainWindow.theNeuronArray.Cols)
                    {
                        width       = MainWindow.theNeuronArray.Cols - col;
                        dimsChanged = true;
                    }
                    if (height + row >= MainWindow.theNeuronArray.rows)
                    {
                        height      = MainWindow.theNeuronArray.rows - row;
                        dimsChanged = true;
                    }
                    if (dimsChanged)
                    {
                        MessageBox.Show("Dimensions reduced to stay within neuron array bondary.", "Warning", MessageBoxButton.OK);
                    }
                    theModuleView.Width  = width;
                    theModuleView.Height = height;
                }
                else
                {
                    //convert a selection rectangle to a module
                    i      = -i - 1;
                    width  = MainWindow.arrayView.theSelection.selectedRectangles[i].Width;
                    height = MainWindow.arrayView.theSelection.selectedRectangles[i].Height;
                    NeuronSelectionRectangle nsr = MainWindow.arrayView.theSelection.selectedRectangles[i];
                    MainWindow.arrayView.theSelection.selectedRectangles.RemoveAt(i);
                    CreateModule(label, commandLine, color, nsr.FirstSelectedNeuron, width, height);
                }
            }
            MainWindow.Update();
        }