File size: 262,162 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 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 | 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
Imports DWSIM.ExtensionMethods
<System.Runtime.InteropServices.ComVisible(True)> Public MustInherit Class FlowsheetBase
Implements IFlowsheet, IFlowsheetCalculationQueue
Private Shared ObjectList As New Dictionary(Of String, Interfaces.ISimulationObject)
Public Property SupressDataLoading As Boolean = False
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 InternalUnitOperations As New Dictionary(Of String, IUnitOperation)
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 SetResourcesManager(_rm As Resources.ResourceManager)
rm = _rm
End Sub
Public Sub SetPropertyResourcesManager(_prm As Resources.ResourceManager)
prm = _prm
End Sub
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", Assembly.GetExecutingAssembly())
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", Assembly.GetExecutingAssembly())
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 Not 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 Function RequestCalculationAndWait() As List(Of Exception) Implements IFlowsheet.RequestCalculationAndWait
Return FlowsheetSolver.FlowsheetSolver.SolveFlowsheet(Me, GlobalSettings.Settings.SolverMode)
End Function
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)
Case ObjectType.Input
Dim myGobj As New InputGraphic(mpx, mpy, 50, 25)
myGobj.Tag = "IN-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "IN-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As Input = New Input(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)
GraphicObjectControlPanelModeEditors.SetInputDelegate(myGobj, myObj)
Case ObjectType.Controller_PID
Dim myGobj As New PIDControllerGraphic(mpx, mpy, 50, 50)
myGobj.Tag = "PID-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "PID-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As PIDController = New PIDController(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)
GraphicObjectControlPanelModeEditors.SetPIDDelegate(myGobj, myObj)
Case ObjectType.Controller_Python
Dim myGobj As New PythonControllerGraphic(mpx, mpy, 50, 50)
myGobj.Tag = "PC-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "PC-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As PythonController = New PythonController(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)
Case ObjectType.LevelGauge
Dim myGobj As New LevelGaugeGraphic(mpx, mpy, 40, 70)
myGobj.Tag = "LG-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "LG-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As LevelGauge = New LevelGauge(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)
Case ObjectType.DigitalGauge
Dim myGobj As New DigitalGaugeGraphic(mpx, mpy, 40, 20)
myGobj.Tag = "DG-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "DG-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As DigitalGauge = New DigitalGauge(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)
Case ObjectType.AnalogGauge
Dim myGobj As New AnalogGaugeGraphic(mpx, mpy, 50, 50)
myGobj.Tag = "AG-" + objindex
If tag <> "" Then myGobj.Tag = tag
gObj = myGobj
CheckTag(gObj)
gObj.Name = "AG-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myGobj)
Dim myObj As AnalogGauge = New AnalogGauge(gObj.Name, "")
myObj.GraphicObject = myGobj
SimulationObjects.Add(myGobj.Name, myObj)
Case ObjectType.OT_Adjust
Dim myNode As New AdjustGraphic(mpx, mpy, 20, 20)
myNode.LineWidth = 2
myNode.Fill = True
myNode.Tag = "C-" + objindex
If tag <> "" Then myNode.Tag = tag
gObj = myNode
CheckTag(gObj)
gObj.Name = "AJ-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myNode)
Dim myADJ As Adjust = New Adjust(myNode.Name, "Ajuste")
myADJ.GraphicObject = myNode
SimulationObjects.Add(myNode.Name, myADJ)
Case ObjectType.OT_Spec
Dim myNode As New SpecGraphic(mpx, mpy, 20, 20)
myNode.LineWidth = 2
myNode.Fill = True
myNode.Tag = "SP-" + objindex
If tag <> "" Then myNode.Tag = tag
gObj = myNode
CheckTag(gObj)
gObj.Name = "ES-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myNode)
Dim myADJ As Spec = New Spec(myNode.Name, "Especificao")
myADJ.GraphicObject = myNode
SimulationObjects.Add(myNode.Name, myADJ)
Case ObjectType.OT_Recycle
Dim myNode As New RecycleGraphic(mpx, mpy, 20, 20)
myNode.LineWidth = 2
myNode.Fill = True
myNode.Tag = "R-" + objindex
If tag <> "" Then myNode.Tag = tag
gObj = myNode
CheckTag(gObj)
gObj.Name = "REC-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myNode)
Dim myADJ As Recycle = New Recycle(myNode.Name, "Reciclo")
myADJ.GraphicObject = myNode
SimulationObjects.Add(myNode.Name, myADJ)
Case ObjectType.OT_EnergyRecycle
Dim myNode As New EnergyRecycleGraphic(mpx, mpy, 20, 20)
myNode.LineWidth = 2
myNode.Fill = True
myNode.Tag = "ER-" + objindex
If tag <> "" Then myNode.Tag = tag
gObj = myNode
CheckTag(gObj)
gObj.Name = "EREC-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myNode)
Dim myADJ As EnergyRecycle = New EnergyRecycle(myNode.Name, "EnergyRecycle")
myADJ.GraphicObject = myNode
SimulationObjects.Add(myNode.Name, myADJ)
Case ObjectType.NodeIn, ObjectType.Mixer
Dim myNode As New MixerGraphic(mpx, mpy, 20, 20)
myNode.LineWidth = 2
myNode.Fill = True
myNode.Tag = "MIX-" + objindex
If tag <> "" Then myNode.Tag = tag
gObj = myNode
CheckTag(gObj)
gObj.Name = "MIST-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myNode)
Dim myCOMIX As Mixer = New Mixer(myNode.Name, "Misturador")
myCOMIX.GraphicObject = myNode
SimulationObjects.Add(myNode.Name, myCOMIX)
Case ObjectType.NodeOut, ObjectType.Splitter
Dim myNodeo As New SplitterGraphic(mpx, mpy, 20, 20)
myNodeo.LineWidth = 2
myNodeo.Fill = True
myNodeo.Tag = "SPL-" + objindex
If tag <> "" Then myNodeo.Tag = tag
gObj = myNodeo
CheckTag(gObj)
gObj.Name = "DIV-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myNodeo)
'OBJETO DWSIM
Dim myCOSP As UnitOperations.UnitOperations.Splitter = New UnitOperations.UnitOperations.Splitter(myNodeo.Name, "Divisor")
myCOSP.GraphicObject = myNodeo
SimulationObjects.Add(myNodeo.Name, myCOSP)
Case ObjectType.Pump
Dim myPump As New PumpGraphic(mpx, mpy, 25, 25)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myPump.SetSize(New SKSize(40, 40))
End If
myPump.LineWidth = 2
myPump.Fill = True
myPump.Tag = "PUMP-" + objindex
If tag <> "" Then myPump.Tag = tag
gObj = myPump
CheckTag(gObj)
gObj.Name = "BB-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myPump)
'OBJETO DWSIM
Dim myCOSP As Pump = New Pump(myPump.Name, "Bomba")
myCOSP.GraphicObject = myPump
SimulationObjects.Add(myPump.Name, myCOSP)
Case ObjectType.Tank
Dim myTank As New TankGraphic(mpx, mpy, 50, 50)
myTank.LineWidth = 2
myTank.Fill = True
myTank.Tag = "TANK-" + objindex
If tag <> "" Then myTank.Tag = tag
gObj = myTank
CheckTag(gObj)
gObj.Name = "TQ-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myTank)
'OBJETO DWSIM
Dim myCOTK As Tank = New Tank(myTank.Name, "Tanque")
myCOTK.GraphicObject = myTank
SimulationObjects.Add(myTank.Name, myCOTK)
Case ObjectType.Vessel
Dim myVessel As New VesselGraphic(mpx, mpy, 50, 50)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myVessel.SetSize(New SKSize(70, 60))
End If
myVessel.LineWidth = 2
myVessel.Fill = True
myVessel.Tag = "V-" + objindex
If tag <> "" Then myVessel.Tag = tag
gObj = myVessel
CheckTag(gObj)
gObj.Name = "SEP-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myVessel)
'OBJETO DWSIM
Dim myCOVESSEL As Vessel = New Vessel(myVessel.Name, "VasoSeparadorGL")
myCOVESSEL.GraphicObject = myVessel
SimulationObjects.Add(myVessel.Name, myCOVESSEL)
Case ObjectType.MaterialStream
Dim myMStr As New MaterialStreamGraphic(mpx, mpy, 20, 20)
myMStr.LineWidth = 2
myMStr.Fill = True
myMStr.Tag = objindex
If tag <> "" Then myMStr.Tag = tag
gObj = myMStr
CheckTag(gObj)
gObj.Name = "MAT-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myMStr)
'OBJETO DWSIM
Dim myCOMS As Thermodynamics.Streams.MaterialStream = New Thermodynamics.Streams.MaterialStream(myMStr.Name, "CorrentedeMatria", Me, Nothing)
myCOMS.GraphicObject = myMStr
AddCompoundsToMaterialStream(myCOMS)
SimulationObjects.Add(myCOMS.Name, myCOMS)
Case ObjectType.EnergyStream
Dim myMStr As New EnergyStreamGraphic(mpx, mpy, 20, 20)
myMStr.LineWidth = 2
myMStr.Fill = True
myMStr.Tag = "E" + objindex
If tag <> "" Then myMStr.Tag = tag
gObj = myMStr
CheckTag(gObj)
gObj.Name = "EN-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myMStr)
'OBJETO DWSIM
Dim myCOES As EnergyStream = New EnergyStream(myMStr.Name, "CorrentedeEnergia")
myCOES.GraphicObject = myMStr
SimulationObjects.Add(myCOES.Name, myCOES)
Case ObjectType.Compressor
Dim myComp As New CompressorGraphic(mpx, mpy, 25, 25)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myComp.SetSize(New SKSize(50, 50))
End If
myComp.LineWidth = 2
myComp.Fill = True
myComp.Tag = "C-" + objindex
If tag <> "" Then myComp.Tag = tag
gObj = myComp
CheckTag(gObj)
gObj.Name = "COMP-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myComp)
'OBJETO DWSIM
Dim myCOCP As Compressor = New Compressor(myComp.Name, "CompressorAdiabtico")
myCOCP.GraphicObject = myComp
SimulationObjects.Add(myComp.Name, myCOCP)
Case ObjectType.Expander
Dim myComp As New TurbineGraphic(mpx, mpy, 25, 25)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myComp.SetSize(New SKSize(50, 50))
End If
myComp.LineWidth = 2
myComp.Fill = True
myComp.Tag = "X-" + objindex
If tag <> "" Then myComp.Tag = tag
gObj = myComp
gObj.Name = "TURB-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myComp)
'OBJETO DWSIM
Dim myCOCP As Expander = New Expander(myComp.Name, "TurbinaAdiabtica")
myCOCP.GraphicObject = myComp
SimulationObjects.Add(myComp.Name, myCOCP)
Case ObjectType.Cooler
Dim myCool As New CoolerGraphic(mpx, mpy, 25, 25)
myCool.LineWidth = 2
myCool.Fill = True
myCool.Tag = "CL-" + objindex
If tag <> "" Then myCool.Tag = tag
gObj = myCool
CheckTag(gObj)
gObj.Name = "RESF-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myCool)
'OBJETO DWSIM
Dim myCOCL As Cooler = New Cooler(myCool.Name, "Resfriador")
myCOCL.GraphicObject = myCool
SimulationObjects.Add(myCool.Name, myCOCL)
Case ObjectType.Heater
Dim myHeat As New HeaterGraphic(mpx, mpy, 25, 25)
myHeat.LineWidth = 2
myHeat.Fill = True
myHeat.Tag = "HT-" + objindex
If tag <> "" Then myHeat.Tag = tag
gObj = myHeat
CheckTag(gObj)
gObj.Name = "AQ-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myHeat)
'OBJETO DWSIM
Dim myCOCL As Heater = New Heater(myHeat.Name, "Aquecedor")
myCOCL.GraphicObject = myHeat
SimulationObjects.Add(myHeat.Name, myCOCL)
Case ObjectType.Pipe
Dim myPipe As New PipeSegmentGraphic(mpx, mpy, 50, 10)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myPipe.SetSize(New SKSize(50, 20))
End If
myPipe.LineWidth = 2
myPipe.Fill = True
myPipe.Tag = "PIPE-" + objindex
If tag <> "" Then myPipe.Tag = tag
gObj = myPipe
CheckTag(gObj)
gObj.Name = "TUB-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myPipe)
'OBJETO DWSIM
Dim myCOPIPE As Pipe = New Pipe(myPipe.Name, "Tubulao")
myCOPIPE.GraphicObject = myPipe
SimulationObjects.Add(myPipe.Name, myCOPIPE)
Case ObjectType.Valve
Dim myValve As New ValveGraphic(mpx, mpy, 20, 20)
Dim myPipe As New PipeSegmentGraphic(mpx, mpy, 50, 10)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myValve.SetSize(New SKSize(30, 30))
End If
myValve.LineWidth = 2
myValve.Fill = True
myValve.Tag = "VALVE-" + objindex
If tag <> "" Then myValve.Tag = tag
gObj = myValve
CheckTag(gObj)
gObj.Name = "VALV-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myValve)
'OBJETO DWSIM
Dim myCOVALVE As Valve = New Valve(myValve.Name, "Vlvula")
myCOVALVE.GraphicObject = myValve
SimulationObjects.Add(myValve.Name, myCOVALVE)
Case ObjectType.RCT_Conversion
Dim myRconv As New ConversionReactorGraphic(mpx, mpy, 50, 50)
myRconv.LineWidth = 2
myRconv.Fill = True
myRconv.Tag = "RCONV-" + objindex
If tag <> "" Then myRconv.Tag = tag
gObj = myRconv
gObj.Name = "RC-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myRconv)
'OBJETO DWSIM
Dim myCORCONV As Reactor_Conversion = New Reactor_Conversion(myRconv.Name, "ReatorConversao")
myCORCONV.GraphicObject = myRconv
SimulationObjects.Add(myRconv.Name, myCORCONV)
Case ObjectType.RCT_Equilibrium
Dim myReq As New EquilibriumReactorGraphic(mpx, mpy, 50, 50)
myReq.LineWidth = 2
myReq.Fill = True
myReq.Tag = "REQ-" + objindex
If tag <> "" Then myReq.Tag = tag
gObj = myReq
CheckTag(gObj)
gObj.Name = "RE-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myReq)
'OBJETO DWSIM
Dim myCOREQ As Reactor_Equilibrium = New Reactor_Equilibrium(myReq.Name, "ReatorEquilibrio")
myCOREQ.GraphicObject = myReq
SimulationObjects.Add(myReq.Name, myCOREQ)
Case ObjectType.RCT_Gibbs
Dim myRgibbs As New GibbsReactorGraphic(mpx, mpy, 50, 50)
myRgibbs.LineWidth = 2
myRgibbs.Fill = True
myRgibbs.Tag = "RGIBBS-" + objindex
If tag <> "" Then myRgibbs.Tag = tag
gObj = myRgibbs
gObj.Name = "RG-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myRgibbs)
'OBJETO DWSIM
Dim myCORGIBBS As Reactor_Gibbs = New Reactor_Gibbs(myRgibbs.Name, "ReatorGibbs")
myCORGIBBS.GraphicObject = myRgibbs
SimulationObjects.Add(myRgibbs.Name, myCORGIBBS)
Case ObjectType.RCT_CSTR
Dim myRcstr As New CSTRGraphic(mpx, mpy, 50, 50)
myRcstr.LineWidth = 2
myRcstr.Fill = True
myRcstr.Tag = "CSTR-" + objindex
If tag <> "" Then myRcstr.Tag = tag
gObj = myRcstr
CheckTag(gObj)
gObj.Name = "CSTR-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myRcstr)
'OBJETO DWSIM
Dim myCORCSTR As Reactor_CSTR = New Reactor_CSTR(myRcstr.Name, "ReatorCSTR")
myCORCSTR.GraphicObject = myRcstr
SimulationObjects.Add(myRcstr.Name, myCORCSTR)
Case ObjectType.RCT_PFR
Dim myRpfr As New PFRGraphic(mpx, mpy, 70, 20)
myRpfr.LineWidth = 2
myRpfr.Fill = True
myRpfr.Tag = "PFR-" + objindex
If tag <> "" Then myRpfr.Tag = tag
gObj = myRpfr
CheckTag(gObj)
gObj.Name = "PFR-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myRpfr)
'OBJETO DWSIM
Dim myCOPFR As Reactor_PFR = New Reactor_PFR(myRpfr.Name, "ReatorPFR")
myCOPFR.GraphicObject = myRpfr
SimulationObjects.Add(myRpfr.Name, myCOPFR)
Case ObjectType.HeatExchanger
Dim myHeatExchanger As New HeatExchangerGraphic(mpx, mpy, 30, 30)
If FlowsheetOptions.FlowsheetColorTheme = 2 Then
myHeatExchanger.SetSize(New SKSize(60, 60))
End If
myHeatExchanger.LineWidth = 2
myHeatExchanger.Fill = True
myHeatExchanger.Tag = "HX-" + objindex
If tag <> "" Then myHeatExchanger.Tag = tag
gObj = myHeatExchanger
CheckTag(gObj)
gObj.Name = "HE-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myHeatExchanger)
'OBJETO DWSIM
Dim myCOHE As HeatExchanger = New HeatExchanger(myHeatExchanger.Name, "HeatExchanger")
myCOHE.GraphicObject = myHeatExchanger
SimulationObjects.Add(myHeatExchanger.Name, myCOHE)
Case ObjectType.ShortcutColumn
Dim mySC As New ShortcutColumnGraphic(mpx, mpy, 144, 180)
mySC.LineWidth = 2
mySC.Fill = True
mySC.Tag = "SCOL-" + objindex
If tag <> "" Then mySC.Tag = tag
gObj = mySC
gObj.Name = "SC-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, mySC)
'OBJETO DWSIM
Dim myCOSC As ShortcutColumn = New ShortcutColumn(mySC.Name, "ShortcutColumn")
myCOSC.GraphicObject = mySC
SimulationObjects.Add(mySC.Name, myCOSC)
Case ObjectType.DistillationColumn
Dim mySC As New RigorousColumnGraphic(mpx, mpy, 144, 180)
mySC.LineWidth = 2
mySC.Fill = True
mySC.Tag = "DCOL-" + objindex
If tag <> "" Then mySC.Tag = tag
gObj = mySC
CheckTag(gObj)
gObj.Name = "DC-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, mySC)
'OBJETO DWSIM
Dim myCOSC As DistillationColumn = New DistillationColumn(mySC.Name, "DistillationColumn", Me)
myCOSC.GraphicObject = mySC
SimulationObjects.Add(mySC.Name, myCOSC)
Case ObjectType.AbsorptionColumn
Dim mySC As New AbsorptionColumnGraphic(mpx, mpy, 144, 180)
mySC.LineWidth = 2
mySC.Fill = True
mySC.Tag = "ABS-" + objindex
If tag <> "" Then mySC.Tag = tag
gObj = mySC
gObj.Name = "ABS-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, mySC)
'OBJETO DWSIM
Dim myCOSC As AbsorptionColumn = New AbsorptionColumn(mySC.Name, "AbsorptionColumn", Me)
myCOSC.GraphicObject = mySC
SimulationObjects.Add(mySC.Name, myCOSC)
Case ObjectType.ComponentSeparator
Dim myCSep As New ComponentSeparatorGraphic(mpx, mpy, 50, 50)
myCSep.LineWidth = 2
myCSep.Fill = True
myCSep.Tag = "CS-" + objindex
If tag <> "" Then myCSep.Tag = tag
gObj = myCSep
CheckTag(gObj)
gObj.Name = "CS-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myCSep)
'OBJETO DWSIM
Dim myCOCSEP As ComponentSeparator = New ComponentSeparator(myCSep.Name, "ComponentSeparator")
myCOCSEP.GraphicObject = myCSep
SimulationObjects.Add(myCSep.Name, myCOCSEP)
Case ObjectType.SolidSeparator
Dim myCSep As New SolidsSeparatorGraphic(mpx, mpy, 50, 50)
myCSep.LineWidth = 2
myCSep.Fill = True
myCSep.Tag = "SS-" + objindex
If tag <> "" Then myCSep.Tag = tag
gObj = myCSep
gObj.Name = "SS-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myCSep)
'OBJETO DWSIM
Dim myCOCSEP As SolidsSeparator = New SolidsSeparator(myCSep.Name, "SolidsSeparator")
myCOCSEP.GraphicObject = myCSep
SimulationObjects.Add(myCSep.Name, myCOCSEP)
Case ObjectType.Filter
Dim myCSep As New FilterGraphic(mpx, mpy, 50, 50)
myCSep.LineWidth = 2
myCSep.Fill = True
myCSep.Tag = "FLT-" + objindex
If tag <> "" Then myCSep.Tag = tag
gObj = myCSep
CheckTag(gObj)
gObj.Name = "FT-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myCSep)
'OBJETO DWSIM
Dim myCOCSEP As Filter = New Filter(myCSep.Name, "Filter")
myCOCSEP.GraphicObject = myCSep
SimulationObjects.Add(myCSep.Name, myCOCSEP)
Case ObjectType.OrificePlate
Dim myOPL As New OrificePlateGraphic(mpx, mpy, 25, 25)
myOPL.LineWidth = 2
myOPL.Fill = True
myOPL.Tag = "OP-" + objindex
If tag <> "" Then myOPL.Tag = tag
gObj = myOPL
CheckTag(gObj)
gObj.Name = "OP-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myOPL)
'OBJETO DWSIM
Dim myCOOPL As OrificePlate = New OrificePlate(myOPL.Name, "OrificePlate")
myCOOPL.GraphicObject = myOPL
SimulationObjects.Add(myOPL.Name, myCOOPL)
Case ObjectType.CustomUO
Dim myCUO As New ScriptGraphic(mpx, mpy, 25, 25)
myCUO.LineWidth = 2
myCUO.Fill = True
myCUO.Tag = "CUSTOM-" + objindex
If tag <> "" Then myCUO.Tag = tag
gObj = myCUO
CheckTag(gObj)
gObj.Name = "UO-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myCUO)
'OBJETO DWSIM
Dim myCOCUO As CustomUO = New CustomUO(myCUO.Name, "CustomUnitOp")
myCOCUO.GraphicObject = myCUO
SimulationObjects.Add(myCUO.Name, myCOCUO)
Case ObjectType.ExcelUO
Dim myEUO As New SpreadsheetGraphic(mpx, mpy, 25, 25)
myEUO.LineWidth = 2
myEUO.Fill = True
myEUO.Tag = "SHEET-" + objindex
If tag <> "" Then myEUO.Tag = tag
gObj = myEUO
CheckTag(gObj)
gObj.Name = "EXL-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myEUO)
'OBJETO DWSIM
Dim myCOEUO As ExcelUO = New ExcelUO(myEUO.Name, "ExcelUnitOp")
myCOEUO.GraphicObject = myEUO
SimulationObjects.Add(myEUO.Name, myCOEUO)
Case ObjectType.FlowsheetUO
Dim myEUO As New FlowsheetGraphic(mpx, mpy, 25, 25)
myEUO.LineWidth = 2
myEUO.Fill = True
myEUO.Tag = "FS-" + objindex
If tag <> "" Then myEUO.Tag = tag
gObj = myEUO
CheckTag(gObj)
gObj.Name = "FS-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myEUO)
'OBJETO DWSIM
Dim myCOEUO As UnitOperations.UnitOperations.Flowsheet = New UnitOperations.UnitOperations.Flowsheet(myEUO.Name, "FlowsheetUnitOp")
myCOEUO.GraphicObject = myEUO
SimulationObjects.Add(myEUO.Name, myCOEUO)
Case ObjectType.CapeOpenUO
Dim myCUO As New CAPEOPENGraphic(mpx, mpy, 40, 40)
myCUO.LineWidth = 2
myCUO.Fill = True
myCUO.Tag = "CO-" + objindex
If tag <> "" Then myCUO.Tag = tag
gObj = myCUO
CheckTag(gObj)
gObj.Name = "COUO-" & Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
GraphicObjects.Add(gObj.Name, myCUO)
Dim myCOCUO As CapeOpenUO = New CapeOpenUO(myCUO.Name, "CapeOpenUnitOperation", gObj, False)
myCOCUO.GraphicObject = myCUO
SimulationObjects.Add(myCUO.Name, myCOCUO)
Case ObjectType.RCT_GibbsReaktoro
Dim fsobj = New Reactor_ReaktoroGibbs()
Dim grobj As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
grobj.Tag = "RGIBBSR-" + objindex
If tag <> "" Then grobj.Tag = tag
gObj = grobj
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(fsobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, grobj)
DirectCast(fsobj, Interfaces.ISimulationObject).GraphicObject = grobj
grobj.CreateConnectors(0, 0)
SimulationObjects.Add(grobj.Name, fsobj)
Case ObjectType.WindTurbine
Dim fsobj = New WindTurbine()
Dim grobj As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
grobj.Tag = "WT-" + objindex
If tag <> "" Then grobj.Tag = tag
gObj = grobj
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(fsobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, grobj)
DirectCast(fsobj, Interfaces.ISimulationObject).GraphicObject = grobj
grobj.CreateConnectors(0, 0)
SimulationObjects.Add(grobj.Name, fsobj)
Case ObjectType.HydroelectricTurbine
Dim fsobj = New HydroelectricTurbine()
Dim grobj As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
grobj.Tag = "HYT-" + objindex
If tag <> "" Then grobj.Tag = tag
gObj = grobj
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(fsobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, grobj)
DirectCast(fsobj, Interfaces.ISimulationObject).GraphicObject = grobj
grobj.CreateConnectors(0, 0)
SimulationObjects.Add(grobj.Name, fsobj)
Case ObjectType.PEMFuelCell
Dim fsobj = New PEMFC_Amphlett()
Dim grobj As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
grobj.Tag = "PEMFC-" + objindex
If tag <> "" Then grobj.Tag = tag
gObj = grobj
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(fsobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, grobj)
DirectCast(fsobj, Interfaces.ISimulationObject).GraphicObject = grobj
grobj.CreateConnectors(0, 0)
SimulationObjects.Add(grobj.Name, fsobj)
Case ObjectType.SolarPanel
Dim fsobj = New SolarPanel()
Dim grobj As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
grobj.Tag = "SP-" + objindex
If tag <> "" Then grobj.Tag = tag
gObj = grobj
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(fsobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, grobj)
DirectCast(fsobj, Interfaces.ISimulationObject).GraphicObject = grobj
grobj.CreateConnectors(0, 0)
SimulationObjects.Add(grobj.Name, fsobj)
Case ObjectType.WaterElectrolyzer
Dim fsobj = New WaterElectrolyzer()
Dim grobj As New ExternalUnitOperationGraphic(mpx, mpy, 40, 40)
grobj.Tag = "WELEC-" + objindex
If tag <> "" Then grobj.Tag = tag
gObj = grobj
CheckTag(gObj)
gObj.Name = Guid.NewGuid.ToString
If id <> "" Then gObj.Name = id
DirectCast(fsobj, Interfaces.ISimulationObject).Name = gObj.Name
GraphicObjects.Add(gObj.Name, grobj)
DirectCast(fsobj, Interfaces.ISimulationObject).GraphicObject = grobj
grobj.CreateConnectors(0, 0)
SimulationObjects.Add(grobj.Name, fsobj)
End Select
If Not gObj Is Nothing Then
gObj.Flowsheet = Me
gObj.PositionConnectors()
gObj.Owner = SimulationObjects(gObj.Name)
SimulationObjects(gObj.Name).SetFlowsheet(Me)
FlowsheetSurface.AddObject(gObj)
End If
If CreateConnected Then
Try
If FlowsheetOptions.AddObjectsWithStreams = 1 Then
AddConnectedObjects(SimulationObjects(gObj.Name), 1)
UpdateInterface()
End If
If FlowsheetOptions.AddObjectsWithStreams = 2 Then
AddConnectedObjects(SimulationObjects(gObj.Name), 2)
AddConnectedObjects(SimulationObjects(gObj.Name), 1)
UpdateInterface()
End If
Catch ex As Exception
End Try
End If
Return gObj.Name
End Function
Public Sub AddConnectedObjects(obj As Interfaces.ISimulationObject, scheme As Integer)
Dim x = obj.GraphicObject.X
Dim y = obj.GraphicObject.Y
Dim w = obj.GraphicObject.Width
Dim h = obj.GraphicObject.Height
Dim gobj = obj.GraphicObject
Dim mstrs = FlowsheetSurface.FindObjectsAtBounds(x - 250, y - 250, 500, 500).Where(Function(o) o.ObjectType = ObjectType.MaterialStream).ToList()
Dim mstrsI = FlowsheetSurface.FindObjectsAtBounds(x - 250, y - 250, 250, 500).Where(Function(o) o.ObjectType = ObjectType.MaterialStream And Not o.OutputConnectors(0).IsAttached).ToList()
Dim mstrsO = FlowsheetSurface.FindObjectsAtBounds(x + w, y - 250, 250, 500).Where(Function(o) o.ObjectType = ObjectType.MaterialStream And Not o.InputConnectors(0).IsAttached).ToList()
Dim estrs = FlowsheetSurface.FindObjectsAtBounds(x - 250, y - 250, 500, 500).Where(Function(o) o.ObjectType = ObjectType.EnergyStream).ToList()
Dim estrsI = FlowsheetSurface.FindObjectsAtBounds(x - 250, y - 250, 250, 500).Where(Function(o) o.ObjectType = ObjectType.EnergyStream And Not o.OutputConnectors(0).IsAttached).ToList()
Dim estrsO = FlowsheetSurface.FindObjectsAtBounds(x + w, y - 250, 250, 500).Where(Function(o) o.ObjectType = ObjectType.EnergyStream And Not o.InputConnectors(0).IsAttached).ToList()
Dim uosI = FlowsheetSurface.FindObjectsAtBounds(x - 250, y - 250, 250, 500).Where(Function(o) o.ObjectType <> ObjectType.MaterialStream And
o.ObjectType <> ObjectType.EnergyStream).ToList()
Dim uosO = FlowsheetSurface.FindObjectsAtBounds(x + w, y - 250, 250, 500).Where(Function(o) o.ObjectType <> ObjectType.MaterialStream And
o.ObjectType <> ObjectType.EnergyStream).ToList()
mstrs = mstrs.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
mstrsI = mstrsI.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
mstrsO = mstrsO.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
estrs = estrs.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
estrsI = estrsI.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
estrsO = estrsO.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
uosI = uosI.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
uosO = uosO.OrderBy(Function(o) Math.Abs(gobj.X - o.X) + Math.Abs(gobj.Y - o.Y)).ToList()
Select Case obj.GraphicObject.ObjectType
Case ObjectType.MaterialStream
If scheme = 2 And uosI.Count > 0 Then
Try : ConnectObject(uosI(0), gobj) : Catch : End Try
End If
If scheme = 2 And uosO.Count > 0 Then
Try : ConnectObject(gobj, uosO(0)) : Catch : End Try
End If
Case ObjectType.EnergyStream
If scheme = 2 And uosI.Count > 0 Then
Try : ConnectObject(uosI(0), gobj) : Catch : End Try
End If
If scheme = 2 And uosO.Count > 0 Then
Try : ConnectObject(gobj, uosO(0)) : Catch : End Try
End If
Case ObjectType.AbsorptionColumn
If scheme = 2 And mstrs.Count > 0 Then
For i = 0 To mstrs.Count
If i > 3 Then Exit For
If i < 2 Then
Try : ConnectObjects(mstrs(i), gobj, 0, i) : Catch : End Try
Else
Try : ConnectObjects(gobj, mstrs(i - 2), i - 2, 0) : Catch : End Try
End If
Next
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y + h - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Dim m3 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h - 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(SimulationObjects(m1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 0, 0) : Catch : DeleteObject(m2, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m3).GraphicObject, 1, 0) : Catch : DeleteObject(m3, False) : End Try
End If
Case ObjectType.Compressor
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then
Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
End If
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y,,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
If scheme = 2 And estrsI.Count > 0 Then
If estrsI.Count > 0 Then
Try : ConnectObjects(estrsI(0), gobj, 0, 0) : Catch : End Try
End If
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x - 60, y + h + 60, ,,, False)
Try : ConnectObjects(SimulationObjects(e1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.DistillationColumn
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Try : ConnectObjects(gobj, mstrsO(1), 1, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsI.Count > 0 Then Try : ConnectObjects(estrsI(0), gobj, 0, 10) : Catch : End Try
If estrsO.Count > 0 Then Try : ConnectObjects(gobj, estrsO(0), 10, 0) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + 40, ,,, False)
Dim e2 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + h - 40, ,,, False)
Try : ConnectObjects(SimulationObjects(e2).GraphicObject, gobj, 0, 10) : Catch : DeleteObject(e1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(e1).GraphicObject, 10, 0) : Catch : DeleteObject(e2, False) : End Try
End If
Case ObjectType.Expander, ObjectType.Cooler
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsO.Count > 0 Then ConnectObjects(gobj, estrsO(0), 0, 0)
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + h + 60, ,,, False)
Try : ConnectObjects(gobj, SimulationObjects(e1).GraphicObject, 0, 0) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.Heater
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsI.Count > 0 Then Try : ConnectObjects(estrsI(0), gobj, 0, 1) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x - 60, y + h + 60, ,,, False)
Try : ConnectObjects(SimulationObjects(e1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.HeatExchanger
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then
Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
Try : ConnectObjects(mstrsI(1), gobj, 0, 1) : Catch : End Try
End If
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Try : ConnectObjects(gobj, mstrsO(1), 1, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y - 40, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y + 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m3 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(SimulationObjects(m1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 0, 0) : Catch : DeleteObject(m2, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m3).GraphicObject, 1, 0) : Catch : DeleteObject(m3, False) : End Try
End If
Case ObjectType.NodeIn
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then
Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
Try : ConnectObjects(mstrsI(1), gobj, 0, 1) : Catch : End Try
Try : ConnectObjects(mstrsI(2), gobj, 0, 2) : Catch : End Try
End If
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y + 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(SimulationObjects(m1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 0, 0) : Catch : DeleteObject(m2, False) : End Try
End If
Case ObjectType.NodeOut
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then
Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
End If
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Try : ConnectObjects(gobj, mstrsO(1), 1, 0) : Catch : End Try
Try : ConnectObjects(gobj, mstrsO(2), 2, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
Case ObjectType.Pipe
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsO.Count > 0 Then Try : ConnectObjects(gobj, estrsO(0), 0, 0) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + h + 60, ,,, False)
Try : ConnectObjects(gobj, SimulationObjects(e1).GraphicObject, 0, 0) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.Pump
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsI.Count > 0 Then Try : ConnectObjects(estrsI(0), gobj, 0, 1) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x - 60, y + h + 60, ,,, False)
Try : ConnectObjects(SimulationObjects(e1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.RCT_Conversion
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsO.Count > 0 Then ConnectObjects(gobj, estrsO(0), 2, 0)
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + h + 60, ,,, False)
Try : ConnectObjects(gobj, SimulationObjects(e1).GraphicObject, 2, 0) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.RCT_CSTR, ObjectType.RCT_PFR
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsI.Count > 0 Then Try : ConnectObjects(estrsI(0), gobj, 0, 1) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x - 60, y + h + 60, ,,, False)
Try : ConnectObjects(SimulationObjects(e1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.RCT_Equilibrium, ObjectType.RCT_Gibbs
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsI.Count > 0 Then Try : ConnectObjects(estrsI(0), gobj, 0, 1) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x - 60, y + h + 60, ,,, False)
Try : ConnectObjects(SimulationObjects(e1).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.ComponentSeparator
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsO.Count > 0 Then Try : ConnectObjects(gobj, estrsO(0), 0, 0) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x + 60, y + h + 60, ,,, False)
Try : ConnectObjects(gobj, SimulationObjects(e1).GraphicObject, 0, 0) : Catch : DeleteObject(e1, False) : End Try
End If
Case ObjectType.ShortcutColumn
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Try : ConnectObjects(gobj, mstrsO(1), 1, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
If scheme = 2 And estrs.Count > 0 Then
If estrsI.Count > 0 Then Try : ConnectObjects(estrsI(0), gobj, 0, 1) : Catch : End Try
If estrsO.Count > 0 Then Try : ConnectObjects(gobj, estrsO(0), 0, 0) : Catch : End Try
Else
Dim e1 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + 40, ,,, False)
Dim e2 = AddObjectToSurface(ObjectType.EnergyStream, x + w + 60, y + h - 40, ,,, False)
Try : ConnectObjects(SimulationObjects(e2).GraphicObject, gobj, 0, 1) : Catch : DeleteObject(e1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(e1).GraphicObject, 0, 0) : Catch : DeleteObject(e2, False) : End Try
End If
Case ObjectType.Tank, ObjectType.Valve, ObjectType.OrificePlate, ObjectType.OT_Recycle
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
End If
Case ObjectType.Vessel, ObjectType.SolidSeparator, ObjectType.Filter
If scheme = 2 And mstrs.Count > 0 Then
If mstrsI.Count > 0 Then Try : ConnectObjects(mstrsI(0), gobj, 0, 0) : Catch : End Try
If mstrsO.Count > 0 Then
Try : ConnectObjects(gobj, mstrsO(0), 0, 0) : Catch : End Try
Try : ConnectObjects(gobj, mstrsO(1), 1, 0) : Catch : End Try
End If
Else
Dim m0 = AddObjectToSurface(ObjectType.MaterialStream, x - 60, y, ,,, False)
Dim m1 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y - 40, ,,, False)
Dim m2 = AddObjectToSurface(ObjectType.MaterialStream, x + w + 60, y + h + 40, ,,, False)
Try : ConnectObjects(SimulationObjects(m0).GraphicObject, gobj, 0, 0) : Catch : DeleteObject(m0, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m1).GraphicObject, 0, 0) : Catch : DeleteObject(m1, False) : End Try
Try : ConnectObjects(gobj, SimulationObjects(m2).GraphicObject, 1, 0) : Catch : DeleteObject(m2, False) : End Try
End If
End Select
End Sub
Public Sub ConnectObject(ByRef gObjFrom As GraphicObject, ByRef gObjTo As GraphicObject, Optional ByVal fidx As Integer = -1, Optional ByVal tidx As Integer = -1)
ConnectObjects(gObjFrom, gObjTo, fidx, tidx)
End Sub
Public Sub DeleteObject(ByVal tag As String, Optional ByVal confirmation As Boolean = True)
Dim gobj As GraphicObject = GetFlowsheetGraphicObject(tag)
If Not gobj Is Nothing Then
FlowsheetSurface.SelectedObject = gobj
DeleteSelectedObject(Me, New EventArgs(), gobj, confirmation)
ElseIf GraphicObjects.ContainsKey(tag) Then
gobj = GraphicObjects(tag)
FlowsheetSurface.SelectedObject = gobj
DeleteSelectedObject(Me, New EventArgs(), gobj, confirmation)
End If
End Sub
Public Sub CheckTag(obj As IGraphicObject)
While GetFlowsheetSimulationObject(obj.Tag) IsNot Nothing
obj.Tag = Regex.Replace(obj.Tag, "\d+", Function(m) (Integer.Parse(m.Value) + 1).ToString(New String("0", m.Value.Length)))
End While
End Sub
Public Sub LoadFromMXML(xdoc As XDocument)
Parallel.ForEach(xdoc.Descendants, Sub(xel1)
SharedClasses.Utility.UpdateElementForMobileXMLLoading_CrossPlatformUI(xel1)
End Sub)
LoadFromXML(xdoc)
End Sub
Public Sub LoadFromXML(xdoc As XDocument) Implements IFlowsheet.LoadFromXML
Dim ci As CultureInfo = CultureInfo.InvariantCulture
Dim excs As New Concurrent.ConcurrentBag(Of Exception)
'check version
Dim sver = New Version("1.0.0.0")
Try
sver = New Version(xdoc.Element("DWSIM_Simulation_Data").Element("GeneralInfo").Element("BuildVersion").Value)
Catch ex As Exception
End Try
If sver < New Version("5.0.0.0") Then
For Each xel1 In xdoc.Descendants
Utility.UpdateElement(xel1)
Next
End If
'check saved from Classic UI
Dim savedfromclui As Boolean = True
Try
savedfromclui = Boolean.Parse(xdoc.Element("DWSIM_Simulation_Data").Element("GeneralInfo").Element("SavedFromClassicUI").Value)
Catch ex As Exception
End Try
If savedfromclui Then
Try
For Each xel1 In xdoc.Descendants
Utility.UpdateElementForNewUI(xel1)
Next
Catch ex As Exception
End Try
End If
Dim data As List(Of XElement) = xdoc.Element("DWSIM_Simulation_Data").Element("Settings").Elements.ToList
Try
Options.LoadData(data)
FlowsheetSurface.DrawFloatingTable = Options.DisplayFloatingPropertyTables
FlowsheetSurface.DrawPropertyList = Options.DisplayCornerPropertyList
If Not AvailableSystemsOfUnits.Contains(Options.SelectedUnitSystem1) Then
AvailableSystemsOfUnits.Add(Options.SelectedUnitSystem1)
End If
If sver < New Version("6.3.0.0") Then
Options.SkipEquilibriumCalculationOnDefinedStreams = False
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Settings", ex))
End Try
If xdoc.Element("DWSIM_Simulation_Data").Element("DynamicProperties") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicProperties").Elements.ToList
Try
ExtraProperties = New ExpandoObject
If Not data Is Nothing Then
For Each xel As XElement In data
Try
Dim propname = xel.Element("Name").Value
Dim proptype = xel.Element("PropertyType").Value
Dim assembly1 As Assembly = Nothing
For Each assembly In AppDomain.CurrentDomain.GetAssemblies()
If proptype.Contains(assembly.GetName().Name) Then
assembly1 = assembly
Exit For
End If
Next
If assembly1 IsNot Nothing Then
Dim ptype As Type = assembly1.GetType(proptype)
Dim propval = Newtonsoft.Json.JsonConvert.DeserializeObject(xel.Element("Data").Value, ptype)
DirectCast(ExtraProperties, IDictionary(Of String, Object))(propname) = propval
End If
Catch ex As Exception
End Try
Next
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Dynamic Properties", ex))
End Try
End If
data = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects").Elements.ToList
AddGraphicObjects(data, excs)
data = xdoc.Element("DWSIM_Simulation_Data").Element("Compounds").Elements.ToList
For Each xel As XElement In data
Dim obj As New ConstantProperties
obj.Name = xel.Element("Name").Value
If Not AvailableCompounds.ContainsKey(obj.Name) Then AvailableCompounds.Add(obj.Name, obj)
Options.SelectedComponents.Add(obj.Name, obj)
Next
Try
For Each xel In data
Options.SelectedComponents(xel.Element("Name").Value).LoadData(xel.Elements.ToList)
Next
Catch ex As Exception
excs.Add(New Exception("Error Loading Compound Information", ex))
End Try
data = xdoc.Element("DWSIM_Simulation_Data").Element("PropertyPackages").Elements.ToList
For Each xel As XElement In data
Try
xel.Element("Type").Value = xel.Element("Type").Value.Replace("PortableDTL.DTL.SimulationObjects", "DWSIM.Thermodynamics")
xel.Element("Type").Value = xel.Element("Type").Value.Replace("DWSIM.DWSIM.SimulationObjects", "DWSIM.Thermodynamics")
Dim obj As PropertyPackage = Nothing
If xel.Element("Type").Value.Contains("ThermoC") Then
Dim thermockey As String = "ThermoC Bridge"
If AvailablePropertyPackages.ContainsKey(thermockey) Then
obj = AvailablePropertyPackages(thermockey).ReturnInstance(xel.Element("Type").Value)
Else
Throw New Exception("The ThermoC bridge library was not found. Please download and install it in order to run this simulation.")
End If
Else
Dim ppkey As String = xel.Element("ComponentName").Value
If ppkey = "" Then
obj = CType(New RaoultPropertyPackage().ReturnInstance(xel.Element("Type").Value), PropertyPackage)
Else
Dim ptype = xel.Element("Type").Value
If ppkey.Contains("1978") And ptype.Contains("PengRobinsonPropertyPackage") Then
ptype = ptype.Replace("PengRobinson", "PengRobinson1978")
End If
If ppkey.Contains("Seawater") Then ppkey = "Seawater IAPWS-08"
If AvailablePropertyPackages.ContainsKey(ppkey) Then
obj = AvailablePropertyPackages(ppkey).ReturnInstance(ptype)
Else
Throw New Exception("The " & ppkey & " Property Package library was not found. Please download and install it in order to run this simulation.")
End If
End If
End If
obj.LoadData(xel.Elements.ToList)
Dim newID As String = Guid.NewGuid.ToString
If Options.PropertyPackages.ContainsKey(obj.UniqueID) Then obj.UniqueID = newID
obj.Flowsheet = Me
Options.PropertyPackages.Add(obj.UniqueID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Property Package Information", ex))
End Try
Next
data = xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects").Elements.ToList
Dim objlist As New Concurrent.ConcurrentBag(Of ISimulationObject)
For Each xel In data
Try
Dim id As String = xel.<Name>.Value
Dim obj As ISimulationObject = Nothing
If xel.Element("Type").Value.Contains("Streams.MaterialStream") Then
obj = New MaterialStream()
Else
Dim uokey As String = xel.Element("ComponentDescription").Value
If ExternalUnitOperations.ContainsKey(uokey) Then
obj = ExternalUnitOperations(uokey).ReturnInstance(xel.Element("Type").Value)
Else
obj = UnitOperations.Resolver.ReturnInstance(xel.Element("Type").Value)
End If
End If
Dim gobj As IGraphicObject = (From go As IGraphicObject In
FlowsheetSurface.DrawingObjects Where go.Name = id).SingleOrDefault
obj.GraphicObject = gobj
gobj.Owner = obj
obj.SetFlowsheet(Me)
If Not gobj Is Nothing Then
DirectCast(obj, ICustomXMLSerialization).LoadData(xel.Elements.ToList)
If TypeOf obj Is Streams.MaterialStream Then
For Each phase As BaseClasses.Phase In DirectCast(obj, Streams.MaterialStream).Phases.Values
For Each c As ConstantProperties In Options.SelectedComponents.Values
phase.Compounds(c.Name).ConstantProperties = c
Next
Next
ElseIf TypeOf obj Is CapeOpenUO Then
If DirectCast(obj, CapeOpenUO)._seluo.Name.ToLower.Contains("chemsep") Then
DirectCast(gobj, CAPEOPENGraphic).ChemSep = True
If gobj.Height = 40 And gobj.Width = 40 Then
gobj.Width = 144
gobj.Height = 180
End If
End If
ElseIf TypeOf obj Is Input Then
GraphicObjectControlPanelModeEditors.SetInputDelegate(gobj, obj)
ElseIf TypeOf obj Is PIDController Then
GraphicObjectControlPanelModeEditors.SetPIDDelegate(gobj, obj)
End If
End If
objlist.Add(obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Unit Operation Information", ex))
End Try
Next
AddSimulationObjects(objlist, excs)
data = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects").Elements.ToList
AddTables(data, excs)
data = xdoc.Element("DWSIM_Simulation_Data").Element("ReactionSets").Elements.ToList
Options.ReactionSets.Clear()
For Each xel As XElement In data
Try
Dim obj As New ReactionSet()
obj.LoadData(xel.Elements.ToList)
Options.ReactionSets.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Reaction Set Information", ex))
End Try
Next
data = xdoc.Element("DWSIM_Simulation_Data").Element("Reactions").Elements.ToList
For Each xel As XElement In data
Try
Dim obj As New Reaction()
obj.LoadData(xel.Elements.ToList)
Options.Reactions.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Reaction Information", ex))
End Try
Next
If xdoc.Element("DWSIM_Simulation_Data").Element("StoredSolutions") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("StoredSolutions").Elements.ToList
StoredSolutions.Clear()
For Each xel As XElement In data
Try
StoredSolutions.Add(xel.@ID, xel.Elements.ToList())
Catch ex As Exception
End Try
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("DynamicsManager") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicsManager").Elements.ToList
Try
DirectCast(DynamicsManager, ICustomXMLSerialization).LoadData(data)
Catch ex As Exception
excs.Add(New Exception("Error Loading Dynamics Manager Information", ex))
End Try
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("OptimizationCases") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("OptimizationCases").Elements.ToList
For Each xel As XElement In data
Try
Dim obj As New Optimization.OptimizationCase
obj.LoadData(xel.Elements.ToList)
OptimizationCollection.Add(obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Optimization Case Information", ex))
End Try
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("SensitivityAnalysis") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("SensitivityAnalysis").Elements.ToList
For Each xel As XElement In data
Try
Dim obj As New Optimization.SensitivityAnalysisCase
obj.LoadData(xel.Elements.ToList)
SensAnalysisCollection.Add(obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Sensitivity Analysis Case Information", ex))
End Try
Next
End If
Scripts = New Dictionary(Of String, Interfaces.IScript)
If xdoc.Element("DWSIM_Simulation_Data").Element("ScriptItems") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("ScriptItems").Elements.ToList
Dim i As Integer = 0
For Each xel As XElement In data
Try
Dim obj As New Script()
obj.LoadData(xel.Elements.ToList)
Scripts.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Script Item Information", ex))
End Try
i += 1
Next
End If
Charts = New Dictionary(Of String, Interfaces.IChart)
If xdoc.Element("DWSIM_Simulation_Data").Element("ChartItems") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("ChartItems").Elements.ToList
Dim i As Integer = 0
For Each xel As XElement In data
Try
Dim obj As New SharedClasses.Charts.Chart()
obj.LoadData(xel.Elements.ToList)
Charts.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Chart Item Information", ex))
End Try
i += 1
Next
End If
ParticleSizeDistributions = New List(Of ISolidParticleSizeDistribution)
If xdoc.Element("DWSIM_Simulation_Data").Element("ParticleSizeDistributions") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("ParticleSizeDistributions").Elements.ToList
Dim i As Integer = 0
For Each xel As XElement In data
Try
Dim obj As New SharedClassesCSharp.Solids.SolidParticleSizeDistribution()
obj.LoadData(xel.Elements.ToList)
ParticleSizeDistributions.Add(obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading PSD Item Information", ex))
End Try
i += 1
Next
End If
Results = New SharedClasses.DWSIM.Flowsheet.FlowsheetResults
If xdoc.Element("DWSIM_Simulation_Data").Element("Results") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("Results").Elements.ToList
DirectCast(Results, ICustomXMLSerialization).LoadData(data)
End If
GHGEmissionCompositions = New Dictionary(Of String, IGHGComposition)()
If xdoc.Element("DWSIM_Simulation_Data").Element("GHGCompositions") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("GHGCompositions").Elements.ToList
For Each xel As XElement In data
Try
Dim obj As New GHGEmissionComposition()
obj.LoadData(xel.Elements.ToList)
GHGEmissionCompositions.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading GHG Composition Item Information", ex))
End Try
Next
End If
If LoadSpreadsheetData IsNot Nothing Then LoadSpreadsheetData.Invoke(xdoc)
ProcessScripts(Enums.Scripts.EventType.SimulationOpened, Enums.Scripts.ObjectType.Simulation, "")
If excs.Count > 0 Then
If Settings.AutomationMode Then
'throw errors
Throw New AggregateException(excs)
Else
ShowMessage("Some errors where found while parsing the XML file. The simulation might not work as expected. Please read the subsequent messages for more details.", IFlowsheet.MessageType.GeneralError)
For Each ex As Exception In excs
ShowMessage(ex.Message.ToString & ": " & ex.InnerException.ToString, IFlowsheet.MessageType.GeneralError)
Next
End If
Else
ShowMessage("Data loaded successfully.", IFlowsheet.MessageType.Information)
End If
End Sub
Public Function SaveToMXML() As XDocument
Dim xdoc = SaveToXML()
Parallel.ForEach(xdoc.Descendants, Sub(xel1)
Try
SharedClasses.Utility.UpdateElementForMobileXMLSaving_CrossPlatformUI(xel1)
Catch ex As Exception
End Try
End Sub)
Return xdoc
End Function
Public Function SaveToXML() As XDocument Implements IFlowsheet.SaveToXML
Dim xdoc As New XDocument()
Dim xel As XElement
Dim ci As CultureInfo = CultureInfo.InvariantCulture
xdoc.Add(New XElement("DWSIM_Simulation_Data"))
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("GeneralInfo"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("GeneralInfo")
If Not DWSIM.GlobalSettings.Settings.AutomationMode Then
Dim appver = Assembly.GetEntryAssembly().GetName().Version
xel.Add(New XElement("BuildVersion", appver.ToString))
xel.Add(New XElement("BuildDate", CType("01/01/2000", DateTime).AddDays(appver.Build).AddSeconds(appver.Revision * 2)))
If GlobalSettings.Settings.RunningPlatform() = GlobalSettings.Settings.Platform.Mac Then
xel.Add(New XElement("OSInfo", "macOS " + Environment.OSVersion.ToString()))
Else
xel.Add(New XElement("OSInfo", Environment.OSVersion.Platform.ToString() & ", Version " & Environment.OSVersion.Version.ToString()))
End If
End If
xel.Add(New XElement("SavedOn", Date.Now))
xel.Add(New XElement("SavedFromClassicUI", False))
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("SimulationObjects"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects")
For Each so As ICustomXMLSerialization In SimulationObjects.Values
DirectCast(so, ISimulationObject).SetFlowsheet(Me)
xel.Add(New XElement("SimulationObject", {so.SaveData().ToArray()}))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Settings"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Settings")
xel.Add(Options.SaveData().ToArray())
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("DynamicProperties"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicProperties")
Dim extraprops = DirectCast(ExtraProperties, IDictionary(Of String, Object))
For Each item In extraprops
Try
xel.Add(New XElement("Property", {New XElement("Name", item.Key),
New XElement("PropertyType", item.Value.GetType.ToString),
New XElement("Data", Newtonsoft.Json.JsonConvert.SerializeObject(item.Value))}))
Catch ex As Exception
End Try
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("GraphicObjects"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects")
For Each go As GraphicObject In FlowsheetSurface.DrawingObjects
If Not go.IsConnector Then xel.Add(New XElement("GraphicObject", go.SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("PropertyPackages"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("PropertyPackages")
For Each pp As KeyValuePair(Of String, IPropertyPackage) In Options.PropertyPackages
Dim createdms As Boolean = False
If pp.Value.CurrentMaterialStream Is Nothing Then
Dim ms As New Streams.MaterialStream("", "")
AddCompoundsToMaterialStream(ms)
pp.Value.CurrentMaterialStream = ms
createdms = True
End If
xel.Add(New XElement("PropertyPackage", {New XElement("ID", pp.Key), DirectCast(pp.Value, ICustomXMLSerialization).SaveData().ToArray()}))
If createdms Then pp.Value.CurrentMaterialStream = Nothing
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Compounds"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Compounds")
For Each cp As ConstantProperties In Options.SelectedComponents.Values
xel.Add(New XElement("Compound", cp.SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ReactionSets"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ReactionSets")
For Each pp As KeyValuePair(Of String, IReactionSet) In Options.ReactionSets
xel.Add(New XElement("ReactionSet", DirectCast(pp.Value, ICustomXMLSerialization).SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Reactions"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Reactions")
For Each pp As KeyValuePair(Of String, IReaction) In Options.Reactions
xel.Add(New XElement("Reaction", {DirectCast(pp.Value, ICustomXMLSerialization).SaveData().ToArray()}))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("StoredSolutions"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("StoredSolutions")
For Each pp As KeyValuePair(Of String, List(Of XElement)) In StoredSolutions
xel.Add(New XElement("Solution", New XAttribute("ID", pp.Key), pp.Value))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("DynamicsManager"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicsManager")
xel.Add(DirectCast(DynamicsManager, ICustomXMLSerialization).SaveData().ToArray())
Dim flsconfig As New System.Text.StringBuilder()
If Not GlobalSettings.Settings.AutomationMode Then
With flsconfig
.Append(FlowsheetSurface.Zoom.ToString(ci) & ";")
.Append("0;")
.Append("0")
End With
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("FlowsheetView"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("FlowsheetView")
xel.Add(flsconfig.ToString)
End If
xel = xdoc.Element("DWSIM_Simulation_Data")
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("OptimizationCases"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("OptimizationCases")
For Each pp As Optimization.OptimizationCase In OptimizationCollection
xel.Add(New XElement("OptimizationCase", {pp.SaveData().ToArray()}))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("SensitivityAnalysis"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("SensitivityAnalysis")
For Each pp As Optimization.SensitivityAnalysisCase In SensAnalysisCollection
xel.Add(New XElement("SensitivityAnalysisCase", {pp.SaveData().ToArray()}))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ScriptItems"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ScriptItems")
For Each scr As Script In Scripts.Values
xel.Add(New XElement("ScriptItem", scr.SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ChartItems"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ChartItems")
For Each ch As SharedClasses.Charts.Chart In Charts.Values
xel.Add(New XElement("ChartItem", ch.SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ParticleSizeDistributions"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ParticleSizeDistributions")
For Each psd In ParticleSizeDistributions
xel.Add(New XElement("ParticleSizeDistribution", DirectCast(psd, ICustomXMLSerialization).SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Results"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Results")
xel.Add(DirectCast(Results, ICustomXMLSerialization).SaveData().ToArray())
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("GHGCompositions"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("GHGCompositions")
For Each ghgcomp In GHGEmissionCompositions.Values
xel.Add(New XElement("GHGComposition", DirectCast(ghgcomp, ICustomXMLSerialization).SaveData().ToArray()))
Next
If SaveSpreadsheetData IsNot Nothing Then SaveSpreadsheetData.Invoke(xdoc)
Return xdoc
End Function
Public Sub RequestSave() Implements IFlowsheet.RequestSave
Throw New NotImplementedException()
End Sub
Public Sub RequestSaveWithDirectory(directory As String) Implements IFlowsheet.RequestSaveWithDirectory
Throw New NotImplementedException()
End Sub
Public Sub RequestSaveWithPath(filepath As String) Implements IFlowsheet.RequestSaveWithPath
Throw New NotImplementedException()
End Sub
Public Function GetProcessData() As List(Of XElement) Implements IFlowsheet.GetProcessData
Dim dlist As New List(Of XElement)
For Each so As SharedClasses.UnitOperations.BaseClass In SimulationObjects.Values
so.SetFlowsheet(Me)
dlist.Add(New XElement("SimulationObject", {so.SaveData().ToArray()}))
Next
Return dlist
End Function
Public Sub LoadProcessData(data As List(Of XElement)) Implements IFlowsheet.LoadProcessData
For Each xel In data
Dim id As String = xel.<Name>.Value
Dim obj = SimulationObjects(id)
obj.LoadData(xel.Elements.ToList)
If TypeOf obj Is Streams.MaterialStream Then
Dim stream = DirectCast(obj, Streams.MaterialStream)
For Each p In stream.Phases.Values
For Each c In p.Compounds.Values
c.ConstantProperties = SelectedCompounds(c.Name)
Next
Next
End If
Next
End Sub
Sub AddGraphicObjects(data As List(Of XElement), excs As Concurrent.ConcurrentBag(Of Exception),
Optional ByVal pkey As String = "", Optional ByVal shift As Integer = 0, Optional ByVal reconnectinlets As Boolean = False)
Dim objcount As Integer
For Each xel As XElement In data
Try
xel.Element("Type").Value = xel.Element("Type").Value.Replace("Microsoft.MSDN.Samples.GraphicObjects", "DWSIM.DrawingTools.GraphicObjects")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Ajuste", "OT_Adjust")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Especificacao", "OT_Spec")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Reciclo", "OT_Recycle")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("GO_Texto", "GO_Text")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("GO_Figura", "GO_Image")
Dim obj As GraphicObject = Nothing
Dim t As Type = Type.GetType(xel.Element("Type").Value, False)
If Not t Is Nothing Then obj = CType(Activator.CreateInstance(t), GraphicObject)
If obj Is Nothing Then
If xel.Element("Type").Value.Contains("OxyPlotGraphic") Then
obj = CType(Extended.Shared.ReturnInstance(xel.Element("Type").Value.Replace("Shapes", "Charts")), GraphicObject)
Else
obj = CType(GraphicObject.ReturnInstance(xel.Element("Type").Value), GraphicObject)
End If
End If
If Not obj Is Nothing Then
obj.LoadData(xel.Elements.ToList)
obj.Name = pkey & obj.Name
obj.X += shift
obj.Y += shift
If pkey <> "" Then
objcount = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Select go Where go.Tag.Equals(obj.Tag)).Count
If objcount > 0 Then obj.Tag += "_copy"
End If
If TypeOf obj Is TableGraphic Then
DirectCast(obj, TableGraphic).Flowsheet = Me
ElseIf TypeOf obj Is MasterTableGraphic Then
DirectCast(obj, MasterTableGraphic).Flowsheet = Me
ElseIf TypeOf obj Is SpreadsheetTableGraphic Then
DirectCast(obj, SpreadsheetTableGraphic).Flowsheet = Me
ElseIf TypeOf obj Is Charts.OxyPlotGraphic Then
DirectCast(obj, Charts.OxyPlotGraphic).Flowsheet = Me
ElseIf TypeOf obj Is RigorousColumnGraphic Or TypeOf obj Is AbsorptionColumnGraphic Or TypeOf obj Is CAPEOPENGraphic Then
obj.CreateConnectors(xel.Element("InputConnectors").Elements.Count, xel.Element("OutputConnectors").Elements.Count)
obj.PositionConnectors()
ElseIf TypeOf obj Is ExternalUnitOperationGraphic Then
Dim euo = ExternalUnitOperations.Values.Where(Function(x) x.Description = obj.Description).FirstOrDefault
If euo IsNot Nothing Then
obj.Owner = euo
DirectCast(euo, Interfaces.ISimulationObject).GraphicObject = obj
obj.CreateConnectors(0, 0)
obj.Owner = Nothing
DirectCast(euo, Interfaces.ISimulationObject).GraphicObject = Nothing
Else
Try
obj.CreateConnectors(0, 0)
Catch ex As Exception
End Try
End If
Else
If obj.Name = "" Then obj.Name = obj.Tag
obj.CreateConnectors(0, 0)
End If
obj.Flowsheet = Me
If Not TypeOf obj Is TableGraphic Then
FlowsheetSurface.DrawingObjects.Add(obj)
GraphicObjects.Add(obj.Name, obj)
End If
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Graphic Objects", ex))
End Try
Next
For Each xel As XElement In data
Try
Dim id As String = pkey & xel.Element("Name").Value
If id <> "" Then
Dim obj As IGraphicObject = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Where go.Name = id).SingleOrDefault
If obj Is Nothing Then obj = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Where go.Name = xel.Element("Name").Value).SingleOrDefault
If Not obj Is Nothing Then
If xel.Element("InputConnectors") IsNot Nothing Then
Dim i As Integer = 0
For Each xel2 As XElement In xel.Element("InputConnectors").Elements
If CBool(xel2.@IsAttached) = True Then
obj.InputConnectors(i).ConnectorName = pkey & xel2.@AttachedFromObjID & "|" & xel2.@AttachedFromConnIndex
obj.InputConnectors(i).Type = CType([Enum].Parse(obj.InputConnectors(i).Type.GetType, xel2.@ConnType), ConType)
If reconnectinlets Then
Dim objFrom As IGraphicObject = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Where go.Name = xel2.@AttachedFromObjID).SingleOrDefault
If Not objFrom Is Nothing Then
If Not objFrom.OutputConnectors(CInt(xel2.@AttachedFromConnIndex)).IsAttached Then
FlowsheetSurface.ConnectObject(CType(objFrom, GraphicObject), CType(obj, GraphicObject), CInt(xel2.@AttachedFromConnIndex), CInt(xel2.@AttachedToConnIndex))
End If
End If
End If
End If
i += 1
Next
End If
End If
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Object Connection Information", ex))
End Try
Next
For Each xel As XElement In data
Try
Dim id As String = pkey & xel.Element("Name").Value
If id <> "" Then
Dim obj As IGraphicObject = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Where go.Name = id).SingleOrDefault
If Not obj Is Nothing Then
If xel.Element("OutputConnectors") IsNot Nothing Then
For Each xel2 As XElement In xel.Element("OutputConnectors").Elements
If CBool(xel2.@IsAttached) = True Then
Dim objToID = pkey & xel2.@AttachedToObjID
If objToID <> "" Then
Dim objTo As IGraphicObject = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Where go.Name = objToID).SingleOrDefault
If objTo Is Nothing Then objTo = (From go As IGraphicObject In FlowsheetSurface.DrawingObjects Where go.Name = xel2.@AttachedToObjID).SingleOrDefault
Dim fromidx As Integer = -1
Dim cp As IConnectionPoint = (From cp2 As IConnectionPoint In objTo.InputConnectors Select cp2 Where cp2.ConnectorName.Split("|"c)(0) = obj.Name).SingleOrDefault
If cp Is Nothing Then cp = (From cp2 As IConnectionPoint In objTo.InputConnectors Select cp2 Where cp2.ConnectorName.Split("|"c)(0) = xel2.@AttachedToObjID).SingleOrDefault
If Not cp Is Nothing Then
fromidx = CInt(cp.ConnectorName.Split("|"c)(1))
End If
If Not obj Is Nothing And Not objTo Is Nothing Then FlowsheetSurface.ConnectObject(CType(obj, GraphicObject), CType(objTo, GraphicObject), fromidx, CInt(xel2.@AttachedToConnIndex))
End If
End If
Next
End If
If xel.Element("EnergyConnector") IsNot Nothing Then
For Each xel2 As XElement In xel.Element("EnergyConnector").Elements
If CBool(xel2.@IsAttached) = True Then
Dim objToID = pkey & xel2.@AttachedToObjID
If objToID <> "" Then
Dim objTo As IGraphicObject = (From go As IGraphicObject In
FlowsheetSurface.DrawingObjects Where go.Name = objToID).SingleOrDefault
If objTo Is Nothing Then obj = (From go As IGraphicObject In
FlowsheetSurface.DrawingObjects Where go.Name = xel2.@AttachedToObjID).SingleOrDefault
If Not obj Is Nothing And Not objTo Is Nothing Then FlowsheetSurface.ConnectObject(CType(obj, GraphicObject), CType(objTo, GraphicObject), -1, CInt(xel2.@AttachedToConnIndex))
End If
End If
Next
End If
End If
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Object Connection Information", ex))
End Try
Next
End Sub
Sub AddTables(data As List(Of XElement), excs As Concurrent.ConcurrentBag(Of Exception))
For Each xel As XElement In data
Try
xel.Element("Type").Value = xel.Element("Type").Value.Replace("Microsoft.MSDN.Samples.GraphicObjects", "DWSIM.DrawingTools.GraphicObjects")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Ajuste", "OT_Adjust")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Especificacao", "OT_Spec")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Reciclo", "OT_Recycle")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("GO_Texto", "GO_Text")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("GO_Figura", "GO_Image")
Dim obj As IGraphicObject = Nothing
Dim t As Type = Type.GetType(xel.Element("Type").Value, False)
If Not t Is Nothing Then obj = CType(Activator.CreateInstance(t), IGraphicObject)
If obj Is Nothing Then obj = GraphicObject.ReturnInstance(xel.Element("Type").Value)
If Not obj Is Nothing Then
DirectCast(obj, ICustomXMLSerialization).LoadData(xel.Elements.ToList)
If TypeOf obj Is TableGraphic Then
DirectCast(obj, TableGraphic).Flowsheet = Me
If obj.Name = "" Then obj.Name = obj.Tag
FlowsheetSurface.DrawingObjects.Add(obj)
GraphicObjects.Add(obj.Name, obj)
End If
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Graphic Objects", ex))
End Try
Next
End Sub
Sub AddSimulationObjects(objlist As Concurrent.ConcurrentBag(Of ISimulationObject), excs As Concurrent.ConcurrentBag(Of Exception))
For Each obj In objlist
Try
SimulationObjects.Add(obj.Name, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Unit Operation Information", ex))
End Try
Next
For Each so As ISimulationObject In SimulationObjects.Values
Try
If TryCast(so, Adjust) IsNot Nothing Then
Dim so2 As Adjust = CType(so, Adjust)
If SimulationObjects.ContainsKey(so2.ManipulatedObjectData.ID) Then
so2.ManipulatedObject = CType(SimulationObjects(so2.ManipulatedObjectData.ID), SharedClasses.UnitOperations.BaseClass)
DirectCast(so2.GraphicObject, AdjustGraphic).ConnectedToMv = CType(so2.ManipulatedObject.GraphicObject, GraphicObject)
End If
If SimulationObjects.ContainsKey(so2.ControlledObjectData.ID) Then
so2.ControlledObject = CType(SimulationObjects(so2.ControlledObjectData.ID), SharedClasses.UnitOperations.BaseClass)
DirectCast(so2.GraphicObject, AdjustGraphic).ConnectedToCv = CType(so2.ControlledObject.GraphicObject, GraphicObject)
End If
If SimulationObjects.ContainsKey(so2.ReferencedObjectData.ID) Then
so2.ReferenceObject = CType(SimulationObjects(so2.ReferencedObjectData.ID), SharedClasses.UnitOperations.BaseClass)
DirectCast(so2.GraphicObject, AdjustGraphic).ConnectedToRv = CType(so2.ReferenceObject.GraphicObject, GraphicObject)
End If
End If
If TryCast(so, Spec) IsNot Nothing Then
Dim so2 As Spec = CType(so, Spec)
If SimulationObjects.ContainsKey(so2.TargetObjectData.ID) Then
so2.TargetObject = CType(SimulationObjects(so2.TargetObjectData.ID), SharedClasses.UnitOperations.BaseClass)
DirectCast(so2.GraphicObject, SpecGraphic).ConnectedToTv = CType(so2.TargetObject.GraphicObject, GraphicObject)
End If
If SimulationObjects.ContainsKey(so2.SourceObjectData.ID) Then
so2.SourceObject = CType(SimulationObjects(so2.SourceObjectData.ID), SharedClasses.UnitOperations.BaseClass)
DirectCast(so2.GraphicObject, SpecGraphic).ConnectedToSv = CType(so2.SourceObject.GraphicObject, GraphicObject)
End If
End If
If TryCast(so, CapeOpenUO) IsNot Nothing Then
DirectCast(so, CapeOpenUO).UpdateConnectors2()
DirectCast(so, CapeOpenUO).UpdatePortsFromConnectors()
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Unit Operation Connection Information", ex))
End Try
Next
End Sub
Public Property AvailableCompounds As New Dictionary(Of String, ICompoundConstantProperties) Implements IFlowsheet.AvailableCompounds
Public Sub Initialize() Implements IFlowsheet.Initialize
Dim calculatorassembly = System.Reflection.Assembly.Load("DWSIM.Thermodynamics")
Dim unitopassembly = System.Reflection.Assembly.Load("DWSIM.UnitOperations")
AddHandler AppDomain.CurrentDomain.AssemblyResolve, New ResolveEventHandler(AddressOf LoadFromExtensionsFolder)
FileDatabaseProvider.CreateDatabase()
DynamicsManager.ToggleDynamicMode = Function()
DynamicMode = Not DynamicMode
Return DynamicMode
End Function
FlowsheetSurface.DrawPropertyList = Options.DisplayCornerPropertyList
FlowsheetSurface.DrawFloatingTable = Options.DisplayFloatingPropertyTables
ReactionSets.Add("DefaultSet", New ReactionSet("DefaultSet", "Default Set", ""))
AddExternalUOs()
AddSystemsOfUnits()
'AddDefaultProperties()
If ObjectList.Count = 0 Then
Dim aTypeList As New List(Of Type)
If GlobalSettings.Settings.RunningPlatform() = Settings.Platform.Linux Then
aTypeList.AddRange(calculatorassembly.GetExportedTypes().Where(Function(x) If(x.GetInterface("DWSIM.Interfaces.ISimulationObject") IsNot Nothing, True, False)))
aTypeList.AddRange(unitopassembly.GetExportedTypes().Where(Function(x) If(x.GetInterface("DWSIM.Interfaces.ISimulationObject") IsNot Nothing And
Not x.IsAbstract And x.GetInterface("DWSIM.Interfaces.IExternalUnitOperation") Is Nothing, True, False)))
Else
aTypeList.AddRange(calculatorassembly.GetTypes().Where(Function(x) If(x.GetInterface("DWSIM.Interfaces.ISimulationObject") IsNot Nothing, True, False)))
aTypeList.AddRange(unitopassembly.GetTypes().Where(Function(x) If(x.GetInterface("DWSIM.Interfaces.ISimulationObject") IsNot Nothing And
Not x.IsAbstract And x.GetInterface("DWSIM.Interfaces.IExternalUnitOperation") Is Nothing, True, False)))
End If
For Each item In aTypeList.OrderBy(Function(x) x.Name)
If Not item.IsAbstract Then
Dim obj = DirectCast(Activator.CreateInstance(item), Interfaces.ISimulationObject)
ObjectList.Add(obj.GetDisplayName(), obj)
End If
Next
For Each item In ExternalUnitOperations.Values.OrderBy(Function(x) x.Name)
ObjectList.Add(item.Name, item)
Next
End If
If Not SupressDataLoading Then
AddPropPacks()
Dim addedcomps As New List(Of String)
Dim casnumbers As New List(Of String)
Dim tc = TaskHelper.Run(Sub()
Dim csdb As New Databases.ChemSep
Dim cpa() As ConstantProperties
csdb.Load()
cpa = csdb.Transfer()
For Each cp As ConstantProperties In cpa
If Not AvailableCompounds.ContainsKey(cp.Name) Then AvailableCompounds.Add(cp.Name, cp)
Next
Dim cpdb As New Databases.CoolProp
cpdb.Load()
cpa = cpdb.Transfer()
addedcomps = AvailableCompounds.Keys.Select(Function(x) x.ToLower).ToList()
For Each cp As ConstantProperties In cpa
If Not addedcomps.Contains(cp.Name.ToLower) Then AvailableCompounds.Add(cp.Name, cp)
Next
Dim bddb As New Databases.Biodiesel
bddb.Load()
cpa = bddb.Transfer()
addedcomps = AvailableCompounds.Keys.Select(Function(x) x.ToLower).ToList()
For Each cp As ConstantProperties In cpa
If Not addedcomps.Contains(cp.Name.ToLower) Then AvailableCompounds.Add(cp.Name, cp)
Next
Dim chedl As New Databases.ChEDL_Thermo
chedl.Load()
cpa = chedl.Transfer().ToArray()
addedcomps = AvailableCompounds.Keys.Select(Function(x) x.ToLower).ToList()
casnumbers = AvailableCompounds.Values.Select(Function(x) x.CAS_Number).ToList()
For Each cp As ConstantProperties In cpa
If Not addedcomps.Contains(cp.Name.ToLower) And Not addedcomps.Contains(cp.Name) Then
If Not casnumbers.Contains(cp.CAS_Number) Then
If Not AvailableCompounds.ContainsKey(cp.Name) Then AvailableCompounds.Add(cp.Name, cp)
End If
End If
Next
Dim elec As New Databases.Electrolyte
elec.Load()
cpa = elec.Transfer().ToArray()
addedcomps = AvailableCompounds.Keys.Select(Function(x) x.ToLower).ToList()
For Each cp As ConstantProperties In cpa
If Not addedcomps.Contains(cp.Name.ToLower) AndAlso Not AvailableCompounds.ContainsKey(cp.Name) Then AvailableCompounds.Add(cp.Name, cp)
Next
Dim comps = Databases.UserDB.LoadAdditionalCompounds()
For Each cp As BaseClasses.ConstantProperties In comps
If Not AvailableCompounds.ContainsKey(cp.Name) Then AvailableCompounds.Add(cp.Name, cp)
Next
Using filestr As Stream = Assembly.GetAssembly(elec.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.FoodProp.xml")
Dim fcomps = Databases.UserDB.ReadComps(filestr)
For Each cp As BaseClasses.ConstantProperties In fcomps
cp.CurrentDB = "FoodProp"
If Not AvailableCompounds.ContainsKey(cp.Name) Then AvailableCompounds.Add(cp.Name, cp)
Next
End Using
csdb.Dispose()
cpdb.Dispose()
chedl.Dispose()
End Sub)
tc.Wait()
End If
End Sub
Public Sub Reset() Implements IFlowsheet.Reset
SimulationObjects.Clear()
GraphicObjects.Clear()
FlowsheetSurface.DrawingObjects.Clear()
SelectedCompounds.Clear()
Options = New SharedClasses.DWSIM.Flowsheet.FlowsheetVariables()
FlowsheetSurface.Zoom = 1.0#
End Sub
Public Property ErrorMessage As String Implements IFlowsheet.ErrorMessage
Public Function GetDockPanel() As Object Implements IFlowsheet.GetDockPanel
Return Nothing
End Function
Public Function GetFlowsheetBag() As IFlowsheetBag Implements IFlowsheet.GetFlowsheetBag
Return CType(Me, IFlowsheetBag)
End Function
Public Function GetUtility(uttype As Enums.FlowsheetUtility) As IAttachedUtility Implements IFlowsheet.GetUtility
Return Nothing
End Function
Public Property MasterFlowsheet As IFlowsheet Implements IFlowsheet.MasterFlowsheet
Public Property MasterUnitOp As ISimulationObject Implements IFlowsheet.MasterUnitOp
Public Property Message As String Implements IFlowsheet.Message
Public Property MobileCompatibilityMode As Boolean Implements IFlowsheet.MobileCompatibilityMode
Public MustOverride Sub RunCodeOnUIThread(act As Action) Implements IFlowsheet.RunCodeOnUIThread
Public MustOverride Sub SetMessageListener(act As Action(Of String, IFlowsheet.MessageType)) Implements IFlowsheet.SetMessageListener
Public Property Solved As Boolean Implements IFlowsheet.Solved
Public Sub UpdateSpreadsheet(act As Action) Implements IFlowsheet.UpdateSpreadsheet
If Not act Is Nothing Then act.Invoke()
End Sub
Public MustOverride Sub UpdateInformation() Implements IFlowsheet.UpdateInformation
Public MustOverride Sub UpdateInterface() Implements IFlowsheet.UpdateInterface
Public ReadOnly Property UtilityPlugins As Dictionary(Of String, IUtilityPlugin) Implements IFlowsheet.UtilityPlugins
Get
Return Nothing
End Get
End Property
Public Sub WriteSpreadsheetVariables(act As Action) Implements IFlowsheet.WriteSpreadsheetVariables
If Not act Is Nothing Then act.Invoke()
End Sub
Public Sub ProcessScripts(ByVal sourceevent As Enums.Scripts.EventType, ByVal sourceobj As Enums.Scripts.ObjectType, ByVal sourceobjname As String) Implements IFlowsheet.ProcessScripts
For Each scr As Script In Scripts.Values
If scr.Linked And scr.LinkedEventType = sourceevent And scr.LinkedObjectType = sourceobj And scr.LinkedObjectName = sourceobjname Then
If scr.LinkedObjectName <> "" Then
ShowMessage("Running script '" & scr.Title & "' for event '" & scr.LinkedEventType.ToString & "', linked to '" & SimulationObjects(scr.LinkedObjectName).GraphicObject.Tag & "'...", IFlowsheet.MessageType.Information)
Else
ShowMessage("Running script '" & scr.Title & "' for event '" & scr.LinkedEventType.ToString & "'", IFlowsheet.MessageType.Information)
End If
If scr.PythonInterpreter = Enums.Scripts.Interpreter.IronPython Then
RunScript_IronPython(scr.ScriptText)
Else
RunScript_PythonNET(scr.ScriptText)
End If
End If
Next
End Sub
Public Function LoadZippedXML(pathtofile As String) As XDocument
Dim pathtosave As String = Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString())
Directory.CreateDirectory(pathtosave)
Dim fullname As String = ""
Dim dbfile As String = ""
Using stream As ZipInputStream = New ZipInputStream(File.OpenRead(pathtofile))
stream.Password = Nothing
Dim entry As ZipEntry
Label_00CC:
entry = stream.GetNextEntry()
Do While (Not entry Is Nothing)
Dim fileName As String = Path.GetFileName(entry.Name)
If (fileName <> String.Empty) Then
Using stream2 As FileStream = File.Create(Path.Combine(pathtosave, Path.GetFileName(entry.Name)))
Dim count As Integer = 2048
Dim buffer As Byte() = New Byte(2048) {}
Do While True
count = stream.Read(buffer, 0, buffer.Length)
If (count <= 0) Then
Dim extension = Path.GetExtension(entry.Name).ToLower()
If extension = ".xml" Then
fullname = Path.Combine(pathtosave, Path.GetFileName(entry.Name))
ElseIf extension = ".db" Then
dbfile = Path.Combine(pathtosave, Path.GetFileName(entry.Name))
End If
GoTo Label_00CC
End If
stream2.Write(buffer, 0, count)
Loop
End Using
End If
entry = stream.GetNextEntry
Loop
End Using
Dim xdoc = XDocument.Load(fullname)
LoadFromXML(xdoc)
FilePath = pathtofile
Options.FilePath = pathtofile
If File.Exists(dbfile) Then
Try
FileDatabaseProvider.LoadDatabase(dbfile)
Catch ex As Exception
Finally
File.Delete(dbfile)
End Try
End If
File.Delete(fullname)
Try
Directory.Delete(pathtosave, True)
Catch ex As Exception
End Try
Return xdoc
End Function
Public Shared Function LoadZippedXMLDoc(pathtofile As String) As XDocument
Dim pathtosave As String = Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString())
Directory.CreateDirectory(pathtosave)
Dim fullname As String = ""
Using stream As ZipInputStream = New ZipInputStream(File.OpenRead(pathtofile))
stream.Password = Nothing
Dim entry As ZipEntry
Label_00CC:
entry = stream.GetNextEntry()
Do While (Not entry Is Nothing)
Dim fileName As String = Path.GetFileName(entry.Name)
If (fileName <> String.Empty) Then
Using stream2 As FileStream = File.Create(Path.Combine(pathtosave, Path.GetFileName(entry.Name)))
Dim count As Integer = 2048
Dim buffer As Byte() = New Byte(2048) {}
Do While True
count = stream.Read(buffer, 0, buffer.Length)
If (count <= 0) Then
Dim extension = Path.GetExtension(entry.Name).ToLower()
If extension = ".xml" Then
fullname = Path.Combine(pathtosave, Path.GetFileName(entry.Name))
End If
GoTo Label_00CC
End If
stream2.Write(buffer, 0, count)
Loop
End Using
End If
entry = stream.GetNextEntry
Loop
End Using
Dim xdoc = XDocument.Load(fullname)
File.Delete(fullname)
Try
Directory.Delete(pathtosave, True)
Catch ex As Exception
End Try
Return xdoc
End Function
Shared Function IsZipFilePasswordProtected(ByVal ZipFile As String) As Boolean
Using fsIn As New FileStream(ZipFile, FileMode.Open, FileAccess.Read)
Using zipInStream As New ZipInputStream(fsIn)
Dim zEntry As ZipEntry = zipInStream.GetNextEntry()
Return zEntry.IsCrypted
End Using
End Using
End Function
Public Shared Sub AddPropPacks()
If AvailablePropPacks.Count > 0 Then Exit Sub
Dim plist As New Concurrent.BlockingCollection(Of PropertyPackage)
Dim t1 = TaskHelper.Run(Sub()
Dim CPPP As CoolPropPropertyPackage = New CoolPropPropertyPackage()
CPPP.ComponentName = "CoolProp"
plist.Add(CPPP)
Dim CPIPP As New CoolPropIncompressiblePurePropertyPackage()
CPIPP.ComponentName = "CoolProp (Incompressible Fluids)"
CPIPP.ComponentDescription = "CoolProp (Incompressible Fluids)"
plist.Add(CPIPP)
Dim CPIMPP As New CoolPropIncompressibleMixturePropertyPackage()
CPIMPP.ComponentName = "CoolProp (Incompressible Mixtures)"
CPIMPP.ComponentDescription = "CoolProp (Incompressible Mixtures)"
plist.Add(CPIMPP)
Dim STPP As SteamTablesPropertyPackage = New SteamTablesPropertyPackage()
STPP.ComponentName = "Steam Tables (IAPWS-IF97)"
plist.Add(STPP)
Dim SEAPP As SeawaterPropertyPackage = New SeawaterPropertyPackage()
SEAPP.ComponentName = "Seawater IAPWS-08"
plist.Add(SEAPP)
End Sub)
Dim t2 = TaskHelper.Run(Sub()
Dim PRPP As PengRobinsonPropertyPackage = New PengRobinsonPropertyPackage()
PRPP.ComponentName = "Peng-Robinson (PR)"
plist.Add(PRPP)
End Sub)
Dim t3 = TaskHelper.Run(Sub()
Dim PRSV2PP As PRSV2PropertyPackage = New PRSV2PropertyPackage()
PRSV2PP.ComponentName = "Peng-Robinson-Stryjek-Vera 2 (PRSV2-M)"
plist.Add(PRSV2PP)
Dim PRSV2PPVL As PRSV2VLPropertyPackage = New PRSV2VLPropertyPackage()
PRSV2PPVL.ComponentName = "Peng-Robinson-Stryjek-Vera 2 (PRSV2-VL)"
plist.Add(PRSV2PPVL)
End Sub)
Dim t4 = TaskHelper.Run(Sub()
Dim SRKPP As SRKPropertyPackage = New SRKPropertyPackage()
SRKPP.ComponentName = "Soave-Redlich-Kwong (SRK)"
plist.Add(SRKPP)
End Sub)
Dim t6 = TaskHelper.Run(Sub()
Dim UPP As UNIFACPropertyPackage = New UNIFACPropertyPackage()
UPP.ComponentName = "UNIFAC"
plist.Add(UPP)
End Sub)
Dim t7 = TaskHelper.Run(Sub()
Dim ULLPP As UNIFACLLPropertyPackage = New UNIFACLLPropertyPackage()
ULLPP.ComponentName = "UNIFAC-LL"
plist.Add(ULLPP)
End Sub)
Dim t8 = TaskHelper.Run(Sub()
Dim MUPP As MODFACPropertyPackage = New MODFACPropertyPackage()
MUPP.ComponentName = "Modified UNIFAC (Dortmund)"
plist.Add(MUPP)
End Sub)
Dim t9 = TaskHelper.Run(Sub()
Dim NUPP As NISTMFACPropertyPackage = New NISTMFACPropertyPackage()
NUPP.ComponentName = "Modified UNIFAC (NIST)"
plist.Add(NUPP)
End Sub)
Dim t10 = TaskHelper.Run(Sub()
Dim WPP As WilsonPropertyPackage = New WilsonPropertyPackage()
WPP.ComponentName = "Wilson"
plist.Add(WPP)
Dim NRTLPP As NRTLPropertyPackage = New NRTLPropertyPackage()
NRTLPP.ComponentName = "NRTL"
plist.Add(NRTLPP)
Dim UQPP As UNIQUACPropertyPackage = New UNIQUACPropertyPackage()
UQPP.ComponentName = "UNIQUAC"
plist.Add(UQPP)
Dim CSLKPP As ChaoSeaderPropertyPackage = New ChaoSeaderPropertyPackage()
CSLKPP.ComponentName = "Chao-Seader"
plist.Add(CSLKPP)
Dim GSLKPP As GraysonStreedPropertyPackage = New GraysonStreedPropertyPackage()
GSLKPP.ComponentName = "Grayson-Streed"
plist.Add(GSLKPP)
Dim RPP As RaoultPropertyPackage = New RaoultPropertyPackage()
RPP.ComponentName = "Raoult's Law"
plist.Add(RPP)
Dim LKPPP As LKPPropertyPackage = New LKPPropertyPackage()
LKPPP.ComponentName = "Lee-Kesler-Plöcker"
plist.Add(LKPPP)
End Sub)
Dim t11 = TaskHelper.Run(Sub()
Dim ISPP As New IdealElectrolytePropertyPackage()
plist.Add(ISPP)
Dim BOPP As BlackOilPropertyPackage = New BlackOilPropertyPackage()
BOPP.ComponentName = "Black Oil"
plist.Add(BOPP)
Dim GERGPP As GERG2008PropertyPackage = New GERG2008PropertyPackage()
plist.Add(GERGPP)
Dim PCSAFTPP As PCSAFT2PropertyPackage = New PCSAFT2PropertyPackage()
plist.Add(PCSAFTPP)
End Sub)
Dim t12 = TaskHelper.Run(Sub()
Dim PR78PP As PengRobinson1978PropertyPackage = New PengRobinson1978PropertyPackage()
PR78PP.ComponentName = "Peng-Robinson 1978 (PR78)"
plist.Add(PR78PP)
End Sub)
Dim t13 = TaskHelper.Run(Sub()
Dim PR78Adv As PengRobinson1978AdvancedPropertyPackage = New PengRobinson1978AdvancedPropertyPackage()
plist.Add(PR78Adv)
End Sub)
Dim t14 = TaskHelper.Run(Sub()
Dim SRKAdv As SoaveRedlichKwongAdvancedPropertyPackage = New SoaveRedlichKwongAdvancedPropertyPackage()
plist.Add(SRKAdv)
End Sub)
Task.WaitAll(t1, t2, t3, t4, t6, t7, t8, t9, t10, t11, t12, t13, t14)
For Each pp In plist
AvailablePropPacks.Add(DirectCast(pp, CapeOpen.ICapeIdentification).ComponentName, pp)
Next
Dim otherpps = SharedClasses.Utility.LoadAdditionalPropertyPackages()
For Each pp In otherpps
If Not AvailablePropPacks.ContainsKey(DirectCast(pp, CapeOpen.ICapeIdentification).ComponentName) Then
AvailablePropPacks.Add(DirectCast(pp, CapeOpen.ICapeIdentification).ComponentName, pp)
Else
Console.WriteLine(String.Format("Error adding External Property Package '{0}'. Check the 'ppacks' and 'extenders' folders for duplicate items.", pp.ComponentName))
End If
Next
'Check if DWSIM is running in Portable/Mono mode, if not then load the CAPE-OPEN Wrapper Property Package.
If Not GlobalSettings.Settings.IsRunningOnMono Then
Dim COPP As CAPEOPENPropertyPackage = New CAPEOPENPropertyPackage()
COPP.ComponentName = "CAPE-OPEN"
AvailablePropPacks.Add(COPP.ComponentName.ToString, COPP)
End If
End Sub
Sub AddExternalUOs()
Dim otheruos = SharedClasses.Utility.LoadAdditionalUnitOperations()
Dim unitopassembly = Assembly.Load("DWSIM.UnitOperations")
Dim euolist As List(Of Interfaces.IExternalUnitOperation) = SharedClasses.Utility.GetUnitOperations(unitopassembly)
otheruos.AddRange(euolist)
For Each uo In otheruos
If Not ExternalUnitOperations.ContainsKey(uo.Description) Then
ExternalUnitOperations.Add(uo.Description, uo)
Else
Console.WriteLine(String.Format("Error adding External Unit Operation '{0}'. Check the 'unitops' and 'extenders' folders for duplicate items.", uo.Description))
End If
Next
End Sub
Function GetPropertyPackages(ByVal assmbly As Assembly) As List(Of Interfaces.IPropertyPackage)
Dim availableTypes As New List(Of Type)()
Try
availableTypes.AddRange(assmbly.GetTypes())
Catch ex As Exception
Logging.Logger.LogError("Property Package Loading (CPUI)", ex)
End Try
Dim ppList As List(Of Type) = availableTypes.FindAll(Function(t) t.GetInterfaces().Contains(GetType(Interfaces.IPropertyPackage)) And Not t.IsAbstract)
Return ppList.ConvertAll(Of Interfaces.IPropertyPackage)(Function(t As Type) TryCast(Activator.CreateInstance(t), Interfaces.IPropertyPackage))
End Function
Private Sub AddSystemsOfUnits()
With Me.AvailableSystemsOfUnits
.Add(New SystemsOfUnits.SI)
.Add(New SystemsOfUnits.SI_ENG)
.Add(New SystemsOfUnits.CGS)
.Add(New SystemsOfUnits.English)
.Add(New SystemsOfUnits.SIUnits_Custom1)
.Add(New SystemsOfUnits.SIUnits_Custom2)
.Add(New SystemsOfUnits.SIUnits_Custom3)
.Add(New SystemsOfUnits.SIUnits_Custom4)
.Add(New SystemsOfUnits.SIUnits_Custom5)
Try
Dim options = New Newtonsoft.Json.JsonSerializerSettings
options.StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml
Dim userunits = Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of SystemsOfUnits.Units))(GlobalSettings.Settings.UserUnits, options)
Dim dontadd = New String() {"SI", "SI (Enginnering)", "CGS", "ENG", "C1", "C2", "C3", "C4", "C5"}
For Each unit In userunits
If Not dontadd.Contains(unit.Name) Then .Add(unit)
Next
Catch ex As Exception
End Try
End With
End Sub
Sub AddDefaultProperties()
If (GlobalSettings.Settings.RunningPlatform() = Settings.Platform.Linux) Then
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
End If
If Me.FlowsheetOptions.VisibleProperties.Count = 0 Then
Dim calculatorassembly = System.Reflection.Assembly.Load("DWSIM.Thermodynamics")
Dim unitopassembly = System.Reflection.Assembly.Load("DWSIM.UnitOperations")
Dim aTypeList As New List(Of Type)
aTypeList.AddRange(calculatorassembly.GetExportedTypes().Where(Function(x) If(x.GetInterface("DWSIM.Interfaces.ISimulationObject") IsNot Nothing, True, False)))
aTypeList.AddRange(unitopassembly.GetExportedTypes().Where(Function(x) If(x.GetInterface("DWSIM.Interfaces.ISimulationObject") IsNot Nothing And
Not x.IsAbstract And x.GetInterface("DWSIM.Interfaces.IExternalUnitOperation") Is Nothing, True, False)))
For Each item In aTypeList.OrderBy(Function(x) x.Name)
If Not item.IsAbstract Then
Dim obj = DirectCast(Activator.CreateInstance(item), Interfaces.ISimulationObject)
obj.SetFlowsheet(Me)
Me.FlowsheetOptions.VisibleProperties(item.Name) = obj.GetDefaultProperties.ToList
obj = Nothing
End If
Next
For Each obj In ExternalUnitOperations.Values
obj.SetFlowsheet(Me)
Me.FlowsheetOptions.VisibleProperties(obj.GetType.Name) = DirectCast(obj, ISimulationObject).GetDefaultProperties().ToList()
Next
End If
End Sub
Public Function GetSpreadsheetData(range As String) As List(Of String()) Implements IFlowsheet.GetSpreadsheetData
Return RetrieveSpreadsheetData.Invoke(range)
End Function
Public Function GetSpreadsheetFormat(range As String) As List(Of String()) Implements IFlowsheet.GetSpreadsheetFormat
Return RetrieveSpreadsheetFormat.Invoke(range)
End Function
Public Property Scripts As New Dictionary(Of String, IScript) Implements IFlowsheet.Scripts
Public Property Charts As Dictionary(Of String, IChart) = New Dictionary(Of String, IChart) Implements IFlowsheet.Charts
Public Property StoredSolutions As Dictionary(Of String, List(Of XElement)) = New Dictionary(Of String, List(Of XElement)) Implements IFlowsheet.StoredSolutions
Public Property ExternalSolvers As Dictionary(Of String, IExternalSolverIdentification) = New Dictionary(Of String, IExternalSolverIdentification) Implements IFlowsheet.ExternalSolvers
Public Property FileDatabaseProvider As IFileDatabaseProvider = New FileStorage.FileDatabaseProvider Implements IFlowsheet.FileDatabaseProvider
Public Property WatchItems As List(Of IWatchItem) = New List(Of IWatchItem) Implements IFlowsheet.WatchItems
Public Sub RunScript(ScriptID As String)
Dim script = Scripts(ScriptID)
PythonPreprocessor?.Invoke(script.ScriptText)
If script.PythonInterpreter = Enums.Scripts.Interpreter.IronPython Then
RunScript_IronPython(script.ScriptText)
Else
RunScript_PythonNET(script.ScriptText)
End If
End Sub
Public Async Sub RunScriptAsync(ScriptID As String)
Await TaskHelper.Run(Sub() RunScript(ScriptID))
End Sub
Private Sub RunScript_IronPython(scripttext As String)
Dim scope As Microsoft.Scripting.Hosting.ScriptScope
Dim engine As Microsoft.Scripting.Hosting.ScriptEngine
Dim opts As New Dictionary(Of String, Object)()
opts("Frames") = Microsoft.Scripting.Runtime.ScriptingRuntimeHelpers.True
engine = IronPython.Hosting.Python.CreateEngine(opts)
Dim paths0 = engine.GetSearchPaths().ToList()
Dim apppath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
paths0.Add(Path.Combine(apppath, "Lib"))
Try
engine.SetSearchPaths(paths0)
Catch ex As Exception
End Try
engine.Runtime.LoadAssembly(GetType(System.String).Assembly)
engine.Runtime.LoadAssembly(GetType(Thermodynamics.BaseClasses.ConstantProperties).Assembly)
engine.Runtime.LoadAssembly(GetType(Drawing.SkiaSharp.GraphicsSurface).Assembly)
engine.Runtime.IO.SetOutput(New FlowsheetLogTextStream(Me), UTF8Encoding.UTF8)
scope = engine.CreateScope()
scope.SetVariable("Plugins", UtilityPlugins)
scope.SetVariable("Flowsheet", Me)
scope.SetVariable("Application", GetApplicationObject)
If GetSpreadsheetObjectFunc IsNot Nothing Then
scope.SetVariable("Spreadsheet", GetSpreadsheetObjectFunc.Invoke())
End If
Dim Solver As New FlowsheetSolver.FlowsheetSolver
scope.SetVariable("Solver", Solver)
For Each obj As ISimulationObject In SimulationObjects.Values
scope.SetVariable(obj.GraphicObject.Tag.Replace("-", "_"), obj)
Next
Dim txtcode As String = scripttext
Dim source As Microsoft.Scripting.Hosting.ScriptSource = engine.CreateScriptSourceFromString(txtcode, Microsoft.Scripting.SourceCodeKind.Statements)
Try
source.Execute(scope)
Catch ex As Exception
Dim ops As ExceptionOperations = engine.GetService(Of ExceptionOperations)()
ShowMessage("Error running script: " & ops.FormatException(ex).ToString, IFlowsheet.MessageType.GeneralError)
Finally
engine.Runtime.Shutdown()
engine = Nothing
scope = Nothing
source = Nothing
End Try
End Sub
Private Sub RunScript_PythonNET(scripttext As String)
If GlobalSettings.Settings.RunningPlatform <> Settings.Platform.Windows Then
If Not GlobalSettings.Settings.PythonInitialized Then
Runtime.PythonDLL = GlobalSettings.Settings.PythonPath
PythonEngine.Initialize()
GlobalSettings.Settings.PythonInitialized = True
PythonEngine.BeginAllowThreads()
End If
Using Py.GIL
Try
Dim sys As Object = Py.Import("sys")
Dim codeToRedirectOutput As String = "import sys" & vbCrLf + "from io import BytesIO as StringIO" & vbCrLf + "sys.stdout = mystdout = StringIO()" & vbCrLf + "sys.stdout.flush()" & vbCrLf + "sys.stderr = mystderr = StringIO()" & vbCrLf + "sys.stderr.flush()"
PythonEngine.RunSimpleString(codeToRedirectOutput)
Dim locals As New PyDict()
locals.SetItem("Plugins", UtilityPlugins.ToPython)
locals.SetItem("Flowsheet", Me.ToPython)
Try
locals.SetItem("Spreadsheet", (GetSpreadsheetObjectFunc.Invoke()).ToPython)
Catch ex As Exception
End Try
Dim Solver As New FlowsheetSolver.FlowsheetSolver
locals.SetItem("Solver", Solver.ToPython)
If Not GlobalSettings.Settings.IsRunningOnMono() Then
locals.SetItem("Application", GetApplicationObject.ToPython)
End If
PythonEngine.Exec(scripttext, Nothing, locals)
If Not GlobalSettings.Settings.IsRunningOnMono() Then
ShowMessage(sys.stdout.getvalue().ToString, IFlowsheet.MessageType.Information)
End If
Catch ex As Exception
ShowMessage("Error running script: " & ex.Message.ToString, IFlowsheet.MessageType.GeneralError)
Finally
End Try
End Using
Else
GlobalSettings.Settings.InitializePythonEnvironment()
Using Py.GIL
Try
Dim sys As Object = Py.Import("sys")
'If Not GlobalSettings.Settings.IsRunningOnMono() Then
Dim codeToRedirectOutput As String = "import sys" & vbCrLf + "from io import BytesIO as StringIO" & vbCrLf + "sys.stdout = mystdout = StringIO()" & vbCrLf + "sys.stdout.flush()" & vbCrLf + "sys.stderr = mystderr = StringIO()" & vbCrLf + "sys.stderr.flush()"
PythonEngine.RunSimpleString(codeToRedirectOutput)
'End If
Dim locals As New PyDict()
locals.SetItem("Plugins", UtilityPlugins.ToPython)
locals.SetItem("Flowsheet", Me.ToPython)
Try
locals.SetItem("Spreadsheet", (GetSpreadsheetObjectFunc.Invoke()).ToPython)
Catch ex As Exception
End Try
Dim Solver As New FlowsheetSolver.FlowsheetSolver
locals.SetItem("Solver", Solver.ToPython)
If Not GlobalSettings.Settings.IsRunningOnMono() Then
locals.SetItem("Application", GetApplicationObject.ToPython)
End If
PythonEngine.Exec(scripttext, Nothing, locals)
If Not GlobalSettings.Settings.IsRunningOnMono() Then
ShowMessage(sys.stdout.getvalue().ToString, IFlowsheet.MessageType.Information)
End If
Catch ex As Exception
ShowMessage("Error running script: " & ex.ToString, IFlowsheet.MessageType.GeneralError)
Finally
End Try
End Using
End If
End Sub
Private Class FlowsheetLogTextStream
Inherits MemoryStream
Private target As FlowsheetBase
Public Sub New(ByVal target As FlowsheetBase)
Me.target = target
End Sub
Public Overrides Sub Write(ByVal buffer As Byte(), ByVal offset As Integer, ByVal count As Integer)
Dim output As String = Encoding.UTF8.GetString(buffer, offset, count)
If output.Trim().Length > 0 Then
Console.WriteLine(output)
target.ShowMessage(output, IFlowsheet.MessageType.Information)
End If
End Sub
End Class
Public MustOverride Function GetApplicationObject() As Object Implements IFlowsheet.GetApplicationObject
Public Function GetFlowsheetSurfaceWidth() As Integer Implements IFlowsheet.GetFlowsheetSurfaceWidth
Return FlowsheetSurface.Size.Width
End Function
Public Function GetFlowsheetSurfaceHeight() As Integer Implements IFlowsheet.GetFlowsheetSurfaceHeight
Return FlowsheetSurface.Size.Height
End Function
Public Function ChangeCalculationOrder(objects As List(Of String)) As List(Of String) Implements IFlowsheet.ChangeCalculationOrder
Dim olist As List(Of String) = objects
RunCodeOnUIThread(Sub()
Dim frm As New SharedClasses.FormCustomCalcOrder
frm.Flowsheet = Me
frm.ItemList = objects
frm.ShowDialog()
olist = frm.NewItemList
End Sub)
Return olist
End Function
Public Function GetSpreadsheetObject() As Object Implements IFlowsheet.GetSpreadsheetObject
Return GetSpreadsheetObjectFunc?.Invoke()
End Function
Public Function GetObject(name As String) As ISimulationObject Implements IFlowsheet.GetObject
Return GetFlowsheetSimulationObject(name)
End Function
Public Function GetCompound(name As String) As ICompoundConstantProperties Implements IFlowsheet.GetCompound
Return AvailableCompounds(name)
End Function
Public Function GetPropertyPackage(name As String) As IPropertyPackage Implements IFlowsheet.GetPropertyPackage
Return PropertyPackages.Values.Where(Function(x) x.Tag = name).FirstOrDefault
End Function
Public Function GetReaction(name As String) As IReaction Implements IFlowsheet.GetReaction
Return Reactions.Values.Where(Function(x) x.Name = name).FirstOrDefault
End Function
Public Function GetReactionSet(name As String) As IReactionSet Implements IFlowsheet.GetReactionSet
Return ReactionSets.Values.Where(Function(x) x.Name = name).FirstOrDefault
End Function
Public Sub AutoLayout() Implements IFlowsheet.AutoLayout
FlowsheetSurface.AutoArrange()
End Sub
Public Sub NaturalLayout() Implements IFlowsheet.NaturalLayout
FlowsheetSurface.ApplyNaturalLayout(FlowsheetSolver.FlowsheetSolver.GetSolvingList(Me, False)(0), 75)
End Sub
Public Sub RefreshInterface() Implements IFlowsheet.RefreshInterface
UpdateInterface()
End Sub
Public Sub SetTranslateTextExternalFunction(act As Func(Of String, String)) Implements IFlowsheet.SetTranslateTextExternalFunction
_translatefunction = act
End Sub
Public Function GetScriptText(name As String) As String Implements IFlowsheet.GetScriptText
Return Scripts.Values.Where(Function(x) x.Title = name).FirstOrDefault().ScriptText
End Function
Public Function GetSimulationFilePath() As String Implements IFlowsheet.GetSimulationFilePath
Return FlowsheetOptions.FilePath
End Function
Public Function GetSimulationFileDirectory() As String Implements IFlowsheet.GetSimulationFileDirectory
Return Path.GetDirectoryName(FlowsheetOptions.FilePath)
End Function
Public Overridable Sub ClearLog() Implements IFlowsheet.ClearLog
End Sub
Public MustOverride Property SupressMessages As Boolean Implements IFlowsheet.SupressMessages
Private Sub IFlowsheet_RunScript(name As String) Implements IFlowsheet.RunScript
Dim script = Scripts.Where(Function(s) s.Value.Title = name).FirstOrDefault()
RunScript(script.Key)
End Sub
Public Property PythonPreprocessor() As Action(Of String) Implements IFlowsheet.PythonPreprocessor
Public Property AvailableExternalUnitOperations As Dictionary(Of String, IExternalUnitOperation) Implements IFlowsheet.AvailableExternalUnitOperations
Get
Return ExternalUnitOperations
End Get
Set(value As Dictionary(Of String, IExternalUnitOperation))
ExternalUnitOperations = value
End Set
End Property
Public Property AvailableSimulationObjects As Dictionary(Of String, ISimulationObject) Implements IFlowsheet.AvailableSimulationObjects
Get
Return ObjectList
End Get
Set(value As Dictionary(Of String, ISimulationObject))
ObjectList = value
End Set
End Property
Public Property Results As IFlowsheetResults = New SharedClasses.DWSIM.Flowsheet.FlowsheetResults() Implements IFlowsheet.Results
Public Property ParticleSizeDistributions As List(Of ISolidParticleSizeDistribution) = New List(Of ISolidParticleSizeDistribution) Implements IFlowsheet.ParticleSizeDistributions
Private Shared Function LoadFromExtensionsFolder(ByVal sender As Object, ByVal args As ResolveEventArgs) As Assembly
Dim assemblyPath1 As String = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly.Location), New AssemblyName(args.Name).Name + ".dll")
Dim assemblyPath2 As String = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly.Location), "extenders", New AssemblyName(args.Name).Name + ".dll")
If Not File.Exists(assemblyPath1) Then
If Not File.Exists(assemblyPath2) Then
'Console.WriteLine("Could not find assembly " + assemblyPath1)
Return Nothing
Else
Try
Dim assembly As Assembly = Assembly.LoadFrom(assemblyPath2)
Return assembly
Catch ex As System.IO.FileLoadException
'Console.WriteLine("Could not find assembly " + ex.FileName)
End Try
End If
Else
Try
Dim assembly As Assembly = Assembly.LoadFrom(assemblyPath1)
Return assembly
Catch ex As System.IO.FileLoadException
'Console.WriteLine("Could not find assembly " + ex.FileName)
End Try
End If
End Function
Public Sub ToggleFlowsheetAnimation() Implements IFlowsheet.ToggleFlowsheetAnimation
Throw New NotImplementedException()
End Sub
Public Function RunCodeOnUIThread2(act As Action) As Task Implements IFlowsheet.RunCodeOnUIThread2
Throw New NotImplementedException()
End Function
Public Function CreateConversionReaction(name As String, description As String, compounds_and_stoichcoeffs As Dictionary(Of String, Double),
basecompound As String, reactionphase As String, conversionExpression As String) As IReaction Implements IFlowsheet.CreateConversionReaction
Dim r As New Reaction()
r.ReactionType = ReactionType.Conversion
r.ID = name
r.Name = name
r.Description = description
For Each kvp In compounds_and_stoichcoeffs
r.Components.Add(kvp.Key, New ReactionStoichBase(kvp.Key, kvp.Value, False, 0, 0))
Next
r.Components(basecompound).IsBaseReactant = True
r.BaseReactant = basecompound
CalcReactionStoichiometry(r)
Select Case reactionphase.ToLower()
Case "mixture"
r.ReactionPhase = PhaseName.Mixture
Case "vapor"
r.ReactionPhase = PhaseName.Vapor
Case "liquid"
r.ReactionPhase = PhaseName.Liquid
Case "solid"
r.ReactionPhase = PhaseName.Solid
End Select
r.Expression = conversionExpression
Return r
End Function
Public Function CreateEquilibriumReaction(name As String, description As String, compounds_and_stoichcoeffs As Dictionary(Of String, Double),
basecompound As String, reactionphase As String, basis As String, units As String, Tapproach As Double,
lnKeq_fT As String) As IReaction Implements IFlowsheet.CreateEquilibriumReaction
Dim r As New Reaction()
r.ReactionType = ReactionType.Equilibrium
r.ID = name
r.Name = name
r.Description = description
For Each kvp In compounds_and_stoichcoeffs
r.Components.Add(kvp.Key, New ReactionStoichBase(kvp.Key, kvp.Value, False, 0, 0))
Next
r.Components(basecompound).IsBaseReactant = True
r.BaseReactant = basecompound
CalcReactionStoichiometry(r)
Select Case reactionphase.ToLower()
Case "mixture"
r.ReactionPhase = PhaseName.Mixture
Case "vapor"
r.ReactionPhase = PhaseName.Vapor
Case "liquid"
r.ReactionPhase = PhaseName.Liquid
Case "solid"
r.ReactionPhase = PhaseName.Solid
End Select
Select Case basis.ToLower()
Case "activity"
r.ReactionBasis = ReactionBasis.Activity
Case "fugacity"
r.ReactionBasis = ReactionBasis.Fugacity
Case "molar concentration"
r.ReactionBasis = ReactionBasis.MolarConc
Case "mass concentration"
r.ReactionBasis = ReactionBasis.MassConc
Case "molar fraction"
r.ReactionBasis = ReactionBasis.MolarFrac
Case "mass fraction"
r.ReactionBasis = ReactionBasis.MassFrac
Case "partial pressure"
r.ReactionBasis = ReactionBasis.PartialPress
End Select
r.EquilibriumReactionBasisUnits = units
r.Approach = Tapproach
If lnKeq_fT <> "" Then r.KExprType = KOpt.Expression Else r.KExprType = KOpt.Gibbs
r.Expression = lnKeq_fT
Return r
End Function
Public Function CreateKineticReaction(name As String, description As String, compounds_and_stoichcoeffs As Dictionary(Of String, Double),
directorders As Dictionary(Of String, Double), reverseorders As Dictionary(Of String, Double),
basecompound As String, reactionphase As String, basis As String, amountunits As String,
rateunits As String, Aforward As Double, Eforward As Double, Areverse As Double, Ereverse As Double,
Expr_forward As String, Expr_reverse As String) As IReaction Implements IFlowsheet.CreateKineticReaction
Dim r As New Reaction()
r.ReactionType = ReactionType.Kinetic
r.ID = name
r.Name = name
r.Description = description
For Each kvp In compounds_and_stoichcoeffs
r.Components.Add(kvp.Key, New ReactionStoichBase(kvp.Key, kvp.Value, False, directorders(kvp.Key), reverseorders(kvp.Key)))
Next
r.Components(basecompound).IsBaseReactant = True
r.BaseReactant = basecompound
CalcReactionStoichiometry(r)
Select Case reactionphase.ToLower()
Case "mixture"
r.ReactionPhase = PhaseName.Mixture
Case "vapor"
r.ReactionPhase = PhaseName.Vapor
Case "liquid"
r.ReactionPhase = PhaseName.Liquid
Case "solid"
r.ReactionPhase = PhaseName.Solid
End Select
Select Case basis.ToLower()
Case "activity"
r.ReactionBasis = ReactionBasis.Activity
Case "fugacity"
r.ReactionBasis = ReactionBasis.Fugacity
Case "molar concentration"
r.ReactionBasis = ReactionBasis.MolarConc
Case "mass concentration"
r.ReactionBasis = ReactionBasis.MassConc
Case "molar fraction"
r.ReactionBasis = ReactionBasis.MolarFrac
Case "mass fraction"
r.ReactionBasis = ReactionBasis.MassFrac
Case "partial pressure"
r.ReactionBasis = ReactionBasis.PartialPress
End Select
r.VelUnit = rateunits
r.ConcUnit = amountunits
r.A_Forward = Aforward
r.E_Forward = Eforward
r.A_Reverse = Areverse
r.E_Reverse = Ereverse
If Expr_forward <> "" Then
r.ReactionKinFwdType = ReactionKineticType.UserDefined
r.ReactionKinFwdExpression = Expr_forward
Else
r.ReactionKinFwdType = ReactionKineticType.Arrhenius
End If
If Expr_reverse <> "" Then
r.ReactionKinRevType = ReactionKineticType.UserDefined
r.ReactionKinRevExpression = Expr_reverse
Else
r.ReactionKinRevType = ReactionKineticType.Arrhenius
End If
Return r
End Function
Public Function CreateHetCatReaction(name As String, description As String, compounds_and_stoichcoeffs As Dictionary(Of String, Double),
basecompound As String, reactionphase As String, basis As String, amountunits As String,
rateunits As String, numeratorExpression As String, denominatorExpression As String) As IReaction Implements IFlowsheet.CreateHetCatReaction
Dim r As New Reaction()
r.ReactionType = ReactionType.Heterogeneous_Catalytic
r.ID = name
r.Name = name
r.Description = description
For Each kvp In compounds_and_stoichcoeffs
r.Components.Add(kvp.Key, New ReactionStoichBase(kvp.Key, kvp.Value, False, 0, 0))
Next
r.Components(basecompound).IsBaseReactant = True
r.BaseReactant = basecompound
CalcReactionStoichiometry(r)
Select Case reactionphase.ToLower()
Case "mixture"
r.ReactionPhase = PhaseName.Mixture
Case "vapor"
r.ReactionPhase = PhaseName.Vapor
Case "liquid"
r.ReactionPhase = PhaseName.Liquid
Case "solid"
r.ReactionPhase = PhaseName.Solid
End Select
Select Case basis.ToLower()
Case "activity"
r.ReactionBasis = ReactionBasis.Activity
Case "fugacity"
r.ReactionBasis = ReactionBasis.Fugacity
Case "molar concentration"
r.ReactionBasis = ReactionBasis.MolarConc
Case "mass concentration"
r.ReactionBasis = ReactionBasis.MassConc
Case "molar fraction"
r.ReactionBasis = ReactionBasis.MolarFrac
Case "mass fraction"
r.ReactionBasis = ReactionBasis.MassFrac
Case "partial pressure"
r.ReactionBasis = ReactionBasis.PartialPress
End Select
r.VelUnit = rateunits
r.ConcUnit = amountunits
r.RateEquationNumerator = numeratorExpression
r.RateEquationDenominator = denominatorExpression
Return r
End Function
Public Function CreateReactionSet(name As String, description As String) As IReactionSet Implements IFlowsheet.CreateReactionSet
Dim rs As New ReactionSet(name, name, description)
Return rs
End Function
Public Sub AddReaction(reaction As IReaction) Implements IFlowsheet.AddReaction
Reactions.Add(reaction.ID, reaction)
End Sub
Public Sub AddReactionSet(reactionSet As IReactionSet) Implements IFlowsheet.AddReactionSet
ReactionSets.Add(reactionSet.ID, reactionSet)
End Sub
Public Sub AddReactionToSet(reactionID As String, reactionSetID As String, enabled As Boolean, rank As Integer) Implements IFlowsheet.AddReactionToSet
ReactionSets(reactionSetID).Reactions.Add(reactionID, New ReactionSetBase(reactionID, rank, enabled))
End Sub
Public Function GetAvailablePropertyPackages() As List(Of String) Implements IFlowsheet.GetAvailablePropertyPackages
Return AvailablePropertyPackages.Keys.ToList()
End Function
Public Function CreatePropertyPackage(name As String) As IPropertyPackage Implements IFlowsheet.CreatePropertyPackage
Dim pp = AvailablePropertyPackages(name).Clone()
pp.Tag = pp.ComponentName
Return pp
End Function
Public Function CreateAndAddPropertyPackage(name As String) As IPropertyPackage Implements IFlowsheet.CreateAndAddPropertyPackage
Dim pp = AvailablePropertyPackages(name).Clone()
pp.Tag = pp.ComponentName
AddPropertyPackage(pp)
Return pp
End Function
Public Function AddCompound(compname As String) As ICompoundConstantProperties Implements IFlowsheet.AddCompound
Dim c = GetCompound(compname)
Options.SelectedComponents.Add(c.Name, c)
If Options.NotSelectedComponents.ContainsKey(c.Name) Then Options.NotSelectedComponents.Remove(c.Name)
Return c
End Function
Private Sub CalcReactionStoichiometry(rc As IReaction)
Dim hp, hr, bp, br, brsc, gp, gr As Double
Dim eq As String = ""
'build reaction equation
'scan for reactants
For Each c In rc.Components
Dim comp = Options.SelectedComponents(c.Key)
If c.Value.StoichCoeff < 0 Then
If c.Value.StoichCoeff = -1 Then
eq += comp.Formula & " + "
Else
eq += Math.Abs(c.Value.StoichCoeff) & comp.Formula & " + "
End If
hr += Math.Abs(c.Value.StoichCoeff) * comp.IG_Enthalpy_of_Formation_25C * comp.Molar_Weight
br += Math.Abs(c.Value.StoichCoeff) * comp.Molar_Weight
gr += Math.Abs(c.Value.StoichCoeff) * comp.IG_Gibbs_Energy_of_Formation_25C * comp.Molar_Weight
End If
Next
If eq.Length >= 2 Then eq = eq.Remove(eq.Length - 2, 2)
eq += "<--> "
'scan for products
For Each c In rc.Components
Dim comp = Options.SelectedComponents(c.Key)
If c.Value.StoichCoeff > 0 Then
If c.Value.StoichCoeff = 1 Then
eq += comp.Formula & " + "
Else
eq += Math.Abs(c.Value.StoichCoeff) & comp.Formula & " + "
End If
hp += Math.Abs(c.Value.StoichCoeff) * comp.IG_Enthalpy_of_Formation_25C * comp.Molar_Weight
bp += Math.Abs(c.Value.StoichCoeff) * comp.Molar_Weight
gp += Math.Abs(c.Value.StoichCoeff) * comp.IG_Gibbs_Energy_of_Formation_25C * comp.Molar_Weight
End If
Next
eq = eq.Remove(eq.Length - 2, 2)
brsc = Math.Abs(rc.Components.Where(Function(c) c.Value.IsBaseReactant).FirstOrDefault().Value.StoichCoeff)
rc.ReactionHeat = (hp - hr) / brsc
rc.ReactionGibbsEnergy = (gp - gr) / brsc
rc.StoichBalance = bp - br
rc.Equation = eq
End Sub
Public Sub SetDirtyStatus() Implements IFlowsheet.SetDirtyStatus
For Each obj In SimulationObjects.Values
obj.SetDirtyStatus(True)
Next
End Sub
Public Sub DisplayBrowserWindow(url As String) Implements IFlowsheet.DisplayBrowserWindow
Throw New NotImplementedException()
End Sub
Public Sub DisplayDockableBrowserWindow(url As String) Implements IFlowsheet.DisplayDockableBrowserWindow
Throw New NotImplementedException()
End Sub
Public Sub ReleaseResources() Implements IFlowsheet.ReleaseResources
Me.ProcessScripts(Enums.Scripts.EventType.SimulationClosed, Enums.Scripts.ObjectType.Simulation, "")
'dispose objects
Try
FileDatabaseProvider.ReleaseDatabase()
Catch ex As Exception
End Try
For Each obj As MaterialStream In SimulationObjects.Values.Where(Function(so) TypeOf so Is MaterialStream)
For Each p In obj.Phases.Values
p.Compounds.Clear()
Next
obj.Dispose()
obj.SetFlowsheet(Nothing)
Next
'For Each uobj As SharedClasses.UnitOperations.BaseClass In SimulationObjects.Values
' uobj.GraphicObject = Nothing
' Try
' If uobj.disposedValue = False Then
' uobj.Dispose()
' uobj = Nothing
' End If
' Catch ex As Exception
' End Try
'Next
'For Each gobj In GraphicObjects.Values
' gobj.Owner = Nothing
'Next
FlowsheetSurface = Nothing
FileDatabaseProvider = Nothing
GraphicObjects.Clear()
SimulationObjects.Clear()
OptimizationCollection.Clear()
SensAnalysisCollection.Clear()
PropertyPackages.Clear()
SelectedCompounds.Clear()
Options.SelectedComponents = Nothing
Options.NotSelectedComponents = Nothing
Options.SelectedUnitSystem = Nothing
Options.SelectedUnitSystem1 = Nothing
Options = Nothing
End Sub
#Region " Snapshots"
Public Sub RegisterSnapshot(stype As SnapshotType, Optional obj As ISimulationObject = Nothing) Implements IFlowsheet.RegisterSnapshot
If Options.EnabledUndoRedo Then
Dim sdata = GetSnapshot(stype, obj)
UndoStack.Push(New Tuple(Of SnapshotType, XDocument)(stype, sdata))
RedoStack.Clear()
End If
End Sub
Public Function GetSnapshot(stype As SnapshotType, Optional obj As ISimulationObject = Nothing) As XDocument Implements IFlowsheet.GetSnapshot
Dim xdoc As New XDocument()
Dim xel As XElement
Dim ci As CultureInfo = CultureInfo.InvariantCulture
Dim IncludeObjectData, IncludeObjectLayout, RestoreObjects, IncludeCompounds, IncludeReactionSubsystem, IncludePropertyPackages,
IncludeSpreadsheet, IncludeSimulationSettings, IncludeWindowLayout As Boolean
Select Case stype
Case SnapshotType.All
IncludeCompounds = True
IncludeObjectData = True
IncludeObjectLayout = True
IncludePropertyPackages = True
IncludeReactionSubsystem = True
IncludeSimulationSettings = True
IncludeSpreadsheet = True
IncludeWindowLayout = True
RestoreObjects = True
Case SnapshotType.Compounds
IncludeCompounds = True
Case SnapshotType.ObjectAddedOrRemoved
RestoreObjects = True
Case SnapshotType.ObjectData
IncludeObjectData = True
Case SnapshotType.ObjectLayout
IncludeObjectLayout = True
Case SnapshotType.PropertyPackages
IncludePropertyPackages = True
Case SnapshotType.ReactionSubsystem
IncludeReactionSubsystem = True
Case SnapshotType.SimulationSettings
IncludeSimulationSettings = True
Case SnapshotType.Spreadsheet
IncludeSpreadsheet = True
Case SnapshotType.WindowLayout
IncludeWindowLayout = True
End Select
xdoc.Add(New XElement("DWSIM_Simulation_Data"))
If IncludeObjectData Or IncludeObjectLayout Then
If IncludeObjectData Then
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("SimulationObjects"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects")
If obj Is Nothing Then
For Each obj In SimulationObjects.Values
obj.SetFlowsheet(Me)
xel.Add(New XElement("SimulationObject", {obj.SaveData().ToArray()}))
Next
Else
SimulationObjects(obj.Name).SetFlowsheet(Me)
xel.Add(New XElement("SimulationObject", {SimulationObjects(obj.Name).SaveData().ToArray()}))
End If
Else 'includeobjectlayout
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("GraphicObjects"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects")
For Each go As GraphicObject In GraphicObjects.Values
If Not go.IsConnector And Not go.ObjectType = ObjectType.GO_FloatingTable Then xel.Add(New XElement("GraphicObject", go.SaveData().ToArray()))
Next
End If
Else
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Settings"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Settings")
xel.Add(Options.SaveData().ToArray())
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("DynamicProperties"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicProperties")
Dim extraprops = DirectCast(ExtraProperties, IDictionary(Of String, Object))
For Each item In extraprops
Try
xel.Add(New XElement("Property", {New XElement("Name", item.Key),
New XElement("PropertyType", item.Value.GetType.ToString),
New XElement("Data", Newtonsoft.Json.JsonConvert.SerializeObject(item.Value))}))
Catch ex As Exception
End Try
Next
If RestoreObjects Then
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("GraphicObjects"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects")
For Each go As GraphicObject In GraphicObjects.Values
If Not go.IsConnector And Not go.ObjectType = ObjectType.GO_FloatingTable Then xel.Add(New XElement("GraphicObject", go.SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("SimulationObjects"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects")
For Each so As SharedClasses.UnitOperations.BaseClass In SimulationObjects.Values
so.SetFlowsheet(Me)
xel.Add(New XElement("SimulationObject", {so.SaveData().ToArray()}))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("DynamicsManager"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicsManager")
xel.Add(DirectCast(DynamicsManager, ICustomXMLSerialization).SaveData().ToArray())
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ScriptItems"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ScriptItems")
For Each scr As Script In Scripts.Values
xel.Add(New XElement("ScriptItem", scr.SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ChartItems"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ChartItems")
For Each ch As SharedClasses.Charts.Chart In Charts.Values
xel.Add(New XElement("ChartItem", ch.SaveData().ToArray()))
Next
End If
If IncludePropertyPackages Then
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("PropertyPackages"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("PropertyPackages")
For Each pp In Options.PropertyPackages
Dim createdms As Boolean = False
If pp.Value.CurrentMaterialStream Is Nothing Then
Dim ms As New Streams.MaterialStream("", "", Me, pp.Value)
AddCompoundsToMaterialStream(ms)
pp.Value.CurrentMaterialStream = ms
createdms = True
End If
xel.Add(New XElement("PropertyPackage", {New XElement("ID", pp.Key),
DirectCast(pp.Value, Interfaces.ICustomXMLSerialization).SaveData().ToArray()}))
If createdms Then pp.Value.CurrentMaterialStream = Nothing
Next
End If
If IncludeCompounds Then
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Compounds"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Compounds")
For Each cp As ConstantProperties In Options.SelectedComponents.Values
xel.Add(New XElement("Compound", cp.SaveData().ToArray()))
Next
End If
If IncludeReactionSubsystem Then
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("ReactionSets"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("ReactionSets")
For Each pp As KeyValuePair(Of String, Interfaces.IReactionSet) In Options.ReactionSets
xel.Add(New XElement("ReactionSet", DirectCast(pp.Value, Interfaces.ICustomXMLSerialization).SaveData().ToArray()))
Next
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Reactions"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Reactions")
For Each pp As KeyValuePair(Of String, Interfaces.IReaction) In Options.Reactions
xel.Add(New XElement("Reaction", {DirectCast(pp.Value, Interfaces.ICustomXMLSerialization).SaveData().ToArray()}))
Next
End If
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("MessagesLog"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("MessagesLog")
Dim inner_elements As New List(Of XElement)
For Each item In MessagesLog
inner_elements.Add(New XElement("Message", item))
Next
xel.Add(inner_elements)
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("Results"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("Results")
xel.Add(DirectCast(Results, ICustomXMLSerialization).SaveData().ToArray())
xdoc.Element("DWSIM_Simulation_Data").Add(New XElement("GHGCompositions"))
xel = xdoc.Element("DWSIM_Simulation_Data").Element("GHGCompositions")
For Each ghgcomp In GHGEmissionCompositions.Values
xel.Add(New XElement("GHGComposition", DirectCast(ghgcomp, ICustomXMLSerialization).SaveData().ToArray()))
Next
End If
Return xdoc
End Function
Public Sub RestoreSnapshot(xdata As XDocument, stype As SnapshotType) Implements IFlowsheet.RestoreSnapshot
Dim ci As CultureInfo = CultureInfo.InvariantCulture
Dim excs As New Concurrent.ConcurrentBag(Of Exception)
Dim xdoc As XDocument = xdata
Dim data As List(Of XElement) = Nothing
Select Case stype
Case SnapshotType.ObjectData, SnapshotType.ObjectLayout
If stype = SnapshotType.ObjectData Then
If xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects").Elements.ToList
For Each xel In data
Dim id As String = xel.<Name>.Value
Dim obj As ISimulationObject = SimulationObjects(id)
obj.LoadData(xel.Elements.ToList)
obj.GraphicObject = GraphicObjects(id)
obj.SetFlowsheet(Me)
If TypeOf obj Is Streams.MaterialStream Then
For Each phase As BaseClasses.Phase In DirectCast(obj, Streams.MaterialStream).Phases.Values
For Each c As ConstantProperties In Options.SelectedComponents.Values
phase.Compounds(c.Name).ConstantProperties = c
Next
Next
ElseIf TypeOf obj Is CapeOpenUO Then
If DirectCast(obj, CapeOpenUO)._seluo.Name.ToLower.Contains("chemsep") Then
DirectCast(obj.GraphicObject, Shapes.CAPEOPENGraphic).ChemSep = True
If obj.GraphicObject.Height = 40 And obj.GraphicObject.Width = 40 Then
obj.GraphicObject.Width = 144
obj.GraphicObject.Height = 180
End If
End If
ElseIf TypeOf obj Is Input Then
GraphicObjectControlPanelModeEditors.SetInputDelegate(obj.GraphicObject, obj)
ElseIf TypeOf obj Is PIDController Then
GraphicObjectControlPanelModeEditors.SetPIDDelegate(obj.GraphicObject, obj)
End If
Next
ResetCalculationStatus()
End If
Else
If xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects").Elements.ToList
'graphic objects
For Each xel As XElement In data
Dim id As String = xel.<Name>.Value
Dim obj As GraphicObject = GraphicObjects(id)
obj.LoadData(xel.Elements.ToList)
If SimulationObjects.ContainsKey(id) Then
obj.Owner = SimulationObjects(id)
End If
obj.Flowsheet = Me
Next
End If
End If
Case Else
If xdoc.Element("DWSIM_Simulation_Data").Element("Results") IsNot Nothing Then
Results = New SharedClasses.DWSIM.Flowsheet.FlowsheetResults
data = xdoc.Element("DWSIM_Simulation_Data").Element("Results").Elements.ToList
DirectCast(Results, ICustomXMLSerialization).LoadData(data)
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("GHGCompositions") IsNot Nothing Then
GHGEmissionCompositions = New Dictionary(Of String, IGHGComposition)()
data = xdoc.Element("DWSIM_Simulation_Data").Element("GHGCompositions").Elements.ToList
For Each xel As XElement In data
Try
Dim obj As New GHGEmissionComposition()
obj.LoadData(xel.Elements.ToList)
GHGEmissionCompositions.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading GHG Composition Item Information", ex))
End Try
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("Settings") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("Settings").Elements.ToList
Try
Options.LoadData(data)
Options.EnabledUndoRedo = False
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Settings", ex))
End Try
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("GraphicObjects").Elements.ToList
'graphic objects
GraphicObjects.Clear()
For Each xel As XElement In data
Try
xel.Element("Type").Value = xel.Element("Type").Value.Replace("Microsoft.MSDN.Samples.GraphicObjects", "DWSIM.DrawingTools.GraphicObjects")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Ajuste", "OT_Adjust")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Especificacao", "OT_Spec")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("OT_Reciclo", "OT_Recycle")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("GO_Texto", "GO_Text")
xel.Element("ObjectType").Value = xel.Element("ObjectType").Value.Replace("GO_Figura", "GO_Image")
Dim obj As GraphicObject = Nothing
Dim t As Type = Type.GetType(xel.Element("Type").Value, False)
If Not t Is Nothing Then obj = Activator.CreateInstance(t)
If obj Is Nothing Then
If xel.Element("Type").Value.Contains("OxyPlotGraphic") Then
obj = CType(Drawing.SkiaSharp.Extended.Shared.ReturnInstance(xel.Element("Type").Value.Replace("Shapes", "Charts")), GraphicObject)
Else
obj = CType(GraphicObject.ReturnInstance(xel.Element("Type").Value), GraphicObject)
End If
End If
If Not obj Is Nothing Then
obj.LoadData(xel.Elements.ToList)
If TypeOf obj Is TableGraphic Then
DirectCast(obj, TableGraphic).Flowsheet = Me
ElseIf TypeOf obj Is MasterTableGraphic Then
DirectCast(obj, MasterTableGraphic).Flowsheet = Me
ElseIf TypeOf obj Is SpreadsheetTableGraphic Then
DirectCast(obj, SpreadsheetTableGraphic).Flowsheet = Me
ElseIf TypeOf obj Is Charts.OxyPlotGraphic Then
DirectCast(obj, Charts.OxyPlotGraphic).Flowsheet = Me
ElseIf TypeOf obj Is Shapes.RigorousColumnGraphic Or TypeOf obj Is Shapes.AbsorptionColumnGraphic Or TypeOf obj Is Shapes.CAPEOPENGraphic Then
obj.CreateConnectors(xel.Element("InputConnectors").Elements.Count, xel.Element("OutputConnectors").Elements.Count)
obj.PositionConnectors()
ElseIf TypeOf obj Is Shapes.ExternalUnitOperationGraphic Then
Dim euo = AvailableExternalUnitOperations.Values.Where(Function(x) x.Description = obj.Description).FirstOrDefault
If euo IsNot Nothing Then
obj.Owner = euo
DirectCast(euo, Interfaces.ISimulationObject).GraphicObject = obj
obj.CreateConnectors(0, 0)
obj.Owner = Nothing
DirectCast(euo, Interfaces.ISimulationObject).GraphicObject = Nothing
End If
Else
If obj.Name = "" Then obj.Name = obj.Tag
obj.CreateConnectors(0, 0)
End If
obj.Flowsheet = Me
GraphicObjects.Add(obj.Name, obj)
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Graphic Objects", ex))
End Try
Next
For Each xel As XElement In data
Try
Dim id As String = xel.Element("Name").Value
If id <> "" Then
Dim obj As GraphicObject = (From go As GraphicObject In GraphicObjects.Values Where go.Name = id).SingleOrDefault
If obj Is Nothing Then obj = (From go As GraphicObject In GraphicObjects.Values Where go.Name = xel.Element("Name").Value).SingleOrDefault
If obj IsNot Nothing Then
If xel.Element("InputConnectors") IsNot Nothing Then
Dim i As Integer = 0
For Each xel2 As XElement In xel.Element("InputConnectors").Elements
If xel2.@IsAttached = True Then
obj.InputConnectors(i).ConnectorName = xel2.@AttachedFromObjID & "|" & xel2.@AttachedFromConnIndex
obj.InputConnectors(i).Type = [Enum].Parse(obj.InputConnectors(i).Type.GetType, xel2.@ConnType)
End If
i += 1
Next
End If
End If
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Object Connection Information", ex))
End Try
Next
For Each xel As XElement In data
Try
Dim id As String = xel.Element("Name").Value
If id <> "" Then
Dim obj As GraphicObject = (From go As GraphicObject In GraphicObjects.Values Where go.Name = id).SingleOrDefault
If obj IsNot Nothing Then
If xel.Element("OutputConnectors") IsNot Nothing Then
For Each xel2 As XElement In xel.Element("OutputConnectors").Elements
If xel2.@IsAttached = True Then
Dim objToID = xel2.@AttachedToObjID
If objToID <> "" Then
Dim objTo As GraphicObject = (From go As GraphicObject In GraphicObjects.Values Where go.Name = objToID).SingleOrDefault
If objTo Is Nothing Then
objTo = (From go As GraphicObject In GraphicObjects.Values Where go.Name = xel2.@AttachedToObjID).SingleOrDefault
End If
Dim fromidx As Integer = -1
Dim cp As ConnectionPoint = (From cp2 As ConnectionPoint In objTo.InputConnectors Select cp2 Where cp2.ConnectorName.Split("|")(0) = obj.Name).SingleOrDefault
If cp Is Nothing Then
cp = (From cp2 As ConnectionPoint In objTo.InputConnectors Select cp2 Where cp2.ConnectorName.Split("|")(0) = xel2.@AttachedToObjID).SingleOrDefault
End If
If Not cp Is Nothing Then
fromidx = cp.ConnectorName.Split("|")(1)
End If
If Not obj Is Nothing And Not objTo Is Nothing Then
ConnectObject(obj, objTo, fromidx, xel2.@AttachedToConnIndex)
End If
End If
End If
Next
End If
If xel.Element("EnergyConnector") IsNot Nothing Then
For Each xel2 As XElement In xel.Element("EnergyConnector").Elements
If xel2.@IsAttached = True Then
Dim objToID = xel2.@AttachedToObjID
If objToID <> "" Then
Dim objTo As GraphicObject = (From go As GraphicObject In
GraphicObjects.Values Where go.Name = objToID).SingleOrDefault
If objTo Is Nothing Then
obj = (From go As GraphicObject In GraphicObjects.Values Where go.Name = xel2.@AttachedToObjID).SingleOrDefault
End If
If Not obj Is Nothing And Not objTo Is Nothing Then
ConnectObject(obj, objTo, -1, xel2.@AttachedToConnIndex)
End If
End If
End If
Next
End If
End If
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Flowsheet Object Connection Information", ex))
End Try
Next
For Each obj In GraphicObjects.Values
If obj.ObjectType = ObjectType.GO_SpreadsheetTable Then
DirectCast(obj, SpreadsheetTableGraphic).Flowsheet = Me
End If
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("Compounds") IsNot Nothing Then
'compounds
Options.SelectedComponents.Clear()
data = xdoc.Element("DWSIM_Simulation_Data").Element("Compounds").Elements.ToList
For Each xel As XElement In data
Dim obj As New ConstantProperties
obj.Name = xel.Element("Name").Value
If Not AvailableCompounds.ContainsKey(obj.Name) Then AvailableCompounds.Add(obj.Name, obj)
Options.SelectedComponents.Add(obj.Name, obj)
Next
Parallel.ForEach(data, Sub(xel)
Try
Options.SelectedComponents(xel.Element("Name").Value).LoadData(xel.Elements.ToList)
Catch ex As Exception
excs.Add(New Exception("Error Loading Compound Information", ex))
End Try
End Sub)
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("DynamicProperties") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicProperties").Elements.ToList
Try
ExtraProperties = New ExpandoObject
If Not data Is Nothing Then
For Each xel As XElement In data
Try
Dim propname = xel.Element("Name").Value
Dim proptype = xel.Element("PropertyType").Value
Dim assembly1 As Assembly = Nothing
For Each assembly In AppDomain.CurrentDomain.GetAssemblies()
If proptype.Contains(assembly.GetName().Name) Then
assembly1 = assembly
Exit For
End If
Next
If assembly1 IsNot Nothing Then
Dim ptype As Type = assembly1.GetType(proptype)
Dim propval = Newtonsoft.Json.JsonConvert.DeserializeObject(xel.Element("Data").Value, ptype)
DirectCast(ExtraProperties, IDictionary(Of String, Object))(propname) = propval
End If
Catch ex As Exception
End Try
Next
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Dynamic Properties", ex))
End Try
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("PropertyPackages") IsNot Nothing Then
Options.PropertyPackages.Clear()
Dim pp As New PropertyPackages.RaoultPropertyPackage
data = xdoc.Element("DWSIM_Simulation_Data").Element("PropertyPackages").Elements.ToList
For Each xel As XElement In data
Try
xel.Element("Type").Value = xel.Element("Type").Value.Replace("DWSIM.DWSIM.SimulationObjects", "DWSIM.Thermodynamics")
Dim obj As PropertyPackages.PropertyPackage = Nothing
If xel.Element("Type").Value.Contains("ThermoC") Then
Dim thermockey As String = "ThermoC Bridge"
If AvailablePropertyPackages.ContainsKey(thermockey) Then
obj = AvailablePropertyPackages(thermockey).ReturnInstance(xel.Element("Type").Value)
End If
Else
Dim ppkey As String = xel.Element("ComponentName").Value
If ppkey = "" Then
obj = CType(New PropertyPackages.RaoultPropertyPackage().ReturnInstance(xel.Element("Type").Value), PropertyPackages.PropertyPackage)
Else
Dim ptype = xel.Element("Type").Value
If ppkey.Contains("1978") And ptype.Contains("PengRobinsonPropertyPackage") Then
ptype = ptype.Replace("PengRobinson", "PengRobinson1978")
End If
If AvailablePropertyPackages.ContainsKey(ppkey) Then
obj = AvailablePropertyPackages(ppkey).ReturnInstance(ptype)
End If
End If
End If
DirectCast(obj, Interfaces.ICustomXMLSerialization).LoadData(xel.Elements.ToList)
Dim newID As String = Guid.NewGuid.ToString
If Options.PropertyPackages.ContainsKey(obj.UniqueID) Then obj.UniqueID = newID
obj.Flowsheet = Me
Options.PropertyPackages.Add(obj.UniqueID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Property Package Information", ex))
End Try
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects") IsNot Nothing Then
SimulationObjects.Clear()
data = xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects").Elements.ToList
Dim objlist As New Concurrent.ConcurrentBag(Of SharedClasses.UnitOperations.BaseClass)
Dim fsuocount = (From go As GraphicObject In SimulationObjects.Values Where go.ObjectType = ObjectType.FlowsheetUO).Count
For Each xel In data
Try
Dim id As String = xel.<Name>.Value
Dim obj As SharedClasses.UnitOperations.BaseClass = Nothing
If xel.Element("Type").Value.Contains("Streams.MaterialStream") Then
obj = New Streams.MaterialStream()
Else
Dim uokey As String = xel.Element("ComponentDescription").Value
If AvailableExternalUnitOperations.ContainsKey(uokey) Then
obj = AvailableExternalUnitOperations(uokey).ReturnInstance(xel.Element("Type").Value)
Else
obj = UnitOperations.Resolver.ReturnInstance(xel.Element("Type").Value)
End If
End If
Dim gobj As GraphicObject = (From go As GraphicObject In
GraphicObjects.Values Where go.Name = id).SingleOrDefault
obj.GraphicObject = gobj
gobj.Owner = obj
obj.SetFlowsheet(Me)
If Not gobj Is Nothing Then
obj.LoadData(xel.Elements.ToList)
If TypeOf obj Is Streams.MaterialStream Then
For Each phase As BaseClasses.Phase In DirectCast(obj, Streams.MaterialStream).Phases.Values
For Each c As ConstantProperties In Options.SelectedComponents.Values
phase.Compounds(c.Name).ConstantProperties = c
Next
Next
ElseIf TypeOf obj Is CapeOpenUO Then
If DirectCast(obj, CapeOpenUO)._seluo.Name.ToLower.Contains("chemsep") Then
DirectCast(gobj, Shapes.CAPEOPENGraphic).ChemSep = True
If gobj.Height = 40 And gobj.Width = 40 Then
gobj.Width = 144
gobj.Height = 180
End If
End If
ElseIf TypeOf obj Is Input Then
GraphicObjectControlPanelModeEditors.SetInputDelegate(gobj, obj)
ElseIf TypeOf obj Is PIDController Then
GraphicObjectControlPanelModeEditors.SetPIDDelegate(gobj, obj)
End If
End If
objlist.Add(obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Unit Operation Information", ex))
End Try
Next
'simulation objects
For Each obj In objlist
Try
Dim id = obj.Name
SimulationObjects.Add(id, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Unit Operation Information", ex))
End Try
Next
For Each so As SharedClasses.UnitOperations.BaseClass In SimulationObjects.Values
Try
If TryCast(so, Adjust) IsNot Nothing Then
Dim so2 As Adjust = so
If SimulationObjects.ContainsKey(so2.ManipulatedObjectData.ID) Then
so2.ManipulatedObject = SimulationObjects(so2.ManipulatedObjectData.ID)
DirectCast(so2.GraphicObject, Shapes.AdjustGraphic).ConnectedToMv = so2.ManipulatedObject.GraphicObject
End If
If SimulationObjects.ContainsKey(so2.ControlledObjectData.ID) Then
so2.ControlledObject = SimulationObjects(so2.ControlledObjectData.ID)
DirectCast(so2.GraphicObject, Shapes.AdjustGraphic).ConnectedToCv = so2.ControlledObject.GraphicObject
End If
If SimulationObjects.ContainsKey(so2.ReferencedObjectData.ID) Then
so2.ReferenceObject = SimulationObjects(so2.ReferencedObjectData.ID)
DirectCast(so2.GraphicObject, Shapes.AdjustGraphic).ConnectedToRv = so2.ReferenceObject.GraphicObject
End If
End If
If TryCast(so, Spec) IsNot Nothing Then
Dim so2 As Spec = so
If SimulationObjects.ContainsKey(so2.TargetObjectData.ID) Then
so2.TargetObject = SimulationObjects(so2.TargetObjectData.ID)
DirectCast(so2.GraphicObject, Shapes.SpecGraphic).ConnectedToTv = so2.TargetObject.GraphicObject
End If
If SimulationObjects.ContainsKey(so2.SourceObjectData.ID) Then
so2.SourceObject = SimulationObjects(so2.SourceObjectData.ID)
DirectCast(so2.GraphicObject, Shapes.SpecGraphic).ConnectedToSv = so2.SourceObject.GraphicObject
End If
End If
If TryCast(so, CapeOpenUO) IsNot Nothing Then
DirectCast(so, CapeOpenUO).UpdateConnectors2()
DirectCast(so, CapeOpenUO).UpdatePortsFromConnectors()
End If
Catch ex As Exception
excs.Add(New Exception("Error Loading Unit Operation Connection Information", ex))
End Try
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("ReactionSets") IsNot Nothing Then
'reactions
data = xdoc.Element("DWSIM_Simulation_Data").Element("ReactionSets").Elements.ToList
Options.ReactionSets.Clear()
For Each xel As XElement In data
Try
Dim obj As New ReactionSet()
obj.LoadData(xel.Elements.ToList)
Options.ReactionSets.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Reaction Set Information", ex))
End Try
Next
data = xdoc.Element("DWSIM_Simulation_Data").Element("Reactions").Elements.ToList
Options.Reactions.Clear()
For Each xel As XElement In data
Try
Dim obj As New Reaction()
obj.LoadData(xel.Elements.ToList)
Options.Reactions.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Reaction Information", ex))
End Try
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("DynamicsManager") IsNot Nothing Then
data = xdoc.Element("DWSIM_Simulation_Data").Element("DynamicsManager").Elements.ToList
Try
DirectCast(DynamicsManager, ICustomXMLSerialization).LoadData(data)
Catch ex As Exception
excs.Add(New Exception("Error Loading Dynamics Manager Information", ex))
End Try
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("ScriptItems") IsNot Nothing Then
Scripts = New Dictionary(Of String, Interfaces.IScript)
data = xdoc.Element("DWSIM_Simulation_Data").Element("ScriptItems").Elements.ToList
Dim i As Integer = 0
For Each xel As XElement In data
Try
Dim obj As New Script()
obj.LoadData(xel.Elements.ToList)
Scripts.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Script Item Information", ex))
End Try
i += 1
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("ChartItems") IsNot Nothing Then
Charts = New Dictionary(Of String, Interfaces.IChart)
data = xdoc.Element("DWSIM_Simulation_Data").Element("ChartItems").Elements.ToList
Dim i As Integer = 0
For Each xel As XElement In data
Try
Dim obj As New SharedClasses.Charts.Chart()
obj.LoadData(xel.Elements.ToList)
Charts.Add(obj.ID, obj)
Catch ex As Exception
excs.Add(New Exception("Error Loading Chart Item Information", ex))
End Try
i += 1
Next
End If
If xdoc.Element("DWSIM_Simulation_Data").Element("MessagesLog") IsNot Nothing Then
MessagesLog.Clear()
Try
data = xdoc.Element("DWSIM_Simulation_Data").Element("MessagesLog").Elements.ToList
For Each xel As XElement In data
MessagesLog.Add(xel.Value)
Next
Catch ex As Exception
End Try
End If
End Select
If excs.Count > 0 Then
End If
End Sub
Private Function GetSnapshotObjectID(xdoc As XDocument) As String
Return xdoc.Element("DWSIM_Simulation_Data").Element("SimulationObjects").Elements.FirstOrDefault().<Name>.Value
End Function
#End Region
#Region " Undo/Redo"
Sub AddUndoRedoAction(act As Interfaces.IUndoRedoAction) Implements IFlowsheet.AddUndoRedoAction
If Options.EnabledUndoRedo AndAlso Me.MasterFlowsheet Is Nothing Then
UndoStack.Push(New Tuple(Of SnapshotType, XDocument)(SnapshotType.All, GetSnapshot(SnapshotType.All)))
RedoStack.Clear()
End If
End Sub
Public Sub ProcessUndo()
If Options.EnabledUndoRedo AndAlso UndoStack.Count > 0 Then
Dim xdata = UndoStack.Pop()
Options.EnabledUndoRedo = False
Dim current As XDocument = Nothing
If xdata.Item1 = SnapshotType.ObjectData Then
Dim objID = GetSnapshotObjectID(xdata.Item2)
current = GetSnapshot(SnapshotType.ObjectData, SimulationObjects(objID))
Else
current = GetSnapshot(xdata.Item1)
End If
If xdata.Item1 = SnapshotType.ObjectAddedOrRemoved Or xdata.Item1 = SnapshotType.All Then CloseOpenEditForms()
RestoreSnapshot(xdata.Item2, xdata.Item1)
UpdateInterface()
UpdateOpenEditForms()
Options.EnabledUndoRedo = True
RedoStack.Push(New Tuple(Of SnapshotType, XDocument)(xdata.Item1, current))
End If
End Sub
Public Sub ProcessRedo()
If Options.EnabledUndoRedo AndAlso RedoStack.Count > 0 Then
Dim xdata = RedoStack.Pop()
Options.EnabledUndoRedo = False
Dim current As XDocument = Nothing
If xdata.Item1 = SnapshotType.ObjectData Then
Dim objID = GetSnapshotObjectID(xdata.Item2)
current = GetSnapshot(SnapshotType.ObjectData, SimulationObjects(objID))
Else
current = GetSnapshot(xdata.Item1)
End If
If xdata.Item1 = SnapshotType.ObjectAddedOrRemoved Or xdata.Item1 = SnapshotType.All Then CloseOpenEditForms()
RestoreSnapshot(xdata.Item2, xdata.Item1)
UpdateInterface()
UpdateOpenEditForms()
Options.EnabledUndoRedo = True
UndoStack.Push(New Tuple(Of SnapshotType, XDocument)(xdata.Item1, current))
End If
End Sub
Public Overridable Function Clone() As IFlowsheet Implements IFlowsheet.Clone
Throw New NotImplementedException()
End Function
Public Function GetResultIDs() As List(Of String) Implements IFlowsheet.GetResultIDs
Dim props As New List(Of String) From {
"Total GHG Mass Emissions",
"Total GHG Molar Emissions",
"Total CO2eq GHG Mass Emissions",
"Total CO2eq GHG Molar Emissions",
"Residual Mass Balance",
"Total Energy Balance",
"Total CAPEX",
"Total OPEX"
}
Dim extraprops = DirectCast(Results.Additional, IDictionary(Of String, Object))
For Each item In extraprops
props.Add(item.Key)
Next
Return props
End Function
Public Function GetResultValue(id As String) As Double Implements IFlowsheet.GetResultValue
Select Case id
Case "Total GHG Mass Emissions"
Return Results.GHGEmissionsSummary.TotalGHGMassEmission.ConvertFromSI(Options.SelectedUnitSystem.massflow)
Case "Total GHG Molar Emissions"
Return Results.GHGEmissionsSummary.TotalGHGMolarEmission.ConvertFromSI(Options.SelectedUnitSystem.molarflow)
Case "Total CO2eq GHG Mass Emissions"
Return Results.GHGEmissionsSummary.TotalCO2eqMassEmission.ConvertFromSI(Options.SelectedUnitSystem.massflow)
Case "Total CO2eq GHG Molar Emissions"
Return Results.GHGEmissionsSummary.TotalCO2eqMolarEmission.ConvertFromSI(Options.SelectedUnitSystem.molarflow)
Case "Total CAPEX"
Return Results.TotalCAPEX
Case "Total OPEX"
Return Results.TotalOPEX
Case "Residual Mass Balance"
Return Results.ResidualMassBalance.ConvertFromSI(Options.SelectedUnitSystem.massflow)
Case "Total Energy Balance"
Return Results.TotalEnergyBalance.ConvertFromSI(Options.SelectedUnitSystem.heatflow)
Case Else
Dim extraprops = DirectCast(Results.Additional, IDictionary(Of String, Object))
If extraprops.ContainsKey(id) Then
Return Convert.ToDouble(extraprops(id))
Else
Return Double.NaN
End If
End Select
End Function
Public Function GetResultUnits(id As String) As String Implements IFlowsheet.GetResultUnits
Select Case id
Case "Total GHG Mass Emissions"
Return Options.SelectedUnitSystem.massflow
Case "Total GHG Molar Emissions"
Return Options.SelectedUnitSystem.molarflow
Case "Total CO2eq GHG Mass Emissions"
Return Options.SelectedUnitSystem.massflow
Case "Total CO2eq GHG Molar Emissions"
Return Options.SelectedUnitSystem.molarflow
Case "Total CAPEX"
Return "$"
Case "Total OPEX"
Return "$/year"
Case "Residual Mass Balance"
Return Options.SelectedUnitSystem.massflow
Case "Total Energy Balance"
Return Options.SelectedUnitSystem.heatflow
Case Else
Return ""
End Select
End Function
Public Sub UpdateMassAndEnergyBalance() Implements IFlowsheet.UpdateMassAndEnergyBalance
Dim equipments = SimulationObjects.Values.Where(Function(o) TypeOf o Is UnitOpBaseClass And TypeOf o IsNot IIndicator)
Dim totalE As Double = 0.0
For Each eq In equipments
'check efficiency
Dim eff As Nullable(Of Double)
Dim props = eq.GetType().GetProperties()
If props.Where(Function(p) p.Name = "Eficiencia").Count > 0 Then
eff = Convert.ToDouble(eq.GetType().GetProperty("Eficiencia").GetValue(eq))
ElseIf props.Where(Function(p) p.Name = "ThermalEfficiency").Count > 0 Then
eff = Convert.ToDouble(eq.GetType().GetProperty("ThermalEfficiency").GetValue(eq))
ElseIf props.Where(Function(p) p.Name = "Efficiency").Count > 0 Then
eff = Convert.ToDouble(eq.GetType().GetProperty("Efficiency").GetValue(eq))
ElseIf props.Where(Function(p) p.Name = "AdiabaticEfficiency").Count > 0 Then
eff = Convert.ToDouble(eq.GetType().GetProperty("AdiabaticEfficiency").GetValue(eq))
Else
eff = Nothing
End If
Dim eb = eq.GetPowerGeneratedOrConsumed()
totalE += eb
Next
Results.TotalEnergyBalance = totalE
Dim streams = SimulationObjects.Values.Where(Function(o) TypeOf o Is IMaterialStream).Select(Function(o) DirectCast(o, MaterialStream))
Dim totalM = 0.0
For Each s In streams
Dim mf = s.GetMassFlow()
If Not s.GraphicObject.InputConnectors(0).IsAttached Then
totalM += mf
End If
If Not s.GraphicObject.OutputConnectors(0).IsAttached Then
totalM -= mf
End If
Next
Results.ResidualMassBalance = totalM
End Sub
#End Region
End Class
|