예제 #1
0
        public static bool DeleteTerrain(string nodeNamesStr)
        {
            bool b = false;

            try
            {
                //从setup文件中删除有关地形的相应的段
                MainWindow.setupStr = MainWindow.setupStr.Remove(MainWindow.setupStr.IndexOf("begin_<globals>"), MainWindow.setupStr.IndexOf("end_<globals>") - MainWindow.setupStr.IndexOf("begin_<globals>") + 15);
                MainWindow.setupStr = MainWindow.setupStr.Remove(MainWindow.setupStr.IndexOf("begin_<studyarea>"), MainWindow.setupStr.IndexOf("end_<studyarea>") - MainWindow.setupStr.IndexOf("begin_<studyarea>") + "end_<studyarea>".Length + 2);
                MainWindow.setupStr = MainWindow.setupStr.Remove(MainWindow.setupStr.IndexOf("begin_<feature>"), MainWindow.setupStr.IndexOf("end_<feature>") - MainWindow.setupStr.IndexOf("begin_<feature>") + "end_<feature>".Length + 2);
                //从工程树中删除原来的地形结点
                MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes[0].Nodes.Remove(MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes[0].Nodes[0]);
                //在.info文件中找出地形的名字,经纬度的大小字符串
                string iniTerrain   = StringFound.FoundBackStr("<terrain>", nodeNamesStr, false);
                string iniLongitude = StringFound.FoundBackStr("<longitude>", nodeNamesStr, false);
                string iniLatitude  = StringFound.FoundBackStr("<latitude>", nodeNamesStr, false);
                //从info文件中删除原来添加的地形的相关信息,然后将删除后的字符串写到info文件中
                nodeNamesStr = nodeNamesStr.Remove(nodeNamesStr.IndexOf("<terrain>"), 12 + iniTerrain.Length);
                nodeNamesStr = nodeNamesStr.Remove(nodeNamesStr.IndexOf("<longitude>"), 14 + iniLongitude.Length);
                nodeNamesStr = nodeNamesStr.Remove(nodeNamesStr.IndexOf("<latitude>"), 13 + iniLatitude.Length);
                FileOperation.WriteFile(nodeNamesStr, MainWindow.nodeInfoFullPath, false);
                //将原来添加的地形从工程文件中删除
                File.Delete(MainWindow.projectRealPath + "\\" + iniTerrain);
                File.Delete(MainWindow.projectRealPath + "\\" + iniTerrain + ".terinfo");
                b = true;
            }
            catch (Exception e)
            {
                //如果捕获到异常,则表示删除失败。
                LogFileManager.ObjLog.fatal(e.Message, e);
                b = false;
            }
            return(b);
        }
예제 #2
0
        //根据索引字符串找出其后的yes或no,再根据CheckBox的状态去修改yes或no
        void ResultSet(CheckBox ch, string indexStr)
        {
            int site = MainWindow.setupStr.IndexOf(indexStr) + indexStr.Length + 1;
            //找出yes或no
            string initStr = StringFound.FoundBackStr(indexStr, MainWindow.setupStr, true);

            //当初始是no
            if (initStr.Equals("no"))
            {
                //如果CheckBox被选中
                if (ch.Checked)
                {
                    MainWindow.setupStr = MainWindow.setupStr.Remove(site, 2);
                    MainWindow.setupStr = MainWindow.setupStr.Insert(site, "yes");
                }
            }
            //当初始是yes
            else
            {
                //CheckBox没被选中
                if (!ch.Checked)
                {
                    MainWindow.setupStr = MainWindow.setupStr.Remove(site, 3);
                    MainWindow.setupStr = MainWindow.setupStr.Insert(site, "no");
                }
            }
        }
예제 #3
0
        //将单击确定按钮后新插入的接收机的编号替换为原来的编号,并利用原来保存的位置信息写到相应的文件中
        private static bool rxStrRecoverInitReceiverNum(TreeNode currentNode, string initReceiverNum, int initialReceiverBlockSite, int initialReceiverNodeSite)
        {
            bool b = false;

            //将单击新建接收机窗口中确定按钮后rx文件中新插入的接收机块提取出来 放在newInsertReceiverBlock
            try
            {
                string rxFilePath = MainWindow.projectRealPath + "\\" + MainWindow.onlyProjectName + ".rx";
                string rxFileStr  = FileOperation.ReadFile(rxFilePath);

                string beginStr = null;
                string endStr   = null;
                switch (currentNode.Parent.Text)
                {
                case "点状分布":
                    beginStr = SetupContent.pointReceiverOfRxStr0;
                    endStr   = SetupContent.transmitterStr24OfTr;
                    break;

                case "区域分布":
                    beginStr = SetupContent.gridReceiverOfRxStr0;
                    endStr   = SetupContent.gridReceiverOfRxStr11;
                    break;
                }
                int start = rxFileStr.LastIndexOf(beginStr);
                int end   = rxFileStr.LastIndexOf(endStr) + endStr.Length + 2;
                //提取出来单击新建接收机确定按钮后的新添加的相应的接收机块
                string newInsertReceiverBlock = rxFileStr.Substring(start, end - start);
                //将新增加的接收机块删除
                rxFileStr = rxFileStr.Remove(start, end - start);

                string receiverName = StringFound.FoundBackStr(beginStr, newInsertReceiverBlock, true);
                //获得新增加接收机的编号
                string newReceiverNum = GetReceiverNumLine(beginStr, receiverName, newInsertReceiverBlock);
                //用原来接收机的编号去代替新加接收机的编号
                newInsertReceiverBlock = newInsertReceiverBlock.Replace(newReceiverNum, initReceiverNum);
                //将修改了接收机编号后的接收机块插入到setupStr中
                rxFileStr = rxFileStr.Insert(initialReceiverBlockSite, newInsertReceiverBlock);
                FileOperation.WriteFile(rxFileStr, rxFilePath, false);

                string receiverNodeInfo = FileOperation.ReadFile(MainWindow.nodeInfoFullPath);

                //将更改后的接收机信息插入到原来的位置
                receiverNodeInfo = receiverNodeInfo.Insert(initialReceiverNodeSite, beginStr + " " + receiverName + "\r\n");
                //在info文件中删除增加的接收机结点信息
                receiverNodeInfo = receiverNodeInfo.Remove(receiverNodeInfo.LastIndexOf(beginStr));

                FileOperation.WriteFile(receiverNodeInfo, MainWindow.nodeInfoFullPath, false);
                b = true;
            }
            catch (Exception e)
            {
                LogFileManager.ObjLog.fatal(e.Message, e);
                //return false;
            }
            return(b);
        }
예제 #4
0
 //选中天线后,波形自动加载
 private void newTransmitterAntennaName_comboBox3_SelectedValueChanged(object sender, EventArgs e)
 {
     if (File.Exists(MainWindow.relationOfAntAndWavePath))
     {
         string antennaAndWaveStr = FileOperation.ReadFile(MainWindow.relationOfAntAndWavePath);
         string waveOfAntenna     = StringFound.FoundBackStr(SetupContent.antennaIndeStr + " " + (string)newTransmitterAntennaName_comboBox3.SelectedItem + "#", antennaAndWaveStr);
         //char[] sep = { '#' };
         //string[] waveStr = waveOfAntenna.Split(sep);
         //newTransmitterWaveformName_textBox1.Text = waveStr[1];
         newTransmitterWaveformName_textBox1.Text = waveOfAntenna;
     }
 }
예제 #5
0
        private static bool setupStrRecoverInitWaveformNum(TreeNode currentNode, string initWaveformNum, int initialWaveformBlockSite, int initialWaveformNodeSite)
        {
            bool b = false;

            //将单击新建波形窗口中确定按钮后插入的新波形块提取出来 放在newInsertAntennaBlock
            try
            {
                int start = MainWindow.setupStr.LastIndexOf(SetupContent.waveFormStr1);
                int end   = MainWindow.setupStr.LastIndexOf(SetupContent.waveFormStr2 + "\r\n") + (SetupContent.waveFormStr2 + "\r\n").Length;
                //提取出来单击新建天线确定按钮后的心添加的相应的天线块
                string newInsertWaveformBlock = MainWindow.setupStr.Substring(start, end - start);
                //将新增加的天线块删除
                MainWindow.setupStr = MainWindow.setupStr.Remove(start, end - start);

                string waveformName = StringFound.FoundBackStr(SetupContent.waveFormStr1, newInsertWaveformBlock, true);
                //获得新增加天线的编号
                string newAntennaNum = GetWaveformNumLine(waveformName, newInsertWaveformBlock);
                //用原来天线的编号去代替新加天线的编号
                newInsertWaveformBlock = newInsertWaveformBlock.Replace(newAntennaNum, initWaveformNum);
                //将修改了天线编号后的天线块插入到setupStr中
                MainWindow.setupStr = MainWindow.setupStr.Insert(initialWaveformBlockSite, newInsertWaveformBlock);
                FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);
                if (System.IO.File.Exists(MainWindow.relationOfAntAndWavePath))
                {
                    string updatedWaveformAndAntennaMatch = FileOperation.ReadFile(MainWindow.relationOfAntAndWavePath);
                    updatedWaveformAndAntennaMatch = updatedWaveformAndAntennaMatch.Replace("#" + currentNode.Text + "\r\n", "#" + waveformName + "\r\n");
                    FileOperation.WriteFile(updatedWaveformAndAntennaMatch, MainWindow.relationOfAntAndWavePath, false);
                }
                string waveformNodeInfo = FileOperation.ReadFile(MainWindow.nodeInfoFullPath);
                //在info文件中先删除增加的天线结点信息
                waveformNodeInfo = waveformNodeInfo.Remove(waveformNodeInfo.LastIndexOf(SetupContent.waveFormStr1));
                //将更改后的天线信息插入到原来的位置
                waveformNodeInfo = waveformNodeInfo.Insert(initialWaveformNodeSite, SetupContent.waveFormStr1 + " " + waveformName + "\r\n");
                FileOperation.WriteFile(waveformNodeInfo, MainWindow.nodeInfoFullPath, false);
                b = true;
            }
            catch (Exception e)
            {
                LogFileManager.ObjLog.fatal(e.Message, e);
            }
            return(b);
        }
예제 #6
0
        //将更改后辐射源的编号调整为原来的编号
        private static bool trStrRecoverInitTransmitterNum(string initTransmitterNum, int initialTransmitterBlockSite, int initialTransmitterNodeSite)
        {
            bool b = false;

            //将单击新建波形窗口中确定按钮后tr文件中新插入的辐射源块提取出来 放在newInsertTransmitterBlock
            try
            {
                string trFilePath = MainWindow.projectRealPath + "\\" + MainWindow.onlyProjectName + ".tx";
                string trFileStr  = FileOperation.ReadFile(trFilePath);
                int    start      = trFileStr.LastIndexOf(SetupContent.transmitterStr1OfTr);
                //int end = trFileStr.LastIndexOf(SetupContent.transmitterStr24OfTr + "\r\n") +( SetupContent.transmitterStr24OfTr + "\r\n").Length ;
                int end = trFileStr.LastIndexOf("MHZ\r\n") + ("MHZ\r\n").Length;

                //提取出来单击新建辐射源确定按钮后的新添加的相应的天线块
                string newInsertTransmitterBlock = trFileStr.Substring(start, end - start);
                //将新增加的辐射源块删除
                trFileStr = trFileStr.Remove(start, end - start);
                //在更改时可能会改变辐射源的名字,因此需要在提取出辐射源的名字
                string transmitterName = StringFound.FoundBackStr(SetupContent.transmitterStr1OfTr, newInsertTransmitterBlock, true);
                //获得新增加辐射源的编号
                string newTransmitterNum = GetTransmitterNumLine(transmitterName, newInsertTransmitterBlock);
                //用原来天线的编号去代替新加辐射源的编号
                newInsertTransmitterBlock = newInsertTransmitterBlock.Replace(newTransmitterNum, initTransmitterNum);
                //将修改了辐射源编号后的天线块写入到tr文件中
                trFileStr = trFileStr.Insert(initialTransmitterBlockSite, newInsertTransmitterBlock);
                FileOperation.WriteFile(trFileStr, trFilePath, false);

                string transmitterNodeInfo = FileOperation.ReadFile(MainWindow.nodeInfoFullPath);
                //将更改后的辐射源信息插入到原来的位置
                transmitterNodeInfo = transmitterNodeInfo.Insert(initialTransmitterNodeSite, SetupContent.transmitterStr1Ofsetup + " " + transmitterName + "\r\n");
                //在info文件中先删除增加的辐射源节点信息
                transmitterNodeInfo = transmitterNodeInfo.Remove(transmitterNodeInfo.LastIndexOf(SetupContent.transmitterStr1Ofsetup));
                FileOperation.WriteFile(transmitterNodeInfo, MainWindow.nodeInfoFullPath, false);
                b = true;
            }
            catch (Exception e)
            {
                LogFileManager.ObjLog.fatal(e.Message, e);
            }
            return(b);
        }
예제 #7
0
        //删除辐射源后应及时更新setup文件中关于辐射源的信息
        private static bool TransmitterUpdateOfSetup()
        {
            bool   b          = false;
            string trFilePath = MainWindow.projectRealPath + "\\" + MainWindow.onlyProjectName + ".tx";
            string trFileStr  = FileOperation.ReadFile(trFilePath);

            try
            {
                //当tr文件中的辐射源全部被删除时
                if (trFileStr.Length <= 0)
                {
                    //辐射源全部被删除时,要删除tr文件
                    File.Delete(trFilePath);
                    //辐射源全部被删除时,setup文件中关于辐射源的信息也要被删除
                    int start = MainWindow.setupStr.IndexOf(SetupContent.transmitterStr1Ofsetup + "\r\n");
                    int end   = MainWindow.setupStr.IndexOf(SetupContent.transmitterStr4Ofsetup + "\r\n") + SetupContent.transmitterStr4Ofsetup.Length;
                    MainWindow.setupStr = MainWindow.setupStr.Remove(start, end - start);
                    //将删除辐射源后的setupStr保存到setup文件中
                    FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);
                }
                //当tr文件中的辐射源没有全部被删除时
                else
                {
                    //使setup文件中辐射源的数量减1
                    string transmitterCountStr     = StringFound.FoundBackStr("\nFirstAvailableTxNumber", MainWindow.setupStr, true);
                    string transmitterCountLineOld = "\nFirstAvailableTxNumber " + transmitterCountStr + "\r\n";
                    int    transmitterCount        = int.Parse(transmitterCountStr);
                    transmitterCount = transmitterCount - 1;
                    string transmitterCountLineNew = "\nFirstAvailableTxNumber " + transmitterCount.ToString() + "\r\n";
                    MainWindow.setupStr = MainWindow.setupStr.Replace(transmitterCountLineOld, transmitterCountLineNew);
                    FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);
                }
                b = true;
            }
            catch (Exception e)
            {
                LogFileManager.ObjLog.fatal(e.Message, e);
            }
            return(b);
        }
예제 #8
0
        //删除接收机时要更新setup文件中接收机的数目
        private static bool ReceiverUpdateOfSetup()
        {
            bool   b          = false;
            string rxFilePath = MainWindow.projectRealPath + "\\" + MainWindow.onlyProjectName + ".rx";
            string rxFileStr  = FileOperation.ReadFile(rxFilePath);

            try
            {
                //如果接收机全部被删除
                if (rxFileStr.Length <= 0)//删除后
                {
                    File.Delete(rxFilePath);

                    int start = MainWindow.setupStr.IndexOf(SetupContent.receiverOfSetupStr0 + "\r\n");
                    int end   = MainWindow.setupStr.IndexOf(SetupContent.receiverOfSetupStr3 + "\r\n") + (SetupContent.receiverOfSetupStr3 + "\r\n").Length;
                    MainWindow.setupStr = MainWindow.setupStr.Remove(start, end - start);
                    FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);
                }
                //接收机没有全部被删除
                else
                {
                    string receiverCountStr     = StringFound.FoundBackStr("\nFirstAvailableRxNumber", MainWindow.setupStr, true);
                    string receiverCountLineOld = "\nFirstAvailableRxNumber " + receiverCountStr + "\r\n";
                    int    receiverCount        = int.Parse(receiverCountStr);
                    receiverCount = receiverCount - 1;
                    string receiverCountLineNew = "\nFirstAvailableRxNumber " + receiverCount.ToString() + "\r\n";
                    MainWindow.setupStr = MainWindow.setupStr.Replace(receiverCountLineOld, receiverCountLineNew);
                    FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);
                }
                b = true;
            }
            catch (Exception e)
            {
                LogFileManager.ObjLog.fatal(e.Message, e);
            }
            return(b);
        }
예제 #9
0
        /*第一个string数组总共有8个元素
         * 每个元素都包含两部分,一是标识字符串,另一是内容和"\r\n"*/
        public string InsertAntenna8(string[] contents, string waveNameOfAntenna, string constStr1, string constStr2)
        {
            int    insertSite   = 0;
            bool   firstAntenna = false;
            string antennaCount = null;

            //插入的是第一个天线
            if (sourceString.LastIndexOf(constStr1) == -1)
            {
                insertSite   = sourceString.LastIndexOf(constStr2) + constStr2.Length + 2;
                firstAntenna = true;
                //当是第一次添加天线时,在traninfo文件中写入antenna 0
                antennaCount = "0";
            }
            //插入的不是第一个天线
            else
            {
                //插入的起始位置
                insertSite = sourceString.LastIndexOf(constStr1) + constStr1.Length + 2;
                //插入的不是第一个天线,算出天线的编号
                int antennaSite = sourceString.LastIndexOf("\nantenna") + 9;//10是\nantenna的长度
                while (sourceString[antennaSite] != '\r')
                {
                    antennaCount = antennaCount + sourceString[antennaSite++];
                }
                int b = int.Parse(antennaCount) + 1;
                antennaCount = string.Format("{0:##}", b);
            }
            //用户没有在combox中选择波形名称,则插入默认的正弦波
            //if (waveNameOfAntenna==null)
            //{
            //    string[] sinStr = { "Sinusoid", "Sinusoid", "1000000000", "1000000", "0" };
            //    sourceString = InsertWaveform5(sinStr, SetupContent.waveFormStr2, SetupContent.waveFormStr3,true);

            //}
            //else
            //{
            string[] waveNames = new string[30];
            waveNames = waveformNames(SetupContent.waveFormStr1);
            //插入setup文件中的波形
            sourceString = sourceString.Insert(insertSite, contents[0]);
            insertSite   = insertSite + contents[0].Length;
            //是第一次添加天线,天线的编号
            if (firstAntenna)
            {
                sourceString = sourceString.Insert(insertSite, "antenna " + "0" + "\r\n");
                insertSite   = insertSite + 11;
            }
            //不是第一次添加天线,天线的编号
            else
            {
                sourceString = sourceString.Insert(insertSite, "antenna " + antennaCount + "\r\n");
                insertSite   = insertSite + 10 + antennaCount.Length;
            }
            sourceString = sourceString.Insert(insertSite, contents[1]);
            insertSite   = insertSite + contents[1].Length;
            //找到最大的waveform编号
            //根据选中的波形名称去获得对应的波形编号
            string waveStr      = null;
            int    waveNameSite = sourceString.IndexOf(SetupContent.waveFormStr1 + " " + waveNameOfAntenna);

            if (waveNameSite != -1)
            {
                //由begin_<Waveform>去获取waveform这一行字符串。第二次循环才获得waveform这一行字符串
                for (int j = 0; j < 2; j++)
                {
                    waveStr = null;
                    while (sourceString[waveNameSite + (SetupContent.waveFormStr1 + " " + waveNameOfAntenna).Length + 2] != '\r')
                    {
                        waveStr = waveStr + sourceString[waveNameSite + (SetupContent.waveFormStr1 + " " + waveNameOfAntenna).Length + 2];
                        waveNameSite++;
                    }
                    //跳过\r\n这两个字符
                    waveNameSite = waveNameSite + 2;
                }
            }
            string antennaName = StringFound.FoundBackStr(SetupContent.antennaStr1, contents[0], true);

            //将发射机需要的信息存放到.transinfo文件中
            FileOperation.WriteFile(contents[0] + "antenna " + antennaCount + "\r\n" + waveStr + "\r\n" + SetupContent.antennaStr3 + " " + antennaName + "\r\n", MainWindow.transInfoFullPath, true);

            //将新建的天线和其对应的波形保存在.match文件中
            string antennaNameTemp = StringFound.FoundBackStr(SetupContent.antennaIndeStr, contents[0], true);

            //FileOperation.WriteLineFile(SetupContent.antennaIndeStr +" "+ antennaNameTemp + "#" + waveStr + "#" + waveNameOfAntenna, MainWindow.relationOfAntAndWavePath,true);
            FileOperation.WriteLineFile(SetupContent.antennaIndeStr + " " + antennaNameTemp + "#" + waveNameOfAntenna, MainWindow.relationOfAntAndWavePath, true);

            sourceString = sourceString.Insert(insertSite, waveStr + "\r\n");
            insertSite   = insertSite + waveStr.Length + 2;

            //contents[2]到contents[7]都是按相同的规律插入
            for (int j = 2; j < 8; j++)
            {
                sourceString = sourceString.Insert(insertSite, contents[j]);
                insertSite   = insertSite + contents[j].Length;
            }
            //}
            return(sourceString);
        }
예제 #10
0
        private void newTerrainOk__Click(object sender, EventArgs e)
        {
            //确保先创建工程。否则插入数据将会出错
            if (MainWindow.mProjectFullName == null)
            {
                //MessageBox.Show("请先创建一个工程之后再从本地添加地形!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }
            else
            {
                //必须先浏览地形,再单击确定
                if (openTerrainDialog.FileName != "")
                {
                    //查找begin_<project>后面的字符串temp
                    string temp = StringFound.FoundBackStr("begin_<project>", MainWindow.setupStr, true);
                    if (temp == null)
                    {
                        MessageBox.Show("文件被破坏,产生错误错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        //从信息文件中读取信息
                        string nodeNamesStr = FileOperation.ReadFile(MainWindow.nodeInfoFullPath);
                        //若信息文件中已经添加了地形,再次添加时要从setup文件先删除原来的地形,从从工程树中删除原来的地形
                        if (nodeNamesStr.LastIndexOf("<terrain>") != -1)
                        {
                            DialogResult result = MessageBox.Show("您确定要替换原来添加的地形吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                            if (result == DialogResult.OK)
                            {
                                if (!TerrainOperation.DeleteTerrain(nodeNamesStr))
                                {
                                    MessageBox.Show("对不起,发生错误,删除失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                                MessageBox.Show("前一个地图已被替换", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                return;
                            }
                        }
                        //向全局字符串setupStr插入<global>段
                        int    startPosiGlobal = MainWindow.setupStr.IndexOf("begin_<project>") + 15 + temp.Length + 3;
                        string globalStr       = SetupContent.terrainGlobalFixedStr1 + longtitude_textBox1.Text + "\r\n"
                                                 + SetupContent.terrainGlobalFixedStr2 + latitude_textBox3.Text + "\r\n"
                                                 + SetupContent.terrainGlobalFixedStr3 + "\r\n";
                        MainWindow.setupStr = MainWindow.setupStr.Insert(startPosiGlobal, globalStr);
                        //向全局字符串插入<studyarea>段
                        int    startPosiStudyArea = MainWindow.setupStr.IndexOf("FirstAvailableStudyAreaNumber") + 33;
                        string studyAreaStr       = SetupContent.terrainStudyAreaStr1 + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr2 + longtitude_textBox1.Text + "\r\n"
                                                    + SetupContent.terrainGlobalFixedStr2 + latitude_textBox3.Text + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr3 + terrainValueStr[2] + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr4 + terrainValueStr[3] + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr5 + "\r\n" + terrainValueStr[4] + "\r\n"
                                                    + terrainValueStr[5] + "\r\n" + terrainValueStr[6] + "\r\n" + terrainValueStr[7] + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr6 + "\r\n";
                        MainWindow.setupStr = MainWindow.setupStr.Insert(startPosiStudyArea, studyAreaStr);
                        //向全局字符串插入<feature>段
                        int    startPosiFeature = MainWindow.setupStr.IndexOf("end_<studyarea>") + 17;
                        string featureStr       = SetupContent.terrainFeatureFixedStr1 + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr2 + "0" + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr3 + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr4
                                                  + MainWindow.projectRealPath + "\\" + terrainname_textBox4.Text + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr5 + "\r\n";
                        MainWindow.setupStr = MainWindow.setupStr.Insert(startPosiFeature, featureStr);

                        string t           = openTerrainDialog.FileName;
                        string terFileName = t.Substring(t.LastIndexOf('\\') + 1, t.Length - 1 - t.LastIndexOf('\\'));
                        //将ter文件拷贝到工程目录下
                        FileCopyUI.FileCopy(openTerrainDialog.FileName, MainWindow.projectRealPath + "\\" + terFileName);
                        FileCopyUI.FileCopy(openTerrainDialog.FileName + ".terinfo", MainWindow.projectRealPath + "\\" + terFileName + ".terinfo");

                        //将工程树的节点信息写到.info文件中
                        FileOperation.WriteLineFile(SetupContent.terrainIndeStr + " " + terFileName, MainWindow.nodeInfoFullPath, true);
                        FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);

                        MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes[0].Nodes.Add(terFileName);
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("请您从本地添加地形!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #11
0
        private void newTerrainWindowOk_button1_Click(object sender, EventArgs e)
        {
            addTerrain = client.iGetTer((string)newTerrainName_comboBox1.SelectedItem);
            LogFileManager.ObjLog.info((string)newTerrainName_comboBox1.SelectedItem);
            //确保先创建工程。否则插入数据将会出错
            if (MainWindow.mProjectFullName == null)
            {
                MessageBox.Show("请先创建一个工程之后再从本地添加地形!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                //必须先选择地形,再单击确定
                if ((string)newTerrainName_comboBox1.SelectedItem != "")
                {
                    string t = addTerrain.path;
                    //将经纬度存储到.setup.info文件中
                    FileOperation.WriteLineFile(SetupContent.longitudeIndeStr + " " + addTerrain.originX, MainWindow.nodeInfoFullPath, true);
                    FileOperation.WriteLineFile(SetupContent.latitudeIndeStr + " " + addTerrain.originY, MainWindow.nodeInfoFullPath, true);
                    if (File.Exists(t) == false)
                    {
                        MessageBox.Show("数据库中已不存在此地图", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    //查找begin_<project>后面的字符串temp
                    string temp = StringFound.FoundBackStr("begin_<project>", MainWindow.setupStr, true);
                    if (temp == null)
                    {
                        MessageBox.Show("程序内部发生错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        //查找begin_<project>后面的字符串temp
                        string nodeNamesStr = FileOperation.ReadFile(MainWindow.nodeInfoFullPath);
                        //若信息文件中已经添加了地形,再次添加时要从setup文件先删除原来的地形,从从工程树中删除原来的地形
                        if (nodeNamesStr.LastIndexOf("<terrain>") != -1)
                        {
                            DialogResult result = MessageBox.Show("您确定要替换原来添加的地形吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                            if (result == DialogResult.OK)
                            {
                                if (!TerrainOperation.DeleteTerrain(nodeNamesStr))
                                {
                                    MessageBox.Show("对不起,程序内部发生错误,删除失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                                MessageBox.Show("前一个地图已被替换", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                return;
                            }
                        }

                        //向全局字符串setupStr插入<global>段
                        int    startPosiGlobal = MainWindow.setupStr.IndexOf("begin_<project>") + 15 + temp.Length + 3;
                        string globalStr       = SetupContent.terrainGlobalFixedStr1 + newTerrainLongtitude_textBox2.Text + "\r\n"
                                                 + SetupContent.terrainGlobalFixedStr2 + newTerrainLatitude_textBox3.Text + "\r\n"
                                                 + SetupContent.terrainGlobalFixedStr3 + "\r\n";
                        MainWindow.setupStr = MainWindow.setupStr.Insert(startPosiGlobal, globalStr);
                        ////向全局字符串插入<studyarea>段  其中zmin zmax及地图顶点先设为默认值
                        int    startPosiStudyArea = MainWindow.setupStr.IndexOf("FirstAvailableStudyAreaNumber") + 33;
                        string studyAreaStr       = SetupContent.terrainStudyAreaStr1 + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr2 + newTerrainLongtitude_textBox2.Text + "\r\n"
                                                    + SetupContent.terrainGlobalFixedStr2 + newTerrainLatitude_textBox3.Text + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr3 + addTerrain.Zmin.ToString() + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr4 + addTerrain.Zmax.ToString() + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr5 + "\r\n"
                                                    + addTerrain.Vertex1X + " " + addTerrain.Vertex1Y + " " + addTerrain.Vertex1Z + "\r\n"
                                                    + addTerrain.Vertex2X + " " + addTerrain.Vertex2Y + " " + addTerrain.Vertex2Z + "\r\n"
                                                    + addTerrain.Vertex3X + " " + addTerrain.Vertex3Y + " " + addTerrain.Vertex3Z + "\r\n"
                                                    + addTerrain.Vertex4X + " " + addTerrain.Vertex4Y + " " + addTerrain.Vertex4Z + "\r\n"
                                                    + SetupContent.terrainStudyAreaStr6 + "\r\n";
                        MainWindow.setupStr = MainWindow.setupStr.Insert(startPosiStudyArea, studyAreaStr);
                        //向全局字符串插入<feature>段
                        int    startPosiFeature = MainWindow.setupStr.IndexOf("end_<studyarea>") + 17;
                        string featureStr       = SetupContent.terrainFeatureFixedStr1 + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr2 + "0" + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr3 + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr4
                                                  + MainWindow.projectRealPath + "\\" + (string)newTerrainName_comboBox1.SelectedItem + "\r\n"
                                                  + SetupContent.terrainFeatureFixedStr5 + "\r\n";
                        MainWindow.setupStr = MainWindow.setupStr.Insert(startPosiFeature, featureStr);



                        string terFileName = t.Substring(t.LastIndexOf('\\') + 1, t.Length - 1 - t.LastIndexOf('\\'));
                        //将ter文件拷贝到工程目录下
                        FileCopyUI.FileCopy(addTerrain.path, MainWindow.projectRealPath + "\\" + terFileName);
                        FileCopyUI.FileCopy(addTerrain.path + ".terinfo", MainWindow.projectRealPath + "\\" + terFileName + ".terinfo");

                        string terainStr = FileOperation.ReadFile(MainWindow.nodeInfoFullPath);
                        if (terainStr.IndexOf(SetupContent.terrainIndeStr) != -1)
                        {
                            terainStr = terainStr.Remove(terainStr.IndexOf(SetupContent.terrainIndeStr), SetupContent.terrainIndeStr.Length + 2);
                            FileOperation.WriteFile(terainStr, MainWindow.nodeInfoFullPath, false);
                        }
                        //将工程树的节点信息写到.info文件中
                        FileOperation.WriteLineFile(SetupContent.terrainIndeStr + " " + terFileName, MainWindow.nodeInfoFullPath, true);
                        FileOperation.WriteFile(MainWindow.setupStr, MainWindow.mProjectFullName, false);
                        MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes[0].Nodes.Add(terFileName);
                    }
                }
            }
            this.Close();
        }
예제 #12
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LogFileManager.ObjLog.info("Begin");
            if (mProjectFullName != null)
            {
                DialogResult result = MessageBox.Show("您是否要打开一个新的工程?若是则原工程将被关闭。", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (DialogResult.OK == result)
                {
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Remove();
                }
                else
                {
                    MainWindow.mProjectFullName = null;  //王佳修改
                    MainWindow.setupStr         = null;
                    return;
                }
            }
            openProject.Filter = "setup文件(*.setup)|*.setup|所有文件|*.*";
            DialogResult dr = openProject.ShowDialog();

            if (dr == DialogResult.OK)
            {
                //在新建一个工程时,又打开这个工程则什么也不做 否则执行下面的操作
                if (mProjectFullName != openProject.FileName)
                {
                    setupStr = FileOperation.ReadFile(openProject.FileName);
                    //.setup文件的包括路径的名字
                    mProjectFullName = openProject.FileName;
                    //.setup.info文件的包含路径的名字
                    nodeInfoFullPath  = openProject.FileName + ".info";
                    transInfoFullPath = openProject.FileName + ".transinfo";

                    relationOfAntAndWavePath = openProject.FileName + ".match";
                    waveinfoFilePath         = openProject.FileName + ".waveinfo";

                    //工程的路径 不包括文件
                    MainWindow.projectRealPath = openProject.FileName.Substring(0, openProject.FileName.LastIndexOf("\\"));
                    staticTreeView.Nodes.Clear();
                    //从信息文件中找出工程树中工程的名字将其加载到工程树中
                    string nodeNamesStr   = FileOperation.ReadFile(nodeInfoFullPath);
                    string projectNameStr = StringFound.FoundBackStr(SetupContent.projectIndeStr, nodeNamesStr, true);
                    MainWindow.onlyProjectName = projectNameStr;
                    longitudeStr = StringFound.FoundBackStr(SetupContent.longitudeIndeStr, nodeNamesStr, true);
                    latitudeStr  = StringFound.FoundBackStr(SetupContent.latitudeIndeStr, nodeNamesStr, true);


                    staticTreeView.Nodes.Add("工程名字");
                    staticTreeView.Nodes[0].Nodes.Add(projectNameStr);
                    staticTreeView.Nodes[0].Nodes[0].Nodes.Add("地形");
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes.Add("波形");
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes.Add("天线");
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes.Add("辐射源");
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes.Add("接收机");
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes[4].Nodes.Add("点状分布");
                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes[4].Nodes.Add("区域分布");

                    MainWindow.staticTreeView.Nodes[0].Nodes[0].Nodes.Add("仿真结果设定");


                    ArrayList nodeNamesArr = new ArrayList();
                    //向工程树中添加波形节点
                    nodeNamesArr = ProjectTreeMatchString.MatchStr(nodeNamesStr, SetupContent.waveIndeStr, SetupContent.waveIndeStr.Length);
                    foreach (string s in nodeNamesArr)
                    {
                        staticTreeView.Nodes[0].Nodes[0].Nodes[1].Nodes.Add(s);
                    }
                    //向工程树中添加地形节点
                    nodeNamesArr = ProjectTreeMatchString.MatchStr(nodeNamesStr, SetupContent.terrainIndeStr, SetupContent.terrainIndeStr.Length);
                    foreach (string s in nodeNamesArr)
                    {
                        staticTreeView.Nodes[0].Nodes[0].Nodes[0].Nodes.Add(s);
                    }
                    //向工程树种添加天线结点
                    nodeNamesArr = ProjectTreeMatchString.MatchStr(nodeNamesStr, SetupContent.antennaIndeStr, SetupContent.antennaIndeStr.Length);
                    foreach (string s in nodeNamesArr)
                    {
                        staticTreeView.Nodes[0].Nodes[0].Nodes[2].Nodes.Add(s);
                    }
                    //向工程树种添加辐射源结点
                    nodeNamesArr = ProjectTreeMatchString.MatchStr(nodeNamesStr, SetupContent.transmitterIndeStr, SetupContent.transmitterIndeStr.Length);
                    foreach (string s in nodeNamesArr)
                    {
                        staticTreeView.Nodes[0].Nodes[0].Nodes[3].Nodes.Add(s);
                    }
                    //向工程树种添加点状接收机
                    nodeNamesArr = ProjectTreeMatchString.MatchStr(nodeNamesStr, SetupContent.pointReceiverIndeStr, SetupContent.pointReceiverIndeStr.Length);
                    foreach (string s in nodeNamesArr)
                    {
                        staticTreeView.Nodes[0].Nodes[0].Nodes[4].Nodes[0].Nodes.Add(s);
                    }
                    //向工程树种添加线状接收机
                    nodeNamesArr = ProjectTreeMatchString.MatchStr(nodeNamesStr, SetupContent.gridReceiverIndeStr, SetupContent.gridReceiverIndeStr.Length);
                    foreach (string s in nodeNamesArr)
                    {
                        staticTreeView.Nodes[0].Nodes[0].Nodes[4].Nodes[1].Nodes.Add(s);
                    }
                    //向工程树中加载结果设定的相应信息
                    string pathsResultStr = StringFound.FoundBackStr(SetupContent.resultSetIndeStr1, nodeNamesStr, false);
                    //若结果设定中的复选框被选中
                    if (GetResultSetStr(pathsResultStr))
                    {
                        //将复选框的状态保存到结果设定窗口中
                        PathsCheck.Checked = true;
                        //在工程树中加载结果设定结点中加载相应的信息
                        staticTreeView.Nodes[0].Nodes[0].Nodes[5].Nodes.Add(SetupContent.resultSetOfTreeIndeStr1);
                    }
                    string pathlossResultStr = StringFound.FoundBackStr(SetupContent.resultSetIndeStr2, nodeNamesStr, false);
                    if (GetResultSetStr(pathlossResultStr))
                    {
                        PathlossCheck.Checked = true;
                        staticTreeView.Nodes[0].Nodes[0].Nodes[5].Nodes.Add(SetupContent.resultSetOfTreeIndeStr2);
                    }
                    string eFieldResultStr = StringFound.FoundBackStr(SetupContent.resultSetIndeStr3, nodeNamesStr, false);
                    if (GetResultSetStr(eFieldResultStr))
                    {
                        EFieldCheck.Checked = true;
                        staticTreeView.Nodes[0].Nodes[0].Nodes[5].Nodes.Add(SetupContent.resultSetOfTreeIndeStr3);
                    }
                    string eFieldTotalResultStr = StringFound.FoundBackStr(SetupContent.resultSetIndeStr4, nodeNamesStr, false);
                    if (GetResultSetStr(eFieldTotalResultStr))
                    {
                        EFieldTotalCheck.Checked = true;
                        staticTreeView.Nodes[0].Nodes[0].Nodes[5].Nodes.Add(SetupContent.resultSetOfTreeIndeStr4);
                    }
                    string powerResultStr = StringFound.FoundBackStr(SetupContent.resultSetIndeStr5, nodeNamesStr, false);
                    if (GetResultSetStr(powerResultStr))
                    {
                        PowerCheck.Checked = true;
                        staticTreeView.Nodes[0].Nodes[0].Nodes[5].Nodes.Add(SetupContent.resultSetOfTreeIndeStr5);
                    }

                    //判断用户是否关闭WI
                    Process pro = null;
                    try
                    {
                        pro = Process.GetProcessById(wiProcessID);
                    }
                    catch (ArgumentException)
                    {
                        //如果ID所对应的WI进程已被关闭,则再重新开启WI
                        Process wiProcess = Process.Start(exePath, openProject.FileName);
                        this.WindowState = FormWindowState.Normal;
                        this.Activate();
                        MainWindow.wiProcessID = wiProcess.Id;
                        return;
                    }
                    if (pro == null)
                    {
                        //如果WI进程还存在,则先将其关闭再打开重新加载工程
                        pro.Kill();
                    }
                    else
                    {
                        Process wiProcess = Process.Start(exePath, openProject.FileName);
                        //Process wiProcess = Process.Start(exePath, openProject.FileName);

                        this.WindowState = FormWindowState.Normal;
                        //this.TopMost = true;
                        this.Activate();
                        this.WindowState = FormWindowState.Maximized;

                        MainWindow.wiProcessID = wiProcess.Id;
                    }
                }
                else
                {
                    MessageBox.Show("该工程已经打开!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                mProjectFullName = null;
            }
        }