Пример #1
0
        //点击温度设置确定按钮
        private void SaveButton_Click(object sender, EventArgs e)
        {
            Document        doc       = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            dbControl.Update(shownTunnel, this);
        }
Пример #2
0
        static public void Init(Document doc)
        {
            Project.Instance.MapProjectID(doc);

            string mainDbName = initMainCol(doc);

            DBEntityControl tmpdb = Project.Instance.GetTmpEntCol(doc);

            if (mainDbName != null)
            {
                if (File.Exists(tmpdb.Name))
                {
                    try
                    {
                        File.Delete(tmpdb.Name);
                    }
                    catch (System.IO.IOException) { }
                }

                try
                {
                    File.Copy(mainDbName, tmpdb.Name);
                }
                catch (System.IO.IOException) { }
            }
        }
Пример #3
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);
     }
 }
Пример #4
0
        public DBEntityControl GetMainEntCol(Document doc, bool create)
        {
            string          projectID = GetDwgId(doc);
            DBEntityControl value     = null;

            dbMainEntFiles.TryGetValue(projectID, out value);
            if (value != null)
            {
                return(value);
            }
            else
            {
                string mainFileNum    = projectID;
                string mainDbFilePath = Utils.formatDbFileName(DataPath, mainFileNum);

                if (!File.Exists(mainDbFilePath) && create)
                {
                    var maindbfile = File.Create(mainDbFilePath);
                    maindbfile.Close();
                }

                DBEntityControl dbControl = new DBEntityControl(mainDbFilePath);
                dbMainEntFiles.Add(projectID, dbControl);

                return(dbControl);
            }
        }
Пример #5
0
        //界面数据修改同步修改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));
                }
            }
        }
Пример #6
0
        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));
            }
        }
Пример #7
0
        /// <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);
            }
        }
Пример #8
0
        private void dataDeleted(object sender, List <DBEntity> entities)
        {
            Document        doc       = Application.DocumentManager.MdiActiveDocument;
            Database        db        = doc.Database;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            if (dbControl.Senders.Contains(db))
            {
                return;
            }

            using (DocumentLock docLock = doc.LockDocument())
            {
                Utils.TransactionControl(() =>
                {
                    foreach (var entity in entities)
                    {
                        Handle handle = new Handle(entity.HandleValue);
                        Entity ent    = Utils.OpenEntityByHandle(handle);
                        if (ent != null)
                        {
                            ent.Erase();
                        }
                    }
                });
            }
        }
Пример #9
0
        //数据库删除事件的回调
        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();
            }
        }
Пример #10
0
        /// <summary>
        /// 从当前项目的litedb中找到对象
        /// </summary>
        /// <param name="handleValue">要找到对象的句柄数值</param>
        /// <returns></returns>
        public static DBEntity GetEntityFromDB(long handleValue)
        {
            Document        doc       = Application.DocumentManager.MdiActiveDocument;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);
            DBEntity        dbEntity  = dbControl.FindOne(LiteDB.Query.EQ("HandleValue", handleValue));

            return(dbEntity);
        }
Пример #11
0
        /// <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();
            }
        }
Пример #12
0
        //数据库删除事件的回调
        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();
                    }
                }
            }
        }
Пример #13
0
        public List <DBTunnel> dbt = new List <DBTunnel>();//临时存放选中巷道数据
        public PropertyControl()
        {
            InitializeComponent();
            DPTunnel dptunnel = new DPTunnel();

            Display("Tunnel", dptunnel);
            Document        doc       = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            dbControl.EntityUpdated      += dataUpdated; //添加litedb数据库事件,为了litedb数据更新时同步到这个控件
            dbControl.EntityDeleted      += dataDelete;
            Global.SelectedTunnelChanged += proSelectTunnel;
            comboBoxEdit1.Text            = "无选择" + "(" + dbt.Count.ToString() + ")";
        }
Пример #14
0
        //修改叶子节点数据到数据库
        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);
        }
Пример #15
0
        public void InitTreelist1(Document doc, DevExpress.XtraTreeList.TreeList treelist)
        {
            treelist.Visible                          = true;
            treelist.Dock                             = System.Windows.Forms.DockStyle.Fill;
            treelist.KeyFieldName                     = "Path";
            treelist.Location                         = new System.Drawing.Point(0, 0);
            treelist.Name                             = "treeList1";
            treelist.OptionsBehavior.Editable         = false;
            treelist.OptionsDragAndDrop.DragNodesMode = DevExpress.XtraTreeList.DragNodesMode.Single;
            treelist.ParentFieldName                  = "ParentPath";
            treelist.RootValue                        = null;
            treelist.SelectImageList                  = this.imageList1;
            treelist.Size                             = new System.Drawing.Size(253, 505);
            treelist.TabIndex                         = 0;
            treelist.GetSelectImage                  += new DevExpress.XtraTreeList.GetSelectImageEventHandler(this.treeList1_GetSelectImage);
            treelist.NodeCellStyle                   += new DevExpress.XtraTreeList.GetCustomNodeCellStyleEventHandler(this.treeList1_NodeCellStyle);
            treelist.ValidatingEditor                += new DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventHandler(this.treeList1_ValidatingEditor);
            treelist.InvalidValueException           += new DevExpress.XtraEditors.Controls.InvalidValueExceptionEventHandler(this.treeList1_InvalidValueException);
            treelist.BeforeDropNode                  += new DevExpress.XtraTreeList.BeforeDropNodeEventHandler(this.treeList1_BeforeDropNode);
            treelist.AfterDropNode                   += new DevExpress.XtraTreeList.AfterDropNodeEventHandler(this.treeList1_AfterDropNode);
            treelist.PopupMenuShowing                += new DevExpress.XtraTreeList.PopupMenuShowingEventHandler(this.treeList1_PopupMenuShowing);
            treelist.CellValueChanged                += new DevExpress.XtraTreeList.CellValueChangedEventHandler(this.treeList1_CellValueChanged);
            treelist.MouseDown                       += new System.Windows.Forms.MouseEventHandler(this.treeList1_MouseDown);

            imageList1.Images.Add(System.Drawing.Image.FromFile(Global.imgPath + @"\a1.ico"));

            imageList1.Images.Add(System.Drawing.Image.FromFile(Global.imgPath + @"\a3.ico"));

            treelist.OptionsBehavior.Editable = false;  //不可编辑

            treelist.OptionsView.ShowIndicator = false; //不显示左边的一列
            treelist.OptionsView.ShowHorzLines = false; //不显示水平线
            treelist.OptionsView.ShowVertLines = false; //垂直线条是否显示

            //聚焦的样式是否只适用于聚焦细胞或所有细胞除了聚焦对象,失去焦点后
            treelist.LookAndFeel.UseWindowsXPTheme    = true;
            treelist.OptionsSelection.InvertSelection = true;

            this.tabNavigationPage1.Controls.Add(treelist);

            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            dbControl.EntityInserted += dataInserted; //添加litedb数据库事件,为了litedb数据更新时同步到这个控件
            dbControl.EntityDeleted  += dataDeleted;  //..删除..
            dbControl.EntityUpdated  += dataUpdated;  //..修改..

            ChangeTreelist1(doc);
            bindProjectData();
        }
Пример #16
0
        }                                                                          //自定义CAD面板
        public GridList()
        {
            InitializeComponent();

            this.gridControl.DataSource = tunnels;//绑定数据源
            gridControl.RefreshDataSource();

            Document        doc       = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            dbControl.EntityInserted += dataInserted;     //添加litedb数据库事件,为了litedb数据更新时同步到这个控件
            dbControl.EntityDeleted  += dataDeleted;      //..删除..
            dbControl.EntityUpdated  += dataUpdated;      //..修改..

            Global.SelectedTunnelChanged += tunnelSelect; //触发巷道选择事件
        }
Пример #17
0
        private void Db_ObjectOpenedForModify(object sender, ObjectEventArgs e)
        {
            if (e.DBObject is BaseTunnel)
            {
                BaseTunnel tunnel = e.DBObject as BaseTunnel;

                Document        doc       = Application.DocumentManager.MdiActiveDocument;
                DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

                DBEntity oldTunnel = dbControl.FindOne
                                         (Query.EQ("HandleValue", e.DBObject.ObjectId.Handle.Value));
                if (oldTunnel != null && tunnel.Location != oldTunnel.Location)
                {
                    tunnel.Location = oldTunnel.Location;
                }
            }
        }
Пример #18
0
        public void AddEvent()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = HostApplicationServices.WorkingDatabase;

            db.SaveComplete += db_SaveComplete;

            db.ObjectErased   += db_ObjectErased;
            db.ObjectAppended += db_ObjectAppend;
            db.ObjectModified += db_ObjectModified;

            db.ObjectOpenedForModify += Db_ObjectOpenedForModify;

            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            dbControl.EntityUpdated += dataUpdated;  //添加litedb数据库事件,为了litedb数据更新时同步到cad数据库
            dbControl.EntityDeleted += dataDeleted;
        }
Пример #19
0
        static string initMainCol(Document doc)
        {
            if (!Fs.DataDirExists())
            {
                return(null);
            }

            DBEntityControl maindb = Project.Instance.GetMainEntCol(doc, false);

            if (!File.Exists(maindb.Name))
            {
                return(null);
            }
            else
            {
                return(maindb.Name);
            }
        }
Пример #20
0
        //删除巷道触发事件
        private void dataDelete(object sender, System.Collections.Generic.List <DBEntity> entities)
        {
            Document        doc       = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            if (dbControl.Senders.Contains(Project.Instance.GetActivePropCtl(doc)))
            {
                return;
            }

            if (propertyGridControl1.SelectedObject == null)
            {
                return;
            }
            DPTunnel dptunnel = new DPTunnel();

            foreach (var entity in entities)
            {
                if (dbt.Count > 0)
                {
                    for (int i = 0; i < dbt.Count; i++)
                    {
                        if (dbt[i].HandleValue == entity.HandleValue)
                        {
                            if (comboBoxEdit1.SelectedIndex == i)
                            {
                                Display("Tunnel", dptunnel);
                            }
                            dbt.RemoveAt(i);
                            comboBoxEdit1.Properties.Items.RemoveAt(i);
                        }
                    }
                    comboBoxEdit1.Text = "选择巷道数" + "(" + dbt.Count.ToString() + ")";
                }
                else
                {
                    comboBoxEdit1.Text = "无选择" + "(" + dbt.Count.ToString() + ")";
                    Display("Tunnel", dptunnel);
                }
                Refresh();
            }
        }
Пример #21
0
        //数据库相关函数
        public DBEntityControl GetTmpEntCol(Document doc)
        {
            string          projectID = GetDwgId(doc);
            DBEntityControl value     = null;

            dbTmpFiles.TryGetValue(projectID, out value);
            if (value != null)
            {
                return(value);
            }
            else
            {
                string          tmpFileNum    = projectID;
                string          tmpDbFilePath = Utils.formatDbFileName(DataPath, tmpFileNum + "(temp)");
                DBEntityControl dbControl     = new DBEntityControl(tmpDbFilePath);
                dbTmpFiles.Add(projectID, dbControl);

                return(dbControl);
            }
        }
Пример #22
0
        //修改已生成巷道的表格坐标数据,图形界面同步刷新
        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);
            }
        }
Пример #23
0
        /// <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);
                }
            }
        }
Пример #24
0
        //数据库dblite修改后事件
        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.GetActivePropCtl(doc)))
            {
                return;
            }

            var selEntity = this.propertyGridControl1.SelectedObject;

            if (selEntity == null)
            {
                return;
            }

            if (selEntity is DPNode && entity is DBNode)
            {
                if (entity.HandleValue != ((DPNode)selEntity).HandleValue)
                {
                    return;
                }
                DPNode displayNode = new DPNode();
                displayNode.SetFromDBEntity(entity as DBNode);
                this.propertyGridControl1.SelectedObject = displayNode;
                this.propertyGridControl1.Refresh();
            }
            else if (selEntity is DPTunnel && entity is DBTunnel)
            {
                if (entity.HandleValue != ((DPTunnel)selEntity).HandleValue)
                {
                    return;
                }
                DPTunnel displayTunnel = new DPTunnel();
                //if (displayTunnel.HandleValue != entity.HandleValue) return;
                displayTunnel.SetFromDBObject(entity as DBTunnel);
                this.propertyGridControl1.SelectedObject = displayTunnel;
                this.propertyGridControl1.Refresh();
            }
        }
Пример #25
0
        //点击右键菜单“删除”触发
        private void t1Delete_ItemClick(object sender, EventArgs e)
        {
            Document doc       = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var      focusNode = treeList1.FocusedNode;

            List <ProjectTreeNode> tree = treeList1.DataSource as List <ProjectTreeNode>;
            var node = getProjectNode(focusNode);

            if (node == null)
            {
                treeList1.Nodes.Remove(focusNode);
                return;
            }

            if (containNode(node, Project.Instance.getCurrentSurface(doc)))
            {
                Autodesk.AutoCAD.ApplicationServices.Application.
                ShowAlertDialog("删除的节点不能包含当前工作面节点");
                return;
            }

            var pNode = node.GetParentNode();

            if (pNode != null)
            {
                pNode.Children.Remove(node);
            }

            List <ProjectTreeLeafNode> ls = new List <ProjectTreeLeafNode>();

            getLeafNodes(node, ls);//得到所有的叶子节点
            treeList1.DeleteNode(focusNode);
            DBEntityControl dbControl = Project.Instance.GetTmpEntCol(doc);

            foreach (var leafNode in ls)
            {
                long handleValue = leafNode.HandleValue;
                dbControl.Delete(Query.EQ("HandleValue", handleValue), this);
            }
            doc.Editor.Regen();
        }
Пример #26
0
        //数据库修改事件的回调
        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();
        }
Пример #27
0
        //数据库插入事件的回调,包含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();
        }
Пример #28
0
        //数据库修改事件的回调
        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();
        }
Пример #29
0
        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);
                    }
                });
            }
        }
Пример #30
0
 //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();
 }