yangyin
2024-12-16 b4c867bf85d3edef5d084a3a26f13cbc6784bf58
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
using DPumpHydr.WinFrmUI.RLT.Child.Crown;
using DPumpHydr.WinFrmUI.RLT.Docking.Crown;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System;
using System.ComponentModel;
 
namespace DPumpHydr.WinFrmUI.Volute 
{
    public partial class SectAreaDockPanel : CrownToolWindow
    {
 
        public SectAreaDockPanel()
        {
            InitializeComponent();
 
            this.DefaultDockArea = RLT.Enum.Crown.DockArea.Bottom;
            this.DockText = "截面面积";
            this.SerializationKey = "SectAreaDockPanel";
 
        }
        private ViewModel.SectionBundleInfo _bundle = null;
        private ViewModel.SectionShapePara _para = null;
        public Action<ViewModel.SectionBundleInfo , int> OnRefreshSingleSectBundle = null;
        public void RefreshControl()
        {
            _selectedPointIndex = -1;
            chart.RefreshControl();
        }
 
        public void SetBindingData(ViewModel.SectionBundleInfo bundle)
        {
            if (bundle == null) return;
            _bundle = bundle;
            List<double> Data = new List<double>();
            for (int i = 0; i < 9; i++) 
            { 
                Data.Add(bundle.Area[i]);
            }
            chart.SetBindingData(Data);
        }
        public void SetBindingData(ViewModel.SectionShapePara para)
        {
            if(para == null) return;
            _para = para;
            chart.SetBindingData(para);
        }
        public ViewModel.SectionBundleInfo GetBindingData(out string error)
        {
            error = "";
            if (_bundle == null) 
            {
                error = "_bundle为空"; 
                return null;
            }
            return _bundle;
        }
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
            {
                return false;
            }
            else
            {
                return base.ProcessDialogKey(keyData);
            }
        }
        private int _selectedPointIndex = -1;
        private void chart_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (_selectedPointIndex == -1)
            {
                return;
            }
            var data = chart.GetBindingData();
            if (data == null)
            {
                return;
            }
           //根据按键增加或减少Y值
            if (e.KeyCode == Keys.Up)
            {
                data[_selectedPointIndex] += data[_selectedPointIndex] * 0.01; // 增加Y值
                chart.SetBindingData(data);
                _bundle.Area[_selectedPointIndex] = data[_selectedPointIndex];
                OnRefreshSingleSectBundle.Invoke(_bundle, _selectedPointIndex);
            }
            else if (e.KeyCode == Keys.Down)
            {
                data[_selectedPointIndex] -= data[_selectedPointIndex] * 0.01; // 减少Y值
                chart.SetBindingData(data);
                _bundle.Area[_selectedPointIndex] = data[_selectedPointIndex];
                OnRefreshSingleSectBundle.Invoke(_bundle, _selectedPointIndex);
            }
        }
        //int _sequence = 0;
        private void chart_MouseClick(object sender, MouseEventArgs e)
        {
            int pointIndex = chart.Judgment_point(e.X, e.Y);
            if (pointIndex == -1)
            {
                return;
            }
            if (_para != null)
            {
                if(_para.Index != pointIndex)
                {
                    return;
                }
            }
            _selectedPointIndex = pointIndex;
        }
 
       
    }
}