工具箱相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Chaginfos.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using GrxCAD.EditorInput;
  11. using GrxCAD.DatabaseServices;
  12. using GrxCAD.Geometry;
  13. using System.IO;
  14. using GrxCAD.ApplicationServices;
  15. namespace HCTools
  16. {
  17. public partial class Chaginfos : Form
  18. {
  19. public Chaginfos()
  20. {
  21. InitializeComponent();
  22. }
  23. public struct record
  24. {
  25. public string original;
  26. public string now;
  27. public double distance;
  28. public record(string original, string now, double distance)
  29. {
  30. this.original = original;
  31. this.now = now;
  32. this.distance = distance;
  33. }
  34. }
  35. private void Chaginfos_Load(object sender, EventArgs e)
  36. {
  37. dataGridView_Update.ColumnCount = 3;
  38. dataGridView_Update.Columns[0].HeaderText = "原始内容";
  39. dataGridView_Update.Columns[1].HeaderText = "修改内容";
  40. dataGridView_Update.Columns[2].HeaderText = "平移距离";
  41. dataGridView_Update.RowHeadersVisible = false;
  42. dataGridView_Update.AllowUserToResizeRows = false;
  43. dataGridView_Update.Columns[0].Width = 181;
  44. dataGridView_Update.Columns[1].Width = 181;
  45. dataGridView_Update.Columns[2].Width = 100;
  46. dataGridView_Update.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  47. dataGridView_Update.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  48. dataGridView_Update.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  49. Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
  50. using (Transaction traction = database.TransactionManager.StartTransaction())
  51. {
  52. //存放所有图层名
  53. List<string> alllayername = new List<string>();
  54. LayerTable layertable = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
  55. foreach (ObjectId objid in layertable)
  56. {
  57. LayerTableRecord layertablerecord = traction.GetObject(objid, OpenMode.ForRead) as LayerTableRecord;
  58. alllayername.Add(layertablerecord.Name);
  59. }
  60. alllayername.Sort();
  61. for (int i = 0; i < alllayername.Count; i++)
  62. {
  63. this.comboBox_layer.Items.Add(alllayername[i]);
  64. }
  65. }
  66. }
  67. List<record> list = new List<record>();
  68. private void btn_Update_Click(object sender, EventArgs e)
  69. {
  70. list.Clear();
  71. int j = 0;
  72. if (path_Open == "" || path_Save == "")
  73. {
  74. MessageBox.Show("需修改的文件所在路径或保存路径为空!", "提示");
  75. return;
  76. }
  77. //Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  78. dataGridView_Update.ReadOnly = true;
  79. for (int i = 0; i < dataGridView_Update.Rows.Count; i++)
  80. {
  81. string original = "";
  82. string now = "";
  83. string str = "";
  84. double distance = 0;
  85. object obj0 = dataGridView_Update[0, i].Value;
  86. if (obj0 != null)
  87. {
  88. original = obj0.ToString();
  89. }
  90. object obj1 = dataGridView_Update[1, i].Value;
  91. if (obj1 != null)
  92. {
  93. now = obj1.ToString();
  94. }
  95. object obj2 = dataGridView_Update[2, i].Value;
  96. if (obj2 != null)
  97. {
  98. str = obj2.ToString();
  99. }
  100. if (string.IsNullOrEmpty(str) == false)
  101. {
  102. distance = Convert.ToDouble(str.ToString());
  103. }
  104. list.Add(new record(original, now, distance));
  105. }
  106. dataGridView_Update.ReadOnly = false;
  107. //记录删除记录
  108. List<string> delete = new List<string>();
  109. string[] file = Directory.GetFiles(path_Open);
  110. for (int i = 0; i < file.Length; i++)
  111. {
  112. string paths = file[i];
  113. string name = System.IO.Path.GetFileName(paths);
  114. if (name.Contains(".dwg") == false)
  115. {
  116. continue;
  117. }
  118. Database data = new Database(false, true);
  119. data.ReadDwgFile(paths, FileShare.Read, true, null);
  120. data.CloseInput(true);
  121. //记录附注起始坐标
  122. //Point3d position = new Point3d();
  123. delete.Clear();
  124. using (Transaction trans = data.TransactionManager.StartTransaction())
  125. {
  126. BlockTable bt = (BlockTable)trans.GetObject(data.BlockTableId, OpenMode.ForWrite);
  127. BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  128. LayerTable lt = trans.GetObject(data.LayerTableId, OpenMode.ForRead) as LayerTable;
  129. LayerTableRecord ltr = trans.GetObject(lt[comboBox_layer.SelectedItem.ToString()], OpenMode.ForRead) as LayerTableRecord;
  130. ObjectId LayerID = ltr.ObjectId;
  131. foreach (ObjectId id in btr)
  132. {
  133. Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;
  134. if (ent != null)
  135. {
  136. if (ent.GetType().ToString() == "GrxCAD.DatabaseServices.DBText" && ent.LayerId == LayerID)
  137. {
  138. DBText T = ent as DBText;
  139. string str = T.TextString.Trim();
  140. //if (str.Contains("投影方式") && T.LayerId == LayerID)
  141. //{
  142. // position = T.Position;
  143. //}
  144. //if (str.Contains("测图员") || str.Contains("数化员") || str.Contains("检查员") || str.Contains("复查员"))
  145. //{
  146. // if (T.LayerId == LayerID)
  147. // {
  148. // delete.Add(str + "\t");
  149. // T.Erase(true);
  150. // //continue;
  151. // }
  152. //}
  153. for (int k = 0; k < list.Count; k++)
  154. {
  155. if (str == list[k].original.Trim())
  156. {
  157. if (string.IsNullOrEmpty(list[k].now) == true)
  158. {
  159. if (T.LayerId == LayerID)
  160. {
  161. j++;
  162. delete.Add(str + "\t");
  163. T.Erase(true);
  164. continue;
  165. }
  166. }
  167. else
  168. {
  169. j++;
  170. T.TextString = list[k].now;
  171. T.Position = new Point3d(T.Position.X + list[k].distance, T.Position.Y, 0);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. //if (position != null)
  179. //{
  180. // TextStyleTable tst = trans.GetObject(data.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
  181. // TextStyleTableRecord tstr = trans.GetObject(tst["HZ"], OpenMode.ForRead) as TextStyleTableRecord;
  182. // ObjectId TStyleID = tstr.ObjectId;
  183. // ObjectId HZ = TStyleID;
  184. // double xx = position.X;
  185. // double yy = position.Y;
  186. // string[] contents = new string[7];
  187. // contents[0] = "SPHEROID:WGS-84 ";
  188. // contents[1] = "PROJECTION:Gauss-Kruger projection;";
  189. // contents[2] = "Center meridian is 104°16′; Projection elevation is 310m.";
  190. // //
  191. // //
  192. // //
  193. // contents[3] = "VERTICAL DATUM : From Mean Sea Level HONDAU(Vietnam), Contour intervals: 1 meter";
  194. // contents[4] = "GB/T 20257.1-2007 Cartographic symbols for national fundamental scale maps ";
  195. // //contents[4] = "GB/T 20257.2-2006 Cartographic symbols for national fundamental scale maps ";
  196. // contents[5] = "Part 1: Specifications for cartographic symbols 1:500 1:1000&1:2000 topographic maps";
  197. // //contents[5] = "Part 2: Specifications for cartographic symbols 1:5000&1:10000 topographic maps";
  198. // contents[6] = "December 2012";
  199. // for (int k = 0; k < contents.Length; k++)
  200. // {
  201. // DBText text1 = new DBText();
  202. // text1.TextString = contents[k];
  203. // text1.Position = new Point3d(xx, yy, 0);
  204. // //text1.Height = 15;
  205. // text1.Height = 3;
  206. // text1.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  207. // text1.LayerId = LayerID;
  208. // text1.TextStyleId = HZ;
  209. // text1.WidthFactor = 0.8;
  210. // text1.SetDatabaseDefaults(data);
  211. // btr.AppendEntity(text1);
  212. // trans.AddNewlyCreatedDBObject(text1, true);
  213. // //yy = yy - 30;
  214. // yy = yy - 5;
  215. // }
  216. //}
  217. //else
  218. //{
  219. //}
  220. trans.Commit();
  221. }
  222. //Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  223. //2007版本格式
  224. //data.SaveAs(path_Save + "\\" + name, true, DwgVersion.AC1021, doc.Database.SecurityParameters);
  225. data.SaveAs(path_Save + "\\" + name, DwgVersion.AC1021);
  226. //2004版本格式
  227. //data.SaveAs(path_Save + "\\" + name, DwgVersion.AC1800);
  228. //2000版本格式
  229. //data.SaveAs(path_Save + "\\" + name, DwgVersion.AC1015);
  230. data.Dispose();
  231. //
  232. delete.Sort();
  233. string deleterecord = "";
  234. foreach (var item in delete)
  235. {
  236. deleterecord += item;
  237. }
  238. deleterecord = name + "\t" + deleterecord;
  239. deleterecord += "\r\n";
  240. System.IO.StreamWriter writer = new StreamWriter(path_Save+"\\改动文件.txt", true);
  241. writer.Write(deleterecord);
  242. writer.Dispose();
  243. }
  244. if (j > 0)
  245. MessageBox.Show("修改成功!");
  246. else
  247. MessageBox.Show("未找到原始内容,修改失败!");
  248. this.Close();
  249. }
  250. private string path_Open = "";
  251. private void btn_BrowseNdupdate_Click(object sender, EventArgs e)
  252. {
  253. path_Open = "";
  254. FolderBrowserDialog FBD = new FolderBrowserDialog();
  255. FBD.Description = "选择需修改数据数据目录";
  256. FBD.ShowNewFolderButton = false;
  257. DialogResult result = FBD.ShowDialog();
  258. if (result == DialogResult.OK)
  259. {
  260. path_Open = FBD.SelectedPath;
  261. }
  262. txtbox_nDupdateLocation.Text = path_Open;
  263. }
  264. string path_Save = "";
  265. private void btn_BrowseSave_Click(object sender, EventArgs e)
  266. {
  267. path_Save = "";
  268. FolderBrowserDialog FBD = new FolderBrowserDialog();
  269. FBD.Description = "选择保存数据目录";
  270. FBD.ShowNewFolderButton = false;
  271. DialogResult result = FBD.ShowDialog();
  272. if (result == DialogResult.OK)
  273. {
  274. path_Save = FBD.SelectedPath;
  275. }
  276. txtbox_SaveLocation.Text = path_Save;
  277. }
  278. }
  279. }