管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-09-04 dbff3d984eb99f474ff63ee6daaadc2c00eee620
TEWin/FrmWin.cs
@@ -34,17 +34,19 @@
        public SGWorld71 SG;
        System.Timers.Timer timer;
        ITerrainLabel71 angleLabel;
        ITerrainPolyline71 angleLine;
        string startName = "OnStart";
        string angleGroupName = "角量算";
        string shpGroupName = "矢量数据";
        string mainUrl = Application.StartupPath;
        System.Timers.Timer timer;
        public FrmWin()
        {
@@ -116,12 +118,25 @@
        void SG_OnLoadFinished(bool bSuccess)
        {
            this.SG.OnLoadFinished -= SG_OnLoadFinished;
            try
            {
                //this.SG.OnLoadFinished -= SG_OnLoadFinished;
                string id = this.SG.ProjectTree.FindItem(startName);
                if (string.IsNullOrEmpty(id)) return;
                var obj = this.SG.ProjectTree.GetObject(id);
                if (obj.ObjectType == ObjectTypeCode.OT_LOCATION)
                {
                    this.SG.Navigate.FlyTo(id);
                }
            }
            catch { }
        }
        void FrmWin_FormClosing(object sender, FormClosingEventArgs e)
        {
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            LogOut.Info("关闭程序.");
        }
        #endregion
@@ -151,6 +166,7 @@
        public void InvokeByCode(int code)
        {
            LogOut.Info("InvokeByCode > " + code);
            switch (code)
            {
                case 0xc0: // 重置鼠标模式
@@ -158,7 +174,7 @@
                case 0xc1: // 打开数据方案/打开显示场景
                    SG.Command.Execute(1001, null); break;
                case 0xc2: // 保存数据方案/保存显示场景
                    SG.Command.Execute(1003, null); break;
                    Save(); break;
                case 0xc3: // 矢量数据(默认为*.shp,支持Excel)
                    SG.Command.Execute(1013, 5); break;
                case 0xc4: // 影像数据(默认为*.tif)
@@ -215,6 +231,10 @@
                    DisplayByAttribute(0, "按照属性显示"); break;
                case 0xdb: // 按照属性设置颜色
                    DisplayByAttribute(1, "按照属性设置颜色"); break;
                case 0xdc: // 打开数据方案
                    OpenPrj(); break;
                case 0xdd: // 保存项目
                    SavePrj(); break;
            }
        }
        #endregion
@@ -317,13 +337,27 @@
            } while (true);
        }
        [DllImport("user32.dll", EntryPoint = "SetClassLongPtr", SetLastError = true)]
        static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
        [DllImport("user32.dll", EntryPoint = "SetClassLong", SetLastError = true)]
        static extern int SetClassLong32(IntPtr hWnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll")]
        static extern IntPtr LoadIcon(IntPtr hInstance, IntPtr iconName);
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        public void DealOsgbLab(IntPtr hWnd)
        {
            SetWindowText(hWnd, "OSGB数据处理工具");
            //ShowWindow(hWnd, 0); // 5
            SetWindowText(hWnd, ConfigurationManager.AppSettings["osgbLabTitle"]);
            Icon icon = new Icon(Path.Combine(mainUrl, @"Resources\favicon.ico"));
            SetClassLongPtr(hWnd, GCLP_HICON + ICON_SMALL, icon.Handle);
            SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle);
            SetClassLongPtr(hWnd, GCLP_HICON, icon.Handle);
            //SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle);
        }
        #endregion
@@ -641,8 +675,8 @@
        private void InvokeOsgbLab()
        {
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            osgbProc = RunExe(GetAbsolutePath("osgblabPath"), null, false);
            DealOsgbLab(osgbProc);
            Process p = RunExe(GetAbsolutePath("osgblabPath"), null, false);
            DealOsgbLab(p);
        }
        private void DisplayByAttribute(int type, String name)
@@ -752,5 +786,84 @@
            return shpTxtPath;
        }
        #endregion
        #region 方案管理
        private void Save()
        {
            //SG.Command.Execute(1003, null);
            SaveLocation();
            this.SG.Project.Save();
        }
        private void OpenPrj()
        {
            string flyPath = ReadPrjPath();
            if (String.IsNullOrEmpty(flyPath)) flyPath = Path.Combine(mainUrl, "see.fly");
            if (!File.Exists(flyPath))
            {
                flyPath = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"];
                if (!flyPath.Contains(":\\")) flyPath = Path.Combine(mainUrl, flyPath);
            }
            this.SG.Open(flyPath);
        }
        private void SavePrj()
        {
            try
            {
                string flyPath = ReadPrjPath();
                if (String.IsNullOrEmpty(flyPath)) flyPath = Path.Combine(mainUrl, "see.fly");
                this.Save();
                //this.SG.Project.SaveAs(flyPath);
                if (this.fly.Equals(flyPath)) return;
                if (File.Exists(flyPath)) File.Delete(flyPath);
                string cmd = string.Format("mklink \"{0}\" \"{1}\"", flyPath, this.fly);
                ExecCmd(new List<string> { cmd });
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        private void SaveLocation()
        {
            try
            {
                string id = this.SG.ProjectTree.FindItem(startName);
                if (!string.IsNullOrEmpty(id)) this.SG.ProjectTree.DeleteItem(id);
                var pos = this.SG.Navigate.GetPosition();
                var loc = this.SG.Creator.CreateLocationHere(this.SG.ProjectTree.RootID, startName);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        private String ReadPrjPath()
        {
            String txt = Path.Combine(mainUrl, "fly.txt");
            if (!File.Exists(txt)) return null;
            try
            {
                using (StreamReader sr = new StreamReader(txt))
                {
                    return sr.ReadLine();
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
        #endregion
    }
}