Ejemplo n.º 1
0
        /// <summary>
        /// Loads the form and initializes controls.
        /// </summary>
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Set up the band list.
            dgvBands.AutoGenerateColumns =
                dgvHeaderAttributes.AutoGenerateColumns =
                    dgvEventLog.AutoGenerateColumns     =
                        false;
            dgvEventLog.DataSource = MessageLog.Events;

            // Add button to band list header for equalizing histograms on all bands.
            btnHistEqAll = new Button();
            Rectangle btnPos = dgvBands.GetCellDisplayRectangle(2, -1, true);

            btnHistEqAll.Text     = "";
            btnHistEqAll.Image    = ESRIBinaryViewer.Properties.Resources.HistEQ;
            btnHistEqAll.Size     = btnPos.Size;
            btnHistEqAll.Location = btnPos.Location;
            btnHistEqAll.Font     = new Font(btnHistEqAll.Font.FontFamily, 8);
            btnHistEqAll.Visible  = false;

            btnHistEqAll.Click += (o, a) => {
                addBackgroundOperation(
                    GraphicOperations.EqualizeHistogram(dataset.Bands),
                    "Equalizing histograms on all bands of the current dataset.",
                    (ps, pe) => {
                    dgvBands.Refresh();
                    updateRGBComposite();
                }
                    );
            };

            // Manually reposition & resize the button in the header...
            EventHandler eh = (o, a) => {
                Rectangle r = dgvBands.GetCellDisplayRectangle(2, -1, true);
                btnHistEqAll.Size     = r.Size;
                btnHistEqAll.Location = r.Location;
            };

            // ... on size change or data source change.
            dgvBands.SizeChanged       += eh;
            dgvBands.DataSourceChanged += eh;
            dgvBands.DataSourceChanged += (o, a) => { btnHistEqAll.Visible = true; };
            dgvBands.Controls.Add(btnHistEqAll);

            // Set up RGB band selection combo boxes.
            rgbCombos = new List <ToolStripComboBox>()
            {
                cmbR, cmbG, cmbB
            };
            rgbCombos.ForEach(i => {
                i.SelectedIndexChanged += (o, a) => updateRGBComposite();
                i.ComboBox.DataSource   = new BindingSource(bandList, "");
                i.SelectedIndex         = 0;
            });

            // Set up the zoom combo box in the status bar.
            var zoomItems = pbxDisplay.ZoomFactors.Select(
                f => {
                var i    = new ToolStripMenuItem(String.Format("{0:0}%", f * 100));
                i.Click += (o, a) => {
                    foreach (var mi in (from object obj in i.Owner.Items
                                        let mi = obj as ToolStripMenuItem
                                                 where mi != null
                                                 select mi))
                    {
                        mi.Checked = false;
                        if (mi.Text == "100%")
                        {
                            mi.Font    = new Font(mi.Font, FontStyle.Bold);
                            mi.Checked = true;
                        }
                    }
                    i.Checked = true;
                    pbxDisplay.CurrentZoom = ddnZoom.DropDownItems.IndexOf(i);
                };
                return(i);
            }
                ).ToArray();

            ddnZoom.DropDownItems.AddRange(zoomItems);

            // Hide the histogram panel.
            splDisplay.Panel2Collapsed = true;
            splDisplay.Panel2.Hide();

            // Set up the custom menu item for applying convolution filters.
            var convoItem = new ConvolutionFilterMenuItem();

            convoItem.FilterApplied += (k) => {
                addBackgroundOperation(
                    GraphicOperations.ApplyConvolutionFilter((Bitmap)pbxDisplay.Image, k),
                    "Applying convolution filter",
                    (ps, pe) => { pbxDisplay.Image = (Bitmap)pe.Result; }
                    );
            };
            mnuConvoFilter.DropDownItems.Add(convoItem);

            // Also set up the custom menu item for applying a median filter.
            var medianItem = new MedianFilterMenuItem();

            medianItem.FilterApplied += (s) => {
                addBackgroundOperation(
                    GraphicOperations.ApplyMedianFilter((Bitmap)pbxDisplay.Image, s),
                    "Applying median filter",
                    (ps, pe) => { pbxDisplay.Image = (Bitmap)pe.Result; }
                    );
            };
            mnuMedianFilter.DropDownItems.Add(medianItem);

            // Compute build timestamp from the assembly version number.
            var version       = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
            var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(
                                                                 TimeSpan.TicksPerDay * version.Build +
                                                                 TimeSpan.TicksPerSecond * 2 * version.Revision)
                                                             );

            // Print welcome banner to the message log.
            MessageLog.Add(String.Format("ESRIBinaryViewer {0}; built on {1}.", version, buildDateTime));
            MessageLog.Add("(C) GPLv3 2013 Barancsuk Ádám <*****@*****.**>");
        }