public void InitFixData(string fixedCitFile, string fixedIdfFile = null, bool diffFileName = false)
        {
            List <ChannelDefinition> channelDefinition = _citProcess.GetChannelDefinitionList(fixedCitFile);

            for (int i = 0; i < FixParams.Count; i++)
            {
                FixParams[i].ChannelID = channelDefinition.Where(p => p.sNameEn == FixParams[i].ChannelName).ToList()[0].sID;
            }
            FileInformation citFile = _citProcess.GetFileInformation(fixedCitFile);

            _fixedData.Clear();

            string idfFIle = fixedCitFile.Replace(".cit", ".idf");

            if (diffFileName)
            {
                idfFIle = fixedIdfFile;
            }

            IndexOperator indexOperator = new IndexOperator();

            if (File.Exists(idfFIle))
            {
                indexOperator.IndexFilePath = idfFIle;
                UserFixedTable fixTable = new UserFixedTable(indexOperator, citFile.iKmInc);
                if (fixTable.MarkedPoints.Count > 0)
                {
                    foreach (var point in fixTable.MarkedPoints)
                    {
                        //左半边数据点个数,包括中间点
                        List <FixPoint> fixPoint         = new List <FixPoint>();
                        int             leftFixedCount   = FixedSamplingCount + 1;
                        long            leftStartPostion = _citProcess.GetAppointFileEndPostion(fixedCitFile, point.FilePointer, -1 * leftFixedCount);
                        long            realLeftCount    = _citProcess.GetSampleCountByRange(fixedCitFile, leftStartPostion, point.FilePointer);
                        long            rightEndPostion  = _citProcess.GetAppointFileEndPostion(fixedCitFile, point.FilePointer, FixedSamplingCount);
                        long            realRightCount   = _citProcess.GetSampleCountByRange(fixedCitFile, point.FilePointer, rightEndPostion);
                        Milestone       mile             = _citProcess.GetAppointMilestone(fixedCitFile, point.FilePointer);
                        foreach (var item in FixParams)
                        {
                            FixPoint fixP = new FixPoint();
                            fixP.FixPostion = leftFixedCount;
                            double[] data = _citProcess.GetOneChannelDataInRange(fixedCitFile, item.ChannelID, leftStartPostion, ((int)(realLeftCount + realRightCount)));
                            fixP.Points          = data;
                            fixP.ChannelID       = item.ChannelID;
                            fixP.OriginalMileage = mile.GetMeter();
                            fixPoint.Add(fixP);
                        }
                        _fixedData.Add(point, fixPoint);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 根据点返回索引文件里对应的里程信息
        /// </summary>
        /// <param name="listIC">索引信息</param>
        /// <param name="lPosition">点的位置</param>
        /// <param name="tds">文件通道书</param>
        /// <param name="sKmInc">增减里程标 【0增里程;1减里程】</param>
        /// <returns>索引里程:单位为米</returns>
        public int PointToMeter(List <IndexSta> listIC, long lPosition, int tds, int iKmInc)
        {
            int iMeter = 0;

            //处理里程
            for (int i = 0; i < listIC.Count; i++)
            {
                if (lPosition >= listIC[i].lStartPoint && lPosition < listIC[i].lEndPoint)
                {
                    int  iCount  = 1;
                    long lCurPos = lPosition - listIC[i].lStartPoint;
                    int  iIndex  = 0;
                    if (listIC[i].sType.Contains("长链"))
                    {
                        int    iKM       = 0;
                        double dCDLMeter = float.Parse(listIC[i].lContainsMeter) * 1000;
                        //减里程
                        if (iKmInc == 1)
                        {
                            iKM = (int)float.Parse(listIC[i].LEndMeter);
                        }
                        else
                        {
                            iKM = (int)float.Parse(listIC[i].lStartMeter);
                        }
                        for (iIndex = 0; iIndex < iCount && (lPosition + iIndex * tds * 2) < listIC[i].lEndPoint;)
                        {
                            float f = (lCurPos / tds / 2 + iIndex) * ((float.Parse(listIC[i].lContainsMeter) * 1000 / listIC[i].lContainsPoint));

                            Milestone wm = new Milestone();
                            //减里程
                            if (iKmInc == 1)
                            {
                                wm.mKm    = iKM;
                                wm.mMeter = (float)(dCDLMeter - f);
                            }
                            else
                            {
                                wm.mKm    = iKM;
                                wm.mMeter = (float)(dCDLMeter + f);
                            }
                            wm.mFilePosition = (lPosition + (iIndex * tds * 2));
                            iMeter           = Convert.ToInt32(wm.GetMeter());
                            return(iMeter);
                        }
                    }
                    else
                    {
                        double dMeter = float.Parse(listIC[i].lStartMeter) * 1000;
                        for (iIndex = 0; iIndex < iCount && (lPosition + iIndex * tds * 2) < listIC[i].lEndPoint;)
                        {
                            float     f  = (lCurPos / tds / 2 + iIndex) * ((float.Parse(listIC[i].lContainsMeter) * 1000 / listIC[i].lContainsPoint));
                            Milestone wm = new Milestone();
                            //减里程
                            if (iKmInc == 1)
                            {
                                wm.mKm    = (int)((dMeter - f) / 1000);
                                wm.mMeter = (float)((dMeter - f) % 1000);
                            }
                            else
                            {
                                wm.mKm    = (int)((dMeter + f) / 1000);
                                wm.mMeter = (float)((dMeter + f) % 1000);
                            }
                            wm.mFilePosition = (lPosition + (iIndex * tds * 2));
                            iMeter           = Convert.ToInt32(wm.GetMeter());
                            return(iMeter);
                        }
                    }
                    break;
                }
            }
            return(iMeter);
        }
        /// <summary>
        /// 根据索引导出CIT文件
        /// </summary>
        /// <param name="filePath">cit文件路径</param>
        /// <param name="startMileage">开始里程(公里)</param>
        /// <param name="endMileage">结束里程(公里)</param>
        /// <returns>成功:返回导出路径,失败:空字符串</returns>
        public string ExportCITFileAndIndexData(string filePath, double startMileage, double endMileage)
        {
            string destFile = filePath + "\\" +
                              Path.GetFileNameWithoutExtension(CitFilePath) + "_" +
                              startMileage.ToString() + "-" + endMileage.ToString() + ".cit";

            if (_citFile.iKmInc == 1 && startMileage < endMileage)
            {
                double change = startMileage;
                startMileage = endMileage;
                endMileage   = change;
            }
            if (_citFile != null && MileageFix.FixData.Count > 0)
            {
                if (_citFile.iKmInc == 0)
                {
                    if (startMileage >= MileageFix.FixData[MileageFix.FixData.Count - 1].MarkedEndPoint.UserSetMileage / 1000 ||
                        endMileage <= MileageFix.FixData[0].MarkedStartPoint.UserSetMileage / 1000)
                    {
                        return("");
                    }
                    if (startMileage < (MileageFix.FixData[0].MarkedStartPoint.UserSetMileage / 1000))
                    {
                        startMileage = (MileageFix.FixData[0].MarkedStartPoint.UserSetMileage / 1000);
                    }
                    if (endMileage > MileageFix.FixData[MileageFix.FixData.Count - 1].MarkedEndPoint.UserSetMileage / 1000)
                    {
                        endMileage = MileageFix.FixData[MileageFix.FixData.Count - 1].MarkedEndPoint.UserSetMileage / 1000;
                    }
                }
                else if (_citFile.iKmInc == 1)
                {
                    if (endMileage >= MileageFix.FixData[MileageFix.FixData.Count - 1].MarkedEndPoint.UserSetMileage / 1000 ||
                        startMileage <= MileageFix.FixData[0].MarkedStartPoint.UserSetMileage / 1000)
                    {
                        return("");
                    }
                    if (startMileage > MileageFix.FixData[0].MarkedStartPoint.UserSetMileage / 1000)
                    {
                        startMileage = MileageFix.FixData[0].MarkedStartPoint.UserSetMileage / 1000;
                    }
                    if (endMileage < MileageFix.FixData[MileageFix.FixData.Count - 1].MarkedEndPoint.UserSetMileage / 1000)
                    {
                        endMileage = MileageFix.FixData[MileageFix.FixData.Count - 1].MarkedEndPoint.UserSetMileage / 1000;
                    }
                }
                Milestone startStone = new Milestone();
                Milestone endStone   = new Milestone();
                startStone = MileageFix.CalcMilestoneByFixedMilestone((float)startMileage * 1000);
                endStone   = MileageFix.CalcMilestoneByFixedMilestone((float)endMileage * 1000);
                if (startStone.mFilePosition != -1 && endStone.mFileEndPostion != -1)
                {
                    if (!Directory.Exists(filePath))
                    {
                        Directory.CreateDirectory(filePath);
                    }

                    List <double[]>          channelData           = CitFileProcess.GetAllChannelDataInRange(_citFilePath, startStone.mFilePosition, endStone.mFileEndPostion);
                    List <ChannelDefinition> channelDefinitionList = CitFileProcess.GetChannelDefinitionList(_citFilePath);
                    if (CitFileProcess.WriteCitFile(destFile, CitFile, channelDefinitionList, "", channelData))
                    {
                        CitFileProcess.SetKmFrom(destFile, (float)startStone.GetMeter() / 1000);
                        CitFileProcess.SetKmTo(destFile, (float)endStone.GetMeter() / 1000);
                        string    indexFile   = destFile.Replace(".cit", ".idf");
                        IOperator newOperator = new IndexOperator();
                        newOperator.IndexFilePath = indexFile;
                        //IndexOperator.CreateDB(indexFile);
                        long fileHead = FileDataOffset.GetSamplePointStartOffset(channelData.Count, 4);
                        AddNewIndexData(destFile, newOperator, fileHead, startStone.mFilePosition, endStone.mFileEndPostion, channelData.Count);
                        AddInvaildData(newOperator, fileHead, startStone.mFilePosition, endStone.mFileEndPostion, channelData.Count);
                        return(destFile);
                    }
                    return("");
                }
                return("");
            }
            else
            {
                return(ExportOnlyCITFile(destFile, startMileage, endMileage));
            }
        }
示例#4
0
        /// <summary>
        /// 导出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExport_Click(object sender, EventArgs e)
        {
            startMileage = double.Parse(txtMileStart.Text.Trim()) * 1000;
            endMileage   = (double.Parse(txtMileEnd.Text.Trim()) * 1000);
            if (startMileage == endMileage)
            {
                MessageBox.Show("起始公里标和终点公里标相同,请重新填写!");
                return;
            }

            string exportFilePath = string.Empty;

            if (!string.IsNullOrEmpty(txtExportPath.Text))
            {
                exportFilePath = txtExportPath.Text;
            }
            else
            {
                exportFilePath = "D://";
            }
            long startPostion = -1;
            long endPostion   = -1;
            //long[] postions = _maker.WaveformDataList[0].CitFileProcess.GetPositons(_maker.WaveformDataList[0].CitFilePath);
            Milestone start = _maker.WaveformDataList[0].CitFileProcess.GetStartMilestone(_maker.WaveformDataList[0].CitFilePath);
            Milestone end   = _maker.WaveformDataList[0].CitFileProcess.GetEndMilestone(_maker.WaveformDataList[0].CitFilePath);

            if (ckbIsStart.Checked)
            {
                startPostion = start.mFilePosition;
                startMileage = start.GetMeter();
            }
            else
            {
                startPostion = _maker.WaveformDataList[0].CitFileProcess.GetCurrentPositionByMilestone(_maker.WaveformDataList[0].CitFilePath, (float)startMileage, true);
            }
            if (ckbIsEnd.Checked)
            {
                endPostion = end.mFilePosition;
                endMileage = end.GetMeter();
            }
            else
            {
                endPostion = _maker.WaveformDataList[0].CitFileProcess.GetCurrentPositionByMilestone(_maker.WaveformDataList[0].CitFilePath, (float)endMileage, true);
            }

            if (startPostion == -1)
            {
                MessageBox.Show("文件中不存在里程为:" + txtMileStart.Text.Trim() + " 的数据,请确认!");
                return;
            }

            if (endPostion == -1)
            {
                MessageBox.Show("文件中不存在里程为:" + txtMileEnd.Text.Trim() + " 的数据,请确认!");
                return;
            }

            btnExport.Enabled  = false;
            labLoading.Visible = true;


            Task <string> task = Task.Factory.StartNew(
                () => _maker.WaveformDataList[0].ExportOnlyCITFile(exportFilePath, startMileage, endMileage)
                );

            task.ContinueWith((t) =>
            {
                if (t.Exception == null && t.IsCompleted)
                {
                    if (this != null && this.IsHandleCreated && btnExport.IsHandleCreated)
                    {
                        this.Invoke(new Action(() =>
                        {
                            btnExport.Enabled  = true;
                            labLoading.Visible = false;
                        }));
                    }
                    string exprotFile = t.Result;
                    if (!string.IsNullOrEmpty(exprotFile))
                    {
                        MessageBox.Show("导出成功,路径为:" + exprotFile);
                    }
                    else
                    {
                        MessageBox.Show("导出完成,但没有数据导出");
                    }
                }
                else if (t.Exception != null)
                {
                    MyLogger.LogError("导出失败", t.Exception.InnerException);
                    MessageBox.Show("导出失败,错误:" + t.Exception.InnerException.Message);
                }
            });
        }
示例#5
0
        public void DisplayInListview(string citPath)
        {
            FileInformation fileInfo     = null;
            double          startMileage = 0;
            double          endMileage   = 0;
            double          totalMileage = 0;

            try
            {
                fileInfo = _citProcess.GetFileInformation(citPath);
                long[]    startAndEnd = _citProcess.GetPositons(citPath);
                Milestone start       = _citProcess.GetStartMilestone(citPath);
                Milestone end         = _citProcess.GetEndMilestone(citPath);
                startMileage = start.GetMeter() / 1000;
                endMileage   = end.GetMeter() / 1000;
                long sampleCount = _citProcess.GetSampleCountByRange(citPath, startAndEnd[0], startAndEnd[1]);
                totalMileage = (sampleCount * 0.25) / 1000;
            }
            catch (Exception ex)
            {
                MyLogger.logger.Error("读取文件头部信息出错:" + ex.Message + ",堆栈:" + ex.StackTrace + ",CIT文件名称:" + citPath);
                MessageBox.Show("读取文件头部信息出错,请检查文件是否有效!");
            }
            if (fileInfo != null)
            {
                //线路名
                ListViewItem item = new ListViewItem(fileInfo.sTrackName);
                //线路编码
                item.SubItems.Add(fileInfo.sTrackCode);
                //行别
                string dir = string.Empty;
                switch (fileInfo.iDir)
                {
                case 1:
                {
                    dir = "上行"; break;
                }

                case 2:
                {
                    dir = "下行"; break;
                }

                case 3:
                {
                    dir = "单线"; break;
                }

                default:
                {
                    dir = "上行"; break;
                }
                }
                item.SubItems.Add(dir);
                if (dir.Contains("下"))
                {
                    item.BackColor = Color.LightCyan;
                }
                else
                {
                    item.BackColor = Color.LightBlue;
                }
                //方向
                item.SubItems.Add(fileInfo.iRunDir == 0 ? "正" : "反");
                //增减里程
                item.SubItems.Add(fileInfo.iKmInc == 0 ? "增" : "减");
                item.SubItems.Add(startMileage.ToString()); //起始里程
                item.SubItems.Add(endMileage.ToString());   //终止里程
                item.SubItems.Add(totalMileage.ToString()); //总里程
                //检测日期
                item.SubItems.Add(fileInfo.sDate);
                //检测时间
                item.SubItems.Add(fileInfo.sTime);
                //检测车号
                item.SubItems.Add(fileInfo.sTrain);
                //原始文件名
                item.SubItems.Add(Path.GetFileName(citPath));
                //大小
                item.SubItems.Add((new FileInfo(citPath)).Length.ToString());
                //原始路径
                item.SubItems.Add(Path.GetDirectoryName(citPath));
                //ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem();
                //subItem.ForeColor = Color.Red;
                //subItem.Text = "点击移除";
                item.SubItems.Add("点击移除");
                item.Tag     = fileInfo;
                item.Checked = true;

                listViewFiles.Items.Add(item);
                listViewFiles.Columns[listViewFiles.Columns.Count - 1].Width = -2;
            }
        }