using Metis.ParameterSet;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.Functionodel;
using PaintDotNet.File;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
namespace PaintDotNet.GeneralAnalysis
{
///
/// 图谱管理
///
internal class AtlasManagerDialog : PdnBaseForm
{
#region 控件
private GroupBox groupBox2;
private GroupBox groupBox3;
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private Button button5;
private TreeView treeView1;
private Panel panel1;
private Panel panel2;
private Label label1;
private RadioButton radioButton1;
private RadioButton radioButton4;
private RadioButton radioButton3;
private RadioButton radioButton2;
private IContainer components;
private ListView listView1;
private ImageList imageList1;
private GroupBox groupBox1;
private Label label2;
private TextBox textBox2;
private Label label3;
private TextBox textBox1;
private TextBox textBox3;
private Label label4;
private Button button6;
private Button button7;
#endregion
///
/// 组织的图谱数据集合
///
private List atlasModels = new List();
///
/// 新建/重命名窗口
///
private CreateNameDialog createNameDialog;
///
/// 图像大小
///
private int imgSize = 72;
///
/// 1新建标准 2新建级别
///
private int createType = 1;
///
/// 主控件
///
private AppWorkspace appWorkspace;
private GeneralAnalysisModel generalAnalysisModel = new GeneralAnalysisModel();
public AtlasManagerDialog(AppWorkspace appWorkspace)
{
this.appWorkspace = appWorkspace;
InitializeComponent();
InitializeLanguageText();
getLastData();
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.saveLastData);
}
///
/// Load事件
///
///
///
private void AtlasManagerDialog_Load(object sender, EventArgs e)
{
InitializeAtlasFile();
InitializeTreeView();
InitListViewData(null);
}
///
/// 初始化图谱数据
/// 读取图谱文件夹(Atlas文件夹)的xml文件并解析
///
private void InitializeAtlasFile()
{
atlasModels.Clear();
List fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Atlas\\");
XmlDocument xml = new XmlDocument();
foreach (string fileName in fileNames)
{
//Load Xml
xml.Load(Application.StartupPath + "\\Atlas\\" + fileName);
//读取根元素
XmlElement root = xml.DocumentElement;
//递归解析xml
RecursiveParsingXml(root, 1, "");
}
}
///
/// 初始化treeview
///
private void InitializeTreeView()
{
this.treeView1.ImageList = new ImageList();
this.treeView1.ImageList.Images.Add("Top", PdnResources.GetImageResource("Icons.SettingsIcon.png").Reference);
this.treeView1.ImageList.Images.Add("Catalog", PdnResources.GetImageResource("Icons.ImageFromDiskIcon.png").Reference);
this.treeView1.ImageList.Images.Add("Atlas", PdnResources.GetImageResource("Icons.AddNoiseEffect.png").Reference);
if (this.atlasModels.Count > 0)
{
for (int i = 0; i < this.atlasModels.Count; i++)
{
if(this.atlasModels[i].parentId.Equals(""))
{
TreeNode anime = new TreeNode();
anime.Tag = this.atlasModels[i].id;
anime.Text = this.atlasModels[i].name;
anime.Name = this.atlasModels[i].id;
anime.ImageKey = "Top";
this.treeView1.Nodes.Add(anime);
RecursiveData(anime);
}
}
}
}
///
/// 递归处理treeview数据
///
private void RecursiveData(TreeNode anime)
{
List models = this.atlasModels.FindAll(a => a.parentId.Equals(anime.Tag));
if (models!=null && models.Count > 0)
{
for (int i = 0; i < models.Count; i++)
{
TreeNode animeC = new TreeNode();
animeC.Tag = models[i].id;
animeC.Text = models[i].name;
animeC.Name = models[i].id;
animeC.ImageKey = (models[i].type==1) ? "Catalog" : "Atlas";
animeC.SelectedImageKey = (models[i].type == 1) ? "Catalog" : "Atlas";
RecursiveData(animeC);
anime.Nodes.Add(animeC);
}
}
}
///
/// 递归解析xml
///
/// 节点
/// 1根节点 2分类 3图铺
private void RecursiveParsingXml(XmlElement element, int level, string parentId)
{
if(level == 1)
{
AtlasModel model = new AtlasModel();
model.name = element.GetAttribute("Name");
model.id = Guid.NewGuid().ToString();
model.parentId = parentId;
model.path = model.name;
model.type = 0;
this.atlasModels.Add(model);
XmlNodeList list = element.FirstChild.ChildNodes;
if(list!=null && list.Count > 0)
{
foreach (XmlNode node in list)
{
RecursiveParsingXml((XmlElement)node, 2, model.id);
}
}
}
else if (level == 2)
{
AtlasModel model = new AtlasModel();
model.name = element.GetAttribute("Name");
model.id = Guid.NewGuid().ToString();
model.parentId = parentId;
model.path = model.name;
model.type = 1;
this.atlasModels.Add(model);
XmlNodeList list = element.FirstChild.ChildNodes;
if (list != null && list.Count > 0)
{
foreach (XmlNode node in list)
{
if (node.FirstChild.Name.Equals("MapImage"))
{
RecursiveParsingXml((XmlElement)node, 3, model.id);
}
else
{
RecursiveParsingXml((XmlElement)node, 2, model.id);
}
}
}
}
else if (level == 3)
{
AtlasModel model = new AtlasModel();
model.name = element.GetAttribute("Name");
model.id = Guid.NewGuid().ToString();
model.parentId = parentId;
model.path = model.name;
model.type = 2;
model.bitmap = DrawRulerHelper.Base64StringToImage(element.InnerText);
model.Value = element.GetAttribute("Value");
model.Zoom = element.GetAttribute("Zoom");
model.Dpi = element.GetAttribute("Dpi");
this.atlasModels.Add(model);
}
}
///
/// 新建图谱
///
///
///
private void button1_Click(object sender, EventArgs e)
{
if (this.treeView1.SelectedNode != null)
{
AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(this.treeView1.SelectedNode.Tag));
if (parent.type == 1)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = PdnResources.GetString("Menu.Theimagefile.Text")+"|*.jpg;*.png;*.bmp;";
dialog.InitialDirectory = Environment.CurrentDirectory;
dialog.ShowDialog();
if (dialog.FileName != String.Empty)
{
try
{
//创建图谱节点
AtlasModel model = new AtlasModel();
model.dirtyFlag = true;
model.name = Path.GetFileName(dialog.FileName);
model.id = Guid.NewGuid().ToString();
model.parentId = parent.id;
model.type = 2;
model.bitmap = new Bitmap(dialog.FileName);
this.atlasModels.Add(model);
//添加节点到treeview
TreeNode anime = new TreeNode();
anime.Tag = model.id;
anime.Text = model.name;
anime.Name = model.id;
anime.ImageKey = "Atlas";
anime.SelectedImageKey = "Atlas";
this.treeView1.SelectedNode.Nodes.Add(anime);
//标记顶级父级为dirtyFlag=true
RecursiveSetTopAtlasModelDirty(parent.id);
}
catch (Exception)
{
MessageBox.Show(PdnResources.GetString("Menu.Notanimagefile,pleasecheck.text")+"!");
}
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectlevel.text")+"!");
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectlevel.text")+"!");
}
}
///
/// 新建级别
///
///
///
private void button2_Click(object sender, EventArgs e)
{
if (this.treeView1.SelectedNode != null)
{
AtlasModel models = this.atlasModels.Find(a => a.id.Equals(this.treeView1.SelectedNode.Tag));
if (models.type == 2)
{
MessageBox.Show(PdnResources.GetString("Menu.Thelevelcandertheatlas.text"));
}
else
{
this.createType = 2;
this.createNameDialog = new CreateNameDialog(this);
this.createNameDialog.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newlevel.text");
this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
this.createNameDialog.ShowDialog();
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectstandardorlevel.text"));
}
}
///
/// 新建标准
///
///
///
private void button3_Click(object sender, EventArgs e)
{
this.createType = 1;
this.createNameDialog = new CreateNameDialog(this);
this.createNameDialog.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newstandard.text");
this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
this.createNameDialog.ShowDialog();
}
///
/// 新建标准/新建级别的名称
///
///
public override void GetCreateName(string name)
{
//新建标准
if (this.createType == 1)
{
AtlasModel model = new AtlasModel();
model.dirtyFlag = true;
model.name = name;
model.id = Guid.NewGuid().ToString();
model.parentId = "";
model.type = 0;
this.atlasModels.Add(model);
TreeNode anime = new TreeNode();
anime.Tag = model.id;
anime.Text = model.name + "*";
anime.Name = model.id;
anime.ImageKey = "Top";
this.treeView1.Nodes.Add(anime);
}
//新建级别
else if (this.createType == 2)
{
AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(this.treeView1.SelectedNode.Tag));
parent.dirtyFlag = true;
//设置顶级节点状态为被修改
RecursiveSetTopAtlasModelDirty(parent.id);
AtlasModel model = new AtlasModel();
model.dirtyFlag = true;
model.name = name;
model.id = Guid.NewGuid().ToString();
model.parentId = parent.id;
model.type = 1;
this.atlasModels.Add(model);
TreeNode anime = new TreeNode();
anime.Tag = model.id;
anime.Text = model.name;
anime.Name = model.id;
anime.ImageKey = "Catalog";
this.treeView1.SelectedNode.Nodes.Add(anime);
}
this.createNameDialog.Close();
}
///
/// 自动建立图谱
///
///
///
private void button4_Click(object sender, EventArgs e)
{
FolderBrowserDialog dilog = new FolderBrowserDialog();
dilog.Description = PdnResources.GetString("Menu.Pleaseelectfolder.Text");
if (dilog.ShowDialog() == DialogResult.OK)
{
DirectoryInfo folder = new DirectoryInfo(dilog.SelectedPath);
//生成guid
string guid = Guid.NewGuid().ToString();
//获取文件夹名称
string name = folder.Name;
//获取文件夹下的所有文件夹
DirectoryInfo[] folders = folder.GetDirectories();
//新建标准
AtlasModel model = new AtlasModel();
model.dirtyFlag = true;
model.name = name;
model.id = guid;
model.parentId = "";
model.type = 0;
this.atlasModels.Add(model);
TreeNode anime = new TreeNode();
anime.Tag = model.id;
anime.Text = model.name + "*";
anime.Name = model.id;
anime.ImageKey = "Top";
this.treeView1.Nodes.Add(anime);
//文件夹集合
if (folders.Length>0)
{
foreach (DirectoryInfo f in folders)
{
//新建分类
string guid1 = Guid.NewGuid().ToString();
AtlasModel model1 = new AtlasModel();
model1.dirtyFlag = true;
model1.name = f.Name;
model1.id = guid1;
model1.parentId = guid;
model1.type = 1;
this.atlasModels.Add(model1);
TreeNode anime1 = new TreeNode();
anime1.Tag = guid1;
anime1.Text = f.Name;
anime1.Name = guid1;
anime1.ImageKey = "Catalog";
anime.Nodes.Add(anime1);
//寻找文件夹下的所有图片
FileInfo[] files = f.GetFiles();
//图片集合
List models = new List();
if (files.Length > 0)
{
foreach (FileInfo file in files)
{
try
{
string guid2 = Guid.NewGuid().ToString();
AtlasModel amodel = new AtlasModel();
amodel.dirtyFlag = true;
amodel.name = Path.GetFileName(file.FullName);
amodel.id = guid2;
amodel.parentId = guid1;
amodel.type = 2;
amodel.bitmap = new Bitmap(file.FullName);
this.atlasModels.Add(amodel);
TreeNode anime2 = new TreeNode();
anime2.Tag = guid2;
anime2.Text = Path.GetFileName(file.FullName);
anime2.Name = guid2;
anime2.ImageKey = "Atlas";
anime2.SelectedImageKey = "Atlas";
anime1.Nodes.Add(anime2);
}
catch (Exception)
{
}
}
}
}
}
}
}
///
/// 初始化listview数据
///
private void InitListViewData(TreeNode node)
{
this.imageList1.Images.Clear();
this.listView1.Items.Clear();
if(node==null)
{
List lists = this.atlasModels.FindAll(a => a.bitmap != null);
for (int i = 0; i < lists.Count; i++)
{
this.imageList1.ImageSize = new System.Drawing.Size(imgSize, imgSize);
this.imageList1.Images.Add("img" + i, lists[i].bitmap);
this.listView1.Items.Add("", i);
this.listView1.Items[i].Tag = lists[i].id;
this.listView1.Items[i].ImageIndex = i;
this.listView1.Items[i].Text = lists[i].name;
}
}
else
{
AtlasModel model = this.atlasModels.Find(a => a.id.Equals(node.Tag.ToString()));
if (model != null)
{
if (model.type == 0 || model.type == 1)
{
List lists = this.atlasModels.FindAll(a => a.bitmap != null && a.parentId.Equals(model.id));
for (int i = 0; i < lists.Count; i++)
{
this.imageList1.ImageSize = new System.Drawing.Size(imgSize, imgSize);
this.imageList1.Images.Add("img" + i, lists[i].bitmap);
this.listView1.Items.Add("", i);
this.listView1.Items[i].Tag = lists[i].id;
this.listView1.Items[i].ImageIndex = i;
this.listView1.Items[i].Text = lists[i].name;
}
}
else if (model.type == 2)
{
this.imageList1.ImageSize = new System.Drawing.Size(imgSize, imgSize);
this.imageList1.Images.Add("img", model.bitmap);
this.listView1.Items.Add("", 0);
this.listView1.Items[0].Tag = model.id;
this.listView1.Items[0].ImageIndex = 0;
this.listView1.Items[0].Text = model.name;
}
}
}
}
///
/// treeview的节点点击事件
///
///
///
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node != null)
{
if (this.treeView1.SelectedNode != e.Node)
{
this.imageList1.Images.Clear();
this.listView1.Items.Clear();
this.treeView1.SelectedNode = e.Node;
this.InitListViewData(this.treeView1.SelectedNode);
}
else
{
this.treeView1.SelectedNode.Text = this.treeView1.SelectedNode.Text.Replace("*", "");
//this.treeView1.SelectedNode.BeginEdit();
}
}
}
///
/// 设置图像尺寸
///
///
///
private void SettingImageSize(object sender, EventArgs e)
{
if (radioButton1.Checked) imgSize = 72;
if (radioButton2.Checked) imgSize = 96;
if (radioButton3.Checked) imgSize = 128;
if (radioButton4.Checked) imgSize = 256;
InitListViewData(this.treeView1.SelectedNode);
}
///
/// 保存图谱
///
///
///
private void button5_Click(object sender, EventArgs e)
{
if(this.atlasModels!=null && this.atlasModels.Count > 0)
{
List models = this.atlasModels.FindAll(a=>a.type==0);
foreach (AtlasModel model in models)
{
if (model.dirtyFlag)
{
XmlDocument xmldoc = new XmlDocument();
XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
xmldoc.AppendChild(xmldec);
//添加根节点
XmlElement rootElement = xmldoc.CreateElement("StandardItem");
rootElement.SetAttribute("Name", model.name);
xmldoc.AppendChild(rootElement);
//添加根节点下的子节点元素
XmlElement classElement = xmldoc.CreateElement("ItemGroup");
rootElement.AppendChild(classElement);
//这里递归添加节点
RecursiveCreateXmlNode(xmldoc, classElement, model.id);
//保存文件
xmldoc.Save(Application.StartupPath + "\\Atlas\\" + model.name + ".xml");
//修改状态
model.dirtyFlag = true;
//修改treeview状态
TreeNode[] node = this.treeView1.Nodes.Find(model.id, false);
node[0].Text = node[0].Text.Replace("*", "");
}
}
}
}
///
/// 递归创建xml节点
///
private void RecursiveCreateXmlNode(XmlDocument xmldoc, XmlElement element, string parentId)
{
List models = this.atlasModels.FindAll(a => a.parentId.Equals(parentId));
if(models!=null && models.Count > 0)
{
foreach(AtlasModel model in models)
{
if(model.type==1)
{
XmlElement childElement = xmldoc.CreateElement("StandardItem");
childElement.SetAttribute("Name", model.name);
XmlElement groupElement = xmldoc.CreateElement("ItemGroup");
childElement.AppendChild(groupElement);
element.AppendChild(childElement);
RecursiveCreateXmlNode(xmldoc, groupElement, model.id);
}
else if(model.type == 2)
{
XmlElement childElement = xmldoc.CreateElement("StandardItem");
childElement.SetAttribute("Name", model.name);
childElement.SetAttribute("Value", model.Value);
childElement.SetAttribute("Zoom", model.Zoom);
childElement.SetAttribute("Dpi", model.Dpi);
XmlElement imageElement = xmldoc.CreateElement("MapImage");
imageElement.InnerText = DrawRulerHelper.ImgToBase64String(model.bitmap);
childElement.AppendChild(imageElement);
element.AppendChild(childElement);
}
}
}
}
///
/// 当图谱改变的时候,找到标准,标识为已改变
///
/// 分类的id,需要向上找
private void RecursiveSetTopAtlasModelDirty(string id)
{
AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(id));
if(parent!=null)
{
if (parent.type == 0)
{
TreeNode[] node = this.treeView1.Nodes.Find(id, false);
node[0].Text = node[0].Text.Replace("*", "") + "*";
parent.dirtyFlag = true;
this.treeView1.Refresh();
}
else
{
RecursiveSetTopAtlasModelDirty(parent.parentId);
}
}
}
///
/// 在用户编辑节点的文本后发生
///
///
///
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
if (!e.CancelEdit)
{
AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(e.Node.Tag));
if (!e.Node.IsEditing && (parent.dirtyFlag || (e.Label != null && !e.Label.Equals(e.Node.Text))))
{
parent.name = e.Label == null ? e.Node.Text.Replace("*", "") : e.Label.Replace("*", "");
e.Node.Text = parent.name;
RecursiveSetTopAtlasModelDirty(parent.id);
}
e.CancelEdit = true;
}
}
///
/// 绘制节点事件
///
///
///
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if ((e.State & TreeNodeStates.Selected) != 0)
{
//演示为绿底白字
e.Graphics.FillRectangle(Brushes.Green, e.Node.Bounds);
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
}
else
{
e.DrawDefault = true;
}
if ((e.State & TreeNodeStates.Focused) != 0)
{
using (Pen focusPen = new Pen(Color.Black))
{
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
Rectangle focusBounds = e.Node.Bounds;
focusBounds.Size = new System.Drawing.Size(focusBounds.Width - 1,
focusBounds.Height - 1);
e.Graphics.DrawRectangle(focusPen, focusBounds);
}
}
}
///
/// 删除节点
///
///
///
private void button7_Click(object sender, EventArgs e)
{
if (this.treeView1.SelectedNode != null)
{
if (MessageBox.Show(PdnResources.GetString("Menu.Confirmtodeleritwillbedeleted.text")+"?", PdnResources.GetString("Menu.Thisdeletioncannotberecovered.text"), MessageBoxButtons.YesNo) == DialogResult.Yes)
{
string id = this.treeView1.SelectedNode.Tag.ToString();
this.RecursiveSetTopAtlasModelDirty(id);
this.treeView1.Nodes.Remove(this.treeView1.SelectedNode);
//判断如果选择的是顶级节点,需要删除xml文件
AtlasModel model = this.atlasModels.Find(a => a.id.Equals(id));
if (model.type == 0)
{
try
{
System.IO.File.Delete(Application.StartupPath + "\\Atlas\\" + model.name + ".xml");
}
catch(Exception)
{
}
}
this.atlasModels.Remove(this.atlasModels.Find(a => a.id.Equals(id)));
this.InitListViewData(this.treeView1.SelectedNode);
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectagraphnode.text"));
}
}
///
/// 设置图谱级别、放大倍数、Dpi
///
///
///
private void button6_Click(object sender, EventArgs e)
{
if(string.IsNullOrWhiteSpace(this.textBox1.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseentertheatlaslevel.text"));
return;
}
if (string.IsNullOrWhiteSpace(this.textBox2.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
return;
}
if (string.IsNullOrWhiteSpace(this.textBox3.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.PleaseenterDpi.text"));
return;
}
if (this.listView1.SelectedItems.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectatleastoneatlas.text"));
return;
}
bool setTopAtlasModelDirty = false;
foreach (ListViewItem item in this.listView1.SelectedItems)
{
AtlasModel model = this.atlasModels.Find(a => a.id.Equals(item.Tag));
model.Value = this.textBox1.Text;
model.Zoom = this.textBox2.Text;
model.Dpi = this.textBox3.Text;
if (!setTopAtlasModelDirty)
{
RecursiveSetTopAtlasModelDirty(model.parentId);
setTopAtlasModelDirty = true;
}
}
MessageBox.Show(PdnResources.GetString("Menu.Setsuccessfully.text"));
}
private void InitializeLanguageText()
{
this.Text = PdnResources.GetString("Menu.GeneralAnalysis.MapManager.Text");
this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Atlaslevel.text") + ":";
this.label3.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
this.button6.Text = PdnResources.GetString("Menu.File.Save.Text");
this.label4.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Atlas.text") + "Dpi:";
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.button7.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Deletemap.text");
this.button5.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Savetheatlas.text");
this.label1.Text = PdnResources.GetString("Menu.imageviewmode.text") + ":";
this.button4.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Automaticmapping.text");
this.button3.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newstandard.text");
this.button2.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newlevel.text");
this.button1.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newatlas.text");
this.groupBox2.Text = PdnResources.GetString("Menu.Help.HelpTopics.Text");
this.groupBox3.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Atlasdata.text");
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button7 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.treeView1 = new System.Windows.Forms.TreeView();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.panel2 = new System.Windows.Forms.Panel();
this.button6 = new System.Windows.Forms.Button();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.listView1 = new System.Windows.Forms.ListView();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.panel2.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.button7);
this.groupBox1.Controls.Add(this.button5);
this.groupBox1.Controls.Add(this.radioButton4);
this.groupBox1.Controls.Add(this.radioButton3);
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Location = new System.Drawing.Point(13, 13);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(1065, 52);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// button7
//
this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button7.Location = new System.Drawing.Point(566, 19);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(75, 23);
this.button7.TabIndex = 10;
this.button7.Text = "删除图谱";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button5
//
this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button5.Location = new System.Drawing.Point(981, 18);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 9;
this.button5.Text = "保存图谱";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// radioButton4
//
this.radioButton4.AutoSize = true;
this.radioButton4.Location = new System.Drawing.Point(278, 23);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(65, 16);
this.radioButton4.TabIndex = 8;
this.radioButton4.TabStop = true;
this.radioButton4.Text = "256*256";
this.radioButton4.UseVisualStyleBackColor = true;
this.radioButton4.CheckedChanged += new System.EventHandler(this.SettingImageSize);
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(207, 23);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(65, 16);
this.radioButton3.TabIndex = 7;
this.radioButton3.TabStop = true;
this.radioButton3.Text = "128*128";
this.radioButton3.UseVisualStyleBackColor = true;
this.radioButton3.CheckedChanged += new System.EventHandler(this.SettingImageSize);
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(149, 23);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(53, 16);
this.radioButton2.TabIndex = 6;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "96*96";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.SettingImageSize);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(90, 23);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(53, 16);
this.radioButton1.TabIndex = 5;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "72*72";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.SettingImageSize);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 25);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(89, 12);
this.label1.TabIndex = 4;
this.label1.Text = "图片查看模式:";
//
// button4
//
this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button4.Location = new System.Drawing.Point(647, 19);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(85, 23);
this.button4.TabIndex = 3;
this.button4.Text = "自动建立图谱";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button3
//
this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button3.Location = new System.Drawing.Point(738, 19);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "新建标准";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Location = new System.Drawing.Point(819, 19);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "新建级别";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(900, 19);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "新建图谱";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox2.Controls.Add(this.treeView1);
this.groupBox2.Location = new System.Drawing.Point(13, 72);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(248, 432);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "目录";
//
// treeView1
//
this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
this.treeView1.HideSelection = false;
this.treeView1.LabelEdit = true;
this.treeView1.Location = new System.Drawing.Point(7, 21);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(235, 405);
this.treeView1.TabIndex = 0;
this.treeView1.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit);
this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView1_DrawNode);
this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.panel2);
this.groupBox3.Controls.Add(this.panel1);
this.groupBox3.Location = new System.Drawing.Point(267, 72);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(811, 432);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "图谱数据";
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.Controls.Add(this.button6);
this.panel2.Controls.Add(this.textBox3);
this.panel2.Controls.Add(this.label4);
this.panel2.Controls.Add(this.textBox2);
this.panel2.Controls.Add(this.label3);
this.panel2.Controls.Add(this.textBox1);
this.panel2.Controls.Add(this.label2);
this.panel2.Location = new System.Drawing.Point(7, 371);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(798, 55);
this.panel2.TabIndex = 1;
//
// button6
//
this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.button6.Location = new System.Drawing.Point(709, 16);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(75, 23);
this.button6.TabIndex = 6;
this.button6.Text = "保存";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(471, 17);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(100, 21);
this.textBox3.TabIndex = 5;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(406, 21);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(47, 12);
this.label4.TabIndex = 4;
this.label4.Text = "图谱Dpi";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(286, 17);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 21);
this.textBox2.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(215, 21);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 2;
this.label3.Text = "放大倍数:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 17);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(15, 21);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(65, 12);
this.label2.TabIndex = 0;
this.label2.Text = "图谱级别:";
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.Controls.Add(this.listView1);
this.panel1.Location = new System.Drawing.Point(7, 21);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(798, 344);
this.panel1.TabIndex = 0;
//
// listView1
//
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listView1.HideSelection = false;
this.listView1.LargeImageList = this.imageList1;
this.listView1.Location = new System.Drawing.Point(4, 4);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(791, 337);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick);
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// AtlasManagerDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.ClientSize = new System.Drawing.Size(1090, 516);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "AtlasManagerDialog";
this.Text = "图谱管理";
this.Load += new System.EventHandler(this.AtlasManagerDialog_Load);
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
///
/// listview内的图片点击事件,设置下面的等级、放大倍数、dpi
///
///
///
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
ListViewHitTestInfo info = this.listView1.HitTest(e.X, e.Y);
if(info!=null)
{
AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(info.Item.Tag));
if (parent != null)
{
this.textBox1.Text = parent.Value;
this.textBox2.Text = parent.Zoom;
this.textBox3.Text = parent.Dpi;
//查看大图
using (ImagePreviewDialog imagePreviewDialog = new ImagePreviewDialog(parent.bitmap, this.appWorkspace))
{
imagePreviewDialog.Text = parent.name;
imagePreviewDialog.StartPosition = FormStartPosition.CenterScreen;
imagePreviewDialog.ShowDialog();
}
}
}
/*
int clickIndex = -1;
if(this.listView1.Items.Count>0)
{
for (int i= 0; i e.X && rectangle.Y e.Y)
{
clickIndex = i;
break;
}
}
}
if (clickIndex>-1)
{
if (this.listView1.Items[clickIndex] != null)
{
AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(this.listView1.Items[clickIndex].Tag));
if (parent != null)
{
this.textBox1.Text = parent.Value;
this.textBox2.Text = parent.Zoom;
this.textBox3.Text = parent.Dpi;
//查看大图
using (ImagePreviewDialog imagePreviewDialog = new ImagePreviewDialog(parent.bitmap, this.appWorkspace))
{
imagePreviewDialog.Text = parent.name;
imagePreviewDialog.StartPosition = FormStartPosition.CenterScreen;
imagePreviewDialog.ShowDialog();
}
}
}
}*/
}
///
/// 获取上次操作参数
///
private void getLastData()
{
string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml";
if (!System.IO.File.Exists(filePath))
{
generalAnalysisModel = new GeneralAnalysisModel();
generalAnalysisModel.PolyphaseMutiAreaContentModels = new GeneralAnalysisModel.PolyphaseMutiAreaContentModel();
generalAnalysisModel.PolyphaseCounterAnalysisModels = new GeneralAnalysisModel.PolyphaseCounterAnalysisModel();
generalAnalysisModel.TwoPhaseScaleModels = new GeneralAnalysisModel.TwoPhaseScaleModel();
generalAnalysisModel.PolyphaseContentModels = new GeneralAnalysisModel.PolyphaseContentModel();
generalAnalysisModel.PolyphaseDistanceModels = new GeneralAnalysisModel.PolyphaseDistanceModel();
generalAnalysisModel.DebrisSelectionModels = new GeneralAnalysisModel.DebrisSelectionModel();
generalAnalysisModel.CountNumberAnalysisModels = new GeneralAnalysisModel.CountNumberAnalysisModel();
generalAnalysisModel.AtlasManagerModels = new GeneralAnalysisModel.AtlasManagerModel();
generalAnalysisModel.PolyphaseMutiAreaContentModels.hasUsed = false;
generalAnalysisModel.PolyphaseCounterAnalysisModels.hasUsed = false;
generalAnalysisModel.TwoPhaseScaleModels.hasUsed = false;
generalAnalysisModel.PolyphaseContentModels.hasUsed = false;
generalAnalysisModel.PolyphaseDistanceModels.hasUsed = false;
generalAnalysisModel.DebrisSelectionModels.hasUsed = false;
generalAnalysisModel.CountNumberAnalysisModels.hasUsed = false;
generalAnalysisModel.AtlasManagerModels.hasUsed = false;
string porosityInfoXml = XmlSerializeHelper.XmlSerialize(generalAnalysisModel);
Directory.CreateDirectory(Application.StartupPath + "\\Config\\Default\\ParameterSaving\\");
FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.CreateNew);
}
else
{
generalAnalysisModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
if (generalAnalysisModel.AtlasManagerModels == null)
{
generalAnalysisModel.AtlasManagerModels = new GeneralAnalysisModel.AtlasManagerModel();
}
if (generalAnalysisModel.AtlasManagerModels.hasUsed)
{
switch (generalAnalysisModel.AtlasManagerModels.parameter1) {
case 0:
radioButton1.Checked = true;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
break;
case 1:
radioButton1.Checked = true;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
break;
case 2:
radioButton1.Checked = false;
radioButton2.Checked = true;
radioButton3.Checked = false;
radioButton4.Checked = false;
break;
case 3:
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = true;
radioButton4.Checked = false;
break;
case 4:
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = true;
break;
}
textBox1.Text = generalAnalysisModel.AtlasManagerModels.parameter2;
textBox2.Text = generalAnalysisModel.AtlasManagerModels.parameter3;
textBox3.Text = generalAnalysisModel.AtlasManagerModels.parameter4;
}
}
}
///
/// 保存上次操作参数
///
private void saveLastData(object sender, EventArgs e)
{
if (generalAnalysisModel.AtlasManagerModels == null)
{
generalAnalysisModel.AtlasManagerModels = new GeneralAnalysisModel.AtlasManagerModel();
}
generalAnalysisModel.AtlasManagerModels.hasUsed = true;
if (radioButton1.Checked)
{
generalAnalysisModel.AtlasManagerModels.parameter1 = 1;
}
else if (radioButton2.Checked) {
generalAnalysisModel.AtlasManagerModels.parameter1 = 2;
}
else if (radioButton3.Checked)
{
generalAnalysisModel.AtlasManagerModels.parameter1 = 3;
}
else if (radioButton4.Checked)
{
generalAnalysisModel.AtlasManagerModels.parameter1 = 4;
}
generalAnalysisModel.AtlasManagerModels.parameter2 = textBox1.Text;
generalAnalysisModel.AtlasManagerModels.parameter3 = textBox2.Text;
generalAnalysisModel.AtlasManagerModels.parameter4 = textBox3.Text;
string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml";
string porosityInfoXml = XmlSerializeHelper.XmlSerialize(generalAnalysisModel);
FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.Create);
}
}
}