private void Button_Click(object sender, RoutedEventArgs e) { //convert the current feature name of the button to string featureName = (sender as Button).Content.ToString(); //set the chosenFeature property of the vm to it. this.gVM.VM_ChosenFeature = featureName; //setting up its PlotModel this.gVM.VM_PlotModelFeatures.Series.Clear(); this.gVM.SetUpModel(this.gVM.VM_PlotModelFeatures); //setting up the lines this.gVM.LoadData(gVM.Data.FeatureChosenValues(), this.gVM.VM_PlotModelFeatures); //"refreshing" the graph. fPlot.InvalidatePlot(true); //again for Corrlation graph. this.gVM.Updatecorr(featureName); this.gVM.VM_PlotModelCor.Series.Clear(); this.gVM.SetUpModel(this.gVM.VM_PlotModelCor); this.gVM.LoadData(gVM.Data.FeatureChosenCorrValues(), this.gVM.VM_PlotModelCor); this.corrPlot.InvalidatePlot(true); //and for regLine graph this.gVM.VM_PlotModelReg.Series.Clear(); this.gVM.SetUpModel(this.gVM.VM_PlotModelReg); this.gVM.LoadRegData(gVM.Data.FeatureChosenValues(), gVM.Data.FeatureChosenCorrValues(), gVM.VM_PlotModelReg); this.rPlot.InvalidatePlot(true); }
private void MyWindow_Price_AxisChanged(object sender, AxisChangedEventArgs e) { //throw new NotImplementedException(); _SmaPlotView.Model.Axes[0].Maximum = _PricePlotView.Model.Axes[0].ActualMaximum; _SmaPlotView.Model.Axes[0].Minimum = _PricePlotView.Model.Axes[0].ActualMinimum; _SmaPlotView.InvalidatePlot(false); }
private void MyWindow_Sma_AxisChanged(object sender, AxisChangedEventArgs e) { _PricePlotView.Model.Axes[0].Maximum = _SmaPlotView.Model.Axes[0].ActualMaximum; _PricePlotView.Model.Axes[0].Minimum = _SmaPlotView.Model.Axes[0].ActualMinimum; _PricePlotView.InvalidatePlot(false); }
/***Methods***/ // the constructor of the Graph View Model - getting a client object and 3 plotviews for graphs public GraphViewModel(IClientModel c, ViewModelController vmc, OxyPlot.Wpf.PlotView Attpv, OxyPlot.Wpf.PlotView Corrpv, OxyPlot.Wpf.PlotView regLinepv) { //getting args from constructor clientModel = c; viewModelController = vmc; VM_pvAtt = Attpv; VM_pvCorr = Corrpv; VM_pvLR = regLinepv; //setting up timer timer = new Stopwatch(); lastUpdate = 0; timer.Start(); //parsing XML for buttons name clientModel.xmlParser(); //Plot models inti VM_AttPlotModel = new PlotModel(); VM_CorrPlotModel = new PlotModel(); VM_RegLinePlotModel = new PlotModel(); //init list for later floatAttList = new List <float>(); floatCorrList = new List <float>(); buttonsList = new List <Button>(); //onPropertyChanged methods clientModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { onPropertyChanged("VM_" + e.PropertyName); }; // responsible of updating the graphs clientModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "lineNumber" && VM_AttUserChoose != null && VM_corralative != null && VM_pvLR != null) { if (timer.ElapsedMilliseconds - lastUpdate > 500) { //setting up attPlotModel VM_AttPlotModel.Series.Clear(); SetUpModel(VM_AttPlotModel); LoadLineDataGraph(VM_currLine, VM_pvAtt, floatAttList, VM_AttPlotModel); VM_pvAtt.InvalidatePlot(true); //setting up corrPlotModel VM_CorrPlotModel.Series.Clear(); SetUpModel(VM_CorrPlotModel); LoadLineDataGraph(VM_currLine, VM_pvCorr, floatCorrList, VM_CorrPlotModel); VM_pvCorr.InvalidatePlot(true); //setting up regLinePlotModel or minCircle VM_RegLinePlotModel.Series.Clear(); VM_RegLinePlotModel.Annotations.Clear(); SetUpModel(VM_RegLinePlotModel); if (viewModelController.isRegLine) { LoadScatterGraphData(VM_currLine, VM_pvLR, floatAttList, floatCorrList, VM_RegLinePlotModel); } if (viewModelController.isCircel) { LoadCircleGraphData(VM_currLine, VM_pvLR, floatAttList, floatCorrList, VM_RegLinePlotModel); } VM_pvLR.InvalidatePlot(true); //updating lastUpdate timer lastUpdate = timer.ElapsedMilliseconds; } } }; viewModelController.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "VM_dllCounter" && viewModelController.VM_dllCounter > 0 && viewModelController.VM_AnomalyReport != null) { foreach (Button b in buttonsList) { foreach (KeyValuePair <string, List <int> > entry in viewModelController.VM_AnomalyReport) { if (entry.Key.Contains(b.Content.ToString())) { b.Background = Brushes.DarkRed; b.Foreground = Brushes.White; break; } else { b.Background = Brushes.LightGray; b.Foreground = Brushes.Black; } } } } ; }; }
public void Calculate() { if (!ready) { return; } pm.Axes[0].MinorStep = double.NaN; pm.Axes[0].MajorStep = double.NaN; CGear frtemp = frnow; CGear bktemp = bknow; CGear intemp = innow; CWheel whtemp = (CWheel)whnow.Clone(); whtemp.Lenth = Whlength; list.Items.Clear(); lineSeriesCurrent.Points.Clear(); double toothratemax = 0; double toothratemin = 0; int num = 1; NaNNumber.Clear(); for (int i = 0; i < frtemp.Speeds; i++) { for (int k = 0; k < intemp.Speeds; k++) { for (int j = 0; j < bktemp.Speeds; j++) { CResult resulttemp = new CResult(); resulttemp.No1 = num; num++; resulttemp.Gear1 = ""; resulttemp.GearT1 = ""; if (frtemp.Speeds != 1) { resulttemp.Gear1 += (i + 1).ToString(); resulttemp.GearT1 += frtemp.teeth[i].teeth.ToString() + "T"; } if (bktemp.Speeds != 1) { if (resulttemp.Gear1 != "") { resulttemp.Gear1 += "x"; resulttemp.GearT1 += "x"; } resulttemp.Gear1 += (j + 1).ToString(); resulttemp.GearT1 += bktemp.teeth[j].teeth.ToString() + "T"; } if (intemp.Speeds != 1) { if (resulttemp.Gear1 != "") { resulttemp.Gear1 += "x"; resulttemp.GearT1 += "x"; } resulttemp.Gear1 += (k + 1).ToString(); resulttemp.GearT1 += intemp.teeth[k].Teeth.ToString("0.00"); } double toothrateout = (double)frtemp.teeth[i].teeth / (double)bktemp.teeth[j].teeth; double toothrate = toothrateout * intemp.teeth[k].teeth; if (toothratemin == 0) { toothratemin = toothrate; } if (toothratemax == 0) { toothratemax = toothrate; } if (toothrate < toothratemin) { toothratemin = toothrate; } if (toothrate > toothratemax) { toothratemax = toothrate; } resulttemp.GearRatio1 = toothrate; resulttemp.SpeedRatio1 = toothrate * whtemp.Lenth / 3.1415926535 / 25.4; if (IsSpd) { if (IsMPH) { resulttemp.Speed1 = Cad * 1.609344 / 2.0 * 1000000.0 / 60.0 / whtemp.Lenth / toothrate; } else { resulttemp.Speed1 = Cad / 2.0 * 1000000.0 / 60.0 / whtemp.Lenth / toothrate; } } else { if (IsMPH) { resulttemp.Speed1 = toothrate * Cad * whtemp.Lenth * 60 / 1000000.0 * 0.6213712; } else { resulttemp.Speed1 = toothrate * Cad * whtemp.Lenth * 60 / 1000000.0; } } if (num >= 3) { resulttemp.Increment1 = toothrate / toothrateold - 1.0; } toothrateold = toothrate; resulttemp.Remark1 = ""; if (frtemp.Speeds != 1 && bktemp.Speeds != 1) { if (i == frtemp.Speeds - 1 && j == 0) { resulttemp.Remark1 += Properties.Resources.StringLFLB; } if (i == 0 && j == bktemp.Speeds - 1) { resulttemp.Remark1 += Properties.Resources.StringSFSB; } } if (intemp.Speeds != 1) { if (toothrateout < 1.5) { resulttemp.Remark1 += Properties.Resources.StringTorque; } } results.Add(resulttemp); list.Items.Add(resulttemp); double tempx = 0; double tempy = 0; switch (CurveX) { case 0: //不分支 tempx = num - 1; break; case 1: //按牙盘 tempx = bktemp.Speeds * k + j + 1; break; case 2: //按飞轮 tempx = i * frtemp.Speeds + k + 1; break; case 3: //按内变速 tempx = i * bktemp.Speeds + j + 1; break; } switch (CurveY) { case 1: //走距速比 tempy = toothrate * whtemp.Lenth / 1000.0; break; case 2: //GI速比 tempy = toothrate * whtemp.Lenth / 3.1415926535 / 25.4; break; case 3: //齿比 tempy = toothrate; break; case 4: //车速踏频 tempy = resulttemp.Speed1; break; } if (lineSeriesCurrent.Points.Count >= 2) { if (lineSeriesCurrent.Points[lineSeriesCurrent.Points.Count - 2].X != double.NaN) { if (tempx - lineSeriesCurrent.Points[lineSeriesCurrent.Points.Count - 2].X <= 0) { lineSeriesCurrent.Points.Add(new DataPoint(double.NaN, double.NaN)); NaNNumber.Add(num - 1); } } } lineSeriesCurrent.Points.Add(new DataPoint(tempx, tempy)); } } } switch (CurveX) { case 0: //不分支 pm.Axes[0].Title = Properties.Resources.StringGear + " No."; break; case 1: //按牙盘 pm.Axes[0].Title = Properties.Resources.StringGear + " No. (" + Properties.Resources.StringBranchfr + ")"; break; case 2: //按飞轮 pm.Axes[0].Title = Properties.Resources.StringGear + " No. (" + Properties.Resources.StringBranchbk + ")"; break; case 3: //按内变速 pm.Axes[0].Title = Properties.Resources.StringGear + " No. (" + Properties.Resources.StringBranchin + ")"; break; } switch (CurveY) { case 1: //走距速比 pm.Axes[1].Title = Properties.Resources.StringSpdRatio; break; case 2: //GI速比 pm.Axes[1].Title = Properties.Resources.StringGI; break; case 3: //齿比 pm.Axes[1].Title = Properties.Resources.StringGearRatio; break; case 4: //车速踏频 pm.Axes[1].Title = (IsSpd ? Properties.Resources.StringCAD + "(rpm)" : (Properties.Resources.StringSpeed + (IsMPH ? "(mph)" : "(km/h)"))); break; } label0.Content = Properties.Resources.StringTotaldiff + ": " + (Convert.ToDouble(toothratemax / toothratemin * 100.0)).ToString("F0") + "%"; label1.Content = Properties.Resources.StringTotalCap + ": " + (frtemp.teeth[frtemp.Speeds - 1].teeth - frtemp.teeth[0].teeth - bktemp.teeth[bktemp.Speeds - 1].teeth + bktemp.teeth[0].teeth).ToString() + "T"; chart.ResetAllAxes(); chart.InvalidatePlot(true); pm.Axes[1].Minimum = 0; //if (pm.Axes[0].ActualMinorStep < 0.9 && pm.Axes[0].MinorStep == double.NaN) pm.Axes[0].MinorStep = 1; //if (pm.Axes[0].ActualMajorStep < 0.9 && pm.Axes[0].MajorStep == double.NaN) pm.Axes[0].MajorStep = 1; //Chart1.InvalidatePlot(true); }
public void Calculate() { if (!ready) { return; } pm.Series.Clear(); //pm.Axes[0].MinorStep = double.NaN; //pm.Axes[0].MajorStep = double.NaN; //CHub hubtemp = frnow; CHub hubtemp = hubnow; CRim rimtemp = rimnow; if (Spokes <= 3) { return; } ///////////////左侧/////////////////////// //花鼓孔 var hubhole = new ScatterSeries(); hubhole.MarkerType = MarkerType.Circle; hubhole.MarkerSize = 3; hubhole.Title = Properties.Resources.StringHubHoleL; for (int i = 0; i < Spokes / 2; i++) { double theta = 2.0 * Math.PI / (Spokes / 2.0) * i; double x = Math.Sin(theta) * hubtemp.LeftFlange / 2.0; double y = Math.Cos(theta) * hubtemp.LeftFlange / 2.0; ScatterPoint scatterPoint = new ScatterPoint(x, y); hubhole.Points.Add(scatterPoint); } //轮圈孔 var rimhole = new ScatterSeries(); rimhole.MarkerType = MarkerType.Circle; rimhole.MarkerSize = 3; for (int i = 0; i < Spokes / 2; i++) { double theta = 2.0 * Math.PI / (Spokes / 2.0) * i; double x = Math.Sin(theta) * rimtemp.ERD / 2.0; double y = Math.Cos(theta) * rimtemp.ERD / 2.0; ScatterPoint scatterPoint = new ScatterPoint(x, y); rimhole.Points.Add(scatterPoint); } //轮圈线 var rimline = new LineSeries(); rimline.StrokeThickness = 2; for (int i = 0; i < 101; i++) { double theta = 2.0 * Math.PI / 100.0 * i; double x = Math.Sin(theta) * rimtemp.ERD / 2.0; double y = Math.Cos(theta) * rimtemp.ERD / 2.0; rimline.Points.Add(new DataPoint(x, y)); } //花鼓线 var hubline = new LineSeries(); hubline.StrokeThickness = 2; for (int i = 0; i < 101; i++) { double theta = 2.0 * Math.PI / 100.0 * i; double x = Math.Sin(theta) * hubtemp.LeftFlange / 2.0 * 1.2; double y = Math.Cos(theta) * hubtemp.LeftFlange / 2.0 * 1.2; hubline.Points.Add(new DataPoint(x, y)); } hubline.Points.Add(new DataPoint(double.NaN, double.NaN)); for (int i = 0; i < 101; i++) { double theta = 2.0 * Math.PI / 100.0 * i; double x = Math.Sin(theta) * 7.0; double y = Math.Cos(theta) * 7.0; hubline.Points.Add(new DataPoint(x, y)); } //辐条 var spokesline = new LineSeries(); spokesline.Title = Properties.Resources.StringSpokeL; spokesline.StrokeThickness = 1; double spokeslenthraw = 0; for (int i = 0; i < Spokes / 2; i++) { DataPoint p1 = new DataPoint(hubhole.Points[i].X, hubhole.Points[i].Y); int j = 0; if (i % 2 == 0) { j = i + CrossesL; } else { j = i - CrossesL; } while (j < 0) { j += Spokes / 2; } j = j % (Spokes / 2); DataPoint p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); if (spokeslenthraw == 0) { spokeslenthraw = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); } spokesline.Points.Add(p1); spokesline.Points.Add(p2); spokesline.Points.Add(new DataPoint(double.NaN, double.NaN)); } /////////////////////右侧/////////////////////// //花鼓孔 var hubholer = new ScatterSeries(); hubholer.MarkerSize = 3; hubholer.Title = Properties.Resources.StringHubHoleR; hubholer.MarkerType = MarkerType.Circle; for (int i = 0; i < Spokes / 2; i++) { double theta = 2.0 * Math.PI / (Spokes / 2.0) * (i + 0.5); double x = Math.Sin(theta) * hubtemp.RightFlange / 2.0; double y = Math.Cos(theta) * hubtemp.RightFlange / 2.0; ScatterPoint scatterPoint = new ScatterPoint(x, y); hubholer.Points.Add(scatterPoint); } //轮圈孔 var rimholer = new ScatterSeries(); rimholer.MarkerSize = 3; rimholer.MarkerType = MarkerType.Circle; for (int i = 0; i < Spokes / 2; i++) { double theta = 2.0 * Math.PI / (Spokes / 2.0) * (i + 0.5); double x = Math.Sin(theta) * rimtemp.ERD / 2.0; double y = Math.Cos(theta) * rimtemp.ERD / 2.0; ScatterPoint scatterPoint = new ScatterPoint(x, y); rimholer.Points.Add(scatterPoint); } //辐条 var spokesliner = new LineSeries(); spokesliner.Title = Properties.Resources.StringSpokeR; spokesliner.StrokeThickness = 1; double spokeslenthrawr = 0; for (int i = 0; i < Spokes / 2; i++) { DataPoint p1 = new DataPoint(hubholer.Points[i].X, hubholer.Points[i].Y); int j = 0; if (i % 2 == 0) { j = i + CrossesR; } else { j = i - CrossesR; } while (j < 0) { j += Spokes / 2; } j = j % (Spokes / 2); DataPoint p2 = new DataPoint(rimholer.Points[j].X, rimholer.Points[j].Y); if (spokeslenthrawr == 0) { spokeslenthrawr = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); } spokesliner.Points.Add(p1); spokesliner.Points.Add(p2); spokesliner.Points.Add(new DataPoint(double.NaN, double.NaN)); } if (disrimline) { pm.Series.Add(rimline); } if (dishubline) { pm.Series.Add(hubline); } if (disrightside && dishubhole) { pm.Series.Add(hubholer); } if (disleftside && dishubhole) { pm.Series.Add(hubhole); } if (disrightside && disrimhole) { pm.Series.Add(rimholer); } if (disleftside && disrimhole) { pm.Series.Add(rimhole); } if (disrightside && disspokesline) { pm.Series.Add(spokesliner); } if (disleftside && disspokesline) { pm.Series.Add(spokesline); } chart.ResetAllAxes(); chart.InvalidatePlot(true); list.Items.Clear(); for (int i = 0; i < 6; i++) { DataPoint p1 = new DataPoint(hubhole.Points[0].X, hubhole.Points[0].Y); while (i < 0) { i += Spokes / 2; } int j = i % (Spokes / 2); DataPoint p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); spokeslenthraw = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); p1 = new DataPoint(hubhole.Points[0].X, hubhole.Points[0].Y); while (i < 0) { i += Spokes / 2; } j = i % (Spokes / 2); p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); spokeslenthrawr = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); CSpokeResult resulttemp = new CSpokeResult(); resulttemp.Crosses = i; double offsetl = hubtemp.CenterToLeft - rimtemp.OSB; double offsetr = hubtemp.CenterToRight + rimtemp.OSB; resulttemp.Lenthleft = Math.Sqrt(spokeslenthraw + offsetl * offsetl) - hubtemp.SpokeHole / 2.0; resulttemp.Lenthright = Math.Sqrt(spokeslenthrawr + offsetr * offsetr) - hubtemp.SpokeHole / 2.0;; double sinphyl = offsetl / Math.Sqrt(spokeslenthraw); double sinphyr = offsetr / Math.Sqrt(spokeslenthrawr); resulttemp.Tensionratio = sinphyr / sinphyl; resulttemp.Remark = ""; list.Items.Add(resulttemp); } if (CrossesL > 5) { int i = CrossesL; DataPoint p1 = new DataPoint(hubhole.Points[0].X, hubhole.Points[0].Y); while (i < 0) { i += Spokes / 2; } int j = i % (Spokes / 2); DataPoint p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); spokeslenthraw = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); p1 = new DataPoint(hubhole.Points[0].X, hubhole.Points[0].Y); while (i < 0) { i += Spokes / 2; } j = i % (Spokes / 2); p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); spokeslenthrawr = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); CSpokeResult resulttemp = new CSpokeResult(); resulttemp.Crosses = i; double offsetl = hubtemp.CenterToLeft - rimtemp.OSB; double offsetr = hubtemp.CenterToRight + rimtemp.OSB; resulttemp.Lenthleft = Math.Sqrt(spokeslenthraw + offsetl * offsetl) - hubtemp.SpokeHole / 2.0; resulttemp.Lenthright = Math.Sqrt(spokeslenthrawr + offsetr * offsetr) - hubtemp.SpokeHole / 2.0;; double sinphyl = offsetl / Math.Sqrt(spokeslenthraw); double sinphyr = offsetr / Math.Sqrt(spokeslenthrawr); resulttemp.Tensionratio = sinphyr / sinphyl; resulttemp.Remark = ""; list.Items.Add(resulttemp); } if (CrossesR > 5 && CrossesR != CrossesL) { int i = CrossesR; DataPoint p1 = new DataPoint(hubhole.Points[0].X, hubhole.Points[0].Y); while (i < 0) { i += Spokes / 2; } int j = i % (Spokes / 2); DataPoint p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); spokeslenthraw = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); p1 = new DataPoint(hubhole.Points[0].X, hubhole.Points[0].Y); while (i < 0) { i += Spokes / 2; } j = i % (Spokes / 2); p2 = new DataPoint(rimhole.Points[j].X, rimhole.Points[j].Y); spokeslenthrawr = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y); CSpokeResult resulttemp = new CSpokeResult(); resulttemp.Crosses = i; double offsetl = hubtemp.CenterToLeft - rimtemp.OSB; double offsetr = hubtemp.CenterToRight + rimtemp.OSB; resulttemp.Lenthleft = Math.Sqrt(spokeslenthraw + offsetl * offsetl) - hubtemp.SpokeHole / 2.0; resulttemp.Lenthright = Math.Sqrt(spokeslenthrawr + offsetr * offsetr) - hubtemp.SpokeHole / 2.0;; double sinphyl = offsetl / Math.Sqrt(spokeslenthraw); double sinphyr = offsetr / Math.Sqrt(spokeslenthrawr); resulttemp.Tensionratio = sinphyr / sinphyl; resulttemp.Remark = ""; list.Items.Add(resulttemp); } }