using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing.Drawing2D; using System.Drawing; using Eventech.Utils.Images; namespace TProduct.PumpGraph.Picture { public partial class LxpMultiSpeedChart { #region 性能曲线 protected List _curveParas = null; public List AllCurveParas { get { return _curveParas; } set { _curveParas = value; } } //两种曲线赋值形式,只要其中一个赋值即可 protected List _allCurveGroup = null; public List AllCurveGroup { get { return _allCurveGroup; } set { _allCurveGroup = value; } } //两种曲线赋值形式,只要其中一个赋值即可 public List AllCurveNPSH { get; set; } public List AllCurveQE { get; set; } public List AllCurveQH { get; set; } public List AllCurveQP { get; set; } protected Eventech.Model.LxpSpectrumParas _spectrumParas = null;//变速的话,切割型谱范围有变化 public Eventech.Model.LxpSpectrumParas SpectrumParas { get { return _spectrumParas; } set { _spectrumParas = value; } } #endregion protected int _curve_note_rect_width = 68; protected int _curve_note_rect_height = 26; // protected void DrawCurve() { if (_allCurveGroup != null) { foreach (var curveGrp in _allCurveGroup) { var curveQH = Eventech.Common.CurveExpressConver.ToPoints(curveGrp.CurveExpressQH, 12); var pict_points = DrawSingleCurveQH(curveQH, _curveColorQH, _curveWidthQH, DashStyle.Solid, curveGrp.Name); if (_isDispCurveQE) { var curveQE = Eventech.Common.CurveExpressConver.ToPoints(curveGrp.CurveExpressQE, 12); DrawSingleCurveQE(curveQE, _curveColorQE, _curveWidthQE, DashStyle.Solid, curveGrp.Name); } if (_isDispCurveQP) { var curveQP = Eventech.Common.CurveExpressConver.ToPoints(curveGrp.CurveExpressQP, 12); DrawSingleCurveQP(curveQP, _curveColorQP, _curveWidthQP, DashStyle.Solid, curveGrp.Name); } if (curveGrp.CurveExpressNPSH != null) { var curveQNPSH = Eventech.Common.FitCurveHelper.GetFitPoints4Npsh(curveGrp.CurveExpressNPSH, 7); DrawSingleCurveQNPSH(curveQNPSH, _curveColorNPSH, _curveWidthQNPSH, DashStyle.Solid, curveGrp.Name); } } } if (this.AllCurveQH != null) { foreach (var curveGrp in AllCurveQH) { if (!curveGrp.IsDispCurve) { continue; } var points = Eventech.Common.CurveExpressConver.ToPoints(curveGrp.CurveExpress, 12); var pict_points = DrawSingleCurveQH(points, _curveColorQH, _curveWidthQH, DashStyle.Solid, curveGrp.IsDispName ? curveGrp.CurveName : null); if (curveGrp.IsDispPara && !string.IsNullOrEmpty(curveGrp.CurvePara) && pict_points != null) { var pt_text = pict_points.Last(); pt_text.X = pt_text.X + 8; if (pt_text.X > 1100) pt_text.X = 1100; Rectangle rect = new Rectangle(new Point((int)pt_text.X - 2, (int)pt_text.Y - _curve_note_rect_height / 2), new Size(_curve_note_rect_width, _curve_note_rect_height)); using (var brush = new System.Drawing.SolidBrush( Color.FromArgb(50,Color.White))) { _graphics.FillRectangle(brush, rect); } using (Pen pen = new Pen(Color.Black, 2f)) { _graphics.DrawRectangle(pen, rect); } StringFormat sf_label = new StringFormat(); sf_label.Alignment = StringAlignment.Near; sf_label.LineAlignment = StringAlignment.Center; using (var font = new System.Drawing.Font("Arial", _axisLabelSizeY, System.Drawing.FontStyle.Regular)) using (var brush = new System.Drawing.SolidBrush(_curveColorQH)) { pt_text.X = pt_text.X + 5; _graphics.DrawString(curveGrp.CurvePara, font, brush, pt_text, sf_label); } } } } if (this.AllCurveQE != null && this.IsDispCurveQE) { foreach (var curveGrp in AllCurveQE) { if (!curveGrp.IsDispCurve) { continue; } var points = Eventech.Common.CurveExpressConver.ToPoints(curveGrp.CurveExpress, 12); var pict_points = DrawSingleCurveQE(points, _curveColorQE, _curveWidthQE, DashStyle.Solid, curveGrp.IsDispName ? curveGrp.CurveName : null); if (curveGrp.IsDispPara && !string.IsNullOrEmpty(curveGrp.CurvePara) && pict_points != null) { var pt_text = pict_points.Last(); pt_text.Y = pt_text.Y + 10; if (pt_text.X > 1100) pt_text.X = 1100; Rectangle rect = new Rectangle(new Point((int)pt_text.X - _curve_note_rect_width / 2 - 2, (int)pt_text.Y), new Size(_curve_note_rect_width, _curve_note_rect_height)); using (var brush = new System.Drawing.SolidBrush(Color.FromArgb(50, Color.White))) { _graphics.FillRectangle(brush, rect); } using (Pen pen = new Pen(Color.Black, 2f)) { _graphics.DrawRectangle(pen, rect); } StringFormat sf_label = new StringFormat(); sf_label.Alignment = StringAlignment.Center; sf_label.LineAlignment = StringAlignment.Near; using (var font = new System.Drawing.Font("Arial", _axisLabelSizeY, System.Drawing.FontStyle.Regular)) using (var brush = new System.Drawing.SolidBrush(_curveColorQH)) { pt_text.Y = pt_text.Y + 3; _graphics.DrawString(curveGrp.CurvePara, font, brush, pt_text, sf_label); } } } } if (this.AllCurveQP != null && this.IsDispCurveQP) { foreach (var curveGrp in AllCurveQP) { if (!curveGrp.IsDispCurve) { continue; } var points = Eventech.Common.CurveExpressConver.ToPoints(curveGrp.CurveExpress, 12); var pict_points = DrawSingleCurveQP(points, _curveColorQE, _curveWidthQP, DashStyle.Solid, curveGrp.IsDispName ? curveGrp.CurveName : null); if (curveGrp.IsDispPara && !string.IsNullOrEmpty(curveGrp.CurvePara) && pict_points != null) { var pt_text = pict_points.Last(); pt_text.X = pt_text.X + 8; if (pt_text.X > 1100) pt_text.X = 1100; Rectangle rect = new Rectangle(new Point((int)pt_text.X - 3, (int)pt_text.Y - _curve_note_rect_height / 2), new Size(_curve_note_rect_width, _curve_note_rect_height)); using (var brush = new System.Drawing.SolidBrush(Color.FromArgb(50, Color.White))) { _graphics.FillRectangle(brush, rect); } using (Pen pen = new Pen(Color.Black, 2f)) { _graphics.DrawRectangle(pen, rect); } StringFormat sf_label = new StringFormat(); sf_label.Alignment = StringAlignment.Near; sf_label.LineAlignment = StringAlignment.Center; using (var font = new System.Drawing.Font("Arial", _axisLabelSizeY, System.Drawing.FontStyle.Regular)) using (var brush = new System.Drawing.SolidBrush(_curveColorQH)) { _graphics.DrawString(curveGrp.CurvePara, font, brush, pt_text, sf_label); } } } } if (this.AllCurveNPSH != null) { foreach (var curveGrp in AllCurveNPSH) { if (!curveGrp.IsDispCurve) { continue; } var points = Eventech.Common.FitCurveHelper.GetFitPoints4Npsh(curveGrp.CurveExpress, 10); DrawSingleCurveQNPSH(points, _curveColorQE, _curveWidthQNPSH, DashStyle.Solid, curveGrp.IsDispName ? curveGrp.CurveName : null); } } } // protected List DrawSingleCurveQH( List curvePoints, System.Drawing.Color curveColor, float curveWidth, DashStyle DashStyle, string curveName) { if (curvePoints == null || curvePoints.Count < 3) return null; List picture_points = new List(); for (int i = 0; i < curvePoints.Count; i++) { PointF image_pt = new PointF(); image_pt.X = MapRealToPictQ(curvePoints[i].X); image_pt.Y = MapRealToPictH(curvePoints[i].Y); picture_points.Add(image_pt); } //去掉重曲线复点 //Point[] pointArray = screenPoints.Distinct().ToArray(); using (Pen pen = new Pen(curveColor, curveWidth)) { pen.DashStyle = DashStyle; //penMajorTick.DashPattern = new float[] { 3f, 3f }; _graphics.DrawCurve(pen, picture_points.ToArray()); } if (!string.IsNullOrEmpty(curveName)) { using (var font = new System.Drawing.Font("Arial", this._curveNameTextHeight, System.Drawing.FontStyle.Regular)) { PointF text_pt = new PointF(); text_pt.X = picture_points.Last().X + 5; text_pt.Y = picture_points.Last().Y + 5; _graphics.DrawString(curveName, text_pt, font, Color.Black, StringAlignment.Near, StringAlignment.Near, 0); } } return picture_points; } // protected List DrawSingleCurveQE(List curvePoints, System.Drawing.Color curveColor, float curveWidth, DashStyle DashStyle, string curveName) { if (curvePoints == null || curvePoints.Count < 3) return null; List picture_points = new List(); for (int i = 0; i < curvePoints.Count; i++) { PointF image_pt = new PointF(); image_pt.X = MapRealToPictQ(curvePoints[i].X); image_pt.Y = MapRealToPictE(curvePoints[i].Y); picture_points.Add(image_pt); } //去掉重曲线复点 //Point[] pointArray = screenPoints.Distinct().ToArray(); using (Pen pen = new Pen(curveColor, curveWidth)) { pen.DashStyle = DashStyle; _graphics.DrawCurve(pen, picture_points.ToArray()); } if (!string.IsNullOrEmpty(curveName)) { using (var font = new System.Drawing.Font("Arial", this._curveNameTextHeight, System.Drawing.FontStyle.Regular)) { PointF text_pt = new PointF(); text_pt.X = picture_points.Last().X + 5; text_pt.Y = picture_points.Last().Y + 5; _graphics.DrawString(curveName, text_pt, font, Color.Black, StringAlignment.Near, StringAlignment.Near, 0); } } return picture_points; } // protected List DrawSingleCurveQP(List curvePoints, System.Drawing.Color curveColor, float curveWidth, DashStyle DashStyle, string curveName) { if (curvePoints == null || curvePoints.Count < 3) return null; List picture_points = new List(); for (int i = 0; i < curvePoints.Count; i++) { PointF image_pt = new PointF(); image_pt.X = MapRealToPictQ(curvePoints[i].X); image_pt.Y = MapRealToPictP(curvePoints[i].Y); picture_points.Add(image_pt); } //去掉重曲线复点 //Point[] pointArray = screenPoints.Distinct().ToArray(); using (Pen pen = new Pen(curveColor, curveWidth)) { pen.DashStyle = DashStyle; _graphics.DrawCurve(pen, picture_points.ToArray()); } if (!string.IsNullOrEmpty(curveName)) { using (var font = new System.Drawing.Font("Arial", this._curveNameTextHeight, System.Drawing.FontStyle.Regular)) { PointF text_pt = new PointF(); text_pt.X = picture_points.Last().X + 5; text_pt.Y = picture_points.Last().Y + 5; _graphics.DrawString(curveName, text_pt, font, Color.Black, StringAlignment.Near, StringAlignment.Near, 0); } } return picture_points; } // protected void DrawSingleCurveQNPSH(List curvePoints, System.Drawing.Color curveColor, float curveWidth, DashStyle DashStyle , string curveName) { if (curvePoints == null || curvePoints.Count < 3) return; List picture_points = new List(); for (int i = 0; i < curvePoints.Count; i++) { PointF image_pt = new PointF(); image_pt.X = MapRealToPictQ(curvePoints[i].X); image_pt.Y = MapRealToPictNPSH(curvePoints[i].Y); picture_points.Add(image_pt); } //去掉重曲线复点 //Point[] pointArray = screenPoints.Distinct().ToArray(); using (Pen pen = new Pen(curveColor, curveWidth)) { pen.DashStyle = DashStyle; _graphics.DrawCurve(pen, picture_points.ToArray()); } if (NPSHr_s > 0.001) { List picture_points2 = new List(); var map_space = MapRealToPictNPSH_Space(NPSHr_s); for (int i = 0; i < picture_points.Count;i++ ) { var pt = picture_points[i]; pt.Y = pt.Y - map_space;//注意是减掉 向上 picture_points2.Add(pt); } using (Pen pen = new Pen(curveColor, curveWidth)) { pen.DashStyle = DashStyle; _graphics.DrawCurve(pen, picture_points2.ToArray()); } } if (!string.IsNullOrEmpty(curveName)) { using (var font = new System.Drawing.Font("Arial", this._curveNameTextHeight, System.Drawing.FontStyle.Regular)) { PointF text_pt = new PointF(); text_pt.X = picture_points.Last().X + 5; text_pt.Y = picture_points.Last().Y + 5; _graphics.DrawString(curveName, text_pt, font, Color.Black, StringAlignment.Near, StringAlignment.Near, 0); } } } //设计点 //length_width_ratio 表示宽度的百分率(三角有效) protected void DrawDesignPoint(Eventech.Model.FeatPoint designPoint,float length_width_ratio = 5.2f) { if (!_isDispDesignPoint) return; if (designPoint == null || designPoint.X <0.1) return; if (_designPointDispType == Eventech.Model.eDesignPointDispType.Cross) { var crossPoint = new Eventech.Model.CrossPoint(designPoint, _toleranceGrade); using (Pen pen = new Pen(_designPointLineColor, _designPointLineWidth)) { _graphics.DrawLine(pen, new PointF(MapRealToPictQ(crossPoint.MinX), MapRealToPictH(designPoint.Y)), new PointF(MapRealToPictQ(crossPoint.MaxX), MapRealToPictH(designPoint.Y))); _graphics.DrawLine(pen, new PointF(MapRealToPictQ(designPoint.X), MapRealToPictH(crossPoint.MinY)), new PointF(MapRealToPictQ(designPoint.X), MapRealToPictH(crossPoint.MaxY))); } } else { using (Pen pen = new Pen(_designPointLineColor, _designPointLineWidth)) { var center_pt = new PointF(MapRealToPictQ(designPoint.X), MapRealToPictH(designPoint.Y)); var h_length = this._chartDiagramQH.Width * length_width_ratio / 100; var v_length = h_length * 0.61f;//0.618黄金分割 _graphics.DrawLine(pen, center_pt, new PointF(center_pt.X, center_pt.Y + v_length)); _graphics.DrawLine(pen, center_pt, new PointF(center_pt.X - h_length, center_pt.Y)); _graphics.DrawLine(pen, new PointF(center_pt.X, center_pt.Y + v_length), new PointF(center_pt.X - h_length, center_pt.Y)); _graphics.DrawLine(pen, new PointF(center_pt.X, center_pt.Y + v_length * 0.33f), new PointF(center_pt.X - h_length * 0.33f, center_pt.Y)); _graphics.DrawLine(pen, new PointF(center_pt.X, center_pt.Y + v_length * 0.66f), new PointF(center_pt.X - h_length * 0.66f, center_pt.Y)); } } } #region 等效线 //绘制等效线 public void DrawEqualParaCurveE() { if (_equalParaCurveE == null || _equalParaCurveE.Count() == 0) return; if (!_isDispEqualParaCurveE) return; using (SolidBrush brushText = new SolidBrush(EqualParaCurveColor)) using (Pen penCurve = new Pen(EqualParaCurveColor, _equalParaCurveWidth)) { foreach (var equalCurve in _equalParaCurveE) { List imgPoints = new List(); for (int i = 0; i < equalCurve.PointInfo.Count; i++) { PointF imgPoint = new PointF(); imgPoint.X = MapRealToPictQ(equalCurve.PointInfo[i].X); imgPoint.Y = MapRealToPictH(equalCurve.PointInfo[i].Y); imgPoints.Add(imgPoint); } //去掉重曲线复点 //Point[] pointArray = screenPoints.Distinct().ToArray(); // 绘制 if (imgPoints.Count() > 2) { if (equalCurve.IsClosed) {//封闭 //penCurve.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; System.Drawing.Drawing2D.FillMode aFillMode = System.Drawing.Drawing2D.FillMode.Alternate; _graphics.DrawClosedCurve(penCurve, imgPoints.ToArray(), equalCurve.DispTension, aFillMode); } else {//开放曲线 _graphics.DrawCurve(penCurve, imgPoints.ToArray(), equalCurve.DispTension); } } else if (imgPoints.Count() == 2) {//直线 _graphics.DrawLine(penCurve, imgPoints[0], imgPoints[1]); } else if (imgPoints.Count() == 1) {//点 RectangleF rc = new RectangleF(imgPoints[0].X - 2, imgPoints[0].Y - 2, 4, 4); using (Brush b = new SolidBrush(EqualParaCurveColor)) _graphics.FillEllipse(b, rc); } //if (_annoAnchorPointList == null) //{//自己定义位置 // //using (SolidBrush brushText = new SolidBrush(colorText)) // //{ // // foreach (var equalCurve in allEqualParaCurveE) // // { // // //位置影射 // // //ControlCoordinates coor = mainDiagram.DiagramToPoint(equalCurve.PointInfo[0].X, // // // equalCurve.PointInfo[0].Y); // // if (equalCurve.PointInfo[0].Y > equalCurve.PointInfo[equalCurve.PointInfo.Count - 1].Y) // // { // // text_pt.X = MapRealToPictQ(equalCurve.PointInfo[0].X); // // text_pt.Y = MapRealToPictH(equalCurve.PointInfo[0].Y); // // } // // else // // { // // text_pt.X = MapRealToPictQ(equalCurve.PointInfo[equalCurve.PointInfo.Count - 1].X); // // text_pt.Y = MapRealToPictH(equalCurve.PointInfo[equalCurve.PointInfo.Count - 1].Y); // // } // // //绘制文字 // // _graphics.DrawString(equalCurve.CurvePara.ToString(), fontText, brushText, // // text_pt.X, text_pt.Y - 15); // // } // //} //} } } } #endregion //显示效率值等 public void DrawAnnotText() { if (_annoAnchorPointList == null || _annoAnchorPointList.Count() == 0) return; //是否显示 if (!_isDispEqualParaTextE) return; // using (var font = new System.Drawing.Font("Arial", _equalCurveParaLabelHeight, System.Drawing.FontStyle.Regular)) { for (int k = 0; k < _annoAnchorPointList.Count; k++) { var annoAncor = _annoAnchorPointList[k]; string textContent = annoAncor.Text; if (string.IsNullOrEmpty(textContent)) continue; PointF text_pt = new PointF(); text_pt.X = MapRealToPictQ(annoAncor.X); text_pt.Y = MapRealToPictH(annoAncor.Y); var colorText = EqualParaCurveColor; if (annoAncor.CurveTag == "QH") { colorText = _curveColorQH; } //右 if (annoAncor.TextAligment == (int)Eventech.Model.eTextAligment.Right) { //text_pt.X = text_pt.X - _equalCurveParaLabelHeight; _graphics.DrawString(textContent, text_pt, font, colorText, StringAlignment.Near, StringAlignment.Center, 0); } //下 if (annoAncor.TextAligment == (int)Eventech.Model.eTextAligment.Bottom) { //text_pt.Y = text_pt.Y - _equalCurveParaLabelHeight; _graphics.DrawString(textContent, text_pt, font, colorText, StringAlignment.Center, StringAlignment.Near, 0); } //左 if (annoAncor.TextAligment == (int)Eventech.Model.eTextAligment.Left) { _graphics.DrawString(textContent, text_pt, font, colorText, StringAlignment.Far, StringAlignment.Center, 0); } //上 if (annoAncor.TextAligment == (int)Eventech.Model.eTextAligment.Top) { _graphics.DrawString(textContent, text_pt, font, colorText, StringAlignment.Center, StringAlignment.Far, 0); } } } } #region 型谱 //背景填充 protected void DrawLxpSpectrum1() { if (_spectrumShape == null) return; if (!isDispSpectrum) return; //图形路径 GraphicsPath shapePath = new GraphicsPath(); //如果点过密,投影到屏幕上,由于是整数可能会位置一样,取Distinct List boundaryPoint = new List(); boundaryPoint.Clear(); var BasePoints = _spectrumShape.BasePoints; for (int i = 0; i < BasePoints.Count; i++) { boundaryPoint.Add(new PointF(MapRealToPictQ(BasePoints[i].X), MapRealToPictH(BasePoints[i].Y))); } PointF[] ptList = boundaryPoint.Distinct().ToArray(); if (ptList.Length < 3) return; shapePath.AddCurve(ptList); boundaryPoint.Clear(); var RightParabolaPoints = _spectrumShape.RightParabolaPoints; for (int i = RightParabolaPoints.Count() - 1; i > -1; i--) { boundaryPoint.Add(new PointF(MapRealToPictQ(RightParabolaPoints[i].X), MapRealToPictH(RightParabolaPoints[i].Y))); } ptList = boundaryPoint.Distinct().ToArray(); if (ptList.Length < 3) return; shapePath.AddCurve(ptList); boundaryPoint.Clear(); var SimularPoints = _spectrumShape.SimularPoints; for (int i = SimularPoints.Count() - 1; i > -1; i--) { boundaryPoint.Add(new PointF(MapRealToPictQ(SimularPoints[i].X), MapRealToPictH(SimularPoints[i].Y))); } ptList = boundaryPoint.Distinct().ToArray(); if (ptList.Length < 3) return; shapePath.AddCurve(ptList); boundaryPoint.Clear(); var LeftParabolaPoints = _spectrumShape.LeftParabolaPoints; for (int i = 0; i < LeftParabolaPoints.Count; i++) { boundaryPoint.Add(new PointF(MapRealToPictQ(LeftParabolaPoints[i].X), MapRealToPictH(LeftParabolaPoints[i].Y))); } ptList = boundaryPoint.Distinct().ToArray(); if (ptList.Length < 3) return; shapePath.AddCurve(ptList); // using (SolidBrush brush = new SolidBrush(this._spectrumBackColor)) { System.Drawing.Region region = new Region(shapePath); _graphics.FillRegion(brush, region); } } #endregion } }