Exemplo n.º 1
0
        private void DragInsertingModule(int currentNeuron)
        {
            if (labelCursor.Parent == null)
            {
                theCanvas.Children.Add(labelCursor);
            }
            if (rectCursor.Parent == null)
            {
                theCanvas.Children.Add(rectCursor);
            }

            string moduleLabel = labelCursor.Content.ToString();
            Type   t           = Type.GetType("BrainSimulator.Modules.Module" + moduleLabel);

            Modules.ModuleBase theModule = (Modules.ModuleBase)Activator.CreateInstance(t);

            MainWindow.theNeuronArray.GetNeuronLocation(currentNeuron, out int col, out int row);
            col           = Math.Min(col, MainWindow.theNeuronArray.Cols - theModule.MinWidth);
            row           = Math.Min(row, MainWindow.theNeuronArray.rows - theModule.MinHeight);
            currentNeuron = MainWindow.theNeuronArray.GetNeuronIndex(col, row);
            Point snappedPosition = dp.pointFromNeuron(currentNeuron);

            labelCursor.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            Canvas.SetTop(labelCursor, snappedPosition.Y - labelCursor.DesiredSize.Height);
            Canvas.SetLeft(labelCursor, snappedPosition.X);
            Canvas.SetTop(rectCursor, snappedPosition.Y);
            Canvas.SetLeft(rectCursor, snappedPosition.X);
            currentOperation = CurrentOperation.insertingModule;
        }
Exemplo n.º 2
0
        public ModuleView(int firstNeuron1, int width, int height, string theLabel, string theModuleTypeStr, int theColor)
        {
            FirstNeuron   = firstNeuron1;
            Width         = width;
            Height        = height;
            Label         = theLabel;
            ModuleTypeStr = theModuleTypeStr;
            color         = theColor;
            Type t = Type.GetType("BrainSimulator.Modules." + theModuleTypeStr);

            theModule = (Modules.ModuleBase)Activator.CreateInstance(t);
        }
Exemplo n.º 3
0
 public ModuleView(int firstNeuron1, int width, int height, string theLabel, string theCommandLine, int theColor)
 {
     FirstNeuron = firstNeuron1;
     Width       = width;
     Height      = height;
     Label       = theLabel;
     CommandLine = theCommandLine;
     color       = theColor;
     string[] Params = CommandLine.Split(' ');
     if (commandLine.IndexOf("Module") == 0) //take this out when all modules are ported to new class structure
     {
         Type t = Type.GetType("BrainSimulator.Modules." + Params[0]);
         theModule = (Modules.ModuleBase)Activator.CreateInstance(t);
     }
 }
Exemplo n.º 4
0
        public static void StartInsertingModule(string moduleLabel)
        {
            StopInsertingModule();
            labelCursor = new Label
            {
                Content    = moduleLabel,
                Background = new SolidColorBrush(Colors.White),
            };

            Type t = Type.GetType("BrainSimulator.Modules.Module" + moduleLabel);

            Modules.ModuleBase theModule = (Modules.ModuleBase)Activator.CreateInstance(t);
            rectCursor = new Rectangle
            {
                Fill    = new SolidColorBrush(Colors.Wheat),
                Opacity = 0.3,
                Width   = theModule.MinWidth * MainWindow.arrayView.dp.NeuronDisplaySize,
                Height  = theModule.MinHeight * MainWindow.arrayView.dp.NeuronDisplaySize,
            };
            MainWindow.arrayView.theCanvas.Cursor = Cursors.None;
            MainWindow.arrayView.currentOperation = CurrentOperation.insertingModule;
        }
Exemplo n.º 5
0
        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();
        }