| | |
| | | |
| | | 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() |
| | | { |
| | |
| | | |
| | | 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) |
| | |
| | | |
| | | public void InvokeByCode(int code) |
| | | { |
| | | LogOut.Info("InvokeByCode > 0x" + code.ToString("x")); |
| | | switch (code) |
| | | { |
| | | case 0xc0: // 重置鼠标模式 |
| | |
| | | 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) |
| | |
| | | DisplayByAttribute(0, "按照属性显示"); break; |
| | | case 0xdb: // 按照属性设置颜色 |
| | | DisplayByAttribute(1, "按照属性设置颜色"); break; |
| | | case 0xdc: // 打开数据方案 |
| | | OpenPrj(); break; |
| | | case 0xdd: // 保存项目 |
| | | SavePrj(); break; |
| | | } |
| | | } |
| | | #endregion |
| | |
| | | return shpTxtPath; |
| | | } |
| | | #endregion |
| | | |
| | | #region 方案管理 |
| | | private void Save() |
| | | { |
| | | SaveLocation(); |
| | | this.SG.Command.Execute(1019, 0); // Capture Tree State |
| | | SG.Command.Execute(1003, 0); // this.SG.Project.Save(); |
| | | } |
| | | |
| | | private void SaveAs(string flyPath) |
| | | { |
| | | SaveLocation(); |
| | | this.SG.Command.Execute(1019, 0); // Capture Tree State |
| | | this.SG.Project.SaveAs(flyPath); |
| | | } |
| | | |
| | | private void OpenPrj() |
| | | { |
| | | string flyPath = ReadPrjPath(); |
| | | if (String.IsNullOrEmpty(flyPath)) flyPath = this.fly; // 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 = this.fly; // 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 }); |
| | | CreateShortcut(flyPath, this.fly); |
| | | } |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | private String GetSavePath() |
| | | { |
| | | string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); |
| | | string tePathName = ConfigurationManager.AppSettings["tePath"].Contains("SmartEarth") ? "SmartEarth" : "Skyline"; |
| | | |
| | | return Path.Combine(appData, tePathName, "TerraExplorer"); |
| | | } |
| | | |
| | | public static void CreateShortcut(string shortcutPath, string targetPath, string description = null, string iconLocation = null) |
| | | { |
| | | var shell = new IWshRuntimeLibrary.WshShell(); |
| | | var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath + ".lnk"); // 创建快捷方式对象 |
| | | shortcut.TargetPath = targetPath; // 指定目标路径 |
| | | shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); // 设置起始位置 |
| | | shortcut.WindowStyle = 1; // 设置运行方式,默认为常规窗口 |
| | | shortcut.Description = description; // 设置备注 |
| | | shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; // 设置图标路径 |
| | | shortcut.Save(); // 保存快捷方式 |
| | | } |
| | | #endregion |
| | | } |
| | | } |