管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-01-02 dce9770dca54e69085948d3f286f289489abeb4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TerraExplorerX;
using TETree;
using TEWin.CS;
 
namespace TEWin
{
    public partial class FrmWin : Form
    {
        FrmTree tree;
 
        FrmTool tool;
 
        public SGWorld74 SG = null;
 
        public static string StartupPath
        {
            get
            {
                return System.Windows.Forms.Application.StartupPath;
            }
        }
 
        public FrmWin()
        {
            InitializeComponent();
            this.Load += FrmWeb_Load;
            this.FormClosed += FrmWin_FormClosed;
        }
 
        void FrmWeb_Load(object sender, EventArgs e)
        {
            try
            {
                LogOut.Info("开始运行..");
 
                string fly = Path.Combine(StartupPath, "Resources\\sample.fly");
                if (!File.Exists(fly))
                {
                    LogOut.Error("Fly文件不存在:" + fly);
                    return;
                }
 
                SG = new SGWorld74();
                SG.OnLoadFinished += SG_OnLoadFinished;
                SG.Open(fly);
 
                tree = new FrmTree();
                tree.Show(this);
 
                string isTest = ConfigurationManager.AppSettings["isTest"];
                if ("1".Equals(isTest))
                {
                    tool = new FrmTool(this);
                    tool.Show();
                }
                else
                {
                    this.WindowState = FormWindowState.Maximized;
                    tree.WindowState = FormWindowState.Maximized;
                }
 
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
 
        void SG_OnLoadFinished(bool bSuccess)
        {
            //
        }
 
        void FrmWin_FormClosed(object sender, FormClosedEventArgs e)
        {
            LogOut.Info("关闭程序.");
        }
 
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0xc0: // 重置鼠标模式
                    SG.Window.SetInputMode(0);
                    break;
                case 0xc1: // 打开数据方案/打开显示场景
                    SG.Command.Execute(1001, null);
                    break;
                case 0xc2: // 保存数据方案/保存显示场景
                    SG.Command.Execute(1003, null);
                    break;
                case 0xc3: // 矢量数据(默认为*.shp,支持Excel)
                    SG.Command.Execute(1013, 5);
                    break;
                case 0xc4: // 影像数据(默认为*.tif)
                    SG.Command.Execute(1014, 9);
                    break;
                case 0xc5: // 地形数据(默认为*.tif)
                    SG.Command.Execute(1014, 26);
                    break;
                case 0xc6: // 模型数据(*.osgb)
                    //SG.Command.Execute(2342, null);
                    string path = Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe");
                    string args = " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb";
                    ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" });
                    RunExe(path, args, false);
                    break;
                case 0xc7: // 模型数据(*.obj)
                    SG.Command.Execute(1012, 13);
                    break;
                case 0xc8: // 基础编辑(选择对象)
                    SG.Command.Execute(1021, null);
                    break;
                case 0xc9: // 点量算(坐标+高程)
                    SG.Command.Execute(1023, null);
                    break;
                case 0xca: // 点量算(坡度+坡向)
                    //
                    break;
                case 0xcb: // 距离量算
                    SG.Command.Execute(2356, null);
                    break;
                case 0xcc: // 面积量算
                    if (SG.Command.IsChecked(2359, null))
                        SG.Window.SetInputMode(0);
                    else
                        SG.Command.Execute(2359, null);
                    break;
 
                default:
                    base.DefWndProc(ref m);
                    break;
            }
        }
 
        public void InvokeProc(int code)
        {
            Message m = new Message();
            m.Msg = code;
 
            this.DefWndProc(ref m);
        }
 
        public void RunExe(string path, string args, bool noWindow = true)
        {
            Process p = new Process();
            p.StartInfo.FileName = path;
            p.StartInfo.Arguments = args;
            p.StartInfo.CreateNoWindow = noWindow;
            p.StartInfo.UseShellExecute = false;
            p.Start();
        }
 
        public static string ExecCmd(List<string> list)
        {
            string str = null;
            Process p = null;
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
 
                StreamWriter si = p.StandardInput;
                StreamReader se = p.StandardError;
 
                LogOut.Info("cmd = " + string.Join(",", list));
                si.AutoFlush = true;
                foreach (string cmd in list)
                {
                    si.WriteLine(cmd);
                }
                si.WriteLine("exit");
 
                str = se.ReadToEnd();
                se.Close();
                si.Close();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                str = ex.Message;
            }
            finally
            {
                if (p != null)
                {
                    p.Close();
                }
            }
 
            return str;
        }
    }
}