tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
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)));
        }
 
 
 
    }
 
 
 
}