年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

549 lines
19 KiB

6 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Mask;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using KGIS.Plugin.LayerProperty.Interface;
namespace KGIS.Plugin.LayerProperty.View.UC_Controls
{
public class UCRasterRGBRenderer : XtraUserControl, IPropertyPage
{
private const string CONST_CHECK = "f_check";
private const string CONST_NAME = "f_name";
private const string CONST_BAND = "f_band";
private IContainer components;
private GridControl grdCtrlRGB;
private GridView grdViewRGB;
private GridColumn colUse;
private RepositoryItemCheckEdit repositoryItemCheckEdit1;
private GridColumn colBand;
private RepositoryItemComboBox repositoryItemComboBox1;
private GridColumn colChannel;
private CheckEdit chkDisplayBackground;
private TextEdit textEdit1;
private TextEdit textEdit2;
private TextEdit textEdit3;
private LabelControl labelControl1;
private ColorEdit colorEdit1;
private LabelControl labelControl2;
private ColorEdit colorEdit2;
private PanelControl panelControl1;
private DataTable m_RGBTable;
private IRasterLayer m_CurrentRasterLayer;
private IRasterRenderer m_CurrentRenderer;
private IRasterRGBRenderer m_RGBRenderer;
private bool hasInitTable;
private IPropertyPage m_UCRasterStretchSet;
private List<IPropertyPage> ucList;
public event System.EventHandler EditorChanged;
private bool isDirty;
public IRasterLayer CurrentRasterLayer
{
set
{
this.m_CurrentRasterLayer = value;
}
}
public IRasterRenderer CurrentRasterRenderer
{
get
{
return this.m_CurrentRenderer;
}
}
public bool IsPageDirty
{
get
{
return this.isDirty;
}
set
{
this.isDirty = value;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.grdCtrlRGB = new GridControl();
this.grdViewRGB = new GridView();
this.colUse = new GridColumn();
this.repositoryItemCheckEdit1 = new RepositoryItemCheckEdit();
this.colChannel = new GridColumn();
this.colBand = new GridColumn();
this.repositoryItemComboBox1 = new RepositoryItemComboBox();
this.chkDisplayBackground = new CheckEdit();
this.textEdit1 = new TextEdit();
this.textEdit2 = new TextEdit();
this.textEdit3 = new TextEdit();
this.labelControl1 = new LabelControl();
this.colorEdit1 = new ColorEdit();
this.labelControl2 = new LabelControl();
this.colorEdit2 = new ColorEdit();
this.panelControl1 = new PanelControl();
((ISupportInitialize)this.grdCtrlRGB).BeginInit();
((ISupportInitialize)this.grdViewRGB).BeginInit();
((ISupportInitialize)this.repositoryItemCheckEdit1).BeginInit();
((ISupportInitialize)this.repositoryItemComboBox1).BeginInit();
((ISupportInitialize)this.chkDisplayBackground.Properties).BeginInit();
((ISupportInitialize)this.textEdit1.Properties).BeginInit();
((ISupportInitialize)this.textEdit2.Properties).BeginInit();
((ISupportInitialize)this.textEdit3.Properties).BeginInit();
((ISupportInitialize)this.colorEdit1.Properties).BeginInit();
((ISupportInitialize)this.colorEdit2.Properties).BeginInit();
((ISupportInitialize)this.panelControl1).BeginInit();
base.SuspendLayout();
this.grdCtrlRGB.EmbeddedNavigator.Name = "";
this.grdCtrlRGB.Location = new Point(3, 4);
this.grdCtrlRGB.MainView = this.grdViewRGB;
this.grdCtrlRGB.Name = "grdCtrlRGB";
this.grdCtrlRGB.RepositoryItems.AddRange(new RepositoryItem[]
{
this.repositoryItemCheckEdit1,
this.repositoryItemComboBox1
});
this.grdCtrlRGB.Size = new Size(388, 130);
this.grdCtrlRGB.TabIndex = 0;
this.grdCtrlRGB.ViewCollection.AddRange(new BaseView[]
{
this.grdViewRGB
});
this.grdViewRGB.Columns.AddRange(new GridColumn[]
{
this.colUse,
this.colChannel,
this.colBand
});
this.grdViewRGB.GridControl = this.grdCtrlRGB;
this.grdViewRGB.Name = "grdViewRGB";
this.grdViewRGB.OptionsCustomization.AllowColumnMoving = false;
this.grdViewRGB.OptionsFilter.AllowFilterEditor = false;
this.grdViewRGB.OptionsMenu.EnableColumnMenu = false;
this.grdViewRGB.OptionsMenu.EnableFooterMenu = false;
this.grdViewRGB.OptionsMenu.EnableGroupPanelMenu = false;
this.grdViewRGB.OptionsSelection.InvertSelection = true;
this.grdViewRGB.OptionsView.ShowFilterPanelMode = ShowFilterPanelMode.Never;
this.grdViewRGB.OptionsView.ShowGroupPanel = false;
this.grdViewRGB.CellValueChanged += new CellValueChangedEventHandler(this.grdViewRGB_CellValueChanged);
this.colUse.Caption = "状态";
this.colUse.ColumnEdit = this.repositoryItemCheckEdit1;
this.colUse.Name = "colUse";
this.colUse.Visible = true;
this.colUse.VisibleIndex = 0;
this.colUse.Width = 67;
this.repositoryItemCheckEdit1.AutoHeight = false;
this.repositoryItemCheckEdit1.Name = "repositoryItemCheckEdit1";
this.colChannel.Caption = "频率";
this.colChannel.Name = "colChannel";
this.colChannel.OptionsColumn.AllowEdit = false;
this.colChannel.Visible = true;
this.colChannel.VisibleIndex = 1;
this.colChannel.Width = 59;
this.colBand.Caption = "波段";
this.colBand.ColumnEdit = this.repositoryItemComboBox1;
this.colBand.Name = "colBand";
this.colBand.Visible = true;
this.colBand.VisibleIndex = 2;
this.colBand.Width = 189;
this.repositoryItemComboBox1.AutoHeight = false;
this.repositoryItemComboBox1.Buttons.AddRange(new EditorButton[]
{
new EditorButton(ButtonPredefines.Combo)
});
this.repositoryItemComboBox1.Items.AddRange(new object[]
{
"Band_1",
"Band_2",
"Band_3"
});
this.repositoryItemComboBox1.Name = "repositoryItemComboBox1";
this.repositoryItemComboBox1.TextEditStyle = TextEditStyles.DisableTextEditor;
this.chkDisplayBackground.Location = new Point(16, 142);
this.chkDisplayBackground.Name = "chkDisplayBackground";
this.chkDisplayBackground.Properties.Caption = "背景色显示颜色(R,G,B):";
this.chkDisplayBackground.Size = new Size(160, 19);
this.chkDisplayBackground.TabIndex = 1;
this.chkDisplayBackground.CheckedChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.chkDisplayBackground.CheckStateChanged += new System.EventHandler(this.chkDisplayBackground_CheckStateChanged);
this.textEdit1.Enabled = false;
this.textEdit1.Location = new Point(182, 142);
this.textEdit1.Name = "textEdit1";
this.textEdit1.Properties.Mask.EditMask = "n";
this.textEdit1.Properties.Mask.MaskType = MaskType.Numeric;
this.textEdit1.Size = new Size(26, 21);
this.textEdit1.TabIndex = 2;
this.textEdit1.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.textEdit2.Enabled = false;
this.textEdit2.Location = new Point(217, 142);
this.textEdit2.Name = "textEdit2";
this.textEdit2.Properties.Mask.EditMask = "n";
this.textEdit2.Properties.Mask.MaskType = MaskType.Numeric;
this.textEdit2.Size = new Size(26, 21);
this.textEdit2.TabIndex = 2;
this.textEdit2.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.textEdit3.Enabled = false;
this.textEdit3.Location = new Point(249, 142);
this.textEdit3.Name = "textEdit3";
this.textEdit3.Properties.Mask.EditMask = "n";
this.textEdit3.Properties.Mask.MaskType = MaskType.Numeric;
this.textEdit3.Size = new Size(26, 21);
this.textEdit3.TabIndex = 2;
this.textEdit3.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.labelControl1.Location = new Point(281, 145);
this.labelControl1.Name = "labelControl1";
this.labelControl1.Size = new Size(12, 14);
this.labelControl1.TabIndex = 3;
this.labelControl1.Text = "为";
this.colorEdit1.EditValue = Color.Empty;
this.colorEdit1.Location = new Point(299, 142);
this.colorEdit1.Name = "colorEdit1";
this.colorEdit1.Properties.Buttons.AddRange(new EditorButton[]
{
new EditorButton(ButtonPredefines.Combo)
});
this.colorEdit1.Size = new Size(62, 21);
this.colorEdit1.TabIndex = 4;
this.colorEdit1.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.labelControl2.Location = new Point(218, 178);
this.labelControl2.Name = "labelControl2";
this.labelControl2.Size = new Size(75, 14);
this.labelControl2.TabIndex = 5;
this.labelControl2.Text = "显示Nodata为";
this.colorEdit2.EditValue = Color.Empty;
this.colorEdit2.Location = new Point(299, 175);
this.colorEdit2.Name = "colorEdit2";
this.colorEdit2.Properties.Buttons.AddRange(new EditorButton[]
{
new EditorButton(ButtonPredefines.Combo)
});
this.colorEdit2.Size = new Size(62, 21);
this.colorEdit2.TabIndex = 4;
this.colorEdit2.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.panelControl1.BorderStyle = BorderStyles.NoBorder;
this.panelControl1.Location = new Point(0, 204);
this.panelControl1.Name = "panelControl1";
this.panelControl1.Size = new Size(403, 296);
this.panelControl1.TabIndex = 6;
this.AutoScroll = true;
base.Controls.Add(this.panelControl1);
base.Controls.Add(this.labelControl2);
base.Controls.Add(this.colorEdit2);
base.Controls.Add(this.colorEdit1);
base.Controls.Add(this.labelControl1);
base.Controls.Add(this.textEdit3);
base.Controls.Add(this.textEdit2);
base.Controls.Add(this.textEdit1);
base.Controls.Add(this.chkDisplayBackground);
base.Controls.Add(this.grdCtrlRGB);
base.Name = "UCRasterRGBRenderer";
base.Size = new Size(409, 508);
((ISupportInitialize)this.grdCtrlRGB).EndInit();
((ISupportInitialize)this.grdViewRGB).EndInit();
((ISupportInitialize)this.repositoryItemCheckEdit1).EndInit();
((ISupportInitialize)this.repositoryItemComboBox1).EndInit();
((ISupportInitialize)this.chkDisplayBackground.Properties).EndInit();
((ISupportInitialize)this.textEdit1.Properties).EndInit();
((ISupportInitialize)this.textEdit2.Properties).EndInit();
((ISupportInitialize)this.textEdit3.Properties).EndInit();
((ISupportInitialize)this.colorEdit1.Properties).EndInit();
((ISupportInitialize)this.colorEdit2.Properties).EndInit();
((ISupportInitialize)this.panelControl1).EndInit();
base.ResumeLayout(false);
base.PerformLayout();
}
public UCRasterRGBRenderer()
{
this.InitializeComponent();
this.ucList = new List<IPropertyPage>();
this.repositoryItemComboBox1.Items.Clear();
this.repositoryItemComboBox1.Items.Add("Band_1");
this.repositoryItemComboBox1.Items.Add("Band_2");
this.repositoryItemComboBox1.Items.Add("Band_3");
}
private void InitTable()
{
this.m_RGBTable = new DataTable();
DataColumn dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.Boolean");
dataColumn.ColumnName = "f_check";
dataColumn.Caption = "f_check";
this.m_RGBTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.String");
dataColumn.ColumnName = "f_name";
dataColumn.Caption = "f_name";
this.m_RGBTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.String");
dataColumn.ColumnName = "f_band";
dataColumn.Caption = "f_band";
this.m_RGBTable.Columns.Add(dataColumn);
}
private void BindGrid()
{
this.grdCtrlRGB.BeginInit();
this.grdCtrlRGB.DataSource = this.m_RGBTable;
this.colBand.FieldName = "f_band";
this.colChannel.FieldName = "f_name";
this.colUse.FieldName = "f_check";
this.grdCtrlRGB.EndInit();
}
private void InitRowData(bool bp, string uBand, string uName, ref DataRow pRow)
{
pRow["f_check"] = bp;
pRow["f_band"] = uBand;
pRow["f_name"] = uName;
}
private void InitForm()
{
if (this.m_CurrentRasterLayer == null)
{
return;
}
this.m_RGBRenderer = (this.m_CurrentRasterLayer.Renderer as IRasterRGBRenderer);
this.m_CurrentRenderer = this.m_CurrentRasterLayer.Renderer;
this.AddRasterStretchSet();
this.GetColorInfo();
this.InitRGBTable();
}
private void InitRGBTable()
{
if (!this.hasInitTable)
{
this.InitTable();
this.BindGrid();
}
this.hasInitTable = true;
this.m_RGBTable.Rows.Clear();
DataRow row = null;
if (this.m_RGBRenderer == null)
{
this.m_RGBRenderer = new RasterRGBRendererClass();
row = this.m_RGBTable.NewRow();
this.InitRowData(true, this.GetBand(0), "Red", ref row);
this.m_RGBTable.Rows.Add(row);
row = null;
row = this.m_RGBTable.NewRow();
this.InitRowData(true, this.GetBand(1), "Green", ref row);
this.m_RGBTable.Rows.Add(row);
row = null;
row = this.m_RGBTable.NewRow();
this.InitRowData(true, this.GetBand(2), "Blue", ref row);
this.m_RGBTable.Rows.Add(row);
row = null;
}
else
{
row = this.m_RGBTable.NewRow();
this.InitRowData(this.m_RGBRenderer.UseRedBand, this.GetBand(this.m_RGBRenderer.RedBandIndex), "Red", ref row);
this.m_RGBTable.Rows.Add(row);
row = null;
row = this.m_RGBTable.NewRow();
this.InitRowData(this.m_RGBRenderer.UseGreenBand, this.GetBand(this.m_RGBRenderer.GreenBandIndex), "Green", ref row);
this.m_RGBTable.Rows.Add(row);
row = null;
row = this.m_RGBTable.NewRow();
this.InitRowData(this.m_RGBRenderer.UseBlueBand, this.GetBand(this.m_RGBRenderer.BlueBandIndex), "Blue", ref row);
this.m_RGBTable.Rows.Add(row);
row = null;
}
this.m_RGBTable.AcceptChanges();
}
private void AddRasterStretchSet()
{
if (this.m_UCRasterStretchSet == null)
{
this.m_UCRasterStretchSet = new UCRasterStretchSet();
}
this.m_UCRasterStretchSet.Dock = DockStyle.Fill;
this.m_UCRasterStretchSet.EditorChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.panelControl1.Controls.Add(this.m_UCRasterStretchSet as UserControl);
this.m_UCRasterStretchSet.InitUC(this.m_CurrentRasterLayer);
this.AddUc(this.m_UCRasterStretchSet);
}
private void GetColorInfo()
{
if (this.m_CurrentRenderer != null)
{
try
{
IRasterStretch2 rasterStretch = this.m_CurrentRenderer as IRasterStretch2;
this.chkDisplayBackground.Checked = rasterStretch.Background;
double[] array = rasterStretch.BackgroundValue as double[];
this.textEdit1.Text = array[0].ToString();
if (array.Length >= 2)
{
this.textEdit2.Text = array[1].ToString();
}
if (array.Length >= 3)
{
this.textEdit3.Text = array[2].ToString();
}
this.colorEdit1.Color = Converter.FromRGBColor(rasterStretch.BackgroundColor as IRgbColor);
IRasterDisplayProps rasterDisplayProps = this.m_CurrentRenderer as IRasterDisplayProps;
this.colorEdit2.Color = Converter.FromRGBColor(rasterDisplayProps.NoDataColor as IRgbColor);
}
catch
{
}
}
}
private void SetColorInfo()
{
if (this.m_CurrentRenderer != null)
{
try
{
IRasterStretch2 rasterStretch = this.m_CurrentRenderer as IRasterStretch2;
rasterStretch.Background = this.chkDisplayBackground.Checked;
IColor transparentColor = new RgbColorClass();
transparentColor.NullColor = true;
//处理栅格影像背景和nodata设置为透明
if (this.colorEdit1.Color.Name.Equals("Transparent", StringComparison.CurrentCultureIgnoreCase))
{
rasterStretch.BackgroundColor = transparentColor;
}
else
{
rasterStretch.BackgroundColor = Converter.ToRGBColor(this.colorEdit1.Color);
}
IRasterDisplayProps rasterDisplayProps = this.m_CurrentRenderer as IRasterDisplayProps;
if (this.colorEdit2.Color.Name.Equals("Transparent", StringComparison.CurrentCultureIgnoreCase))
{
rasterDisplayProps.NoDataColor = transparentColor;
}
else
{
rasterDisplayProps.NoDataColor = Converter.ToRGBColor(this.colorEdit2.Color);
}
}
catch
{
}
}
}
private void AddUc(IPropertyPage uc)
{
if (!this.ucList.Contains(uc))
{
this.ucList.Add(uc);
}
}
private int GetIndex(string band)
{
if (band != null)
{
if (band == "Band_1")
{
return 0;
}
if (band == "Band_2")
{
return 1;
}
}
return 2;
}
private string GetBand(int index)
{
switch (index)
{
case 0:
return "Band_1";
case 1:
return "Band_2";
default:
return "Band_3";
}
}
private void SetRGBRasterRenderer()
{
if (this.m_RGBTable.Rows.Count == 0)
{
return;
}
DataRow dataRow = this.m_RGBTable.Rows[0];
this.m_RGBRenderer.UseRedBand = Convert.ToBoolean(dataRow["f_check"]);
this.m_RGBRenderer.RedBandIndex = this.GetIndex(dataRow["f_band"].ToString());
dataRow = this.m_RGBTable.Rows[1];
this.m_RGBRenderer.UseGreenBand = Convert.ToBoolean(dataRow["f_check"]);
this.m_RGBRenderer.GreenBandIndex = this.GetIndex(dataRow["f_band"].ToString());
dataRow = this.m_RGBTable.Rows[2];
this.m_RGBRenderer.UseBlueBand = Convert.ToBoolean(dataRow["f_check"]);
this.m_RGBRenderer.BlueBandIndex = this.GetIndex(dataRow["f_band"].ToString());
this.m_CurrentRenderer = (this.m_RGBRenderer as IRasterRenderer);
this.m_CurrentRenderer.Update();
}
public void InitUC(object property)
{
this.m_CurrentRasterLayer = (property as IRasterLayer);
if (this.m_CurrentRasterLayer == null)
{
return;
}
IRasterRenderer renderer = this.m_CurrentRasterLayer.Renderer;
this.m_RGBRenderer = (renderer as IRasterRGBRenderer);
this.InitForm();
}
public bool CanWrite2Prop()
{
return true;
}
public void Write2Prop()
{
if (this.m_UCRasterStretchSet.CanWrite2Prop())
{
this.m_UCRasterStretchSet.Write2Prop();
}
this.SetRGBRasterRenderer();
this.SetColorInfo();
this.m_CurrentRasterLayer.Renderer = this.m_CurrentRenderer;
}
public void SetDefaultValue(object value)
{
this.InitUC(value);
}
private void InvokeEditValueChanged(object sender, System.EventArgs e)
{
if (this.EditorChanged != null)
{
this.EditorChanged(sender, e);
}
this.isDirty = true;
}
private void grdViewRGB_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
this.InvokeEditValueChanged(sender, e);
}
private void chkDisplayBackground_CheckStateChanged(object sender, System.EventArgs e)
{
this.textEdit1.Enabled = this.chkDisplayBackground.Checked;
this.textEdit2.Enabled = this.chkDisplayBackground.Checked;
this.textEdit3.Enabled = this.chkDisplayBackground.Checked;
}
}
}