Example #1
0
 /// <summary>
 /// Registers the image loaded callback.
 /// </summary>
 /// <param name="cb">Callback function.</param>
 public void RegisterImageLoadedCallback(Preview.MyCallBack cb)
 {
     this.imageLoadedCallback = cb;
 }
Example #2
0
        /// <summary>
        /// Initializes the user inferface
        /// </summary>
        private void InitializeUI()
        {
            // restore last window size and location
            Location = new Point(
                Settings.Default.WindowLocationX,
                Settings.Default.WindowLocationY
            );

            Size = new Size(
                Settings.Default.WindowSizeWidth,
                Settings.Default.WindowSizeHeight
            );

            // set window preference
            Title = "BAIMP";

            // file menu
            var fileMenu = new MenuItem("_File");
            fileMenu.SubMenu = new Menu();

            MenuItem menuNew = new MenuItem("_New...");
            menuNew.Clicked += (object sender, EventArgs e) => project.NewDialog();
            fileMenu.SubMenu.Items.Add(menuNew);

            MenuItem menuOpen = new MenuItem("_Open...");
            menuOpen.Clicked += delegate {
                if (!project.OpenDialog() && !string.IsNullOrEmpty(project.ErrorMessage)) {
                    MessageDialog.ShowMessage ("Error while opening the file", project.ErrorMessage);
                    project.ErrorMessage = null;
                }
            };
            fileMenu.SubMenu.Items.Add(menuOpen);

            if (Settings.Default.LastOpenedProjects != null) {
                MenuItem menuLastOpened = new MenuItem("Recently opened");
                menuLastOpened.SubMenu = new Menu();
                fileMenu.SubMenu.Items.Add(menuLastOpened);

                for (int i = Settings.Default.LastOpenedProjects.Count-1; i >= 0; i--) {
                    string path = Settings.Default.LastOpenedProjects[i];

                    MenuItem menuLastOpenedi = new MenuItem(path);
                    menuLastOpenedi.Clicked += delegate(object sender, EventArgs e) {
                        if (!project.Open(path) && !string.IsNullOrEmpty(project.ErrorMessage)) {
                            MessageDialog.ShowMessage ("Error while opening the file", project.ErrorMessage);
                            project.ErrorMessage = null;
                        }
                    };

                    menuLastOpened.SubMenu.Items.Add(menuLastOpenedi);
                }
            }

            fileMenu.SubMenu.Items.Add(new SeparatorMenuItem());

            MenuItem menuImport = new MenuItem("_Import...");
            menuImport.Clicked += (object sender, EventArgs e) => project.ImportDialog();
            fileMenu.SubMenu.Items.Add(menuImport);

            MenuItem menuSave = new MenuItem("_Save");
            menuSave.Clicked += (object sender, EventArgs e) => SaveAll();
            fileMenu.SubMenu.Items.Add(menuSave);

            fileMenu.SubMenu.Items.Add(new SeparatorMenuItem());

            MenuItem menuClose = new MenuItem("_Exit");
            menuClose.Clicked += (object sender, EventArgs e) => Close();
            fileMenu.SubMenu.Items.Add(menuClose);

            // View menu
            MenuItem viewMenu = new MenuItem("_View");
            viewMenu.SubMenu = new Menu();
            RadioButtonMenuItemGroup viewRadioGroup = new RadioButtonMenuItemGroup();
            RadioButtonMenuItem menuViewOverview = new RadioButtonMenuItem("Overview");
            menuViewOverview.Checked = true;
            menuViewOverview.Group = viewRadioGroup;
            viewMenu.SubMenu.Items.Add(menuViewOverview);

            RadioButtonMenuItem menuViewPipeline = new RadioButtonMenuItem("Pipeline");
            menuViewPipeline.Group = menuViewOverview.Group;
            viewMenu.SubMenu.Items.Add(menuViewPipeline);

            menuViewOverview.Clicked += delegate {
                splitMain_Status.Remove(pipelineShelf);
                splitScan_Pipeline.Panel2.Content = pipelineShelf;
                splitMain_Status.PackStart(splitScan_Pipeline, true, true);
            };
            menuViewPipeline.Clicked += delegate {
                splitScan_Pipeline.Panel2.Content = null;
                splitMain_Status.Remove(splitScan_Pipeline);
                splitMain_Status.PackStart(pipelineShelf, true, true);
            };

            // Edit menu
            MenuItem editMenu = new MenuItem("_Edit");
            editMenu.SubMenu = new Menu();
            MenuItem menuWorksheetRename = new MenuItem("_Rename worksheet...");
            editMenu.SubMenu.Items.Add(menuWorksheetRename);
            menuWorksheetRename.Clicked += (object sender, EventArgs e) => pipelineController.RenameCurrentWorksheetDialog();

            // Pipeline menu
            MenuItem pipelineMenu = new MenuItem("_Pipeline");
            pipelineMenu.SubMenu = new Menu();

            MenuItem menuExecute = new MenuItem("_Execute");
            menuExecute.Clicked += (object sender, EventArgs e) => pipelineController.CurrentPipeline.Execute(project);
            pipelineMenu.SubMenu.Items.Add(menuExecute);

            pipelineMenu.SubMenu.Items.Add(new SeparatorMenuItem());

            MenuItem menuExport = new MenuItem("Export");
            menuExport.SubMenu = new Menu();
            pipelineMenu.SubMenu.Items.Add(menuExport);

            Type exporterType = typeof(BaseExporter);
            IEnumerable<Type> exporter = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes())
                .Where(t => t.BaseType == exporterType);

            foreach (Type export in exporter) {
                MenuItem ni = new MenuItem(string.Format("As {0}...", export.Name));
                ni.Tag = export.Name;
                menuExport.SubMenu.Items.Add(ni);
                var lExport = export;
                ni.Clicked += delegate(object sender, EventArgs e) {
                    MenuItem s = sender as MenuItem;

                    if (s != null) {
                        if (exporterList.ContainsKey(s.Tag.ToString())) {
                            exporterList[s.Tag.ToString()].ShowDialog(pipelineController.CurrentPipeline.Nodes);
                        } else {
                            BaseExporter instance =
                                Activator.CreateInstance(lExport, pipelineController.CurrentPipeline.PipelineName) as BaseExporter;
                            if (instance != null) {
                                exporterList[s.Tag.ToString()] = instance;
                                instance.ShowDialog(pipelineController.CurrentPipeline.Nodes);
                            }
                        }
                    }
                };
            }

            // Extras menu
            MenuItem extrasMenu = new MenuItem("E_xtras");
            extrasMenu.SubMenu = new Menu();
            MenuItem menuResetAllMasks = new MenuItem("_Reset all masks");
            menuResetAllMasks.Clicked += delegate {
                foreach (BaseScan scan in project.scanCollection) {
                    scan.Mask.ResetMask();
                }
            };
            MenuItem menuExportLog = new MenuItem("Export _logs");
            menuExportLog.Clicked += delegate {
                SaveFileDialog d = new SaveFileDialog("Export logs");
                if (d.Run()) {
                    string filename = d.FileName;
                    if (!string.IsNullOrEmpty(filename)) {
                        System.IO.File.WriteAllText(filename, Log.ToText());
                    }
                }
                d.Dispose();
            };

            extrasMenu.SubMenu.Items.Add(menuResetAllMasks);
            extrasMenu.SubMenu.Items.Add(menuExportLog);

            // main menu
            Menu menu = new Menu();
            menu.Items.Add(fileMenu);
            menu.Items.Add(viewMenu);
            menu.Items.Add(editMenu);
            menu.Items.Add(pipelineMenu);
            menu.Items.Add(extrasMenu);
            MainMenu = menu;

            // initialize preview widget
            preview = new Preview();

            // load tree view with all available files
            fileTree = new FileTreeView();
            VBox splitFileTreeSearch_FileTree = new VBox();
            splitFileTreeSearch_FileTree.PackStart(new FileTreeFilter(fileTree));
            splitFileTreeSearch_FileTree.PackStart(fileTree, true);

            // load pipeline controller
            pipelineShelf = new VBox();
            pipelineController = new PipelineController(project, pipelineShelf);

            splitFiletree_Preview = new HPaned();
            splitFiletree_Preview.Panel1.Content = splitFileTreeSearch_FileTree;
            splitFiletree_Preview.Panel1.Shrink = true;
            fileTree.HorizontalScrollPolicy = ScrollPolicy.Never;
            splitFiletree_Preview.Panel2.Content = preview;
            splitFiletree_Preview.Panel2.Resize = true;

            splitController_Preview = new VBox();
            //splitController_Preview.PackStart(controllbarShelf, false, false);
            splitController_Preview.PackEnd(splitFiletree_Preview, true, true);

            splitScan_Pipeline = new VPaned();
            splitScan_Pipeline.Panel1.Content = splitController_Preview;
            splitScan_Pipeline.Panel2.Content = pipelineShelf;
            splitScan_Pipeline.Panel2.Resize = true;

            splitMain_Status = new VBox();
            splitMain_Status.PackStart(splitScan_Pipeline, true, true);
            splitMain_Status.PackEnd(new StatusBar());

            Content = splitMain_Status;
        }