File size: 50,579 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 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 |
Imports System.IO
Imports System.Reflection
Imports DWSIM.Interfaces
Namespace Scripts
Public Class IronPythonSnippet
Public Property Name As String = ""
Public Property Category1 As String = ""
Public Property Category2 As String = ""
Public Property Scope As String = ""
Public Property Snippet As String = ""
End Class
Public Class IronPythonSnippets
Public Sub New()
End Sub
Private Shared Function GetSnippetsXML() As XDocument
Dim xmldoc = New XDocument()
Using filestr As Stream = Assembly.GetExecutingAssembly.GetManifestResourceStream("DWSIM.SharedClasses.IronPythonSnippets.xml")
xmldoc = XDocument.Load(filestr)
End Using
Return xmldoc
End Function
Public Shared Function GetSnippets() As List(Of IronPythonSnippet)
Dim list As New List(Of IronPythonSnippet)
Dim xml = GetSnippetsXML()
For Each node As XElement In xml.Elements.First.Elements
Dim snippet As New IronPythonSnippet()
snippet.Name = node.Elements("A").Value
snippet.Category1 = node.Elements("B").Value
snippet.Category2 = node.Elements("C").Value
snippet.Scope = node.Elements("D").Value
snippet.Snippet = node.Elements("E").Value
list.Add(snippet)
Next
list.Remove(list.First)
Return list
End Function
Public Shared Sub PopulateWithDynamicSnippets(contextmenu As Eto.Forms.ContextMenu, fs As IFlowsheet, InsertText As Action(Of String))
Dim gettsmi = New Eto.Forms.ButtonMenuItem With {.Text = "Get Object Property"}
Dim settsmi = New Eto.Forms.ButtonMenuItem With {.Text = "Set Object Property"}
For Each item In fs.SimulationObjects.Values.OrderBy(Function(x) x.GraphicObject.Tag)
Dim itemtsmig As New Eto.Forms.ButtonMenuItem
itemtsmig.Text = item.GraphicObject.Tag
gettsmi.Items.Add(itemtsmig)
Dim itemtsmis As New Eto.Forms.ButtonMenuItem
itemtsmis.Text = item.GraphicObject.Tag
settsmi.Items.Add(itemtsmis)
If TypeOf item Is IMaterialStream Then
' set overall properties
itemtsmis.Items.Add(
CreateMenuItem("Stream Temperature", Sub()
InsertText("# Define Stream Temperature")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetTemperature(value) # value must be in K"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Pressure", Sub()
InsertText("# Define Stream Pressure")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetPressure(value) # value must be in Pa"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Enthalpy", Sub()
InsertText("# Define Stream Enthalpy")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetMassEnthalpy(value) # value must be in kJ/kg"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Entropy", Sub()
InsertText("# Define Stream Entropy")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetMassEntropy(value) # value must be in kJ/[kg.K]"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Mass Flow", Sub()
InsertText("Define Stream Mass Flow")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetMassFlow(value) # value must be in kg/s"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Molar Flow", Sub()
InsertText("# Define Stream Molar Flow")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetMolarFlow(value) # value must be in mol/s"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Volumetric Flow", Sub()
InsertText("# Define Stream Volumetric Flow")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream.SetVolumetricFlow(value) # value must be in m3/s"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Vapor Molar Fraction", Sub()
InsertText("# Set Stream Vapor Molar Fraction")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj.GetPhase('Vapor').Properties.molarfraction = value # number ranging from 0.0 to 1.0"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Molar Composition", Sub()
InsertText("# Define Stream Molar Composition")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = System.Array[double]([0.1, ..., x])"))
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj.SetOverallComposition(value) # value must be an array of mole fractions"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmis.Items.Add(
CreateMenuItem("Stream Flash Specification", Sub()
InsertText("# Define Stream Flash Specification")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj.SpecType = value # number from 0 to 5"))
InsertText(System.Environment.NewLine)
InsertText("# Accepted values:")
InsertText(System.Environment.NewLine)
InsertText("# 0: Temperature_and_Pressure")
InsertText(System.Environment.NewLine)
InsertText("# 1: Pressure_and_Enthalpy")
InsertText(System.Environment.NewLine)
InsertText("# 2: Pressure_and_Entropy")
InsertText(System.Environment.NewLine)
InsertText("# 3: Pressure_and_VaporFraction")
InsertText(System.Environment.NewLine)
InsertText("# 4: Temperature_and_VaporFraction")
InsertText(System.Environment.NewLine)
InsertText("# 5: Pressure_and_SolidFraction")
InsertText(System.Environment.NewLine)
End Sub, fs))
'get overall properties
itemtsmig.Items.Add(
CreateMenuItem("Stream Temperature", Sub()
InsertText("# Get Stream Temperature")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetTemperature() # in K"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Pressure", Sub()
InsertText("# Get Stream Pressure")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetPressure() # in Pa"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Enthalpy", Sub()
InsertText("# Get Stream Enthalpy")
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetMassEnthalpy() # in kJ/kg"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Entropy", Sub()
InsertText("# Get Stream Entropy")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetMassEntropy() # in kJ/[kg.K]"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Mass Flow", Sub()
InsertText("Get Stream Mass Flow")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetMassFlow() # in kg/s"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Molar Flow", Sub()
InsertText("# Get Stream Molar Flow")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetMolarFlow() # in mol/s"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Volumetric Flow", Sub()
InsertText("# Get Stream Volumetric Flow")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("stream = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = stream.GetVolumetricFlow() # in m3/s"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Vapor Molar Fraction", Sub()
InsertText("# Get Stream Vapor Molar Fraction")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('Vapor').Properties.molarfraction # number ranging from 0.0 to 1.0"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Molar Composition", Sub()
InsertText("# Get Stream Molar Composition")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetOverallComposition() # array of mole fractions"))
InsertText(System.Environment.NewLine)
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Stream Flash Specification", Sub()
InsertText("# Get Stream Flash Specification")
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.SpecType # number from 0 to 5"))
InsertText(System.Environment.NewLine)
InsertText("# Current values:")
InsertText(System.Environment.NewLine)
InsertText("# 0: Temperature_and_Pressure")
InsertText(System.Environment.NewLine)
InsertText("# 1: Pressure_and_Enthalpy")
InsertText(System.Environment.NewLine)
InsertText("# 2: Pressure_and_Entropy")
InsertText(System.Environment.NewLine)
InsertText("# 3: Pressure_and_VaporFraction")
InsertText(System.Environment.NewLine)
InsertText("# 4: Temperature_and_VaporFraction")
InsertText(System.Environment.NewLine)
InsertText("# 5: Pressure_and_SolidFraction")
InsertText(System.Environment.NewLine)
End Sub, fs))
Dim p1 = CreateMenuItem(("Phase Properties") & " - " & ("Overall"), Nothing, fs)
Dim p2 = CreateMenuItem(("Phase Properties") & " - " & ("Vapor"), Nothing, fs)
Dim p3 = CreateMenuItem(("Phase Properties") & " - " & ("Overall Liquid"), Nothing, fs)
Dim p4 = CreateMenuItem(("Phase Properties") & " - " & ("Liquid 1"), Nothing, fs)
Dim p5 = CreateMenuItem(("Phase Properties") & " - " & ("Liquid 2"), Nothing, fs)
Dim p6 = CreateMenuItem(("Phase Properties") & " - " & ("Solid"), Nothing, fs)
Dim pprops = GetType(IPhaseProperties).GetRuntimeProperties()
For Each pitem In pprops
p1.Items.Add(CreateMenuItem(pitem.Name, Sub()
InsertText("# Get Stream Phase Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('Overall').Properties.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
p2.Items.Add(CreateMenuItem(pitem.Name, Sub()
InsertText("# Get Stream Phase Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('Vapor').Properties.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
p3.Items.Add(CreateMenuItem(pitem.Name, Sub()
InsertText("# Get Stream Phase Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('OverallLiquid').Properties.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
p4.Items.Add(CreateMenuItem(pitem.Name, Sub()
InsertText("# Get Stream Phase Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('Liquid1').Properties.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
p5.Items.Add(CreateMenuItem(pitem.Name, Sub()
InsertText("# Get Stream Phase Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('Liquid2').Properties.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
p6.Items.Add(CreateMenuItem(pitem.Name, Sub()
InsertText("# Get Stream Phase Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.GetPhase('Solid').Properties.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
Next
Dim pc = CreateMenuItem("Compounds", Nothing, fs)
itemtsmig.Items.AddRange({pc, p1, p2, p3, p4, p5, p6})
Dim ccprops = GetType(Interfaces.ICompoundConstantProperties).GetRuntimeProperties()
Dim cpprops = GetType(Interfaces.ICompound).GetRuntimeProperties()
For Each c In fs.SelectedCompounds.Values
Dim cx = CreateMenuItem(c.Name, Nothing, fs)
Dim c1 = CreateMenuItem(("Constant Properties"), Nothing, fs)
Dim c2 = CreateMenuItem(("Phase Properties"), Nothing, fs)
pc.Items.Add(cx)
cx.Items.Add(c1)
cx.Items.Add(c2)
For Each cc1 In ccprops
c1.Items.Add(CreateMenuItem(cc1.Name, Sub()
InsertText("# Get Compound Constant Property: " & cc1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("compound = Flowsheet.SelectedCompounds['{0}']", c.Name))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = compound.{0}", cc1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
Next
For Each cp1 In cpprops
c2.Items.Add(CreateMenuItem(cp1.Name & " (Mixture Phase)", Sub()
InsertText("# Get Compound Property in Mixture (Overall) Phase: " & cp1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = obj.GetPhase('Overall').Compounds['{0}'].{1}", c.Name, cp1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
c2.Items.Add(CreateMenuItem(cp1.Name & " (Vapor Phase)", Sub()
InsertText("# Get Compound Property in Vapor Phase: " & cp1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = obj.GetPhase('Vapor').Compounds['{0}'].{1}", c.Name, cp1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
c2.Items.Add(CreateMenuItem(cp1.Name & " (Overall Liquid Phase)", Sub()
InsertText("# Get Compound Property in Overall Liquid Phase: " & cp1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = obj.GetPhase('OverallLiquid').Compounds['{0}'].{1}", c.Name, cp1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
c2.Items.Add(CreateMenuItem(cp1.Name & " (Liquid Phase 1)", Sub()
InsertText("# Get Compound Property in Liquid Phase 1: " & cp1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = obj.GetPhase('Liquid1').Compounds['{0}'].{1}", c.Name, cp1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
c2.Items.Add(CreateMenuItem(cp1.Name & " (Liquid Phase 2)", Sub()
InsertText("# Get Compound Property in Liquid Phase 2: " & cp1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = obj.GetPhase('Liquid2').Compounds['{0}'].{1}", c.Name, cp1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
c2.Items.Add(CreateMenuItem(cp1.Name & " (Solid Phase)", Sub()
InsertText("# Get Compound Property in Solid Phase: " & cp1.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("propval = obj.GetPhase('Solid').Compounds['{0}'].{1}", c.Name, cp1.Name))
InsertText(System.Environment.NewLine)
End Sub, fs))
Next
Next
Else
Dim itemprops = item.GetType.GetRuntimeProperties()
Dim itemfields = item.GetType.GetRuntimeFields()
For Each pitem In itemprops
itemtsmis.Items.Add(
CreateMenuItem("Object Property: " & pitem.Name, Sub()
InsertText("# Define Object Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj.{0} = value", pitem.Name))
InsertText(System.Environment.NewLine)
If pitem.PropertyType.BaseType Is GetType([Enum]) Then
InsertText(System.Environment.NewLine)
InsertText("# This property is an Enumeration (Enum) type.")
InsertText(System.Environment.NewLine)
InsertText(String.Format("# Full type name: {0}", pitem.PropertyType.ToString.Replace("+", ".")))
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText("# Accepted enumeration values:")
InsertText(System.Environment.NewLine)
For Each etype In [Enum].GetNames(pitem.PropertyType)
InsertText(String.Format("# {0}.{1}", pitem.PropertyType.ToString.Replace("+", "."), etype))
InsertText(System.Environment.NewLine)
Next
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText("# example usage:")
InsertText(System.Environment.NewLine)
InsertText(String.Format("# obj.{0} = {1}.{2}", pitem.Name, pitem.PropertyType.ToString.Replace("+", "."), [Enum].GetNames(pitem.PropertyType)(0)))
End If
End Sub, fs))
itemtsmig.Items.Add(
CreateMenuItem("Object Property: " & pitem.Name, Sub()
InsertText("# Get Object Property: " & pitem.Name)
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText(String.Format("obj = Flowsheet.GetFlowsheetSimulationObject('{0}')", item.GraphicObject.Tag))
InsertText(System.Environment.NewLine)
InsertText(String.Format("value = obj.{0}", pitem.Name))
InsertText(System.Environment.NewLine)
If pitem.PropertyType.BaseType Is GetType([Enum]) Then
InsertText(System.Environment.NewLine)
InsertText("# This property is an Enumeration (Enum) type.")
InsertText(System.Environment.NewLine)
InsertText(String.Format("# Full type name: {0}", pitem.PropertyType.ToString.Replace("+", ".")))
InsertText(System.Environment.NewLine)
InsertText(System.Environment.NewLine)
InsertText("# Possible enumeration values:")
InsertText(System.Environment.NewLine)
For Each etype In [Enum].GetNames(pitem.PropertyType)
InsertText(String.Format("# {0}.{1}", pitem.PropertyType.ToString.Replace("+", "."), etype))
InsertText(System.Environment.NewLine)
Next
End If
End Sub, fs))
Next
End If
Next
contextmenu.Items.Insert(0, gettsmi)
contextmenu.Items.Insert(1, settsmi)
End Sub
Private Shared Function CreateMenuItem(text As String, clickaction As Action, flowsheet As IFlowsheet) As Eto.Forms.ButtonMenuItem
Dim tsmi As New Eto.Forms.ButtonMenuItem With {.Text = text}
AddHandler tsmi.Click, Sub()
If clickaction IsNot Nothing Then flowsheet.RunCodeOnUIThread(clickaction)
End Sub
Return tsmi
End Function
End Class
End Namespace
|