File size: 2,974 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
Imports System.Drawing
Imports System.Windows.Forms
Imports DWSIM.ExtensionMethods
Imports DWSIM.UnitOperations.SpecialOps

Public Class FormPIDCPEditor

    Public PID As PIDController

    Private Sub FormPIDCPEditor_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Text = PID.GraphicObject.Tag

        chkActive.Checked = PID.Active

        chkAuto.Checked = Not PID.ManualOverride

        tbSP.Text = PID.SPValue.ToString(PID.GetFlowsheet.FlowsheetOptions.NumberFormat)

        tbPV.Text = PID.PVValue.ToString(PID.GetFlowsheet.FlowsheetOptions.NumberFormat)

        tbMV.Text = PID.MVValue.ToString(PID.GetFlowsheet.FlowsheetOptions.NumberFormat)

        tbMV.ReadOnly = chkAuto.Checked

    End Sub

    Private Sub tbSP_KeyDown(sender As Object, e As KeyEventArgs) Handles tbSP.KeyDown

        If e.KeyCode = Keys.Enter Then
            Try
                PID.AdjustValue = tbSP.Text.ToDoubleFromCurrent
                PID.SPValue = PID.AdjustValue
                Close()
            Catch ex As Exception
                MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If

    End Sub

    Private Sub tbMV_KeyDown(sender As Object, e As KeyEventArgs) Handles tbMV.KeyDown

        If e.KeyCode = Keys.Enter And Not tbMV.ReadOnly Then
            Try
                PID.MVValue = tbMV.Text.ToDoubleFromCurrent
                Close()
            Catch ex As Exception
                MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If

    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles chkAuto.CheckedChanged

        If PID Is Nothing Then Exit Sub

        PID.ManualOverride = Not chkAuto.Checked

        tbMV.ReadOnly = chkAuto.Checked

        If chkAuto.Checked Then
            chkAuto.ForeColor = Color.White
            chkAuto.BackColor = Color.Green
            chkAuto.Text = "AUTO"
        Else
            chkAuto.ForeColor = Color.White
            chkAuto.BackColor = Color.Blue
            chkAuto.Text = "MANUAL"
        End If

    End Sub

    Private Sub chkActive_CheckedChanged(sender As Object, e As EventArgs) Handles chkActive.CheckedChanged

        If PID Is Nothing Then Exit Sub

        PID.Active = chkActive.Checked

        If chkActive.Checked Then

            chkActive.ForeColor = Color.White
            chkActive.BackColor = Color.Green
            chkActive.Text = "ON"
            chkAuto.Enabled = True
            tbMV.Enabled = True
            tbPV.Enabled = True
            tbSP.Enabled = True

        Else

            chkActive.ForeColor = Color.White
            chkActive.BackColor = Color.Red
            chkActive.Text = "OFF"
            chkAuto.Enabled = False
            tbMV.Enabled = False
            tbPV.Enabled = False
            tbSP.Enabled = False

        End If

    End Sub

End Class