Пример #1
0
            /// <summary>
            /// Finishing procedure.
            /// </summary>
            public void Finish(IRasterModule m)
            {
                // Called as UpdateAsync() finish routine.

                // Elapsed time in milliseconds.
                sw.Stop();
                long elapsed = sw.ElapsedMilliseconds;

                // Optional output message.
                string message = DefaultRasterModule.UserBreak ? "User break!" : module.GetOutputMessage(0);

                form?.SetText(string.Format(CultureInfo.InvariantCulture, "Elapsed: {0:0.000}s{1}",
                                            0.001 * elapsed,
                                            string.IsNullOrEmpty(message) ? "" : $", {message}"));
                DefaultRasterModule.UserBreak = false;

                form?.UpdateTooltip();

                // Gui is already visible (if applicable). See Start()
                // !!! TODO: needs check ???
                //module.GuiWindow = true;

                // Update result image.
                Bitmap oi = module.GetOutput(0);

                // Finish the job on the Form side (and discard this RecomputeTask eventually).
                form?.SetImage(oi);
            }
Пример #2
0
 private void recomputeRequest(IRasterModule module)
 {
     if (module == currModuleSafe())
     {
         recompute(false);
     }
 }
Пример #3
0
        /// <summary>
        /// Called every time left mouse button is pressed WHILE Ctrl key is down
        /// and the current module has positive 'HasPixelUpdate'.
        /// </summary>
        /// <param name="x">Recomputed image coordinate in pixels.</param>
        /// <param name="y">Recomputed image coordinate in pixels.</param>
        private void recomputePixel(
            int x,
            int y)
        {
            if (running != null)
            {
                return;
            }

            IRasterModule module = currModule;

            if (module == null)
            {
                // Nothing to compute => set outputImage to null.

                setImage(ref outputImage, null);
                checkBoxResult.Checked = false;
                setSaveButton();

                // Display input image.
                displayImage();

                return;
            }

            running = new RecomputeTask(this, module);
            setRecomputeGui(true);
            running.Start(inputImage, textBoxParam.Text, x, y);
        }
Пример #4
0
 private void updateParamFromModule(IRasterModule module)
 {
     if (module == currModule)
     {
         textBoxParam.Text = currModule.Param;
     }
 }
Пример #5
0
        public HistogramForm(IRasterModule hModule)
        {
            module = hModule;

            InitializeComponent();
            Show();
        }
Пример #6
0
 public HistogramHsvForm(IRasterModule hModule)
 {
     module = hModule;
     InitializeComponent();
     this.FormClosed += HistogramForm_FormClosed;
     this.Resize     += HistogramForm_Resize;
     this.Paint      += HistogramForm_Paint;
 }
Пример #7
0
 private void deactivateRequest(IRasterModule module)
 {
     if (module == currModuleSafe())
     {
         int    selectedModule = comboBoxModule.SelectedIndex;
         string moduleName     = (string)comboBoxModule.Items[selectedModule];
         deactivateModule(moduleName);
     }
 }
Пример #8
0
        private void updateParamFromModule(IRasterModule module)
        {
            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            if (module == cm)
            {
                textBoxParam.Text = cm.Param;
            }
        }
Пример #9
0
        private void updateParamFromModule(IRasterModule module)
        {
            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            if (module == cm)
            {
                SetParamText(module.Param);
            }
        }
Пример #10
0
        private void buttonShowGUI_Click(object sender, EventArgs e)
        {
            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            if (cm != null)
            {
                cm.GuiWindow = true;
            }
        }
Пример #11
0
        private void pictureBoxMain_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            panAndZoom.OnKeyDown(e.KeyCode, ModifierKeys);

            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            // Module's key handling.
            if (cm != null &&
                cm.KeyDown != null)
            {
                cm.KeyDown(sender, new KeyEventArgs(e.KeyData));
            }
        }
Пример #12
0
        /// <summary>
        /// Catches mouse wheel movement for zoom in/out of image in picture box
        /// </summary>
        /// <param name="sender">Not needed</param>
        /// <param name="e">Needed for mouse wheel delta value and cursor location</param>
        private void pictureBoxMain_MouseWheel(object sender, MouseEventArgs e)
        {
            panAndZoom.OnMouseWheel(e, ModifierKeys);

            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            // Module's mouse handling.
            if (cm != null &&
                cm.MouseWheel != null)
            {
                cm.MouseWheel(sender, transformMouseEvent(e));
            }
        }
Пример #13
0
        private void deactivateModule(string moduleName)
        {
            // Deactivate the current module.
            currModule.GuiWindow = false;
            modules.Remove(moduleName);
            currModule = null;

            // Form elements.
            textBoxParam.Text       = "";
            tooltip                 = "";
            buttonModule.Text       = "Activate module";
            buttonRecompute.Enabled = false;
            buttonBreak.Enabled     = false;
            buttonShowGUI.Enabled   = false;
        }
Пример #14
0
        private void pictureBoxMain_MouseUp(object sender, MouseEventArgs e)
        {
            panAndZoom.OnMouseUp(out Cursor cursor);

            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            // Module's mouse handling.
            if (cm != null &&
                cm.MouseUp != null)
            {
                cm.MouseUp(sender, transformMouseEvent(e));
            }

            Cursor = cursor;
        }
Пример #15
0
        private void comboBoxModule_SelectedIndexChanged(object sender, EventArgs e)
        {
            int    selectedModule = comboBoxModule.SelectedIndex;
            string moduleName     = (string)comboBoxModule.Items[selectedModule];

            lock (runLock)
            {
                // Backup data of the old module.
                if (currModule != null)
                {
                    currModule.Param = textBoxParam.Text;
                }

                // Is the new selected module activated?
                bool activated = modules.ContainsKey(moduleName);

                if (activated)
                {
                    // Switch data for the new module.
                    currModule = modules[moduleName];

                    // Form.
                    textBoxParam.Text = currModule.Param;
                    UpdateTooltip();
                    buttonModule.Text = "Deactivate module";

                    currModule.GuiWindow = true;
                    if (currModule.InputSlots > 0 &&
                        inputImage != null)
                    {
                        currModule.SetInput(inputImage, 0);
                    }
                }
                else
                {
                    currModule = null;

                    // Form.
                    textBoxParam.Text = "";
                    tooltip           = "";
                    buttonModule.Text = "Activate module";
                }

                buttonRecompute.Enabled = activated;
                buttonBreak.Enabled     = false;
            }
        }
Пример #16
0
        private void pictureBoxMain_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBoxMain.Focus();

            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            bool   isCtrl         = (ModifierKeys & Keys.Control) > 0;
            bool   isModule       = cm != null;
            bool   hasPixelUpdate = isModule && cm.HasPixelUpdate;
            bool   leftButton     = e.Button == MouseButtons.Left;
            Cursor cursor;

            if (hasPixelUpdate &&
                isCtrl)
            {
                panAndZoom.OnMouseDown(e, recomputePixel, leftButton,
                                       ModifierKeys, out cursor);
            }
            else
            {
                panAndZoom.OnMouseDown(e, imageProbe, leftButton,
                                       ModifierKeys, out cursor);
            }

            // Warning for Ctrl+Mouse without currModule.HasPixelUpdate.
            if (isCtrl &&
                isModule &&
                !hasPixelUpdate)
            {
                SetText($"Current module '{ModuleRegistry.DecoratedModuleName(cm)}' has no PixelUpdate()");
            }

            // Module's mouse handling.
            if (isModule &&
                cm.MouseDown != null)
            {
                cm.MouseDown(sender, transformMouseEvent(e));
            }

            if (cursor != null)
            {
                Cursor = cursor;
            }
        }
Пример #17
0
        private void pictureBoxMain_MouseMove(object sender, MouseEventArgs e)
        {
            panAndZoom.OnMouseMove(e, imageProbe, e.Button == MouseButtons.Left, ModifierKeys, out Cursor cursor);

            // MT-safe currentModule.
            IRasterModule cm = currModuleSafe();

            // Module's mouse handling.
            if (cm != null &&
                cm.MouseMove != null)
            {
                cm.MouseMove(sender, transformMouseEvent(e));
            }

            if (cursor != null)
            {
                Cursor = cursor;
            }
        }
Пример #18
0
        private void buttonModule_Click(object sender, EventArgs e)
        {
            int    selectedModule = comboBoxModule.SelectedIndex;
            string moduleName     = (string)comboBoxModule.Items[selectedModule];

            // Is the selected module activated?
            bool activated = modules.ContainsKey(moduleName);

            if (activated)
            {
                // Deactivate the current module.
                deactivateModule(moduleName);
            }
            else
            {
                lock (runLock)
                {
                    // Activate the module.
                    currModule = modules[moduleName] = ModuleRegistry.CreateModule(moduleName);

                    // Notifications module -> main.
                    currModule.UpdateRequest     = recomputeRequest;
                    currModule.ParamUpdated      = updateParamFromModule;
                    currModule.DeactivateRequest = deactivateRequest;

                    // Form elements.
                    textBoxParam.Text = currModule.Param;
                    UpdateTooltip();
                    buttonModule.Text     = "Deactivate module";
                    buttonShowGUI.Enabled = true;

                    currModule.GuiWindow = true;
                    if (currModule.InputSlots > 0 &&
                        inputImage != null)
                    {
                        currModule.SetInput(inputImage);
                    }

                    buttonRecompute.Enabled = true;
                    buttonBreak.Enabled     = false;
                }
            }
        }
Пример #19
0
        public RoundedHistogramForm(IRasterModule hModule)
        {
            module = hModule;

            InitializeComponent();
        }
Пример #20
0
 /// <summary>
 /// Keep references to FormMain and the current module (to be sure).
 /// </summary>
 public RecomputeTask(FormMain f, IRasterModule m)
 {
     form   = f;
     module = m;
 }
Пример #21
0
        public FormHSV(IRasterModule hModule)
        {
            module = hModule;

            InitializeComponent();
        }