public void SetFromDBObject(DBTunnel dbtunnel) { if (dbtunnel.Type == "T_SquareTunnel") { this.Type = "方形巷道"; } else if (dbtunnel.Type == "T_CylinderTunnel") { this.Type = "柱形巷道"; } this.Name = dbtunnel.Name; this.HandleValue = dbtunnel.HandleValue; this.TagData = dbtunnel.TagData; this.Location = dbtunnel.Location; this.Segment = dbtunnel.Segment; this.Colors = dbtunnel.Colors; for (int i = 0; i < dbtunnel.BasePoints.Count; i++) { DPVertice dp = new DPVertice(); dp.SetFromDBVertice(dbtunnel.BasePoints[i]); _verticeCollection.SetByDBVertice(dp); } this.DisplayTag = dbtunnel.DisplayTag; }
private void modify(Func <DBVertice, bool> handler) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity entity = dbControl.FindOne (Query.EQ("HandleValue", this._handleValue)); if (entity == null) { return; } bool changed = false; if (entity.Type == "Tunnel") { DBTunnel tunnel = entity as DBTunnel; changed = handler(tunnel.BasePoints[this._index]); } else if (entity.Type == "TunnelNode") { DBNode node = entity as DBNode; changed = handler(node.Position); } if (changed) { dbControl.Update(entity, Project.Instance.GetActivePropCtl(doc)); } }
static public void DynamicDrawTrapezoidalTunnel(DBTunnel inTunnel = null) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; //输入起点坐标 PromptPointOptions opts = new PromptPointOptions("\nEnter Tunnel Start Point:"); PromptPointResult res = ed.GetPoint(opts); if (res.Status == PromptStatus.Cancel) { return; } Point3d firstPoint = res.Value; //create Tunnel SquareTunnelJig jig = new SquareTunnelJig(firstPoint); SquareTunnel tmpTunnel = (SquareTunnel)jig.GetEntity(); for (int i = 0; ; i++) { jig.setPromptCounter(i); PromptResult drag = ed.Drag(jig); if (drag.Status == PromptStatus.Cancel || drag.Status == PromptStatus.None)//画完了 { Utils.TransactionControl(() => { List <Point3d> points = tmpTunnel.BasePoints; points.RemoveAt(points.Count - 1); if (points.Count < 2) { return; } SquareTunnel tunnel = new SquareTunnel(); tunnel.TunnelType = DBTunnel.Tunnel_type_t; tunnel.Width_b = 12; tunnel.Width_t = 8; tunnel.BasePoints = points; tunnel.Name = "巷道"; try { tunnel.Location = Project.Instance.getCurrentSurface(doc).Path; } catch (System.Exception) { } Utils.AppendEntity(tunnel); appendNode(tunnel); appendTag(tunnel); tunnel.Dispose(); tmpTunnel.Dispose(); }); break; } else if (drag.Status == PromptStatus.OK) { } } }
//控件界面显示数据绑定 private void display() { tunnelList = Global.SelectedTunnels; if (tunnelList.Count < 1) { return; } shownTunnel = tunnelList[0]; List <short> temperature = shownTunnel.Temperatures; List <int> indexes1 = new List <int>(); for (int i = 0; i < temperature.Count; i++) { indexes1.Add(i); } comboBox_ti.DataSource = indexes1; comboBox_ti.SelectedIndex = 0; List <DBVertice> points = shownTunnel.BasePoints; List <int> indexes2 = new List <int>(); for (int i = 0; i < points.Count; i++) { indexes2.Add(i); } comboBox_pi.DataSource = indexes2; comboBox_pi.SelectedIndex = 0; }
//删除坐标,图形界面同步删除节点 public void deleDataRow() { if (tunnels[gridView1.FocusedRowHandle].HandleValue < 0) { gridView1.DeleteRow(gridView1.FocusedRowHandle); } else { gridView1.DeleteRow(gridView1.FocusedRowHandle); gridControl.RefreshDataSource(); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity entity = dbControl.FindOne(Query.EQ("HandleValue", tunnels[gridView1.FocusedRowHandle].HandleValue)); DBTunnel newTunnel = entity as DBTunnel; newTunnel.BasePoints.Clear(); foreach (var t in tunnels) { if (t.HandleValue == tunnels[gridView1.FocusedRowHandle].HandleValue) { newTunnel.BasePoints.Add(new DBVertice(t.X, t.Y, t.Z)); } } dbControl.Update(newTunnel, this); } }
/// <summary> /// 添加事件使临时数据库与图纸中所有效的数据相一致 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void db_ObjectAppend(object sender, ObjectEventArgs e) { if (!(e.DBObject is BaseTunnel) && !(e.DBObject is Node)) { return; } Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Entity entity = e.DBObject as Entity; if (entity == null || entity.BlockName != "*Model_Space") { return; } if (entity is BaseTunnel) { DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBTunnel dbTunnel = new DBTunnel(); dbTunnel.SetProperty(entity); dbControl.Insert(dbTunnel, db); } else if (entity is Node) { DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBNode dbNode = new DBNode(); dbNode.SetProperty(entity); dbControl.Insert(dbNode, db); } }
//界面数据修改同步修改litedb private void modify(Func <DBTunnel, bool> handler) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity entity = dbControl.FindOne (Query.EQ("HandleValue", this.HandleValue)); if (entity == null) { return; } bool changed = false; if (entity is DBTunnel) { DBTunnel tunnel = entity as DBTunnel; changed = handler(tunnel); if (changed) { dbControl.Update(entity, Project.Instance.GetActivePropCtl(doc)); } } }
//数据库删除事件的回调 private void dataDeleted(object sender, List <DBEntity> entities) { ArrayList deleteNum = new ArrayList(); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(Project.Instance.GetActiveGridList(doc))) { return; } using (DocumentLock doclock = doc.LockDocument()) { foreach (var entity in entities) { if (!(entity is DBTunnel)) { continue; } DBTunnel dbTunnel = entity as DBTunnel; gridControl.RefreshDataSource(); for (int i = 0; i < tunnels.Count + deleteNum.Count; i++) { if (tunnels[i - deleteNum.Count].HandleValue == dbTunnel.HandleValue) { tunnels.RemoveAt(i - deleteNum.Count); deleteNum.Add(i); } } deleteNum.Clear(); } gridControl.RefreshDataSource(); } }
/// <summary> /// 保存事件使数据库与图纸中的已保存数据相一致 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void db_SaveComplete(object sender, DatabaseIOEventArgs e) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; //保存树结构 DBTreeControl treeControl = Project.Instance.GetMainTreeCol(doc); treeControl.StoreTree(Project.Instance.GetProjectTree(doc)); //保存模型数据 DBEntityControl dbControl = Project.Instance.GetMainEntCol(doc, true); TypedValue[] value = { new TypedValue((int)DxfCode.Start, "TUNNEL_SQUARE,TUNNEL_CYLINDER,TUNNELNODE") }; SelectionFilter sf = new SelectionFilter(value); PromptSelectionResult res = ed.SelectAll(sf); if (res.Status != PromptStatus.OK) { dbControl.Delete(Query.All(), db); return; } SelectionSet SS = res.Value; if (SS == null) { return; } Autodesk.AutoCAD.DatabaseServices.ObjectId[] idArray = SS.GetObjectIds(); Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; using (Transaction myT = tm.StartTransaction()) { //储存之前先把之前数据的删除干净 int deleteCounts = dbControl.Delete(Query.All(), db); foreach (var id in idArray) { Entity entity = (Entity)tm.GetObject(id, OpenMode.ForRead, true); if (entity is BaseTunnel) { DBTunnel dbTunnel = new DBTunnel(); dbTunnel.SetProperty(entity); dbControl.Insert(dbTunnel, db); } else if (entity is Node) { DBNode dbNode = new DBNode(); dbNode.SetProperty(entity); dbControl.Insert(dbNode, db); } } myT.Commit(); } }
static public void ChangeSelection(object sender, SelectionSet set) { SelectedTunnels = new List <DBTunnel>(); SelectedNodes = new List <DBNode>(); if (set.Count != 0) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; var ids = set.GetObjectIds(); Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; Utils.TransactionControl(() => { Entity entity = null; foreach (var id in ids) { entity = (Entity)tm.GetObject(id, OpenMode.ForRead, false); if (entity.IsErased == true) { return; } long handleValue = entity.Handle.Value; if (entity is BaseTunnel) { DBTunnel dbTunnel = Utils.GetEntityFromDB(handleValue) as DBTunnel; if (dbTunnel == null) { return; } else { SelectedTunnels.Add(dbTunnel); } } else if (entity is Node) { DBNode dbNode = Utils.GetEntityFromDB(handleValue) as DBNode; if (dbNode == null) { return; } else { SelectedNodes.Add(dbNode); } } } }); } SelectedTunnelChanged?.Invoke(sender, SelectedTunnels); SelectedNodeChanged?.Invoke(sender, SelectedNodes); }
/**********************************************/ //通过参数的方式生成方形巷道 static public List <DBTunnel> StaticDrawSquareTunnel(List <DBTunnel> inList) { if (inList == null) { return(null); } List <DBTunnel> outList = new List <DBTunnel>(); Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; foreach (var v in inList) { if (v.HandleValue > 0) { outList.Add(v); continue; } Utils.TransactionControl(() => { List <Point3d> points = new List <Point3d>(); foreach (var point in v.BasePoints) { points.Add(new Point3d( point.X, point.Y, point.Z )); } SquareTunnel tunnel = new SquareTunnel(); tunnel.TunnelType = DBTunnel.Tunnel_type_s; tunnel.BasePoints = points; tunnel.SetClose(v.IsClosed); tunnel.Name = (v.Name == null || v.Name == "")?"巷道":v.Name; try { tunnel.Location = (v.Location != null && v.Location != "") ? v.Location : Project.Instance.getCurrentSurface(doc).Path; } catch (System.Exception) { } Utils.AppendEntity(tunnel); appendNode(tunnel); appendTag(tunnel); DBTunnel dbTunnel = new DBTunnel(); dbTunnel.SetProperty(tunnel); tunnel.Dispose(); outList.Add(dbTunnel); }); } return(outList); }
private void DrawButton_Click(object sender, EventArgs e) { string type = (string)this.TypeEdit.SelectedItem; DBTunnel tunnel = new DBTunnel(); if (type == _squareTunnel) { } else if (type == _cylinderTunnel) { } }
//数据库删除事件的回调 private void dataDeleted(object sender, List <DBEntity> entities) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(this)) { return; } foreach (var entity in entities) { if (!(entity is DBTunnel)) { continue; } DBTunnel dbTunnel = entity as DBTunnel; var projectTree = Project.Instance.GetProjectTree(doc); var deleteNode = projectTree.Find((node) => { if (!(node is ProjectTreeLeafNode)) { return(false); } else { ProjectTreeLeafNode leafNode = node as ProjectTreeLeafNode; if (leafNode.HandleValue == dbTunnel.HandleValue) { return(true); } else { return(false); } } }); if (deleteNode != null) { deleteNode.GetParentNode().Children.Remove(deleteNode); bool ok = projectTree.Remove(deleteNode); if (ok) { treeList1.RefreshDataSource(); } } } }
//修改叶子节点数据到数据库 private void modityLeafNode(ProjectTreeLeafNode leafNode) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity entity = dbControl.FindOne (Query.EQ("HandleValue", leafNode.HandleValue)); DBTunnel tunnel = entity as DBTunnel; tunnel.Location = leafNode.ParentPath; tunnel.Name = leafNode.Name; dbControl.Update(entity, this); }
//坐标数据表GridList生成巷道 public void DrawStatic() { List <DBTunnel> inList = new List <DBTunnel>(); for (int i = 1; i <= hand.Count; i++) { bool isAddpoint = false; DBTunnel dbtunnel = new DBTunnel(); dbtunnel.BasePoints = new List <DBVertice>(); foreach (var item in tunnels) { if (item.HandleValue == -i) { dbtunnel.BasePoints.Add(new DBVertice(item.X, item.Y, item.Z)); isAddpoint = true; } } if (isAddpoint) { inList.Add(dbtunnel); } else { continue; } } DrawTunnel.StaticDrawSquareTunnel(inList); List <Tunnel> deleteTunnel = new List <Tunnel>(); foreach (var tunnel in tunnels) { if (tunnel.HandleValue < 0) { deleteTunnel.Add(tunnel); } } foreach (var tunnel in deleteTunnel) { tunnels.Remove(tunnel); } }
//修改已生成巷道的表格坐标数据,图形界面同步刷新 private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (tunnels[e.RowHandle].HandleValue > 0) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity entity = dbControl.FindOne(Query.EQ("HandleValue", tunnels[e.RowHandle].HandleValue)); DBTunnel newTunnel = entity as DBTunnel; newTunnel.BasePoints.Clear(); foreach (var t in tunnels) { if (t.HandleValue == tunnels[e.RowHandle].HandleValue) { newTunnel.BasePoints.Add(new DBVertice(t.X, t.Y, t.Z)); } } dbControl.Update(newTunnel, this); } }
//数据库修改事件的回调 private void dataUpdated(object sender, DBEntity entity) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(this)) { return; } if (!(entity is DBTunnel)) { return; } DBTunnel dbTunnel = entity as DBTunnel; var projectTree = Project.Instance.GetProjectTree(doc); var updatedNode = projectTree.Find((node) => { if (!(node is ProjectTreeLeafNode)) { return(false); } else { ProjectTreeLeafNode leafNode = node as ProjectTreeLeafNode; if (leafNode.HandleValue == dbTunnel.HandleValue) { return(true); } else { return(false); } } }); updatedNode.Name = dbTunnel.Name; treeList1.RefreshDataSource(); }
/// <summary> /// 删除事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void db_ObjectErased(object sender, ObjectErasedEventArgs e) { if (!(e.DBObject is BaseTunnel) && !(e.DBObject is Node)) { return; } Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; if (e.Erased == true) //这时候是删除触发的 { DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); dbControl.Delete(Query.EQ("HandleValue", e.DBObject.ObjectId.Handle.Value), db); if (e.DBObject is BaseTunnel) { Global.EraseSelectedTunnel(sender, e.DBObject.ObjectId.Handle.Value); } } else //这时候是删除后的撤销动作触发的 { Entity entity = e.DBObject as Entity; if (entity is BaseTunnel) { DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBTunnel dbTunnel = new DBTunnel(); dbTunnel.SetProperty(entity); dbControl.Insert(dbTunnel, db); } else if (entity is Node) { DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBNode dbNode = new DBNode(); dbNode.SetProperty(entity); dbControl.Insert(dbNode, db); } } }
//数据库插入事件的回调,包含cad撤销事件 private void dataInserted(object sender, DBEntity entity) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(Project.Instance.GetActiveGridList(doc))) { return; } if (!(entity is DBTunnel)) { return; } DBTunnel dbTunnel = entity as DBTunnel; gridControl.RefreshDataSource(); if (gridView1.RowCount > 0) { for (int i = 0; i < dbTunnel.BasePoints.Count; i++) { if (dbTunnel.HandleValue != tunnels[tunnels.Count - i - 1].HandleValue) { tunnels.Add(new Tunnel(dbTunnel.HandleValue, dbTunnel.Name, dbTunnel.BasePoints[i].X, dbTunnel.BasePoints[i].Y, dbTunnel.BasePoints[i].Z)); coTunnels.Add(new Tunnel(dbTunnel.HandleValue, dbTunnel.Name, dbTunnel.BasePoints[i].X, dbTunnel.BasePoints[i].Y, dbTunnel.BasePoints[i].Z)); } } } else { for (int i = 0; i < dbTunnel.BasePoints.Count; i++) { tunnels.Add(new Tunnel(dbTunnel.HandleValue, dbTunnel.Name, dbTunnel.BasePoints[i].X, dbTunnel.BasePoints[i].Y, dbTunnel.BasePoints[i].Z)); coTunnels.Add(new Tunnel(dbTunnel.HandleValue, dbTunnel.Name, dbTunnel.BasePoints[i].X, dbTunnel.BasePoints[i].Y, dbTunnel.BasePoints[i].Z)); } } gridControl.RefreshDataSource(); }
//数据库修改事件的回调 private void dataUpdated(object sender, DBEntity entity) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(Project.Instance.GetActiveGridList(doc))) { return; } if (!(entity is DBTunnel)) { return; } DBTunnel dbTunnel = entity as DBTunnel; int mm = 0; gridControl.RefreshDataSource(); for (int i = 0; i < tunnels.Count; i++) { bool isBool = true; if (tunnels[i].HandleValue == dbTunnel.HandleValue) { tunnels.RemoveAt(i); for (int j = mm; j < dbTunnel.BasePoints.Count; j++) { if (isBool == true) { tunnels.Insert(i, new Tunnel(dbTunnel.HandleValue, dbTunnel.Name, dbTunnel.BasePoints[j].X, dbTunnel.BasePoints[j].Y, dbTunnel.BasePoints[j].Z)); isBool = false; mm = mm + 1; } } } } gridControl.RefreshDataSource(); }
//combox下拉选项变化触发事件 private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e) { if (dbt.Count > 0) { for (int i = 0; i < tunnelName.Count; i++) { if (comboBoxEdit1.SelectedIndex == i) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbcontrol = Project.Instance.GetTmpEntCol(doc); DBEntity entity = dbcontrol.FindOne(Query.EQ("HandleValue", dbt[i].HandleValue)); DBTunnel dbtunnel = entity as DBTunnel; DPTunnel dptunnel = new DPTunnel(); dptunnel.SetFromDBObject(dbtunnel); if (Utils.GetEntityFromDB(dbt[i].HandleValue) != null) { Display("Tunnel", dptunnel); propertyGridControl1.Refresh(); } } } } comboBoxEdit1.Refresh(); }
private void dataUpdated(object sender, DBEntity dbEntity) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(db)) { return; } Handle handle = new Handle(dbEntity.HandleValue); using (DocumentLock docLock = doc.LockDocument()) { Utils.TransactionControl(() => { Entity ent = Utils.OpenEntityByHandle(handle); if (ent is Node) { Node node = ent as Node; DBNode dbNode = dbEntity as DBNode; dbNode.ToCADObject(node); } else if (ent is BaseTunnel) { BaseTunnel tunnel = ent as BaseTunnel; DBTunnel dbTunnel = dbEntity as DBTunnel; dbTunnel.ToCADObject(tunnel); } }); } }
/// <summary> /// 修改事件使临时数据库与图纸窗口中有效的数据相一致 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void db_ObjectModified(object sender, ObjectEventArgs e) { // if (modifyGraph == true) return; if (Global.AnimateMode == true) { return; } Entity entity = e.DBObject as Entity; if (!(entity is BaseTunnel) && !(entity is Node)) { return; } try { if (entity == null || entity.BlockName != "*Model_Space") { return; } } catch (Autodesk.AutoCAD.Runtime.Exception) { return; } Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; if (e.DBObject is BaseTunnel) { DBTunnel newTunnel = new DBTunnel(); newTunnel.SetProperty((Entity)(e.DBObject)); DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity oldTunnel = dbControl.FindOne (Query.EQ("HandleValue", e.DBObject.ObjectId.Handle.Value)); if (oldTunnel == null) { return; } newTunnel._id = oldTunnel._id; lock (modifyMutex) { dbControl.Update(newTunnel, db); } } else if (e.DBObject is Node) { DBNode newNode = new DBNode(); newNode.SetProperty((Entity)(e.DBObject)); DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); DBEntity oldTunnel = dbControl.FindOne (Query.EQ("HandleValue", e.DBObject.ObjectId.Handle.Value)); if (oldTunnel == null) { return; } newNode._id = oldTunnel._id; lock (modifyMutex) { dbControl.Update(newNode, db); } } }
static public void transformToTunnel() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptSelectionResult res = ed.SelectAll(); if (res.Status == PromptStatus.Error) { return; } Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value; var tmpidarray = SS.GetObjectIds(); var idArray = SS.GetObjectIds(); Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; List <DBTunnel> inList = new List <DBTunnel>(); Utils.TransactionControl(() => { foreach (ObjectId id in tmpidarray) { Entity entity = (Entity)tm.GetObject(id, OpenMode.ForWrite, true); if (!(entity is Line) && !(entity is Autodesk.AutoCAD.DatabaseServices.Polyline)) { continue; } if (entity is Line) { Line line = entity as Line; DBTunnel dbTunnel = new DBTunnel(); dbTunnel.BasePoints = new List <DBVertice> { new DBVertice(line.StartPoint), new DBVertice(line.EndPoint) }; inList.Add(dbTunnel); line.Erase(); } else if (entity is Autodesk.AutoCAD.DatabaseServices.Polyline) { Autodesk.AutoCAD.DatabaseServices.Polyline polyline = entity as Autodesk.AutoCAD.DatabaseServices.Polyline; DBTunnel dbTunnel = new DBTunnel(); dbTunnel.BasePoints = new List <DBVertice>(); for (int i = 0; i < polyline.NumberOfVertices; i++) { dbTunnel.BasePoints.Add(new DBVertice(polyline.GetPoint3dAt(i))); } if (polyline.Closed == true) { dbTunnel.IsClosed = true; } inList.Add(dbTunnel); polyline.Erase(); } } }); var resList = DrawTunnel.StaticDrawSquareTunnel(inList); }
//**************************数据库事件的回调函数**************************// //数据库插入事件的回调,包含cad撤销事件 private void dataInserted(object sender, DBEntity entity) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc); if (dbControl.Senders.Contains(this)) { return; } if (!(entity is DBTunnel)) { return; } DBTunnel dbTunnel = entity as DBTunnel; var currentWorkingSurface = Project.Instance.getCurrentSurface(doc); if (currentWorkingSurface == null) { throw new System.Exception("找不到当前工作面"); } //确定工作面 ProjectTreeNode pNode = null; //如果是当前工作面 if (dbTunnel.Location == currentWorkingSurface.Path) { pNode = currentWorkingSurface; } else //非当前工作面 { var surface = findNodeByPath(dbTunnel.Location); //var surface = findParentNodeByPath(dbTunnel.Location); if (surface != null) //工程树中有巷道保存的工作面 { pNode = surface; } else { pNode = getUnassignedNode(); } } ProjectTreeLeafNode nodex = new ProjectTreeLeafNode(dbTunnel.Name, pNode, dbTunnel.HandleValue); pNode.Children.Add(nodex); var projectTree = Project.Instance.GetProjectTree(doc); var flag = projectTree.Find((n) => { if (n.Path == nodex.Path) { return(true); } else { return(false); } }); if (flag == null) { projectTree.Add(nodex); } treeList1.RefreshDataSource(); }