-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
FlowsheetBase.vb
5247 lines (4095 loc) · 247 KB
/
FlowsheetBase.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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Globalization
Imports System.Reflection
Imports DWSIM.Interfaces
Imports DWSIM.Drawing.SkiaSharp
Imports DWSIM.SharedClasses
Imports DWSIM.Thermodynamics.BaseClasses
Imports DWSIM.FlowsheetSolver
Imports DWSIM.Interfaces.Enums.GraphicObjects
Imports DWSIM.Drawing.SkiaSharp.GraphicObjects.Shapes
Imports DWSIM.UnitOperations.SpecialOps
Imports DWSIM.UnitOperations.UnitOperations
Imports DWSIM.UnitOperations.Reactors
Imports DWSIM.Thermodynamics.PropertyPackages
Imports DWSIM.Drawing.SkiaSharp.GraphicObjects
Imports DWSIM.Thermodynamics
Imports DWSIM.UnitOperations.Streams
Imports DWSIM.Thermodynamics.Streams
Imports ICSharpCode.SharpZipLib.Zip
Imports System.IO
Imports DWSIM.Drawing.SkiaSharp.GraphicObjects.Tables
Imports Python.Runtime
Imports Microsoft.Scripting.Hosting
Imports System.Text
Imports DWSIM.SharedClasses.Flowsheet
Imports System.Dynamic
Imports DWSIM.Interfaces.Enums
Imports DWSIM.GlobalSettings
Imports DWSIM.Thermodynamics.AdvancedEOS
Imports SkiaSharp
Imports System.Text.RegularExpressions
Imports System.Xml
<System.Runtime.InteropServices.ComVisible(True)> Public MustInherit Class FlowsheetBase
Implements IFlowsheet, IFlowsheetCalculationQueue
Public Property WeatherProvider As IWeatherProvider = New SharedClasses.WeatherProvider() Implements IFlowsheet.WeatherProvider
Public Property DynamicMode As Boolean = False Implements IFlowsheet.DynamicMode
Public Property DynamicsManager As IDynamicsManager = New DynamicsManager.Manager Implements IFlowsheet.DynamicsManager
Public Property ExtraProperties As New ExpandoObject Implements IFlowsheet.ExtraProperties
Public WithEvents Options As New SharedClasses.DWSIM.Flowsheet.FlowsheetVariables
Public UndoStack As New Stack(Of Tuple(Of Enums.SnapshotType, XDocument))
Public RedoStack As New Stack(Of Tuple(Of Enums.SnapshotType, XDocument))
Public Property MessagesLog As New List(Of String) Implements IFlowsheet.MessagesLog
Private FlowsheetSurface As New GraphicsSurface
Public SensAnalysisCollection As New List(Of Optimization.SensitivityAnalysisCase)
Public OptimizationCollection As New List(Of Optimization.OptimizationCase)
Private Shared AvailablePropPacks As New Dictionary(Of String, IPropertyPackage)
Public Property AvailablePropertyPackages As Dictionary(Of String, IPropertyPackage) Implements IFlowsheet.AvailablePropertyPackages
Get
Return AvailablePropPacks
End Get
Set(value As Dictionary(Of String, IPropertyPackage))
AvailablePropPacks = value
End Set
End Property
Public Property AvailableSystemsOfUnits As New List(Of IUnitsOfMeasure) Implements IFlowsheet.AvailableSystemsOfUnits
Public Property ExternalUnitOperations As New Dictionary(Of String, IExternalUnitOperation)
Public Property GHGEmissionCompositions As Dictionary(Of String, IGHGComposition) = New Dictionary(Of String, IGHGComposition) Implements IFlowsheet.GHGEmissionCompositions
Private loaded As Boolean = False
Private rm, prm As Resources.ResourceManager
Public LoadSpreadsheetData, SaveSpreadsheetData As Action(Of XDocument)
Public GetSpreadsheetObjectFunc As Func(Of Object)
Public RetrieveSpreadsheetData As Func(Of String, List(Of String()))
Public RetrieveSpreadsheetFormat As Func(Of String, List(Of String()))
Public Property ScriptKeywordsF As String = ""
Public Property ScriptKeywordsU As String = ""
Protected _translatefunction As Func(Of String, String)
Public Sub AddCompoundsToMaterialStream(ms As IMaterialStream) Implements IFlowsheet.AddCompoundsToMaterialStream
For Each phase As IPhase In ms.Phases.Values
For Each comp In Me.Options.SelectedComponents.Values
With phase
.Compounds.Add(comp.Name, New Compound(comp.Name, ""))
.Compounds(comp.Name).ConstantProperties = comp
End With
Next
Next
DirectCast(ms, MaterialStream).EqualizeOverallComposition()
DirectCast(ms, MaterialStream).CalcOverallCompMassFractions()
End Sub
Public Sub AddGraphicObject(obj As IGraphicObject) Implements IFlowsheet.AddGraphicObject
FlowsheetSurface.DrawingObjects.Add(obj)
GraphicObjects.Add(obj.Name, obj)
End Sub
Public Function AddObject(t As Enums.GraphicObjects.ObjectType, xcoord As Integer, ycoord As Integer, tag As String) As ISimulationObject Implements IFlowsheet.AddObject
Dim id = Me.AddObjectToSurface(t, xcoord, ycoord, tag)
Return Me.SimulationObjects(id)
End Function
Public Function AddObject(t As Enums.GraphicObjects.ObjectType, xcoord As Integer, ycoord As Integer, id As String, tag As String) As ISimulationObject Implements IFlowsheet.AddObject
Me.AddObjectToSurface(t, xcoord, ycoord, tag, id)
Return Me.SimulationObjects(id)
End Function
Public Sub AddPropertyPackage(obj As IPropertyPackage) Implements IFlowsheet.AddPropertyPackage
If obj.UniqueID = "" Then obj.UniqueID = Guid.NewGuid().ToString()
If obj.Tag = "" Then obj.Tag = obj.GetType().Name
obj.Flowsheet = Me
Me.Options.PropertyPackages.Add(obj.UniqueID, obj)
End Sub
Public Sub AddSimulationObject(obj As ISimulationObject) Implements IFlowsheet.AddSimulationObject
SimulationObjects.Add(obj.Name, obj)
End Sub
Public Sub CheckStatus() Implements IFlowsheet.CheckStatus
FlowsheetSolver.FlowsheetSolver.CheckCalculatorStatus()
End Sub
Public Sub ConnectObjects(gobjfrom As IGraphicObject, gobjto As IGraphicObject, fromidx As Integer, toidx As Integer) Implements IFlowsheet.ConnectObjects
RegisterSnapshot(SnapshotType.ObjectAddedOrRemoved)
FlowsheetSurface.ConnectObject(CType(gobjfrom, GraphicObject), CType(gobjto, GraphicObject), fromidx, toidx)
End Sub
Public Sub DisconnectObjects(gobjfrom As IGraphicObject, gobjto As IGraphicObject) Implements IFlowsheet.DisconnectObjects
RegisterSnapshot(SnapshotType.ObjectAddedOrRemoved)
FlowsheetSurface.DisconnectObject(CType(gobjfrom, GraphicObject), CType(gobjto, GraphicObject), False)
End Sub
Public Sub DeleteSelectedObject(ByVal sender As System.Object, ByVal e As System.EventArgs, gobj As IGraphicObject, Optional ByVal confirmation As Boolean = True, Optional ByVal triggercalc As Boolean = False) Implements IFlowsheet.DeleteSelectedObject
RegisterSnapshot(SnapshotType.ObjectAddedOrRemoved)
If Not gobj Is Nothing Then
Dim namesel As String = gobj.Name
If Not gobj.IsConnector Then
If gobj.IsEnergyStream Then
Dim InCon, OutCon As IConnectionPoint
For Each InCon In gobj.InputConnectors
If InCon.IsAttached = True Then DisconnectObjects(InCon.AttachedConnector.AttachedFrom, gobj)
Next
For Each OutCon In gobj.OutputConnectors
If OutCon.IsAttached = True Then DisconnectObjects(gobj, OutCon.AttachedConnector.AttachedTo)
Next
'DWSIM
Me.SimulationObjects.Remove(namesel)
Me.GraphicObjects.Remove(namesel)
Me.FlowsheetSurface.DeleteSelectedObject(gobj)
Else
If gobj.ObjectType = ObjectType.GO_Table Or
gobj.ObjectType = ObjectType.GO_FloatingTable Or
gobj.ObjectType = ObjectType.GO_MasterTable Or
gobj.ObjectType = ObjectType.GO_SpreadsheetTable Or
gobj.ObjectType = ObjectType.GO_Text Or
gobj.ObjectType = ObjectType.GO_HTMLText Or
gobj.ObjectType = ObjectType.GO_Button Or
gobj.ObjectType = ObjectType.GO_Chart Then
Me.FlowsheetSurface.DeleteSelectedObject(gobj)
Else
Dim obj As ISimulationObject = Me.SimulationObjects(gobj.Name)
If gobj.EnergyConnector.IsAttached = True Then DisconnectObjects(gobj, gobj.EnergyConnector.AttachedConnector.AttachedTo)
Dim InCon, OutCon As IConnectionPoint
For Each InCon In gobj.InputConnectors
Try
If InCon.IsAttached = True Then DisconnectObjects(InCon.AttachedConnector.AttachedFrom, gobj)
Catch ex As Exception
End Try
Next
For Each OutCon In gobj.OutputConnectors
Try
If OutCon.IsAttached = True Then DisconnectObjects(gobj, OutCon.AttachedConnector.AttachedTo)
Catch ex As Exception
End Try
Next
If gobj.ObjectType = ObjectType.OT_Spec Then
Dim specobj As Spec = CType(SimulationObjects(namesel), Spec)
If Me.SimulationObjects.ContainsKey(specobj.TargetObjectData.ID) Then
Me.SimulationObjects(specobj.TargetObjectData.ID).IsSpecAttached = False
Me.SimulationObjects(specobj.TargetObjectData.ID).AttachedSpecId = ""
End If
If Me.SimulationObjects.ContainsKey(specobj.SourceObjectData.ID) Then
Me.SimulationObjects(specobj.SourceObjectData.ID).IsSpecAttached = False
Me.SimulationObjects(specobj.SourceObjectData.ID).AttachedSpecId = ""
End If
ElseIf gobj.ObjectType = ObjectType.OT_Adjust Then
Dim adjobj As Adjust = CType(SimulationObjects(namesel), Adjust)
If Me.SimulationObjects.ContainsKey(adjobj.ManipulatedObjectData.ID) Then
Me.SimulationObjects(adjobj.ManipulatedObjectData.ID).IsAdjustAttached = False
Me.SimulationObjects(adjobj.ManipulatedObjectData.ID).AttachedAdjustId = ""
End If
If Me.SimulationObjects.ContainsKey(adjobj.ControlledObjectData.ID) Then
Me.SimulationObjects(adjobj.ControlledObjectData.ID).IsAdjustAttached = False
Me.SimulationObjects(adjobj.ControlledObjectData.ID).AttachedAdjustId = ""
End If
If Me.SimulationObjects.ContainsKey(adjobj.ReferencedObjectData.ID) Then
Me.SimulationObjects(adjobj.ReferencedObjectData.ID).IsAdjustAttached = False
Me.SimulationObjects(adjobj.ReferencedObjectData.ID).AttachedAdjustId = ""
End If
ElseIf gobj.ObjectType = ObjectType.Controller_PID Then
Dim adjobj As PIDController = CType(SimulationObjects(namesel), PIDController)
If Me.SimulationObjects.ContainsKey(adjobj.ManipulatedObjectData.ID) Then
Me.SimulationObjects(adjobj.ManipulatedObjectData.ID).IsAdjustAttached = False
Me.SimulationObjects(adjobj.ManipulatedObjectData.ID).AttachedAdjustId = ""
End If
If Me.SimulationObjects.ContainsKey(adjobj.ControlledObjectData.ID) Then
Me.SimulationObjects(adjobj.ControlledObjectData.ID).IsAdjustAttached = False
Me.SimulationObjects(adjobj.ControlledObjectData.ID).AttachedAdjustId = ""
End If
If Me.SimulationObjects.ContainsKey(adjobj.ReferencedObjectData.ID) Then
Me.SimulationObjects(adjobj.ReferencedObjectData.ID).IsAdjustAttached = False
Me.SimulationObjects(adjobj.ReferencedObjectData.ID).AttachedAdjustId = ""
End If
End If
Me.SimulationObjects.Remove(namesel)
Me.GraphicObjects.Remove(namesel)
Me.FlowsheetSurface.DeleteSelectedObject(gobj)
End If
End If
End If
End If
End Sub
Public MustOverride Sub DisplayForm(form As Object) Implements IFlowsheet.DisplayForm
Public Property FilePath As String Implements IFlowsheet.FilePath
Public ReadOnly Property FlowsheetOptions As IFlowsheetOptions Implements IFlowsheet.FlowsheetOptions
Get
Return Options
End Get
End Property
Public Function GetFlowsheetGraphicObject(tag As String) As IGraphicObject
Return SimulationObjects.Values.Where(Function(x) x.GraphicObject.Tag = tag).FirstOrDefault?.GraphicObject
End Function
Public Function GetFlowsheetSimulationObject(tag As String) As ISimulationObject Implements IFlowsheet.GetFlowsheetSimulationObject
Return SimulationObjects.Values.Where(Function(x) x.GraphicObject.Tag = tag).FirstOrDefault
End Function
Public MustOverride Function GetNewInstance() As IFlowsheet Implements IFlowsheet.GetNewInstance
Public Function GetSelectedFlowsheetSimulationObject(tag As String) As ISimulationObject Implements IFlowsheet.GetSelectedFlowsheetSimulationObject
If tag Is Nothing OrElse tag = "" Then
If FlowsheetSurface.SelectedObject IsNot Nothing Then
If SimulationObjects.ContainsKey(FlowsheetSurface.SelectedObject.Name) Then Return SimulationObjects(FlowsheetSurface.SelectedObject.Name) Else Return Nothing
Else
Return Nothing
End If
Else
Return SimulationObjects.Values.Where(Function(x) x.GraphicObject.Tag = tag).FirstOrDefault
End If
End Function
Public Function GetSurface() As Object Implements IFlowsheet.GetSurface
Return FlowsheetSurface
End Function
Public Function GetSurfaceControl() As Object Implements IFlowsheet.GetSurfaceControl
Return Nothing
End Function
Public Function GetTranslatedString(text As String) As String Implements IFlowsheet.GetTranslatedString
If _translatefunction IsNot Nothing Then
Return _translatefunction.Invoke(text)
End If
If rm Is Nothing Then
rm = New Resources.ResourceManager("DWSIM.FlowsheetBase.Strings", MyBase.GetType.GetTypeInfo.BaseType.GetTypeInfo.Assembly)
End If
Dim ttext As String = rm.GetString(text)
If Not ttext Is Nothing AndAlso Not ttext.Equals(text) Then
Return ttext
Else
If prm Is Nothing Then
prm = New Resources.ResourceManager("DWSIM.FlowsheetBase.Properties", MyBase.GetType.GetTypeInfo.BaseType.GetTypeInfo.Assembly)
End If
Try
If text.Split("/"c).Length = 2 Then
Dim prop As String = text.Split("/"c)(0)
Dim ttext2 As String = prm.GetString(prop)
If ttext2 Is Nothing Then Return text Else Return ttext2 + " / " + text.Split("/"c)(1)
Else
Dim ttext2 As String = prm.GetString(text)
If ttext2 Is Nothing Then Return text Else Return ttext2
End If
Catch ex As Exception
Return text
End Try
End If
End Function
Public Function GetTranslatedString(text As String, locale As String) As String Implements IFlowsheet.GetTranslatedString
Return GetTranslatedString(text)
End Function
Public Property GraphicObjects As New Dictionary(Of String, IGraphicObject) Implements IFlowsheet.GraphicObjects
Public Property PropertyPackages As Dictionary(Of String, IPropertyPackage) Implements IFlowsheet.PropertyPackages
Get
Return Options.PropertyPackages
End Get
Set(value As Dictionary(Of String, IPropertyPackage))
Options.PropertyPackages = value
End Set
End Property
Public Property Reactions As Dictionary(Of String, IReaction) Implements IFlowsheet.Reactions
Get
Return Options.Reactions
End Get
Set(value As Dictionary(Of String, IReaction))
Options.Reactions = value
End Set
End Property
Public Property ReactionSets As Dictionary(Of String, IReactionSet) Implements IFlowsheet.ReactionSets
Get
Return Options.ReactionSets
End Get
Set(value As Dictionary(Of String, IReactionSet))
Options.ReactionSets = value
End Set
End Property
Public Property RedirectMessages As Boolean Implements IFlowsheet.RedirectMessages
Public Sub Solve()
RequestCalculation()
End Sub
Public Sub RequestCalculation(Optional sender As ISimulationObject = Nothing, Optional ChangeCalculationOrder As Boolean = False) Implements IFlowsheet.RequestCalculation
If Not sender Is Nothing Then
'Call function to calculate flowsheet
Dim objargs As New CalculationArgs
With objargs
.Calculated = False
.Tag = sender.GraphicObject.Tag
.Name = sender.Name
.ObjectType = sender.GraphicObject.ObjectType
.Sender = "PropertyGrid"
End With
CalculationQueue.Enqueue(objargs)
Task.Factory.StartNew(Sub()
FlowsheetSolver.FlowsheetSolver.SolveFlowsheet(Me, GlobalSettings.Settings.SolverMode, , True)
End Sub)
Else
FlowsheetSolver.FlowsheetSolver.SolveFlowsheet(Me, GlobalSettings.Settings.SolverMode, ChangeCalcOrder:=ChangeCalculationOrder)
End If
End Sub
Public Sub RequestCalculation2(Wait As Boolean) Implements IFlowsheet.RequestCalculation2
If Wait Then
Task.Factory.StartNew(Sub()
FlowsheetSolver.FlowsheetSolver.SolveFlowsheet(Me, GlobalSettings.Settings.SolverMode)
End Sub)
Else
FlowsheetSolver.FlowsheetSolver.SolveFlowsheet(Me, GlobalSettings.Settings.SolverMode)
End If
End Sub
Public Sub RequestCalculation3(Obj As ISimulationObject, Wait As Boolean) Implements IFlowsheet.RequestCalculation3
If Obj Is Nothing Then
RequestCalculation2(Wait)
Else
RequestCalculation(Obj)
End If
End Sub
Public Sub ResetCalculationStatus() Implements IFlowsheet.ResetCalculationStatus
For Each obj In SimulationObjects.Values
obj.SetDirtyStatus(True)
obj.Calculated = False
obj.GraphicObject.Calculated = False
Next
End Sub
Public Property SelectedCompounds As Dictionary(Of String, ICompoundConstantProperties) Implements IFlowsheet.SelectedCompounds
Get
Select Case Options.CompoundOrderingMode
Case CompoundOrdering.CAS_ASC
Return Options.SelectedComponents.OrderBy(Function(c) c.Value.CAS_Number).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.CAS_DESC
Return Options.SelectedComponents.OrderByDescending(Function(c) c.Value.CAS_Number).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.MW_ASC
Return Options.SelectedComponents.OrderBy(Function(c) c.Value.Molar_Weight).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.MW_DESC
Return Options.SelectedComponents.OrderByDescending(Function(c) c.Value.Molar_Weight).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.Name_ASC
Return Options.SelectedComponents.OrderBy(Function(c) c.Value.Name).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.Name_DESC
Return Options.SelectedComponents.OrderByDescending(Function(c) c.Value.Name).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.NBP_ASC
Return Options.SelectedComponents.OrderBy(Function(c) c.Value.NBP.GetValueOrDefault).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.NBP_DESC
Return Options.SelectedComponents.OrderByDescending(Function(c) c.Value.NBP.GetValueOrDefault).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.TAG_ASC
Return Options.SelectedComponents.OrderBy(Function(c) c.Value.Tag).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case CompoundOrdering.TAG_DESC
Return Options.SelectedComponents.OrderByDescending(Function(c) c.Value.Tag).ToDictionary(Of String, ICompoundConstantProperties)(Function(k) k.Key, Function(k) k.Value)
Case Else
Return Options.SelectedComponents
End Select
End Get
Set(value As Dictionary(Of String, ICompoundConstantProperties))
Options.SelectedComponents = value
End Set
End Property
Public MustOverride Sub ShowDebugInfo(text As String, level As Integer) Implements IFlowsheet.ShowDebugInfo
Public MustOverride Sub ShowMessage(text As String, mtype As IFlowsheet.MessageType, Optional ByVal exceptionID As String = "") Implements IFlowsheet.ShowMessage
Public Property SimulationObjects As New Dictionary(Of String, ISimulationObject) Implements IFlowsheet.SimulationObjects
Public MustOverride Sub UpdateOpenEditForms() Implements IFlowsheet.UpdateOpenEditForms
Public MustOverride Sub CloseOpenEditForms() Implements IFlowsheet.CloseOpenEditForms
Public Property CalculationQueue As New Queue(Of ICalculationArgs) Implements IFlowsheetCalculationQueue.CalculationQueue
Public Function AddObject(ByVal typename As String, ByVal x As Integer, ByVal y As Integer, Optional ByVal tag As String = "",
Optional ByVal id As String = "", Optional CreateConnected As Boolean = False) As ISimulationObject
Select Case typename
Case "Controller Block"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.OT_Adjust, x, y, tag,,, CreateConnected))
Case "Specification Block"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.OT_Spec, x, y, tag,,, CreateConnected))
Case "Recycle Block"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.OT_Recycle, x, y, tag,,, CreateConnected))
Case "Energy Recycle Block"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.OT_EnergyRecycle, x, y, tag,,, CreateConnected))
Case "Stream Mixer"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.NodeIn, x, y, tag,,, CreateConnected))
Case "Stream Splitter"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.NodeOut, x, y, tag,,, CreateConnected))
Case "Pump"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Pump, x, y, tag,,, CreateConnected))
Case "Tank"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Tank, x, y, tag,,, CreateConnected))
Case "Gas-Liquid Separator"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Vessel, x, y, tag,,, CreateConnected))
Case "Material Stream"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.MaterialStream, x, y, tag,,, CreateConnected))
Case "Energy Stream"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.EnergyStream, x, y, tag,,, CreateConnected))
Case "Compressor"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Compressor, x, y, tag,,, CreateConnected))
Case "Expander (Turbine)"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Expander, x, y, tag,,, CreateConnected))
Case "Heater"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Heater, x, y, tag,,, CreateConnected))
Case "Cooler"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Cooler, x, y, tag,,, CreateConnected))
Case "Pipe Segment"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Pipe, x, y, tag,,, CreateConnected))
Case "Valve"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Valve, x, y, tag,,, CreateConnected))
Case "Conversion Reactor"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.RCT_Conversion, x, y, tag,,, CreateConnected))
Case "Equilibrium Reactor"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.RCT_Equilibrium, x, y, tag,,, CreateConnected))
Case "Gibbs Reactor"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.RCT_Gibbs, x, y, tag,,, CreateConnected))
Case "Plug-Flow Reactor (PFR)"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.RCT_PFR, x, y, tag,,, CreateConnected))
Case "Continuous Stirred Tank Reactor (CSTR)"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.RCT_CSTR, x, y, tag,,, CreateConnected))
Case "Heat Exchanger"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.HeatExchanger, x, y, tag,,, CreateConnected))
Case "Shortcut Column"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.ShortcutColumn, x, y, tag,,, CreateConnected))
Case "Distillation Column"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.DistillationColumn, x, y, tag,,, CreateConnected))
Case "Absorption Column", "Absorption/Extraction Column"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.AbsorptionColumn, x, y, tag,,, CreateConnected))
Case "Compound Separator"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.ComponentSeparator, x, y, tag,,, CreateConnected))
Case "Solids Separator"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.SolidSeparator, x, y, tag,,, CreateConnected))
Case "Filter"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Filter, x, y, tag,,, CreateConnected))
Case "Orifice Plate"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.OrificePlate, x, y, tag,,, CreateConnected))
Case "Python Script"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.CustomUO, x, y, tag,,, CreateConnected))
Case "Spreadsheet"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.ExcelUO, x, y, tag,,, CreateConnected))
Case "Flowsheet"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.FlowsheetUO, x, y, tag,,, CreateConnected))
Case "CAPE-OPEN Unit Operation"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.CapeOpenUO, x, y, tag,,, CreateConnected))
Case "Digital Gauge"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.DigitalGauge, x, y, tag,,, CreateConnected))
Case "Analog Gauge"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.AnalogGauge, x, y, tag,,, CreateConnected))
Case "Level Gauge"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.LevelGauge, x, y, tag,,, CreateConnected))
Case "PID Controller"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Controller_PID, x, y, tag,,, CreateConnected))
Case "Python Controller"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Controller_Python, x, y, tag,,, CreateConnected))
Case "Input Box"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Input, x, y, tag,,, CreateConnected))
Case "Switch"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.Switch, x, y, tag,,, CreateConnected))
Case "Air Cooler 2"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.AirCooler2, x, y, tag,,, CreateConnected))
Case "Gibbs Reactor (Reaktoro)"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.RCT_GibbsReaktoro, x, y, tag,,, CreateConnected))
Case "Wind Turbine"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.WindTurbine, x, y, tag,,, CreateConnected))
Case "Hydroelectric Turbine"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.HydroelectricTurbine, x, y, tag,,, CreateConnected))
Case "Solar Panel"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.SolarPanel, x, y, tag,,, CreateConnected))
Case "Water Electrolyzer"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.WaterElectrolyzer, x, y, tag,,, CreateConnected))
Case "PEM Fuel Cell (Amphlett)"
Return Me.SimulationObjects(AddObjectToSurface(ObjectType.PEMFuelCell, x, y, tag,,, CreateConnected))
Case Else
Return Nothing
End Select
End Function
Public Function GetAvailableFlowsheetObjectTypeNames() As Array Implements IFlowsheet.GetAvailableFlowsheetObjectTypeNames
Dim list As New List(Of String)
list.AddRange({
"Controller Block",
"Specification Block",
"Recycle Block",
"Energy Recycle Block",
"Stream Mixer",
"Stream Splitter",
"Pump",
"Tank",
"Gas-Liquid Separator",
"Material Stream",
"Energy Stream",
"Compressor",
"Expander",
"Heater",
"Cooler",
"Pipe Segment",
"Valve",
"Conversion Reactor",
"Equilibrium Reactor",
"Gibbs Reactor",
"Plug-Flow Reactor (PFR)",
"Continuous Stirred Tank Reactor (CSTR)",
"Heat Exchanger",
"Shortcut Column",
"Distillation Column",
"Absorption Column", "Absorption/Extraction Column",
"Compound Separator",
"Solids Separator",
"Filter",
"Orifice Plate",
"Python Script",
"Spreadsheet",
"Flowsheet",
"CAPE-OPEN Unit Operation",
"Digital Gauge",
"Analog Gauge",
"Level Gauge",
"PID Controller",
"Python Controller",
"Input Box",
"Switch",
"Air Cooler 2",
"Gibbs Reactor (Reaktoro)",
"Wind Turbine",
"Hydroelectric Turbine",
"Solar Panel",
"Water Electrolyzer",
"PEM Fuel Cell (Amphlett)"})
list.Sort()
Return list.ToArray()
End Function
Public Function AddFlowsheetObject(typename As String, objname As String) As ISimulationObject Implements IFlowsheet.AddFlowsheetObject
Select Case typename
Case "Controller Block"
Return AddObject(ObjectType.OT_Adjust, 50, 50, objname)
Case "Specification Block"
Return AddObject(ObjectType.OT_Spec, 50, 50, objname)
Case "Recycle Block"
Return AddObject(ObjectType.OT_Recycle, 50, 50, objname)
Case "Energy Recycle Block"
Return AddObject(ObjectType.OT_EnergyRecycle, 50, 50, objname)
Case "Stream Mixer"
Return AddObject(ObjectType.NodeIn, 50, 50, objname)
Case "Stream Splitter"
Return AddObject(ObjectType.NodeOut, 50, 50, objname)
Case "Pump"
Return AddObject(ObjectType.Pump, 50, 50, objname)
Case "Tank"
Return AddObject(ObjectType.Tank, 50, 50, objname)
Case "Gas-Liquid Separator"
Return AddObject(ObjectType.Vessel, 50, 50, objname)
Case "Material Stream"
Return AddObject(ObjectType.MaterialStream, 50, 50, objname)
Case "Energy Stream"
Return AddObject(ObjectType.EnergyStream, 50, 50, objname)
Case "Compressor"
Return AddObject(ObjectType.Compressor, 50, 50, objname)
Case "Expander"
Return AddObject(ObjectType.Expander, 50, 50, objname)
Case "Heater"
Return AddObject(ObjectType.Heater, 50, 50, objname)
Case "Cooler"
Return AddObject(ObjectType.Cooler, 50, 50, objname)
Case "Pipe Segment"
Return AddObject(ObjectType.Pipe, 50, 50, objname)
Case "Valve"
Return AddObject(ObjectType.Valve, 50, 50, objname)
Case "Conversion Reactor"
Return AddObject(ObjectType.RCT_Conversion, 50, 50, objname)
Case "Equilibrium Reactor"
Return AddObject(ObjectType.RCT_Equilibrium, 50, 50, objname)
Case "Gibbs Reactor"
Return AddObject(ObjectType.RCT_Gibbs, 50, 50, objname)
Case "Plug-Flow Reactor (PFR)"
Return AddObject(ObjectType.RCT_PFR, 50, 50, objname)
Case "Continuous Stirred Tank Reactor (CSTR)"
Return AddObject(ObjectType.RCT_CSTR, 50, 50, objname)
Case "Heat Exchanger"
Return AddObject(ObjectType.HeatExchanger, 50, 50, objname)
Case "Shortcut Column"
Return AddObject(ObjectType.ShortcutColumn, 50, 50, objname)
Case "Distillation Column"
Return AddObject(ObjectType.DistillationColumn, 50, 50, objname)
Case "Absorption Column", "Absorption/Extraction Column"
Return AddObject(ObjectType.AbsorptionColumn, 50, 50, objname)
Case "Compound Separator"
Return AddObject(ObjectType.ComponentSeparator, 50, 50, objname)
Case "Solids Separator"
Return AddObject(ObjectType.SolidSeparator, 50, 50, objname)
Case "Filter"
Return AddObject(ObjectType.Filter, 50, 50, objname)
Case "Orifice Plate"
Return AddObject(ObjectType.OrificePlate, 50, 50, objname)
Case "Python Script"
Return AddObject(ObjectType.CustomUO, 50, 50, objname)
Case "Spreadsheet"
Return AddObject(ObjectType.ExcelUO, 50, 50, objname)
Case "Flowsheet"
Return AddObject(ObjectType.FlowsheetUO, 50, 50, objname)
Case "CAPE-OPEN Unit Operation"
Return AddObject(ObjectType.CapeOpenUO, 50, 50, objname)
Case "Digital Gauge"
Return AddObject(ObjectType.DigitalGauge, 50, 50, objname)
Case "Analog Gauge"
Return AddObject(ObjectType.AnalogGauge, 50, 50, objname)
Case "Level Gauge"
Return AddObject(ObjectType.LevelGauge, 50, 50, objname)
Case "PID Controller"
Return AddObject(ObjectType.Controller_PID, 50, 50, objname)
Case "Python Controller"
Return AddObject(ObjectType.Controller_Python, 50, 50, objname)
Case "Input Box"
Return AddObject(ObjectType.Input, 50, 50, objname)
Case "Switch"
Return AddObject(ObjectType.Switch, 50, 50, objname)
Case "Air Cooler 2"
Return AddObject(ObjectType.AirCooler2, 50, 50, objname)
Case "Gibbs Reactor (Reaktoro)"
Return AddObject(ObjectType.RCT_GibbsReaktoro, 50, 50, objname)
Case "Wind Turbine"
Return AddObject(ObjectType.WindTurbine, 50, 50, objname)
Case "Hydroelectric Turbine"
Return AddObject(ObjectType.HydroelectricTurbine, 50, 50, objname)
Case "Solar Panel"
Return AddObject(ObjectType.SolarPanel, 50, 50, objname)
Case "Water Electrolyzer"
Return AddObject(ObjectType.WaterElectrolyzer, 50, 50, objname)
Case "PEM Fuel Cell (Amphlett)"
Return AddObject(ObjectType.PEMFuelCell, 50, 50, objname)
Case Else
Return Nothing
End Select
End Function
Public Function AddObjectToSurface(type As ObjectType, x As Integer, y As Integer,
Optional tag As String = "",
Optional id As String = "",
Optional uoobj As Interfaces.IExternalUnitOperation = Nothing,
Optional CreateConnected As Boolean = False) As String
RegisterSnapshot(SnapshotType.ObjectAddedOrRemoved)
Dim gObj As GraphicObject = Nothing
Dim mpx = x '- SplitContainer1.SplitterDistance
Dim mpy = y '- ToolStripContainer1.TopToolStripPanel.Height
Dim objindex = (SimulationObjects.Values.Where(Function(o) o.GraphicObject.ObjectType = type).Count + 1).ToString()
Select Case type
Case ObjectType.External
Dim myNode As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
myNode.Tag = uoobj.Prefix + objindex
If tag <> "" Then myNode.Tag = tag
gObj = myNode
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(uoobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, myNode)
DirectCast(uoobj, Interfaces.ISimulationObject).GraphicObject = myNode
myNode.CreateConnectors(0, 0)
SimulationObjects.Add(myNode.Name, uoobj)
Case ObjectType.Switch
Dim myGobj As New SwitchGraphic(mpx, mpy, 50, 40)
myGobj.Tag = "SW-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "SW-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As UnitOperations.UnitOperations.Switch = New UnitOperations.UnitOperations.Switch(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)