using Arction.Wpf.ChartingMVVM.Maps; using Arction.Wpf.ChartingMVVM.Views.ViewPolar; using Arction.Wpf.ChartingMVVM; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using OxyPlot.Annotations; using OxyPlot.Axes; using OxyPlot; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Txgy.Microseismic.BaseLib.Models; using Prism.Mvvm; using Txgy.EWS.Client.FocalMechanism.Core; using Txgy.EWS.Client.FocalMechanism.Model; using Txgy.EWS.Client.Common; using FmGrid = Txgy.EWS.Client.FocalMechanism.Model.FmGrid; using FMStation = Txgy.EWS.Client.FocalMechanism.Model.FMStation; using System.Windows.Threading; using Prism.Events; using Txgy.EWS.Client.IBLL; using Unity; using Txgy.EWS.Client.Common.MessageEvents; using Txgy.EWS.Client.Entity; namespace Txgy.EWS.Client.PageModule.ViewModels { public class FocalMechanismViewModel : BindableBase { Dispatcher _dispatcher; IFreeSql fsqlTencent = FreeSqlTencent.tencentRemoteMySQL; private readonly IEventAggregator _ea; private readonly ISearchMsEventBLL searchMsEventBLL; IFreeSql fsqlSqLite = FreeSqlLocalSqLite.freeLocalSqLite; private string pageName= "震源机制页面"; public string PageName { get { return pageName; } set { SetProperty(ref pageName, value); } } private double _stationSize = 20; public double StationSize { get { return _stationSize; } set { SetProperty(ref _stationSize, value); } } private System.Drawing.Color _stationColor; public System.Drawing.Color StationColor { get { return _stationColor; } set { SetProperty(ref _stationColor, value); } } public OxyRect n1105Rect = new OxyRect(38398835.72, 4030097, 305.4, 2168); public OxyRect n1100Rect = new OxyRect(38397556.72, 4029613, 328, 1397); public OxyRect n1103Rect = new OxyRect(38398539.02, 4029605, 307, 1567); private double _eAxisMin; public double EAxisMin { get { return _eAxisMin; } set { SetProperty(ref _eAxisMin, value); } } private double _eAxisMax; public double EAxisMax { get { return _eAxisMax; } set { SetProperty(ref _eAxisMax, value); } } private double _nAxisMin; public double NAxisMin { get { return _nAxisMin; } set { SetProperty(ref _nAxisMin, value); } } private double _nAxisMax; public double NAxisMax { get { return _nAxisMax; } set { SetProperty(ref _nAxisMax, value); } } public ProcessCore pCore { get; set; } public Factory factory { get; set; } public FMMap fmMap { get; set; } public PlotModel PlotModel { get; set; } public const int NumberOfItems = 10; public int fontSize = 16; private int _amplitudePointCount = 361; public int AplitudePointCount { get { return _amplitudePointCount; } set { _amplitudePointCount = value; } } private AxisPolarCollection _axisPolar; public AxisPolarCollection AxisPolar { get { return _axisPolar; } set { SetProperty(ref _axisPolar, value); } } public FocalMechanismViewModel(IUnityContainer unityContainer, IEventAggregator ea, ISearchMsEventBLL searchMsEventBLL) { _dispatcher = unityContainer.Resolve(); this._ea = ea; this.searchMsEventBLL = searchMsEventBLL; EAxisMin = GlobalConfig.ProjectConfig.WorkArea.EMin; EAxisMax = GlobalConfig.ProjectConfig.WorkArea.EMax; NAxisMin = GlobalConfig.ProjectConfig.WorkArea.NMin; NAxisMax = GlobalConfig.ProjectConfig.WorkArea.NMax; this.PlotModel = new PlotModel(); this.PlotModel.Title = "震源机制"; var linearAxis1 = new LinearAxis(); linearAxis1.Minimum = 0; linearAxis1.Maximum = EAxisMax - EAxisMin; //linearAxis1.Minimum = -(EAxisMax - EAxisMin)/2; //linearAxis1.Maximum = (EAxisMax - EAxisMin)/2; linearAxis1.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); linearAxis1.MajorGridlineStyle = OxyPlot.LineStyle.Solid; linearAxis1.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); linearAxis1.MinorGridlineStyle = OxyPlot.LineStyle.Solid; linearAxis1.Position = AxisPosition.Bottom; linearAxis1.Title = "X-axis"; this.PlotModel.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); linearAxis2.Minimum = 0; linearAxis2.Maximum = (NAxisMax - NAxisMin); linearAxis2.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139); linearAxis2.MajorGridlineStyle = OxyPlot.LineStyle.Solid; linearAxis2.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139); linearAxis2.MinorGridlineStyle = OxyPlot.LineStyle.Solid; linearAxis2.Title = "Y-axis"; this.PlotModel.Axes.Add(linearAxis2); SetFacotry(EAxisMax - EAxisMin, NAxisMax - NAxisMin, GlobalConfig.ProjectConfig.StationDic); //this._ea.GetEvent().Subscribe(u => //{ // MmEvent me; // var lre = fsqlSqLite.Select().Where(re => re.EventTime == u).First(); // if (lre == null) // { // //string courseSql = @"select * from " + GlobalConfig.UseResultTable + " where " + GlobalConfig.EventIDColName + "==@eid"; // var rre = this.searchMsEventBLL.GetEvent(u); // if (rre != null) // { // me = new MmEvent(); // me.EventID = rre.EventID; // me.EventTimeStr = rre.EventTimeStr; // me.EventTime = rre.EventTime; // me.X = rre.X; // me.Y = rre.Y; // me.Z = rre.Z; // me.ML = rre.ML; // me.LocSta = rre.LocSta; // me.MLSta = rre.MLSta; // me.Energy = rre.Energy; // ShowEventFocalMechanism(me); // } // } // else // { // me = new MmEvent(); // me.EventID = lre.RTEventID; // me.EventTimeStr = lre.EventTime; // me.EventTime = DateTime.Parse(lre.EventTime); // me.X = lre.Y; // me.Y = lre.X; // me.Z = lre.Z; // me.ML = lre.ML; // me.LocSta = lre.LocSta; // me.MLSta = lre.MLSta; // me.SetEnergy(); // ShowEventFocalMechanism(me); // } //}); } public void SetFacotry(double XMax, double YMax, Dictionary StationDic) { FmGrid fmGrid = new FmGrid(); fmGrid.xmin = 0; fmGrid.xmax = XMax; fmGrid.ymin = 0; fmGrid.ymax = YMax; fmGrid.StationCount = StationDic.Count; fmGrid.StationList = new List(); int sc = 0; foreach (var item in StationDic) { fmGrid.StationList.Add(new FMStation(sc, item.Key, XMax, YMax)); sc++; } fmGrid.initZeroCenter(); fmGrid.computeDistance(); pCore = new ProcessCore(fmGrid); factory = new Factory(fmGrid); } private void ConverterData(object obj) { //AmplitudeSeries = _amplitudeModel.GenerateAmplitudeSeries(AplitudePointCount); //OpenFileDialog ofd=new OpenFileDialog(); //ofd.Filter = "Mseed文件|*.mseed"; //if (ofd.ShowDialog()==true) //{ // string path = Path.GetDirectoryName(ofd.FileName); // string[] mseedFiles = Directory.GetFiles(path, "*.mseed"); // string ascPath = path + "\\txt"; // if (!Directory.Exists(ascPath)) // { // Directory.CreateDirectory(ascPath); // } // for (int i = 0; i < mseedFiles.Length; i++) // { // string saveFn=Path.GetFileNameWithoutExtension(mseedFiles[i]) +".txt"; // Task.Factory.StartNew(() => { // PublicConfig.MSeed2Asc(mseedFiles[i], ascPath + "\\" + saveFn); // }); // Thread.Sleep(100); // Console.WriteLine(i); // } // Dialog.Show(new TextDialog() { ShowText = "转换完成!" }); //} } private void CheckEventShowWave(MmEvent mmEvent) { string downLoadStr = mmEvent.EventTimeStr; string datePath = downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2); string mseedStr = "HA." + downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2) + downLoadStr.Substring(10, 3) + downLoadStr.Substring(14, 2) + downLoadStr.Substring(17, 2) + ".01" + GlobalConfig.DataTypeString; string mseedPath = GlobalConfig.ProjectConfig.MseedFilePath + "\\" + datePath + "\\"; string savePath = GlobalConfig.ProjectConfig.TxtFilePath + "\\" + datePath + "\\" + mseedStr + ".txt"; if (!File.Exists(mseedPath + mseedStr + ".mseed")) { if (!Directory.Exists(mseedPath)) { Directory.CreateDirectory(mseedPath); } this.searchMsEventBLL.DownLoadWavedata(downLoadStr, mseedPath, mseedStr, GlobalConfig.UseWaveDataTable); if (!File.Exists(savePath)) { if (!Directory.Exists(Path.GetDirectoryName(savePath))) { Directory.CreateDirectory(Path.GetDirectoryName(savePath)); } //MSeed2Asc(mseedPath + mseedStr + ".mseed", savePath); } //Dialog.Show(new TextDialog() { ShowText = mseedPath + mseedStr + ".mseed" + "下载完成!" }); } else { //if (!File.Exists(savePath)) //{ // if (!Directory.Exists(Path.GetDirectoryName(savePath))) // { // Directory.CreateDirectory(Path.GetDirectoryName(savePath)); // } // MSeed2Asc(mseedPath + mseedStr + ".mseed", savePath); //} //Dialog.Show(new TextDialog() { ShowText = mseedPath + mseedStr + ".mseed" + "已存在!" }); } } private void ShowEventFocalMechanism(object obj) { double lineLen = 50; double lineStep = 10; FracturePoint r1 = new FracturePoint(0, 0); FracturePoint r2 = new FracturePoint(0, 0); this.PlotModel.Annotations.Clear(); MmEvent CurMmEvent = (MmEvent)obj; CheckEventShowWave(CurMmEvent); SetEventPhases(CurMmEvent); //fmMap = CreateFM(CurMmEvent); ComputeFM(CurMmEvent); switch (CurMmEvent.FocalType) { case FocalMechanismType.strikeSlip: FractureLine strikeSlipLine1 = new FractureLine(); strikeSlipLine1.p1 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin + lineStep), (float)(CurMmEvent.Y - lineLen - NAxisMin)); strikeSlipLine1.p2 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin + lineStep), (float)(CurMmEvent.Y + lineLen - NAxisMin)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine1.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine1.p2, CurMmEvent.Direction); strikeSlipLine1.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); strikeSlipLine1.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateStrikeSlipModel(strikeSlipLine1)); FractureLine strikeSlipLine2 = new FractureLine(); strikeSlipLine2.p1 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin - lineStep), (float)(CurMmEvent.Y - lineLen - NAxisMin)); strikeSlipLine2.p2 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin - lineStep), (float)(CurMmEvent.Y + lineLen - NAxisMin)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine2.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine2.p2, CurMmEvent.Direction); strikeSlipLine2.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); strikeSlipLine2.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateStrikeSlipModel(strikeSlipLine2)); break; case FocalMechanismType.dipSlip: FractureLine dipSlipLine = new FractureLine(); dipSlipLine.p1 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - lineLen - NAxisMin)); dipSlipLine.p2 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y + lineLen - NAxisMin)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), dipSlipLine.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), dipSlipLine.p2, CurMmEvent.Direction); dipSlipLine.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); dipSlipLine.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateDipSlipModel(dipSlipLine)); break; case FocalMechanismType.tensile: this.PlotModel.Annotations.Add(CreateTensileModel(CurMmEvent, EAxisMin, NAxisMin)); FractureLine tensileLine = new FractureLine(); tensileLine.p1 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - lineLen - NAxisMin)); tensileLine.p2 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y + lineLen - NAxisMin)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), tensileLine.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), tensileLine.p2, CurMmEvent.Direction); tensileLine.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); tensileLine.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateLineModel(tensileLine)); break; case FocalMechanismType.unknown: strikeSlipLine1 = new FractureLine(); strikeSlipLine1.p1 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin + lineStep), (float)(CurMmEvent.Y - lineLen - NAxisMin)); strikeSlipLine1.p2 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin + lineStep), (float)(CurMmEvent.Y + lineLen - NAxisMin)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine1.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine1.p2, CurMmEvent.Direction); strikeSlipLine1.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); strikeSlipLine1.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateStrikeSlipModel(strikeSlipLine1)); strikeSlipLine2 = new FractureLine(); strikeSlipLine2.p1 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin - lineStep), (float)(CurMmEvent.Y - lineLen - NAxisMin)); strikeSlipLine2.p2 = new FracturePoint((float)((float)CurMmEvent.X - EAxisMin - lineStep), (float)(CurMmEvent.Y + lineLen - NAxisMin)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine2.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X - EAxisMin), (float)(CurMmEvent.Y - NAxisMin)), strikeSlipLine2.p2, CurMmEvent.Direction); strikeSlipLine2.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); strikeSlipLine2.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateStrikeSlipModel(strikeSlipLine2)); break; default: break; } CreateStationOxy(CurMmEvent); //Console.WriteLine(r1.X.ToString() + "\t" + r1.Y.ToString() + "\t" + CurMmEvent.Direction.ToString()); //Console.WriteLine(r2.X.ToString() + "\t" + r2.Y.ToString() + "\t" + CurMmEvent.Direction.ToString()); this.PlotModel.InvalidatePlot(true); } public void ShowEventInfo() { //AllWaveDataList = PublicConfig.CreateWaveModelFromText(CurMmEvent.AsciiFile); //this.PlotModel.Annotations.Clear(); //SetShowWaveModel(CurMmEvent); //AmplitudeSeries = _amplitudeModel.GenerateAmplitudeSeries(showWaveDataList); //AxisPolar = _amplitudeModel.GenerateAxes(); ////Console.WriteLine(Math.Round(cm.DominantFreq, 3).ToString()); //PointLineSeries = _amplitudeModel.GenerateData(showWaveDataList); //if (CurMmEvent == null) //{ // System.Windows.Forms.MessageBox.Show("没有符合条件的数据"); // return; //} //CreateStationOxy(CurMmEvent); //this.PlotModel.Annotations.Add(AddFocalMechaismModel(CurMmEvent)); //var arrowAnnotation1 = new ArrowAnnotation(); //arrowAnnotation1.Color = OxyColors.Green; //arrowAnnotation1.StartPoint = new DataPoint(CurMmEvent.X - EAxisMin, CurMmEvent.Y - NAxisMin); //arrowAnnotation1.EndPoint = new DataPoint(CurMmEvent.X - EAxisMin + 10, CurMmEvent.Y - NAxisMin + 10); //arrowAnnotation1.Text = "StartPoint and EndPoint"; //this.PlotModel.Annotations.Add(arrowAnnotation1); //var linearAxis1 = new LinearAxis(); //linearAxis1.Maximum = CurMmEvent.X-EAxisMin; //linearAxis1.Minimum = CurMmEvent.Y - NAxisMax; //linearAxis1.Position = AxisPosition.Bottom; //this.PlotModel.Axes.Add(linearAxis1); //计算震源机制数据 //fmMap = CreateFM(CurMmEvent); //ComputeFM(fmMap); this.PlotModel.InvalidatePlot(true); } /// /// 以中心点旋转Angle角度 /// /// 中心点 /// 待旋转的点 /// 旋转角度, 逆时针 private PointF PointRotate(PointF origin, PointF rePoint, double angle) { float x = (float)((rePoint.X - origin.X) * Math.Cos(angle) - (rePoint.Y - origin.Y) * Math.Sin(angle) + origin.X); float y = (float)((rePoint.X - origin.X) * Math.Sin(angle) + (rePoint.Y - origin.Y) * Math.Cos(angle) + origin.Y); return new PointF(x, y); } private FracturePoint PointRotate(FracturePoint origin, FracturePoint rePoint, double angle) { FracturePoint rotatePoint = new FracturePoint(); double arc = angle * Math.PI / 180.0; double x = (rePoint.X - origin.X) * Math.Cos(-arc) - (rePoint.Y - origin.Y) * Math.Sin(-arc) + origin.X; double y = (rePoint.X - origin.X) * Math.Sin(-arc) + (rePoint.Y - origin.Y) * Math.Cos(-arc) + origin.Y; rotatePoint.X = (float)x; rotatePoint.Y = (float)y; return rotatePoint; } public ComputationResult MmEventCalFocalMechanism(MmEvent mmEvent, double BaseX, double BaseY) { FMMap fmMap = new FMMap(); fmMap.X = mmEvent.X - BaseX; fmMap.Y = mmEvent.Y - BaseY; fmMap.R = mmEvent.RMS; foreach (var item in mmEvent.Phases) { if (item.Value == -1) { fmMap.negStation.Add(item.Key); } else { fmMap.posStation.Add(item.Key); } } //ComputationResult cr = pCore.ComputeResult(fmMap); //if (cr == null) // return null; //return cr; //mmEvent.FocalType = cr.FocalType; //mmEvent.Direction = cr.Direction; return null; } public void SetShowWaveModelFromSqLite(MmEvent cm) { //foreach (var item in cm.Phases) //{ // WaveDataModel wdm = AllWaveDataList.Where(awd => awd.waveHeader.StationName // == stationName && awd.waveHeader.Channel == "Z").First(); // DateTime dt = DateTime.Parse(phaseArr[i]["atime"].ToString()); // wdm.waveHeader.MaxValueIndex = PublicConfig.GetWaveMaxAmpIndex(wdm, dt); // wdm.waveHeader.MaxValue = Math.Abs(wdm.Points[wdm.waveHeader.MaxValueIndex]); // wdm.waveHeader.MaxAmp = WaveHeader.CalAmp(wdm.waveHeader.MaxValue, 4); // wdm.waveHeader.ToEventDist = WaveHeader.CalDist(cm, stationName); // wdm.mmEvent = cm; // StationModel sm = PublicConfig.ProjectConfig.StationDic.First(sd => sd.Key == stationName).Value; // PointF p1 = new PointF((float)cm.X, (float)cm.Y); // PointF p2 = new PointF((float)sm.E, (float)sm.N); // double angleOfLine = WaveHeader.PointsAngleTool(p1, p2); // double realAngle = 0; // if (angleOfLine > 0 && angleOfLine <= 90)//右 // { // realAngle = 90 - angleOfLine; // } // else if (angleOfLine > 90 && angleOfLine <= 180)//左 // { // realAngle = 450 - angleOfLine; // } // else if (angleOfLine >= -180 && angleOfLine <= 0)//上 // { // realAngle = 90 - angleOfLine; // } // wdm.waveHeader.ToEventAngle = (int)realAngle; // //Console.WriteLine(wdm.waveHeader.ToEventAngle); // showWaveDataList.Add(wdm); //} } public void SetShowWaveModel(MmEvent cm) { //using (StreamReader sr = System.IO.File.OpenText(cm.JsonFile)) //{ // JsonTextReader reader = new JsonTextReader(sr); // JArray jArray = (JArray)JToken.ReadFrom(reader); // JObject jobj = (JObject)jArray[0]; // JArray phaseArr = JArray.FromObject(jobj["phases"]); // showWaveDataList = new List(); // for (int i = 0; i < phaseArr.Count; i++) // { // if (phaseArr[i]["first_motion_direct"] != null) // { // string stationName = phaseArr[i]["id"].ToString().Substring(3, 3); // WaveDataModel wdm = AllWaveDataList.Where(awd => awd.waveHeader.StationName // == stationName && awd.waveHeader.Channel == "Z").First(); // DateTime dt = DateTime.Parse(phaseArr[i]["atime"].ToString()); // wdm.waveHeader.MaxValueIndex = PublicConfig.GetWaveMaxAmpIndex(wdm, dt); // wdm.waveHeader.MaxValue = Math.Abs(wdm.Points[wdm.waveHeader.MaxValueIndex]); // wdm.waveHeader.MaxAmp = WaveHeader.CalAmp(wdm.waveHeader.MaxValue, 4); // wdm.waveHeader.ToEventDist = WaveHeader.CalDist(cm, stationName); // wdm.mmEvent = cm; // StationModel sm = PublicConfig.ProjectConfig.StationDic.First(sd => sd.Key == stationName).Value; // PointF p1 = new PointF((float)cm.X, (float)cm.Y); // PointF p2 = new PointF((float)sm.E, (float)sm.N); // double angleOfLine = WaveHeader.PointsAngleTool(p1, p2); // double realAngle = 0; // if (angleOfLine > 0 && angleOfLine <= 90)//右 // { // realAngle = 90 - angleOfLine; // } // else if (angleOfLine > 90 && angleOfLine <= 180)//左 // { // realAngle = 450 - angleOfLine; // } // else if (angleOfLine >= -180 && angleOfLine <= 0)//上 // { // realAngle = 90 - angleOfLine; // } // wdm.waveHeader.ToEventAngle = (int)realAngle; // //Console.WriteLine(wdm.waveHeader.ToEventAngle); // showWaveDataList.Add(wdm); // } // } //} } public void CreateStationOxy(MmEvent cm) { #region oxyplot //this.PlotModel.Annotations.Clear(); RectangleAnnotation fra1100 = new RectangleAnnotation(); fra1100.MinimumX = n1100Rect.Left - EAxisMin; fra1100.MaximumX = n1100Rect.Right - EAxisMin; fra1100.MinimumY = n1100Rect.Bottom - NAxisMin; fra1100.MaximumY = n1100Rect.Top - NAxisMin; fra1100.Fill = OxyColor.FromArgb(0, 0, 0, 0); //zra.Fill = OxyColor.FromArgb(99, 0, 0, 255); fra1100.StrokeThickness = 2; fra1100.Stroke = OxyColor.FromArgb(255, 255, 0, 255); fra1100.Text = "N1100"; //zra.TextRotation = 10; this.PlotModel.Annotations.Add(fra1100); RectangleAnnotation fra1103 = new RectangleAnnotation(); fra1103.MinimumX = n1103Rect.Left - EAxisMin; fra1103.MaximumX = n1103Rect.Right - EAxisMin; fra1103.MinimumY = n1103Rect.Bottom - NAxisMin; fra1103.MaximumY = n1103Rect.Top - NAxisMin; fra1103.Fill = OxyColor.FromArgb(0, 0, 0, 0); //zra.Fill = OxyColor.FromArgb(99, 0, 0, 255); fra1103.StrokeThickness = 2; fra1103.Stroke = OxyColor.FromArgb(255, 255, 0, 255); fra1103.Text = "N1103"; //zra.TextRotation = 10; this.PlotModel.Annotations.Add(fra1103); this.PlotModel.Annotations.Add(CreateEventModelOxy(cm)); foreach (var item in cm.Phases) { StationModel sm; var stationDic = GlobalConfig.ProjectConfig.StationDic.Where(sd => sd.Key == item.Key.ToUpper()); if (stationDic.Count() > 0) { sm = stationDic.First().Value; if (item.Value > 0) { this.PlotModel.Annotations.Add(CreatePolygon(sm.Name, sm.E - EAxisMin, sm.N - NAxisMin, StationSize, OxyColors.Red)); } else { this.PlotModel.Annotations.Add(CreatePolygon(sm.Name, sm.E - EAxisMin, sm.N - NAxisMin, StationSize, OxyColors.Transparent)); } } } #endregion } public void CreateStationLv(MmEvent cm) { #region livechart #endregion } /// /// LiveCharts /// /// public void ShowStationLv(object o) { } public EllipseAnnotation CreateEventModelOxy(MmEvent mm) { var ellipseAnnotation1 = new EllipseAnnotation(); ellipseAnnotation1.X = mm.X - EAxisMin; ellipseAnnotation1.Y = mm.Y - NAxisMin; ellipseAnnotation1.Width = StationSize; ellipseAnnotation1.Height = StationSize; ellipseAnnotation1.Fill = OxyColor.FromArgb(255, 0, 128, 0); return ellipseAnnotation1; } public PolygonAnnotation CreatePolygon(string text, double x, double y, double size, OxyColor color) { PolygonAnnotation pa = new PolygonAnnotation(); pa.Text = text.Substring(1); pa.TextPosition = new DataPoint(x, y); pa.TextHorizontalAlignment = OxyPlot.HorizontalAlignment.Center; pa.TextVerticalAlignment = OxyPlot.VerticalAlignment.Middle; pa.FontSize = size * 0.7; pa.Font = "Arail"; pa.Fill = color; pa.StrokeThickness = 2; pa.Stroke = OxyColors.Black; pa.Points.Add(new DataPoint(x - size, y - size)); pa.Points.Add(new DataPoint(x + size, y - size)); pa.Points.Add(new DataPoint(x + size, y + size)); pa.Points.Add(new DataPoint(x - size, y + size)); return pa; } public PolygonAnnotation AddFocalMechaismModel(MmEvent mmEvent) { double x = mmEvent.X - EAxisMin; double y = mmEvent.Y - NAxisMin; double angle = mmEvent.Direction; double major = 50; double minor = 30; return GeneratePolygonAsEllipse(x, y, angle, major, minor); } private PolygonAnnotation GeneratePolygonAsEllipse(double xCenter, double yCenter, double AngleOfRotation, double MajorAxisLength, double MinorAxisLength) { PolygonAnnotation polygonAnnotation = new PolygonAnnotation(); polygonAnnotation.Fill = OxyColor.FromArgb(0, 0, 0, 0); polygonAnnotation.Stroke = OxyColors.Blue; polygonAnnotation.StrokeThickness = 2; double step = 2 * Math.PI / 200; var h = xCenter; var k = yCenter; var rotation = AngleOfRotation; var a = MajorAxisLength; var b = MinorAxisLength; for (double theta = 0; theta < 2 * Math.PI; theta += step) { var x = a * Math.Cos(rotation) * Math.Cos(theta) + b * Math.Sin(rotation) * Math.Sin(theta) + h; var y = b * Math.Cos(rotation) * Math.Sin(theta) + a * Math.Sin(rotation) * Math.Cos(theta) + k; polygonAnnotation.Points.Add(new DataPoint(x, y)); } return polygonAnnotation; } public void DrawStrikeSlip(MmEvent CurMmEvent) { FractureLine strikeSlipLine1 = new FractureLine(); strikeSlipLine1.p1 = new FracturePoint((float)((float)CurMmEvent.X + 2), (float)(CurMmEvent.Y - 10)); strikeSlipLine1.p2 = new FracturePoint((float)((float)CurMmEvent.X + 2), (float)(CurMmEvent.Y + 10)); FracturePoint r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X), (float)(CurMmEvent.Y)), strikeSlipLine1.p1, CurMmEvent.Direction); FracturePoint r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X), (float)(CurMmEvent.Y)), strikeSlipLine1.p2, CurMmEvent.Direction); strikeSlipLine1.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); strikeSlipLine1.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateStrikeSlipModel(strikeSlipLine1)); FractureLine strikeSlipLine2 = new FractureLine(); strikeSlipLine2.p1 = new FracturePoint((float)((float)CurMmEvent.X - 2), (float)(CurMmEvent.Y - 10)); strikeSlipLine2.p2 = new FracturePoint((float)((float)CurMmEvent.X - 2), (float)(CurMmEvent.Y + 10)); r1 = PointRotate(new FracturePoint((float)(CurMmEvent.X), (float)(CurMmEvent.Y)), strikeSlipLine2.p1, CurMmEvent.Direction); r2 = PointRotate(new FracturePoint((float)(CurMmEvent.X), (float)(CurMmEvent.Y)), strikeSlipLine2.p2, CurMmEvent.Direction); strikeSlipLine2.p1 = new FracturePoint((float)(r1.X), (float)(r1.Y)); strikeSlipLine2.p2 = new FracturePoint((float)(r2.X), (float)(r2.Y)); this.PlotModel.Annotations.Add(CreateStrikeSlipModel(strikeSlipLine2)); } /// /// 绘制走滑模型,黑色双线 /// /// public LineAnnotation CreateStrikeSlipModel(FractureLine fractureLine) { double slope = (fractureLine.p2.Y - fractureLine.p1.Y) / (fractureLine.p2.X - fractureLine.p1.X); if (slope == 0) { slope = 0.5; } //Console.WriteLine(slope); double intercept = fractureLine.p2.Y - slope * fractureLine.p2.X; //Console.WriteLine(intercept); LineAnnotation lineAnnotation = new LineAnnotation(); var linearAxis1 = new LinearAxis(); //Y截距 lineAnnotation.Intercept = intercept; //斜率 lineAnnotation.Slope = slope; lineAnnotation.Color = OxyColors.Black; lineAnnotation.MaximumX = fractureLine.p2.X; lineAnnotation.MinimumX = fractureLine.p1.X; lineAnnotation.LineStyle = OxyPlot.LineStyle.Solid; lineAnnotation.StrokeThickness = 2; //lineAnnotation.Text = "Second"; return lineAnnotation; } public LineAnnotation CreateDipSlipModel(FractureLine fractureLine) { double slope = (fractureLine.p2.Y - fractureLine.p1.Y) / (fractureLine.p2.X - fractureLine.p1.X); if (slope == 0) { slope = 0.5; } //Console.WriteLine(slope); double intercept = fractureLine.p2.Y - slope * fractureLine.p2.X; //Console.WriteLine(intercept); LineAnnotation lineAnnotation = new LineAnnotation(); var linearAxis1 = new LinearAxis(); //Y截距 lineAnnotation.Intercept = intercept; //斜率 lineAnnotation.Slope = slope; lineAnnotation.Color = OxyColors.Blue; lineAnnotation.MaximumX = fractureLine.p2.X; lineAnnotation.MinimumX = fractureLine.p1.X; lineAnnotation.LineStyle = OxyPlot.LineStyle.Solid; lineAnnotation.StrokeThickness = 2; //lineAnnotation.Text = "Second"; return lineAnnotation; } public EllipseAnnotation CreateTensileModel(MmEvent mmEvent, double baseX, double baseY) { EllipseAnnotation ellipseAnnotation = new EllipseAnnotation(); ellipseAnnotation.X = mmEvent.X - baseX; ellipseAnnotation.Y = mmEvent.Y - baseY; ellipseAnnotation.StrokeThickness = 2; ellipseAnnotation.Stroke = OxyColors.Red; ellipseAnnotation.Fill = OxyColor.FromArgb(0, 0, 0, 0); ellipseAnnotation.Width = 10; ellipseAnnotation.Height = 10; return ellipseAnnotation; } private LineAnnotation CreateLineModel(FractureLine fractureLine) { double slope = (fractureLine.p2.Y - fractureLine.p1.Y) / (fractureLine.p2.X - fractureLine.p1.X); if (slope == 0) { slope = 0.5; } //Console.WriteLine(slope); double intercept = fractureLine.p2.Y - slope * fractureLine.p2.X; //Console.WriteLine(intercept); LineAnnotation lineAnnotation = new LineAnnotation(); var linearAxis1 = new LinearAxis(); //Y截距 lineAnnotation.Intercept = intercept; //斜率 lineAnnotation.Slope = slope; lineAnnotation.Color = OxyColors.Red; lineAnnotation.MaximumX = fractureLine.p2.X; lineAnnotation.MinimumX = fractureLine.p1.X; lineAnnotation.LineStyle = OxyPlot.LineStyle.Solid; lineAnnotation.StrokeThickness = 2; //lineAnnotation.Text = "Second"; return lineAnnotation; } public void SetEventPhases(MmEvent mmEvent) { string downLoadStr = mmEvent.EventTimeStr; string datePath = downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2); string jsonStr = "HA." + downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2) + downLoadStr.Substring(10, 3) + downLoadStr.Substring(14, 2) + downLoadStr.Substring(17, 2) + ".01"+GlobalConfig.DataTypeString+".json"; string jsonFilePath = GlobalConfig.ProjectConfig.MseedFilePath + "\\" + datePath + "\\" + jsonStr; if (File.Exists(jsonFilePath)) { using (StreamReader sr = System.IO.File.OpenText(jsonFilePath)) { mmEvent.JsonFile = jsonFilePath; JsonTextReader reader = new JsonTextReader(sr); JArray jArray = (JArray)JToken.ReadFrom(reader); //解析普通属性和数组混合的Json文件 //数组0是普通属性集合 JObject jobj = (JObject)jArray[0]; mmEvent.SetEnergy(); mmEvent.DominantFreq = 15; mmEvent.Phases = new Dictionary(); List DominantFreqlist = new List(); JArray phaseArr = JArray.FromObject(jobj["phases"]); List DominantFreqList = new List(); for (int i = 0; i < phaseArr.Count; i++) { if (phaseArr[i]["first_motion_direct"] != null) { mmEvent.Phases.Add(phaseArr[i]["id"].ToString().Substring(3, 3), int.Parse(phaseArr[i]["first_motion_direct"].ToString())); } if (phaseArr[i]["fmd_semi_period"] != null) { DominantFreqlist.Add(double.Parse(phaseArr[i]["fmd_semi_period"].ToString())); } } if (DominantFreqlist.Count > 0) { if (DominantFreqlist.Count > 3) { double min = DominantFreqlist.Min(); double max = DominantFreqlist.Max(); DominantFreqlist.Remove(min); DominantFreqlist.Remove(max); mmEvent.DominantFreq = DominantFreqlist.Sum() / (double)DominantFreqlist.Count; } else { mmEvent.DominantFreq = 0; } } } } } public MmEvent Json2MmEvent(string jsonFile) { using (StreamReader sr = System.IO.File.OpenText(jsonFile)) { MmEvent mmEvent = new MmEvent(); mmEvent.JsonFile = jsonFile; string filePath = System.IO.Path.GetDirectoryName(jsonFile); string fileName = System.IO.Path.GetFileNameWithoutExtension(jsonFile).TrimEnd('B').TrimEnd('A'); string ascName = filePath + "\\" + fileName + ".txt"; mmEvent.AsciiFile = ascName; JsonTextReader reader = new JsonTextReader(sr); JArray jArray = (JArray)JToken.ReadFrom(reader); //解析普通属性和数组混合的Json文件 //数组0是普通属性集合 JObject jobj = (JObject)jArray[0]; string dateStr = jobj["otime"].ToString(); mmEvent.EventTime = DateTime.Parse(dateStr); mmEvent.EventTimeStr = dateStr; mmEvent.X = double.Parse(jobj["lon"].ToString()); mmEvent.Y = double.Parse(jobj["lat"].ToString()); mmEvent.Z = double.Parse(jobj["depth"].ToString()); mmEvent.ML = double.Parse(jobj["ml"].ToString()); mmEvent.RMS = double.Parse(jobj["rms"].ToString()); mmEvent.SetEnergy(); mmEvent.DominantFreq = 15; mmEvent.Phases = new Dictionary(); List DominantFreqlist = new List(); JArray phaseArr = JArray.FromObject(jobj["phases"]); List DominantFreqList = new List(); for (int i = 0; i < phaseArr.Count; i++) { if (phaseArr[i]["first_motion_direct"] != null) { mmEvent.Phases.Add(phaseArr[i]["id"].ToString().Substring(3, 3), int.Parse(phaseArr[i]["first_motion_direct"].ToString())); } if (phaseArr[i]["fmd_semi_period"] != null) { DominantFreqlist.Add(double.Parse(phaseArr[i]["fmd_semi_period"].ToString())); } } if (DominantFreqlist.Count > 0) { if (DominantFreqlist.Count > 3) { double min = DominantFreqlist.Min(); double max = DominantFreqlist.Max(); DominantFreqlist.Remove(min); DominantFreqlist.Remove(max); mmEvent.DominantFreq = DominantFreqlist.Sum() / (double)DominantFreqlist.Count; } else { mmEvent.DominantFreq = 0; } } return mmEvent; } //return null; } public MmEvent Json2MmEventWithPara(string jsonFile) { using (StreamReader sr = System.IO.File.OpenText(jsonFile)) { MmEvent mmEvent = new MmEvent(); mmEvent.JsonFile = jsonFile; string filePath = System.IO.Path.GetDirectoryName(jsonFile); string fileName = System.IO.Path.GetFileNameWithoutExtension(jsonFile).TrimEnd('B').TrimEnd('A'); //fileName=fileName.TrimEnd('B'); //fileName.TrimEnd('A'); string ascName = filePath + "\\" + fileName + ".txt"; mmEvent.AsciiFile = ascName; JsonTextReader reader = new JsonTextReader(sr); JArray jArray = (JArray)JToken.ReadFrom(reader); //解析普通属性和数组混合的Json文件 //数组0是普通属性集合 JObject jobj = (JObject)jArray[0]; string dateStr = jobj["otime"].ToString(); //LocalSqLiteServerAccess localSqLiteServerAccess = new LocalSqLiteServerAccess(); //int selectResult = localSqLiteServerAccess.SelectWithTime(dateStr); int selectResult = 1; if (selectResult < 1) { return null; } else { mmEvent.Phases = new Dictionary(); List Semiperiodlist = new List(); JArray phaseArr = JArray.FromObject(jobj["phases"]); List DominantFreqList = new List(); for (int i = 0; i < phaseArr.Count; i++) { if (phaseArr[i]["first_motion_direct"] != null) { mmEvent.Phases.Add(phaseArr[i]["id"].ToString().Substring(3, 3), int.Parse(phaseArr[i]["first_motion_direct"].ToString())); } if (phaseArr[i]["fmd_semi_period"] != null) { Semiperiodlist.Add(double.Parse(phaseArr[i]["fmd_semi_period"].ToString())); } } if (Semiperiodlist.Count > 0) { if (Semiperiodlist.Count > 3) { double min = Semiperiodlist.Min(); double max = Semiperiodlist.Max(); Semiperiodlist.Remove(min); Semiperiodlist.Remove(max); mmEvent.DominantFreq = Semiperiodlist.Sum() / (double)Semiperiodlist.Count; } else { mmEvent.DominantFreq = 0; } } JArray ampsArr = JArray.FromObject(jobj["amps"]); List ampsArrList = new List(); for (int i = 0; i < ampsArr.Count; i++) { if (ampsArr[i]["amp"] != null) { ampsArrList.Add(float.Parse(ampsArr[i]["amp"].ToString())); } } MmEvent.SetAmp(ampsArrList); return mmEvent; } } } public FMMap CreateFM(MmEvent mmEvent, double BaseX, double BaseY) { FMMap fmMap = new FMMap(); fmMap.X = mmEvent.X - BaseX; fmMap.Y = mmEvent.Y - BaseY; fmMap.R = mmEvent.RMS; foreach (var item in mmEvent.Phases) { if (item.Value == -1) { fmMap.negStation.Add(item.Key); } else { fmMap.posStation.Add(item.Key); } } return fmMap; } public PolygonAnnotation CreateStationModel(StationModel sm) { PolygonAnnotation pa = new PolygonAnnotation(); OxyColor oxyColor = OxyColor.FromArgb(StationColor.A, StationColor.R, StationColor.G, StationColor.B); pa.Text = sm.Name; pa.TextPosition = new DataPoint(sm.E, sm.N); pa.TextHorizontalAlignment = OxyPlot.HorizontalAlignment.Center; pa.TextVerticalAlignment = OxyPlot.VerticalAlignment.Middle; pa.FontSize = StationSize * 1.5; pa.Font = "Arail"; pa.Fill = oxyColor; pa.StrokeThickness = 2; pa.Stroke = OxyColors.Black; pa.Points.Add(new DataPoint(sm.E - StationSize, sm.N - StationSize)); pa.Points.Add(new DataPoint(sm.E + StationSize, sm.N - StationSize)); pa.Points.Add(new DataPoint(sm.E + StationSize, sm.N + StationSize)); pa.Points.Add(new DataPoint(sm.E - StationSize, sm.N + StationSize)); return pa; } public void ComputeFM(MmEvent mmEvent) { //fmMap = CreateFM(mmEvent, GlobalConfig.ProjectConfig.WorkArea.EMin, GlobalConfig.ProjectConfig.WorkArea.NMin); //ComputationResult cr = pCore.ComputeResult(fmMap); //if (cr == null) // return; //mmEvent.FocalType = cr.FocalType; //mmEvent.Direction = cr.Direction; } //public ComputationResult MmEventCalFocalMechanism(MmEvent mmEvent) //{ // FMMap fmMap = new FMMap(); // fmMap.X = mmEvent.X; // fmMap.Y = mmEvent.Y; // fmMap.R = mmEvent.RMS; // foreach (var item in mmEvent.Phases) // { // if (item.Value == -1) // { // fmMap.negStation.Add(item.Key); // } // else // { // fmMap.posStation.Add(item.Key); // } // } // ComputationResult cr = pCore.ComputeResult(fmMap); // if (cr == null) // return null; // return cr; // //mmEvent.FocalType = cr.FocalType; // //mmEvent.Direction = cr.Direction; //} public void UpdateFocalMechanismWithSourceParaDirection(object o) { //if (ShowEvents != null) //{ // int cnt = 0; // foreach (var item in ShowEvents) // { // ComputationResult cr = MmEventCalFocalMechanism(item, GlobalConfig.ProjectConfig.WorkArea.EMin // , GlobalConfig.ProjectConfig.WorkArea.NMin); // if (cr != null) // { // item.FocalType = cr.FocalType; // item.Direction = cr.Direction; // //localSqLiteServerAccess.UpdataFocalMechanism(item); // Console.WriteLine($"{++cnt}/{ShowEvents.Count}"); // } // } // System.Windows.Forms.MessageBox.Show("完成!"); //} //else //{ // System.Windows.Forms.MessageBox.Show("没有数据!"); //} } } }