-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
FormPropSelection.vb
154 lines (121 loc) · 6.29 KB
/
FormPropSelection.vb
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
Imports System.Linq
Public Class FormPropSelection
Inherits System.Windows.Forms.Form
Public formC As FormFlowsheet
Public ssheet As unvell.ReoGrid.ReoGridControl
Public ssmode As Boolean = True
Public wi As Extras.WatchItem
Public mode As Integer
Private Sub UICVSelectorForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ExtensionMethods.ChangeDefaultFont(Me)
formC = My.Application.ActiveSimulation
lvObject.Sorting = SortOrder.Ascending
lvType.Items.Add("All Added Objects")
lvType.Items.AddRange(FormMain.ObjectList.Keys.OrderBy(Function(x) x).Select(Function(x) New ListViewItem(x)).ToArray())
lvUnits.Enabled = ssmode
If ssmode Then btnOK.Enabled = False
End Sub
Private Sub KryptonButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim separator = ";"
If lvObject.SelectedItems.Count = 0 Then
MessageBox.Show("Please select an object.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If lvProp.SelectedItems.Count = 0 Then
MessageBox.Show("Please select a property.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If ssmode Then
Dim scell = ssheet.CurrentWorksheet.GetCell(ssheet.CurrentWorksheet.SelectionRange.StartPos)
If scell Is Nothing Then scell = ssheet.CurrentWorksheet.CreateAndGetCell(ssheet.CurrentWorksheet.SelectionRange.StartPos)
Dim units As String = ""
If lvUnits.SelectedItems.Count > 0 Then
units = lvUnits.SelectedItems(0).Text
End If
If mode = 0 Then
scell.Formula = String.Format("GETPROPVAL({3}{1}{3}{0}{3}{2}{3}{0}{3}{4}{3})",
separator,
lvObject.SelectedItems(0).Tag,
lvProp.SelectedItems(0).Tag,
Chr(34),
units)
Else
scell.Formula = String.Format("SETPROPVAL({3}{1}{3}{0}{3}{2}{3}{0}{3}{4}{3}{0}{3}{5}{3})",
separator,
lvObject.SelectedItems(0).Tag,
lvProp.SelectedItems(0).Tag,
Chr(34),
If(scell.Formula = "", scell.Data, scell.Formula),
units)
End If
Else
Dim obj As SharedClasses.UnitOperations.BaseClass = formC.GetFlowsheetSimulationObject(lvObject.SelectedItems(0).Text)
If obj.GetProperties(Interfaces.Enums.PropertyType.RO).Contains(lvProp.SelectedItems(0).Tag) Then
Me.wi = New Extras.WatchItem(lvObject.SelectedItems(0).Tag, lvProp.SelectedItems(0).Tag, True)
Else
Me.wi = New Extras.WatchItem(lvObject.SelectedItems(0).Tag, lvProp.SelectedItems(0).Tag, False)
End If
End If
Me.Close()
End Sub
Private Sub lvType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvType.SelectedIndexChanged
If lvType.SelectedItems.Count > 0 Then
If lvType.SelectedItems(0).Text = "All Added Objects" Then
lvObject.Items.Clear()
For Each obj In formC.SimulationObjects.Values.OrderBy(Function(o) o.GraphicObject.Tag)
lvObject.Items.Add(New ListViewItem(obj.GraphicObject.Tag) With {.Tag = obj.Name})
Next
Else
Dim obj = FormMain.ObjectList(lvType.SelectedItems(0).Text)
Dim objs = formC.SimulationObjects.Values.Where(Function(x) x.GetType().Equals(obj.GetType())).ToList()
lvObject.Items.Clear()
For Each obj In objs
lvObject.Items.Add(New ListViewItem(obj.GraphicObject.Tag) With {.Tag = obj.Name})
Next
End If
End If
End Sub
Private Sub lvObject_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvObject.SelectedIndexChanged
If lvObject.SelectedItems.Count > 0 Then
lvProp.Items.Clear()
With lvProp.Items
Dim key As String = lvObject.SelectedItems(0).Tag
Dim properties As String()
If mode = 0 Then
properties = formC.Collections.FlowsheetObjectCollection(key).GetProperties(Interfaces.Enums.PropertyType.ALL)
Else
properties = formC.Collections.FlowsheetObjectCollection(key).GetProperties(Interfaces.Enums.PropertyType.WR)
End If
For Each prop As String In properties
.Add(DWSIM.App.GetPropertyName(prop)).Tag = prop
Next
End With
End If
End Sub
Private Sub lvProp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvProp.SelectedIndexChanged
If lvProp.SelectedItems.Count > 0 Then
lvUnits.Items.Clear()
Dim key As String = lvProp.SelectedItems(0).Tag
Dim obj = formC.GetFlowsheetSimulationObject(lvObject.SelectedItems(0).Text)
Dim unit = obj.GetPropertyUnit(key)
Dim su = formC.FlowsheetOptions.SelectedUnitSystem
Dim units = su.GetUnitSet(su.GetUnitType(unit))
For Each item In units
lvUnits.Items.Add(item)
Next
If ssmode Then
If lvProp.SelectedItems.Count > 0 Then btnOK.Enabled = True
End If
End If
End Sub
Private Sub FormPropSelection_Shown(sender As Object, e As EventArgs) Handles Me.Shown
ColumnHeader1.Width = lvType.Width - 5
ColumnHeader2.Width = lvObject.Width - 5
ColumnHeader3.Width = lvProp.Width - 5
ColumnHeader4.Width = lvUnits.Width - 5
FormMain.TranslateFormFunction?.Invoke(Me)
End Sub
End Class