123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- using GrxCAD.EditorInput;
- using GrxCAD.DatabaseServices;
- using GrxCAD.Geometry;
- using System.IO;
- using GrxCAD.ApplicationServices;
-
- namespace HCTools
- {
- public partial class Chaginfos : Form
- {
- public Chaginfos()
- {
- InitializeComponent();
- }
-
- public struct record
- {
- public string original;
- public string now;
- public double distance;
-
- public record(string original, string now, double distance)
- {
- this.original = original;
- this.now = now;
- this.distance = distance;
- }
- }
-
- private void Chaginfos_Load(object sender, EventArgs e)
- {
- dataGridView_Update.ColumnCount = 3;
- dataGridView_Update.Columns[0].HeaderText = "原始内容";
- dataGridView_Update.Columns[1].HeaderText = "修改内容";
- dataGridView_Update.Columns[2].HeaderText = "平移距离";
-
- dataGridView_Update.RowHeadersVisible = false;
- dataGridView_Update.AllowUserToResizeRows = false;
-
- dataGridView_Update.Columns[0].Width = 181;
- dataGridView_Update.Columns[1].Width = 181;
- dataGridView_Update.Columns[2].Width = 100;
-
- dataGridView_Update.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- dataGridView_Update.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
- dataGridView_Update.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
-
- Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- //存放所有图层名
- List<string> alllayername = new List<string>();
- LayerTable layertable = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
- foreach (ObjectId objid in layertable)
- {
- LayerTableRecord layertablerecord = traction.GetObject(objid, OpenMode.ForRead) as LayerTableRecord;
- alllayername.Add(layertablerecord.Name);
- }
- alllayername.Sort();
-
- for (int i = 0; i < alllayername.Count; i++)
- {
- this.comboBox_layer.Items.Add(alllayername[i]);
- }
- }
- }
-
-
- List<record> list = new List<record>();
- private void btn_Update_Click(object sender, EventArgs e)
- {
- list.Clear();
- int j = 0;
-
- if (path_Open == "" || path_Save == "")
- {
- MessageBox.Show("需修改的文件所在路径或保存路径为空!", "提示");
- return;
- }
-
- //Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- dataGridView_Update.ReadOnly = true;
- for (int i = 0; i < dataGridView_Update.Rows.Count; i++)
- {
- string original = "";
- string now = "";
- string str = "";
- double distance = 0;
-
- object obj0 = dataGridView_Update[0, i].Value;
- if (obj0 != null)
- {
- original = obj0.ToString();
- }
- object obj1 = dataGridView_Update[1, i].Value;
-
- if (obj1 != null)
- {
- now = obj1.ToString();
- }
- object obj2 = dataGridView_Update[2, i].Value;
-
- if (obj2 != null)
- {
- str = obj2.ToString();
- }
-
- if (string.IsNullOrEmpty(str) == false)
- {
- distance = Convert.ToDouble(str.ToString());
- }
-
- list.Add(new record(original, now, distance));
- }
- dataGridView_Update.ReadOnly = false;
-
- //记录删除记录
- List<string> delete = new List<string>();
-
- string[] file = Directory.GetFiles(path_Open);
- for (int i = 0; i < file.Length; i++)
- {
- string paths = file[i];
- string name = System.IO.Path.GetFileName(paths);
-
- if (name.Contains(".dwg") == false)
- {
- continue;
- }
-
- Database data = new Database(false, true);
- data.ReadDwgFile(paths, FileShare.Read, true, null);
- data.CloseInput(true);
-
-
- //记录附注起始坐标
- //Point3d position = new Point3d();
-
-
- delete.Clear();
-
- using (Transaction trans = data.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(data.BlockTableId, OpenMode.ForWrite);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
-
-
- LayerTable lt = trans.GetObject(data.LayerTableId, OpenMode.ForRead) as LayerTable;
- LayerTableRecord ltr = trans.GetObject(lt[comboBox_layer.SelectedItem.ToString()], OpenMode.ForRead) as LayerTableRecord;
- ObjectId LayerID = ltr.ObjectId;
-
- foreach (ObjectId id in btr)
- {
- Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;
- if (ent != null)
- {
- if (ent.GetType().ToString() == "GrxCAD.DatabaseServices.DBText" && ent.LayerId == LayerID)
- {
-
- DBText T = ent as DBText;
- string str = T.TextString.Trim();
-
- //if (str.Contains("投影方式") && T.LayerId == LayerID)
- //{
- // position = T.Position;
- //}
-
- //if (str.Contains("测图员") || str.Contains("数化员") || str.Contains("检查员") || str.Contains("复查员"))
- //{
- // if (T.LayerId == LayerID)
- // {
- // delete.Add(str + "\t");
- // T.Erase(true);
- // //continue;
- // }
-
- //}
-
- for (int k = 0; k < list.Count; k++)
- {
- if (str == list[k].original.Trim())
- {
-
- if (string.IsNullOrEmpty(list[k].now) == true)
- {
- if (T.LayerId == LayerID)
- {
- j++;
- delete.Add(str + "\t");
- T.Erase(true);
- continue;
- }
- }
- else
- {
- j++;
- T.TextString = list[k].now;
- T.Position = new Point3d(T.Position.X + list[k].distance, T.Position.Y, 0);
- }
- }
- }
-
- }
-
- }
-
- }
-
-
- //if (position != null)
- //{
-
- // TextStyleTable tst = trans.GetObject(data.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
- // TextStyleTableRecord tstr = trans.GetObject(tst["HZ"], OpenMode.ForRead) as TextStyleTableRecord;
- // ObjectId TStyleID = tstr.ObjectId;
-
-
-
- // ObjectId HZ = TStyleID;
- // double xx = position.X;
- // double yy = position.Y;
-
- // string[] contents = new string[7];
- // contents[0] = "SPHEROID:WGS-84 ";
- // contents[1] = "PROJECTION:Gauss-Kruger projection;";
- // contents[2] = "Center meridian is 104°16′; Projection elevation is 310m.";
- // //
- // //
- // //
- // contents[3] = "VERTICAL DATUM : From Mean Sea Level HONDAU(Vietnam), Contour intervals: 1 meter";
- // contents[4] = "GB/T 20257.1-2007 Cartographic symbols for national fundamental scale maps ";
- // //contents[4] = "GB/T 20257.2-2006 Cartographic symbols for national fundamental scale maps ";
- // contents[5] = "Part 1: Specifications for cartographic symbols 1:500 1:1000&1:2000 topographic maps";
- // //contents[5] = "Part 2: Specifications for cartographic symbols 1:5000&1:10000 topographic maps";
- // contents[6] = "December 2012";
-
- // for (int k = 0; k < contents.Length; k++)
- // {
- // DBText text1 = new DBText();
- // text1.TextString = contents[k];
- // text1.Position = new Point3d(xx, yy, 0);
- // //text1.Height = 15;
- // text1.Height = 3;
- // text1.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
- // text1.LayerId = LayerID;
- // text1.TextStyleId = HZ;
- // text1.WidthFactor = 0.8;
-
- // text1.SetDatabaseDefaults(data);
- // btr.AppendEntity(text1);
- // trans.AddNewlyCreatedDBObject(text1, true);
-
-
-
- // //yy = yy - 30;
- // yy = yy - 5;
- // }
-
- //}
- //else
- //{
-
- //}
-
-
- trans.Commit();
- }
-
- //Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- //2007版本格式
- //data.SaveAs(path_Save + "\\" + name, true, DwgVersion.AC1021, doc.Database.SecurityParameters);
- data.SaveAs(path_Save + "\\" + name, DwgVersion.AC1021);
- //2004版本格式
- //data.SaveAs(path_Save + "\\" + name, DwgVersion.AC1800);
- //2000版本格式
- //data.SaveAs(path_Save + "\\" + name, DwgVersion.AC1015);
-
-
- data.Dispose();
-
- //
- delete.Sort();
- string deleterecord = "";
- foreach (var item in delete)
- {
- deleterecord += item;
- }
-
- deleterecord = name + "\t" + deleterecord;
- deleterecord += "\r\n";
-
- System.IO.StreamWriter writer = new StreamWriter(path_Save+"\\改动文件.txt", true);
- writer.Write(deleterecord);
- writer.Dispose();
- }
- if (j > 0)
- MessageBox.Show("修改成功!");
- else
- MessageBox.Show("未找到原始内容,修改失败!");
- this.Close();
- }
-
-
- private string path_Open = "";
- private void btn_BrowseNdupdate_Click(object sender, EventArgs e)
- {
- path_Open = "";
-
- FolderBrowserDialog FBD = new FolderBrowserDialog();
- FBD.Description = "选择需修改数据数据目录";
- FBD.ShowNewFolderButton = false;
- DialogResult result = FBD.ShowDialog();
-
- if (result == DialogResult.OK)
- {
- path_Open = FBD.SelectedPath;
- }
-
- txtbox_nDupdateLocation.Text = path_Open;
- }
-
-
- string path_Save = "";
- private void btn_BrowseSave_Click(object sender, EventArgs e)
- {
- path_Save = "";
-
- FolderBrowserDialog FBD = new FolderBrowserDialog();
- FBD.Description = "选择保存数据目录";
- FBD.ShowNewFolderButton = false;
- DialogResult result = FBD.ShowDialog();
-
- if (result == DialogResult.OK)
- {
- path_Save = FBD.SelectedPath;
- }
-
- txtbox_SaveLocation.Text = path_Save;
- }
-
- }
- }
|