duheng
2024-03-26 bb006801e4d7fc281e8c1b43ab4b7b83da044ab6
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
 
 
//编辑原始的性能曲线
namespace IStation.WinFrmUI.Curve
{
    public partial class ImportCurveByFeatCurveExpressGroupCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public ImportCurveByFeatCurveExpressGroupCtrl()
        {
            InitializeComponent();
 
            this.imgCmbCurveSourceFrom.Properties.AddEnum(typeof(Model.eCurveSourceFrom), false);
            this.imgCmbCurveSourceFrom.EditValue = Model.eCurveSourceFrom.现场测试;
 
            this.imgCmbQHFitType.Properties.AddEnum(typeof(Model.eCurveFitType), false);
            this.imgCmbQHFitType.EditValue = _qhFitType;
 
            this.imgCmbQEFitType.Properties.AddEnum(typeof(Model.eCurveFitType), false);
            this.imgCmbQEFitType.EditValue = _qeFitType;
 
            this.imgCmbQPFitType.Properties.AddEnum(typeof(Model.eCurveFitType), false);
            this.imgCmbQPFitType.EditValue = _qpFitType;
        }
 
 
        Model.eCurveFitType _qhFitType = Model.eCurveFitType.CubicCurve;
        Model.eCurveFitType _qeFitType = Model.eCurveFitType.CubicCurve;
        Model.eCurveFitType _qpFitType = Model.eCurveFitType.CubicCurve;
 
 
        private Model.CurveExpress QhCurve = null, QeCurve = null, QpCurve = null;
        List<Model.CurvePoint> QhPoints = null, QePoints = null, QpPoints = null;
 
        private bool initial = false;
 
 
        /// <summary>
        /// 初始化数据
        /// </summary> 
        public void SetBindingData()
        {
            this.chartFeatCurveViewCtrl1.Enabled = false;
        }
 
        //选择文件
        private void btnFilePath_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Filter = "EXCEL 文件(*.express)|*.express";
            dlg.CheckFileExists = true;
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            initial = false;
            this.btnFilePath.Text = dlg.FileName;
            var json = File.ReadAllText(dlg.FileName);
            var express = JsonHelper.Json2Object<Model.FeatCurveExpressGroup>(json);
            if (express == null || express.CurveQH == null)
            {
                this.QhCurve = null; this.QeCurve = null; this.QpCurve = null;
                this.QhPoints = null; this.QePoints = null; this.QpPoints = null;
                this.chartFeatCurveViewCtrl1.Enabled = false;
                this.chartFeatCurveViewCtrl1.ClearData();
                XtraMessageBox.Show("解析失败!");
            }
            else
            {
                this.QhPoints = null;
                this.QePoints = null;
                this.QpPoints = null;
 
                if (express.CurveQH.DefinePoints != null)
                    this.QhPoints = express.CurveQH.DefinePoints;
                else
                    this.QhPoints = express.CurveQH.GetFitPoints(12);
 
                if (express.CurveQE != null)
                {
                    if (express.CurveQE.DefinePoints != null)
                        this.QePoints = express.CurveQE.DefinePoints;
                    else
                        this.QePoints = express.CurveQE.GetFitPoints(12);
 
                }
 
                if (express.CurveQP != null)
                {
                    if (express.CurveQP.DefinePoints != null)
                        this.QpPoints = express.CurveQP.DefinePoints;
                    else
                        this.QpPoints = express.CurveQP.GetFitPoints(12);
                }
 
                this.txtCurveCode.Text = Path.GetFileNameWithoutExtension(dlg.FileName);
                this.imgCmbQHFitType.EditValue = express.CurveQH.FitType;
                this.imgCmbQEFitType.EditValue = express.CurveQE.FitType;
                this.imgCmbQPFitType.EditValue = express.CurveQP.FitType;
                initial = true;
                loadCurve();
            }
        }
 
 
        //加载曲线
        private bool loadCurve()
        {
            if (!initial)
                return false;
            if (QhPoints == null)
            {
                this.chartFeatCurveViewCtrl1.Enabled = false;
                this.chartFeatCurveViewCtrl1.ClearData();
                return false;
            }
 
            this.chartFeatCurveViewCtrl1.Enabled = true;
            _qhFitType = (Model.eCurveFitType)this.imgCmbQHFitType.EditValue;
            _qeFitType = (Model.eCurveFitType)this.imgCmbQEFitType.EditValue;
            _qpFitType = (Model.eCurveFitType)this.imgCmbQPFitType.EditValue;
 
 
 
            QhCurve = new Model.CurveExpress(QhPoints, _qhFitType);
            QeCurve = new Model.CurveExpress(QePoints, _qeFitType);
            QpCurve = new Model.CurveExpress(QpPoints, _qpFitType);
 
            this.chartFeatCurveViewCtrl1.SetCurveInfo(QhCurve, QeCurve, QpCurve);
            this.chartFeatCurveViewCtrl1.UpdateChart(true);
            this.chartFeatCurveViewCtrl1.SetWorkPointQ_Auto();
 
            return true;
        }
 
 
        public bool GetGroup(out string curveCode, out Model.eCurveSourceFrom eCurveSourceFrom,
            out Model.FeatCurvePointGroup featCurvePointGroup, out Model.FeatCurveExpressGroup featCurveExpressGroup)
        {
            curveCode = "";
            eCurveSourceFrom = Model.eCurveSourceFrom.现场测试;
            featCurvePointGroup = null;
            featCurveExpressGroup = null;
            if (!loadCurve())
                return false;
            curveCode = this.txtCurveCode.Text.Trim();
            if (string.IsNullOrEmpty(curveCode))
            {
                XtraMessageBox.Show("请输入曲线名称!");
                return false;
            }
            eCurveSourceFrom = (Model.eCurveSourceFrom)this.imgCmbCurveSourceFrom.EditValue;
            featCurvePointGroup = new Model.FeatCurvePointGroup(QhPoints, QePoints, QpPoints);
            featCurveExpressGroup = new Model.FeatCurveExpressGroup(QhCurve, QeCurve, QpCurve);
            return true;
        }
 
        private void imgCmbQHFitType_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadCurve();
        }
 
        private void imgCmbQEFitType_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadCurve();
        }
 
        private void imgCmbQPFitType_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadCurve();
        }
 
    }
}