From d958cc372ab2efd11ba4296a84d037331186e842 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Sun, 16 Apr 2023 23:57:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mseedChart.MainModule/Models/StationAxis.cs | 36 ++ mseedChart.MainModule/Models/WavesModel.cs | 160 +++++- .../ViewModels/ChartPlotViewModel.cs | 454 ++++++------------ .../Views/ChartPlotView.xaml | 40 +- .../mseedChart.MainModule.csproj | 1 + 5 files changed, 354 insertions(+), 337 deletions(-) create mode 100644 mseedChart.MainModule/Models/StationAxis.cs diff --git a/mseedChart.MainModule/Models/StationAxis.cs b/mseedChart.MainModule/Models/StationAxis.cs new file mode 100644 index 0000000..5edc5f8 --- /dev/null +++ b/mseedChart.MainModule/Models/StationAxis.cs @@ -0,0 +1,36 @@ +using Prism.Commands; +using Prism.Common; +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace mseedChart.MainModule.Models +{ + public class StationAxis : BindableBase + { + + public string Name { get; set; } + + private bool _isChecked=true; + + public bool IsChecked + { + get + { + return _isChecked; + } + set + { + _isChecked = value; + SetProperty(ref _isChecked, value); + } + } + + public DelegateCommand SelectCommand { set; get; } + + } +} diff --git a/mseedChart.MainModule/Models/WavesModel.cs b/mseedChart.MainModule/Models/WavesModel.cs index 77f28e0..9232ac1 100644 --- a/mseedChart.MainModule/Models/WavesModel.cs +++ b/mseedChart.MainModule/Models/WavesModel.cs @@ -6,10 +6,12 @@ using mseedChart.Core; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; +using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; - +using System.Threading.Tasks; namespace mseedChart.MainModule.Models { @@ -69,19 +71,18 @@ namespace mseedChart.MainModule.Models Tag=ph.id, //用于排序otime,只需要排更SHZ通道 Lines = new SegmentLine[] { new SegmentLine(chartV.XAxes[0].DateTimeToAxisValue(ph.atime), chartV.YAxes[assignYAxisIndex].Minimum, chartV.XAxes[0].DateTimeToAxisValue(ph.atime), chartV.YAxes[assignYAxisIndex].Maximum) }, ShowInLegendBox = false - }; lineCollection.LineStyle.Color = System.Windows.Media.Colors.Red; - lineCollection.Title.Text = ph.atime.ToString(); + lineCollection.Title.Text = chartV.YAxes[assignYAxisIndex].Title.Text + ph.atime.ToString(); lineCollection.Title.Visible = true; lineCollection.Title.Font.Size = 8; lineCollection.Title.Shadow.DropColor = System.Windows.Media.Colors.Transparent; lineCollection.Title.Shadow.ContrastColor = System.Windows.Media.Colors.Transparent; lineCollection.Title.AutoPlacement = false; lineCollection.Title.HorizontalAlign = AlignmentHorizontal.Left; - var b= (ph.atime- stationEventJson.otime).TotalSeconds*100; - lineCollection.Title.Offset= new PointIntXY((int)b, 0); + var b= (ph.atime- stationModels.First().BeginTime).TotalSeconds*100; + lineCollection.Title.Offset.SetValues((int)b, 0); lineCollection.Title.Color = System.Windows.Media.Colors.Red; lineCollection.Title.AutoPlacement = false; @@ -97,7 +98,7 @@ namespace mseedChart.MainModule.Models continue; } int assignYAxisIndex = index * 3; - assignYAxisIndex = am.id.Contains("SHE") ? assignYAxisIndex + 1 : assignYAxisIndex + 2; + assignYAxisIndex = am.id.Contains("SHN") ? assignYAxisIndex + 1 : assignYAxisIndex + 2; LineCollection lineCollection = new LineCollection() { AssignXAxisIndex = 0, @@ -106,14 +107,15 @@ namespace mseedChart.MainModule.Models ShowInLegendBox = false }; lineCollection.LineStyle.Color = System.Windows.Media.Colors.Red; - lineCollection.Title.Text = am.atime.ToString(); + lineCollection.Title.Text = chartV.YAxes[assignYAxisIndex].Title.Text+ " "+ am.atime.ToString("HH:mm:ss.fff"); lineCollection.Title.Visible = true; - lineCollection.Title.Font.Size = 8; + lineCollection.Title.Font.Size = 10; lineCollection.Title.Shadow.DropColor = System.Windows.Media.Colors.Transparent; lineCollection.Title.Shadow.ContrastColor = System.Windows.Media.Colors.Transparent; lineCollection.Title.AutoPlacement = false; lineCollection.Title.HorizontalAlign = AlignmentHorizontal.Left; - var b = (am.atime - stationEventJson.otime).TotalSeconds * 100; + + var b= chartV.XAxes[0].ValueToCoordD(chartV.XAxes[0].DateTimeToAxisValue(am.atime)); lineCollection.Title.Offset = new PointIntXY((int)b, 0); lineCollection.Title.Color = System.Windows.Media.Colors.Red; // lineCollection.Title.AllowDragging = false; @@ -122,13 +124,143 @@ namespace mseedChart.MainModule.Models return new List(); } - public StationEventJson mseedJsonResolve(string jsonFile) + + public ConcurrentQueue ReadMseedFile(string dataFilePath, string asciiSavePath, bool isMultFile = false) + { + if (!Directory.Exists(Path.GetDirectoryName(dataFilePath))) + { + Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath)); + } + if (!Directory.Exists(Path.GetDirectoryName(asciiSavePath))) + { + Directory.CreateDirectory(Path.GetDirectoryName(asciiSavePath)); + } + ConcurrentQueue smList = new ConcurrentQueue(); + Stopwatch sw = Stopwatch.StartNew(); + if (isMultFile) + { + var filePath = new DirectoryInfo(Path.GetDirectoryName(dataFilePath)); + FileInfo[] files = filePath.GetFiles(); + var mseedFiles = files.Where(i => i.Extension == ".mseed"); + + var asciiFiles = new DirectoryInfo(Path.GetDirectoryName(asciiSavePath)); + var asciifile = asciiFiles.GetFiles(); + if (asciifile.Count() == 0) + { + // 并行运算 + Parallel.ForEach(mseedFiles, (item) => + { + MSeed2Asc(item.FullName, Path.Combine(Path.GetDirectoryName(asciiSavePath), Path.GetFileNameWithoutExtension(item.Name))); + }); + + } + // 并行运算 + Parallel.ForEach(asciiFiles.GetFiles(), (item) => + { + var list = UpdateWavesFromTxt(item.FullName); + list.ForEach(i => smList.Enqueue(i)); + }); + } + else + { + if (!File.Exists(asciiSavePath)) + { + MSeed2Asc(dataFilePath, asciiSavePath); + } + var list = UpdateWavesFromTxt(asciiSavePath); + list.ForEach(i => smList.Enqueue(i)); + } + sw.Stop(); + Debug.WriteLine("MSeed2Asc解压时间:" + sw.Elapsed.TotalSeconds); + return smList; + } + + public List UpdateWavesFromTxt(string fn) { - var str = File.ReadAllText(jsonFile); - var st = JsonConvert.DeserializeObject(str); + string allStr; + List temSM = new List(); + using (StreamReader streamReader = new StreamReader(fn)) + { + allStr = streamReader.ReadToEnd(); + } + if (allStr.Length > 0) + { + string[] strLines = allStr.Trim().Split(new char[] { '\n' }); + // List strList = strLines.ToList(); + // int cnt = strList.Count; + // string[] snStr = strLines[0].Trim().Split(','); + // string tmpName = snStr[0].Substring(14, 3); + StationModel station = new StationModel(); + // station.Name = tmpName; + + int channelFlag = 0; + + for (int i = 0; i < strLines.Length; i++) + { + string row = strLines[i].Trim(); + if (strLines[i].Contains("HA")) + { + string[] rowStr = strLines[i].Split(','); + string chnStr1 = rowStr[0].Substring(21, 3); + string stationName = rowStr[0].Substring(14, 3); + if (!temSM.Any(name => name.Name == stationName)) + { + station = new StationModel(); + station.Name = stationName; + station.BeginTime = Convert.ToDateTime(rowStr[3]).AddHours(8); + station.PointCount = int.Parse(rowStr[1].Trim().Split(' ')[0]); + station.SamplingFrequency = int.Parse(rowStr[2].Trim().Split(' ')[0]); + temSM.Add(station); + } + channelFlag = (chnStr1 == "SHZ") ? 0 : (chnStr1 == "SHN") ? 1 : 2; + } + else + { + switch (channelFlag) + { + case 0://Z + station.dz.Add(double.Parse(row)); + break; + case 1://N + station.dn.Add(double.Parse(row)); + break; + case 2://E + station.de.Add(double.Parse(row)); + break; + } + } + } + // temSM.Add(station); + temSM.Reverse(); + } + return temSM; + } + + public void MSeed2Asc(string filePath, string savePath) + { + using (Process compiler = new Process()) + { + compiler.StartInfo.FileName = "mseed2ascii.exe"; + compiler.StartInfo.Arguments = filePath + " -o " + savePath; + compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + compiler.StartInfo.CreateNoWindow = true; + compiler.Start(); + compiler.WaitForExit(); + } + } + + public StationEventJson ReadChartJsonFile(string jsonFile) + { + if (File.Exists(jsonFile)) + { + var str = File.ReadAllText(jsonFile); + var st = JsonConvert.DeserializeObject(str); + + StationEventJson jsonST = st[0]; + return jsonST; + } + return null; - StationEventJson jsonST = st[0]; - return jsonST; } } } diff --git a/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs b/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs index e7a8065..cc8bb9c 100644 --- a/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs +++ b/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs @@ -27,6 +27,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Documents; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -42,64 +43,25 @@ namespace mseedChart.MainModule.ViewModels { _dispatcher = Application.Current.Dispatcher; _wavesModel = new WavesModel(); - CreateChart(); (Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose; - string fileName = "2023-03-28T05:14:59.108464"; - // fileName = "2023-03-24T04:53:46.199584"; - bool multFlies = false; - string eventTimeStr = fileName; - string datePath = eventTimeStr.Substring(0, 4) + eventTimeStr.Substring(5, 2) + eventTimeStr.Substring(8, 2); - string dataFilePath = RegionNames.MseedFilePath + "\\" + datePath + "\\"; - string dataFileName = "HA." + eventTimeStr.Substring(0, 4) + eventTimeStr.Substring(5, 2) - + eventTimeStr.Substring(8, 2) + eventTimeStr.Substring(10, 3) - + eventTimeStr.Substring(14, 2) + eventTimeStr.Substring(17, 2) + ".01" + RegionNames.DataTypeString; - string jsonStr = ".json"; - string mseedStr = ".mseed"; - string asciiSavePath = RegionNames.TxtFilePath + "\\" + datePath + "\\"; - if (!multFlies) - { - CurrentEventTime = _wavesModel.mseedJsonResolve(dataFilePath + dataFileName + jsonStr); - } - ShowWave(dataFilePath + dataFileName + mseedStr, asciiSavePath + dataFileName + ".txt" , multFlies); - - YaxisItems.Add("SHZ"); - YaxisItems.Add("SHN"); - YaxisItems.Add("SHE"); + CreateChart(); } #region 字段 Dispatcher _dispatcher; public int CurPoints; - int _channelCount = 0; int _samplingFrequency = 500; // 采样频率 (Hz). WavesModel _wavesModel; private int _lChartCount = 1; public ConcurrentQueue smList; + + public List _chartAxisY=new List(); #endregion #region 属性 - private List _yaxisItems=new List(); - - public List YaxisItems - { - get { return _yaxisItems; } - set { _yaxisItems = value; } - } - - private int _selectIndex=1; - - public int SelectIndex - { - get { return _selectIndex; } - set - { - SetProperty(ref _selectIndex, value); - } - } - private bool _isMultFiles; public bool IsMultFiles @@ -161,82 +123,52 @@ namespace mseedChart.MainModule.ViewModels set { _currentEventTime = value; } } - private List _stationYaxis; + private List _stationsName; - public List StationYaxis + public List StationsName { - get { return _stationYaxis; } + get { return _stationsName; } set { - SetProperty(ref _stationYaxis, value); + SetProperty(ref _stationsName, value); } } - private int _selectStationYaxisIndex; + private string _currentTime; - public int SelectStationYaxisIndex + public string CurrentTime { - get { return _selectStationYaxisIndex; } + get { return _currentTime; } set { - SetProperty(ref _selectStationYaxisIndex, value); - } - } - private bool _stationYaxisIsChecked; - - public bool StationYaxisIsChecked - { - get { return _stationYaxisIsChecked; } - set { - StationYaxisVisible(value); - SetProperty(ref _stationYaxisIsChecked, value); + SetProperty(ref _currentTime, value); } } #endregion #region 事件 + public DelegateCommand LoadedCommand => new DelegateCommand(Loaded); public DelegateCommand AxesYVisibleCommand => new DelegateCommand(AxesYVisible); public DelegateCommand FileSelectorCommand => new DelegateCommand(FileSelector); public DelegateCommand OtimeSortCommand => new DelegateCommand(OtimeSort); public DelegateCommand YasixZENVisibleCommand => new DelegateCommand(YasixZENVisible); public DelegateCommand IntervalSureCommand => new DelegateCommand(IntervalSure); - public DelegateCommand RealTimeDataCommand => new DelegateCommand(RealTimeData); + private void Loaded() + { + + } + private void AxesYVisible(object isCheck) { if (_lChartAll != null) { bool yAxesVisible = ((bool)isCheck == true); _lChartAll.BeginUpdate(); - - AxisY lastYAxis = _lChartAll.ViewXY.YAxes.Last(); - - _lChartAll.ViewXY.AxisLayout.AutoAdjustMargins = false; - foreach (AxisY yAxis in _lChartAll.ViewXY.YAxes) { - if (yAxis != lastYAxis) - { - yAxis.Visible = yAxesVisible; - } - else - { - yAxis.Visible = true; - yAxis.LabelsVisible = yAxesVisible; - //yAxis.MajorDivTickStyle.Visible = yAxesVisible; - //yAxis.MinorDivTickStyle.Visible = yAxesVisible; - yAxis.Title.Visible = yAxesVisible; - if (yAxesVisible) - { - yAxis.AxisThickness = 3; - } - else - { - yAxis.AxisThickness = 0; - } - // lastYAxis.MiniScale.Visible = !yAxesVisible; - } + yAxis.Visible = yAxesVisible; } _lChartAll.EndUpdate(); @@ -252,13 +184,21 @@ namespace mseedChart.MainModule.ViewModels }; if (openFileDialog.ShowDialog() == true) { - string asciiSavePath = openFileDialog.FileName; - asciiSavePath = asciiSavePath.Replace("Mseed", "Txt"); + string asciiSavePath = openFileDialog.FileName.Replace("Mseed", "Txt"); asciiSavePath = Path.ChangeExtension(asciiSavePath, ".txt"); - - ShowWave(openFileDialog.FileName, asciiSavePath, IsMultFiles); - } - } + string JsonPath = Path.ChangeExtension(openFileDialog.FileName, "Json"); + //读取.json文件 + CurrentEventTime = _wavesModel.ReadChartJsonFile(JsonPath); + //读取.mseed文件 + smList = _wavesModel.ReadMseedFile(openFileDialog.FileName, asciiSavePath, IsMultFiles); + _channelCount = smList.Count * 3; + CurrentTime = smList.First().BeginTime.ToShortDateString(); + StationsName = smList.Select(a => new StationAxis{Name= a.Name,IsChecked=true,SelectCommand =new DelegateCommand(StationsNameVisible)}).ToList(); + StartChart(); + FeedDatasToChart(); + } + } + private void OtimeSort(object isCheck) { if (_lChartAll != null) @@ -275,57 +215,82 @@ namespace mseedChart.MainModule.ViewModels { lines = v.LineCollections.Where(a => a.Tag != null && a.Tag.ToString().Contains("SHZ")).OrderByDescending(b => b.Lines[0].AX); ; } - foreach (var item in lines) - { - var a = item.Tag.ToString().Contains("SHZ"); - } + int number = v.YAxes.Count / (_chartAxisY.Count / 3); foreach (var item in lines.Reverse()) { int index = item.AssignYAxisIndex; - for (int i = 0; i < 3; i++) + for (int i = 0; i < number; i++) { + if (index == -1) continue; //隐藏轴不需要处理 AxisY axisY = v.YAxes[index + i]; v.YAxes.RemoveAt(index + i); v.YAxes.Insert(i, axisY); } } LChartALL.EndUpdate(); - } } - private void YasixZENVisible(object isCheck) + + private void YasixZENVisible(object cBox) { + var checkBox= cBox as CheckBox; if (_lChartAll != null) { _lChartAll.BeginUpdate(); - bool yAxesVisible = ((bool)isCheck == true); + bool yAxesVisible = (checkBox.IsChecked == false); ViewXY v = _lChartAll.ViewXY; - List indexs = new List(); - switch (SelectIndex) + string content = checkBox.Content.ToString(); + string conStr = (content == "SHZ") ? ".Z" : (content == "SHN") ? ".N" : ".E"; + for (int i = 0; i <_chartAxisY.Count; i++) { - case 0: - indexs = v.YAxes.Select(a => a.Title.Text.Contains(".Z")).ToList(); - break; - case 1: - indexs = v.YAxes.Select(a => a.Title.Text.Contains(".N")).ToList(); - break; - case 2: - indexs = v.YAxes.Select(a => a.Title.Text.Contains(".E")).ToList(); - break; - default: - break; - } - for (int i = 0; i < indexs.Count; i++) - { - if (indexs[i] == true) + AxisY axisY = _chartAxisY[i]; + if (axisY.Title.Text.Contains(conStr)) { - AxisY axisY = v.YAxes[i]; - axisY.Visible = !yAxesVisible; - v.SampleDataSeries[i].Visible = !yAxesVisible; - int index = v.LineCollections.FindIndex(a => a.AssignYAxisIndex == i); - if (index != -1) + if (yAxesVisible) { - v.LineCollections[index].Visible = !yAxesVisible; + v.YAxes.Remove(axisY); + } + else + { + string str = axisY.Title.Text.Replace(conStr, ""); + int yIndex = 0; + if (content == "SHZ") + { + yIndex = v.YAxes.FindIndex(y => y.Title.Text.Contains(str)); + } + else if (content == "SHE") + { + yIndex = v.YAxes.FindLastIndex(y => y.Title.Text.Contains(str)); + if (yIndex != -1) yIndex += 1; + } + else + { + yIndex = v.YAxes.FindIndex(y => y.Title.Text.Contains(str)); + if (yIndex != -1) + { + if (v.YAxes[yIndex].Title.Text.Contains(".Z")) + { + yIndex = yIndex + 1; + } + } + } + //如果没有查到,直接添加到前面,如果为容器最大索引,只能添加到后面 + if (yIndex == -1 || (yIndex == v.YAxes.Count)) + { + yIndex = v.YAxes.Count; + v.YAxes.Add(axisY); + } + else + { + v.YAxes.Insert(yIndex, axisY); + } + int sampleIndex = v.SampleDataSeries.FindIndex(y => y.Title.Text == _chartAxisY[i].Title.Text); + v.SampleDataSeries[sampleIndex].AssignYAxisIndex = yIndex; + int lineIndex = v.LineCollections.FindIndex(a => a.Title.Text.Contains(_chartAxisY[i].Title.Text)); + if (lineIndex != -1) + { + v.LineCollections[lineIndex].AssignYAxisIndex = yIndex; + } } } } @@ -348,33 +313,39 @@ namespace mseedChart.MainModule.ViewModels } } - private void StationYaxisVisible(bool visible) + private void StationsNameVisible(object obj) { + var station = obj as StationAxis; if (_lChartAll != null) { _lChartAll.BeginUpdate(); - bool yAxesVisible = ((bool)visible == true); + bool yAxesVisible = (station.IsChecked == false); ViewXY v = _lChartAll.ViewXY; - for (int i = 0; i < v.YAxes.Count; i++) + var yAxisList= _chartAxisY.Where(y => y.Title.Text.Contains(station.Name)); + foreach (var item in yAxisList) { - AxisY axisY = v.YAxes[i]; - if (axisY.Title.Text.Contains(StationYaxis[SelectStationYaxisIndex])) + if (yAxesVisible) { - axisY.Visible = !yAxesVisible; - v.SampleDataSeries[i].Visible = !yAxesVisible; - int index = v.LineCollections.FindIndex(a => a.AssignYAxisIndex == i); - if (index != -1) + v.YAxes.Remove(item); + } + else + { + v.YAxes.Add(item); + //SampleDataSeries查找数据对应的Y轴索引, 重新分配到对应的轴 + int sampleIndex = v.SampleDataSeries.FindIndex(s => s.Title.Text == item.Title.Text); + v.SampleDataSeries[sampleIndex].AssignYAxisIndex = v.YAxes.Count()-1; + //LineCollections查找数据对应的Y轴索引, 重新分配到对应的轴 + int lineIndex = v.LineCollections.FindIndex(s => s.Title.Text.Contains(item.Title.Text)); + if (lineIndex != -1) { - v.LineCollections[index].Visible = !yAxesVisible; + v.LineCollections[lineIndex].AssignYAxisIndex = v.YAxes.Count() - 1; } } - } - + } _lChartAll.EndUpdate(); } } - private void RealTimeData(object isCheck) { if (_lChartAll != null) @@ -400,93 +371,7 @@ namespace mseedChart.MainModule.ViewModels _lChartAll.EndUpdate(); } } - #endregion - public List UpdateWavesFromTxt(string fn) - { - string allStr; - List temSM = new List(); - using (StreamReader streamReader = new StreamReader(fn)) - { - allStr = streamReader.ReadToEnd(); - } - if (allStr.Length > 0) - { - string[] strLines = allStr.Trim().Split(new char[] { '\n' }); - List strList = strLines.ToList(); - int cnt = strList.Count; - string[] snStr = strLines[0].Trim().Split(','); - string tmpName = snStr[0].Substring(14, 3); - CurPoints = int.Parse(snStr[1].Trim().Split(' ')[0]); - StationModel station = new StationModel(); - station.Name = tmpName; - - int channelFlag = 0; - - for (int i = 0; i < strLines.Length; i++) - { - string row = strLines[i].Trim(); - if (strLines[i].Contains("HA")) - { - string[] rowStr = strLines[i].Split(','); - string chnStr1 = rowStr[0].Substring(21, 3); - string stationName = rowStr[0].Substring(14, 3); - if (!temSM.Any(name => name.Name == stationName)) - { - station = new StationModel(); - station.Name = stationName; - station.BeginTime = Convert.ToDateTime(rowStr[3]); - station.PointCount = int.Parse(rowStr[1].Trim().Split(' ')[0]); - station.SamplingFrequency = int.Parse(rowStr[2].Trim().Split(' ')[0]); - temSM.Add(station); - } - if (chnStr1 == "SHZ") - { - - channelFlag = 0;//Z - } - else if (chnStr1 == "SHN") - { - channelFlag = 1;//N - } - else - { - channelFlag = 2;//E - } - } - else - { - switch (channelFlag) - { - case 0://Z - station.dz.Add(double.Parse(row)); - break; - case 1://N - station.dn.Add(double.Parse(row)); - break; - case 2://E - station.de.Add(double.Parse(row)); - break; - } - } - } - // temSM.Add(station); - temSM.Reverse(); - } - return temSM; - } - public void MSeed2Asc(string filePath, string savePath) - { - using (Process compiler = new Process()) - { - compiler.StartInfo.FileName = "mseed2ascii.exe"; - compiler.StartInfo.Arguments = filePath + " -o " + savePath; - compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - compiler.StartInfo.CreateNoWindow = true; - compiler.Start(); - compiler.WaitForExit(); - } - } - + #endregion private void CreateChart() { if (LChartALL != null) @@ -507,7 +392,7 @@ namespace mseedChart.MainModule.ViewModels LChartALL.ViewXY.ZoomPanOptions.PanDirection = PanDirection.Horizontal; LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Horizontal; LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.AllLeft; - LChartALL.ViewXY.AxisLayout.YAxisTitleAutoPlacement = true; + LChartALL.ViewXY.AxisLayout.YAxisTitleAutoPlacement = false; LChartALL.ViewXY.AxisLayout.AutoAdjustMargins = false; LChartALL.ViewXY.ZoomPanOptions.DevicePrimaryButtonAction = UserInteractiveDeviceButtonAction.None; @@ -539,61 +424,10 @@ namespace mseedChart.MainModule.ViewModels this.ChildContent = GridChart; } - private void ShowWave(string dataFilePath, string asciiSavePath, bool isMultFile = false) - { - if (!Directory.Exists(Path.GetDirectoryName(dataFilePath))) - { - Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath)); - } - if (!Directory.Exists(Path.GetDirectoryName(asciiSavePath))) - { - Directory.CreateDirectory(Path.GetDirectoryName(asciiSavePath)); - } - smList = new ConcurrentQueue(); - if (isMultFile) - { - var filePath = new DirectoryInfo(Path.GetDirectoryName(dataFilePath)); - FileInfo[] files = filePath.GetFiles(); - var mseedFiles = files.Where(i => i.Extension == ".mseed"); - var asciiFiles = new DirectoryInfo(Path.GetDirectoryName(asciiSavePath)); - var asciifile = asciiFiles.GetFiles(); - if (asciifile.Count() == 0) - { - // 并行运算 - Stopwatch sw = Stopwatch.StartNew(); - Parallel.ForEach(mseedFiles, (item) => - { - MSeed2Asc(item.FullName, Path.Combine(Path.GetDirectoryName(asciiSavePath), Path.GetFileNameWithoutExtension(item.Name))); - }); - sw.Stop(); - Debug.WriteLine("MSeed2Asc解压时间:" + sw.Elapsed.TotalSeconds); - } - // 并行运算 - Parallel.ForEach(asciiFiles.GetFiles(), (item) => - { - var list = UpdateWavesFromTxt(item.FullName); - list.ForEach(i => smList.Enqueue(i)); - }); - } - else - { - if (!File.Exists(asciiSavePath)) - { - MSeed2Asc(dataFilePath, asciiSavePath); - } - var list = UpdateWavesFromTxt(asciiSavePath); - list.ForEach(i => smList.Enqueue(i)); - } - - _channelCount = smList.Count * 3; - StationYaxis = smList.Select(a => a.Name).ToList(); - UpdateChart(); - UpdateChartData(); - } - - private void UpdateChart() + private void StartChart() { + DisposeAllAndClear(_chartAxisY); ViewXY v = LChartALL.ViewXY; DisposeAllAndClear(v.YAxes); DisposeAllAndClear(v.SampleDataSeries); @@ -604,28 +438,32 @@ namespace mseedChart.MainModule.ViewModels v.LegendBoxes[0].Offset.SetValues(-10, 180); v.LegendBoxes[0].Layout = LegendBoxLayout.Vertical; v.LegendBoxes[0].Visible = false; + v.LegendBoxes[0].Shadow.Color = Colors.Transparent; + v.LegendBoxes[0].BorderColor = Colors.Transparent; v.AutoSpaceLegendBoxes = true; v.AxisLayout.SegmentsGap = 3; v.LegendBoxes[0].Shadow.Visible = false; - StationModel stationModel = smList.ElementAt(0); + StationModel stationModel = smList.First(); + var beginTime= stationModel.BeginTime; if (AxisValueType.DateTime == v.XAxes[0].ValueType) { //设置X轴的开始时间 v.XAxes[0].AutoFormatLabels = false; v.XAxes[0].LabelsTimeFormat = "HH:mm:ss.ff"; - v.XAxes[0].DateOriginYear = CurrentEventTime.otime.Year; - v.XAxes[0].DateOriginDay = CurrentEventTime.otime.Day; - v.XAxes[0].DateOriginMonth = CurrentEventTime.otime.Month; - - DateTime MaxDateTime = CurrentEventTime.otime.AddSeconds(_samplingFrequency == 500 ? 30 : 60); - v.XAxes[0].SetRange(v.XAxes[0].DateTimeToAxisValue(CurrentEventTime.otime), v.XAxes[0].DateTimeToAxisValue(MaxDateTime)); + v.XAxes[0].DateOriginYear = beginTime.Year; + v.XAxes[0].DateOriginDay = beginTime.Day; + v.XAxes[0].DateOriginMonth = beginTime.Month; + DateTime MaxDateTime = beginTime.AddSeconds(_samplingFrequency == 500 ? 30 : 60); + v.XAxes[0].SetRange(v.XAxes[0].DateTimeToAxisValue(beginTime), v.XAxes[0].DateTimeToAxisValue(MaxDateTime)); } + double firstSampleTimeStamp = v.XAxes[0].DateTimeToAxisValue(beginTime); - double firstSampleTimeStamp = v.XAxes[0].DateTimeToAxisValue(CurrentEventTime.otime); - for (int i = 0; i < smList.Count; i++) + int count = stationModel.Dzne.Count; + int number= smList.Count; + for (int i = 0; i < number; i++) { - for (int k = 0; k < smList.ElementAt(i).Dzne.Count; k++) + for (int k = 0; k { - FeedNewDataToChar(multiChannelData); + LChartALL.BeginUpdate(); + _wavesModel.CreateAxisYEventTime(CurrentEventTime, LChartALL.ViewXY, smList.ToList()); + for (int channelIndex = 0; channelIndex < _channelCount; channelIndex++) + { + LChartALL.ViewXY.SampleDataSeries[channelIndex].AddSamples(_data[channelIndex], true); + } + LChartALL.EndUpdate(); }); } catch (Exception ex) @@ -744,19 +588,6 @@ namespace mseedChart.MainModule.ViewModels } } - private void FeedNewDataToChar(double[][] data) - { - LChartALL.BeginUpdate(); - _wavesModel.CreateAxisYEventTime(CurrentEventTime, LChartALL.ViewXY, smList.ToList()); - for (int channelIndex = 0; channelIndex < _channelCount; channelIndex++) - { - LChartALL.ViewXY.SampleDataSeries[channelIndex].AddSamples(data[channelIndex], true); - } - LChartALL.EndUpdate(); - - } - - #region 实时数据 private void CompositionTarget_Rendering(object sender, EventArgs e) { @@ -780,7 +611,6 @@ namespace mseedChart.MainModule.ViewModels int PreGenerateDataForRoundCount = 6; private void FeedData(/*string chartTitleText*/) { - if (_lChartAll != null) { _lChartAll.BeginUpdate(); diff --git a/mseedChart.MainModule/Views/ChartPlotView.xaml b/mseedChart.MainModule/Views/ChartPlotView.xaml index cebb82e..4999339 100644 --- a/mseedChart.MainModule/Views/ChartPlotView.xaml +++ b/mseedChart.MainModule/Views/ChartPlotView.xaml @@ -14,23 +14,41 @@ + + + + + + + + - + - - - - - - X轴时间间隔: + + + + + + + + + + + + + + + X轴间隔: - - + - - + + + + diff --git a/mseedChart.MainModule/mseedChart.MainModule.csproj b/mseedChart.MainModule/mseedChart.MainModule.csproj index 2e6e372..553af15 100644 --- a/mseedChart.MainModule/mseedChart.MainModule.csproj +++ b/mseedChart.MainModule/mseedChart.MainModule.csproj @@ -108,6 +108,7 @@ + Code