修改功能

master
mzhifa 2 years ago
parent 1fcae94da6
commit d958cc372a

@ -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<object> SelectCommand { set; get; }
}
}

@ -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<AxisY>();
}
public StationEventJson mseedJsonResolve(string jsonFile)
public ConcurrentQueue<StationModel> 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<StationModel> smList = new ConcurrentQueue<StationModel>();
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<StationModel> UpdateWavesFromTxt(string fn)
{
var str = File.ReadAllText(jsonFile);
var st = JsonConvert.DeserializeObject<StationEventJson[]>(str);
string allStr;
List<StationModel> temSM = new List<StationModel>();
using (StreamReader streamReader = new StreamReader(fn))
{
allStr = streamReader.ReadToEnd();
}
if (allStr.Length > 0)
{
string[] strLines = allStr.Trim().Split(new char[] { '\n' });
// List<string> 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<StationEventJson[]>(str);
StationEventJson jsonST = st[0];
return jsonST;
}
return null;
StationEventJson jsonST = st[0];
return jsonST;
}
}
}

@ -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<StationModel> smList;
public List<AxisY> _chartAxisY=new List<AxisY>();
#endregion
#region 属性
private List<string> _yaxisItems=new List<string>();
public List<string> 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<string> _stationYaxis;
private List<StationAxis> _stationsName;
public List<string> StationYaxis
public List<StationAxis> 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<object> AxesYVisibleCommand => new DelegateCommand<object>(AxesYVisible);
public DelegateCommand FileSelectorCommand => new DelegateCommand(FileSelector);
public DelegateCommand<object> OtimeSortCommand => new DelegateCommand<object>(OtimeSort);
public DelegateCommand<object> YasixZENVisibleCommand => new DelegateCommand<object>(YasixZENVisible);
public DelegateCommand IntervalSureCommand => new DelegateCommand(IntervalSure);
public DelegateCommand<object> RealTimeDataCommand => new DelegateCommand<object>(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<object>(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<bool> indexs = new List<bool>();
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<StationModel> UpdateWavesFromTxt(string fn)
{
string allStr;
List<StationModel> temSM = new List<StationModel>();
using (StreamReader streamReader = new StreamReader(fn))
{
allStr = streamReader.ReadToEnd();
}
if (allStr.Length > 0)
{
string[] strLines = allStr.Trim().Split(new char[] { '\n' });
List<string> 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<StationModel>();
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 <count; k++)
{
int seriesIndex = i * 3 + k;
AxisY axisY = v.YAxes[seriesIndex];
@ -637,12 +475,11 @@ namespace mseedChart.MainModule.ViewModels
axisY.LabelsAngle = 0;
axisY.LabelsFont.Size = 8;
axisY.Title.Angle = 0;
axisY.MajorGrid.Visible = true;
// axisY.MajorGrid.Visible = true;
axisY.MinorGrid.Visible = false;
axisY.MajorGrid.Pattern = LinePattern.Solid;
axisY.AutoDivSpacing = false;
// axisY.AutoDivSeparationPercent = 100;
axisY.Visible = true;
axisY.MajorDivCount = 2;
axisY.MajorDivTickStyle.Visible = true;
axisY.MinorDivTickStyle.Visible = false;
@ -679,25 +516,32 @@ namespace mseedChart.MainModule.ViewModels
series.ScrollingStabilizing = true;
series.AllowUserInteraction = false;
v.SampleDataSeries.Add(series);
_chartAxisY.Add(axisY);
}
}
}
private void UpdateChartData()
private void FeedDatasToChart()
{
double[][] multiChannelData = new double[smList.Count * 3][];
_data = new double[smList.Count * 3][];
try
{
for (int channelIndex = 0; channelIndex < smList.Count; channelIndex++)
{
multiChannelData[channelIndex * 3] = smList.ElementAt(channelIndex).dz.ToArray();
multiChannelData[channelIndex * 3 + 1] = smList.ElementAt(channelIndex).dn.ToArray();
multiChannelData[channelIndex * 3 + 2] = smList.ElementAt(channelIndex).de.ToArray();
_data[channelIndex * 3] = smList.ElementAt(channelIndex).dz.ToArray();
_data[channelIndex * 3 + 1] = smList.ElementAt(channelIndex).dn.ToArray();
_data[channelIndex * 3 + 2] = smList.ElementAt(channelIndex).de.ToArray();
}
_data = multiChannelData;
// Invoke FeedNewDataToChart.
_dispatcher.Invoke(() =>
{
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();

@ -14,23 +14,41 @@
<RowDefinition Height="30"/>
<RowDefinition Height="10000*"/>
</Grid.RowDefinitions>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding Path=LoadedCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unloaded">
<i:InvokeCommandAction Command="{Binding Path=UnloadedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBlock Text="{Binding Message}"
HorizontalAlignment="Center"
VerticalAlignment="Top" Margin="0,162,0,0" Grid.Row="1" />
<DockPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Command="{Binding AxesYVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="Y轴显示" VerticalContentAlignment="Center" IsChecked="True" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold" />
<ComboBox ItemsSource="{Binding StationYaxis}" SelectedIndex="{Binding SelectStationYaxisIndex}"/>
<CheckBox IsChecked="{Binding StationYaxisIsChecked}" Content="台站" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<CheckBox Command="{Binding OtimeSortCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="排序" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<ComboBox ItemsSource="{Binding YaxisItems}" SelectedIndex="{Binding SelectIndex}" />
<CheckBox Command="{Binding YasixZENVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="ZEN" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<TextBlock VerticalAlignment="Center">X轴时间间隔:</TextBlock>
<ComboBox ItemsSource="{Binding StationsName}" SelectedIndex="{Binding SelectStationYaxisIndex}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}" Command="{Binding SelectCommand}" CommandParameter="{Binding }" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Command="{Binding OtimeSortCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="时间排序" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<CheckBox Command="{Binding YasixZENVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" IsChecked="True" Content="SHZ" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<CheckBox Command="{Binding YasixZENVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" IsChecked="True" Content="SHN" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<CheckBox Command="{Binding YasixZENVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" IsChecked="True" Content="SHE" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<TextBlock VerticalAlignment="Center">X轴间隔:</TextBlock>
<TextBox Text="{Binding XaisInterval}" Width="80" VerticalAlignment="Center"></TextBox>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding IntervalSureCommand}" Margin="20,0,50,0" Background="#FF66B1FF" HorizontalAlignment="Right" Width="60">OK</Button>
<CheckBox Command="{Binding RealTimeDataCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="实时数据" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" FontWeight="Bold" DockPanel.Dock="Right"></CheckBox>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding IntervalSureCommand}" Margin="10,0,10,0" Background="#FF66B1FF" HorizontalAlignment="Right" Height="20" Width="30">OK</Button>
<CheckBox IsChecked="{Binding IsMultFiles}" Content="MultFiles" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" FontWeight="Bold" DockPanel.Dock="Right"></CheckBox>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding FileSelectorCommand}" Margin="0,0,50,0" Background="#FF66B1FF" HorizontalAlignment="Right" Width="60">Open</Button>
</DockPanel>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding FileSelectorCommand}" Margin="5,0,20,0" Background="#FF66B1FF" HorizontalAlignment="Right" Width="60" Height="20">打开</Button>
<CheckBox Command="{Binding RealTimeDataCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="实时" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" FontWeight="Bold" DockPanel.Dock="Right"></CheckBox>
</StackPanel>
<ContentControl x:Name="contentControl" Content="{Binding ChildContent}" Grid.Row="1" />
<TextBlock Text="{Binding CurrentTime}" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,46"></TextBlock>
</Grid>
</UserControl>

@ -108,6 +108,7 @@
<Compile Include="Models\LineDatas.cs" />
<Compile Include="Models\MmEvent.cs" />
<Compile Include="Models\StationModel.cs" />
<Compile Include="Models\StationAxis.cs" />
<Compile Include="Models\WavesModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>

Loading…
Cancel
Save