This file is indexed.

/usr/share/elmerfront/tcl/ecif_tk_standardPanelCheck.tcl is in elmer-common 6.1.0.svn.5396.dfsg-2ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
#/*****************************************************************************/
# *
# *  Elmer, A Finite Element Software for Multiphysical Problems
# *
# *  Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
# * 
# *  This program is free software; you can redistribute it and/or
# *  modify it under the terms of the GNU General Public License
# *  as published by the Free Software Foundation; either version 2
# *  of the License, or (at your option) any later version.
# * 
# *  This program is distributed in the hope that it will be useful,
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# *  GNU General Public License for more details.
# *
# *  You should have received a copy of the GNU General Public License
# *  along with this program (in file fem/GPL-2); if not, write to the 
# *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
# *  Boston, MA 02110-1301, USA.
# *
# *****************************************************************************/

#***********************************************************************
#Program:   ELMER Front 
#Module:    ecif_tk_standardPanelCheck.tcl
#Language:  Tcl
#Date:      05.10.98
#Version:   1.00
#Author(s): Martti Verho
#Revisions: 
#
#Abstract:  Standard panels checking procedures.
#
#************************************************************************

# ========================== #
# Panel specific check procs #
# ========================== #

# *fillProcs:
# ==========
# are run when field data is filled after selecting a parameter etc.

# *editProcs:
# ==========
# are run when field's value is modified on the screen

# *checkProcs :
# ===========
# are run when field's value is being checked # before add or update.
# These fields are normally not on the screen, so there is no editProc for them!
#
# NOTE: checkProcs are called from procedure PanelCheck::evalFieldCheckProc
# in procedure StdPanelCheck::checkFieldValue
#
# NOTE: These field should located after the fields they are using for checking the
# value in the array-name(allFields) list! An example is the Calculator PROCEDURE
# field which is built from LIBRARY_FILE and FUNCTION_NAME fields
#
# NOTE: These procs should return "" when ok, otherwise some error message!!!


################################
### BOUNDARY CONDITION panel ###
################################

# Check if argument parameter has one common parent body in all its atachemnts
# This is needed eg. when deciding if DiffuseGray button should be active
# for the paramter
#
proc BoundaryCondition::parameterHasCommonParent {pid} {
  global BoundaryCondition Info ObjectTable

  set counter 0
  set parent_ids ""
  set attach_count ""

  foreach oid $ObjectTable(ids) {

    if { ![info exists ObjectTable($oid,bc)] ||
         $ObjectTable($oid,bc) != $pid
       } {
      continue
    }

    set pr_id $ObjectTable($oid,prId)

    # No parent: vertex, edge in 3D
    if { $pr_id == $Info(NO_INDEX) } {
      continue
    }

    set pr1_id $ObjectTable($pr_id,pr1Id)
    set pr2_id $ObjectTable($pr_id,pr2Id)

    incr counter

    if { -1 == [lsearch $parent_ids $pr1_id] } {
      lappend parent_ids $pr1_id
    }

    if { -1 == [lsearch $parent_ids $pr2_id] } {
      lappend parent_ids $pr2_id
    }

    if { ![info exist attach_count$pr1_id] } {
      set attach_count$pr1_id 1
    } else {
      incr attach_count$pr1_id
    }

    if { ![info exist attach_count$pr2_id] } {
      set attach_count$pr2_id 1
    } else {
      incr attach_count$pr2_id
    }
  }

  if { [llength $parent_ids] == 0 } {
    return 1
  }

  foreach id $parent_ids {

    set value [set attach_count$id]


    if { $value >= $counter } {
      return 1
    }
  }

  return 0
}


# Check if a given boundary condition accepts current target
# Problem here is the radiation target body matching!
# NOTE: Target body id is an absolute id in the sif-file. That's why
# we must be careful with targets!
#
proc BoundaryCondition::parameterTargetCheckProc {paramter_id {accept_var ""} } {
  global BoundaryCondition Info ObjectTable

  if { $accept_var != "" } {
    upvar #1 $accept_var accept
  }

  set accept 1

  set pid $paramter_id

  set mode [DataField::getFieldValue BoundaryCondition $pid RADIATION]

  if { $mode == "" || ![string equal -nocase $mode "Diffuse gray"] } {
    return $accept
  }

  # Diffusegray radiation defined --> target bodies must match!
  #
  #set oid $BoundaryCondition($pid,oid)
  #set parent_id $ObjectTable($oid,prId)

  set target_body [DataField::getFieldValue BoundaryCondition $pid RADIATION_TARGET_BODY]

  set oid $BoundaryCondition(objectId)
  set bd1_id $ObjectTable($oid,pr1Id)
  set bd2_id $ObjectTable($oid,pr2Id)

  set bd1_tag $ObjectTable($bd1_id,tg)
  set bd2_tag $ObjectTable($bd2_id,tg)

  # Body2 is "Outside"
  if { $bd1_tag == $bd2_tag } {
    set bd2_tag $Info(NO_INDEX)
  }

  #if { $parent_id != $BoundaryCondition(objectId) }

  if { $target_body == $bd1_tag ||
       $target_body == $bd2_tag
     } {
    
    return $accept
  }

  set accept 0


  return $accept
}


proc BoundaryCondition(RADIATION,fillProc) {} {

  BoundaryCondition(RADIATION,groupEditProc)
}


proc BoundaryCondition(RADIATION,groupEditProc) { {fld ""} } {
  global BoundaryCondition Model ObjectTable

  set BoundaryCondition(EMISSIVITY,act) 0
  set BoundaryCondition(RADIATION_TARGET_BODY_NAME,act) 0
  set BoundaryCondition(RADIATION_TARGET_BODY,act) 0

  set value $BoundaryCondition(RADIATION)

  if { $value != "None" && $value != "" } {
    set BoundaryCondition(EMISSIVITY,act) 1
  }

  # Diffuse gray radiation
  # ======================
  if { $value != "" && [string equal -nocase $value "Diffuse gray"] } {

    set BoundaryCondition(RADIATION_TARGET_BODY_NAME,act) 1
    set BoundaryCondition(RADIATION_TARGET_BODY,act) 1
  }

  if { ![Widget::arrayWidgetExists BoundaryCondition RD_DIFFUSE_GRAY] } {
    return
  }

  if { ![BoundaryCondition::parameterHasCommonParent $BoundaryCondition(parameterId)] } {
    set BoundaryCondition(RD_DIFFUSE_GRAY,act) 0
  }

  Widget::configureField BoundaryCondition RD_DIFFUSE_GRAY
  Widget::configureField BoundaryCondition EMISSIVITY

  # NOTE: Name-list widget state is handled in its own check-proc
  # because widget must be rebuilt if name list changes!
  BoundaryCondition(RADIATION_TARGET_BODY,fillProc)
  BoundaryCondition(RADIATION_TARGET_BODY_NAME,fillProc)
}


# This proc puts the radiation target body name-list in the OptionMenu
# widget according to the selected boundary
#
proc BoundaryCondition(RADIATION_TARGET_BODY_NAME,fillProc) {} {
  global BoundaryCondition Info ObjectTable

  if { ![Widget::arrayWidgetExists BoundaryCondition RADIATION_TARGET_BODY_NAME] } {
    return
  }

  set fld RADIATION_TARGET_BODY_NAME

  set wdg $BoundaryCondition(allWidgets,$fld)

  set bd1 $BoundaryCondition(body1Id)
  set bd2 $BoundaryCondition(body2Id)

  if {$bd1 == "" || $bd1 == $Info(NO_INDEX) } {
    return
  }

  set body1 "($ObjectTable($bd1,tg)) "
  append body1 $ObjectTable($bd1,nm)

  if { $bd2 != $Info(NO_INDEX) } {
    set body2 "($ObjectTable($bd2,tg)) "
    append body2 $ObjectTable($bd2,nm)

  } else {
    set body2 "Outside"
  }

  set names [list $body1 $body2]
  
  if { $BoundaryCondition(RADIATION) != "" &&   
       [string equal -nocase $BoundaryCondition(RADIATION) "Diffuse gray"]
     } {
    set wdg_state normal
  } else {
    set wdg_state disabled
  }

  # Pick current MenuSelect proc
  set ms_proc [ bind $BoundaryCondition(allWidgets,$fld,om) <<MenuSelect>>]

  destroy $wdg

  # Build new option-menu with current parent names
  set om [Panel::createOptionMenuWidget $wdg BoundaryCondition($fld) $names]
  $wdg configure -indicatoron 0 -width 9 
  #$wdg configure -activeforeground black
  #$wdg configure -disabledforeground darkGray
  Widget::configureS $wdg $wdg_state

  BoundaryCondition(RADIATION_TARGET_BODY_NAME,checkWidgetState)

  bind $om <<MenuSelect>> $ms_proc

  # Save and pack rebuilt widget
  set BoundaryCondition(allWidgets,$fld) $wdg
  pack $wdg

}


# This proc picks the user selected name value from the OptionMenu
# widget body-name variable and then sets corresponding value 
# to the target-body variable
#
proc BoundaryCondition(RADIATION_TARGET_BODY_NAME,editProc) {} {
  global BoundaryCondition Info ObjectTable

  set name $BoundaryCondition(RADIATION_TARGET_BODY_NAME)
  set name_prev $BoundaryCondition(RADIATION_TARGET_BODY_NAME,prev)
  set BoundaryCondition(RADIATION_TARGET_BODY_NAME,prev) $name

  if { $name != $name_prev } {
    Panel::panelDataModified 1 BoundaryCondition
  }    
  
  #-Outside
  if { $name == "Outside" } {
    set bd_tag $Info(NO_INDEX)
  
  #-Pick body tag
  } else {
    set bd_tag [string trim [lindex [split $name ")"] 0] "("]
  }

  set BoundaryCondition(RADIATION_TARGET_BODY) $bd_tag
}


# This proc checks if the radiation target body widget must be disabled to prevent
# changing the target body
#
proc BoundaryCondition(RADIATION_TARGET_BODY_NAME,checkWidgetState) { {force_state 0} {value 0} } {
  global BoundaryCondition ObjectTable

  set wdg $BoundaryCondition(allWidgets,RADIATION_TARGET_BODY_NAME)
  
  if { ![winfo exists $wdg] } {
    return
  }

  #-Calculate nof parent bodies for the parameter attachments
  #
  set parent_ids ""
  set pid $BoundaryCondition(parameterId)

  foreach oid $ObjectTable(ids) {

    if { [info exists ObjectTable($oid,bc)] &&
         $ObjectTable($oid,bc) == $pid
       } {
      
      if { -1 == [lsearch $parent_ids $ObjectTable($oid,prId)] } {
        lappend parent_ids $ObjectTable($oid,prId)
      }
    }
  }

  # If no attachments or attachments only for the boundaries of the
  # current body, we can allow changing the target bodies, ie. activate
  # the widget
  #   
  if {  0 == [llength $parent_ids] ||
       (1 == [llength $parent_ids] &&
        $BoundaryCondition(objectId) == [lindex $parent_ids 0]
       ) } {
    return
  }

  Widget::configureS $wdg "disabled"
}


# This proc puts the correct body-name value to be displayed in the
# OptionMenu widget, based on target-body value, when a boundary
# or boundary condition is selected
# NOTE: Current version with only one target body in the result list!
#
proc BoundaryCondition(RADIATION_TARGET_BODY,fillProc) {} {
  global BoundaryCondition Info ObjectTable

  if { ![Widget::arrayWidgetExists BoundaryCondition RADIATION_TARGET_BODY_NAME] } {
    return
  }


  set oid $BoundaryCondition(objectId)

  set bd1_id $ObjectTable($oid,pr1Id)
  set bd2_id $ObjectTable($oid,pr2Id)

  set bd1_tag $ObjectTable($bd1_id,tg)
  set bd2_tag $ObjectTable($bd2_id,tg)

  # Second 'body' is 'Outside'
  if { $bd2_tag == $bd1_tag } {
    set bd2_id $Info(NO_INDEX)
    set bd2_tag $Info(NO_INDEX)
  }


  # Select correct body tag for the target body
  #
  set bd_tag $BoundaryCondition(RADIATION_TARGET_BODY)

  # First of the body pair is ok
  if { $bd_tag == $bd1_tag } {
    set bd_id $bd1_id

  # Second of the body pair is ok
  } elseif { $bd_tag == $bd2_tag } {
    set bd_id $bd2_id

  # We are adding: must be one of the bodies!
  } elseif { $bd_tag == "" || $bd_tag == $Info(NO_INDEX) || $BoundaryCondition(mode) == "ADD" } {
    set bd_id $bd1_id
    set bd_tag $bd1_tag

  # An existing paramter was selected, we use its target body tag
  } else {
      set bd_id [Object::findIdByTag "B" $bd_tag]
  }

  set BoundaryCondition(RADIATION_TARGET_BODY) $bd_tag

  # Set target body name 
  # =====================
  #-Outside
  if { $bd_tag == $Info(NO_INDEX) } {  
    set name "Outside"

  #-Body tag and name
  } else {
    set name "($bd_tag) "
    append name $ObjectTable($bd_id,nm)
  }

  set BoundaryCondition(RADIATION_TARGET_BODY_NAME) $name
  set BoundaryCondition(RADIATION_TARGET_BODY_NAME,prev) $name
}


# This proc puts the correct body-name value to be displayed in the
# OptionMenu widget, based on target-body value, when a boundary
# or boundary condition is selected
# NOT IN USE, MVe 01.08.00!
#
proc BoundaryCondition_experimental(RADIATION_TARGET_BODIES,fillProc) {} {
  global BoundaryCondition Info ObjectTable

  if { ![Widget::arrayWidgetExists BoundaryCondition RADIATION_TARGET_BODY_NAME] } {
    return
  }

  set oid $BoundaryCondition(objectId)

  set bd1_id $ObjectTable($oid,pr1Id)
  set bd2_id $ObjectTable($oid,pr2Id)

  set bd1_tag $ObjectTable($bd1_id,tg)
  set bd2_tag $ObjectTable($bd2_id,tg)

  set bndr_tag $ObjectTable($BoundaryCondition(boundaryId),tg)

  # Pre version 5 file conversion!
  if { $BoundaryCondition(RADIATION_TARGET_BODIES) == "" &&
       [info exists BoundaryCondition(RADIATION_TARGET_BODY)] &&
       $BoundaryCondition(RADIATION_TARGET_BODY) != ""
     } {

    set bd_tag $BoundaryCondition(RADIATION_TARGET_BODY)

    lappend BoundaryCondition(RADIATION_BOUNDARIES) $bndr_tag
    lappend BoundaryCondition(RADIATION_TARGET_BODIES) $bd_tag
  }

  set idx [lsearch $BoundaryCondition(RADIATION_BOUNDARIES) $bndr_tag]

  #--If not yet stored
  if { $idx == -1 } {

    set bd_tag $BoundaryCondition(RADIATION_TARGET_BODY)

    if { $bd_tag == $Info(NO_INDEX) } {
      
      if { $ObjectTable($oid,tp) == "B" } {
        set bd_id $Info(NO_INDEX)

      } else {
        set bd_id $bd2_id
      }

    } elseif { $bd_tag == $bd1_tag } {
      set bd_id $bd1_id

    } elseif { $bd_tag == $bd2_tag } {
      set bd_id $bd2_id

    } else {
      set bd_tag $bd1_tag
      set bd_id $bd1_id
    }

  # Check parent body by boundary's index
  } else {

    set bd_tag [lindex $BoundaryCondition(RADIATION_TARGET_BODIES) $idx]

    if { $bd_tag != $Info(NO_INDEX) } {
      set bd_id [Object::findIdByTag "B" $bd_tag]
    }
  }

  set BoundaryCondition(RADIATION_TARGET_BODY) $bd_tag

  # Set target body name 
  # =====================
  #-Outside
  if { $bd_tag == $Info(NO_INDEX) } {  
    set name "Outside"

  #-Body tag and name
  } else {
    set name "($bd_tag) "
    append name $ObjectTable($bd_id,nm)
  }

  set BoundaryCondition(RADIATION_TARGET_BODY_NAME) $name
  set BoundaryCondition(RADIATION_TARGET_BODY_NAME,prev) $name
}



# Checks and marks if there are some force related flow boundary conditions
#
proc BoundaryCondition(FLOW_FORCE_BC,fillProc) {} {
  global BoundaryCondition

  set value ""

  if { $BoundaryCondition(EXTERNAL_PRESSURE) != ""
       ||
       ( $BoundaryCondition(PRESSURE_1) != ""  ||
         $BoundaryCondition(PRESSURE_2) != ""  ||
         $BoundaryCondition(PRESSURE_3) != ""  
       )
       ||
       $BoundaryCondition(SURFACE_TENSION_COEFFICIENT) != "" 
       ||
       ( [info exists BoundaryCondition(WALL_LAW)] &&
         $BoundaryCondition(WALL_LAW) == "True"
       )
     } {
    set value "True"
  }

  set BoundaryCondition(FLOW_FORCE_BC) $value
}


# Checks and marks if there are some heat flux related boundary conditions
#
proc BoundaryCondition(HEAT_FLUX_BC,fillProc) {} {
  global BoundaryCondition

  set value ""

  if { ($BoundaryCondition(RADIATION) == "Idealized" ||
        $BoundaryCondition(RADIATION) == "Diffuse gray"
       ) 
       ||
       $BoundaryCondition(HEAT_FLUX) != ""
       ||
       ($BoundaryCondition(HEAT_TRANSFER_COEFFICIENT) != "" &&
        $BoundaryCondition(EXTERNAL_TEMPERATURE) != ""
       )
     } {
    set value "True"
  }

  set BoundaryCondition(HEAT_FLUX_BC) $value
}


proc BoundaryCondition(NORMAL-TANGENTIAL_DISPLACEMENT,fillProc) {} {

  BoundaryCondition(NORMAL-TANGENTIAL_DISPLACEMENT,editProc)
}

proc BoundaryCondition(NORMAL-TANGENTIAL_DISPLACEMENT,editProc) {} {
  global BoundaryCondition

  if { ![Widget::arrayWidgetExists BoundaryCondition NORMAL-TANGENTIAL_DISPLACEMENT] } {
    return
  }

  StdPanelExec::setNormalTangentialLabels \
    BoundaryCondition \
    DISPLACEMENT \
    $BoundaryCondition(NORMAL-TANGENTIAL_DISPLACEMENT)
}


proc BoundaryCondition(NORMAL-TANGENTIAL_VELOCITY,fillProc) {} {

  BoundaryCondition(NORMAL-TANGENTIAL_VELOCITY,editProc)
}


proc BoundaryCondition(NORMAL-TANGENTIAL_VELOCITY,editProc) {} {
  global BoundaryCondition

  if { ![Widget::arrayWidgetExists BoundaryCondition NORMAL-TANGENTIAL_VELOCITY] } {
    return
  }

  StdPanelExec::setNormalTangentialLabels \
    BoundaryCondition \
    VELOCITY \
    $BoundaryCondition(NORMAL-TANGENTIAL_VELOCITY)
}


#-Procedure checks velocity-group field data
# Not in use!
#
proc BoundaryCondition(VELOCITY,checkProc) { } {
  return [Common(VectorGroup,checkProc) BoundaryCondition VELOCITY]
}



########################
### CALCULATOR panel ###
########################

proc Calculator(ACTIVE,fillProc) {} {
  Calculator(ACTIVE,editProc)
}

proc Calculator(ACTIVE,editProc) {} {
  global Calculator

  if { $Calculator(ACTIVE) == "True" } {
    set active 1
  } else {
    set active 0
  }

  set flds { INCLUDE,Use
             EQUATION LIBRARY_FILE FUNCTION_NAME
             VARIABLE VARIABLE_DOFS
           }

  foreach fld $flds {
    set Calculator($fld,act) $active
    Widget::configureField Calculator $fld
  }

  Widget::configureField Calculator INCLUDE

}


proc Calculator(EQUATION,fillProc) {} {
  global Calculator

  #set Calculator(parameterName) [string trim $Calculator(EQUATION)]
}


proc Calculator(PROCEDURE,fillProc) {} {
  global Calculator

  set vals [split $Calculator(PROCEDURE) ";"]

  set Calculator(LIBRARY_FILE) [lindex $vals 0]
  set Calculator(FUNCTION_NAME) [lindex $vals 1]
}

proc Calculator(PROCEDURE,checkProc) {} {
  global Calculator

  set lb $Calculator(LIBRARY_FILE)
  set fn $Calculator(FUNCTION_NAME)

  set Calculator(PROCEDURE) [join [list $lb $fn] ";"]

  return ""
}


proc Calculator(VARIABLE_DOFS_ALL,checkProc) {} {
  global Calculator Model

  set values $Calculator(VARIABLE_DOFS_ALL)
  
  if { 2 == [llength $values] } {
    set values [linsert $values 0 1]
  }

  #-No dimension dependence
  #
  if { 1 == [llength $values] } {
    set dof $values

  #-Depends on simulation dimension
  #
  } elseif { $Model(SIMULATION_DIMENSION) == "1D" } {
    set dof [lindex $values 0]

  } elseif { $Model(SIMULATION_DIMENSION) == "2D" } {
    set dof [lindex $values 1]

  } else {
    set dof [lindex $values end]
  }

  set Calculator(VARIABLE_DOFS) [Calculator::getVariableDofs $values]

  return ""
}



######################
### EQUATION panel ###
######################

proc Equation(EQUATION_LIST,fillProc) {} {
  global Equation EquationVariable Model

  Equation::updateEquationList 
  
  if { $Model(GEOMETRY_DIMENSION) == "" ||
       ![info exists Equation(allWidgets,EQUATION_LIST)] ||
       ![winfo exists $Equation(allWidgets,EQUATION_LIST)]
     } {
    return
  }

  set sindex [lsearch $Equation(ownIndices) $Equation(equationIndex)]
  $Equation(allWidgets,EQUATION_LIST) selection set $sindex

  Equation::setVariableWidgetsActivity $Equation(equationIndex)
  Equation::updateVariableList $Equation(equationIndex)
}


proc Equation(EQUATION_LIST,editProc) { arguments } {
  global Equation

  #-Pick arguments
  set event_mode [lindex $arguments 0] ;# Button and keys pressed
  set lb_x [lindex $arguments 1] ;# Local lb x-coordinate for selection
  set lb_y [lindex $arguments 2] ;# Local lb y-coordinate for selection 

  set current_row ""
  set picked_row ""
  set sindex ""

  set current_row [$Equation(allWidgets,EQUATION_LIST) curselection]

  #-Selected ("clicked") equation row
  #
  if { $lb_x != "" && $lb_y != "" } {
    set picked_row [$Equation(allWidgets,EQUATION_LIST) index @$lb_x,$lb_y]
  } else {
    set picked_row $current_row
  }


  if { $current_row == "" && $picked_row == "" } {
    return
  }

  if { $event_mode == "ButtonRelease-1" &&
       ($lb_x != "" && $lb_x < 25)
     } {
    set event_mode "ButtonRelease-3"
  }

  #-Btn-1: Equation change only
  # ==================================
  if { $event_mode == "ButtonRelease-1" } {
    set select_row $picked_row
    set toggle_row ""
    set sindex $picked_row
    
  #-Btn-3: Equation change+toggle
  # ==================================
  } elseif { $event_mode == "ButtonRelease-3" } {
    set select_row $picked_row
    set toggle_row $picked_row
    set sindex $picked_row


  #-Ctrl-Btn-1: Toggle current row
  # ==================================
  } elseif { $event_mode == "Control-ButtonRelease-1" } {
    set select_row ""
    set toggle_row $current_row
    set sindex $current_row

  #-Ctrl-Btn-3: Toggle picked row
  # ==================================
  } elseif { $event_mode == "Control-ButtonRelease-3" } {
    set select_row ""
    set toggle_row $picked_row
    set sindex $current_row
  }
  
  # Select equation
  #
  if { $select_row != "" } {

    set ename [lindex $Equation(ownNames) $select_row]
    set eindex [lindex $Equation(ownIndices) $select_row]

    set Equation(equationLabel) [Equation::getFieldPropertyByIndex $eindex EquationLabel]
    StdPanelExec::equationMenuSelectionProc Equation $eindex
  }

  # Toggle equation on/off value
  #
  if { $toggle_row != "" } {

    set ename [lindex $Equation(ownNames) $toggle_row]
    set eindex [lindex $Equation(ownIndices) $toggle_row]

    # Toggle value
    #
    if { $Equation($ename) == "True" } {
      set Equation($ename) "False"
    } else {
      set Equation($ename) "True"
    }

    #-Pick current top row index in the listbox
    set  ix [ $Equation(allWidgets,EQUATION_LIST) nearest 0]

    #-Update equation list itself (X-markers!)
    Equation::updateEquationList

    # Keep same rows in the listbox
    $Equation(allWidgets,EQUATION_LIST) see [expr 7 + $ix]

    #-Update variable list stuff
    if { $Equation(equationIndex) == $eindex } {
      Equation::setVariableWidgetsActivity $eindex
    }

    Equation::updateVariableList $eindex

    Panel::panelDataModified 1 Equation
  }


  #-Some further checking
  #
  if { "" != [info commands Equation($ename,editProc) ] } {
    Equation($ename,editProc)

  } else {
    if { 1 == [DataField::getFieldProperty Equation $ename IsUserDefinedField "" 0] } {
      Equation::setUserDefinedEquationMask $ename
    }
  }

  # Update Equation panel field activity
  StdPanelExec::setValuesAreaActivity Equation $Equation(targetMask)
  
  if { $sindex != "" } {
    $Equation(allWidgets,EQUATION_LIST) selection set $sindex
    $Equation(allWidgets,EQUATION_LIST) activate $sindex
  }
}


proc Equation(VARIABLE_LIST,editProc) {arguments} {
  global Equation EquationVariable

  if { !$Equation(VARIABLE_LIST,act) } {
    return
  }

  set event_mode [lindex $arguments 0] ;# Button an d keys pressed
  set lb_x [lindex $arguments 1] ;# Local lb x-coordinate for selection
  set lb_y [lindex $arguments 2] ;# Local lb y-coordinate for selection 

  set sindex [$Equation(allWidgets,VARIABLE_LIST) index @$lb_x,$lb_y]

  if { $sindex == "" || $sindex < 0 } {
    return
  } 

  set eindex $Equation(equationIndex)
  set ename [Equation::getFieldPropertyByIndex $eindex EquationField]

  #-All possible variable names

  set all_names [Equation::getAllVariableNames $eindex]

  #-Find currently active variable names
  set act_names [Equation::getActiveVariableNames $eindex]

  #-Find selected variable and "toggle" its state
  set sel_name [lindex $all_names $sindex]

  set idx [List::nocaseSearch $act_names $sel_name]

  #-Turn on (= add to the actives' list)
  if { $idx == -1 } {
    lappend act_names $sel_name

  #-Turn off (= delete from the actives' list)
  } else {
    set act_names [lreplace $act_names $idx $idx]
  }

  #-Sort names in actives-list by the names order in all-list
  #
  set sorted_list ""

  foreach name $all_names {

    if { -1 != [List::nocaseSearch $act_names $name] } {
      lappend sorted_list $name
    }
  }

  #-Update actives-list variable
  set act_names_var [DataField::getFieldProperty Equation $ename EquationVars]
  set sep [DataField::getFieldProperty EquationVariable $ename FieldDataSep]
  set act_names [join $sorted_list $sep]

  set Equation($act_names_var) $act_names

  #-Update variable-list widget
  Equation::updateVariableList $eindex
}


# NOTE: Be careful with the (...,groupEditProc)-procs
# because they are also called in the "fillGroupFromDispList"
# (..procsDataField.tcl) proc when an equation parameter is
# selected in the equation list box!!!

#======================================#
#     Generic UserDefinedField         #
#======================================#

proc Equation(UserDefinedField,fillProc) { fld } {
 
  if { "" != [DataField::getFieldProperty Equation $fld EquationIndex "" 0] } {
    Equation::setUserDefinedEquationMask $fld
  }
}


proc Equation(UserDefinedField,editProc) { fld } {

  if { "" != [DataField::getFieldProperty Equation $fld EquationIndex "" 0] } {
    Equation::setUserDefinedEquationMask $fld
  }
}


#===========================================#
#                 FLOW equation             #
#===========================================#

# NOTE: This is called always when Navier-Stokes panel is activated
#
proc Equation(NAVIER-STOKES,fillProc) {} {
  global Equation

  #-We can not update values area now (loop!), so
  # store old value befor setting ther global var
  #
  set flag $Equation(updateValuesArea)
  set Equation(updateValuesArea) 0

  Equation(NAVIER-STOKES,editProc)
  Equation(TURBULENCE_MODEL,groupEditProc)
  
  set Equation(updateValuesArea) $flag
}


# NOTE: This is called when Navier-Stokes box is clicked
#
proc Equation(NAVIER-STOKES,editProc) {} {
  global Equation

  #-If no flow 
  if {$Equation(NAVIER-STOKES) != "True"} {
    set Equation(flow_type) ""
    set Equation(flow_laminarType) ""
    set Equation(flow_turbulentType) ""
    set Equation(TURBULENCE_MODEL) ""
    set Equation(HYDROSTATIC_PRESSURE) "False"

  #-When flow is checked on, default is laminar (NS) flow
  } else {
    set Equation(flow_type) "¤FL"
    set Equation(flow_laminarType) "¤FL1"
  }

  #-Broadcast type change to other
  Equation::updateTargetMask
}


#-Group (container) widget Turbulence Model widgets
# NOTE: This is grouper variable, it is not meant to be output
# into Solver-input file, but we need it to set the value
# for variables like like KE_TURBULENCE which are not on screen
#
proc Equation(TURBULENCE_MODEL,groupEditProc) { {fld ""} } {
  global Equation

  # Reset all group's target output variables
  set Equation(flow_turbulentType) ""
  set Equation(KE_TURBULENCE) "False"

  # Is some flow
  if { $Equation(flow_type) != "" } {

    switch $Equation(TURBULENCE_MODEL) {
      "" {
        set Equation(flow_turbulentType) ""
      }
      "KE" {
        set Equation(flow_turbulentType) "¤FT1"
        set Equation(KE_TURBULENCE) "True"
      }
    }
  }

  #-Broadcast type change
  Equation::updateTargetMask
}



#=======================================#
#               HEAT equation           #
#=======================================#

# NOTE: This is called when Heat equation panel is activated
#
proc Equation(HEAT_EQUATION,fillProc) {} {
  global Equation

  #-We can not update values area now (loop!), so
  # store old value befor setting ther global var
  #
  set flag $Equation(updateValuesArea)
  set Equation(updateValuesArea) 0

  Equation(HEAT_EQUATION,editProc)
  Equation(CONVECTION,groupEditProc)
  Equation(PHASE_CHANGE_MODEL,groupEditProc)

  set Equation(updateValuesArea) $flag
}


# NOTE: This is called when Heat Equation check box is clicked
#
proc Equation(HEAT_EQUATION,editProc) {} {
  global Equation

  #-If no heat
  if {$Equation(HEAT_EQUATION) != "True"} {

    set Equation(heat_type) ""
    set Equation(heat_transferType) ""
    set Equation(heat_phaseType) ""

    set Equation(PHASE_CHANGE_MODEL) ""
    set Equation(CHECK_LATENT_HEAT_RELEASE) ""

    # If no adv-diff, disable convetion fields
    # ========================================
    if { $Equation(ADVECTION_DIFFUSION_EQUATION) != "True" } {
      set Equation(CONVECTION) "None"
    }

  #-Heat equation was selected, we have at least:
  } else {
    set Equation(heat_type) "¤H"
    set Equation(heat_transferType) "¤HT1"
  }

  #-Broadcast type change
  Equation::updateTargetMask
}


#-Convection group (container) widget
#
proc Equation(CONVECTION,groupEditProc) { {fld ""} } {
  Equation(CONVECTION,heatCheckProc)  
  Equation(CONVECTION,diffusionCheckProc)  
}


#-Convection heat tranfer part check proc
#
proc Equation(CONVECTION,heatCheckProc) { {fld ""} } {
  global Equation

  if { $Equation(heat_transferType) == "" } {
    return
  }

  if { ![info exists Equation(CONVECTION)] } {
    return
  }

  switch $Equation(CONVECTION) {
    "None" {
      set Equation(heat_transferType) "¤HT1"
    }
    "Constant" {
      set Equation(heat_transferType) "¤HT1 ¤HT2"
    }
    "Computed" {
      set Equation(heat_transferType) "¤HT1 ¤HT3"
    }
  }
    
  #-Broadcast type change
  Equation::updateTargetMask
}


proc Equation(PHASE_CHANGE_MODEL,groupEditProc) { {fld ""} } {
  global Equation

  switch $Equation(PHASE_CHANGE_MODEL) {
    "None" {
      set Equation(heat_phaseType) ""
    }
    "Spatial 1" {
      set Equation(heat_phaseType) "¤HP1"
    }
    "Spatial 2" {
      set Equation(heat_phaseType) "¤HP2"
    }
    "Temporal" {
      set Equation(heat_phaseType) "¤HP3"
    }
  }

  #-Broadcast change
  Equation::updateTargetMask
}



#=========================================#
#                STRESS analysis          #
#=========================================#

# NOTE: This is called when Stress Analysis panel is activated
#
proc Equation(STRESS_ANALYSIS,fillProc) {} {
  global Equation

  #-We can not update values area now (loop!), so
  # store old value befor setting ther global var
  #
  set flag $Equation(updateValuesArea)
  set Equation(updateValuesArea) 0

  Equation(STRESS_ANALYSIS,editProc)
  Equation(STRESS_MODEL,groupEditProc)

  set Equation(updateValuesArea) $flag
}


# NOTE: This is called when Stress Analysis check box is clicked
#
proc Equation(STRESS_ANALYSIS,editProc) {} {
  global Equation Model

  #-No stress analysis selected
  if {$Equation(STRESS_ANALYSIS) != "True"} {
    set Equation(stress_type) ""
    set Equation(stress_mechanicalType) ""
    set Equation(stress_thermalType) ""
    set Equation(STRESS_MODEL) ""

  } else {

    set Equation(stress_type) "¤S"
  }

  Equation::setUserDefinedFieldsActivity STRESS_ANALYSIS

  #-Broadcast type change to other
  Equation::updateTargetMask
}


proc Equation(STRESS_MODEL,groupEditProc) { {fld ""} } {
  global Equation

  if { $Equation(stress_type) == "" } {
    return
  }

  set Equation(stress_mechanicalType) ""
  set Equation(stress_thermalType) ""

  switch $Equation(STRESS_MODEL) {

    "" {
      if { $Equation(heat_type) != "" } {
        set Equation(stress_mechanicalType) "¤ST1"
        #set Equation(STRESS_MODEL) "Thermal"
      } else {
        set Equation(stress_thermalType) "¤SM1"
        #set Equation(STRESS_MODEL) "Mechanical"
      }
    }

    "Mechanical" {
      set Equation(stress_mechanicalType) "¤SM1"
      set Equation(stress_thermalType) ""
    }

    "Thermal" {
      set Equation(stress_thermalType) "¤ST1"
      set Equation(stress_mechanicalType) ""
    }
  }

  #-Broadcast type change
  Equation::updateTargetMask
}


#===========================#
#   ADVECTION-DIFFUSION     #
#===========================#


# NOTE: This is called when Advection-Diffusion panel is activated
#
proc Equation(ADVECTION_DIFFUSION_EQUATION,fillProc) {} {
  global Equation EquationVariable

  #-We can not update values area now (loop!), so
  # store old value befor setting ther global var
  #
  set flag $Equation(updateValuesArea)
  set Equation(updateValuesArea) 0

  set Equation(diffusion_type) "" 
  set Equation(diffusion_transferType) "" 

  # No advection-diffusion
  # ======================
  if { $Equation(ADVECTION_DIFFUSION_EQUATION) != "True" } {

    set Equation(updateValuesArea) $flag

    #-Broadcast type change
    Equation::updateTargetMask

    return
  }

  set Equation(diffusion_type) "¤AD" 

  Equation(CONVECTION,diffusionCheckProc)  
  Equation(ADVECTION_DIFFUSION_EQUATION,editProc)

  #-Restore global flag var
  set Equation(updateValuesArea) $flag
}


#-Convection advection-diffusion field check proc (done when panel opened
# or in general when data contenst is searched
#
proc Equation(CONVECTION,diffusionCheckProc) { {fld ""} } {
  global Equation

  if { $Equation(diffusion_type) == "" } {
    return
  }

  if { ![info exists Equation(CONVECTION)] } {
    return
  }

  switch $Equation(CONVECTION) {
    "None"     { set Equation(diffusion_transferType) "¤AD1"}
    "Constant" { set Equation(diffusion_transferType) "¤AD1 ¤AD2"}
    "Computed" { set Equation(diffusion_transferType) "¤AD1 ¤AD3"}
  }
    
  #-Broadcast type change
  Equation::updateTargetMask
}



# NOTE: This is called when Advection-Diffusion check box is clicked
#
proc Equation(ADVECTION_DIFFUSION_EQUATION,editProc) {} {
  global Equation EquationVariable Info

  # No diffusion selected
  # =====================
  if { $Equation(ADVECTION_DIFFUSION_EQUATION) != "True" } {
    
    # If no heat, disable convection fields
    # =====================================
    if { $Equation(HEAT_EQUATION) != "True" } {
      #set Equation(CONVECTION) "None"
    }

    set Equation(diffusion_type) ""
    set Equation(diffusion_transferType) ""

  # Diffusion selected
  # ==================
  } else {
    set Equation(diffusion_type) "¤AD"
  }

  #-Broadcast type change to other
  Equation::updateTargetMask
}



####################
### GRID H panel ###
####################

# Procedure checks if a parameter (pid) is applied to
# vertices. In this case the parameter cannot be
# modified to a nof-elements type density value!
#
proc GridH::parameterHasVertexParents {pid} {
  global GridH ObjectTable

  foreach id $ObjectTable(ids) {

    # Not a vertex
    # We should add 3D edges here also?
    #
    if { "V" != [Object::getType $id] } {
      continue
    }


    # If parameter attached to this boundary, we can stop here!
    #
    if { [info exists ObjectTable($id,gh)] &&
         $ObjectTable($id,gh) == $pid
       } {
      return 1
    }
  }

  return 0
}


# Nof elements-type density paramater cannot be attached to a vertex!
#
proc GridH::parameterTargetCheckProc {paramter_id {accept_var ""} } {
  global GridH Info ObjectTable

  if { $accept_var != "" } {
    upvar #1 $accept_var accept
  }

  set accept 1

  set pid $paramter_id

  set mode [DataField::getFieldValue GridH $pid MESH_DENSITY_TYPE]
  
  if { $mode == "N" &&
       "V" == [Object::getType $GridH(targetId)]
     } {
    set accept 0
  }

  return $accept
}


proc GridH::checkPanel {} {
  global GridH Model ObjectTable

  set id $GridH(targetId)

  if { "V" == [Object::getType $GridH(targetId)] } {
    set GridH(MESH_DT_N,act) 0
  } else {
    set GridH(MESH_DT_N,act) 1
  }

  Widget::configureField GridH MESH_DT_N
}


# Set current mesh index based on selection in the mesh
# option menu
#
proc GridH(MESH_NAME,fillProc) {} {
  global GridH Model

  set GridH(MESH_NAME) [lindex $Model(meshNames) $GridH(MESH_INDEX)]
}


# Set mesh density type field states when parameter is selected
#
proc GridH(MESH_DENSITY_TYPE,fillProc) {} {
  global GridH

  GridH(MESH_DENSITY_TYPE,groupEditProc)
}


# Set mesh density type field states when radiobutton is selected
#
proc GridH(MESH_DENSITY_TYPE,groupEditProc) { {fld ""} } {
  global GridH ObjectTable

  set accept_dt_n 1

  if { "V" == [Object::getType $GridH(targetId)] } {
    set GridH(MESH_DT_N,act) 0
    set accept_dt_n 0
  }

  set GridH(MESH_H,act) 0
  set GridH(MESH_N,act) 0
  set GridH(MESH_R,act) 0

  switch $GridH(MESH_DENSITY_TYPE) {

    "H" {
      set GridH(MESH_H,act) 1
    }

    "N" {
      if { $accept_dt_n } {
        set GridH(MESH_N,act) 1
      }
    }
    
    "R" {
      set GridH(MESH_R,act) 1
    }
  }

  Widget::configureField GridH MESH_H
  Widget::configureField GridH MESH_R
  Widget::configureField GridH MESH_N

  GridH(MESH_DT_N,editProc)
}


# If parameter is attached also to vertices and the mesh density
# type "Number of elements" is selected, user cannot update this
# paramter
#
proc GridH(MESH_DT_N,editProc) {} {
  global GridH Model ObjectTable

  set pid $GridH(parameterId)

  if { [GridH::parameterHasVertexParents $pid] } {
    
    if { "N" == $GridH(MESH_DENSITY_TYPE) } {
      set GridH(updateAllowed) 0

    } else {
      set GridH(updateAllowed) 1
      #set GridH(MESH_N) ""
    }
  }

  Panel::panelDataModified $GridH(dataModified) GridH ""
}



# Update ObjectTable gh-id from ghIds when panel is opend or
# mesh has been changed in the panel
#
proc GridH::updateObjectParameterId {} {
  global GridH Info MeshDefine Model ObjectTable

  if { [info exists MeshDefine(edited,GridH)] &&
       $MeshDefine(edited,GridH)
     } {
    return
  }

  if { ![info exists GridH(MESH_NAME)] } {
    set GridH(MESH_NAME) $Model(currentMeshName)
    set GridH(MESH_INDEX) $Model(currentMeshIndex)
  }

  foreach id $ObjectTable(ids) {
 
    if { [info exists ObjectTable($id,gh)] } {

      # Default value
      set ObjectTable($id,gh) $Info(NO_INDEX)

      # If ids list given, try to find one for the current
      # mesh
      if { $GridH(MESH_INDEX) != $Info(NO_INDEX) &&
           [info exists ObjectTable($id,ghIds)] &&
           $ObjectTable($id,ghIds) != ""
         } { 

        set idx [lsearch $ObjectTable($id,ghMshIndcs) $GridH(MESH_INDEX)]
        # If something for the current mesh!
        if { $idx != -1 } {

          set ObjectTable($id,gh) [lindex $ObjectTable($id,ghIds) $idx]
        }
      }
    }

  }
}


# Update ObjectTable gh-id to ghIds (and ghMshIndcs)
# Used after ok/apply and when mesh has been changed
# in the panel
#
proc GridH::updateObjectParameterIds {} {
  global Info GridH ObjectTable

  if { ![info exist GridH(MESH_INDEX)] ||
       $GridH(MESH_INDEX) == ""        ||
       $GridH(MESH_INDEX) == $Info(NO_INDEX)
     } {
    return
  }

  set msh_idx $GridH(MESH_INDEX)

  foreach id $ObjectTable(ids) {

    if { ![info exists ObjectTable($id,gh)] } {
      continue
    }

    set ids $ObjectTable($id,ghIds)
    set indices $ObjectTable($id,ghMshIndcs)
    set gid $ObjectTable($id,gh)

    if { $gid == $Info(NO_INDEX) } {
      set result [List::removeFromIndexedIdList $indices $ids $msh_idx $gid]
    } else {
      set result [List::addToIndexedIdList $indices $ids $msh_idx $gid]
    }

    set ObjectTable($id,ghMshIndcs) [lindex $result 0]
    set ObjectTable($id,ghIds) [lindex $result 1]

  } ;# Foreach object

  Panel::panelDataChanged 0 GridH
}



############################
### GRID PARAMETER panel ###
############################

# Procedure checks if a parameter (pid) is applied to
# non-structured bodies. In this case the parameter cannot be
# modified to a structured (quadgrid mesh) parameter!
#
proc GridParameter::parameterHasNonStructuredParents {pid} {
  global GridParameter ObjectTable

  foreach id $ObjectTable(ids) {

    # Not a body or boyd-layer
    #
    if { "BL" != [Object::getType $id] &&
         "BL" != [Object::getType $id]
       } {
      continue
    }

    # If structure body, no problems
    #
    if { [info exists ObjectTable($id,accptStrMsh)] &&
         $ObjectTable($id,accptStrMsh)
       } {
      continue
    }

    # If parameter attached to this body, we can stop here!
    #
    if { [info exists ObjectTable($id,gr)] &&
         $ObjectTable($id,gr) == $pid
       } {
      return 1
    }
  }

  return 0
}


# Structured mesh paramater cannot be attached to a non-structurerd body!
#
proc GridParameter::parameterTargetCheckProc {paramter_id {accept_var ""} } {
  global GridParameter Info ObjectTable

  if { $accept_var != "" } {
    upvar #1 $accept_var accept
  }

  set accept 1


  set pid $paramter_id

  set mode [DataField::getFieldValue GridParameter $pid MESH_ELEMENT_TYPE]
  
  if { $mode == "Quad" && !$ObjectTable($GridParameter(objectId),accptStrMsh) } {
    set accept 0
  }

  return $accept
}


proc GridParameter::checkPanel {} {
  global GridParameter Model ObjectTable

  set id $GridParameter(objectId)

  if { $ObjectTable($id,excldMsh) } {
    set GridParameter(ACTIVE_IN_MESHING) 0
  } else {
    set GridParameter(ACTIVE_IN_MESHING) 1
  }

  # For open bodies line is the only option
  #
  if { "OPN" == [Object::getClass $id] ||
       $GridParameter(MESH_ELEMENT_TYPE) == "Line"  
     } {
    set GridParameter(MESH_ET_LINE,act) 1
    set GridParameter(MESH_ET_TRIANGLE,act) 0
    set GridParameter(MESH_ET_QUAD,act) 0
    set GridParameter(MESH_ELEMENT_TYPE) "Line"
    set GridParameter(MESH_LAYER_TYPE) "BoundaryMesh"
    GridParameter(MESH_ET_LINE,editProc)

  } else {
    set GridParameter(MESH_ET_LINE,act) 0
    set GridParameter(MESH_ET_TRIANGLE,act) 1
    set GridParameter(MESH_ET_QUAD,act) 1
  }

  if { !$ObjectTable($id,accptStrMsh) } {
    set GridParameter(MESH_ET_QUAD,act) 0
  } else {
    set GridParameter(MESH_ET_QUAD,act) 1
  }

  Widget::configureField GridParameter MESH_ET_LINE
  Widget::configureField GridParameter MESH_ET_TRIANGLE
  Widget::configureField GridParameter MESH_ET_QUAD
}


proc GridParameter::updateObjectBoundariesWdg {} {
  global GridParameter Model ObjectTable

  set list ""

  foreach id $ObjectTable($GridParameter(objectId),sbIds) {
    
    set row ""
    append row "("
    append row $ObjectTable($id,tg)
    append row ") "
    append row $ObjectTable($id,nm)

    lappend list $row
  }

  ListBox::fill $GridParameter(allWidgets,LISTBOX1) $list
}


# Set state for group of widgets
#
proc GridParameter::setGroupState {group activity} {
  global GridParameter

  foreach fld $group {
    set GridParameter($fld,act) $activity
    Widget::configureField GridParameter $fld
  }
}


proc GridParameter(ACTIVE_IN_MESHING,editProc) {} {
  global GridParameter Model ObjectTable

  if { $Model(nofBodies) == 1 } {
    set GridParameter(ACTIVE_IN_MESHING) 1
  }

  set id $GridParameter(objectId)

  if { !$GridParameter(ACTIVE_IN_MESHING) } {
    set ObjectTable($id,excldMsh) 1
  } else {
    set ObjectTable($id,excldMsh) 0
  }
}


proc GridParameter(LISTBOX1,editProc) {key} {
  global GridParameter ObjectTable

  set ids $ObjectTable($GridParameter(objectId),sbIds)

  set lb $GridParameter(allWidgets,LISTBOX1) 
 
  set sindex [$lb curselection]

  if { $sindex == "" } {
    return
  }

  # Normal selection, highlight corresponding entry!
  #
  if { $key == "ButtonRelease-1" } {
  
    set n1 $GridParameter(MESH_QUADGRID_N1,prev)
    set n2 $GridParameter(MESH_QUADGRID_N2,prev)
    set wdg1 $GridParameter(allWidgets,MESH_QUADGRID_N1)
    set wdg2 $GridParameter(allWidgets,MESH_QUADGRID_N2)

    #wdg1 configure -bg white
    #wdg2 configure -bg white

    if { $sindex == 0 || $sindex == 2 } {
      #wdg1 configure -bg green
      focus $wdg1
      $wdg1 delete 0 end; $wdg1 insert 0 $n1
      $wdg1 icursor end
    } else {
      #wdg2 configure -bg green
      focus $wdg2 
      $wdg2 delete 0 end; $wdg2 insert 0 $n2
      $wdg2 icursor end
    }
    return
  }

  set id [lindex $ids $sindex]

  set prntId $ObjectTable($id,prId)

  set bndr $id
  set bd1 $ObjectTable($prntId,pr1Id)
  set bd2 $ObjectTable($prntId,pr2Id)
  set lr1 -1
  set lr2 -1
  set accept_body_change 1
  set update_gui 1

  #--NOTE: Apply boundary selection via cpp !!!
  #
  set GridParameter(boundaryIds) $ids
  set GridParameter(boundaryLB) $lb
  set GridParameter(boundaryIndex) $sindex

  set data "$bndr $bd1 $lr1 $bd2 $lr2 $accept_body_change $update_gui"

  Util::cpp_exec boundarySelected $data
}


# Set proper widget states when panel data is filled
# (after selecting a paramter etc.)
#
proc GridParameter(MESH_ELEMENT_TYPE,fillProc) {} {
  global GridParameter ObjectTable

  if { $GridParameter(MESH_ELEMENT_TYPE) == "Line" } {
    GridParameter(MESH_ET_LINE,editProc)

  } elseif { $GridParameter(MESH_ELEMENT_TYPE) == "Triangle" } {
    GridParameter(MESH_ET_TRIANGLE,editProc)

  } elseif { $GridParameter(MESH_ELEMENT_TYPE) == "Quad" } {

    if {!$ObjectTable($GridParameter(targetId),accptStrMsh)} {
      GridParameter::setGroupState $GridParameter(quadGridGroup) 0

    } else {      
      set GridParameter(MESH_LAYER_TYPE) "QuadGrid"
      GridParameter(MESH_ET_QUAD,editProc)
    }
  }

  if { ![Util::panelExists GridParameter] } {
    return
  }
}


proc GridParameter(MESH_ET_LINE,editProc) {} {
  global GridParameter Model ObjectTable

  GridParameter::setGroupState $GridParameter(triangleGroup) 0
  GridParameter::setGroupState $GridParameter(seededTriangleGroup) 0

  GridParameter::setGroupState $GridParameter(quadGridGroup) 0

  GridParameter::setGroupState $GridParameter(lineGroup) 1

  set GridParameter(MESH_QUADGRID_N1) ""
  set GridParameter(MESH_QUADGRID_N2) ""

  GridParameter::updateMeshLayerMenu

  GridParameter(MESH_LAYER_TYPE,fillProc)

  GridParameter(MESH_DENSITY_TYPE,fillProc)

  if { ![Util::panelExists GridParameter] } {
    return
  }

}


proc GridParameter(MESH_ET_TRIANGLE,editProc) {} {
  global GridParameter Model ObjectTable

  GridParameter::setGroupState $GridParameter(lineGroup) 0
  GridParameter::setGroupState $GridParameter(quadGridGroup) 0
  GridParameter::setGroupState $GridParameter(triangleGroup) 1

  if {!$ObjectTable($GridParameter(targetId),accptStrMsh)} {
    set GridParameter(MESH_QUADGRID_N1) ""
    set GridParameter(MESH_QUADGRID_N2) ""
  }

  if { [string match "SS*" $GridParameter(MESH_LAYER_TYPE)] } {
    GridParameter::setGroupState $GridParameter(seededTriangleGroup) 1
  } else {
    GridParameter::setGroupState $GridParameter(seededTriangleGroup) 0
  }

  GridParameter::updateMeshLayerMenu

  GridParameter(MESH_LAYER_TYPE,fillProc)

  GridParameter(MESH_DENSITY_TYPE,fillProc)

  if { ![Util::panelExists GridParameter] } {
    return
  }

}


proc GridParameter(MESH_ET_QUAD,editProc) {} {
  global GridParameter Model ObjectTable

  set pid $GridParameter(parameterId)

  GridParameter::setGroupState $GridParameter(lineGroup) 0
  GridParameter::setGroupState $GridParameter(triangleGroup) 0
  GridParameter::setGroupState $GridParameter(seededTriangleGroup) 0
  GridParameter::setGroupState $GridParameter(quadGridGroup) 1

  GridParameter::updateMeshLayerMenu

  GridParameter(MESH_LAYER_TYPE,fillProc)

  GridParameter(MESH_DENSITY_TYPE,fillProc)

  if { ![Util::panelExists GridParameter] } {
    return
  }

}


proc GridParameter::updateMeshLayerMenu {} {
  global GridParameter

  if { ![Util::panelExists GridParameter] } {
    return
  }

  if { $GridParameter(MESH_ELEMENT_TYPE) == "Line" } {
    set idx $GridParameter(meshMethodIndices,LINE)

  } elseif { $GridParameter(MESH_ELEMENT_TYPE) == "Triangle" } {
    set idx $GridParameter(meshMethodIndices,TRIANGLE)

  } elseif { $GridParameter(MESH_ELEMENT_TYPE) == "Quad" } {
    set idx $GridParameter(meshMethodIndices,QUAD_GRID)

  } else {
    return
  }

  set fld MESH_LAYER_TYPE

  # Pick current MenuSelect proc
  #
  set wdg $GridParameter(allWidgets,$fld)
  set ms_proc [ bind $GridParameter(allWidgets,$fld,om) <<MenuSelect>>]

  # Get new menu options
  #
  set tmp [lindex [DataField::getFieldProperty GridParameter $fld Limits] 1]
  set names [lindex $tmp $idx]

  destroy $wdg

  # Build new option-menu
  #
  set om [Panel::createOptionMenuWidget $wdg GridParameter($fld) $names]
  $wdg configure -indicatoron 0 -width 16 
  Widget::configureS $wdg active

  bind $om <<MenuSelect>> $ms_proc

  # Save and pack rebuilt widget
  #
  set GridParameter(allWidgets,$fld) $wdg
  pack $wdg
}


proc GridParameter(MESH_BG_MESH,fillProc) {} {

  GridParameter(MESH_BG_MESH,editProc)
}


proc GridParameter(MESH_BG_MESH,editProc) {} {
  global GridParameter MeshDefine

  # If mesh level bg-mesh is active and it is not
  # a control type-mesh, then body level bg-meshes
  # are not active
  #
  # NOTE: This test not is use currently!!!, MVe 15.02.01
  #
  if { 0 && 
       $MeshDefine(MESH_BG_MESH_ACTIVE) &&
       $MeshDefine(MESH_BG_MESH_FILE) != "" &&
       !$MeshDefine(MESH_BG_MESH_CONTROL)
     } {
    set GridParameter(MESH_BG_MESH_FILE,act) 0

  # Otherwise External bg-mesh type activates
  # the file name entry
  #
  } else {

    if { $GridParameter(MESH_BG_MESH) == "External" } {
      set GridParameter(MESH_BG_MESH_FILE,act) 1
    } else {
      set GridParameter(MESH_BG_MESH_FILE,act) 0
    }
  }

  Widget::configureField GridParameter MESH_BG_MESH_FILE 
}


# Set mesh density type field states when parameter is selected
#
proc GridParameter(MESH_DENSITY_TYPE,fillProc) {} {
  global GridParameter

  GridParameter(MESH_DENSITY_TYPE,groupEditProc)
}


# Set mesh density type field states when radiobutton is selected
#
proc GridParameter(MESH_DENSITY_TYPE,groupEditProc) { {fld ""} } {
  global GridParameter

  set GridParameter(MESH_H,act) 0
  set GridParameter(MESH_R,act) 0

  switch $GridParameter(MESH_DENSITY_TYPE) {

    "H" {
      set GridParameter(MESH_H,act) 1
    }
    
    "R" {
      set GridParameter(MESH_R,act) 1
    }
  }

  if { ![Util::panelExists GridParameter] } {
    return
  }

  Widget::configureField GridParameter MESH_H
  Widget::configureField GridParameter MESH_R
}


# Set mesh seed type states by option menu value when
# parameter is selected
#
proc GridParameter(MESH_LAYER_TYPE,fillProc) {} {
  global GridParameter

  if { [string match "SS*" $GridParameter(MESH_LAYER_TYPE)] } {
    GridParameter::setGroupState $GridParameter(seededTriangleGroup) 1
  } else {
    GridParameter::setGroupState $GridParameter(seededTriangleGroup) 0
  }
}


# Set mesh seed type states when option menu is updated
#
proc GridParameter(MESH_LAYER_TYPE,editProc) {} {
  global GridParameter

  if { [string match "SS*" $GridParameter(MESH_LAYER_TYPE)] } {
    GridParameter::setGroupState $GridParameter(seededTriangleGroup) 1
  } else {
    GridParameter::setGroupState $GridParameter(seededTriangleGroup) 0
  }
}


# Set current mesh name value
#
proc GridParameter(MESH_NAME,fillProc) {} {
  global GridParameter Model

  set GridParameter(MESH_NAME) [lindex $Model(meshNames) $GridParameter(MESH_INDEX)]
}


# Update ObjectTable gr-id from grIds when panel is opend or
# mesh has been changed in the panel
# gr --> grIds
#
proc GridParameter::updateObjectParameterId {} {
  global GridParameter Info MeshDefine Model ObjectTable

  if { [info exists MeshDefine(edited,GridParameter)] &&
       $MeshDefine(edited,GridParameter)
     } {
    return
  }

  if { ![info exists GridParameter(MESH_NAME)] } {
    set GridParameter(MESH_NAME) $Model(currentMeshName)
    set GridParameter(MESH_INDEX) $Model(currentMeshIndex)
  }

  if { $GridParameter(MESH_INDEX) == $Info(NO_INDEX) ||
       $GridParameter(MESH_INDEX) == ""
     } {
    return
  }

  foreach id $ObjectTable(ids) {

    if { ![info exists ObjectTable($id,gr)] } {
      continue
    }

    # Default values
    set ObjectTable($id,gr) $Info(NO_INDEX)
    set ObjectTable($id,excldMsh) 0

    # If grid parameter ids given, try to find one for the current
    # mesh
    set idx [lsearch $ObjectTable($id,grMshIndcs) $GridParameter(MESH_INDEX)]
    if { $idx != -1 } {
      set ObjectTable($id,gr) [lindex $ObjectTable($id,grIds) $idx]
    }

    # If meshing exclude indices given, try to find one for the current
    # mesh
    set idx [lsearch $ObjectTable($id,excldMshIndcs) $GridParameter(MESH_INDEX)]
    if { $idx != -1 } {
      set ObjectTable($id,excldMsh) 1
    } else {
      set ObjectTable($id,excldMsh) 0
    }
  }

  if { [info exists GridParameter(objectLB)] &&
       [winfo exists $GridParameter(objectLB)]
     } {
    StdPanelInit::constructObjectLBList GridParameter
    StdPanelInit::fillObjectListBox GridParameter
    #GridParameter::objectSelected $GridParameter(objectIndex)
    $GridParameter(objectLB) selection set $GridParameter(objectIndex)
  }
}


# Update ObjectTable gr-id to grIds (and grMshIndcs)
# Used after ok/apply and when mesh has been changed
# in the panel
# grIds --> gr
#
proc GridParameter::updateObjectParameterIds {} {
  global GridParameter Info MeshDefine ObjectTable

  if { [info exist GridParameter(MESH_INDEX)] &&
       $GridParameter(MESH_INDEX) != ""       &&
       $GridParameter(MESH_INDEX) != $Info(NO_INDEX)
     } {
    set msh_idx $GridParameter(MESH_INDEX)
  } else {
    set msh_idx [llength MeshDefine(mehNames)]
  }

  foreach id $ObjectTable(ids) {

    if { ![info exists ObjectTable($id,gr)] } {
      continue
    }

    #--Grid parameter ids
    set ids $ObjectTable($id,grIds)
    set indices $ObjectTable($id,grMshIndcs)
    set gid $ObjectTable($id,gr)

    if { $gid == $Info(NO_INDEX) } {
      set result [List::removeFromIndexedIdList $indices $ids $msh_idx $gid]
    } else {
      set result [List::addToIndexedIdList $indices $ids $msh_idx $gid]
    }

    set ObjectTable($id,grMshIndcs) [lindex $result 0]
    set ObjectTable($id,grIds) [lindex $result 1]

    #--Exclude from meshing indices
    set ids $ObjectTable($id,excldMshIndcs)

    if { $ObjectTable($id,excldMsh) } {
      set result [List::addToIdList $ids $msh_idx]

    } else {
      set result [List::removeFromIdList $ids $msh_idx]

    }

    set ObjectTable($id,excldMshIndcs) $result

  } ;# Foreach object

  Panel::panelDataChanged 0 GridParameter
}


# Check that QuadGrid definitions are matching after
# attaching or updating a quadgrid-type parameter
#
proc  GridParameter::checkParameterAttachment {} {
  global GridParameter Info ObjectTable

  #--Current target body
  set tid $GridParameter(targetId)

  #--If no gridable body
  if { $tid == $Info(NO_INDEX) ||
       !$ObjectTable($tid,accptStrMsh) ||
       $ObjectTable($tid,gr) == $Info(NO_INDEX)
     } {
    return
  }

  #--If no quadgrid-type parameter
  if { $GridParameter(MESH_ELEMENT_TYPE) != "Quad" } {
    return
  }

  #--Pick current body element's all sub ids (including inner
  #  boundaries!) and equivalent quadgrid n-values
  #
  set sub_ids $ObjectTable($tid,sbIds)

  set grid_ns ""
  lappend grid_ns $GridParameter(MESH_QUADGRID_N1)
  lappend grid_ns $GridParameter(MESH_QUADGRID_N2)
  lappend grid_ns $GridParameter(MESH_QUADGRID_N1)
  lappend grid_ns $GridParameter(MESH_QUADGRID_N2)

  #--Loop all objects and check if they have a quadgrid-type
  #  mesh parameter for the (current) mesh
  #
  foreach id $ObjectTable(ids) {

    #-Current body
    if { $id == $tid } {
      continue
    }

    #-No quadgrid possible for the body
    if { ![info exists ObjectTable($id,gr)] ||
         !$ObjectTable($id,accptStrMsh) ||
         $ObjectTable($id,gr) ==$Info(NO_INDEX)
       } {
      continue
    }

    set pid $ObjectTable($id,gr)  

    set etype [DataField::getFieldValue GridParameter $pid MESH_ELEMENT_TYPE]

    #-No quadgrid defined for the body
    if { $etype != "Quad" } {
      continue
    }

    #-Ok, check if body under inspection have any of same
    # elements in the current target body
    #
    foreach sid $sub_ids grid_n $grid_ns {

      set idx [lsearch $ObjectTable($id,sbIds) $sid]

      if { $idx == -1 } {
        continue
      }

      #-Overwrite the QuadGrid-N value for the
      # corresponding element

      # Get first proper variable name 
      if { $idx == 0 || $idx == 2 } {
        set fn MESH_QUADGRID_N1
      } else {
        set fn MESH_QUADGRID_N2
      }

      # The update parameter
      DataField::setFieldValue GridParameter $pid $fn $grid_n

    } ;# Foreach subelement in the current target body

  } ;# Foreach object

}


######################
### MATERIAL panel ###
######################

proc Material(checkPanel) {} {
  Material(COMPRESSIBILITY_MODEL,editProc)
}

proc Material(COMPRESSIBILITY_MODEL,fillProc) {} {

  Material(COMPRESSIBILITY_MODEL,editProc)
}


proc Material(COMPRESSIBILITY_MODEL,editProc) {} {
  global Material

  if { [Util::masksAreMatching (¤H) [Panel::getTargetMask Material] ] } {
    set has_heat_eq 1
  } else {
    set has_heat_eq 0
  }

  set value $Material(COMPRESSIBILITY_MODEL)

  # Note: Possible HeatCapacity field in the flow panel is
  # controlled by incompressibility when the current body
  # does not have any heat-equation
  #
  if { $value == "" || $value == "Incompressible" } {

    set Material(REFERENCE_PRESSURE,act) 0
    set Material(SPECIFIC_HEAT_RATIO,act) 0

    if { !$has_heat_eq } {
      set Material(HEAT_CAPACITY,act) 0
    }
  
  } else {
    set Material(REFERENCE_PRESSURE,act) 1
    set Material(SPECIFIC_HEAT_RATIO,act) 1

    if { !$has_heat_eq } {
      set Material(HEAT_CAPACITY,act) 1
    }
  }

  if { ![Util::panelExists Material] } {
    return
  }

  if { !$has_heat_eq } {
    Widget::configureField Material HEAT_CAPACITY
  }

  if { ![Widget::arrayWidgetExists Material COMPRESSIBILITY_MODEL] } {
    return
  }

  Widget::configureField Material REFERENCE_PRESSURE
  Widget::configureField Material SPECIFIC_HEAT_RATIO

}



####################
### SOLVER panel ###
####################

proc Solver(PROCEDURE,fillProc) {} {
  global Solver

  set vals [split $Solver(PROCEDURE) ";"]

  set Solver(LIBRARY_FILE) [lindex $vals 0]
  set Solver(FUNCTION_NAME) [lindex $vals 1]
}


proc Solver(PROCEDURE,checkProc) {} {
  global Solver

  set lb $Solver(LIBRARY_FILE)
  set fn $Solver(FUNCTION_NAME)

  set Solver(PROCEDURE) [join [list $lb $fn] ";"]

  return ""
}


proc Solver(BUBBLES,editProc) {} {
  global Solver

  if { $Solver(BUBBLES) } {
    set Solver(STABILIZE) "False"

  } else {
    set Solver(STABILIZE) "True"
  }
}


proc Solver(STABILIZE,editProc) {} {
  global Solver

  if { $Solver(STABILIZE) } {
    set Solver(BUBBLES) "False"

  } else {
    set Solver(BUBBLES) "True"
  }
}


# When Solver panel is opened
#
proc Solver(LINEAR_SYSTEM_SOLVER,fillProc) {} {
  global Solver

  Solver(LINEAR_SYSTEM_SOLVER,editProc)
}


# When Solver type OptionMenu is pressed
#
proc Solver(LINEAR_SYSTEM_SOLVER,editProc) {} {
  global Equation Solver

  if { $Solver(LINEAR_SYSTEM_SOLVER) == "Direct" } {
    #Solver::setFieldStates "True" $Solver(direct_group) 
    #Solver::setFieldStates "False" $Solver(iter_group)
    #Solver::setFieldStates "False" $Solver(multigrid_group) 
    set method_fld LINEAR_SYSTEM_DIRECT_METHOD

  } elseif { $Solver(LINEAR_SYSTEM_SOLVER) == "Iterative" } {
    #Solver::setFieldStates "True" $Solver(iter_group) 
    #Solver::setFieldStates "False" $Solver(multigrid_group) 
    #Solver::setFieldStates "False" $Solver(direct_group) 
    Solver::precond_proc
    set method_fld LINEAR_SYSTEM_ITERATIVE_METHOD

  } elseif { $Solver(LINEAR_SYSTEM_SOLVER) == "Multigrid" } {
    #Solver::setFieldStates "False" $Solver(iter_group) 
    #Solver::setFieldStates "True" $Solver(multigrid_group) 
    #Solver::setFieldStates "False" $Solver(direct_group) 
    #Solver::setFieldStates "False" LINEAR_SYSTEM_ITERATIVE_METHOD 
    Solver::precond_proc
    set method_fld LINEAR_SYSTEM_MULTIGRID_METHOD
  }

  set Solver(LINEAR_SYSTEM_METHOD) $Solver($method_fld)
  
  # Rebuild method menu if panel open
  #
  set fld LINEAR_SYSTEM_METHOD

  if { ![info exists Solver(allWidgets,$fld) ] ||
       ![winfo exists $Solver(allWidgets,$fld) ]
     } {
    return
  }

  set wdg $Solver(allWidgets,$fld)

  # Pick current MenuSelect proc
  set ms_proc [ bind $Solver(allWidgets,$fld,om) <<MenuSelect>>]

  destroy $wdg

  set mvals [DataField::getFieldProperty Solver $method_fld Limits]
  set mvals [lindex $mvals 1]

  # Build new method option-menu
  set om [Panel::createOptionMenuWidget $wdg Solver($fld) $mvals]
  $wdg configure -indicatoron 0 -width 12 
  Widget::configureS $wdg active

  bind $om <<MenuSelect>> $ms_proc

  # Save and pack rebuilt widget
  set Solver(allWidgets,$fld) $wdg
  pack $wdg
}


# When Solver method OptionMenu is pressed
#
proc Solver(LINEAR_SYSTEM_METHOD,editProc) {} {
  global Solver

  set fld LINEAR_SYSTEM_METHOD

  if { [Util::nce $Solver(LINEAR_SYSTEM_SOLVER) "Direct"] } {
    set Solver(LINEAR_SYSTEM_DIRECT_METHOD) $Solver($fld)

  } elseif { [Util::nce $Solver(LINEAR_SYSTEM_SOLVER) "Iterative"] } {
    set Solver(LINEAR_SYSTEM_ITERATIVE_METHOD) $Solver($fld)

  } elseif { [Util::nce $Solver(LINEAR_SYSTEM_SOLVER) "Multigrid"] } {
    set Solver(LINEAR_SYSTEM_MULTIGRID_METHOD) $Solver($fld)
  }
}


# When ILU-menu is used
#
proc Solver(LINEAR_SYSTEM_PRECONDITIONING,editProc) {} {
  global Solver

  Solver::precond_proc
}


# Make ILUT-threshold-entry active if preconditiong mode is "ILUT"
#
proc Solver::precond_proc {} {
  global Solver

  if { [Util::nce $Solver(LINEAR_SYSTEM_PRECONDITIONING) "ILUT"] } {
    Solver::setFieldStates "True" LINEAR_SYSTEM_ILUT_TOLERANCE
  } else {
    Solver::setFieldStates "False" LINEAR_SYSTEM_ILUT_TOLERANCE
  }
}


# end ecif_tk_panelCheck.tcl
# ********************