年度变更建库软件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.

603 lines
23 KiB

6 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using KGIS.Plugin.LayerProperty.Interface;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using System.Collections;
using KGIS.Plugin.LayerProperty.Utils;
using DevExpress.XtraGrid.Views.Base;
using ESRI.ArcGIS.Geodatabase;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Runtime.InteropServices;
using KGIS.Framework.Utils.Helper;
namespace KGIS.Plugin.LayerProperty.View.UC_Controls
{
public partial class UCSymbolMatch : XtraUserControl, IUCPropertyPageEx, IPropertyPage
{
private const string CONST_SYMBOL = "F_Symbol";
private const string CONST_VALUE = "F_Value";
private const string CONST_LABEL = "F_Label";
private const string CONST_BITMAP = "F_BITMAP";
private IFeatureLayer2 m_MatchLayer;
private DataTable m_SymbolTable;
private esriGeometryType GeometryType;
private IStyleGalleryClass m_SymbologyStyleClass;
private IUniqueValueRenderer m_LyrRender;
private ISymbol m_SelectedSymbol;
private DataRow m_SelectedRow;
private IRotationRenderer mRotationrenderer;
private ISymbol m_DefaultSymbol;
private Hashtable m_TempSymbols;
private IFeatureRenderer m_CurFeatureRenderer;
private FormPointRatation frmPointRatation;
private string m_ValueField;
private bool isDirty;
public event System.EventHandler EditorChanged;
public bool IsPageDirty
{
get
{
return this.isDirty;
}
set
{
this.isDirty = value;
}
}
public int Priority
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public string Title
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public UCSymbolMatch()
{
InitializeComponent();
}
public void InitUC(object layerProperty)
{
if (layerProperty == null)
{
return;
}
this.m_MatchLayer = (layerProperty as IFeatureLayer2);
if (this.m_TempSymbols == null)
{
this.m_TempSymbols = new Hashtable();
}
else
{
this.m_TempSymbols.Clear();
}
this.GeometryType = this.m_MatchLayer.ShapeType;
switch (this.GeometryType)
{
case esriGeometryType.esriGeometryPoint:
this.m_SymbologyStyleClass = new MarkerSymbolStyleGalleryClassClass();
break;
case esriGeometryType.esriGeometryPolyline:
this.m_SymbologyStyleClass = new LineSymbolStyleGalleryClassClass();
break;
case esriGeometryType.esriGeometryPolygon:
this.m_SymbologyStyleClass = new FillSymbolStyleGalleryClassClass();
break;
}
this.InitSymbolTable();
this.BindGrid();
this.m_CurFeatureRenderer = (layerProperty as IGeoFeatureLayer).Renderer;
this.m_LyrRender = (this.m_CurFeatureRenderer as IUniqueValueRenderer);
if (this.m_LyrRender == null)
{
this.m_LyrRender = new UniqueValueRendererClass();
this.InitDefaultRender();
Utils.Util.InitFieldList(ref this.cmbFields, this.m_MatchLayer.FeatureClass.Fields, "", false, false, true, false);
}
else
{
this.m_DefaultSymbol = this.m_LyrRender.DefaultSymbol;
this.m_ValueField = this.m_LyrRender.get_Field(0);
Utils.Util.InitFieldList(ref this.cmbFields, this.m_MatchLayer.FeatureClass.Fields, this.m_ValueField, false, false, true, false);
this.LoadDefaultRender();
}
this.RefreshDefaultSymbol();
}
public void Write2Prop()
{
try
{
(this.m_MatchLayer as IGeoFeatureLayer).Renderer = this.m_CurFeatureRenderer;
this.isDirty = false;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public bool CanWrite2Prop()
{
this.SetMatchSymbol();
return this.m_CurFeatureRenderer != null && this.isDirty;
}
public void SetDefaultValue(object value)
{
this.m_LyrRender = (value as IUniqueValueRenderer);
this.InitSymbolTable();
this.BindGrid();
this.LoadDefaultRender();
this.InvokeEditValueChanged(this, null);
}
private void InitSymbolTable()
{
this.m_SymbolTable = new DataTable();
DataColumn dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.Object");
dataColumn.ColumnName = "F_BITMAP";
dataColumn.Caption = "F_BITMAP";
this.m_SymbolTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.String");
dataColumn.ColumnName = "F_Value";
dataColumn.Caption = "F_Value";
this.m_SymbolTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.String");
dataColumn.ColumnName = "F_Label";
dataColumn.Caption = "F_Label";
this.m_SymbolTable.Columns.Add(dataColumn);
dataColumn = new DataColumn();
dataColumn.DataType = Type.GetType("System.Object");
dataColumn.ColumnName = "F_Symbol";
dataColumn.Caption = "F_Symbol";
this.m_SymbolTable.Columns.Add(dataColumn);
}
private void BindGrid()
{
this.grdSymbolCtrl.BeginInit();
this.grdSymbolCtrl.DataSource = this.m_SymbolTable;
this.colSymbol.FieldName = "F_BITMAP";
this.colName.FieldName = "F_Value";
this.colLabels.FieldName = "F_Label";
this.grdSymbolCtrl.EndInit();
}
private void InitDefaultRender()
{
this.m_DefaultSymbol = RenderUtil.GetDefaultSymbol(this.m_MatchLayer.FeatureClass.ShapeType);
}
private Hashtable GetAllSymbols(string path, string className)
{
IStyleGallery styleGallery = new ServerStyleGalleryClass();
Hashtable hashtable = new Hashtable();
IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;
styleGalleryStorage.AddFile(path);
IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items(className, path, null);
enumStyleGalleryItem.Reset();
for (IStyleGalleryItem styleGalleryItem = enumStyleGalleryItem.Next(); styleGalleryItem != null; styleGalleryItem = enumStyleGalleryItem.Next())
{
object item = styleGalleryItem.Item;
if (item is ISymbol)
{
ISymbol value = item as ISymbol;
string name = styleGalleryItem.Name;
try
{
hashtable.Add(name, value);
}
catch (Exception)
{
}
}
}
return hashtable;
}
private void InitRowData(Bitmap bp, string uValue, string uLabel, ISymbol symbol, ref DataRow pRow)
{
pRow["F_BITMAP"] = bp;
pRow["F_Value"] = uValue;
pRow["F_Label"] = uLabel;
pRow["F_Symbol"] = symbol;
}
private void SetMatchSymbol()
{
string text = "";
ItemInfo<IField, string> itemInfo = this.cmbFields.SelectedItem as ItemInfo<IField, string>;
if (itemInfo != null)
{
text = itemInfo.InnerValue.Name;
}
this.m_LyrRender.RemoveAllValues();
this.m_LyrRender.FieldCount = 1;
this.m_LyrRender.set_Field(0, text);
if (this.m_MatchLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint && this.mRotationrenderer != null)
{
this.m_LyrRender = (IUniqueValueRenderer)this.mRotationrenderer;
}
if (this.chkUseDefaultSymbol.Checked)
{
this.m_LyrRender.DefaultSymbol = this.m_DefaultSymbol;
this.m_LyrRender.UseDefaultSymbol = this.chkUseDefaultSymbol.Checked;
}
else
{
this.m_LyrRender.DefaultSymbol = null;
this.m_LyrRender.UseDefaultSymbol = false;
}
this.m_LyrRender.LookupStyleset = this.txtStyleFile.Text;
RenderUtil.SetUniqueValuesFromTable(this.m_LyrRender, text, this.m_SymbolTable);
this.m_CurFeatureRenderer = (this.m_LyrRender as IFeatureRenderer);
}
private void LoadDefaultRender()
{
try
{
this.m_TempSymbols.Clear();
string text = this.m_LyrRender.get_Field(0);
this.txtStyleFile.Text = this.m_LyrRender.LookupStyleset;
if (text != null)
{
Utils.Util.InitFieldList(ref this.cmbFields, this.m_MatchLayer.FeatureClass.Fields, text, false, false, true, false);
}
this.m_DefaultSymbol = this.m_LyrRender.DefaultSymbol;
this.chkUseDefaultSymbol.Checked = this.m_LyrRender.UseDefaultSymbol;//是否使用默认符号库初始化 王欢 2018-12-14
this.RefreshDefaultSymbol();
RenderUtil.SetUniqueValuesToTable(this.m_LyrRender, this.m_SymbologyStyleClass, this.m_SymbolTable);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private string GetFileExtent(string path)
{
int num = path.LastIndexOf('.');
return path.Substring(num + 1, path.Length - num - 1);
}
private void btnSelStyle_Click(object sender, System.EventArgs e)
{
object obj = RenderUtil.OpenGalleryPathSelector();
if (obj == null)
{
return;
}
if (obj is string)
{
this.txtStyleFile.Text = obj.ToString();
return;
}
IDoStyleGalleryPath doStyleGalleryPath = obj as IDoStyleGalleryPath;
if (doStyleGalleryPath != null)
{
this.txtStyleFile.Text = doStyleGalleryPath.Name;
this.txtStyleFile.Tag = doStyleGalleryPath;
}
}
private void btnDefaultSymbol_Click(object sender, System.EventArgs e)
{
try
{
IDoStyleGalleryItem doStyleGalleryItem = RenderUtil.OpenStyleSelector(this.GeometryType);
if (doStyleGalleryItem != null)
{
this.m_DefaultSymbol = (doStyleGalleryItem.Item.Item as ISymbol);
this.RefreshDefaultSymbol();
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private void btnMatch_Click(object sender, System.EventArgs e)
{
this.ControlsEnable(false);
try
{
if (this.m_MatchLayer == null)
{
return;
}
if (this.m_ValueField == "")
{
return;
}
if (this.txtStyleFile.Text.Trim().Length == 0)
{
MessageHelper.ShowTips("请选择符号库!");
this.ControlsEnable(true);
return;
}
this.m_SymbolTable.Rows.Clear();
string text = this.txtStyleFile.Text;
DataRow row = null;
string text2 = null;
bool flag = true;
bool flag2 = false;
IDisplayTable displayTable = (IDisplayTable)this.m_MatchLayer;
ICursor cursor = displayTable.DisplayTable.Search(null, false);
IDataStatistics dataStatistics = new DataStatisticsClass();
dataStatistics.Cursor = cursor;
dataStatistics.Field = this.m_ValueField;
dataStatistics.SampleRate = -1;
if (dataStatistics.UniqueValueCount >= 500 && !flag2)
{
if (MessageHelper.ShowYesNoAndTips("找到的唯一值个数大于500个,是否继续生成唯一值的完整列表?这会消耗较长时间。") == DialogResult.No)
{
flag = false;
}
flag2 = true;
}
IEnumerator uniqueValues = dataStatistics.UniqueValues;
uniqueValues.Reset();
string className = RenderUtil.GetClassName(this.m_MatchLayer);
if (this.txtStyleFile.Tag is IDoStyleGalleryPath)
{
IDoStyleGalleryPath path = this.txtStyleFile.Tag as IDoStyleGalleryPath;
this.m_TempSymbols = RenderUtil.GetAllSymbols(path, className);
}
else
{
this.m_TempSymbols = RenderUtil.GetAllSymbols(text, className);
}
int num = 0;
while (uniqueValues.MoveNext())
{
row = this.m_SymbolTable.NewRow();
try
{
text2 = Convert.ToString(uniqueValues.Current);
}
catch (Exception)
{
}
ISymbol symbol = this.m_TempSymbols[text2] as ISymbol;
if (this.chkMatched.Checked)
{
if (symbol != null)
{
//只显示匹配项 王欢 2018-12-14
//LoadDefaultRender();
///默认游标本身就是只有已匹配到的符号 不需要单独处理
Bitmap symbolBitMap = RenderUtil.GetSymbolBitMap(40, 20, this.m_SymbologyStyleClass, symbol);
this.InitRowData(symbolBitMap, text2, text2, symbol, ref row);
this.m_SymbolTable.Rows.Add(row);
if (dataStatistics.UniqueValueCount >= 500 && !flag2)
{
if (MessageHelper.ShowYesNoAndTips("找到的唯一值个数大于500个,是否继续生成唯一值的完整列表?这会消耗较长时间。") == DialogResult.No)
{
flag = false;
}
flag2 = true;
}
}
}
else
{
if (symbol == null)
{
symbol = this.m_DefaultSymbol;
this.m_TempSymbols.Add(text2, symbol);
}
Bitmap symbolBitMap = RenderUtil.GetSymbolBitMap(40, 20, this.m_SymbologyStyleClass, symbol);
this.InitRowData(symbolBitMap, text2, text2, symbol, ref row);
this.m_SymbolTable.Rows.Add(row);
if (dataStatistics.UniqueValueCount >= 500 && !flag2)
{
if (MessageHelper.ShowYesNoAndTips("找到的唯一值个数大于500个,是否继续生成唯一值的完整列表?这会消耗较长时间。") == DialogResult.No)
{
flag = false;
}
flag2 = true;
}
}
num++;
if (!flag && num >= 500)
{
break;
}
}
this.InvokeEditValueChanged(sender, e);
Marshal.ReleaseComObject(cursor);
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
this.ControlsEnable(true);
}
private void ControlsEnable(bool enable)
{
base.Enabled = enable;
}
private void grdSymbolView_MouseDown(object sender, MouseEventArgs e)
{
//this.m_TempSymbols如果为空 this.m_TempSymbols.count报错 王欢 2018-13-13
//if (this.m_TempSymbols.Count == 0)
//{
// return;
//}
if (this.m_TempSymbols != null)
{
GridHitInfo gridHitInfo = this.grdSymbolView.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
if (gridHitInfo.HitTest == GridHitTest.RowCell)
{
this.m_SelectedRow = this.grdSymbolView.GetDataRow(gridHitInfo.RowHandle);
this.m_SelectedSymbol = (this.m_SelectedRow["F_Symbol"] as ISymbol);
}
}
}
private void grdSymbolView_DoubleClick(object sender, System.EventArgs e)
{
try
{
if (this.m_SelectedSymbol != null)
{
if (this.m_MatchLayer != null)
{
ISymbol symbol = this.m_SelectedSymbol;
symbol = (RenderUtil.OpenStyleSelector(this.GeometryType, symbol) as ISymbol);
if (symbol != null)
{
this.m_SelectedRow["F_BITMAP"] = RenderUtil.GetSymbolBitMap(40, 20, this.m_SymbologyStyleClass, symbol);
this.m_SelectedRow["F_Symbol"] = symbol;
this.m_SymbolTable.AcceptChanges();
this.InvokeEditValueChanged(sender, e);
}
}
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private void btnDelAll_Click(object sender, System.EventArgs e)
{
this.m_SymbolTable.Rows.Clear();
this.m_SymbolTable.AcceptChanges();
this.InvokeEditValueChanged(sender, e);
}
private void btnDelOne_Click(object sender, System.EventArgs e)
{
if (this.m_SelectedRow == null)
{
return;
}
try
{
this.m_SymbolTable.Rows.Remove(this.m_SelectedRow);
this.InvokeEditValueChanged(sender, e);
}
catch (Exception)
{
}
}
private void cboFieldNames_SelectedIndexChanged(object sender, System.EventArgs e)
{
ItemInfo<IField, string> itemInfo = this.cmbFields.SelectedItem as ItemInfo<IField, string>;
if (itemInfo != null)
{
this.m_ValueField = itemInfo.InnerValue.Name;
}
this.m_SymbolTable.Rows.Clear();
this.m_SymbolTable.AcceptChanges();
}
private void RefreshDefaultSymbol()
{
this.picDefaultSymbol.Image = RenderUtil.GetSymbolBitMap(this.picDefaultSymbol.Width - 1, this.picDefaultSymbol.Height - 1, this.m_SymbologyStyleClass, this.m_DefaultSymbol);
}
private void InvokeEditValueChanged(object sender, System.EventArgs e)
{
if (this.EditorChanged != null)
{
this.EditorChanged(sender, e);
}
this.isDirty = true;
}
private void grdSymbolView_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
{
try
{
this.m_SelectedRow = this.grdSymbolView.GetDataRow(e.FocusedRowHandle);
if (this.m_SelectedRow != null)
{
this.btnDelOne.Enabled = true;
}
else
{
this.btnDelOne.Enabled = false;
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private void picDefaultSymbol_Click(object sender, System.EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
this.m_DefaultSymbol = (RenderUtil.OpenStyleSelector(this.GeometryType, this.m_DefaultSymbol) as ISymbol);
if (this.m_DefaultSymbol == null)
{
this.Cursor = Cursors.Default;
return;
}
this.RefreshDefaultSymbol();
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
this.Cursor = Cursors.Default;
}
private void btnRotateSet_Click(object sender, System.EventArgs e)
{
try
{
IGeoFeatureLayer geoFeatureLayer = this.m_MatchLayer as IGeoFeatureLayer;
IFeatureRenderer renderer = geoFeatureLayer.Renderer;
if (this.frmPointRatation == null)
{
this.frmPointRatation = new FormPointRatation();
}
if (this.frmPointRatation.Init(this.m_MatchLayer, renderer))
{
if (this.frmPointRatation.ShowDialog() == DialogResult.OK)
{
this.mRotationrenderer = this.frmPointRatation.RotationRenderer;
}
this.InvokeEditValueChanged(sender, e);
this.btnRotateSet.Focus();
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
public int Activate()
{
throw new Exception("The method or operation is not implemented.");
}
public void Deactivate()
{
throw new Exception("The method or operation is not implemented.");
}
public void Cancel()
{
throw new Exception("The method or operation is not implemented.");
}
private void grdSymbolView_RowCountChanged(object sender, System.EventArgs e)
{
this.btnDelAll.Enabled = Convert.ToBoolean(this.grdSymbolView.RowCount);
}
}
}