コード例 #1
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();
            }
        }
コード例 #2
0
        public static void Init()
        {
            Document      doc         = Application.DocumentManager.MdiActiveDocument;
            DBTreeControl treeControl = Project.Instance.GetMainTreeCol(doc);

            ProjectTreeNode        currentWorkingSurface;
            List <ProjectTreeNode> tree = treeControl.RebuldFromDB(out currentWorkingSurface);

            Project.Instance.CreateProjectTree(doc, tree);
            Project.Instance.setCurrentSurface(doc, currentWorkingSurface);
        }
コード例 #3
0
ファイル: PROJECT.cs プロジェクト: presscad/DrawTunnel
        public DBTreeControl GetMainTreeCol(Document doc)
        {
            string        projectID = GetDwgId(doc);
            DBTreeControl value     = null;

            dbMainTreeFiles.TryGetValue(projectID, out value);
            if (value != null)
            {
                return(value);
            }
            else
            {
                string        mainFileNum    = projectID;
                string        mainDbFilePath = Utils.formatDbFileName(DataPath, mainFileNum);
                DBTreeControl dbControl      = new DBTreeControl(mainDbFilePath);
                dbMainTreeFiles.Add(projectID, dbControl);

                return(dbControl);
            }
        }