using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
using WW.Cad.Base;
|
using WW.Cad.Drawing;
|
using WW.Cad.Drawing.GDI;
|
using WW.Cad.IO;
|
using WW.Cad.Model;
|
using WW.Math;
|
using WW.Cad.Model.Entities;
|
using WW.Actions;
|
using WW.Cad.Model.Tables;
|
using WW.Cad.Model.Objects;
|
using System.Drawing.Drawing2D;
|
using System.Drawing;
|
|
|
|
|
namespace TProduct.PumpGraph.Dxf
|
{
|
public partial class LxpSeriesChart
|
{
|
public LxpSeriesChart()
|
{
|
|
|
}
|
|
int _imageWidth = 1500;
|
int _imageHeight = 1000;
|
|
|
private Eventech.Model.LxpSpectrumShapeExList _simuSpectrumShapeList = null;
|
public Eventech.Model.LxpSpectrumShapeExList SimuSpectrumShapeList { get { return _simuSpectrumShapeList; } set { _simuSpectrumShapeList = value; } }
|
|
|
private List<Eventech.Model.FeatPointString> _curveNameLabelPosiList = null;
|
public List<Eventech.Model.FeatPointString> CurveNameLabelPosiList
|
{
|
get { return _curveNameLabelPosiList; }
|
set { _curveNameLabelPosiList = value; }
|
}
|
|
|
protected DxfModel _dxfFileModel = null;
|
|
public bool CreateDxf(string strFilePath)
|
{
|
if (_coordinateParas == null)
|
return false;
|
try
|
{
|
_dxfFileModel = new DxfModel(DxfVersion.Dxf21);
|
|
|
|
InitialDiagramSize(_imageWidth, _imageHeight);
|
|
|
|
|
////绘制X坐标
|
|
|
for (int i = 0; i < _coordinateParas.AxisLabelH.Count; i++)
|
{
|
double posi_H = MapRealToPictH(_coordinateParas.AxisLabelH[i]);
|
|
var horizLeftH_sub = new Point2D(_diagramLeftTopPt.X, posi_H);
|
var horizRightH_sub = new Point2D(_diagramRightTopPt.X, posi_H);
|
var horizLine_sub = new DxfLine(horizLeftH_sub, horizRightH_sub);
|
horizLine_sub.LineWeight = 1;
|
horizLine_sub.Color = EntityColors.DarkGray;
|
_dxfFileModel.Entities.Add(horizLine_sub);
|
|
var posi_label = new Point3D(_diagramLeftTopPt.X-10 , posi_H, 0d);
|
DxfMText axisLabel_q = new DxfMText(_coordinateParas.AxisLabelH[i].ToString(), posi_label, 8);//\P表示回车
|
axisLabel_q.AttachmentPoint = AttachmentPoint.MiddleRight;
|
_dxfFileModel.Entities.Add(axisLabel_q);
|
}
|
|
|
for (int i = 0; i < _coordinateParas.AxisLabelQ.Count; i++)
|
{
|
double posi_Q = MapRealToPictQ(_coordinateParas.AxisLabelQ[i]);
|
|
var horizLeftH_sub = new Point2D(posi_Q, _diagramLeftTopPt.Y);
|
var horizRightH_sub = new Point2D(posi_Q, _diagramLeftBottomPt.Y);
|
var horizLine_sub = new DxfLine(horizLeftH_sub, horizRightH_sub);
|
horizLine_sub.LineWeight = 1;
|
horizLine_sub.Color = EntityColors.DarkGray;
|
_dxfFileModel.Entities.Add(horizLine_sub);
|
|
|
var posi_label = new Point3D(posi_Q, _diagramLeftBottomPt.Y - 10, 0d);
|
DxfMText axisLabel_q = new DxfMText(_coordinateParas.AxisLabelQ[i].ToString(), posi_label, 8);//\P表示回车
|
axisLabel_q.AttachmentPoint = AttachmentPoint.TopCenter;
|
_dxfFileModel.Entities.Add(axisLabel_q);
|
|
}
|
|
if (_simuSpectrumShapeList != null)
|
{
|
foreach (var shape in _simuSpectrumShapeList)
|
{
|
DrawLxpSpectrum1_split(shape);
|
}
|
}
|
|
if (_curveNameLabelPosiList != null)
|
{
|
foreach (var label in _curveNameLabelPosiList)
|
{
|
var posi = new Point3D(MapRealToPictQ(label.X), MapRealToPictH(label.Y), 0d);
|
DxfMText axisLabel_q = new DxfMText(label.StringValue.Trim(), posi, 5);//\P表示回车
|
axisLabel_q.AttachmentPoint = AttachmentPoint.MiddleLeft;
|
axisLabel_q.Color = EntityColors.Yellow;
|
_dxfFileModel.Entities.Add(axisLabel_q);
|
}
|
}
|
|
|
|
if (System.IO.File.Exists(strFilePath))
|
{
|
System.IO.File.Delete(strFilePath);
|
}
|
|
DwgWriter.Write(strFilePath, _dxfFileModel);
|
|
}
|
catch //(Exception ex)
|
{
|
return false;
|
}
|
|
|
return true;
|
}
|
|
|
protected void DrawLxpSpectrum1_join(Eventech.Model.LxpSpectrumShape _spectrumShape)
|
{
|
if (_spectrumShape == null)
|
return;
|
|
#region Polyline
|
DxfHatch shapeHatch = new DxfHatch();
|
shapeHatch.Color = EntityColors.GreenYellow;
|
|
DxfHatch.BoundaryPath boundaryPath = new DxfHatch.BoundaryPath();
|
boundaryPath.Type = BoundaryPathType.Polyline;
|
boundaryPath.IsPolyline = true;
|
|
shapeHatch.BoundaryPaths.Add(boundaryPath);
|
List<Point2D> boundaryPoint = new List<Point2D>();
|
boundaryPoint.Clear();
|
var BasePoints = _spectrumShape.BasePoints;
|
for (int i = 0; i < BasePoints.Count - 1; i++)
|
{
|
Point2D pt = new Point2D();
|
pt.X = MapRealToPictQ(BasePoints[i].X);
|
pt.Y = MapRealToPictH(BasePoints[i].Y);
|
boundaryPoint.Add(pt);
|
}
|
var RightParabolaPoints = _spectrumShape.RightParabolaPoints;
|
for (int i = RightParabolaPoints.Count() - 1; i > -1; i--)
|
{
|
Point2D pt = new Point2D();
|
pt.X = MapRealToPictQ(RightParabolaPoints[i].X);
|
pt.Y = MapRealToPictH(RightParabolaPoints[i].Y);
|
boundaryPoint.Add(pt);
|
}
|
var SimularPoints = _spectrumShape.SimularPoints;
|
for (int i = SimularPoints.Count() - 1; i > -1; i--)
|
{
|
Point2D pt = new Point2D();
|
pt.X = MapRealToPictQ(SimularPoints[i].X);
|
pt.Y = MapRealToPictH(SimularPoints[i].Y);
|
boundaryPoint.Add(pt);
|
}
|
var LeftParabolaPoints = _spectrumShape.LeftParabolaPoints;
|
for (int i = 0; i < LeftParabolaPoints.Count; i++)
|
{
|
Point2D pt = new Point2D();
|
pt.X = MapRealToPictQ(LeftParabolaPoints[i].X);
|
pt.Y = MapRealToPictH(LeftParabolaPoints[i].Y);
|
boundaryPoint.Add(pt);
|
}
|
|
boundaryPath.PolylineData = new DxfHatch.BoundaryPath.Polyline(true, boundaryPoint);
|
boundaryPath.PolylineData.Closed = true;
|
shapeHatch.BoundaryPaths.Add(boundaryPath);
|
_dxfFileModel.Entities.Add(shapeHatch);
|
#endregion
|
|
}
|
|
protected void DrawLxpSpectrum1_split(Eventech.Model.LxpSpectrumShape _spectrumShape)
|
{
|
if (_spectrumShape == null)
|
return;
|
|
#region Polyline
|
|
var curveColor = EntityColors.GreenYellow;
|
|
DrawSingleCurveQH(curveColor, _spectrumShape.BasePoints);
|
|
DrawSingleCurveQH(curveColor, _spectrumShape.RightParabolaPoints);
|
|
DrawSingleCurveQH(curveColor, _spectrumShape.SimularPoints);
|
|
DrawSingleCurveQH(curveColor, _spectrumShape.LeftParabolaPoints);
|
|
|
#endregion
|
|
}
|
|
protected DxfSpline DrawSingleCurveQH(WW.Cad.Model.Entities.EntityColor colorCurve, List<Eventech.Model.FeatPoint> curvePoints)
|
{
|
if (curvePoints == null || curvePoints.Count() < 3)
|
return null;
|
|
DxfSpline dxfSpline = new DxfSpline();
|
dxfSpline.Degree = 3;
|
dxfSpline.LineWeight = 2;
|
dxfSpline.Color = colorCurve;
|
|
for (int i = 0; i < curvePoints.Count; i++)
|
{
|
|
Point3D pt3D = new Point3D();
|
pt3D.X = MapRealToPictQ(curvePoints[i].X);
|
pt3D.Y = MapRealToPictH(curvePoints[i].Y);
|
pt3D.Z = 0;
|
|
|
dxfSpline.FitPoints.Add(pt3D);
|
}
|
|
if (dxfSpline.FitPoints.Count < 3)
|
return null;
|
_dxfFileModel.Entities.Add(dxfSpline);
|
|
// DxfLineType dashedLineType = new DxfLineType("Dashed", 0.5d, -0.3d);
|
// DxfLineType dashedLineType = new DxfLineType("ByLayer", 1d, -0.3d);
|
// _dxfFileModel.LineTypes.Add(dashedLineType);
|
//_dxfFileModel.Colors.Add(colorCurve);
|
|
return dxfSpline;
|
}
|
|
|
|
#region 坐标
|
Eventech.Model.QhCoordinateParas _coordinateParas = null;
|
|
public Eventech.Model.QhCoordinateParas CoordinateParas
|
{
|
get { return _coordinateParas; }
|
set { _coordinateParas = value; }
|
}
|
|
#endregion
|
|
|
protected Point2D _diagramLeftBottomPt = new Point2D();
|
protected Point2D _diagramRightBottomPt = new Point2D();
|
protected Point2D _diagramLeftTopPt = new Point2D();
|
protected Point2D _diagramRightTopPt = new Point2D();
|
protected virtual void InitialDiagramSize(double diagramTotalLength, double diagramTotalHeight)
|
{
|
_diagramLeftBottomPt = new Point2D(0, 0);
|
|
_diagramRightBottomPt.X = _diagramLeftBottomPt.X + diagramTotalLength;
|
_diagramRightBottomPt.Y = _diagramLeftBottomPt.Y;
|
|
_diagramLeftTopPt.X = _diagramLeftBottomPt.X;
|
_diagramLeftTopPt.Y = _diagramLeftBottomPt.Y + diagramTotalHeight;
|
|
_diagramRightTopPt.X = _diagramRightBottomPt.X;
|
_diagramRightTopPt.Y = _diagramLeftTopPt.Y;
|
|
|
|
}
|
|
|
protected double MapRealToPictQ(double Q)
|
{
|
return _diagramLeftBottomPt.X + ((Math.Log10(Q) - Math.Log10(_coordinateParas.MinQ)) * (_diagramRightBottomPt.X - _diagramLeftBottomPt.X) / (Math.Log10(_coordinateParas.MaxQ) - Math.Log10(_coordinateParas.MinQ)));
|
}
|
|
|
//扬程曲线Y坐标实际尺寸换算为像素尺寸(复制,需要修改)
|
protected double MapRealToPictH(double H)
|
{
|
return _diagramRightBottomPt.Y + ((Math.Log10(H) - Math.Log10(_coordinateParas.MinH)) * (_diagramRightTopPt.Y - _diagramRightBottomPt.Y) / (Math.Log10(_coordinateParas.MaxH) - Math.Log10(_coordinateParas.MinH)));
|
}
|
|
|
|
}
|
|
|
|
}
|