|
|
|
|
|
using GeoSigmaDrawLib;
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using TreeView = System.Windows.Forms.TreeView;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SmartWells
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class FormLayers : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
public List<string> SelectedNodes { get; set; }
|
|
|
|
|
|
private string layerData;
|
|
|
|
|
|
public FormLayers()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
public FormLayers(string layers):this()
|
|
|
|
|
|
{
|
|
|
|
|
|
layerData = layers;
|
|
|
|
|
|
}
|
|
|
|
|
|
private void FormLayers_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.CreateTree();
|
|
|
|
|
|
this.treeView1.ExpandAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
private void CreateTree()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.treeView1.BeginUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] saFullLayers = Regex.Split(layerData, "\r\n");
|
|
|
|
|
|
treeView1.Nodes.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
TreeNode tnRoot = new TreeNode("图层");
|
|
|
|
|
|
tnRoot.Name = tnRoot.Text;
|
|
|
|
|
|
treeView1.Nodes.Add(tnRoot);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (string strLine in saFullLayers)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strLine.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
string[] saLayers = Regex.Split(strLine, @"\\");
|
|
|
|
|
|
FillLayerTree(tnRoot, saLayers, 0, (LayerStatus)10);
|
|
|
|
|
|
}
|
|
|
|
|
|
tnRoot.EnsureVisible();
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
treeView1.EndUpdate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The FillLayerTree.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="tnRoot">The tnRoot<see cref="TreeNode"/>.</param>
|
|
|
|
|
|
/// <param name="saLayers">The saLayers.</param>
|
|
|
|
|
|
/// <param name="startIndex">The startIndex<see cref="int"/>.</param>
|
|
|
|
|
|
/// <param name="status">The status<see cref="LayerStatus"/>图层可见、可编辑状态</param>
|
|
|
|
|
|
private void FillLayerTree(TreeNode tnRoot, string[] saLayers, int startIndex, LayerStatus status)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = startIndex; i < saLayers.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string strLayer = saLayers[i];
|
|
|
|
|
|
if (strLayer.Equals("Layer:"))
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
int nFind = tnRoot.Nodes.IndexOfKey(strLayer);
|
|
|
|
|
|
if (nFind < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
MakeFullNode(tnRoot, saLayers, i, status);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
TreeNode tnFind = tnRoot.Nodes[nFind];
|
|
|
|
|
|
FillLayerTree(tnFind, saLayers, i + 1, status);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 生成节点及其子节点.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="curNode">.</param>
|
|
|
|
|
|
/// <param name="nodeNames">节点名称</param>
|
|
|
|
|
|
/// <param name="startIndex">起始索引</param>
|
|
|
|
|
|
/// <param name="status">The status<see cref="LayerStatus"/>.</param>
|
|
|
|
|
|
private void MakeFullNode(TreeNode curNode, string[] nodeNames, int startIndex, LayerStatus status)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (startIndex < nodeNames.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
TreeNode tnChild = new TreeNode(nodeNames[startIndex]);
|
|
|
|
|
|
tnChild.Name = tnChild.Text;
|
|
|
|
|
|
tnChild.ImageIndex = 0;
|
|
|
|
|
|
curNode.Nodes.Insert(0, tnChild);
|
|
|
|
|
|
if (startIndex == nodeNames.Length - 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//SetNodeStatus(tnChild, status);
|
|
|
|
|
|
}
|
|
|
|
|
|
MakeFullNode(tnChild, nodeNames, startIndex + 1, status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//只处理鼠标点击引起的状态变化
|
|
|
|
|
|
if (e.Action == TreeViewAction.ByMouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Node.ForeColor = Color.Black;
|
|
|
|
|
|
//更新子节点状态
|
|
|
|
|
|
UpdateChildNodes(e.Node);
|
|
|
|
|
|
//更新父节点状态
|
|
|
|
|
|
UpdateParents(e.Node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void UpdateChildNodes(TreeNode node)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (TreeNode child in node.Nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Checked = node.Checked;
|
|
|
|
|
|
child.ForeColor = Color.Black;
|
|
|
|
|
|
UpdateChildNodes(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateParents(TreeNode node)
|
|
|
|
|
|
{
|
|
|
|
|
|
var parent = node.Parent;
|
|
|
|
|
|
while (parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//设置父节点状态
|
|
|
|
|
|
SetNodeState(parent);
|
|
|
|
|
|
parent = parent.Parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void SetNodeState(TreeNode parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parent.Nodes.IsAllChecked())
|
|
|
|
|
|
{
|
|
|
|
|
|
//子节点全选中
|
|
|
|
|
|
parent.Checked = true;
|
|
|
|
|
|
parent.ForeColor = Color.Black;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (parent.Nodes.IsAllUnChecked())
|
|
|
|
|
|
{
|
|
|
|
|
|
//子节点全未选中
|
|
|
|
|
|
parent.Checked = false;
|
|
|
|
|
|
parent.ForeColor = Color.Black;
|
|
|
|
|
|
//还要判断子节点中是否有半选中状态
|
|
|
|
|
|
foreach (TreeNode child in parent.Nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (child.ForeColor == Color.Blue)
|
|
|
|
|
|
{
|
|
|
|
|
|
//用蓝色标记半选中状态
|
|
|
|
|
|
parent.ForeColor = Color.Blue;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//子节点有的选中有的未选中
|
|
|
|
|
|
parent.Checked = false;
|
|
|
|
|
|
parent.ForeColor = Color.Blue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Bounds.Location.X <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var treeview = sender as TreeView;
|
|
|
|
|
|
var brush = Brushes.Black;
|
|
|
|
|
|
if (e.Node.ForeColor == Color.Blue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var location = e.Node.Bounds.Location;
|
|
|
|
|
|
location.Offset(-11, 2);
|
|
|
|
|
|
var size = new Size(9, 9);
|
|
|
|
|
|
brush = Brushes.Blue;
|
|
|
|
|
|
e.Graphics.FillRectangle(brush, new Rectangle(location, size));
|
|
|
|
|
|
}
|
|
|
|
|
|
//绘制文本
|
|
|
|
|
|
e.Graphics.DrawString(e.Node.Text, treeview.Font, brush, e.Bounds.Left, e.Bounds.Top);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
treeView1.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectedNodes = new List<string>();
|
|
|
|
|
|
// Print each node.
|
|
|
|
|
|
foreach (TreeNode n in treeView1.Nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
TreeNode treeNode = n;
|
|
|
|
|
|
//Using a queue to store and process each node in the TreeView
|
|
|
|
|
|
Queue<TreeNode> staging = new Queue<TreeNode>();
|
|
|
|
|
|
staging.Enqueue(treeNode);
|
|
|
|
|
|
while (staging.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
treeNode = staging.Dequeue();
|
|
|
|
|
|
// Print the node.
|
|
|
|
|
|
//MessageBox.Show(treeNode.Text);
|
|
|
|
|
|
if (treeNode.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectedNodes.Add(treeNode.FullPath.Replace("图层\\",""));
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (TreeNode node in treeNode.Nodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
staging.Enqueue(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
static class TreeNodeCollectionExtern
|
|
|
|
|
|
{
|
|
|
|
|
|
public static bool IsAllChecked(this TreeNodeCollection treeNodeCollection)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (TreeNode node in treeNodeCollection)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (node.Checked == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool IsAllUnChecked(this TreeNodeCollection treeNodeCollection)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (TreeNode node in treeNodeCollection)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (node.Checked == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|