AtlasManagerDialog.cs 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. using Metis.ParameterSet;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.Base.Functionodel;
  4. using PaintDotNet.File;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Windows.Forms;
  11. using System.Xml;
  12. namespace PaintDotNet.GeneralAnalysis
  13. {
  14. /// <summary>
  15. /// 图谱管理
  16. /// </summary>
  17. internal class AtlasManagerDialog : PdnBaseForm
  18. {
  19. #region 控件
  20. private GroupBox groupBox2;
  21. private GroupBox groupBox3;
  22. private Button button1;
  23. private Button button2;
  24. private Button button3;
  25. private Button button4;
  26. private Button button5;
  27. private TreeView treeView1;
  28. private Panel panel1;
  29. private Panel panel2;
  30. private Label label1;
  31. private RadioButton radioButton1;
  32. private RadioButton radioButton4;
  33. private RadioButton radioButton3;
  34. private RadioButton radioButton2;
  35. private IContainer components;
  36. private ListView listView1;
  37. private ImageList imageList1;
  38. private GroupBox groupBox1;
  39. private Label label2;
  40. private TextBox textBox2;
  41. private Label label3;
  42. private TextBox textBox1;
  43. private TextBox textBox3;
  44. private Label label4;
  45. private Button button6;
  46. private Button button7;
  47. #endregion
  48. /// <summary>
  49. /// 组织的图谱数据集合
  50. /// </summary>
  51. private List<AtlasModel> atlasModels = new List<AtlasModel>();
  52. /// <summary>
  53. /// 新建/重命名窗口
  54. /// </summary>
  55. private CreateNameDialog createNameDialog;
  56. /// <summary>
  57. /// 图像大小
  58. /// </summary>
  59. private int imgSize = 72;
  60. /// <summary>
  61. /// 1新建标准 2新建级别
  62. /// </summary>
  63. private int createType = 1;
  64. /// <summary>
  65. /// 主控件
  66. /// </summary>
  67. private AppWorkspace appWorkspace;
  68. private GeneralAnalysisModel generalAnalysisModel = new GeneralAnalysisModel();
  69. public AtlasManagerDialog(AppWorkspace appWorkspace)
  70. {
  71. this.appWorkspace = appWorkspace;
  72. InitializeComponent();
  73. InitializeLanguageText();
  74. getLastData();
  75. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.saveLastData);
  76. }
  77. /// <summary>
  78. /// Load事件
  79. /// </summary>
  80. /// <param name="sender"></param>
  81. /// <param name="e"></param>
  82. private void AtlasManagerDialog_Load(object sender, EventArgs e)
  83. {
  84. InitializeAtlasFile();
  85. InitializeTreeView();
  86. InitListViewData(null);
  87. }
  88. /// <summary>
  89. /// 初始化图谱数据
  90. /// 读取图谱文件夹(Atlas文件夹)的xml文件并解析
  91. /// </summary>
  92. private void InitializeAtlasFile()
  93. {
  94. atlasModels.Clear();
  95. List<string> fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Atlas\\");
  96. XmlDocument xml = new XmlDocument();
  97. foreach (string fileName in fileNames)
  98. {
  99. //Load Xml
  100. xml.Load(Application.StartupPath + "\\Atlas\\" + fileName);
  101. //读取根元素
  102. XmlElement root = xml.DocumentElement;
  103. //递归解析xml
  104. RecursiveParsingXml(root, 1, "");
  105. }
  106. }
  107. /// <summary>
  108. /// 初始化treeview
  109. /// </summary>
  110. private void InitializeTreeView()
  111. {
  112. this.treeView1.ImageList = new ImageList();
  113. this.treeView1.ImageList.Images.Add("Top", PdnResources.GetImageResource("Icons.SettingsIcon.png").Reference);
  114. this.treeView1.ImageList.Images.Add("Catalog", PdnResources.GetImageResource("Icons.ImageFromDiskIcon.png").Reference);
  115. this.treeView1.ImageList.Images.Add("Atlas", PdnResources.GetImageResource("Icons.AddNoiseEffect.png").Reference);
  116. if (this.atlasModels.Count > 0)
  117. {
  118. for (int i = 0; i < this.atlasModels.Count; i++)
  119. {
  120. if(this.atlasModels[i].parentId.Equals(""))
  121. {
  122. TreeNode anime = new TreeNode();
  123. anime.Tag = this.atlasModels[i].id;
  124. anime.Text = this.atlasModels[i].name;
  125. anime.Name = this.atlasModels[i].id;
  126. anime.ImageKey = "Top";
  127. this.treeView1.Nodes.Add(anime);
  128. RecursiveData(anime);
  129. }
  130. }
  131. }
  132. }
  133. /// <summary>
  134. /// 递归处理treeview数据
  135. /// </summary>
  136. private void RecursiveData(TreeNode anime)
  137. {
  138. List<AtlasModel> models = this.atlasModels.FindAll(a => a.parentId.Equals(anime.Tag));
  139. if (models!=null && models.Count > 0)
  140. {
  141. for (int i = 0; i < models.Count; i++)
  142. {
  143. TreeNode animeC = new TreeNode();
  144. animeC.Tag = models[i].id;
  145. animeC.Text = models[i].name;
  146. animeC.Name = models[i].id;
  147. animeC.ImageKey = (models[i].type==1) ? "Catalog" : "Atlas";
  148. animeC.SelectedImageKey = (models[i].type == 1) ? "Catalog" : "Atlas";
  149. RecursiveData(animeC);
  150. anime.Nodes.Add(animeC);
  151. }
  152. }
  153. }
  154. /// <summary>
  155. /// 递归解析xml
  156. /// </summary>
  157. /// <param name="element">节点</param>
  158. /// <param name="level">1根节点 2分类 3图铺</param>
  159. private void RecursiveParsingXml(XmlElement element, int level, string parentId)
  160. {
  161. if(level == 1)
  162. {
  163. AtlasModel model = new AtlasModel();
  164. model.name = element.GetAttribute("Name");
  165. model.id = Guid.NewGuid().ToString();
  166. model.parentId = parentId;
  167. model.path = model.name;
  168. model.type = 0;
  169. this.atlasModels.Add(model);
  170. XmlNodeList list = element.FirstChild.ChildNodes;
  171. if(list!=null && list.Count > 0)
  172. {
  173. foreach (XmlNode node in list)
  174. {
  175. RecursiveParsingXml((XmlElement)node, 2, model.id);
  176. }
  177. }
  178. }
  179. else if (level == 2)
  180. {
  181. AtlasModel model = new AtlasModel();
  182. model.name = element.GetAttribute("Name");
  183. model.id = Guid.NewGuid().ToString();
  184. model.parentId = parentId;
  185. model.path = model.name;
  186. model.type = 1;
  187. this.atlasModels.Add(model);
  188. XmlNodeList list = element.FirstChild.ChildNodes;
  189. if (list != null && list.Count > 0)
  190. {
  191. foreach (XmlNode node in list)
  192. {
  193. if (node.FirstChild.Name.Equals("MapImage"))
  194. {
  195. RecursiveParsingXml((XmlElement)node, 3, model.id);
  196. }
  197. else
  198. {
  199. RecursiveParsingXml((XmlElement)node, 2, model.id);
  200. }
  201. }
  202. }
  203. }
  204. else if (level == 3)
  205. {
  206. AtlasModel model = new AtlasModel();
  207. model.name = element.GetAttribute("Name");
  208. model.id = Guid.NewGuid().ToString();
  209. model.parentId = parentId;
  210. model.path = model.name;
  211. model.type = 2;
  212. model.bitmap = DrawRulerHelper.Base64StringToImage(element.InnerText);
  213. model.Value = element.GetAttribute("Value");
  214. model.Zoom = element.GetAttribute("Zoom");
  215. model.Dpi = element.GetAttribute("Dpi");
  216. this.atlasModels.Add(model);
  217. }
  218. }
  219. /// <summary>
  220. /// 新建图谱
  221. /// </summary>
  222. /// <param name="sender"></param>
  223. /// <param name="e"></param>
  224. private void button1_Click(object sender, EventArgs e)
  225. {
  226. if (this.treeView1.SelectedNode != null)
  227. {
  228. AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(this.treeView1.SelectedNode.Tag));
  229. if (parent.type == 1)
  230. {
  231. OpenFileDialog dialog = new OpenFileDialog();
  232. dialog.Filter = PdnResources.GetString("Menu.Theimagefile.Text")+"|*.jpg;*.png;*.bmp;";
  233. dialog.InitialDirectory = Environment.CurrentDirectory;
  234. dialog.ShowDialog();
  235. if (dialog.FileName != String.Empty)
  236. {
  237. try
  238. {
  239. //创建图谱节点
  240. AtlasModel model = new AtlasModel();
  241. model.dirtyFlag = true;
  242. model.name = Path.GetFileName(dialog.FileName);
  243. model.id = Guid.NewGuid().ToString();
  244. model.parentId = parent.id;
  245. model.type = 2;
  246. model.bitmap = new Bitmap(dialog.FileName);
  247. this.atlasModels.Add(model);
  248. //添加节点到treeview
  249. TreeNode anime = new TreeNode();
  250. anime.Tag = model.id;
  251. anime.Text = model.name;
  252. anime.Name = model.id;
  253. anime.ImageKey = "Atlas";
  254. anime.SelectedImageKey = "Atlas";
  255. this.treeView1.SelectedNode.Nodes.Add(anime);
  256. //标记顶级父级为dirtyFlag=true
  257. RecursiveSetTopAtlasModelDirty(parent.id);
  258. }
  259. catch (Exception)
  260. {
  261. MessageBox.Show(PdnResources.GetString("Menu.Notanimagefile,pleasecheck.text")+"!");
  262. }
  263. }
  264. }
  265. else
  266. {
  267. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectlevel.text")+"!");
  268. }
  269. }
  270. else
  271. {
  272. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectlevel.text")+"!");
  273. }
  274. }
  275. /// <summary>
  276. /// 新建级别
  277. /// </summary>
  278. /// <param name="sender"></param>
  279. /// <param name="e"></param>
  280. private void button2_Click(object sender, EventArgs e)
  281. {
  282. if (this.treeView1.SelectedNode != null)
  283. {
  284. AtlasModel models = this.atlasModels.Find(a => a.id.Equals(this.treeView1.SelectedNode.Tag));
  285. if (models.type == 2)
  286. {
  287. MessageBox.Show(PdnResources.GetString("Menu.Thelevelcandertheatlas.text"));
  288. }
  289. else
  290. {
  291. this.createType = 2;
  292. this.createNameDialog = new CreateNameDialog(this);
  293. this.createNameDialog.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newlevel.text");
  294. this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
  295. this.createNameDialog.ShowDialog();
  296. }
  297. }
  298. else
  299. {
  300. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectstandardorlevel.text"));
  301. }
  302. }
  303. /// <summary>
  304. /// 新建标准
  305. /// </summary>
  306. /// <param name="sender"></param>
  307. /// <param name="e"></param>
  308. private void button3_Click(object sender, EventArgs e)
  309. {
  310. this.createType = 1;
  311. this.createNameDialog = new CreateNameDialog(this);
  312. this.createNameDialog.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newstandard.text");
  313. this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
  314. this.createNameDialog.ShowDialog();
  315. }
  316. /// <summary>
  317. /// 新建标准/新建级别的名称
  318. /// </summary>
  319. /// <param name="name"></param>
  320. public override void GetCreateName(string name)
  321. {
  322. //新建标准
  323. if (this.createType == 1)
  324. {
  325. AtlasModel model = new AtlasModel();
  326. model.dirtyFlag = true;
  327. model.name = name;
  328. model.id = Guid.NewGuid().ToString();
  329. model.parentId = "";
  330. model.type = 0;
  331. this.atlasModels.Add(model);
  332. TreeNode anime = new TreeNode();
  333. anime.Tag = model.id;
  334. anime.Text = model.name + "*";
  335. anime.Name = model.id;
  336. anime.ImageKey = "Top";
  337. this.treeView1.Nodes.Add(anime);
  338. }
  339. //新建级别
  340. else if (this.createType == 2)
  341. {
  342. AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(this.treeView1.SelectedNode.Tag));
  343. parent.dirtyFlag = true;
  344. //设置顶级节点状态为被修改
  345. RecursiveSetTopAtlasModelDirty(parent.id);
  346. AtlasModel model = new AtlasModel();
  347. model.dirtyFlag = true;
  348. model.name = name;
  349. model.id = Guid.NewGuid().ToString();
  350. model.parentId = parent.id;
  351. model.type = 1;
  352. this.atlasModels.Add(model);
  353. TreeNode anime = new TreeNode();
  354. anime.Tag = model.id;
  355. anime.Text = model.name;
  356. anime.Name = model.id;
  357. anime.ImageKey = "Catalog";
  358. this.treeView1.SelectedNode.Nodes.Add(anime);
  359. }
  360. this.createNameDialog.Close();
  361. }
  362. /// <summary>
  363. /// 自动建立图谱
  364. /// </summary>
  365. /// <param name="sender"></param>
  366. /// <param name="e"></param>
  367. private void button4_Click(object sender, EventArgs e)
  368. {
  369. FolderBrowserDialog dilog = new FolderBrowserDialog();
  370. dilog.Description = PdnResources.GetString("Menu.Pleaseelectfolder.Text");
  371. if (dilog.ShowDialog() == DialogResult.OK)
  372. {
  373. DirectoryInfo folder = new DirectoryInfo(dilog.SelectedPath);
  374. //生成guid
  375. string guid = Guid.NewGuid().ToString();
  376. //获取文件夹名称
  377. string name = folder.Name;
  378. //获取文件夹下的所有文件夹
  379. DirectoryInfo[] folders = folder.GetDirectories();
  380. //新建标准
  381. AtlasModel model = new AtlasModel();
  382. model.dirtyFlag = true;
  383. model.name = name;
  384. model.id = guid;
  385. model.parentId = "";
  386. model.type = 0;
  387. this.atlasModels.Add(model);
  388. TreeNode anime = new TreeNode();
  389. anime.Tag = model.id;
  390. anime.Text = model.name + "*";
  391. anime.Name = model.id;
  392. anime.ImageKey = "Top";
  393. this.treeView1.Nodes.Add(anime);
  394. //文件夹集合
  395. if (folders.Length>0)
  396. {
  397. foreach (DirectoryInfo f in folders)
  398. {
  399. //新建分类
  400. string guid1 = Guid.NewGuid().ToString();
  401. AtlasModel model1 = new AtlasModel();
  402. model1.dirtyFlag = true;
  403. model1.name = f.Name;
  404. model1.id = guid1;
  405. model1.parentId = guid;
  406. model1.type = 1;
  407. this.atlasModels.Add(model1);
  408. TreeNode anime1 = new TreeNode();
  409. anime1.Tag = guid1;
  410. anime1.Text = f.Name;
  411. anime1.Name = guid1;
  412. anime1.ImageKey = "Catalog";
  413. anime.Nodes.Add(anime1);
  414. //寻找文件夹下的所有图片
  415. FileInfo[] files = f.GetFiles();
  416. //图片集合
  417. List<AtlasModel> models = new List<AtlasModel>();
  418. if (files.Length > 0)
  419. {
  420. foreach (FileInfo file in files)
  421. {
  422. try
  423. {
  424. string guid2 = Guid.NewGuid().ToString();
  425. AtlasModel amodel = new AtlasModel();
  426. amodel.dirtyFlag = true;
  427. amodel.name = Path.GetFileName(file.FullName);
  428. amodel.id = guid2;
  429. amodel.parentId = guid1;
  430. amodel.type = 2;
  431. amodel.bitmap = new Bitmap(file.FullName);
  432. this.atlasModels.Add(amodel);
  433. TreeNode anime2 = new TreeNode();
  434. anime2.Tag = guid2;
  435. anime2.Text = Path.GetFileName(file.FullName);
  436. anime2.Name = guid2;
  437. anime2.ImageKey = "Atlas";
  438. anime2.SelectedImageKey = "Atlas";
  439. anime1.Nodes.Add(anime2);
  440. }
  441. catch (Exception)
  442. {
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. }
  450. /// <summary>
  451. /// 初始化listview数据
  452. /// </summary>
  453. private void InitListViewData(TreeNode node)
  454. {
  455. this.imageList1.Images.Clear();
  456. this.listView1.Items.Clear();
  457. if(node==null)
  458. {
  459. List<AtlasModel> lists = this.atlasModels.FindAll(a => a.bitmap != null);
  460. for (int i = 0; i < lists.Count; i++)
  461. {
  462. this.imageList1.ImageSize = new System.Drawing.Size(imgSize, imgSize);
  463. this.imageList1.Images.Add("img" + i, lists[i].bitmap);
  464. this.listView1.Items.Add("", i);
  465. this.listView1.Items[i].Tag = lists[i].id;
  466. this.listView1.Items[i].ImageIndex = i;
  467. this.listView1.Items[i].Text = lists[i].name;
  468. }
  469. }
  470. else
  471. {
  472. AtlasModel model = this.atlasModels.Find(a => a.id.Equals(node.Tag.ToString()));
  473. if (model != null)
  474. {
  475. if (model.type == 0 || model.type == 1)
  476. {
  477. List<AtlasModel> lists = this.atlasModels.FindAll(a => a.bitmap != null && a.parentId.Equals(model.id));
  478. for (int i = 0; i < lists.Count; i++)
  479. {
  480. this.imageList1.ImageSize = new System.Drawing.Size(imgSize, imgSize);
  481. this.imageList1.Images.Add("img" + i, lists[i].bitmap);
  482. this.listView1.Items.Add("", i);
  483. this.listView1.Items[i].Tag = lists[i].id;
  484. this.listView1.Items[i].ImageIndex = i;
  485. this.listView1.Items[i].Text = lists[i].name;
  486. }
  487. }
  488. else if (model.type == 2)
  489. {
  490. this.imageList1.ImageSize = new System.Drawing.Size(imgSize, imgSize);
  491. this.imageList1.Images.Add("img", model.bitmap);
  492. this.listView1.Items.Add("", 0);
  493. this.listView1.Items[0].Tag = model.id;
  494. this.listView1.Items[0].ImageIndex = 0;
  495. this.listView1.Items[0].Text = model.name;
  496. }
  497. }
  498. }
  499. }
  500. /// <summary>
  501. /// treeview的节点点击事件
  502. /// </summary>
  503. /// <param name="sender"></param>
  504. /// <param name="e"></param>
  505. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  506. {
  507. if (e.Node != null)
  508. {
  509. if (this.treeView1.SelectedNode != e.Node)
  510. {
  511. this.imageList1.Images.Clear();
  512. this.listView1.Items.Clear();
  513. this.treeView1.SelectedNode = e.Node;
  514. this.InitListViewData(this.treeView1.SelectedNode);
  515. }
  516. else
  517. {
  518. this.treeView1.SelectedNode.Text = this.treeView1.SelectedNode.Text.Replace("*", "");
  519. //this.treeView1.SelectedNode.BeginEdit();
  520. }
  521. }
  522. }
  523. /// <summary>
  524. /// 设置图像尺寸
  525. /// </summary>
  526. /// <param name="sender"></param>
  527. /// <param name="e"></param>
  528. private void SettingImageSize(object sender, EventArgs e)
  529. {
  530. if (radioButton1.Checked) imgSize = 72;
  531. if (radioButton2.Checked) imgSize = 96;
  532. if (radioButton3.Checked) imgSize = 128;
  533. if (radioButton4.Checked) imgSize = 256;
  534. InitListViewData(this.treeView1.SelectedNode);
  535. }
  536. /// <summary>
  537. /// 保存图谱
  538. /// </summary>
  539. /// <param name="sender"></param>
  540. /// <param name="e"></param>
  541. private void button5_Click(object sender, EventArgs e)
  542. {
  543. if(this.atlasModels!=null && this.atlasModels.Count > 0)
  544. {
  545. List<AtlasModel> models = this.atlasModels.FindAll(a=>a.type==0);
  546. foreach (AtlasModel model in models)
  547. {
  548. if (model.dirtyFlag)
  549. {
  550. XmlDocument xmldoc = new XmlDocument();
  551. XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
  552. xmldoc.AppendChild(xmldec);
  553. //添加根节点
  554. XmlElement rootElement = xmldoc.CreateElement("StandardItem");
  555. rootElement.SetAttribute("Name", model.name);
  556. xmldoc.AppendChild(rootElement);
  557. //添加根节点下的子节点元素
  558. XmlElement classElement = xmldoc.CreateElement("ItemGroup");
  559. rootElement.AppendChild(classElement);
  560. //这里递归添加节点
  561. RecursiveCreateXmlNode(xmldoc, classElement, model.id);
  562. //保存文件
  563. xmldoc.Save(Application.StartupPath + "\\Atlas\\" + model.name + ".xml");
  564. //修改状态
  565. model.dirtyFlag = true;
  566. //修改treeview状态
  567. TreeNode[] node = this.treeView1.Nodes.Find(model.id, false);
  568. node[0].Text = node[0].Text.Replace("*", "");
  569. }
  570. }
  571. }
  572. }
  573. /// <summary>
  574. /// 递归创建xml节点
  575. /// </summary>
  576. private void RecursiveCreateXmlNode(XmlDocument xmldoc, XmlElement element, string parentId)
  577. {
  578. List<AtlasModel> models = this.atlasModels.FindAll(a => a.parentId.Equals(parentId));
  579. if(models!=null && models.Count > 0)
  580. {
  581. foreach(AtlasModel model in models)
  582. {
  583. if(model.type==1)
  584. {
  585. XmlElement childElement = xmldoc.CreateElement("StandardItem");
  586. childElement.SetAttribute("Name", model.name);
  587. XmlElement groupElement = xmldoc.CreateElement("ItemGroup");
  588. childElement.AppendChild(groupElement);
  589. element.AppendChild(childElement);
  590. RecursiveCreateXmlNode(xmldoc, groupElement, model.id);
  591. }
  592. else if(model.type == 2)
  593. {
  594. XmlElement childElement = xmldoc.CreateElement("StandardItem");
  595. childElement.SetAttribute("Name", model.name);
  596. childElement.SetAttribute("Value", model.Value);
  597. childElement.SetAttribute("Zoom", model.Zoom);
  598. childElement.SetAttribute("Dpi", model.Dpi);
  599. XmlElement imageElement = xmldoc.CreateElement("MapImage");
  600. imageElement.InnerText = DrawRulerHelper.ImgToBase64String(model.bitmap);
  601. childElement.AppendChild(imageElement);
  602. element.AppendChild(childElement);
  603. }
  604. }
  605. }
  606. }
  607. /// <summary>
  608. /// 当图谱改变的时候,找到标准,标识为已改变
  609. /// </summary>
  610. /// <param name="id">分类的id,需要向上找</param>
  611. private void RecursiveSetTopAtlasModelDirty(string id)
  612. {
  613. AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(id));
  614. if(parent!=null)
  615. {
  616. if (parent.type == 0)
  617. {
  618. TreeNode[] node = this.treeView1.Nodes.Find(id, false);
  619. node[0].Text = node[0].Text.Replace("*", "") + "*";
  620. parent.dirtyFlag = true;
  621. this.treeView1.Refresh();
  622. }
  623. else
  624. {
  625. RecursiveSetTopAtlasModelDirty(parent.parentId);
  626. }
  627. }
  628. }
  629. /// <summary>
  630. /// 在用户编辑节点的文本后发生
  631. /// </summary>
  632. /// <param name="sender"></param>
  633. /// <param name="e"></param>
  634. private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
  635. {
  636. if (!e.CancelEdit)
  637. {
  638. AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(e.Node.Tag));
  639. if (!e.Node.IsEditing && (parent.dirtyFlag || (e.Label != null && !e.Label.Equals(e.Node.Text))))
  640. {
  641. parent.name = e.Label == null ? e.Node.Text.Replace("*", "") : e.Label.Replace("*", "");
  642. e.Node.Text = parent.name;
  643. RecursiveSetTopAtlasModelDirty(parent.id);
  644. }
  645. e.CancelEdit = true;
  646. }
  647. }
  648. /// <summary>
  649. /// 绘制节点事件
  650. /// </summary>
  651. /// <param name="sender"></param>
  652. /// <param name="e"></param>
  653. private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
  654. {
  655. if ((e.State & TreeNodeStates.Selected) != 0)
  656. {
  657. //演示为绿底白字
  658. e.Graphics.FillRectangle(Brushes.Green, e.Node.Bounds);
  659. Font nodeFont = e.Node.NodeFont;
  660. if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
  661. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
  662. }
  663. else
  664. {
  665. e.DrawDefault = true;
  666. }
  667. if ((e.State & TreeNodeStates.Focused) != 0)
  668. {
  669. using (Pen focusPen = new Pen(Color.Black))
  670. {
  671. focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  672. Rectangle focusBounds = e.Node.Bounds;
  673. focusBounds.Size = new System.Drawing.Size(focusBounds.Width - 1,
  674. focusBounds.Height - 1);
  675. e.Graphics.DrawRectangle(focusPen, focusBounds);
  676. }
  677. }
  678. }
  679. /// <summary>
  680. /// 删除节点
  681. /// </summary>
  682. /// <param name="sender"></param>
  683. /// <param name="e"></param>
  684. private void button7_Click(object sender, EventArgs e)
  685. {
  686. if (this.treeView1.SelectedNode != null)
  687. {
  688. if (MessageBox.Show(PdnResources.GetString("Menu.Confirmtodeleritwillbedeleted.text")+"?", PdnResources.GetString("Menu.Thisdeletioncannotberecovered.text"), MessageBoxButtons.YesNo) == DialogResult.Yes)
  689. {
  690. string id = this.treeView1.SelectedNode.Tag.ToString();
  691. this.RecursiveSetTopAtlasModelDirty(id);
  692. this.treeView1.Nodes.Remove(this.treeView1.SelectedNode);
  693. //判断如果选择的是顶级节点,需要删除xml文件
  694. AtlasModel model = this.atlasModels.Find(a => a.id.Equals(id));
  695. if (model.type == 0)
  696. {
  697. try
  698. {
  699. System.IO.File.Delete(Application.StartupPath + "\\Atlas\\" + model.name + ".xml");
  700. }
  701. catch(Exception)
  702. {
  703. }
  704. }
  705. this.atlasModels.Remove(this.atlasModels.Find(a => a.id.Equals(id)));
  706. this.InitListViewData(this.treeView1.SelectedNode);
  707. }
  708. }
  709. else
  710. {
  711. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectagraphnode.text"));
  712. }
  713. }
  714. /// <summary>
  715. /// 设置图谱级别、放大倍数、Dpi
  716. /// </summary>
  717. /// <param name="sender"></param>
  718. /// <param name="e"></param>
  719. private void button6_Click(object sender, EventArgs e)
  720. {
  721. if(string.IsNullOrWhiteSpace(this.textBox1.Text))
  722. {
  723. MessageBox.Show(PdnResources.GetString("Menu.Pleaseentertheatlaslevel.text"));
  724. return;
  725. }
  726. if (string.IsNullOrWhiteSpace(this.textBox2.Text))
  727. {
  728. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
  729. return;
  730. }
  731. if (string.IsNullOrWhiteSpace(this.textBox3.Text))
  732. {
  733. MessageBox.Show(PdnResources.GetString("Menu.PleaseenterDpi.text"));
  734. return;
  735. }
  736. if (this.listView1.SelectedItems.Count == 0)
  737. {
  738. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectatleastoneatlas.text"));
  739. return;
  740. }
  741. bool setTopAtlasModelDirty = false;
  742. foreach (ListViewItem item in this.listView1.SelectedItems)
  743. {
  744. AtlasModel model = this.atlasModels.Find(a => a.id.Equals(item.Tag));
  745. model.Value = this.textBox1.Text;
  746. model.Zoom = this.textBox2.Text;
  747. model.Dpi = this.textBox3.Text;
  748. if (!setTopAtlasModelDirty)
  749. {
  750. RecursiveSetTopAtlasModelDirty(model.parentId);
  751. setTopAtlasModelDirty = true;
  752. }
  753. }
  754. MessageBox.Show(PdnResources.GetString("Menu.Setsuccessfully.text"));
  755. }
  756. private void InitializeLanguageText()
  757. {
  758. this.Text = PdnResources.GetString("Menu.GeneralAnalysis.MapManager.Text");
  759. this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Atlaslevel.text") + ":";
  760. this.label3.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
  761. this.button6.Text = PdnResources.GetString("Menu.File.Save.Text");
  762. this.label4.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Atlas.text") + "Dpi:";
  763. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  764. this.button7.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Deletemap.text");
  765. this.button5.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Savetheatlas.text");
  766. this.label1.Text = PdnResources.GetString("Menu.imageviewmode.text") + ":";
  767. this.button4.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Automaticmapping.text");
  768. this.button3.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newstandard.text");
  769. this.button2.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newlevel.text");
  770. this.button1.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Newatlas.text");
  771. this.groupBox2.Text = PdnResources.GetString("Menu.Help.HelpTopics.Text");
  772. this.groupBox3.Text = PdnResources.GetString("Menu.Generalanalysis.atlasmanagement.Atlasdata.text");
  773. }
  774. private void InitializeComponent()
  775. {
  776. this.components = new System.ComponentModel.Container();
  777. this.groupBox1 = new System.Windows.Forms.GroupBox();
  778. this.button7 = new System.Windows.Forms.Button();
  779. this.button5 = new System.Windows.Forms.Button();
  780. this.radioButton4 = new System.Windows.Forms.RadioButton();
  781. this.radioButton3 = new System.Windows.Forms.RadioButton();
  782. this.radioButton2 = new System.Windows.Forms.RadioButton();
  783. this.radioButton1 = new System.Windows.Forms.RadioButton();
  784. this.label1 = new System.Windows.Forms.Label();
  785. this.button4 = new System.Windows.Forms.Button();
  786. this.button3 = new System.Windows.Forms.Button();
  787. this.button2 = new System.Windows.Forms.Button();
  788. this.button1 = new System.Windows.Forms.Button();
  789. this.groupBox2 = new System.Windows.Forms.GroupBox();
  790. this.treeView1 = new System.Windows.Forms.TreeView();
  791. this.groupBox3 = new System.Windows.Forms.GroupBox();
  792. this.panel2 = new System.Windows.Forms.Panel();
  793. this.button6 = new System.Windows.Forms.Button();
  794. this.textBox3 = new System.Windows.Forms.TextBox();
  795. this.label4 = new System.Windows.Forms.Label();
  796. this.textBox2 = new System.Windows.Forms.TextBox();
  797. this.label3 = new System.Windows.Forms.Label();
  798. this.textBox1 = new System.Windows.Forms.TextBox();
  799. this.label2 = new System.Windows.Forms.Label();
  800. this.panel1 = new System.Windows.Forms.Panel();
  801. this.listView1 = new System.Windows.Forms.ListView();
  802. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  803. this.groupBox1.SuspendLayout();
  804. this.groupBox2.SuspendLayout();
  805. this.groupBox3.SuspendLayout();
  806. this.panel2.SuspendLayout();
  807. this.panel1.SuspendLayout();
  808. this.SuspendLayout();
  809. //
  810. // groupBox1
  811. //
  812. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  813. | System.Windows.Forms.AnchorStyles.Right)));
  814. this.groupBox1.Controls.Add(this.button7);
  815. this.groupBox1.Controls.Add(this.button5);
  816. this.groupBox1.Controls.Add(this.radioButton4);
  817. this.groupBox1.Controls.Add(this.radioButton3);
  818. this.groupBox1.Controls.Add(this.radioButton2);
  819. this.groupBox1.Controls.Add(this.radioButton1);
  820. this.groupBox1.Controls.Add(this.label1);
  821. this.groupBox1.Controls.Add(this.button4);
  822. this.groupBox1.Controls.Add(this.button3);
  823. this.groupBox1.Controls.Add(this.button2);
  824. this.groupBox1.Controls.Add(this.button1);
  825. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  826. this.groupBox1.Name = "groupBox1";
  827. this.groupBox1.Size = new System.Drawing.Size(1065, 52);
  828. this.groupBox1.TabIndex = 0;
  829. this.groupBox1.TabStop = false;
  830. this.groupBox1.Text = "操作";
  831. //
  832. // button7
  833. //
  834. this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  835. this.button7.Location = new System.Drawing.Point(566, 19);
  836. this.button7.Name = "button7";
  837. this.button7.Size = new System.Drawing.Size(75, 23);
  838. this.button7.TabIndex = 10;
  839. this.button7.Text = "删除图谱";
  840. this.button7.UseVisualStyleBackColor = true;
  841. this.button7.Click += new System.EventHandler(this.button7_Click);
  842. //
  843. // button5
  844. //
  845. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  846. this.button5.Location = new System.Drawing.Point(981, 18);
  847. this.button5.Name = "button5";
  848. this.button5.Size = new System.Drawing.Size(75, 23);
  849. this.button5.TabIndex = 9;
  850. this.button5.Text = "保存图谱";
  851. this.button5.UseVisualStyleBackColor = true;
  852. this.button5.Click += new System.EventHandler(this.button5_Click);
  853. //
  854. // radioButton4
  855. //
  856. this.radioButton4.AutoSize = true;
  857. this.radioButton4.Location = new System.Drawing.Point(278, 23);
  858. this.radioButton4.Name = "radioButton4";
  859. this.radioButton4.Size = new System.Drawing.Size(65, 16);
  860. this.radioButton4.TabIndex = 8;
  861. this.radioButton4.TabStop = true;
  862. this.radioButton4.Text = "256*256";
  863. this.radioButton4.UseVisualStyleBackColor = true;
  864. this.radioButton4.CheckedChanged += new System.EventHandler(this.SettingImageSize);
  865. //
  866. // radioButton3
  867. //
  868. this.radioButton3.AutoSize = true;
  869. this.radioButton3.Location = new System.Drawing.Point(207, 23);
  870. this.radioButton3.Name = "radioButton3";
  871. this.radioButton3.Size = new System.Drawing.Size(65, 16);
  872. this.radioButton3.TabIndex = 7;
  873. this.radioButton3.TabStop = true;
  874. this.radioButton3.Text = "128*128";
  875. this.radioButton3.UseVisualStyleBackColor = true;
  876. this.radioButton3.CheckedChanged += new System.EventHandler(this.SettingImageSize);
  877. //
  878. // radioButton2
  879. //
  880. this.radioButton2.AutoSize = true;
  881. this.radioButton2.Location = new System.Drawing.Point(149, 23);
  882. this.radioButton2.Name = "radioButton2";
  883. this.radioButton2.Size = new System.Drawing.Size(53, 16);
  884. this.radioButton2.TabIndex = 6;
  885. this.radioButton2.TabStop = true;
  886. this.radioButton2.Text = "96*96";
  887. this.radioButton2.UseVisualStyleBackColor = true;
  888. this.radioButton2.CheckedChanged += new System.EventHandler(this.SettingImageSize);
  889. //
  890. // radioButton1
  891. //
  892. this.radioButton1.AutoSize = true;
  893. this.radioButton1.Checked = true;
  894. this.radioButton1.Location = new System.Drawing.Point(90, 23);
  895. this.radioButton1.Name = "radioButton1";
  896. this.radioButton1.Size = new System.Drawing.Size(53, 16);
  897. this.radioButton1.TabIndex = 5;
  898. this.radioButton1.TabStop = true;
  899. this.radioButton1.Text = "72*72";
  900. this.radioButton1.UseVisualStyleBackColor = true;
  901. this.radioButton1.CheckedChanged += new System.EventHandler(this.SettingImageSize);
  902. //
  903. // label1
  904. //
  905. this.label1.AutoSize = true;
  906. this.label1.Location = new System.Drawing.Point(6, 25);
  907. this.label1.Name = "label1";
  908. this.label1.Size = new System.Drawing.Size(89, 12);
  909. this.label1.TabIndex = 4;
  910. this.label1.Text = "图片查看模式:";
  911. //
  912. // button4
  913. //
  914. this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  915. this.button4.Location = new System.Drawing.Point(647, 19);
  916. this.button4.Name = "button4";
  917. this.button4.Size = new System.Drawing.Size(85, 23);
  918. this.button4.TabIndex = 3;
  919. this.button4.Text = "自动建立图谱";
  920. this.button4.UseVisualStyleBackColor = true;
  921. this.button4.Click += new System.EventHandler(this.button4_Click);
  922. //
  923. // button3
  924. //
  925. this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  926. this.button3.Location = new System.Drawing.Point(738, 19);
  927. this.button3.Name = "button3";
  928. this.button3.Size = new System.Drawing.Size(75, 23);
  929. this.button3.TabIndex = 2;
  930. this.button3.Text = "新建标准";
  931. this.button3.UseVisualStyleBackColor = true;
  932. this.button3.Click += new System.EventHandler(this.button3_Click);
  933. //
  934. // button2
  935. //
  936. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  937. this.button2.Location = new System.Drawing.Point(819, 19);
  938. this.button2.Name = "button2";
  939. this.button2.Size = new System.Drawing.Size(75, 23);
  940. this.button2.TabIndex = 1;
  941. this.button2.Text = "新建级别";
  942. this.button2.UseVisualStyleBackColor = true;
  943. this.button2.Click += new System.EventHandler(this.button2_Click);
  944. //
  945. // button1
  946. //
  947. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  948. this.button1.Location = new System.Drawing.Point(900, 19);
  949. this.button1.Name = "button1";
  950. this.button1.Size = new System.Drawing.Size(75, 23);
  951. this.button1.TabIndex = 0;
  952. this.button1.Text = "新建图谱";
  953. this.button1.UseVisualStyleBackColor = true;
  954. this.button1.Click += new System.EventHandler(this.button1_Click);
  955. //
  956. // groupBox2
  957. //
  958. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  959. | System.Windows.Forms.AnchorStyles.Left)));
  960. this.groupBox2.Controls.Add(this.treeView1);
  961. this.groupBox2.Location = new System.Drawing.Point(13, 72);
  962. this.groupBox2.Name = "groupBox2";
  963. this.groupBox2.Size = new System.Drawing.Size(248, 432);
  964. this.groupBox2.TabIndex = 1;
  965. this.groupBox2.TabStop = false;
  966. this.groupBox2.Text = "目录";
  967. //
  968. // treeView1
  969. //
  970. this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  971. | System.Windows.Forms.AnchorStyles.Left)
  972. | System.Windows.Forms.AnchorStyles.Right)));
  973. this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
  974. this.treeView1.HideSelection = false;
  975. this.treeView1.LabelEdit = true;
  976. this.treeView1.Location = new System.Drawing.Point(7, 21);
  977. this.treeView1.Name = "treeView1";
  978. this.treeView1.Size = new System.Drawing.Size(235, 405);
  979. this.treeView1.TabIndex = 0;
  980. this.treeView1.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit);
  981. this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView1_DrawNode);
  982. this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
  983. //
  984. // groupBox3
  985. //
  986. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  987. | System.Windows.Forms.AnchorStyles.Left)
  988. | System.Windows.Forms.AnchorStyles.Right)));
  989. this.groupBox3.Controls.Add(this.panel2);
  990. this.groupBox3.Controls.Add(this.panel1);
  991. this.groupBox3.Location = new System.Drawing.Point(267, 72);
  992. this.groupBox3.Name = "groupBox3";
  993. this.groupBox3.Size = new System.Drawing.Size(811, 432);
  994. this.groupBox3.TabIndex = 2;
  995. this.groupBox3.TabStop = false;
  996. this.groupBox3.Text = "图谱数据";
  997. //
  998. // panel2
  999. //
  1000. this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  1001. | System.Windows.Forms.AnchorStyles.Right)));
  1002. this.panel2.Controls.Add(this.button6);
  1003. this.panel2.Controls.Add(this.textBox3);
  1004. this.panel2.Controls.Add(this.label4);
  1005. this.panel2.Controls.Add(this.textBox2);
  1006. this.panel2.Controls.Add(this.label3);
  1007. this.panel2.Controls.Add(this.textBox1);
  1008. this.panel2.Controls.Add(this.label2);
  1009. this.panel2.Location = new System.Drawing.Point(7, 371);
  1010. this.panel2.Name = "panel2";
  1011. this.panel2.Size = new System.Drawing.Size(798, 55);
  1012. this.panel2.TabIndex = 1;
  1013. //
  1014. // button6
  1015. //
  1016. this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  1017. | System.Windows.Forms.AnchorStyles.Right)));
  1018. this.button6.Location = new System.Drawing.Point(709, 16);
  1019. this.button6.Name = "button6";
  1020. this.button6.Size = new System.Drawing.Size(75, 23);
  1021. this.button6.TabIndex = 6;
  1022. this.button6.Text = "保存";
  1023. this.button6.UseVisualStyleBackColor = true;
  1024. this.button6.Click += new System.EventHandler(this.button6_Click);
  1025. //
  1026. // textBox3
  1027. //
  1028. this.textBox3.Location = new System.Drawing.Point(471, 17);
  1029. this.textBox3.Name = "textBox3";
  1030. this.textBox3.Size = new System.Drawing.Size(100, 21);
  1031. this.textBox3.TabIndex = 5;
  1032. //
  1033. // label4
  1034. //
  1035. this.label4.AutoSize = true;
  1036. this.label4.Location = new System.Drawing.Point(406, 21);
  1037. this.label4.Name = "label4";
  1038. this.label4.Size = new System.Drawing.Size(47, 12);
  1039. this.label4.TabIndex = 4;
  1040. this.label4.Text = "图谱Dpi";
  1041. //
  1042. // textBox2
  1043. //
  1044. this.textBox2.Location = new System.Drawing.Point(286, 17);
  1045. this.textBox2.Name = "textBox2";
  1046. this.textBox2.Size = new System.Drawing.Size(100, 21);
  1047. this.textBox2.TabIndex = 3;
  1048. //
  1049. // label3
  1050. //
  1051. this.label3.AutoSize = true;
  1052. this.label3.Location = new System.Drawing.Point(215, 21);
  1053. this.label3.Name = "label3";
  1054. this.label3.Size = new System.Drawing.Size(65, 12);
  1055. this.label3.TabIndex = 2;
  1056. this.label3.Text = "放大倍数:";
  1057. //
  1058. // textBox1
  1059. //
  1060. this.textBox1.Location = new System.Drawing.Point(88, 17);
  1061. this.textBox1.Name = "textBox1";
  1062. this.textBox1.Size = new System.Drawing.Size(100, 21);
  1063. this.textBox1.TabIndex = 1;
  1064. //
  1065. // label2
  1066. //
  1067. this.label2.AutoSize = true;
  1068. this.label2.Location = new System.Drawing.Point(15, 21);
  1069. this.label2.Name = "label2";
  1070. this.label2.Size = new System.Drawing.Size(65, 12);
  1071. this.label2.TabIndex = 0;
  1072. this.label2.Text = "图谱级别:";
  1073. //
  1074. // panel1
  1075. //
  1076. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  1077. | System.Windows.Forms.AnchorStyles.Left)
  1078. | System.Windows.Forms.AnchorStyles.Right)));
  1079. this.panel1.Controls.Add(this.listView1);
  1080. this.panel1.Location = new System.Drawing.Point(7, 21);
  1081. this.panel1.Name = "panel1";
  1082. this.panel1.Size = new System.Drawing.Size(798, 344);
  1083. this.panel1.TabIndex = 0;
  1084. //
  1085. // listView1
  1086. //
  1087. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  1088. | System.Windows.Forms.AnchorStyles.Left)
  1089. | System.Windows.Forms.AnchorStyles.Right)));
  1090. this.listView1.HideSelection = false;
  1091. this.listView1.LargeImageList = this.imageList1;
  1092. this.listView1.Location = new System.Drawing.Point(4, 4);
  1093. this.listView1.Name = "listView1";
  1094. this.listView1.Size = new System.Drawing.Size(791, 337);
  1095. this.listView1.TabIndex = 0;
  1096. this.listView1.UseCompatibleStateImageBehavior = false;
  1097. this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick);
  1098. //
  1099. // imageList1
  1100. //
  1101. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  1102. this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
  1103. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  1104. //
  1105. // AtlasManagerDialog
  1106. //
  1107. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  1108. this.ClientSize = new System.Drawing.Size(1090, 516);
  1109. this.Controls.Add(this.groupBox3);
  1110. this.Controls.Add(this.groupBox2);
  1111. this.Controls.Add(this.groupBox1);
  1112. this.Name = "AtlasManagerDialog";
  1113. this.Text = "图谱管理";
  1114. this.Load += new System.EventHandler(this.AtlasManagerDialog_Load);
  1115. this.Controls.SetChildIndex(this.groupBox1, 0);
  1116. this.Controls.SetChildIndex(this.groupBox2, 0);
  1117. this.Controls.SetChildIndex(this.groupBox3, 0);
  1118. this.groupBox1.ResumeLayout(false);
  1119. this.groupBox1.PerformLayout();
  1120. this.groupBox2.ResumeLayout(false);
  1121. this.groupBox3.ResumeLayout(false);
  1122. this.panel2.ResumeLayout(false);
  1123. this.panel2.PerformLayout();
  1124. this.panel1.ResumeLayout(false);
  1125. this.ResumeLayout(false);
  1126. }
  1127. /// <summary>
  1128. /// listview内的图片点击事件,设置下面的等级、放大倍数、dpi
  1129. /// </summary>
  1130. /// <param name="sender"></param>
  1131. /// <param name="e"></param>
  1132. private void listView1_MouseClick(object sender, MouseEventArgs e)
  1133. {
  1134. ListViewHitTestInfo info = this.listView1.HitTest(e.X, e.Y);
  1135. if(info!=null)
  1136. {
  1137. AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(info.Item.Tag));
  1138. if (parent != null)
  1139. {
  1140. this.textBox1.Text = parent.Value;
  1141. this.textBox2.Text = parent.Zoom;
  1142. this.textBox3.Text = parent.Dpi;
  1143. //查看大图
  1144. using (ImagePreviewDialog imagePreviewDialog = new ImagePreviewDialog(parent.bitmap, this.appWorkspace))
  1145. {
  1146. imagePreviewDialog.Text = parent.name;
  1147. imagePreviewDialog.StartPosition = FormStartPosition.CenterScreen;
  1148. imagePreviewDialog.ShowDialog();
  1149. }
  1150. }
  1151. }
  1152. /*
  1153. int clickIndex = -1;
  1154. if(this.listView1.Items.Count>0)
  1155. {
  1156. for (int i= 0; i<this.listView1.Items.Count; i++)
  1157. {
  1158. Rectangle rectangle = this.listView1.Items[i].Bounds;
  1159. if (rectangle.X<e.X && rectangle.X + rectangle.Width > e.X && rectangle.Y<e.Y && rectangle.Y + rectangle.Height > e.Y)
  1160. {
  1161. clickIndex = i;
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. if (clickIndex>-1)
  1167. {
  1168. if (this.listView1.Items[clickIndex] != null)
  1169. {
  1170. AtlasModel parent = this.atlasModels.Find(a => a.id.Equals(this.listView1.Items[clickIndex].Tag));
  1171. if (parent != null)
  1172. {
  1173. this.textBox1.Text = parent.Value;
  1174. this.textBox2.Text = parent.Zoom;
  1175. this.textBox3.Text = parent.Dpi;
  1176. //查看大图
  1177. using (ImagePreviewDialog imagePreviewDialog = new ImagePreviewDialog(parent.bitmap, this.appWorkspace))
  1178. {
  1179. imagePreviewDialog.Text = parent.name;
  1180. imagePreviewDialog.StartPosition = FormStartPosition.CenterScreen;
  1181. imagePreviewDialog.ShowDialog();
  1182. }
  1183. }
  1184. }
  1185. }*/
  1186. }
  1187. /// <summary>
  1188. /// 获取上次操作参数
  1189. /// </summary>
  1190. private void getLastData()
  1191. {
  1192. string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml";
  1193. if (!System.IO.File.Exists(filePath))
  1194. {
  1195. generalAnalysisModel = new GeneralAnalysisModel();
  1196. generalAnalysisModel.PolyphaseMutiAreaContentModels = new GeneralAnalysisModel.PolyphaseMutiAreaContentModel();
  1197. generalAnalysisModel.PolyphaseCounterAnalysisModels = new GeneralAnalysisModel.PolyphaseCounterAnalysisModel();
  1198. generalAnalysisModel.TwoPhaseScaleModels = new GeneralAnalysisModel.TwoPhaseScaleModel();
  1199. generalAnalysisModel.PolyphaseContentModels = new GeneralAnalysisModel.PolyphaseContentModel();
  1200. generalAnalysisModel.PolyphaseDistanceModels = new GeneralAnalysisModel.PolyphaseDistanceModel();
  1201. generalAnalysisModel.DebrisSelectionModels = new GeneralAnalysisModel.DebrisSelectionModel();
  1202. generalAnalysisModel.CountNumberAnalysisModels = new GeneralAnalysisModel.CountNumberAnalysisModel();
  1203. generalAnalysisModel.AtlasManagerModels = new GeneralAnalysisModel.AtlasManagerModel();
  1204. generalAnalysisModel.PolyphaseMutiAreaContentModels.hasUsed = false;
  1205. generalAnalysisModel.PolyphaseCounterAnalysisModels.hasUsed = false;
  1206. generalAnalysisModel.TwoPhaseScaleModels.hasUsed = false;
  1207. generalAnalysisModel.PolyphaseContentModels.hasUsed = false;
  1208. generalAnalysisModel.PolyphaseDistanceModels.hasUsed = false;
  1209. generalAnalysisModel.DebrisSelectionModels.hasUsed = false;
  1210. generalAnalysisModel.CountNumberAnalysisModels.hasUsed = false;
  1211. generalAnalysisModel.AtlasManagerModels.hasUsed = false;
  1212. string porosityInfoXml = XmlSerializeHelper.XmlSerialize<GeneralAnalysisModel>(generalAnalysisModel);
  1213. Directory.CreateDirectory(Application.StartupPath + "\\Config\\Default\\ParameterSaving\\");
  1214. FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.CreateNew);
  1215. }
  1216. else
  1217. {
  1218. generalAnalysisModel = XmlSerializeHelper.DESerializer<GeneralAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
  1219. if (generalAnalysisModel.AtlasManagerModels == null)
  1220. {
  1221. generalAnalysisModel.AtlasManagerModels = new GeneralAnalysisModel.AtlasManagerModel();
  1222. }
  1223. if (generalAnalysisModel.AtlasManagerModels.hasUsed)
  1224. {
  1225. switch (generalAnalysisModel.AtlasManagerModels.parameter1) {
  1226. case 0:
  1227. radioButton1.Checked = true;
  1228. radioButton2.Checked = false;
  1229. radioButton3.Checked = false;
  1230. radioButton4.Checked = false;
  1231. break;
  1232. case 1:
  1233. radioButton1.Checked = true;
  1234. radioButton2.Checked = false;
  1235. radioButton3.Checked = false;
  1236. radioButton4.Checked = false;
  1237. break;
  1238. case 2:
  1239. radioButton1.Checked = false;
  1240. radioButton2.Checked = true;
  1241. radioButton3.Checked = false;
  1242. radioButton4.Checked = false;
  1243. break;
  1244. case 3:
  1245. radioButton1.Checked = false;
  1246. radioButton2.Checked = false;
  1247. radioButton3.Checked = true;
  1248. radioButton4.Checked = false;
  1249. break;
  1250. case 4:
  1251. radioButton1.Checked = false;
  1252. radioButton2.Checked = false;
  1253. radioButton3.Checked = false;
  1254. radioButton4.Checked = true;
  1255. break;
  1256. }
  1257. textBox1.Text = generalAnalysisModel.AtlasManagerModels.parameter2;
  1258. textBox2.Text = generalAnalysisModel.AtlasManagerModels.parameter3;
  1259. textBox3.Text = generalAnalysisModel.AtlasManagerModels.parameter4;
  1260. }
  1261. }
  1262. }
  1263. /// <summary>
  1264. /// 保存上次操作参数
  1265. /// </summary>
  1266. private void saveLastData(object sender, EventArgs e)
  1267. {
  1268. if (generalAnalysisModel.AtlasManagerModels == null)
  1269. {
  1270. generalAnalysisModel.AtlasManagerModels = new GeneralAnalysisModel.AtlasManagerModel();
  1271. }
  1272. generalAnalysisModel.AtlasManagerModels.hasUsed = true;
  1273. if (radioButton1.Checked)
  1274. {
  1275. generalAnalysisModel.AtlasManagerModels.parameter1 = 1;
  1276. }
  1277. else if (radioButton2.Checked) {
  1278. generalAnalysisModel.AtlasManagerModels.parameter1 = 2;
  1279. }
  1280. else if (radioButton3.Checked)
  1281. {
  1282. generalAnalysisModel.AtlasManagerModels.parameter1 = 3;
  1283. }
  1284. else if (radioButton4.Checked)
  1285. {
  1286. generalAnalysisModel.AtlasManagerModels.parameter1 = 4;
  1287. }
  1288. generalAnalysisModel.AtlasManagerModels.parameter2 = textBox1.Text;
  1289. generalAnalysisModel.AtlasManagerModels.parameter3 = textBox2.Text;
  1290. generalAnalysisModel.AtlasManagerModels.parameter4 = textBox3.Text;
  1291. string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml";
  1292. string porosityInfoXml = XmlSerializeHelper.XmlSerialize<GeneralAnalysisModel>(generalAnalysisModel);
  1293. FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.Create);
  1294. }
  1295. }
  1296. }