Inheritance: WeifenLuo.WinFormsUI.Docking.DockContent, INotifyPropertyChanged
Esempio n. 1
0
        public MainForm()
        {
            this.Font = SystemFonts.MessageBoxFont;
            InitializeComponent();

            SimulationHandler = new MySimulationHandler(backgroundWorker);
            SimulationHandler.StateChanged    += SimulationHandler_StateChanged;
            SimulationHandler.ProgressChanged += SimulationHandler_ProgressChanged;

            // must be created in advance to grab possible error logs
            ConsoleView = new ConsoleForm(this);

            var assemblyName = Assembly.GetExecutingAssembly().GetName();

            MyLog.INFO.WriteLine(assemblyName.Name + " version " + assemblyName.Version);

            try
            {
                SimulationHandler.Simulation = new MyLocalSimulation();
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occured when initializing simulation. Please make sure you have a supported CUDA-enabled graphics card and apropriate drivers." +
                                "Technical details: " + e.Message, "Simulation Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                // this way you do not have to tweak form Close and Closing events and it works even with any worker threads still running
                Environment.Exit(1);
            }

            MyConfiguration.SetupModuleSearchPath();
            MyConfiguration.ProcessCommandParams();

            try
            {
                MyConfiguration.LoadModules();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Fatal error occured during initialization", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            Documentation = new MyDocProvider();

            foreach (MyModuleConfig module in MyConfiguration.Modules)
            {
                Documentation.LoadXMLDoc(module.Assembly);
            }

            NodePropertyView = new NodePropertyForm(this);
            MemoryBlocksView = new MemoryBlocksForm(this);

            TaskView         = new TaskForm(this);
            TaskPropertyView = new TaskPropertyForm(this);

            GraphViews    = new Dictionary <MyNodeGroup, GraphLayoutForm>();
            ObserverViews = new List <ObserverForm>();

            ValidationView         = new ValidationForm(this);
            HelpView               = new NodeHelpForm(this);
            HelpView.StartPosition = FormStartPosition.CenterScreen;

            DebugView = new DebugForm(this);

            PopulateWorldList();
            CreateNewProject();
            CreateNetworkView();

            m_views = new List <DockContent>()
            {
                NetworkView, NodePropertyView, MemoryBlocksView, TaskView, TaskPropertyView, ConsoleView, ValidationView, DebugView, HelpView
            };

            foreach (DockContent view in m_views)
            {
                ToolStripMenuItem viewMenuItem = new ToolStripMenuItem(view.Text);
                viewMenuItem.Click += viewToolStripMenuItem_Click;
                viewMenuItem.Tag    = view;
                viewMenuItem.Name   = view.Text;

                viewToolStripMenuItem.DropDownItems.Add(viewMenuItem);
            }

            ((ToolStripMenuItem)viewToolStripMenuItem.DropDownItems.Find(HelpView.Text, false).First()).ShortcutKeys = Keys.F1;
            viewToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());

            ToolStripMenuItem resetViewsMenuItem = new ToolStripMenuItem("Reset Views Layout");

            resetViewsMenuItem.ShortcutKeys = Keys.Control | Keys.W;
            resetViewsMenuItem.Click       += resetViewsMenuItem_Click;

            viewToolStripMenuItem.DropDownItems.Add(resetViewsMenuItem);

            ToolStripMenuItem nodeSettingsMenuItem = new ToolStripMenuItem("Configure node selection...");

            nodeSettingsMenuItem.ShortcutKeys = Keys.Control | Keys.L;
            nodeSettingsMenuItem.Click       += nodeSettingsMenuItem_Click;

            viewToolStripMenuItem.DropDownItems.Add(nodeSettingsMenuItem);

            modeDropDownList.SelectedIndex = 0;

            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 0);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 10);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 20);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 50);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 100);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 500);

            timerItem_Click(timerToolStripSplitButton.DropDownItems[Properties.Settings.Default.StepDelay], EventArgs.Empty);

            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 0);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 20);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 100);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 500);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 1000);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 5000);

            observerTimerItem_Click(observerTimerToolButton.DropDownItems[Properties.Settings.Default.ObserverPeriod], EventArgs.Empty);

            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(typeof(MyWorkingNode))["DataFolder"];
            EditorAttribute    editor     = (EditorAttribute)descriptor.Attributes[typeof(EditorAttribute)];

            editor.GetType().GetField("typeName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(editor,
                                                                                                           typeof(MyFolderDialog).AssemblyQualifiedName);

            editor.GetType().GetField("baseTypeName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(editor,
                                                                                                               typeof(UITypeEditor).AssemblyQualifiedName);

            autosaveTextBox.Text = Properties.Settings.Default.AutosaveInterval.ToString();
            autosaveTextBox_Validating(this, new CancelEventArgs());

            autosaveButton.Checked = Properties.Settings.Default.AutosaveEnabled;
        }
Esempio n. 2
0
        public MainForm()
        {
            this.Font = SystemFonts.MessageBoxFont;
            InitializeComponent();

            MySimulation simulation = null;
            try
            {
                simulation = TypeMap.GetInstance<MySimulation>();
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occured when initializing simulation. Please make sure you have a supported CUDA-enabled graphics card and apropriate drivers." +
                        "Technical details: " + e.Message, "Simulation Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                // this way you do not have to tweak form Close and Closing events and it works even with any worker threads still running
                Environment.Exit(1);
            }

            SimulationHandler = new MySimulationHandler(simulation);
            SimulationHandler.StateChanged += SimulationHandler_StateChanged;
            SimulationHandler.ProgressChanged += SimulationHandler_ProgressChanged;
            SimulationHandler.SimulationStopped += SimulationHandler_SimulationStopped;

            // must be created in advance to grab possible error logs
            ConsoleView = new ConsoleForm(this);

            var assemblyName = Assembly.GetExecutingAssembly().GetName();
            MyLog.INFO.WriteLine(assemblyName.Name + " version " + assemblyName.Version);

            MyConfiguration.SetupModuleSearchPath();
            MyConfiguration.ProcessCommandParams();

            try
            {
                MyConfiguration.LoadModules();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Fatal error occured during initialization", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }

            UndoManager = new UndoManager(Settings.Default.UndoHistorySize);

            Documentation = new MyDocProvider();

            foreach (MyModuleConfig module in MyConfiguration.Modules)
            {
                Documentation.LoadXMLDoc(module.Assembly);
            }

            NodePropertyView = new NodePropertyForm(this);

            MemoryBlocksView = new MemoryBlocksForm(this);

            TaskView = new TaskForm(this);
            TaskPropertyView = new TaskPropertyForm(this);

            DashboardPropertyView = new DashboardPropertyForm(this);
            SimulationHandler.StateChanged += DashboardPropertyView.OnSimulationStateChanged;

            // Link the Task and Node property views to the dashboard's PropertyChanged.
            DashboardPropertyView.PropertyValueChanged += RefreshPropertyViews;

            // Link the Node and Task property views' PropertyChanged to the dashboard so that it can refresh etc.
            NodePropertyView.PropertyChanged += DashboardPropertyView.OnPropertyExternallyChanged;
            TaskPropertyView.PropertyChanged += DashboardPropertyView.OnPropertyExternallyChanged;
            TaskView.PropertyChanged += DashboardPropertyView.OnPropertyExternallyChanged;

            GraphViews = new Dictionary<MyNodeGroup, GraphLayoutForm>();
            TextEditors = new Dictionary<IScriptableNode, TextEditForm>();

            ObserverViews = new List<ObserverForm>();

            ValidationView = new ValidationForm(this, TypeMap.GetInstance<MyValidator>());
            HelpView = new NodeHelpForm(this) { StartPosition = FormStartPosition.CenterScreen };

            DebugView = new DebugForm(this);

            PopulateWorldList();
            CreateNewProject();
            CreateNetworkView();

            m_views = new List<DockContent>() { NetworkView, DashboardPropertyView, NodePropertyView, MemoryBlocksView, TaskView,
                TaskPropertyView, ConsoleView, ValidationView, DebugView, HelpView };

            foreach (var form in UIPlugins.GetBrainSimUIExtensions(this))
                m_views.Add(form);

            foreach (DockContent view in m_views)
            {
                ToolStripMenuItem viewMenuItem = new ToolStripMenuItem(view.Text);
                viewMenuItem.Click += viewToolStripMenuItem_Click;
                viewMenuItem.Tag = view;
                viewMenuItem.Name = view.Text;

                viewToolStripMenuItem.DropDownItems.Add(viewMenuItem);
            }

            ((ToolStripMenuItem)viewToolStripMenuItem.DropDownItems.Find(HelpView.Text, false).First()).ShortcutKeys = Keys.F1;
            viewToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());

            showHideObserversMenuItem = new ToolStripMenuItem("Show/Hide all observers");
            showHideObserversMenuItem.ShortcutKeys = Keys.Control | Keys.H;
            showHideObserversMenuItem.Click += showHideObserversMenuItem_Click;
            showHideObserversMenuItem.Checked = true;

            viewToolStripMenuItem.DropDownItems.Add(showHideObserversMenuItem);

            ToolStripMenuItem resetViewsMenuItem = new ToolStripMenuItem("Reset Views Layout");
            resetViewsMenuItem.ShortcutKeys = Keys.Control | Keys.W;
            resetViewsMenuItem.Click += resetViewsMenuItem_Click;

            viewToolStripMenuItem.DropDownItems.Add(resetViewsMenuItem);

            ToolStripMenuItem nodeSettingsMenuItem = new ToolStripMenuItem("Configure node selection...");
            nodeSettingsMenuItem.ShortcutKeys = Keys.Control | Keys.L;
            nodeSettingsMenuItem.Click += nodeSettingsMenuItem_Click;

            viewToolStripMenuItem.DropDownItems.Add(nodeSettingsMenuItem);

            modeDropDownList.SelectedIndex = 0;

            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 0);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 10);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 20);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 50);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 100);
            AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 500);

            timerItem_Click(timerToolStripSplitButton.DropDownItems[Settings.Default.StepDelay], EventArgs.Empty);

            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 0);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 20);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 100);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 500);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 1000);
            AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 5000);

            observerTimerItem_Click(observerTimerToolButton.DropDownItems[Settings.Default.ObserverPeriod], EventArgs.Empty);

            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(typeof(MyWorkingNode))["DataFolder"];
            EditorAttribute editor = (EditorAttribute)descriptor.Attributes[typeof(EditorAttribute)];

            editor.GetType().GetField("typeName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(editor,
                typeof(MyFolderDialog).AssemblyQualifiedName);

            editor.GetType().GetField("baseTypeName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(editor,
                typeof(UITypeEditor).AssemblyQualifiedName);

            autosaveTextBox.Text = Settings.Default.AutosaveInterval.ToString();
            autosaveTextBox_Validating(this, new CancelEventArgs());

            autosaveButton.Checked = Settings.Default.AutosaveEnabled;
        }